Skip to content

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

Python

Fix stair headroom, the roof cabin door, walls in doorways and blurry walls

23f20056391245b73ed9c0
diff --git a/blender/gen.py b/blender/gen.py
index 9272bd0..c65b672 100644
--- a/blender/gen.py
+++ b/blender/gen.py
@@ -167,7 +167,8 @@ def stair_parts(f, rise):
b = a + d * run
a, b = min(a, b), max(a, b)
zt = z + per * (i + 1) / n
- bx = (a, b, y0, y1, 0, zt) if ax == 0 else (x0, x1, a, b, 0, zt)
+ zb = max(0.0, z + per * i / n - 0.6) # a 0.6 ft waist, not solid to the floor: the flight of the storey
+ bx = (a, b, y0, y1, zb, zt) if ax == 0 else (x0, x1, a, b, zb, zt) # above stands over this one
boxes.append((*bx, "stair"))
end = start + d * (hi - lo)
meta.append(dict(rect=[x0, x1, y0, y1], axis=s["axis"], start=start, dir=d, z0=z, z1=z + per))
@@ -568,6 +569,11 @@ for k, f in enumerate(floors):
else:
door_list.append(o)
walls_f = [list(w) for w in f["walls"]]
+ # a wall standing in a doorway (a double line in the drawing) blocks the door: cut the door's path through it
+ path = [(r[0] - 1.5, r[1] + 1.5, r[2] + 0.15, r[3] - 0.15, -1, 2) if o["axis"] == "y" else
+ (r[0] + 0.15, r[1] - 0.15, r[2] - 1.5, r[3] + 1.5, -1, 2) for o in f["openings"] if o["type"] != "window" for r in [o["rect"]]]
+ walls_f = [[*b[:4], w[4]] for w in walls_f for b in subtract_all([(*w[:4], 0, 1)], path)
+ if b[1] - b[0] > 0.05 and b[3] - b[2] > 0.05]
if f["stairs"]:
fb = bbox_of([s["rect"] for s in f["stairs"]])
ax = f["stairs"][0]["axis"]
@@ -666,6 +672,7 @@ for k, f in enumerate(floors):
if sboxes:
mesh_from_boxes(f"stairs_{k}", sboxes)
stair_box_prev = bbox_of([b[:4] for b in sboxes])
+ stair_top = [q for q in smeta if not q.get("landing")][-1]
else:
stair_box_prev = None
items = furnish.floor_items(plan, f)
@@ -724,8 +731,11 @@ if stair_box_prev: # the top storey's stairs reach the roof: a small cabin ove
x0, x1, y0, y1 = stair_box_prev
walls_m = disjoint([(x0 - t, x1 + t, y0 - t, y0, 0, 8), (x0 - t, x1 + t, y1, y1 + t, 0, 8),
(x0 - t, x0, y0, y1, 0, 8), (x1, x1 + t, y0, y1, 0, 8)])
- cx = (x0 + x1) / 2
- walls_m = subtract_all(walls_m, [(cx - 1.5, cx + 1.5, y1 - 1, y1 + 1, -1, 7)])
+ # the door where the last flight comes up, so you walk straight out onto the roof
+ q = stair_top
+ end = q["start"] + q["dir"] * ((q["rect"][1] - q["rect"][0]) if q["axis"] == "x" else (q["rect"][3] - q["rect"][2]))
+ door = (end - 1, end + 1, *q["rect"][2:], -1, 7) if q["axis"] == "x" else (*q["rect"][:2], end - 1, end + 1, -1, 7)
+ walls_m = subtract_all(walls_m, [door])
mesh_from_boxes("mumty", [(*b, "exterior") for b in walls_m] + [(x0 - t, x1 + t, y0 - t, y1 + t, 8, 8.5, "slab")])
by_floor[NF] = new_objects(before)
@@ -775,7 +785,15 @@ progress(35, "model built")
# ------------------------------------------------------------------ bake + export
import bake # noqa: E402
-groups = {f"level_{k}": objs for k, objs in by_floor.items()}
+# imported models (scans, uploads) get a light map of their own per storey: their many small faces crowd the walls'
+# map (blurry walls) and can make its unwrap fail. Baked first: joining keeps their world place before their parents go.
+model_meshes = {o.data for objs in [*lib.PROTO.values(), *UPLOADS.values()] if objs for o in objs if o.type == "MESH"}
+groups = {}
+for k, objs in by_floor.items():
+ models = [o for o in objs if o.type == "MESH" and o.data in model_meshes]
+ if models:
+ groups[f"level_{k}_models"] = models
+ groups[f"level_{k}"] = [o for o in objs if o not in models]
groups["site"] = site
res = bake.bake_and_export(groups, unbaked=trees, out=JOB, quality=QUALITY, do_bake=BAKE, progress=progress)
# the floor textures the walkthrough's Finishes panel can lay (tile = metres per repeat, as the UVs were made)