I'm working on a project which requires me to export all keyframes for 1 object (the camera) in a "generated" state, meaning all the control points as well as all the keyframes generated by the interpolation.

I'm not too familiar with python, and this is my first time using the blender API. Is there any way to do this?

Code so far:

import bpy
import mathutils
action = bpy.data.objects['Camera'].animation_data.action
for curve in action.fcurves:
    for i in range(len(curve.keyframe_points)):
        point = curve.keyframe_points[i]
        print(mathutils.geometry.interpolate_bezier(point.co, point.handle_left, point.handle_right, point.co, 100)) # I know the second knot probably shouldn't be point.co here, but I don't know what to make it.

This has the drawback of point.co only being a Vec2, so it only has x and y, and it doesn't account for whatever the set interpolation type is (I could only find the bezier func). I might be thinking through things wrongly though.'

EDIT: New code, although a bit hacky, is better. It seems to provide what I need

import bpy
import mathutils
scn = bpy.context.scene
obj = bpy.data.objects['Camera']
action = obj.animation_data.action
for frame in range(scn.frame_start, scn.frame_end):
  • $\begingroup$ Hi and welcome! To which file format you'd like to export? FYI: alembic does a good job usually... Or just a plain text file? If so, how the data should be formatted? Also do you'd like to export key frames only or all frames baked? Recommend add a blend file to your question, preferably using blend-exchange.giantcowfilms.com $\endgroup$ – brockmann Jan 11 at 17:43
  • $\begingroup$ Thanks for the reply @brockmann, there isn't really a specific blend file for this, just make a simple animation with the camera and it suffices. As for storing the data, I was just planning on making a simple binary format for it, but right now I'm just interested in getting the data in a python script before worrying about having to save it. I should've worded it better, I don't need the user-defined keyframes, I need the baked frames that are animated in the final render. Specifically I only need xyz locations and rotations for each frame. What is alembic? $\endgroup$ – PepegaClapWR Jan 11 at 17:54
  • $\begingroup$ Added new code, it seems to provide what I need $\endgroup$ – PepegaClapWR Jan 11 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.