def computeNormals(vtx, idx):
nrml = numpy.zeros(vtx.shape, numpy.float32)
# compute normal per triangle
triN = numpy.cross(vtx[idx[:,1]] - vtx[idx[:,0]], vtx[idx[:,2]] - vtx[idx[:,0]])
# sum normals at vtx
nrml[idx[:,0]] += triN[:]
nrml[idx[:,1]] += triN[:]
nrml[idx[:,2]] += triN[:]
# compute norms
nrmlNorm = numpy.sqrt(nrml[:,0]*nrml[:,0]+nrml[:,1]*nrml[:,1]+nrml[:,2]*nrml[:,2])
return nrml/nrmlNorm.reshape(-1,1)
评论列表
文章目录