From 916a621765d4846a01fe81bac5e9f60f9583b7ae Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 7 Jul 2015 18:32:25 -0400 Subject: [PATCH] Add more find/create helpers --- korman/exporter/convert.py | 8 ++++---- korman/exporter/manager.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index d68bc0a..9eace31 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -147,7 +147,7 @@ class Exporter: # Instead of exporting a skeleton now, we'll just make an orphaned CI. # The bl_obj export will make this work. - parent_ci = self.mgr.find_create_key(plCoordinateInterface, bl=bo, so=so).object + parent_ci = self.mgr.find_create_object(plCoordinateInterface, bl=bo, so=so) parent_ci.addChild(so.key) else: self.report.warn("You have parented Plasma Object '{}' to '{}', which has not been marked for export. \ @@ -157,7 +157,7 @@ class Exporter: def export_coordinate_interface(self, so, bl, name=None): """Ensures that the SceneObject has a CoordinateInterface""" if not so.coord: - ci = self.mgr.find_create_key(plCoordinateInterface, bl=bl, so=so, name=name).object + ci = self.mgr.find_create_object(plCoordinateInterface, bl=bl, so=so, name=name) # Now we have the "fun" work of filling in the CI ci.localToWorld = utils.matrix44(bl.matrix_basis) @@ -183,7 +183,7 @@ class Exporter: # Create a sceneobject if one does not exist. # Before we call the export_fn, we need to determine if this object is an actor of any # sort, and barf out a CI. - sceneobject = self.mgr.find_create_key(plSceneObject, bl=bl_obj).object + sceneobject = self.mgr.find_create_object(plSceneObject, bl=bl_obj) self._export_actor(sceneobject, bl_obj) export_fn(sceneobject, bl_obj) @@ -210,7 +210,7 @@ class Exporter: def _post_process_scene_objects(self): print("\nPostprocessing SceneObjects...") for bl_obj in self._objects: - sceneobject = self.mgr.find_key(plSceneObject, bl=bl_obj).object + sceneobject = self.mgr.find_object(plSceneObject, bl=bl_obj) bl_obj.plasma_net.export(bl_obj, sceneobject) # Modifiers don't have to expose post-processing, but if they do, run it diff --git a/korman/exporter/manager.py b/korman/exporter/manager.py index 4eda89d..ecbab28 100644 --- a/korman/exporter/manager.py +++ b/korman/exporter/manager.py @@ -188,6 +188,18 @@ class ExportManager: return key return None + def find_create_object(self, pClass, bl=None, name=None, so=None): + key = self.find_key(pClass, bl, name, so) + if key is None: + return self.add_object(pl=pClass, name=name, bl=bl, so=so) + return key.object + + def find_object(self, pClass, bl=None, name=None, so=None): + key = self.find_key(pClass, bl, name, so) + if key is not None: + return key.object + return None + def get_location(self, bl): """Returns the Page Location of a given Blender Object""" return self._pages[bl.plasma_object.page]