From df056603ec0d7630dd1714146a75e3510c7fb94e Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 20 Jul 2016 19:41:45 -0400 Subject: [PATCH] Implement Layer SDL Animations --- korman/exporter/material.py | 22 ++++++++++++++++------ korman/nodes/node_messages.py | 3 +++ korman/properties/prop_texture.py | 3 +++ korman/ui/ui_texture.py | 26 ++++++++++++++++---------- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/korman/exporter/material.py b/korman/exporter/material.py index 29d4247..ca22b97 100644 --- a/korman/exporter/material.py +++ b/korman/exporter/material.py @@ -282,7 +282,7 @@ class MaterialConverter: fcurves = [] mat_action = harvest_fcurves(bm, fcurves, "texture_slots[{}]".format(idx)) - tex_action = harvest_fcurves(bm.texture_slots[idx].texture, fcurves) + tex_action = harvest_fcurves(tex_slot.texture, fcurves) if not fcurves: return base_layer @@ -294,7 +294,7 @@ class MaterialConverter: if ctrl is not None: if layer_animation is None: name = "{}_LayerAnim".format(base_layer.key.name) - layer_animation = self._mgr.find_create_object(plLayerAnimation, bl=bo, name=name) + layer_animation = self.get_texture_animation_key(bo, bm, tex_slot=tex_slot).object setattr(layer_animation, attr, ctrl) # Alrighty, if we exported any controllers, layer_animation is a plLayerAnimation. We need to do @@ -318,6 +318,8 @@ class MaterialConverter: atc.flags |= plAnimTimeConvert.kLoop atc.loopBegin = atc.begin atc.loopEnd = atc.end + if layer_props.anim_sdl_var: + layer_animation.varName = layer_props.anim_sdl_var return layer_animation # Well, we had some FCurves but they were garbage... Too bad. @@ -598,13 +600,21 @@ class MaterialConverter: def get_materials(self, bo): return self._obj2mat.get(bo, []) - def get_texture_animation_key(self, bo, bm, tex_name): + def get_texture_animation_key(self, bo, bm, tex_name=None, tex_slot=None): """Finds or creates the appropriate key for sending messages to an animated Texture""" - tex_slot = bm.texture_slots.get(tex_name, None) + assert tex_name or tex_slot + if tex_slot is None: - raise ExportError("Material '{}' does not contain Texture '{}'".format(bm.name, tex_name)) + tex_slot = bm.texture_slots.get(tex_name, None) + if tex_slot is None: + raise ExportError("Material '{}' does not contain Texture '{}'".format(bm.name, tex_name)) + if tex_name is None: + tex_name = tex_slot.name + name = "{}_{}_LayerAnim".format(bm.name, tex_name) - return self._mgr.find_create_key(plLayerAnimation, bl=bo, name=name) + layer = tex_slot.texture.plasma_layer + pClass = plLayerSDLAnimation if layer.anim_sdl_var else plLayerAnimation + return self._mgr.find_create_key(pClass, bl=bo, name=name) @property def _mgr(self): diff --git a/korman/nodes/node_messages.py b/korman/nodes/node_messages.py index 6fa9be0..b25d54d 100644 --- a/korman/nodes/node_messages.py +++ b/korman/nodes/node_messages.py @@ -189,8 +189,11 @@ class PlasmaAnimCmdMsgNode(PlasmaMessageNode, bpy.types.Node): if material is None: self.raise_error("invalid material: '{}'".format(self.material_name)) target = exporter.mesh.material.get_texture_animation_key(obj, material, self.texture_name) + if target is None: raise RuntimeError() + if isinstance(target.object, plLayerSDLAnimation): + self.raise_error("Cannot control an SDL Animation") msg.addReceiver(target) # Check the enum properties to see what commands we need to add diff --git a/korman/properties/prop_texture.py b/korman/properties/prop_texture.py index 6757ac5..bfd93a7 100644 --- a/korman/properties/prop_texture.py +++ b/korman/properties/prop_texture.py @@ -50,6 +50,9 @@ class PlasmaLayer(bpy.types.PropertyGroup): anim_loop = BoolProperty(name="Loop", description="Loop layer animation", default=True) + anim_sdl_var = StringProperty(name="SDL Variable", + description="Name of the SDL Variable to use for this animation", + options=set()) is_detail_map = BoolProperty(name="Detail Fade", description="Texture fades out as distance from the camera increases", diff --git a/korman/ui/ui_texture.py b/korman/ui/ui_texture.py index 435e8f8..98fbf8a 100644 --- a/korman/ui/ui_texture.py +++ b/korman/ui/ui_texture.py @@ -69,15 +69,26 @@ class PlasmaLayerPanel(TextureButtonsPanel, bpy.types.Panel): split = layout.split() col = split.column() col.label("Animation:") - col.enabled = self._has_animation_data(context) and not slot.use_stencil + col.active = self._has_animation_data(context) and not slot.use_stencil col.prop(layer_props, "anim_auto_start") col.prop(layer_props, "anim_loop") + col.separator() + col.label("SDL Animation:") + col.prop(layer_props, "anim_sdl_var", text="") col = split.column() col.label("Miscellaneous:") col.active = not slot.use_stencil col.prop(layer_props, "opacity", text="Opacity") - layout.separator() + col.separator() + + col = col.column() + col.enabled = True + col.label("Z Depth:") + col.prop(layer_props, "alpha_halo") + col.prop(layer_props, "skip_depth_write") + col.prop(layer_props, "skip_depth_test") + col.prop(layer_props, "z_bias") split = layout.split() col = split.column() @@ -87,17 +98,12 @@ class PlasmaLayerPanel(TextureButtonsPanel, bpy.types.Panel): col.active = texture.use_mipmap and layer_props.is_detail_map col.prop(layer_props, "detail_fade_start") col.prop(layer_props, "detail_fade_stop") - col.separator() + col = split.column(align=True) + col.active = texture.use_mipmap and layer_props.is_detail_map + col.label(text="") col.prop(layer_props, "detail_opacity_start") col.prop(layer_props, "detail_opacity_stop") - col = split.column() - col.label("Z Depth:") - col.prop(layer_props, "alpha_halo") - col.prop(layer_props, "skip_depth_write") - col.prop(layer_props, "skip_depth_test") - col.prop(layer_props, "z_bias") - def _has_animation_data(self, context): tex = getattr(context, "texture", None) if tex is not None: