|
|
@ -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: |
|
|
|