From 0d73893ac5c826cfd649f9c9c99d198eabda6743 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 27 Jun 2016 18:53:27 -0400 Subject: [PATCH] Limit CoordInterface creation for animated objects to xform animations only. --- korman/exporter/animation.py | 8 ++++++++ korman/exporter/convert.py | 4 ++-- korman/properties/modifiers/anim.py | 28 -------------------------- korman/properties/modifiers/physics.py | 26 ++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/korman/exporter/animation.py b/korman/exporter/animation.py index 69d082d..c32532a 100644 --- a/korman/exporter/animation.py +++ b/korman/exporter/animation.py @@ -214,6 +214,7 @@ class AnimationConverter: scale = self.make_scale_controller(fcurves, xform) if pos is None and rot is None and scale is None: return None + tm = plCompoundController() tm.X = pos tm.Y = rot @@ -250,6 +251,13 @@ class AnimationConverter: master = self._mgr.find_create_object(plAGMasterMod, so=so, bl=bo) return mod, master + def has_transform_animation(self, bo): + if bo.animation_data is not None: + if bo.animation_data.action is not None: + data_paths = frozenset((i.data_path for i in bo.animation_data.action.fcurves)) + return {"location", "rotation_euler", "scale"} & data_paths + return False + def is_animated(self, bo): if bo.animation_data is not None: if bo.animation_data.action is not None: diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index 4037088..24763d2 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -257,10 +257,10 @@ class Exporter: return True if bo.parent is not None: return True - if bo.animation_data is not None and bo.animation_data.action is not None: - return True if bo.name in self.actors: return True + if self.animation.has_transform_animation(bo): + return True for mod in bo.plasma_modifiers.modifiers: if mod.enabled: diff --git a/korman/properties/modifiers/anim.py b/korman/properties/modifiers/anim.py index dd45bfe..413c570 100644 --- a/korman/properties/modifiers/anim.py +++ b/korman/properties/modifiers/anim.py @@ -60,10 +60,6 @@ class PlasmaAnimationModifier(ActionModifier, PlasmaModifierProperties): loop_end = StringProperty(name="Loop End", description="Marker indicating where the default loop ends") - @property - def requires_actor(self): - return True - def export(self, exporter, bo, so): action = self.blender_action @@ -95,30 +91,6 @@ class PlasmaAnimationModifier(ActionModifier, PlasmaModifierProperties): atcanim.loopStart = atcanim.start atcanim.loopEnd = atcanim.end - def _make_physical_movable(self, so): - sim = so.sim - if sim is not None: - sim = sim.object - sim.setProperty(plSimulationInterface.kPhysAnim, True) - phys = sim.physical.object - phys.setProperty(plSimulationInterface.kPhysAnim, True) - - # If the mass is zero, then we will fail to animate. Fix that. - if phys.mass == 0.0: - phys.mass = 1.0 - - # set kPinned so it doesn't fall through - sim.setProperty(plSimulationInterface.kPinned, True) - phys.setProperty(plSimulationInterface.kPinned, True) - - # Do the same for children objects - for child in so.coord.object.children: - self.make_physical_movable(child.object) - - def post_export(self, exporter, bo, so): - # If this object has a physical, we need to tell the simulation iface that it can be animated - self._make_physical_movable(so) - class AnimGroupObject(bpy.types.PropertyGroup): object_name = StringProperty(name="Child", diff --git a/korman/properties/modifiers/physics.py b/korman/properties/modifiers/physics.py index 53a5198..c52c95e 100644 --- a/korman/properties/modifiers/physics.py +++ b/korman/properties/modifiers/physics.py @@ -84,6 +84,32 @@ class PlasmaCollider(PlasmaModifierProperties): if self.terrain: physical.LOSDBs |= plSimDefs.kLOSDBAvatarWalkable + def _make_physical_movable(self, so): + sim = so.sim + if sim is not None: + sim = sim.object + phys = sim.physical.object + _set_phys_prop(plSimulationInterface.kPhysAnim, sim, phys) + + # If the mass is zero, then we will fail to animate. Fix that. + if phys.mass == 0.0: + phys.mass = 1.0 + + # set kPinned so it doesn't fall through + _set_phys_prop(plSimulationInterface.kPinned, sim, phys) + + # Do the same for child objects + for child in so.coord.object.children: + self._make_physical_movable(child.object) + + def post_export(self, exporter, bo, so): + test_bo = bo + while test_bo is not None: + if exporter.animation.has_transform_animation(test_bo): + self._make_physical_movable(so) + break + test_bo = test_bo.parent + @property def key_name(self): return "{}_Collision".format(self.id_data.name)