tags:

views:

196

answers:

1

I'm trying to export animation from blender, here's what I've done so far:
--- This is just to give you an idea of what I'm doing and I've left out a lot to keep it short.
--- If it's too confusing or if it's needed I could post the whole source.

# Get the armature  
arm = ob.getData()  
# Start at the root bone  
for bone in bones:  
    if not bone.parent:  
        traceBone(bone)  

def traceBone(bone):
  # Get the channel for this bone
  channel=action.getChannelIpo(bone.name);

  # Get the loc x, y, z channels
  c_locx=channel[Ipo.OB_LOCX].bezierPoints
  frameCount=len(c_locx)

  # Write each location frame
  for frameIndex in  range(frameCount):
    frame_x=c_locx[frameIndex].pt
    frameTime=int(frame_x[0]-1)
    # Write the time of the frame
    writeInt(frameTime)
    # Write the x, y and z coordinates
    writeFloats(frame_x[1], frame_z[1], frame_y[1])

  # Iv'e done the same for rotation
  c_quatx=channel[Ipo.PO_QUATX].bezierPoints
  # Write the quaternion w, x, y and z values
  writeFloats(frame_w[1], frame_x[1], frame_z[1], frame_y[1])

  # Go through the children
  for child in bone.children:
    traceBone(child)

As far as I can tell this all works fine, the problem is that these values are offsets, representing change, but what I need is absolute values representing the location and rotation values of the bone relative to it's parent.

How do I get the position and rotation relative to it's parent?

+1  A: 

The channel data should be applied on top of the bind pose matrix.

The complete formula is the following:

Mr = Ms * B0*P0 * B1*P1 ... Bn*Pn

where:

Mr = result matrix for a bone 'n'

Ms = skeleton->world matrix

Bi = bind pose matrix for bone 'i'

Pi = pose actual matrix constructed from stored channels (that you are exporting)

'n-1' is a parent bone for 'n', 'n-2' is parent of 'n-1', ... , '0' is a parent of '1'

kvark