]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_animation.py
Check the flat qualifier from the correct member
[libs/gl.git] / blender / io_mspgl / export_animation.py
index e2c7733df69be358cd5e54029675a2caebc5361d..ba83cd490686069cb68b9f874c9fa2fc82add84c 100644 (file)
@@ -2,12 +2,8 @@ import math
 import os
 
 class AnimationExporter:
-       def __init__(self):
-               self.export_all = False
-               self.collection = True
-
-       def export_to_file(self, context, out_fn):
-               if self.export_all:
+       def export_to_file(self, context, out_fn, *, export_all=False, collection=True, looping_threshold=0.001):
+               if export_all:
                        actions = []
                        for o in context.selected_objects:
                                if not o.animation_data:
@@ -23,42 +19,36 @@ class AnimationExporter:
 
                        resources = {}
                        for a in actions:
-                               resources[a.name+".anim"] = self.export_animation(context, a)
+                               resources[a.name+".anim"] = self.export_animation(context, a, looping_threshold=looping_threshold)
 
                        path, base = os.path.split(out_fn)
                        base, ext = os.path.splitext(base)
 
-                       if self.collection:
-                               from .datafile import Statement
-                               with open(os.path.join(path, base+".mdc"), "w") as out_file:
-                                       for r in resources.values():
-                                               st = Statement("animation", r.name)
-                                               st.sub = r.statements
-                                               st.write_to_file(out_file)
+                       if collection:
+                               from .datafile import Resource
+                               dummy = Resource("dummy", "dummy")
+                               dummy.references = list(sorted(resources.values(), key=lambda r: r.name))
+                               dummy.write_collection(os.path.join(path, base+".mdc"), exclude_self=True)
                        else:
                                for r in resources.values():
-                                       with open(os.path.join(path, r.name), w) as out_file:
-                                               for s in r.statements:
-                                                       s.write_to_file(out_file)
+                                       r.write_to_file(os.path.join(path, r.name))
                else:
                        anim_data = context.active_object.animation_data
                        if not anim_data:
-                               raise Exception("Object has no animation data")
+                               raise Exception("Object {} has no animation data".format(context.active_object.name))
                        if not anim_data.action:
-                               raise Exception("No active action")
+                               raise Exception("Object {} has no active action".format(context.active_object.name))
 
                        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)
+                       resource.write_to_file(out_fn)
 
-       def export_animation(self, context, action):
+       def export_animation(self, context, action, *, looping_threshold=0.001):
                from .animation import create_animation_from_action
-               anim = create_animation_from_action(context, action)
+               anim = create_animation_from_action(context, action, looping_threshold=looping_threshold)
 
                from .datafile import Resource, Statement
-               resource = Resource(action.name+".anim")
+               resource = Resource(action.name+".anim", "animation")
 
                components = [(0, "location", "position"), (1, "rotation_euler", "euler"), (2, "scale", "scale")]
                coords = "xyz"
@@ -100,5 +90,7 @@ class AnimationExporter:
 
                        resource.statements.append(st)
 
+               resource.statements.append(Statement("looping", anim.looping))
+
                return resource