From 52752b9ddad0754c2fe97a926361dba7f554699e Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 14 Jul 2014 23:22:35 -0400 Subject: [PATCH] CI and other modifier improvements These were picked over from the larger basic physics commit. I don't want to hold up better modifier stuff while waiting on more physics code. --- korman/exporter/convert.py | 11 +++++------ korman/exporter/manager.py | 22 +++++++++++++++++++--- korman/exporter/mesh.py | 4 ++-- korman/operators/op_modifier.py | 2 +- korman/properties/modifiers/base.py | 5 +++++ korman/properties/modifiers/logic.py | 4 ++++ korman/ui/ui_modifiers.py | 5 +---- 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index 92e1010..210e7cd 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -95,16 +95,13 @@ class Exporter: def _export_actor(self, so, bo): """Exports a Coordinate Interface if we need one""" - empty = bo.type in {"CAMERA", "EMPTY", "LAMP"} - childobj = bo.parent is not None - - if empty or childobj: + if self.mgr.has_coordiface(bo): self._export_coordinate_interface(so, bo) # If this object has a parent, then we will need to go upstream and add ourselves to the # parent's CoordinateInterface... Because life just has to be backwards. - if childobj: - parent = bo.parent + parent = bo.parent + if parent is not None: if parent.plasma_object.enabled: print(" Attaching to parent SceneObject '{}'".format(parent.name)) @@ -120,6 +117,8 @@ class Exporter: def _export_coordinate_interface(self, so, bo): """Ensures that the SceneObject has a CoordinateInterface""" if not so.coord: + print(" Exporting CoordinateInterface") + ci = self.mgr.find_create_key(bo, plCoordinateInterface) so.coord = ci ci = ci.object diff --git a/korman/exporter/manager.py b/korman/exporter/manager.py index 5e58291..f737464 100644 --- a/korman/exporter/manager.py +++ b/korman/exporter/manager.py @@ -151,12 +151,16 @@ class ExportManager: return key return None - def get_location(self, bl_obj): + def get_location(self, bl): """Returns the Page Location of a given Blender Object""" - return self._pages[bl_obj.plasma_object.page] + return self._pages[bl.plasma_object.page] - def get_scene_node(self, location): + def get_scene_node(self, location=None, bl=None): """Gets a Plasma Page's plSceneNode key""" + assert (location is not None) ^ (bl is not None) + + if location is None: + location = self._pages[bl.plasma_object.page] return self._nodes[location].key def get_textures_page(self, layer): @@ -167,6 +171,18 @@ class ExportManager: else: return layer.key.location + def has_coordiface(self, bo): + if bo.type in {"CAMERA", "EMPTY", "LAMP"}: + return True + if bo.parent is not None: + return True + + for mod in bo.plasma_modifiers.modifiers: + if mod.enabled: + if mod.requires_actor: + return True + return False + def sanity_check_object_pages(self, age, objects): """Ensure all objects are in valid pages and create the Default page if used""" diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index b723b5d..39e5dec 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -111,7 +111,7 @@ class MeshConverter: # TODO: RunTime lights (requires libHSPlasma feature) # If this object has a CI, we don't need xforms here... - if self._mgr.find_key(bo, plCoordinateInterface) is not None: + if self._mgr.has_coordiface(bo): geospan.localToWorld = hsMatrix44() geospan.worldToLocal = hsMatrix44() else: @@ -270,7 +270,7 @@ class MeshConverter: if crit not in self._dspans[location]: # AgeName_[District_]_Page_RenderLevel_Crit[Blend]Spans # Just because it's nice to be consistent - node = self._mgr.get_scene_node(location) + node = self._mgr.get_scene_node(location=location) name = "{}_{:08X}_{:X}{}".format(node.name, crit.render_level.level, crit.criteria, crit.span_type) dspan = self._mgr.add_object(pl=plDrawableSpans, name=name, loc=location) diff --git a/korman/operators/op_modifier.py b/korman/operators/op_modifier.py index 0a9526c..6b5311f 100644 --- a/korman/operators/op_modifier.py +++ b/korman/operators/op_modifier.py @@ -22,7 +22,7 @@ def _fetch_modifiers(): items = [] mapping = modifiers.modifier_mapping() - for i in mapping.keys(): + for i in sorted(mapping.keys()): items.append(("", i, "")) items.extend(mapping[i]) #yield ("", i, "") diff --git a/korman/properties/modifiers/base.py b/korman/properties/modifiers/base.py index 53a1992..a8a5211 100644 --- a/korman/properties/modifiers/base.py +++ b/korman/properties/modifiers/base.py @@ -28,6 +28,11 @@ class PlasmaModifierProperties(bpy.types.PropertyGroup): def enabled(self): return self.display_order >= 0 + @property + def requires_actor(self): + """Indicates if this modifier requires the object to be a movable actor""" + return False + # Guess what? # You can't register properties on a base class--Blender isn't smart enough to do inheritance, # you see... So, we'll store our definitions in a dict and make those properties on each subclass diff --git a/korman/properties/modifiers/logic.py b/korman/properties/modifiers/logic.py index 2facf55..1e512e7 100644 --- a/korman/properties/modifiers/logic.py +++ b/korman/properties/modifiers/logic.py @@ -33,3 +33,7 @@ class PlasmaSpawnPoint(PlasmaModifierProperties): # place the avatar can show up." Nice to have a simple one to get started with. spawn = exporter.mgr.add_object(pl=plSpawnModifier, bl=bo, name=self.display_name) so.addModifier(spawn.key) + + @property + def requires_actor(self): + return True diff --git a/korman/ui/ui_modifiers.py b/korman/ui/ui_modifiers.py index ffb7257..3d3a9d2 100644 --- a/korman/ui/ui_modifiers.py +++ b/korman/ui/ui_modifiers.py @@ -73,10 +73,7 @@ class PlasmaModifiersPanel(ModifierButtonsPanel, bpy.types.Panel): row = layout.row(align=True) exicon = "TRIA_DOWN" if modifier.show_expanded else "TRIA_RIGHT" row.prop(modifier, "show_expanded", text="", icon=exicon, emboss=False) - if hasattr(modifier, "bl_icon"): - row.label(icon=modifier.bl_icon) - else: - row.label(text=modifier.bl_label) + row.label(text=modifier.bl_label, icon=getattr(modifier, "bl_icon", "NONE")) row.prop(modifier, "display_name", text="") row.operator("object.plasma_modifier_move_up", text="", icon="TRIA_UP").active_modifier = modifier.display_order