Browse Source

Merge pull request #67 from Hoikas/moar_toolbox

Moar Toolbox Schtuff
pull/70/head
Adam Johnson 7 years ago committed by GitHub
parent
commit
9029b2b792
  1. 87
      korman/operators/op_toolbox.py
  2. 16
      korman/ui/ui_toolbox.py

87
korman/operators/op_toolbox.py

@ -14,6 +14,7 @@
# along with Korman. If not, see <http://www.gnu.org/licenses/>. # along with Korman. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
from bpy.props import *
class ToolboxOperator: class ToolboxOperator:
@classmethod @classmethod
@ -21,20 +22,58 @@ class ToolboxOperator:
return context.scene.render.engine == "PLASMA_GAME" return context.scene.render.engine == "PLASMA_GAME"
class PlasmaEnablePlasmaObjectOperator(ToolboxOperator, bpy.types.Operator): class PlasmaConvertLayerOpacitiesOperator(ToolboxOperator, bpy.types.Operator):
bl_idname = "object.plasma_enable_all_objects" bl_idname = "texture.plasma_convert_layer_opacities"
bl_label = "Plasma Objects" bl_label = "Convert Layer Opacities"
bl_description = "Marks all Objects as Plasma Objects for exporting" bl_description = "Convert layer opacities from diffuse color factor"
def execute(self, context): 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 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: for i in bpy.data.objects:
i.plasma_object.enabled = True 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"} return {"FINISHED"}
class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator): class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator):
bl_idname = "texture.plasma_enable_all_textures" bl_idname = "texture.plasma_enable_all_textures"
bl_label = "Textures" bl_label = "Enable All Textures"
bl_description = "Ensures that all Textures are enabled" bl_description = "Ensures that all Textures are enabled"
def execute(self, context): def execute(self, context):
@ -49,21 +88,31 @@ class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator):
slot.use = True slot.use = True
return {"FINISHED"} return {"FINISHED"}
class PlasmaConvertLayerOpacitiesOperator(ToolboxOperator, bpy.types.Operator):
bl_idname = "texture.plasma_convert_layer_opacities" class PlasmaToggleAllPlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator):
bl_label = "Layer Opacities" bl_idname = "object.plasma_toggle_all_objects"
bl_description = "Convert layer opacities from diffuse color factor" 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): def execute(self, context):
for mesh in bpy.data.meshes: for i in bpy.data.objects:
for material in mesh.materials: i.plasma_object.enabled = self.enable
if material is None: return {"FINISHED"}
continue
for slot in material.texture_slots:
if slot is None:
continue
slot.texture.plasma_layer.opacity = slot.diffuse_color_factor * 100 class PlasmaTogglePlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator):
slot.diffuse_color_factor = 1.0 bl_idname = "object.plasma_toggle_selected_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"} return {"FINISHED"}

16
korman/ui/ui_toolbox.py

@ -33,9 +33,15 @@ class PlasmaToolboxPanel(ToolboxPanel, bpy.types.Panel):
layout = self.layout layout = self.layout
col = layout.column(align=True) col = layout.column(align=True)
col.label("Enable All:") col.label("Plasma Objects:")
col.operator("object.plasma_enable_all_objects", icon="OBJECT_DATA") 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_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")
col.operator("texture.plasma_enable_all_textures", icon="TEXTURE") col.operator("texture.plasma_enable_all_textures", icon="TEXTURE")
col.operator("texture.plasma_convert_layer_opacities", icon="IMAGE_RGB_ALPHA", text="Layer Opacities")
col.label("Convert All:")
col.operator("texture.plasma_convert_layer_opacities", icon="IMAGE_RGB_ALPHA")

Loading…
Cancel
Save