Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This is for the Blender 2.6 API.

There are two problems:

1. When I import a single animation frame from my animation file to Blender, all bones look fine. But when I import multiple (all of the frames), just the first one looks right, seems like newer frames are affected by older ones, so you get slightly off positions/rotations.

This is true when both assigning PoseBone.matrix and PoseBone.matrix_basis.

bone_index = 0

# for each frame:
for frame_index in range(frame_count):
    # for each pose bone: add a key
    for bone_name in bone_names: # "bone_names" - a list of bone names I got earlier
        pose.bones[bone_name].matrix = animation_matrices[frame_index][bone_index] # "animation_matrices" - a nested list of matrices generated from reading a file

        # create the 'keys' for the Action from the poses
        pose.bones[bone_name].keyframe_insert('location', frame = frame_index+1)
        pose.bones[bone_name].keyframe_insert('rotation_euler', frame = frame_index+1)
        pose.bones[bone_name].keyframe_insert('scale', frame = frame_index+1)

        bone_index += 1

    bone_index = 0

Again, it seems like previous frames are affecting latter ones, because if I import a single frame from the middle of the animation, it looks fine.

2. I can't assign armature-space animation matrices read from a file to a skeleton with hierarchy (parenting).

In Blender 2.4 you could just assign them to PoseBone.poseMatrix and bones would deform perfectly whether the bones had a hierarchy or none at all.

In Blender 2.6, there's PoseBone.matrix_basis and PoseBone.matrix. While matrix_basis is relative to parent bone, matrix isn't, the API says it's in object space. So it should have worked, but doesn't. So I guess we need to calculate a local space matrix from our armature-space animation matrices from the files. So I tried multiplying it ( PoseBone.matrix ) with PoseBone.parent.matrix.inverted() in both possible orders with no luck, still weird deformations.

share|improve this question
I would flag this for migration to, but it's too old –  Pip Aug 5 '13 at 16:44

1 Answer 1

The matrix_basis of a pose bone is the transform required to go from the bind pose to the current pose, in parent relative space. It's NOT the final matrix that you want.

pose_bone.matrix_basis = bind_matrix.inverted() * animation_matrix

Both bind_matrix and animation_matrix in the above example are in parent relative space.

share|improve this answer
My animation_matrix (the one from the file) is in armature space, so the above code gives wrong results... When there is no parent relation, it looks fine, except still has the problem #1. –  user17402 Jul 11 '12 at 12:14
I can post a video example of the problem (wrong on in Blender and correct one in game engine) –  user17402 Jul 12 '12 at 17:51
Solution for problem #1 seems to be using keyframe_insert('rotation_quaternion') instead. Still can't fix problem # 2. –  user17402 Jul 13 '12 at 11:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.