Philosophy of bone matrices (and scale)

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

damix
Posts: 21
Joined: Wed Dec 07, 2011 4:42 pm

Philosophy of bone matrices (and scale)

Postby damix » Mon Aug 13, 2012 7:24 pm

(Sorry, long post with quite a lot of background information)

Hi everybody, I'm writing an armature/animation exporter for my personal OpenGL ES engine and I would like to match Blender behaviour as closely as possible. Before tackling the problem of vertex deformation, I would like to be able to draw the armature exactly as it appears in Blender, and animate it accordingly using the exported data.

I would like to draw the armature bone by bone, in a hierarchical fashion; I have a routine that draws a bone in the same space as the untrasformed Blender bone; when you add a "vertical" bone to an armature the bpy.types.Bone.matrix is not the 3x3 identity; if you rotate the bone such that the tail points in the positive-y direction, then you get the identity; I'm assuming this is the standard position for a bone in Blender, and the editor creates a rotated version only for convenience on the side of the artist.

Well, in my engine I have a routine, let's call it DrawBone() that draws the bone exactly in this way, with the tail pointing in the positive-y. For each bone Bi in Blender I would like to export a transformation Ti such that if I multiply the current transform by Ti before drawing Bi:

Code: Select all

MultiplyTransform(Ti)
DrawBone()


Then Bi appears exactly as it is in Blender. The current transformation is the transformation of the parent bone or it is the identity for root bones. I don't care about the location, rotation and scale of the armature object itself for now.

Now, the questions:

1) Does the Blender Python API expose something like Ti for each bone Bi? In particular, none of the properties of bpy.types.Bone seems to be affected by scale. I am aware that the concept of scale is not defined for Bone and EditBone, but only for PoseBone. However to me it looks like the distance between head and tail is, in some way, a sort of scale, and it does not seem to affect any of the Bone internal data.

2) Is it unreasonable to try to draw an armature without relying on bone lengths? The way I'm seeing it bone lengths are not really necessary; the standard bone is a unit length thingy, lying on the positive-y axis. If I want to make it longer or shorter I only need to include a scale factor into its bone matrix. For a child bone the scale would be defined relatively to the size of the parent, i.e. if the child is half the length of the parent it would include a scale factor of 1/2.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests