Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I am looking for help on how to export armatures and their animations in a custom export script.

I wish to have an animation format similar to BVH, i.e. a bunch of [Xposition Yposition Zposition] Xrotation Yrotation Zrotation for each bone for each keyframe.

Given the model (which exports fine using the bvh exporter), how does one get the keyframe data? A long time searching the object tree of bpy has left me somewhat baffled.

share|improve this question
    
Welcome to the site :) Tutorial requests are considered off topic here. If you are looking for a tutorial, then youtube or Blender Artists would be a better place to look. If you have a specific question like "How to access keyframe data with python", then this is the place. –  gandalf3 Apr 7 at 20:26
    
Noted. Any help would be appreciated (not necessarily full tutorials). My question is basically what you stated "How to access keyframe data with python", as I can do the rest. –  rspencer Apr 7 at 20:29

1 Answer 1

up vote 4 down vote accepted

A common way to get the animation data is to loop over the scene's frame range and read the matrices for every single frame. This is okay most of the time, and way easier to do than reading the F-Curve data directly (which won't include F-Curve modifiers and Drivers AFAIK).

Assume the Armature object is currently active:

import bpy

sce = bpy.context.scene
ob = bpy.context.object

for f in range(sce.frame_start, sce.frame_end+1):
    sce.frame_set(f)
    print("Frame %i" % f)

    for pbone in ob.pose.bones:
        print(pbone.name, pbone.matrix) # bone in object space

bpy.types.PoseBone.matrix

You may use the utility function convert_space to avoid fancy matrix math.

share|improve this answer
    
Precisely what I was after. Thanks. –  rspencer Apr 8 at 7:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.