Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- # scene and camera data
- scene = bpy.context.scene
- camera_curves = scene.objects['camera'].animation_data.action.fcurves
- target_curves = scene.objects['target'].animation_data.action.fcurves
- # camera animation constants
- LOCATION_X = 0
- LOCATION_Y = 1
- LOCATION_Z = 2
- # read out camera animation data
- camera_animation_frames = []
- for index in range(0, len(camera_curves[LOCATION_X].keyframe_points)):
- camera_animation_frames.append({
- # Read the frame_offset from the first element of the co vector. These
- # are the same across all the properties, so we just pick from LOCATION_X.
- 'frame_index': camera_curves[LOCATION_X].keyframe_points[index].co[0],
- # The properties value is sitting in the [1] element of the 'co' vector.
- 'properties': {
- 'position_x': camera_curves[LOCATION_X].keyframe_points[index].co[1],
- 'position_y': camera_curves[LOCATION_Y].keyframe_points[index].co[1],
- 'position_z': camera_curves[LOCATION_Z].keyframe_points[index].co[1],
- 'target_x': target_curves[LOCATION_X].keyframe_points[index].co[1],
- 'target_y': target_curves[LOCATION_Y].keyframe_points[index].co[1],
- 'target_z': target_curves[LOCATION_Z].keyframe_points[index].co[1],
- }
- })
- # write to parent
- data = json.dumps(camera_animation_frames, indent=2, sort_keys=True)
- file = open("../animation.json","w+")
- file.write(data)
- file.close()
- print(data)
- print('animation saved')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement