How do I apply skeletal animation from a .x (Direct X) file?
Posted
by
Byte56
on Game Development
See other posts from Game Development
or by Byte56
Published on 2012-09-03T05:37:05Z
Indexed on
2012/09/03
9:50 UTC
Read the original article
Hit count: 334
Using the .x format to export a model from Blender, I can load a mesh, armature and animation. I have no problems generating the mesh and viewing models in game. Additionally, I have animations and the armature properly loaded into appropriate data structures.
My problem is properly applying the animation to the models. I have the framework for applying the models and the code for selecting animations and stepping through frames.
From what I understand, the AnimationKey
s inside the AnimationSet
supplies the transformations to transform the bind pose to the pose in the animated frame. As small example:
Animation {
{Armature_001_Bone}
AnimationKey {
2; //Position
121; //number of frames
0;3; 0.000000, 0.000000, 0.000000;;,
1;3; 0.000000, 0.000000, 0.005524;;,
2;3; 0.000000, 0.000000, 0.022217;;,
...
}
AnimationKey {
0; //Quaternion Rotation
121;
0;4; -0.707107, 0.707107, 0.000000, 0.000000;;,
1;4; -0.697332, 0.697332, 0.015710, 0.015710;;,
2;4; -0.684805, 0.684805, 0.035442, 0.035442;;,
...
}
AnimationKey {
1; //Scale
121;
0;3; 1.000000, 1.000000, 1.000000;;,
1;3; 1.000000, 1.000000, 1.000000;;,
2;3; 1.000000, 1.000000, 1.000000;;,
...
}
}
So, to apply frame 2, I would take the position, rotation and scale from frame 2, create a transformation matrix (call it Transform_A
) from them and apply that matrix the vertices controlled by Armature_001_Bone
at their weights. So I'd stuff TransformA
into my shader and transform the vertex. Something like:
vertexPos = vertexPos * bones[ int(bfs_BoneIndices.x) ] * bfs_BoneWeights.x;
Where bfs_BoneIndices
and bfs_BoneWeights
are values specific to the current vertex.
When loading in the mesh vertices, I transform them by the rootTransform
and the meshTransform
. This ensures they're oriented and scaled correctly for viewing the bind pose.
The problem is when I create that transformation matrix (using the position, rotation and scale from the animation), it doesn't properly transform the vertex. There's likely more to it than just using the animation data. I also tried applying the bone transform hierarchies, still no dice. Basically I end up with some twisted models. It should also be noted that I'm working in openGL, so any matrix transposes that might need to be applied should be considered.
What data do I need and how do I combine it for applying .x animations to models?
© Game Development or respective owner