3 class AnimationExporter:
4 def export_to_file(self, context, out_fn):
5 anim_data = context.active_object.animation_data
7 raise Exception("Object has no animation data")
8 if not anim_data.action:
9 raise Exception("No active action")
11 resource = self.export_animation(context, anim_data.action)
13 with open(out_fn, "w") as out_file:
14 for s in resource.statements:
15 s.write_to_file(out_file)
17 def export_animation(self, context, action):
18 from .animation import create_animation_from_action
19 anim = create_animation_from_action(context, action)
21 from .datafile import Resource, Statement
22 resource = Resource(action.name+".anim")
24 components = [(0, "location", "position"), (1, "rotation_euler", "euler"), (2, "scale", "scale")]
27 for k in anim.keyframes:
29 resource.statements.append(Statement("interval", k.time-prev_time))
32 st = Statement("control_keyframe" if k.control else "keyframe")
37 for j, dp, kw in components:
39 transform[j*3+c.array_index] = c.knots[i][1]
40 mask |= 1<<(j*3+c.array_index)
44 ss = Statement("transform")
46 for i, dp, kw in components:
47 v = transform[i*3:i*3+3]
49 v = [c*180/math.pi for c in v]
53 ss.sub.append(Statement(kw, *v))
58 ss.sub.append(Statement("{}_{}".format(kw, coords[j]), v[j]))
62 resource.statements.append(st)