I'm trying to work out skeletal animation using Assimp (Open Asset Import Library). Right now I can successfully load a .dae model and render it with animation, but in the process of doing so the model gets messed up.
https://i.stack.imgur.com/ucWLk.png
The left model is not rigged and loaded properly. The model to the right is rigged and takes the correct pose from the animation but gets distorted weirdly (flat stick-figure~).
My take on it is that I probably do something wrong through the bone matrix multiplications.
the final matrices(let's call them M) are calculated as follows:
M[i] = transform_matrix[i] * scene->mRootNode->mTransformation * offset_matrix[i]
where offset_matrix[i]
is the combined offset matrix from the concatenation of aiBone->mOffsetMatrix
, and transform_matrix[i]
is the combined transform matrix from the concatenation of matrices from aiNodeAnim
TRS.
Respective concatenations are done from the bottom and up to the root.
while(node!=NULL){
mOffset = loadRelativeOffset(node, scene) * mOffset
node = node->mParent;
}
offset_matrix.push_back(mOffset);
loadRelativeOffset(node, scene)
will loop through scene->mMeshes[0]->mNumBones
and return the matrix of matched aiBone
. If no bone is found, the identity matrix will be returned. As such the end result will be a concatenation of all the bone matrices, ignoring Armature and the root node.
Loading the transform matrix is done in a similar fashion but with aiNodeAnim
in mNumChannels
instead of aiBones
in mNumBones
.
I imagine the end result looks something like this:
M = Arm * Hand * Finger * RootNode * Offset_Arm * Offset_Hand * Offset_Finger;
I don't know why the RootNode matrix is there, but if it is not there everything looks like nonsense.
Any idea what causes this, or what I can do?