From 9626b22409203b396694702327b543d4e3ddc255 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 13 Jun 2015 22:35:34 -0400 Subject: [PATCH] Allow user to specify a light group for light maps --- korman/exporter/mesh.py | 5 ++-- korman/operators/op_lightmap.py | 40 +++++++++++++++++---------- korman/properties/modifiers/render.py | 3 ++ korman/ui/modifiers/render.py | 7 +++-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index bb41ae1..2f01b1f 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -302,10 +302,11 @@ class MeshConverter: "screen": bpy.context.screen, "window": bpy.context.window} - if bo.plasma_modifiers.lightmap.enabled: + lm = bo.plasma_modifiers.lightmap + if lm.enabled: print(" Baking lightmap...") print("====") - bpy.ops.object.plasma_lightmap_autobake(context) + bpy.ops.object.plasma_lightmap_autobake(context, light_group=lm.light_group) print("====") else: for vcol_layer in bo.data.vertex_colors: diff --git a/korman/operators/op_lightmap.py b/korman/operators/op_lightmap.py index dcb704b..7f6b09f 100644 --- a/korman/operators/op_lightmap.py +++ b/korman/operators/op_lightmap.py @@ -14,6 +14,7 @@ # along with Korman. If not, see . import bpy +from bpy.props import * from ..helpers import GoodNeighbor def _fetch_lamp_objects(): @@ -37,26 +38,30 @@ class _LightingOperator: toggle.track(render, "use_raytrace", True) toggle.track(render, "bake_type", "FULL") - def _generate_lightgroups(self, mesh): + def _generate_lightgroups(self, mesh, user_lg=None): """Makes a new light group for the baking process that excludes all Plasma RT lamps""" - shouldibake = False + shouldibake = (user_lg and user_lg.objects) for material in mesh.materials: lg = material.light_group self._old_lightgroups[material] = lg - # TODO: faux-lightgroup caching for the entire export process. you dig? - if lg is None or len(lg.objects) == 0: - source = _fetch_lamp_objects() + if user_lg is None: + # TODO: faux-lightgroup caching for the entire export process. you dig? + if not lg or len(lg.objects) == 0: + source = _fetch_lamp_objects() + else: + source = lg.objects + dest = bpy.data.groups.new("_LIGHTMAPGEN_{}".format(material.name)) + + # Only use non-RT lights + for obj in source: + if obj.plasma_object.enabled: + continue + dest.objects.link(obj) + shouldibake = True else: - source = lg.objects - dest = bpy.data.groups.new("_LIGHTMAPGEN_{}".format(material.name)) - - for obj in source: - if obj.plasma_object.enabled: - continue - dest.objects.link(obj) - shouldibake = True + dest = user_lg material.light_group = dest return shouldibake @@ -77,6 +82,8 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator): bl_label = "Bake Lightmap" bl_options = {"INTERNAL"} + light_group = StringProperty(name="Light Group") + def __init__(self): super().__init__() @@ -135,7 +142,8 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator): self._apply_render_settings(render, toggle) # Now, we *finally* bake the lightmap... - if self._generate_lightgroups(mesh): + light_group = bpy.data.groups[self.light_group] if self.light_group else None + if self._generate_lightgroups(mesh, light_group): bpy.ops.object.bake_image() im.pack(as_png=True) self._pop_lightgroups() @@ -149,11 +157,13 @@ class LightmapAutobakePreviewOperator(_LightingOperator, bpy.types.Operator): bl_label = "Preview Lightmap" bl_options = {"INTERNAL"} + light_group = StringProperty(name="Light Group") + def __init__(self): super().__init__() def execute(self, context): - bpy.ops.object.plasma_lightmap_autobake() + bpy.ops.object.plasma_lightmap_autobake(light_group=self.light_group) tex = bpy.data.textures.get("LIGHTMAPGEN_PREVIEW") if tex is None: diff --git a/korman/properties/modifiers/render.py b/korman/properties/modifiers/render.py index bfdc0b6..daf4975 100644 --- a/korman/properties/modifiers/render.py +++ b/korman/properties/modifiers/render.py @@ -36,6 +36,9 @@ class PlasmaLightMapGen(PlasmaModifierProperties): ("1024", "1024px", "1024x1024 pixels"), ]) + light_group = StringProperty(name="Light Group", + description="Group that defines the collection of lights to bake") + def created(self, obj): self.display_name = "{}_LIGHTMAPGEN".format(obj.name) diff --git a/korman/ui/modifiers/render.py b/korman/ui/modifiers/render.py index ac4936e..de88b96 100644 --- a/korman/ui/modifiers/render.py +++ b/korman/ui/modifiers/render.py @@ -16,9 +16,10 @@ import bpy def lightmap(modifier, layout, context): - col = layout.column(align=True) - col.row(align=True).prop(modifier, "quality", expand=True) - col.operator("object.plasma_lightmap_preview", "Preview Lightmap", icon="RENDER_STILL") + layout.row(align=True).prop(modifier, "quality", expand=True) + layout.prop_search(modifier, "light_group", bpy.data, "groups", icon="GROUP") + operator = layout.operator("object.plasma_lightmap_preview", "Preview Lightmap", icon="RENDER_STILL") + operator.light_group = modifier.light_group # Kind of clever stuff to show the user a preview... # We can't show images, so we make a hidden ImageTexture called LIGHTMAPGEN_PREVIEW. We check