X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=blender%2Fio_mspgl%2Fexport_animation.py;fp=blender%2Fio_mspgl%2Fexport_animation.py;h=b990e054ff0c8b8196207a1c1ef7c65e728eaf1d;hb=f2cab83d5704f3f4a91f551f402187637e5063d2;hp=0000000000000000000000000000000000000000;hpb=553f3ec4fbe28a37978ee53b9b6e22fedb691e1d;p=libs%2Fgl.git diff --git a/blender/io_mspgl/export_animation.py b/blender/io_mspgl/export_animation.py new file mode 100644 index 00000000..b990e054 --- /dev/null +++ b/blender/io_mspgl/export_animation.py @@ -0,0 +1,65 @@ +import math + +class AnimationExporter: + def export_to_file(self, context, out_fn): + anim_data = context.active_object.animation_data + if not anim_data: + raise Exception("Object has no animation data") + if not anim_data.action: + raise Exception("No active action") + + resource = self.export_animation(context, anim_data.action) + + with open(out_fn, "w") as out_file: + for s in resource.statements: + s.write_to_file(out_file) + + def export_animation(self, context, action): + from .animation import create_animation_from_action + anim = create_animation_from_action(context, action) + + from .datafile import Resource, Statement + resource = Resource(action.name+".anim") + + components = [(0, "location", "position"), (1, "rotation_euler", "euler"), (2, "scale", "scale")] + coords = "xyz" + prev_time = 0.0 + for k in anim.keyframes: + if k.time>prev_time: + resource.statements.append(Statement("interval", k.time-prev_time)) + prev_time = k.time + + st = Statement("control_keyframe" if k.control else "keyframe") + + transform = [0.0]*9 + mask = 0 + for c, i in k.curves: + for j, dp, kw in components: + if c.data_path==dp: + transform[j*3+c.array_index] = c.knots[i][1] + mask |= 1<<(j*3+c.array_index) + break + + if mask: + ss = Statement("transform") + + for i, dp, kw in components: + v = transform[i*3:i*3+3] + if i==1: + v = [c*180/math.pi for c in v] + + m = 7<<(i*3) + if (mask&m)==m: + ss.sub.append(Statement(kw, *v)) + else: + m &= m>>2 + for j in range(3): + if mask&(m<