Skip to content

Single place to convert your 2D floor plans to 3d model (no LLM)

Python

Fix black light maps on floors with heavy models

23f200563936d1da2347c2
diff --git a/blender/bake.py b/blender/bake.py
index e0d8978..0e5fd41 100644
--- a/blender/bake.py
+++ b/blender/bake.py
@@ -123,6 +123,19 @@ def _unwrap(ob):
except TypeError:
bpy.ops.uv.smart_project(**kw)
bpy.ops.object.mode_set(mode="OBJECT")
+ if not _packed(me): # the FRACTION packer silently gives up on big meshes (e.g. 270k faces of chandeliers)
+ bpy.ops.object.mode_set(mode="EDIT")
+ bpy.ops.uv.smart_project(**kw)
+ bpy.ops.object.mode_set(mode="OBJECT")
+ if not _packed(me):
+ raise RuntimeError(f"light map unwrap failed for {ob.name}")
+
+
+def _packed(me):
+ """the 'lm' UVs all lie in the 0..1 square"""
+ uv = np.empty(len(me.uv_layers["lm"].data) * 2, np.float32)
+ me.uv_layers["lm"].data.foreach_get("uv", uv)
+ return uv.size == 0 or (uv.min() >= -1e-4 and uv.max() <= 1 + 1e-4)
def _cool_down(progress, limit=78, resume=65, most=900):