Posted: Tue May 29, 2012 1:17 am
Joined: 08 Jan 2012
Posts: 11
I'm trying to figure out a way to export animation keyframes for each individual action in a scene. My current method is to find each keyframe for each action, set the pose to that key, and export the current pose bone transforms. It doesn't work though. I can't get the pose bones to change when I change the frame.
I have searched the forums and found solutions, but they don't work for me. I think it's probably because I'm running the script from the command line rather than in an existing instance of Blender.
Here's my code so far:
| Code: |
for action in bpy.data.actions:
ob.animation_data.action = action
bpy.ops.object.mode_set(mode="POSE")
bpy.ops.pose.select_all(action="SELECT")
bpy.ops.pose.transforms_clear()
# get all frame numbers in this action
frames = dict()
for fcurve in action.fcurves:
for key in fcurve.keyframe_points:
frame = key.co.x
frames[frame] = 1
for f in sorted(frames):
bpy.context.scene.frame_set(f)
# (read pose bone data here) |
Posted: Tue May 29, 2012 2:16 am
Joined: 05 Apr 2009
Posts: 680
you should use print() for some debug output, to see what values your variables hold, maybe there's a problem
run Blender via cmd to see the print output
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Posted: Tue May 29, 2012 5:20 am
Joined: 08 Jan 2012
Posts: 11
Mmhmm, I did that. It is able to get all the correct pose bones, actions, and frame numbers. It's just that setting the frame with bpy.context.scene.frame_set has no effect on the pose bones.
Posted: Tue May 29, 2012 6:51 pm
Joined: 05 Apr 2009
Posts: 680
that's weird...
you may try
bpy.context.scene.update()
after changing frame
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Posted: Wed May 30, 2012 1:26 am
Joined: 08 Jan 2012
Posts: 11
I just gave it a try. Didn't work.
Posted: Thu May 31, 2012 4:21 am
Joined: 08 Jan 2012
Posts: 11
Solved. My previous code works. The problem was that matrix_basis, rotation_euler, rotation_quaternion, and rotation_axis_angle in PoseBone are always set to the identity transform. (Why would they do that?!) So, instead, I have to use this to get the transform for each frame:
| Code: |
def getPoseBoneLocalMatrix(poseBone):
if poseBone.parent is None:
return poseBone.matrix
else:
return poseBone.parent.matrix.inverted() * poseBone.matrix |