Browse Source

Don't track lightmaps by name.

That's bugprone and can lead to pain.
pull/261/head
Adam Johnson 3 years ago
parent
commit
b2859a3a41
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 7
      korman/exporter/convert.py
  2. 7
      korman/exporter/etlight.py
  3. 4
      korman/operators/op_lightmap.py
  4. 7
      korman/properties/modifiers/render.py

7
korman/exporter/convert.py

@ -56,6 +56,7 @@ class Exporter:
self.image = image.ImageCache(self)
self.locman = locman.LocalizationConverter(self)
self.decal = decal.DecalConverter(self)
self.oven = etlight.LightBaker(self.report)
# Step 0.8: Init the progress mgr
self.mesh.add_progress_presteps(self.report)
@ -126,10 +127,8 @@ class Exporter:
self.report.raise_errors()
def _bake_static_lighting(self):
lighting_method = self._op.lighting_method
if lighting_method != "skip":
oven = etlight.LightBaker(self.report)
oven.bake_static_lighting(self._objects)
if self._op.lighting_method != "skip":
self.oven.bake_static_lighting(self._objects)
def _collect_objects(self):
scene = bpy.context.scene

7
korman/exporter/etlight.py

@ -43,6 +43,7 @@ class LightBaker(_MeshManager):
self.lightmap_uvtex_name = "LIGHTMAPGEN"
self.retain_lightmap_uvtex = True
self.force = False
self._lightmap_images = {}
self._uvtexs = {}
def __del__(self):
@ -213,6 +214,9 @@ class LightBaker(_MeshManager):
material.light_group = dest
return shouldibake
def get_lightmap(self, bo):
return self._lightmap_images.get(bo.name)
def get_lightmap_name(self, bo):
return self.lightmap_name.format(bo.name)
@ -282,7 +286,7 @@ class LightBaker(_MeshManager):
def _pack_lightmaps(self, bake):
lightmap_iter = itertools.chain.from_iterable((value for key, value in bake.items() if key[0] == "lightmap"))
for bo in lightmap_iter:
im = bpy.data.images.get(self.get_lightmap_name(bo))
im = self.get_lightmap(bo)
if im is not None and im.is_dirty:
im.pack(as_png=True)
@ -337,6 +341,7 @@ class LightBaker(_MeshManager):
# Force delete and recreate the image because the size is out of date
data_images.remove(im)
im = data_images.new(im_name, width=size, height=size)
self._lightmap_images[bo.name] = im
# If there is a cached LIGHTMAPGEN uvtexture, nuke it
uvtex = uv_textures.get(self.lightmap_uvtex_name, None)

4
korman/operators/op_lightmap.py

@ -81,7 +81,7 @@ class LightmapAutobakePreviewOperator(_LightingOperator, bpy.types.Operator):
if tex is None:
tex = bpy.data.textures.new("LIGHTMAPGEN_PREVIEW", "IMAGE")
tex.extension = "CLIP"
image = bpy.data.images[bake.get_lightmap_name(context.object)]
image = bake.get_lightmap(context.object)
tex.image = image
if self.final:
lightmap_mod.image = image
@ -126,7 +126,7 @@ class LightmapBakeMultiOperator(_LightingOperator, bpy.types.Operator):
for i in filtered_objects:
lightmap_mod = i.plasma_modifiers.lightmap
if lightmap_mod.bake_lightmap:
lightmap_mod.image = bpy.data.images[bake.get_lightmap_name(i)]
lightmap_mod.image = bake.get_lightmap(i)
return {"FINISHED"}

7
korman/properties/modifiers/render.py

@ -463,14 +463,9 @@ class PlasmaLightMapGen(idprops.IDPropMixin, PlasmaModifierProperties, PlasmaMod
if not self.bake_lightmap:
return
if self.image is not None:
lightmap_im = self.image
else:
# Gulp...
lightmap_im = bpy.data.images.get("{}_LIGHTMAPGEN.png".format(bo.name))
# If no lightmap image is found, then either lightmap generation failed (error raised by oven)
# or baking is turned off. Either way, bail out.
lightmap_im = self.image if self.image is not None else exporter.oven.get_lightmap(bo)
if lightmap_im is None:
return
mat_mgr = exporter.mesh.material

Loading…
Cancel
Save