Blender - creating bones from transform matrices

Posted by user975135 on Game Development See other posts from Game Development or by user975135
Published on 2012-07-08T15:24:13Z Indexed on 2012/07/08 21:23 UTC
Read the original article Hit count: 261

Filed under:
|
|

Notice: this is for the Blender 2.5/2.6 API.

Back in the old days in the Blender 2.4 API, you could easily create a bone from a transform matrix in your 3d file as EditBones had an attribute named "matrix", which was an armature-space matrix you could access and modify.

The new 2.5+ API still has the "matrix" attribute for EditBones, but for some unknown reason it is now read-only.

So how to create EditBones from transform matrices? I could only find one thing: a new "transform()" function, which takes a Matrix too.

Transform the the bones head, tail, roll and envelope (when the matrix has a scale component).

Perfect, but you already need to have some values (loc/rot/scale) for your bone, otherwise transforming with a matrix like this will give you nothing, your bone will be a zero-sized bone which will be deleted by Blender.

if you create default bone values first, like this:

bone.tail = mathutils.Vector([0,1,0])

Then transform() will work on your bone and it might seem to create correct bones, but setting a tail position actually generates a matrix itself, use transform() and you don't get the matrix from your model file on your EditBone, but the multiplication of your matrix with the bone's existing one. This can be easily proven by comparing the matrices read from the file with EditBone.matrix.

Again it might seem correct in Blender, but now export your model and you see your animations are messed up, as the bind pose rotations of the bones are wrong.

I've tried to find an alternative way to assign the transformation matrix from my file to my EditBone with no luck.

© Game Development or respective owner

Related posts about matrix

Related posts about python