def makeMesh(self):
if self.Xs.shape[2] == 0:
return
X = self.Xs[:, :, 0]
Y = self.Ys[:, :, 0]
Z = self.Zs[:, :, 0]
mesh = PolyMesh()
#Come up with vertex indices in the mask
Mask = np.array(self.Mask, dtype=np.int32)
nV = np.sum(Mask)
Mask[self.Mask > 0] = np.arange(nV) + 1
Mask = Mask - 1
VPos = np.zeros((nV, 3))
VPos[:, 0] = X[self.Mask > 0]
VPos[:, 1] = Y[self.Mask > 0]
VPos[:, 2] = -Z[self.Mask > 0]
#Add lower right triangle
v1 = Mask[0:-1, 0:-1].flatten()
v2 = Mask[1:, 0:-1].flatten()
v3 = Mask[1:, 1:].flatten()
N = v1.size
ITris1 = np.concatenate((np.reshape(v1, [N, 1]), np.reshape(v2, [N, 1]), np.reshape(v3, [N, 1])), 1)
#Add upper right triangle
v1 = Mask[0:-1, 0:-1].flatten()
v2 = Mask[1:, 1:].flatten()
v3 = Mask[0:-1, 1:].flatten()
N = v1.size
ITris2 = np.concatenate((np.reshape(v1, [N, 1]), np.reshape(v2, [N, 1]), np.reshape(v3, [N, 1])), 1)
ITris = np.concatenate((ITris1, ITris2), 0)
#Only retain triangles which have all three points
ITris = ITris[np.sum(ITris == -1, 1) == 0, :]
mesh.VPos = VPos
mesh.ITris = ITris
mesh.VColors = 0.5*np.ones(mesh.VPos.shape)
mesh.updateNormalBuffer()
mesh.VPosVBO = vbo.VBO(np.array(mesh.VPos, dtype=np.float32))
mesh.VNormalsVBO = vbo.VBO(np.array(mesh.VNormals, dtype=np.float32))
mesh.VColorsVBO = vbo.VBO(np.array(mesh.VColors, dtype=np.float32))
mesh.IndexVBO = vbo.VBO(mesh.ITris, target=GL_ELEMENT_ARRAY_BUFFER)
mesh.needsDisplayUpdate = False
self.mesh = mesh
#Compute the delta coordinates and solvers for all frames of the video
评论列表
文章目录