From 13d6b94e3ff6140458c1fcd0897e8caa7699a445 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Sep 2017 22:35:55 -0400 Subject: [PATCH] Add a more useful PyPRP->Korman Plasma Object tool This actually inspects the old style page_num property and will put the objects into the correct page if the page has been created by the artist. Fancy. --- korman/operators/op_toolbox.py | 33 +++++++++++++++++++++++++++++++-- korman/ui/ui_toolbox.py | 11 ++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/korman/operators/op_toolbox.py b/korman/operators/op_toolbox.py index ed68d5a..bef4f23 100644 --- a/korman/operators/op_toolbox.py +++ b/korman/operators/op_toolbox.py @@ -41,9 +41,38 @@ class PlasmaConvertLayerOpacitiesOperator(ToolboxOperator, bpy.types.Operator): return {"FINISHED"} +class PlasmaConvertPlasmaObjectOperator(ToolboxOperator, bpy.types.Operator): + bl_idname = "object.plasma_convert_plasma_objects" + bl_label = "Convert Plasma Objects" + bl_description = "Converts PyPRP objects to Plasma Objects" + + def execute(self, context): + # We will loop through all the objects and enable Plasma Object on every object that + # is either inserted into a valid page using the old-style text properties or is lacking + # a page property. Unfortunately, unless we start bundling some YAML interpreter, we cannot + # use the old AlcScript schtuff. + pages = { i.seq_suffix: i.name for i in context.scene.world.plasma_age.pages } + for i in bpy.data.objects: + pageid = i.game.properties.get("page_num", None) + if pageid is None: + i.plasma_object.enabled = True + continue + + page_name = pages.get(pageid.value, None) + if page_name is None: + # a common hack to prevent exporting in PyPRP was to set page_num == -1, + # so don't warn about that. + if pageid.value != -1: + print("Object '{}' in page_num '{}', which is not available :/".format(i.name, pageid.value)) + else: + i.plasma_object.enabled = True + i.plasma_object.page = page_name + return {"FINISHED"} + + class PlasmaEnablePlasmaObjectOperator(ToolboxOperator, bpy.types.Operator): bl_idname = "object.plasma_enable_all_objects" - bl_label = "Plasma Objects" + bl_label = "Enable All Plasma Objects" bl_description = "Marks all Objects as Plasma Objects for exporting" def execute(self, context): @@ -54,7 +83,7 @@ class PlasmaEnablePlasmaObjectOperator(ToolboxOperator, bpy.types.Operator): class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator): bl_idname = "texture.plasma_enable_all_textures" - bl_label = "Textures" + bl_label = "Enable All Textures" bl_description = "Ensures that all Textures are enabled" def execute(self, context): diff --git a/korman/ui/ui_toolbox.py b/korman/ui/ui_toolbox.py index 07f56c7..ab7ab1b 100644 --- a/korman/ui/ui_toolbox.py +++ b/korman/ui/ui_toolbox.py @@ -33,9 +33,10 @@ class PlasmaToolboxPanel(ToolboxPanel, bpy.types.Panel): layout = self.layout col = layout.column(align=True) - col.label("Enable All:") - col.operator("object.plasma_enable_all_objects", icon="OBJECT_DATA") - col.operator("texture.plasma_enable_all_textures", icon="TEXTURE") + col.label("Plasma Objects:") + col.operator("object.plasma_enable_all_objects", icon="OBJECT_DATA", text="Enable All") - col.label("Convert All:") - col.operator("texture.plasma_convert_layer_opacities", icon="IMAGE_RGB_ALPHA") + col.label("Convert:") + col.operator("object.plasma_convert_plasma_objects", icon="OBJECT_DATA", text="Plasma Objects") + col.operator("texture.plasma_enable_all_textures", icon="TEXTURE") + col.operator("texture.plasma_convert_layer_opacities", icon="IMAGE_RGB_ALPHA", text="Layer Opacities")