Skinned Mesh in M3G
Skinned Mesh,就是根据skeleton去变换顶点,通过addTransform函数将Vertex和bone绑定,Specification中给出了计算式子:
Denote the set of nodes (bones) associated with a vertex by { N1, N2, …, NN }.
Denote by Mi the transformation from the local coordinate system of node Ni to a reference coordinate system.
The choice of the reference coordinate system is not critical; depending on the implementation,
good choices may include the world coordinate system, the coordinate system of the SkinnedMesh node,
or the coordinate system of the current camera. Finally, let us denote the weight associated with node Ni as Wi.
The blended position of a vertex in the reference coordinate system is then:
- v‘ = sum [ wi Mi Bi v ]
其中,
- 0 <= i < N, 其中N 是和顶点v 关联的bone个数;
- v 是VertexBuffer中初始的顶点位置;
- Bi 是"at rest"变换,即从SkinnedMesh到顶点bone的初始变换矩阵,可以用Node.getTransformTo(bone, transform)取得;
- Mi 是当前顶点bone到参考坐标系的变换矩阵,我们取SkinnedMesh的坐标系,这样得到的是一个标准的Mesh,方便调用渲染;
- wi is the normalized weight of bone Ni, computed as wi = Wi / (W1 + … + WN).
Bi 在addTransform时,就可以得到,而Mi 则需要在渲染时获取,bone.getTransformTo(skinnedMesh, Mi) ,
注意对应的Normal变换有点不一样,不是直接的用Mi ,而需要用对应的inverse transpose矩阵:
n‘ = sum [ wi (Mi * Bi)-1T n ]