From b6b065e253fbb5adb57486aeb7f0b8e0229c410a Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Sep 2017 22:35:35 -0400 Subject: [PATCH 1/4] Fix op_toolbox.py ordering --- korman/operators/op_toolbox.py | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/korman/operators/op_toolbox.py b/korman/operators/op_toolbox.py index 496a32b..ed68d5a 100644 --- a/korman/operators/op_toolbox.py +++ b/korman/operators/op_toolbox.py @@ -21,6 +21,26 @@ class ToolboxOperator: return context.scene.render.engine == "PLASMA_GAME" +class PlasmaConvertLayerOpacitiesOperator(ToolboxOperator, bpy.types.Operator): + bl_idname = "texture.plasma_convert_layer_opacities" + bl_label = "Convert Layer Opacities" + bl_description = "Convert layer opacities from diffuse color factor" + + def execute(self, context): + for mesh in bpy.data.meshes: + for material in mesh.materials: + if material is None: + continue + + for slot in material.texture_slots: + if slot is None: + continue + + slot.texture.plasma_layer.opacity = slot.diffuse_color_factor * 100 + slot.diffuse_color_factor = 1.0 + return {"FINISHED"} + + class PlasmaEnablePlasmaObjectOperator(ToolboxOperator, bpy.types.Operator): bl_idname = "object.plasma_enable_all_objects" bl_label = "Plasma Objects" @@ -48,22 +68,3 @@ class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator): continue slot.use = True return {"FINISHED"} - -class PlasmaConvertLayerOpacitiesOperator(ToolboxOperator, bpy.types.Operator): - bl_idname = "texture.plasma_convert_layer_opacities" - bl_label = "Layer Opacities" - bl_description = "Convert layer opacities from diffuse color factor" - - def execute(self, context): - for mesh in bpy.data.meshes: - for material in mesh.materials: - if material is None: - continue - - for slot in material.texture_slots: - if slot is None: - continue - - slot.texture.plasma_layer.opacity = slot.diffuse_color_factor * 100 - slot.diffuse_color_factor = 1.0 - return {"FINISHED"} From 13d6b94e3ff6140458c1fcd0897e8caa7699a445 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Sep 2017 22:35:55 -0400 Subject: [PATCH 2/4] 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") From 5ac7ac149aa54d7ae0f685df338ff89e98424fd5 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Sep 2017 22:56:10 -0400 Subject: [PATCH 3/4] Add a Plasma Object toggle tool for dendwaler --- korman/operators/op_toolbox.py | 16 ++++++++++++++++ korman/ui/ui_toolbox.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/korman/operators/op_toolbox.py b/korman/operators/op_toolbox.py index bef4f23..3b34522 100644 --- a/korman/operators/op_toolbox.py +++ b/korman/operators/op_toolbox.py @@ -97,3 +97,19 @@ class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator): continue slot.use = True return {"FINISHED"} + + +class PlasmaTogglePlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator): + bl_idname = "object.plasma_toggle_objects" + bl_label = "Toggle Plasma Objects" + bl_description = "Toggles the Plasma Object status of a selection" + + @classmethod + def poll(cls, context): + return super().poll(context) and hasattr(bpy.context, "selected_objects") + + def execute(self, context): + enable = not all((i.plasma_object.enabled for i in bpy.context.selected_objects)) + for i in context.selected_objects: + i.plasma_object.enabled = enable + return {"FINISHED"} diff --git a/korman/ui/ui_toolbox.py b/korman/ui/ui_toolbox.py index ab7ab1b..1d5297f 100644 --- a/korman/ui/ui_toolbox.py +++ b/korman/ui/ui_toolbox.py @@ -35,6 +35,8 @@ class PlasmaToolboxPanel(ToolboxPanel, bpy.types.Panel): col.label("Plasma Objects:") col.operator("object.plasma_enable_all_objects", icon="OBJECT_DATA", text="Enable All") + all_plasma_objects = all((i.plasma_object.enabled for i in bpy.context.selected_objects)) + col.operator("object.plasma_toggle_objects", icon="VIEW3D", text="Disable Selection" if all_plasma_objects else "Enable Selection") col.label("Convert:") col.operator("object.plasma_convert_plasma_objects", icon="OBJECT_DATA", text="Plasma Objects") From 5eef79223fe54139e41decb0f4f5cbad43a3df2b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Sep 2017 23:05:17 -0400 Subject: [PATCH 4/4] Add a Disable All tool for Plasma Objects --- korman/operators/op_toolbox.py | 27 +++++++++++++++------------ korman/ui/ui_toolbox.py | 7 +++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/korman/operators/op_toolbox.py b/korman/operators/op_toolbox.py index 3b34522..8df708a 100644 --- a/korman/operators/op_toolbox.py +++ b/korman/operators/op_toolbox.py @@ -14,6 +14,7 @@ # along with Korman. If not, see . import bpy +from bpy.props import * class ToolboxOperator: @classmethod @@ -70,17 +71,6 @@ class PlasmaConvertPlasmaObjectOperator(ToolboxOperator, bpy.types.Operator): return {"FINISHED"} -class PlasmaEnablePlasmaObjectOperator(ToolboxOperator, bpy.types.Operator): - bl_idname = "object.plasma_enable_all_objects" - bl_label = "Enable All Plasma Objects" - bl_description = "Marks all Objects as Plasma Objects for exporting" - - def execute(self, context): - for i in bpy.data.objects: - i.plasma_object.enabled = True - return {"FINISHED"} - - class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator): bl_idname = "texture.plasma_enable_all_textures" bl_label = "Enable All Textures" @@ -99,8 +89,21 @@ class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator): return {"FINISHED"} +class PlasmaToggleAllPlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator): + bl_idname = "object.plasma_toggle_all_objects" + bl_label = "Toggle All Plasma Objects" + bl_description = "Changes the state of all Plasma Objects" + + enable = BoolProperty(name="Enable", description="Enable Plasma Object") + + def execute(self, context): + for i in bpy.data.objects: + i.plasma_object.enabled = self.enable + return {"FINISHED"} + + class PlasmaTogglePlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator): - bl_idname = "object.plasma_toggle_objects" + bl_idname = "object.plasma_toggle_selected_objects" bl_label = "Toggle Plasma Objects" bl_description = "Toggles the Plasma Object status of a selection" diff --git a/korman/ui/ui_toolbox.py b/korman/ui/ui_toolbox.py index 1d5297f..a73bc93 100644 --- a/korman/ui/ui_toolbox.py +++ b/korman/ui/ui_toolbox.py @@ -34,9 +34,12 @@ class PlasmaToolboxPanel(ToolboxPanel, bpy.types.Panel): col = layout.column(align=True) col.label("Plasma Objects:") - col.operator("object.plasma_enable_all_objects", icon="OBJECT_DATA", text="Enable All") + enable_all = col.operator("object.plasma_toggle_all_objects", icon="OBJECT_DATA", text="Enable All") + enable_all.enable = True all_plasma_objects = all((i.plasma_object.enabled for i in bpy.context.selected_objects)) - col.operator("object.plasma_toggle_objects", icon="VIEW3D", text="Disable Selection" if all_plasma_objects else "Enable Selection") + col.operator("object.plasma_toggle_selected_objects", icon="VIEW3D", text="Disable Selection" if all_plasma_objects else "Enable Selection") + disable_all = col.operator("object.plasma_toggle_all_objects", icon="OBJECT_DATA", text="Disable All") + disable_all.enable = False col.label("Convert:") col.operator("object.plasma_convert_plasma_objects", icon="OBJECT_DATA", text="Plasma Objects")