From a208ee21d35543d25cd4290ca3aa7c1fa0cf56d4 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Thu, 2 Jul 2015 03:22:07 -0700 Subject: [PATCH] Add Plasma layer options panel to Texture context. - Add an opacity value for exported layer. - Add a conversion button in the toolbar for old PyPRP Ages which used the diffuse color factor as the opacity value. --- korman/exporter/material.py | 5 ++++- korman/operators/op_toolbox.py | 19 ++++++++++++++++++ korman/properties/__init__.py | 2 ++ korman/properties/prop_texture.py | 27 ++++++++++++++++++++++++++ korman/ui/__init__.py | 1 + korman/ui/ui_texture.py | 32 +++++++++++++++++++++++++++++++ korman/ui/ui_toolbox.py | 3 +++ 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 korman/properties/prop_texture.py create mode 100644 korman/ui/ui_texture.py diff --git a/korman/exporter/material.py b/korman/exporter/material.py index 249ac20..6f7690d 100644 --- a/korman/exporter/material.py +++ b/korman/exporter/material.py @@ -255,8 +255,11 @@ class MaterialConverter: elif slot.blend_type == "MULTIPLY": state.blendFlags |= hsGMatState.kBlendMult - # Export the specific texture type + # Apply custom layer properties texture = slot.texture + layer.opacity = texture.plasma_layer.opacity / 100 + + # Export the specific texture type self._tex_exporters[texture.type](bo, hsgmat, layer, slot) hsgmat.addLayer(layer.key) return num_exported diff --git a/korman/operators/op_toolbox.py b/korman/operators/op_toolbox.py index 3e52d3a..496a32b 100644 --- a/korman/operators/op_toolbox.py +++ b/korman/operators/op_toolbox.py @@ -48,3 +48,22 @@ 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"} diff --git a/korman/properties/__init__.py b/korman/properties/__init__.py index cfafdf8..45e82d3 100644 --- a/korman/properties/__init__.py +++ b/korman/properties/__init__.py @@ -17,11 +17,13 @@ import bpy from . import modifiers from .prop_object import * +from .prop_texture import * from .prop_world import * def register(): bpy.types.Object.plasma_net = bpy.props.PointerProperty(type=PlasmaNet) bpy.types.Object.plasma_object = bpy.props.PointerProperty(type=PlasmaObject) + bpy.types.Texture.plasma_layer = bpy.props.PointerProperty(type=PlasmaLayer) bpy.types.World.plasma_age = bpy.props.PointerProperty(type=PlasmaAge) bpy.types.World.plasma_fni = bpy.props.PointerProperty(type=PlasmaFni) diff --git a/korman/properties/prop_texture.py b/korman/properties/prop_texture.py new file mode 100644 index 0000000..41af233 --- /dev/null +++ b/korman/properties/prop_texture.py @@ -0,0 +1,27 @@ +# This file is part of Korman. +# +# Korman is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Korman is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Korman. If not, see . + +import bpy +from bpy.props import * + +class PlasmaLayer(bpy.types.PropertyGroup): + bl_idname = "texture.plasma_layer" + + opacity = FloatProperty(name="Layer Opacity", + description="Opacity of the texture", + default=100, + min=0, + max=100, + subtype="PERCENTAGE") diff --git a/korman/ui/__init__.py b/korman/ui/__init__.py index 0c04b5e..00e2d3d 100644 --- a/korman/ui/__init__.py +++ b/korman/ui/__init__.py @@ -15,5 +15,6 @@ from .ui_modifiers import * from .ui_object import * +from .ui_texture import * from .ui_toolbox import * from .ui_world import * diff --git a/korman/ui/ui_texture.py b/korman/ui/ui_texture.py new file mode 100644 index 0000000..ab4b8a3 --- /dev/null +++ b/korman/ui/ui_texture.py @@ -0,0 +1,32 @@ +# This file is part of Korman. +# +# Korman is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Korman is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Korman. If not, see . + +import bpy + +class TextureButtonsPanel: + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "texture" + + @classmethod + def poll(cls, context): + return context.texture and context.scene.render.engine == "PLASMA_GAME" + +class PlasmaLayerPanel(TextureButtonsPanel, bpy.types.Panel): + bl_label = "Plasma Layer Options" + + def draw(self, context): + layout = self.layout + layout.prop(context.texture.plasma_layer, "opacity") diff --git a/korman/ui/ui_toolbox.py b/korman/ui/ui_toolbox.py index af25c12..07f56c7 100644 --- a/korman/ui/ui_toolbox.py +++ b/korman/ui/ui_toolbox.py @@ -36,3 +36,6 @@ class PlasmaToolboxPanel(ToolboxPanel, bpy.types.Panel): 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("Convert All:") + col.operator("texture.plasma_convert_layer_opacities", icon="IMAGE_RGB_ALPHA")