Trying to get access to bone pose info.

I want to get the x location of a bone pose relative to its rest position. I’ve read the pose module info at

http://www.blender.org/documentation/245PythonDoc/Pose-module.html

but it’s a bit beyond my current Python ability. Could someone give me a line of code (or even the correct command to use) to point me in the right direction?

cheers,
n

I’m not sure if this helps you, but…
THis is what we use in our game engine. The thing is, we haven’t actually used this code for about a year, since our latest game used no skeletal animation - but I know it USED TO WORK…

this code snippet works on a list of bones, iterating currentbone.
It retrieves the RestMatrix (the matrix that takes the bone from rest into current position, and it does so in bone space, which is its parents space).
Then it breaks it down into a translation and rotation quaternion (axis-angle) although you could just use the restmatrix as is.


mymat = Mathutils.Matrix(currentbone.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])
radianangle = Quatty.angle * (pi / 180.0)

Thanks so much for that Vek. I was using this for an animation project but I’m sure it will help me.
cheers,
n

Where does ‘currentbone’ come from?

Is ‘objectdatalist’, just an empty / user defined list ?

Mike

objectdatalist is just a user list that we then write to file. currentbone would just be an iteration over all the bones of the object…

I have a feeling that some of this code does not work any more due to the armature / pose changes done to the blender/Python API :frowning:

Here is a guess (only a guess) about what would be changed for the new API:

like I guess that in the new API it would be something like (given an Armature armature_object):


for currentbone in armature_object.bones.values():
   # do stuff, using currentbone.matrix['BONESPACE'] instead of getRestMatrix

see the http://www.blender.org/documentation/245PythonDoc/Armature.Bone-class.html for the operations on the bone class

alternatively, given an armature object, arm_ob, you could call arm_ob.getPose().bones.values() to get a sequence of Armature Pose Bones instead of just Bones…
http://www.blender.org/documentation/245PythonDoc/Pose.PoseBone-class.html
Pose Bones appear to only keep the differences between their rest state and their position at a given keyframe, though - not the actual collapse matrix.

If you need to export more than keyframes you might have to use blender to interpolate the frames for you (ie, set frame to 1, export all the positions and rotations, set frame to 2, export all positions rotations, etc)