[Bf-python] Possible bug in the creation of the Matrices of bones in Bonespace

Nick Lawson vektuz at cox.net
Fri Feb 4 00:43:53 CET 2005


Greetings!

I'm busy writing an animation script and exporter for a game project.
Currently, the problem is the bone local matrices.  What most games need,
when they talk about the matrix of a bone (in bonespace), is the rotation
and translation relative to the parent.  Most skeletons (like human body,
joints, etc) never have any translation along Z and X, only along Y (the
size of the bone).

In other works, if a figure is dancing or moving their arms about, the
rotation of the bones should change but never, ever, the translation, since
that would equate to a joint popping out, sliding around.  You bend your
elbow as a rotation, not a translation.  I'm sorry if this is obvious, but
it introduces the following.

Initial pose
http://members.cox.net/vexgames/rotationproblem1.gif

Animated to this, via rotation:
http://members.cox.net/vexgames/rotationproblem2.gif

You can clearly see that the effect being applied is a rotation of a bone,
not a translation.  Mathematically, as well as visibly, the bone is rotated.
Additional evidence is that the vertices attached to the bone are rotated
around the bone.  Additionally, the Y axis of the bone is rotated.

The bonespace matrix for that particular bone, therefore, should be a 90
degree rotation along the Z axis.

I output them like this (For each bone in the armature)

objectdatalist = [bone.name]
mymat = bone.getRestMatrix('bonespace')
TransMat = mymat.translationPart()
RotMat = mymat.rotationPart()
Quatty = RotMat.toQuat()	
objectdatalist.append(TransMat.x)
objectdatalist.append(TransMat.y)
objectdatalist.append(TransMat.z)
objectdatalist.append(Quatty.axis[0])
objectdatalist.append(Quatty.axis[1])
objectdatalist.append(Quatty.axis[2])
objectdatalist.append(Quatty.angle)
print "%10s  %8.5f %8.5f %8.5f  %8.5f %8.5f %8.5f %8.7f" %
(objectdatalist[0],objectdatalist[1],objectdatalist[2],objectdatalist[3],obj
ectdatalist[4],objectdatalist[5],objectdatalist[6],objectdatalist[7])

And the results are as pictured.  The straight line of bones looks like
this:
http://members.cox.net/vexgames/rotationproblem1_output.gif
(This result is correct - the format is 
NAME, X, Y, Z, AXIS X, AXIS Y, AXIS Z, ANGLE

Then, I output the rotated one:
http://members.cox.net/vexgames/rotationproblem2_output.gif
(This Result is where the problem lies)

There are two problems with this.  Firstly, no rotations show up.  In fact,
manipulation of joints never show up as rotations from GetRestMatrix, when
almost all of them should ONLY show up as rotations (and a translation along
Y).

Secondly, after that bone has been rotated 90 degrees, if the matrix really
were in bonespace, the rest of the bones down the chain should resume their
one unit Y axis translation.  Instead, they say they are translated one unit
along the X axis instead, showing that they are NOT being represented in
bonespace.  The picture:

http://members.cox.net/vexgames/rotationproblem2.gif

...makes it clear that after the one bone has been rotated 90 degrees, the
rest of them clearly extend one unit along their local Y axis, not the X
axis.

I guess my questions are thus:

1.  Is this a bug in blender/pose?  Or am I simply using the wrong function
here?  I need the translation and rotation of the bone, in bonespace, (which
is the coordinate system of its parent), and I figured
GetRestMatrix('bonespace') would be exactly that.

2.  Is there a way around this?

And 
3.  Is this the right place to post these kind of python questions/bugs?

-Nick Lawson
vektuz at cox.net
Iocaine Studios

PS... Come see our game at GDC 2005, we'll have a booth there...  We intend
to release all blender-python tools we use to make our scenes, publicly,
too... go blender!





More information about the Bf-python mailing list