-import math\r
+import math, time\r
\r
from util import util3d\r
from util import profile\r
\r
def DrawSTL(mesh):\r
glEnable(GL_CULL_FACE)\r
- for i in xrange(0, mesh.vertexCount, 3):\r
- glBegin(GL_TRIANGLES)\r
- v1 = mesh.vertexes[i]\r
- v2 = mesh.vertexes[i+1]\r
- v3 = mesh.vertexes[i+2]\r
- glNormal3f(mesh.normal[i/3][0], mesh.normal[i/3][1], mesh.normal[i/3][2])\r
- glVertex3f(v1[0], v1[1], v1[2])\r
- glVertex3f(v2[0], v2[1], v2[2])\r
- glVertex3f(v3[0], v3[1], v3[2])\r
- glNormal3f(-mesh.normal[i/3][0], -mesh.normal[i/3][1], -mesh.normal[i/3][2])\r
- glVertex3f(v1[0], v1[1], v1[2])\r
- glVertex3f(v3[0], v3[1], v3[2])\r
- glVertex3f(v2[0], v2[1], v2[2])\r
- glEnd()\r
+ glEnableClientState(GL_VERTEX_ARRAY);\r
+ glEnableClientState(GL_NORMAL_ARRAY);\r
+ glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)\r
+ glNormalPointer(GL_FLOAT, 0, mesh.normal)\r
+ \r
+ glCullFace(GL_BACK)\r
+ glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)\r
+ \r
+ glCullFace(GL_FRONT)\r
+ glNormalPointer(GL_FLOAT, 0, mesh.invNormal)\r
+ glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)\r
+ \r
+ glDisableClientState(GL_VERTEX_ARRAY)\r
+ glDisableClientState(GL_NORMAL_ARRAY);\r
\r
def DrawGCodeLayer(layer):\r
filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2\r
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):
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)
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()