Browse Source

Allow user to specify a light group for light maps

pull/6/head
Adam Johnson 10 years ago
parent
commit
9626b22409
  1. 5
      korman/exporter/mesh.py
  2. 20
      korman/operators/op_lightmap.py
  3. 3
      korman/properties/modifiers/render.py
  4. 7
      korman/ui/modifiers/render.py

5
korman/exporter/mesh.py

@ -302,10 +302,11 @@ class MeshConverter:
"screen": bpy.context.screen, "screen": bpy.context.screen,
"window": bpy.context.window} "window": bpy.context.window}
if bo.plasma_modifiers.lightmap.enabled: lm = bo.plasma_modifiers.lightmap
if lm.enabled:
print(" Baking lightmap...") print(" Baking lightmap...")
print("====") print("====")
bpy.ops.object.plasma_lightmap_autobake(context) bpy.ops.object.plasma_lightmap_autobake(context, light_group=lm.light_group)
print("====") print("====")
else: else:
for vcol_layer in bo.data.vertex_colors: for vcol_layer in bo.data.vertex_colors:

20
korman/operators/op_lightmap.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 *
from ..helpers import GoodNeighbor from ..helpers import GoodNeighbor
def _fetch_lamp_objects(): def _fetch_lamp_objects():
@ -37,26 +38,30 @@ class _LightingOperator:
toggle.track(render, "use_raytrace", True) toggle.track(render, "use_raytrace", True)
toggle.track(render, "bake_type", "FULL") 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""" """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: for material in mesh.materials:
lg = material.light_group lg = material.light_group
self._old_lightgroups[material] = lg self._old_lightgroups[material] = lg
if user_lg is None:
# TODO: faux-lightgroup caching for the entire export process. you dig? # TODO: faux-lightgroup caching for the entire export process. you dig?
if lg is None or len(lg.objects) == 0: if not lg or len(lg.objects) == 0:
source = _fetch_lamp_objects() source = _fetch_lamp_objects()
else: else:
source = lg.objects source = lg.objects
dest = bpy.data.groups.new("_LIGHTMAPGEN_{}".format(material.name)) dest = bpy.data.groups.new("_LIGHTMAPGEN_{}".format(material.name))
# Only use non-RT lights
for obj in source: for obj in source:
if obj.plasma_object.enabled: if obj.plasma_object.enabled:
continue continue
dest.objects.link(obj) dest.objects.link(obj)
shouldibake = True shouldibake = True
else:
dest = user_lg
material.light_group = dest material.light_group = dest
return shouldibake return shouldibake
@ -77,6 +82,8 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator):
bl_label = "Bake Lightmap" bl_label = "Bake Lightmap"
bl_options = {"INTERNAL"} bl_options = {"INTERNAL"}
light_group = StringProperty(name="Light Group")
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -135,7 +142,8 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator):
self._apply_render_settings(render, toggle) self._apply_render_settings(render, toggle)
# Now, we *finally* bake the lightmap... # 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() bpy.ops.object.bake_image()
im.pack(as_png=True) im.pack(as_png=True)
self._pop_lightgroups() self._pop_lightgroups()
@ -149,11 +157,13 @@ class LightmapAutobakePreviewOperator(_LightingOperator, bpy.types.Operator):
bl_label = "Preview Lightmap" bl_label = "Preview Lightmap"
bl_options = {"INTERNAL"} bl_options = {"INTERNAL"}
light_group = StringProperty(name="Light Group")
def __init__(self): def __init__(self):
super().__init__() super().__init__()
def execute(self, context): 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") tex = bpy.data.textures.get("LIGHTMAPGEN_PREVIEW")
if tex is None: if tex is None:

3
korman/properties/modifiers/render.py

@ -36,6 +36,9 @@ class PlasmaLightMapGen(PlasmaModifierProperties):
("1024", "1024px", "1024x1024 pixels"), ("1024", "1024px", "1024x1024 pixels"),
]) ])
light_group = StringProperty(name="Light Group",
description="Group that defines the collection of lights to bake")
def created(self, obj): def created(self, obj):
self.display_name = "{}_LIGHTMAPGEN".format(obj.name) self.display_name = "{}_LIGHTMAPGEN".format(obj.name)

7
korman/ui/modifiers/render.py

@ -16,9 +16,10 @@
import bpy import bpy
def lightmap(modifier, layout, context): def lightmap(modifier, layout, context):
col = layout.column(align=True) layout.row(align=True).prop(modifier, "quality", expand=True)
col.row(align=True).prop(modifier, "quality", expand=True) layout.prop_search(modifier, "light_group", bpy.data, "groups", icon="GROUP")
col.operator("object.plasma_lightmap_preview", "Preview Lightmap", icon="RENDER_STILL") 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... # 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 # We can't show images, so we make a hidden ImageTexture called LIGHTMAPGEN_PREVIEW. We check

Loading…
Cancel
Save