Skinning
The process of attaching the vertices of a 3D mesh to a posed skeleton is known as "Skinning".
Each vertex can be bound to one or more joints.
The vertex's positions is a weighted average of the positions it would have assumed if it had been bound to each joint independently.
At each vertex, you ned to have the following information:
- The index or indices of the
Joint
s to which it is bound, - The weighting factor describing how much influence that joint should have on the final vertex position.
Tracking mesh vertices to joints
A skinning matrix
is a matrix that can transform the vertices of a mesh from bind pose into new positions that correspond to the current pose of the skeleton.
The position of a skinned vertex is specified in model space, like all mesh vertices.
Unlike other matrix transforms, a skinning matrix is NOT a change of basis transform: it goes from model space (bind pose) to model space (actual pose)
Given the bind pose of the joint j in model space, Bj→M, this matrix transforms a point whose coordinates expressed in j's space into an equivalent set of model-space coordinates.
Then, given a vertex whose coordinates are expressed in model-space, if you want to express it in joint-space, you can do so with the inverse of the above bind pose matrix.
→vj=→vBMBM→j=→vBM(Bj→M)−1
Given a joint's current pose, similar to the bind pose matrix, it defines vertices in joint space in model space, i.e., Cj→M.
→vCM=vjCj→M=→vBM(Bj→M>)−1Cj→M=→vBMKj
Where
- Kj=→vBM(Bj→M>)−1Cj→M
- This Kj is known as the skinning matrix.
When you have multiple joints, it can be useful to create an array of skinning matrices Kj for every joint.
Bj→M matrices never change so can be calculated once per vertex. The current poses Cj→M change on each frame and will therefore need to be calculated on the fly.
Don't forget that a single matrix from joint space to model space represents a global pose, meaning for a given joint, you have to walk up its local pose matrices to the root joint to create either Bj→M or Cj→M.
When multiple joints per vertex are involved
Calculate a new vector for each joint individually, then average all the vectors together.
→vCM=N−1∑i=0wi→vBMKji
Where
- N is the number of joints associated with vertex →v.
- wi is the weighting factor of joint i.
- Kji is the skinning matrix for joint ji.