diff --git a/Cura/gui/opengl.py b/Cura/gui/opengl.py index 7b2b676..4cf9740 100644 --- a/Cura/gui/opengl.py +++ b/Cura/gui/opengl.py @@ -1,4 +1,4 @@ -import math +import math, time from util import util3d from util import profile @@ -205,20 +205,20 @@ def DrawBox(vMin, vMax): def DrawSTL(mesh): glEnable(GL_CULL_FACE) - for i in xrange(0, mesh.vertexCount, 3): - glBegin(GL_TRIANGLES) - v1 = mesh.vertexes[i] - v2 = mesh.vertexes[i+1] - v3 = mesh.vertexes[i+2] - glNormal3f(mesh.normal[i/3][0], mesh.normal[i/3][1], mesh.normal[i/3][2]) - glVertex3f(v1[0], v1[1], v1[2]) - glVertex3f(v2[0], v2[1], v2[2]) - glVertex3f(v3[0], v3[1], v3[2]) - glNormal3f(-mesh.normal[i/3][0], -mesh.normal[i/3][1], -mesh.normal[i/3][2]) - glVertex3f(v1[0], v1[1], v1[2]) - glVertex3f(v3[0], v3[1], v3[2]) - glVertex3f(v2[0], v2[1], v2[2]) - glEnd() + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes) + glNormalPointer(GL_FLOAT, 0, mesh.normal) + + glCullFace(GL_BACK) + glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount) + + glCullFace(GL_FRONT) + glNormalPointer(GL_FLOAT, 0, mesh.invNormal) + glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount) + + glDisableClientState(GL_VERTEX_ARRAY) + glDisableClientState(GL_NORMAL_ARRAY); def DrawGCodeLayer(layer): filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2 diff --git a/Cura/util/mesh.py b/Cura/util/mesh.py index dc01198..799551f 100644 --- a/Cura/util/mesh.py +++ b/Cura/util/mesh.py @@ -20,7 +20,7 @@ class mesh(object): def _prepareVertexCount(self, vertexNumber): #Set the amount of faces before loading data in them. This way we can create the numpy arrays before we fill them. self.origonalVertexes = numpy.zeros((vertexNumber, 3), float) - self.normal = numpy.zeros((vertexNumber / 3, 3)) + self.normal = numpy.zeros((vertexNumber, 3), float) self.vertexCount = 0 def _postProcessAfterLoad(self): @@ -56,11 +56,11 @@ class mesh(object): mat10 = math.sin(rotate) * scaleX mat11 = math.cos(rotate) * scaleY - mat = numpy.array([[mat00,mat10,0],[mat01,mat11,0],[0,0,scaleZ]]) + mat = numpy.array([[mat00,mat10,0],[mat01,mat11,0],[0,0,scaleZ]], float) if swapXZ: - mat = numpy.array([mat[2],mat[1],mat[0]]) + mat = numpy.array([mat[2],mat[1],mat[0]], float) if swapYZ: - mat = numpy.array([mat[0],mat[2],mat[1]]) + mat = numpy.array([mat[0],mat[2],mat[1]], float) self.vertexes = (numpy.matrix(self.origonalVertexes, copy = False) * numpy.matrix(mat)).getA() tris = self.vertexes.reshape(self.vertexCount / 3, 3, 3) @@ -69,7 +69,13 @@ class mesh(object): normals[:,0] /= lens normals[:,1] /= lens normals[:,2] /= lens - self.normal = normals + + n = numpy.zeros((self.vertexCount / 3, 9), float) + n[:,0:3] = normals + n[:,3:6] = normals + n[:,6:9] = normals + self.normal = n.reshape(self.vertexCount, 3) + self.invNormal = -self.normal self.getMinimumZ()