Edit (Original post below):
So I have come up with the following code. I can export the mesh, bone structure and animations. I can animate a simple skeleton. But for some reason if I animate more than one bone, something goes wrong and the arm will move in the wrong axis.
My cpp code is here: http://kyuu.co.uk/so/main.cpp
My python export code is here: http://kyuu.co.uk/so/test.py
Could someone please tell me what I am doing wrong? I think it might be something to do with the bone roll in blender. I have seen many posts about that.
Thanks.
(Original post:)
I have been working on this problem for a while now and still cannot figure out what I am missing, so I am hoping someone kind will help me :3
Right, I have something like the following code in my application:
class bone {
bone * child;
Eigen::Matrix4f local_bind_pose; // this i read from a file
Eigen::Matrix4f final_skinning_matrix; // i then transform each vertex by this matrix
// temporary variables
Eigen::Matrix4f inv_bind_pose;
Eigen::Matrix4f world_bind_pose;
}
I.e. a simple bone hierarchy.
I believe I can work out the inv_bind_pose
with:
world_bind_pose = bone.parent.world_bind_pose * local_bind_pose
inv_bind_pose = world_bind_pose.inverse()
I know that the bind_pose
must be relative to the parent bone.
I know that blender is z = up and I am using y = up.
But I cannot get this information exported from blender. I am using version 2.56.3.
Would the rotation part of the matrix be bone.matrix_local
? Would the translation part be bone.tail() - bone.head()
?
What about bone roll? It seems that does affect the result.
Some references:
http://www.gamedev.net/topic/571044-skeletal-animation-bonespace
http://www.blender.org/development/release-logs/blender-240/how-armatures-work
Thank-you so much!