chiark / gitweb /
Fix the steep overhang display when rotating/scaling.
authordaid303 <daid303@gmail.com>
Tue, 29 Jan 2013 08:46:35 +0000 (09:46 +0100)
committerdaid303 <daid303@gmail.com>
Tue, 29 Jan 2013 08:46:35 +0000 (09:46 +0100)
Cura/gui/preview3d.py
Cura/gui/util/opengl.py

index 4f63f0f124f3c659b1ddcf5fc09726a551a5071a..2e1451c2142fa785c8a8a84367cb76ae2c0ecdfa 100644 (file)
@@ -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)
index 5aa00d616cce0dafbfcc69b282b13fb09cc5b10b..b1dc7e8fcf10660d35a72c802f3a40c9bd8b50a5 100644 (file)
@@ -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])