Don't create a new ndarray for each getBlockFaceVertices call
This commit is contained in:
parent
f4124610a3
commit
ca58a60fc6
@ -343,6 +343,8 @@ cdef class BlockModels(object):
|
|||||||
cdef FaceInfo faceInfo
|
cdef FaceInfo faceInfo
|
||||||
cdef short * vec
|
cdef short * vec
|
||||||
|
|
||||||
|
cdef cnp.ndarray xyzuvstc = np.empty(shape=(4, 8), dtype='f4')
|
||||||
|
|
||||||
for nameAndState, allQuads in self.modelQuads.iteritems():
|
for nameAndState, allQuads in self.modelQuads.iteritems():
|
||||||
if nameAndState != UNKNOWN_BLOCK:
|
if nameAndState != UNKNOWN_BLOCK:
|
||||||
try:
|
try:
|
||||||
@ -372,10 +374,10 @@ cdef class BlockModels(object):
|
|||||||
|
|
||||||
quadface = faceInfo.face
|
quadface = faceInfo.face
|
||||||
cullface = faceInfo.cullface
|
cullface = faceInfo.cullface
|
||||||
xyzuvstc = getBlockFaceVertices(faceInfo.x1, faceInfo.y1, faceInfo.z1,
|
getBlockFaceVertices(<float *>xyzuvstc.data,
|
||||||
|
faceInfo.x1, faceInfo.y1, faceInfo.z1,
|
||||||
faceInfo.x2, faceInfo.y2, faceInfo.z2,
|
faceInfo.x2, faceInfo.y2, faceInfo.z2,
|
||||||
quadface, u1, v1, u2, v2, faceInfo.textureRotation)
|
quadface, u1, v1, u2, v2, faceInfo.textureRotation)
|
||||||
xyzuvstc.shape = 4, 8
|
|
||||||
|
|
||||||
if faceInfo.variantZrot:
|
if faceInfo.variantZrot:
|
||||||
quadface = rotateFace(quadface, 2, faceInfo.variantZrot)
|
quadface = rotateFace(quadface, 2, faceInfo.variantZrot)
|
||||||
@ -405,11 +407,10 @@ cdef class BlockModels(object):
|
|||||||
rgba[..., 1] = (tintcolor[1] * int(rgba[0, 1])) >> 8
|
rgba[..., 1] = (tintcolor[1] * int(rgba[0, 1])) >> 8
|
||||||
rgba[..., 2] = (tintcolor[2] * int(rgba[0, 2])) >> 8
|
rgba[..., 2] = (tintcolor[2] * int(rgba[0, 2])) >> 8
|
||||||
|
|
||||||
xyzuvstc.shape = 32 # flatten to store in ModelQuad.xyzuvstc
|
|
||||||
|
|
||||||
#cookedQuads.append((xyzuvstc, cullface, face))
|
#cookedQuads.append((xyzuvstc, cullface, face))
|
||||||
quadxyzuvstc = modelQuads.quads[i].xyzuvstc
|
quadxyzuvstc = modelQuads.quads[i].xyzuvstc
|
||||||
modelxyzuvstc = xyzuvstc
|
modelxyzuvstc = xyzuvstc.ravel()
|
||||||
quadxyzuvstc[:] = modelxyzuvstc[:]
|
quadxyzuvstc[:] = modelxyzuvstc[:]
|
||||||
if cullface != -1:
|
if cullface != -1:
|
||||||
modelQuads.quads[i].cullface[0] = 1
|
modelQuads.quads[i].cullface[0] = 1
|
||||||
@ -451,6 +452,8 @@ cdef class BlockModels(object):
|
|||||||
cdef float[:] quadVerts, modelQuadVerts
|
cdef float[:] quadVerts, modelQuadVerts
|
||||||
cdef short * fv
|
cdef short * fv
|
||||||
cdef short dx, dy, dz
|
cdef short dx, dy, dz
|
||||||
|
cdef cnp.ndarray varray = np.empty(shape=(4, 8), dtype='f4')
|
||||||
|
|
||||||
for filled in range(9):
|
for filled in range(9):
|
||||||
box = FloatBox((0, 0, 0), (1, ((8 - filled) / 9.0) if filled < 8 else 1.0, 1))
|
box = FloatBox((0, 0, 0), (1, ((8 - filled) / 9.0) if filled < 8 else 1.0, 1))
|
||||||
|
|
||||||
@ -471,15 +474,14 @@ cdef class BlockModels(object):
|
|||||||
modelQuads.quads[face].quadface[2] = dy
|
modelQuads.quads[face].quadface[2] = dy
|
||||||
modelQuads.quads[face].quadface[3] = dz
|
modelQuads.quads[face].quadface[3] = dz
|
||||||
|
|
||||||
varray = getBlockFaceVertices(box.minx, box.miny, box.minz,
|
getBlockFaceVertices(<float *>varray.data,
|
||||||
|
box.minx, box.miny, box.minz,
|
||||||
box.maxx, box.maxy, box.maxz,
|
box.maxx, box.maxy, box.maxz,
|
||||||
face, 0, 0, 16, 16, 0)
|
face, 0, 0, 16, 16, 0)
|
||||||
|
|
||||||
varray.shape = 4, 8
|
|
||||||
varray.view('uint8')[:, 28:] = faceShades[face]
|
varray.view('uint8')[:, 28:] = faceShades[face]
|
||||||
|
|
||||||
varray.shape = 32
|
quadVerts = varray.ravel()
|
||||||
quadVerts = varray
|
|
||||||
modelQuadVerts = modelQuads.quads[face].xyzuvstc
|
modelQuadVerts = modelQuads.quads[face].xyzuvstc
|
||||||
modelQuadVerts[:] = quadVerts[:]
|
modelQuadVerts[:] = quadVerts[:]
|
||||||
|
|
||||||
@ -655,12 +657,12 @@ def npRotate(axis, angle, rescale=False):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cdef getBlockFaceVertices(float x1, float y1, float z1,
|
cdef getBlockFaceVertices(float[] xyzuvstc,
|
||||||
|
float x1, float y1, float z1,
|
||||||
float x2, float y2, float z2,
|
float x2, float y2, float z2,
|
||||||
short face,
|
short face,
|
||||||
short u1, short v1, short u2, short v2, int textureRotation):
|
short u1, short v1, short u2, short v2, int textureRotation):
|
||||||
cdef int roll = 0
|
cdef int roll = 0
|
||||||
cdef float[32] xyzuvstc
|
|
||||||
|
|
||||||
cdef float[8] tc
|
cdef float[8] tc
|
||||||
if textureRotation:
|
if textureRotation:
|
||||||
@ -722,8 +724,3 @@ cdef getBlockFaceVertices(float x1, float y1, float z1,
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Unknown face %s" % face)
|
raise ValueError("Unknown face %s" % face)
|
||||||
|
|
||||||
cdef cnp.npy_intp shape = 32
|
|
||||||
|
|
||||||
faceVertices = cnp.PyArray_EMPTY(1, &shape, cnp.NPY_FLOAT, 0)
|
|
||||||
faceVertices[:] = <float[:]>xyzuvstc
|
|
||||||
return faceVertices
|
|
||||||
|
Reference in New Issue
Block a user