Created
December 7, 2011 15:58
-
-
Save tamask/1443309 to your computer and use it in GitHub Desktop.
Export Blender Actions (.json)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import json | |
json.encoder.c_make_encoder = None | |
json.encoder.FLOAT_REPR = lambda o: format(o, '.6f') | |
actions = [] | |
for action in bpy.data.actions: | |
a = { | |
'name': action.name, | |
'range': list(action.frame_range), | |
'groups': [], | |
} | |
for group in action.groups: | |
g = { | |
'name': group.name, | |
'channels': [], | |
} | |
for fcurve in group.channels: | |
c = { | |
'path': fcurve.data_path, | |
'index': fcurve.array_index, | |
'points': [], | |
} | |
for point in fcurve.keyframe_points: | |
p = { | |
'a': list(point.handle_left), | |
'b': list(point.handle_right), | |
'co': list(point.co), | |
'lerp': point.interpolation.lower(), | |
} | |
c['points'].append(p) | |
g['channels'].append(c) | |
a['groups'].append(g) | |
actions.append(a) | |
print(json.dumps(actions)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment