From 07ac68974aaf4c1ebcdf09e8e240ef65e584eea6 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 3 Feb 2024 15:55:26 -0500 Subject: [PATCH] Allow vertex colors to modulate lightmaps. Weird feature request by artists. Korman's lighting equation selection looks like it should work fine with this, though. The key is to be sure that we don't pick up a stale autocolor layer. --- korman/exporter/mesh.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index 212386d5..a05fba5e 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -384,7 +384,7 @@ def _export_geometry(self, bo, mesh, materials, geospans, mat2span_LUT): # Locate relevant vertex color layers now... lm = bo.plasma_modifiers.lightmap - color = None if lm.bake_lightmap else self._find_vtx_color_layer(mesh.tessface_vertex_colors) + color = self._find_vtx_color_layer(mesh.tessface_vertex_colors, autocolor=not lm.bake_lightmap, manual=True) alpha = self._find_vtx_alpha_layer(mesh.tessface_vertex_colors) # Convert Blender faces into things we can stuff into libHSPlasma @@ -717,13 +717,15 @@ def _find_vtx_alpha_layer(self, color_collection): return alpha_layer.data return None - def _find_vtx_color_layer(self, color_collection): - manual_layer = next((i for i in color_collection if i.name.lower() in _VERTEX_COLOR_LAYERS), None) - if manual_layer is not None: - return manual_layer.data - baked_layer = color_collection.get("autocolor") - if baked_layer is not None: - return baked_layer.data + def _find_vtx_color_layer(self, color_collection, autocolor: bool = True, manual: bool = True): + if manual: + manual_layer = next((i for i in color_collection if i.name.lower() in _VERTEX_COLOR_LAYERS), None) + if manual_layer is not None: + return manual_layer.data + if autocolor: + baked_layer = color_collection.get("autocolor") + if baked_layer is not None: + return baked_layer.data return None def is_nonpreshaded(self, bo: bpy.types.Object, bm: bpy.types.Material) -> bool: