From 437e990b5b486306d28c8e5635d7fd900aee4cc8 Mon Sep 17 00:00:00 2001 From: daid303 Date: Tue, 29 Jan 2013 09:46:35 +0100 Subject: [PATCH] Fix the steep overhang display when rotating/scaling. --- Cura/gui/preview3d.py | 13 +++++++++---- Cura/gui/util/opengl.py | 15 ++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Cura/gui/preview3d.py b/Cura/gui/preview3d.py index 4f63f0f1..2e1451c2 100644 --- a/Cura/gui/preview3d.py +++ b/Cura/gui/preview3d.py @@ -321,6 +321,7 @@ class previewPanel(wx.Panel): mesh = meshLoader.loadMesh(obj.filename) obj.mesh = mesh obj.dirty = True + obj.steepDirty = True self.updateModelTransform() self.OnScaleMax(True) self.glCanvas.zoom = numpy.max(self.objectsSize) * 3.5 @@ -511,6 +512,8 @@ class PreviewGLCanvas(openglGui.glGuiPanel): self.parent.matrix *= self.tempMatrix self.parent.updateModelTransform() self.tempMatrix = None + for obj in self.parent.objectList: + obj.steepDirty = True self.parent.tool.OnDragEnd() self.dragType = '' if e.Dragging() and e.RightIsDown(): @@ -596,13 +599,10 @@ class PreviewGLCanvas(openglGui.glGuiPanel): glNewList(obj.displayList, GL_COMPILE) opengl.DrawMesh(obj.mesh) glEndList() - glNewList(obj.steepDisplayList, GL_COMPILE) - opengl.DrawMeshSteep(obj.mesh, 60) - glEndList() glNewList(obj.outlineDisplayList, GL_COMPILE) opengl.DrawMeshOutline(obj.mesh) glEndList() - + if self.viewMode == "Mixed": glDisable(GL_BLEND) glColor3f(0.0,0.0,0.0) @@ -724,6 +724,11 @@ class PreviewGLCanvas(openglGui.glGuiPanel): self.drawModel(obj.outlineDisplayList) if self.drawSteepOverhang: + if obj.steepDirty: + obj.steepDirty = False + glNewList(obj.steepDisplayList, GL_COMPILE) + opengl.DrawMeshSteep(obj.mesh, self.parent.matrix, 60) + glEndList() glDisable(GL_LIGHTING) glColor3f(1,1,1) self.drawModel(obj.steepDisplayList) diff --git a/Cura/gui/util/opengl.py b/Cura/gui/util/opengl.py index 5aa00d61..b1dc7e8f 100644 --- a/Cura/gui/util/opengl.py +++ b/Cura/gui/util/opengl.py @@ -332,12 +332,13 @@ def DrawMesh(mesh): glDisableClientState(GL_NORMAL_ARRAY); -def DrawMeshSteep(mesh, angle): +def DrawMeshSteep(mesh, matrix, angle): cosAngle = math.sin(angle / 180.0 * math.pi) glDisable(GL_LIGHTING) glDepthFunc(GL_EQUAL) + normals = (numpy.matrix(mesh.normal, copy = False) * matrix).getA() for i in xrange(0, int(mesh.vertexCount), 3): - if mesh.normal[i][2] < -0.999999: + if normals[i][2] < -0.999999: if mesh.vertexes[i + 0][2] > 0.01: glColor3f(0.5, 0, 0) glBegin(GL_TRIANGLES) @@ -345,14 +346,14 @@ def DrawMeshSteep(mesh, angle): glVertex3f(mesh.vertexes[i + 1][0], mesh.vertexes[i + 1][1], mesh.vertexes[i + 1][2]) glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) glEnd() - elif mesh.normal[i][2] < -cosAngle: - glColor3f(-mesh.normal[i][2], 0, 0) + elif normals[i][2] < -cosAngle: + glColor3f(-normals[i][2], 0, 0) glBegin(GL_TRIANGLES) glVertex3f(mesh.vertexes[i + 0][0], mesh.vertexes[i + 0][1], mesh.vertexes[i + 0][2]) glVertex3f(mesh.vertexes[i + 1][0], mesh.vertexes[i + 1][1], mesh.vertexes[i + 1][2]) glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) glEnd() - elif mesh.normal[i][2] > 0.999999: + elif normals[i][2] > 0.999999: if mesh.vertexes[i + 0][2] > 0.01: glColor3f(0.5, 0, 0) glBegin(GL_TRIANGLES) @@ -360,8 +361,8 @@ def DrawMeshSteep(mesh, angle): glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) glVertex3f(mesh.vertexes[i + 1][0], mesh.vertexes[i + 1][1], mesh.vertexes[i + 1][2]) glEnd() - elif mesh.normal[i][2] > cosAngle: - glColor3f(mesh.normal[i][2], 0, 0) + elif normals[i][2] > cosAngle: + glColor3f(normals[i][2], 0, 0) glBegin(GL_TRIANGLES) glVertex3f(mesh.vertexes[i + 0][0], mesh.vertexes[i + 0][1], mesh.vertexes[i + 0][2]) glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) -- 2.30.2