Browse Source

Tighten up static light baking object select algo.

It tried to bake some stupid stuff before, eg objects with no materials.
The bug was related to items being removed from a list during a loop. This
has been corrected by looping backwards by index.
pull/38/head
Adam Johnson 8 years ago
parent
commit
04d7af8827
  1. 36
      korman/exporter/etlight.py

36
korman/exporter/etlight.py

@ -83,18 +83,20 @@ class LightBaker:
# Step 1: Prepare... Apply UVs, etc, etc, etc # Step 1: Prepare... Apply UVs, etc, etc, etc
print(" Preparing to bake...") print(" Preparing to bake...")
for key, value in bake.copy().items(): for key in bake.keys():
if key[0] == "lightmap": if key[0] == "lightmap":
for i in value: for i in range(len(bake[key])-1, -1, -1):
if not self._prep_for_lightmap(i, toggle): obj = bake[key][i]
print(" Lightmap '{}' will not be baked -- no applicable lights".format(i.name)) if not self._prep_for_lightmap(obj, toggle):
bake[key].remove(i) print(" Lightmap '{}' will not be baked -- no applicable lights".format(obj.name))
bake[key].pop(i)
elif key[0] == "vcol": elif key[0] == "vcol":
for i in value: for i in range(len(bake[key])-1, -1, -1):
if not self._prep_for_vcols(i, toggle): obj = bake[key][i]
if self._has_valid_material(i): if not self._prep_for_vcols(obj, toggle):
print(" VCols '{}' will not be baked -- no applicable lights".format(i.name)) if self._has_valid_material(obj):
bake[key].remove(i) print(" VCols '{}' will not be baked -- no applicable lights".format(obj.name))
bake[key].pop(i)
else: else:
raise RuntimeError(key[0]) raise RuntimeError(key[0])
print(" ...") print(" ...")
@ -114,14 +116,14 @@ class LightBaker:
raise RuntimeError(key[0]) raise RuntimeError(key[0])
# Return how many thingos we baked # Return how many thingos we baked
return sum(map(sum, bake.values())) return sum(map(len, bake.values()))
def _generate_lightgroup(self, mesh, user_lg=None): def _generate_lightgroup(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"""
if user_lg is not None: if user_lg is not None:
user_lg = bpy.data.groups.get(user_lg) user_lg = bpy.data.groups.get(user_lg)
shouldibake = (user_lg and user_lg.objects) shouldibake = (user_lg is not None and bool(user_lg.objects))
for material in mesh.materials: for material in mesh.materials:
if material is None: if material is None:
@ -131,15 +133,11 @@ class LightBaker:
# Already done it? # Already done it?
name = material.name name = material.name
lg = material.light_group lg = material.light_group
if name in self._lightgroups: if name not in self._lightgroups:
# No, this is not Pythonic, but bpy_prop_collection is always "True",
# even when empty. Sigh.
return bool(len(lg.objects))
else:
self._lightgroups[name] = lg self._lightgroups[name] = lg
if user_lg is None: if user_lg is None:
if not lg or len(lg.objects) == 0: if not lg or bool(lg.objects) is False:
source = [i for i in bpy.data.objects if i.type == "LAMP"] source = [i for i in bpy.data.objects if i.type == "LAMP"]
else: else:
source = lg.objects source = lg.objects
@ -177,6 +175,8 @@ class LightBaker:
for i in objs: for i in objs:
if i.type != "MESH": if i.type != "MESH":
continue continue
if bool(i.data.materials) is False:
continue
mods = i.plasma_modifiers mods = i.plasma_modifiers
if mods.lightmap.enabled: if mods.lightmap.enabled:

Loading…
Cancel
Save