Improve rendering time by using numpy to generate normals, and vertex arrays. This also seems to have increased performance.
parent
c92cc07afd
commit
05d3c36c61
|
@ -1,4 +1,4 @@
|
||||||
import math
|
import math, time
|
||||||
|
|
||||||
from util import util3d
|
from util import util3d
|
||||||
from util import profile
|
from util import profile
|
||||||
|
@ -205,20 +205,20 @@ def DrawBox(vMin, vMax):
|
||||||
|
|
||||||
def DrawSTL(mesh):
|
def DrawSTL(mesh):
|
||||||
glEnable(GL_CULL_FACE)
|
glEnable(GL_CULL_FACE)
|
||||||
for i in xrange(0, mesh.vertexCount, 3):
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glBegin(GL_TRIANGLES)
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
v1 = mesh.vertexes[i]
|
glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)
|
||||||
v2 = mesh.vertexes[i+1]
|
glNormalPointer(GL_FLOAT, 0, mesh.normal)
|
||||||
v3 = mesh.vertexes[i+2]
|
|
||||||
glNormal3f(mesh.normal[i/3][0], mesh.normal[i/3][1], mesh.normal[i/3][2])
|
glCullFace(GL_BACK)
|
||||||
glVertex3f(v1[0], v1[1], v1[2])
|
glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)
|
||||||
glVertex3f(v2[0], v2[1], v2[2])
|
|
||||||
glVertex3f(v3[0], v3[1], v3[2])
|
glCullFace(GL_FRONT)
|
||||||
glNormal3f(-mesh.normal[i/3][0], -mesh.normal[i/3][1], -mesh.normal[i/3][2])
|
glNormalPointer(GL_FLOAT, 0, mesh.invNormal)
|
||||||
glVertex3f(v1[0], v1[1], v1[2])
|
glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)
|
||||||
glVertex3f(v3[0], v3[1], v3[2])
|
|
||||||
glVertex3f(v2[0], v2[1], v2[2])
|
glDisableClientState(GL_VERTEX_ARRAY)
|
||||||
glEnd()
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
def DrawGCodeLayer(layer):
|
def DrawGCodeLayer(layer):
|
||||||
filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
|
filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
|
||||||
|
|
|
@ -20,7 +20,7 @@ class mesh(object):
|
||||||
def _prepareVertexCount(self, vertexNumber):
|
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.
|
#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.origonalVertexes = numpy.zeros((vertexNumber, 3), float)
|
||||||
self.normal = numpy.zeros((vertexNumber / 3, 3))
|
self.normal = numpy.zeros((vertexNumber, 3), float)
|
||||||
self.vertexCount = 0
|
self.vertexCount = 0
|
||||||
|
|
||||||
def _postProcessAfterLoad(self):
|
def _postProcessAfterLoad(self):
|
||||||
|
@ -56,11 +56,11 @@ class mesh(object):
|
||||||
mat10 = math.sin(rotate) * scaleX
|
mat10 = math.sin(rotate) * scaleX
|
||||||
mat11 = math.cos(rotate) * scaleY
|
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:
|
if swapXZ:
|
||||||
mat = numpy.array([mat[2],mat[1],mat[0]])
|
mat = numpy.array([mat[2],mat[1],mat[0]], float)
|
||||||
if swapYZ:
|
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()
|
self.vertexes = (numpy.matrix(self.origonalVertexes, copy = False) * numpy.matrix(mat)).getA()
|
||||||
|
|
||||||
tris = self.vertexes.reshape(self.vertexCount / 3, 3, 3)
|
tris = self.vertexes.reshape(self.vertexCount / 3, 3, 3)
|
||||||
|
@ -69,7 +69,13 @@ class mesh(object):
|
||||||
normals[:,0] /= lens
|
normals[:,0] /= lens
|
||||||
normals[:,1] /= lens
|
normals[:,1] /= lens
|
||||||
normals[:,2] /= 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()
|
self.getMinimumZ()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue