X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fexport_animation.py;h=90d5d4125197d0557741febe92eb75d311181778;hb=c3ebbcb56c1ca9bb3022a7f49aab1da5e09150ba;hp=b990e054ff0c8b8196207a1c1ef7c65e728eaf1d;hpb=f2cab83d5704f3f4a91f551f402187637e5063d2;p=libs%2Fgl.git diff --git a/blender/io_mspgl/export_animation.py b/blender/io_mspgl/export_animation.py index b990e054..90d5d412 100644 --- a/blender/io_mspgl/export_animation.py +++ b/blender/io_mspgl/export_animation.py @@ -1,25 +1,59 @@ import math +import os class AnimationExporter: + def __init__(self): + self.export_all = False + self.collection = True + self.looping_threshold = 0.001 + 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") + if self.export_all: + actions = [] + for o in context.selected_objects: + if not o.animation_data: + continue + + for t in o.animation_data.nla_tracks: + for s in t.strips: + if s.action and s.action not in actions: + actions.append(s.action) + + if not actions: + raise Exception("No actions found") + + resources = {} + for a in actions: + resources[a.name+".anim"] = self.export_animation(context, a) - resource = self.export_animation(context, anim_data.action) + path, base = os.path.split(out_fn) + base, ext = os.path.splitext(base) - with open(out_fn, "w") as out_file: - for s in resource.statements: - s.write_to_file(out_file) + if self.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(): + 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") + if not anim_data.action: + raise Exception("No active action") + + resource = self.export_animation(context, anim_data.action) + + resource.write_to_file(out_fn) def export_animation(self, context, action): from .animation import create_animation_from_action - anim = create_animation_from_action(context, action) + anim = create_animation_from_action(context, action, looping_threshold=self.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" @@ -61,5 +95,7 @@ class AnimationExporter: resource.statements.append(st) + resource.statements.append(Statement("looping", anim.looping)) + return resource