Hello,
while implementing skinning support to my engine and therefore my mesh file format, I'm down to one problem: The inverse bind pose matrices (at least of my test model) don't match with what would be needed to render it correctly. I've converted the Tiny.x - mesh from the DirectX9-SDK to my own mesh format, and I've verified up until now that all data is 100% matching, minus the bind pose/offset matrix.
I am calculating the matrix by traversing the bone hierachy, and then inversing the absolute transform of each bone:
void MeshSkeleton::ProcessSkeleton(void)
{
m_vMatrices.clear();
size_t numBone = 0;
ProcessBone(m_root, nullptr, numBone);
}
void MeshSkeleton::ProcessBone(Bone& bone, Bone* pParent, size_t& numBone)
{
if(pParent)
bone.mAbsolute = bone.mRelative * pParent->mAbsolute;
else
bone.mAbsolute = bone.mRelative;
// in case the inverse bind poses have already been calculated, output the final bone matrix
if(!m_vInvBindPoses.empty())
m_vMatrices.push_back(m_vInvBindPoses[numBone] * bone.mAbsolute);
else
m_vMatrices.push_back(math::MatIdentity());
numBone++;
for(auto& child : bone.m_vChildren)
{
ProcessBone(child, &bone, numBone);
}
}
void MeshSkeleton::CalculateBindPoses(void)
{
m_vInvBindPoses.clear();
CalculateBindPose(m_root);
}
void MeshSkeleton::CalculateBindPose(Bone& bone)
{
m_vInvBindPoses.push_back(bone.mAbsolute.inverse());
for(auto& child : bone.m_vChildren)
{
CalculateBindPose(child);
}
}
First, ProcessSceleton is called, then CalculateBindPoses. The absolute matrices are identically to those of the Tiny.x-mesh when loaded in the sample, so there should be no problem here. However, when I look at the offset matrices from the sample:
// get each of the bone offset matrices so that we don't need to get them later
for( iBone = 0; iBone < cBones; iBone++ )
{
pMeshContainer->pBoneOffsetMatrices[iBone] = *( pMeshContainer->pSkinInfo->GetBoneOffsetMatrix( iBone ) );
}
They aren't even similiar to mine in any way shape or form (I checked the correct bones).
Now I can fix this by storing the offset matrix from pSkinInfo in the mesh file and load them with the file (that way the animation works correctly), but I am wondering about the reasoning behind this. Is there some error in my calculations? Or is the offset-matrix calculated differently in the DirectX9-file format?