From: Daid Date: Sat, 28 Jul 2012 09:04:04 +0000 (+0200) Subject: Faster generation of normals with numpy. X-Git-Tag: 12.08~15 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c92cc07afd8af81434d1c46867136d481e0ed833;p=cura.git Faster generation of normals with numpy. --- diff --git a/Cura/util/mesh.py b/Cura/util/mesh.py index 128d362e..dc01198c 100644 --- a/Cura/util/mesh.py +++ b/Cura/util/mesh.py @@ -63,13 +63,14 @@ class mesh(object): mat = numpy.array([mat[0],mat[2],mat[1]]) self.vertexes = (numpy.matrix(self.origonalVertexes, copy = False) * numpy.matrix(mat)).getA() - for i in xrange(0, len(self.origonalVertexes), 3): - v1 = self.vertexes[i] - v2 = self.vertexes[i+1] - v3 = self.vertexes[i+2] - self.normal[i/3] = numpy.cross((v2 - v1), (v3 - v1)) - self.normal[i/3] /= (self.normal[i/3] * self.normal[i/3]).sum() - + tris = self.vertexes.reshape(self.vertexCount / 3, 3, 3) + normals = numpy.cross( tris[::,1 ] - tris[::,0] , tris[::,2 ] - tris[::,0] ) + lens = numpy.sqrt( normals[:,0]**2 + normals[:,1]**2 + normals[:,2]**2 ) + normals[:,0] /= lens + normals[:,1] /= lens + normals[:,2] /= lens + self.normal = normals + self.getMinimumZ() def splitToParts(self):