Problem with exporting Blender's armature...

I’ve got really annoying problem with exporting Blender’s armature (skeleton) into my own file format, and then loading it and using in programs (games).

Problem is that each bone that has parent has coordinates in parent coordinates system. This parent coordinates system is defined by normal, which we get by tail minus head. And also we’ve got roll, so it’s not very nice… I want to translate all coordinates of all bones into world coordinates system. How to do that?

I don’t want any source files of other scripts (for example “Ogre” which I’ve got, but I don’t understand). Also don’t tell me to view Blender’s source code (I’ve tryied, with no result). I’ve posted a few messages on other forums, but without any reply. So I wish that there’s someone who can help me here, on elYsiun forum.

Given: An Armature.
I want: Head and Tail of Each Bone in World Coordinates.

Note: This might be the hard way. I also am a bit rusty on my matrices, and if the order should be vector * matrix or matrix * vector. If this doesn’t work, that would be the first thing I’d try to swap.


for bone_obj in arm_data.bones:
  p_bone_obj = bone_obj.getParent()
  if None == p_bone_obj:
    continue

  b_mtx = p_bone_obj.getMatrix('worldspace')
  b_head = bone_obj.getHead()
  b_tail = bone_obj.getTail()
  pos0 = Mathutils.Vector([b_head[0], b_head[1], b_head[2], 1.0])
  pos1 = Mathutils.Vector([b_tail[0], b_tail[1], b_tail[2], 1.0])

  b_head_wcs = Mathutils.VecMultMat(pos0, b_mtx)
  b_tail_wcs = Mathutils.VecMultMat(pos1, b_mtx)

Result:
The WCS for the head of the bone should be in b_head_wcs (as a Vector object).
The WCS for the tail of the bone should be in b_tail_wcs (as a Vector object).

-If you use m = getRestMatrix() (by default in world space) then
m[3][0],m[3][1] and m[3][2] gives the location of the bone(head)
in worldspace.For the roll…??? mabe by adding all parent’s roll
Ben

Thanks, wyndam, everything went smoothly, now I can write that damn exporter :stuck_out_tongue:

There’s one problem in your code: there’s no such function as ‘getMatrix’ in bone object. It’s not big problem, becouse such function exists but has other name: ‘getRestMatrix’. The Blender’s API documentation is were I’ve got it from :wink:

seya!

Yeah – getRestMatrix() was the correct answer. :slight_smile: