Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import json
  2.  
  3. # scene and camera data
  4. scene         = bpy.context.scene
  5. camera_curves = scene.objects['camera'].animation_data.action.fcurves
  6. target_curves = scene.objects['target'].animation_data.action.fcurves
  7.  
  8. # camera animation constants
  9. LOCATION_X = 0
  10. LOCATION_Y = 1
  11. LOCATION_Z = 2
  12.  
  13. # read out camera animation data
  14. camera_animation_frames = []
  15. for index in range(0, len(camera_curves[LOCATION_X].keyframe_points)):
  16.     camera_animation_frames.append({
  17.          # Read the frame_offset from the first element of the co vector. These
  18.          # are the same across all the properties, so we just pick from LOCATION_X.
  19.         'frame_index': camera_curves[LOCATION_X].keyframe_points[index].co[0],
  20.          # The properties value is sitting in the [1] element of the 'co' vector.
  21.          'properties': {
  22.             'position_x': camera_curves[LOCATION_X].keyframe_points[index].co[1],
  23.             'position_y': camera_curves[LOCATION_Y].keyframe_points[index].co[1],
  24.             'position_z': camera_curves[LOCATION_Z].keyframe_points[index].co[1],
  25.             'target_x':   target_curves[LOCATION_X].keyframe_points[index].co[1],
  26.             'target_y':   target_curves[LOCATION_Y].keyframe_points[index].co[1],
  27.             'target_z':   target_curves[LOCATION_Z].keyframe_points[index].co[1],
  28.         }
  29.     })
  30.  
  31. # write to parent
  32. data = json.dumps(camera_animation_frames, indent=2, sort_keys=True)
  33. file = open("../animation.json","w+")
  34. file.write(data)
  35. file.close()
  36. print(data)
  37. print('animation saved')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement