In X format this template within a mesh defines the vertices and weights influence of a particular bone.

template SkinWeights 
{
    STRING transformNodeName;            // Bone name
    DWORD nWeights;                      // The number of vertices affected by this bone
    array DWORD vertexIndices[nWeights]; // The vertices indices influenced by this bone
    array FLOAT weights[nWeights];       // The weights for each of the vertices influenced by this bone
    Matrix4x4 matrixOffset;              // The matrix transforms the mesh vertices to the space of the bone
}

The corresponding structure in glTF / glb is:

  "skins": [
    {
      "inverseBindMatrices": 0,
      "joints": [0, 1, 2, 3]
    }
  ],

Assuming we have a mesh with 4 bones and use row matrix style, the bone skinning transformation process of the vertices is as follows:

Matrix4x4 mBone[4];        // 4 bones world matrices
Matrix4x4 matrixOffset[4]; // inverse bind matrix from SkinWeights
float weight[4];           // bones weights array from SkinWeights
 
void skin_compute()        // gltf and X file formats have the same idea
{
    Matrix4x4 mSkin = matrixOffset[0] * mBone[0] * weight[0] +
                      matrixOffset[1] * mBone[1] * weight[1] +
                      matrixOffset[2] * mBone[2] * weight[2] +
                      matrixOffset[3] * mBone[3] * weight[3];
 
    vec4 pos_world = pos * mSkin;
}

Leave a Reply

Your email address will not be published. Required fields are marked *