Skip to content

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

Python

Softer furniture and real materials: fabric bed and sofa with pillows, curtains, marble tea table, granite worktop, brushed steel fridge, washer and stone shower

23f200563940a61788e918
diff --git a/AGENTS.md b/AGENTS.md
index b551efc..5f0f9f7 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -7,7 +7,7 @@ There is no AI model in the pipeline: detection is geometry, furniture is rules,
```bash
./run.sh --port 8080 # npm install (three.js) + python3 server.py
-python3 fetch_assets.py # CC0 textures and models into assets/ (about 60 MB), once
+python3 fetch_assets.py # CC0 textures and models into assets/ (about 75 MB), once
```
Needs Python 3, Node 18+, Blender 4.2+ and poppler. If Blender is not on `PATH`, set `BLENDER` to its full path.
diff --git a/README.md b/README.md
index bce53cf..cba1739 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,7 @@ git clone <this repo> && cd planto3d
./run.sh # installs three.js, serves http://127.0.0.1:8080
```
-Open the page. It checks Blender, the PDF tools, the viewer library and the materials, and accepts a plan only when all four are in place. The textures and models (about 60 MB, CC0, from [Poly Haven](https://polyhaven.com)) are not in the repository: press **Download materials** on the page, or run `python3 fetch_assets.py`.
+Open the page. It checks Blender, the PDF tools, the viewer library and the materials, and accepts a plan only when all four are in place. The textures and models (about 75 MB, CC0, from [Poly Haven](https://polyhaven.com)) are not in the repository: press **Download materials** on the page, or run `python3 fetch_assets.py`.
Then press **Try the sample plan**, or drop your own PDF on the page.
diff --git a/blender/gen.py b/blender/gen.py
index 30e296a..e08aa5f 100644
--- a/blender/gen.py
+++ b/blender/gen.py
@@ -39,7 +39,6 @@ mat("pebbles", tex="dry_river_pebbles", tile=0.8)
mat("terrace", tex="concrete_tiles", tile=1.5)
mat("turf", tex="leafy_grass", tile=1.0, tint=(0.5, 0.75, 0.35))
mat("exterior", (0.93, 0.91, 0.87), 0.9, tex="white_plaster_02", tile=2.5, albedo=False)
-mat("sofa_fabric", rough=0.95, tex="fabric_pattern_07", tile=0.6, tint=(0.75, 0.7, 0.62))
mat("cushion", rough=0.95, tex="caban", tile=0.5, tint=(0.55, 0.45, 0.35))
FLOOR_MAT = dict(dress="wood", bedroom="wood", toilet="bathtile", kitchen="marble", living="marble", dining="marble", puja="marble",
@@ -106,6 +105,46 @@ def opening_heights(f, o):
return (6.0, 7.5) if wet or width <= VENT_MAX else (3.0, 7.0)
+CURTAIN_ROOMS = {"bedroom", "living", "dining", "study", "room", "dress", "puja"}
+
+
+def curtains(f, items):
+ """linen curtains on a brass rod at each full-size window of a living room or bedroom, on the room side.
+ Floor length, unless furniture stands in front of the window: then they stop above the sill."""
+ for o in f["openings"]:
+ if o["type"] != "window":
+ continue
+ sill, head = opening_heights(f, o)
+ if sill >= 5: # high ventilator or bathroom window
+ continue
+ x0, x1, y0, y1 = o["rect"]
+ along_x = o["axis"] == "x"
+ a0, a1 = (x0, x1) if along_x else (y0, y1)
+ for side in (-1, 1):
+ face = (y0 if side < 0 else y1) if along_x else (x0 if side < 0 else x1)
+ probe = (((x0 + x1) / 2, face + side), (face + side, (y0 + y1) / 2))[not along_x]
+ zn = zone_at(f, *probe)
+ if not zn or zn["type"] not in CURTAIN_ROOMS:
+ continue
+ plane = face + side * 0.3
+ strip = (a0 - 0.6, a1 + 0.6, *sorted((face, face + side * 1.2)))
+ if not along_x:
+ strip = (strip[2], strip[3], strip[0], strip[1])
+ blocked = any(it.get("box") and overlap((*strip, 0, 1), (*it["box"], 0, 1)) for it in items)
+ bottom = sill - 0.3 if blocked else 0.1
+ rod = min(head + 0.6, lib.WALL_H - 0.3)
+ c = (a0 + a1) / 2
+ r = item("curtain", c if along_x else plane, plane if along_x else c, 0 if along_x else 90)
+ span = a1 - a0 + 1.4
+ p_cyl(r, "curtain_rod", 0.05, 0.05, span, "brass", (-span / 2, 0, rod), rot=(0, 90, 0), segs=12)
+ for s_ in (-1, 1):
+ p_cyl(r, "rod_end", 0.1, 0.1, 0.12, "brass", (s_ * span / 2, 0, rod), rot=(0, 90, 0), segs=12)
+ pw = max(1.3, (a1 - a0) * 0.3)
+ for s_ in (-1, 1):
+ p_pleats(r, "curtain", pw, rod - bottom, "curtain", (s_ * ((a1 - a0) / 2 + 0.6 - pw / 2), 0, bottom))
+ done(r, collide=False)
+
+
# ------------------------------------------------------------------ stairs
def stair_parts(f, rise):
"""flights + landing from the detected tread runs. The flight next to the UP word starts at floor level
@@ -170,20 +209,41 @@ def nightstand(x, y, rot):
def sofa(x, y, rot, w=7.0):
+ """velvet sofa: rounded arms and back, loose seat and back cushions, throw pillows, brass feet"""
hw = w / 2
- group("sofa", [(-hw, hw, -1.5, 1.5, 0.3, 1.4, "sofa_fabric"), (-hw, hw, 0.8, 1.5, 1.4, 2.8, "sofa_fabric"),
- (-hw, -hw + 0.6, -1.5, 1.5, 1.4, 2.2, "sofa_fabric"), (hw - 0.6, hw, -1.5, 1.5, 1.4, 2.2, "sofa_fabric"),
- (-hw + 0.3, hw - 0.3, -1.5, 1.4, 0, 0.3, "black")], x, y, rot, bevel=0.1, seg=3)
- n = max(2, round((w - 1.2) / 2.2))
- cw = (w - 1.2) / n
- cush = [(-hw + 0.6 + cw * i + 0.03, -hw + 0.6 + cw * (i + 1) - 0.03, -1.4, 0.8, 1.4, 1.95, "cushion") for i in range(n)]
- cush += [(-hw + 0.6 + cw * i + 0.05, -hw + 0.6 + cw * (i + 1) - 0.05, 0.35, 0.85, 1.95, 3.0, "cushion") for i in range(n)]
- group("sofa_cushions", cush, x, y, rot, bevel=0.18, seg=4, collide=False)
+ r = item("sofa", x, y, rot)
+ for sx in (-1, 1):
+ for sy in (-1, 1):
+ p_cyl(r, "sofa_foot", 0.08, 0.05, 0.35, "brass", (sx * (hw - 0.35), sy * 1.2, 0), segs=16)
+ p_soft(r, "sofa_base", w, 3.0, 0.9, "velvet", (0, 0, 0.35), r=0.12)
+ for s_ in (-1, 1):
+ p_soft(r, "sofa_arm", 0.62, 3.0, 1.9, "velvet", (s_ * (hw - 0.31), 0, 0.35), r=0.25)
+ p_soft(r, "sofa_back", w - 1.2, 0.6, 1.55, "velvet", (0, 1.2, 1.2), r=0.2)
+ n = max(2, round((w - 1.24) / 2.2))
+ cw = (w - 1.24) / n
+ for i in range(n):
+ cx = -hw + 0.62 + cw * (i + 0.5)
+ p_soft(r, "seat_cushion", cw - 0.04, 2.35, 0.55, "velvet", (cx, -0.3, 1.2), r=0.2)
+ p_soft(r, "back_cushion", cw - 0.06, 0.55, 1.45, "velvet", (cx, 0.62, 1.68), (-12, 0, 0), r=0.24)
+ for s_, m in ((-1, "jacquard"), (1, "boucle")):
+ p_soft(r, "throw_pillow", 1.3, 0.38, 1.3, m, (s_ * (hw - 1.45), 0.2, 1.72), (-24, 0, -s_ * 12), r=0.22)
+ return done(r)
def coffee_table(x, y, rot):
- group("coffee_table", [(-1.8, 1.8, -1.0, 1.0, 1.25, 1.4, "teak"), (-1.6, 1.6, -0.8, 0.8, 0.0, 0.1, "black"),
- (-0.1, 0.1, -0.1, 0.1, 0.1, 1.25, "steel")], x, y, rot, bevel=0.03)
+ """tea table: oval white marble top on a walnut base with a shelf; books and a bowl on top"""
+ r = item("coffee_table", x, y, rot)
+ p_cyl(r, "table_top", 1.0, 1.0, 0.1, "marble_top", (0, 0, 1.35), sx=1.8, segs=64, bevel=0.03, seg=2)
+ p_cyl(r, "table_apron", 0.92, 0.92, 0.18, "teak", (0, 0, 1.17), sx=1.82, segs=64)
+ p_cyl(r, "table_shelf", 0.85, 0.85, 0.08, "teak", (0, 0, 0.35), sx=1.8, segs=64)
+ for sx in (-1, 1):
+ for sy in (-1, 1):
+ p_cyl(r, "table_leg", 0.07, 0.1, 1.17, "teak", (sx * 1.05, sy * 0.48, 0), segs=16)
+ p_box(r, "book", 0.9, 0.65, 0.1, "blue_accent", (-0.7, 0.05, 1.45), (0, 0, 8), bevel=0.01)
+ p_box(r, "book", 0.8, 0.6, 0.08, "throw", (-0.68, 0.08, 1.55), (0, 0, -4), bevel=0.01)
+ p_bowl(r, "bowl", 0.35, 0.22, "ceramic", (0.75, -0.05, 1.67))
+ p_box(r, "tray", 1.0, 0.6, 0.05, "brass", (0.0, 0.0, 0.43), bevel=0.01)
+ return done(r)
def tv_unit(x, y, rot):
@@ -459,6 +519,8 @@ for k, f in enumerate(floors):
custom(it) or CALLS[it["fn"]](*it["args"], **it["kw"])
except Exception as e: # one bad item must not stop the build
print("ITEM FAILED", it["fn"], e, flush=True)
+ if items:
+ curtains(f, items)
# lamps (emissive panel + area light for the bake) in roofed rooms
for zn in f["rooms"]:
if zn["type"] not in INDOOR and zn["type"] not in ("balcony", "parking", "stair"):
diff --git a/blender/lib.py b/blender/lib.py
index 18c9491..087b925 100644
--- a/blender/lib.py
+++ b/blender/lib.py
@@ -1,6 +1,8 @@
"""Blender building blocks used by gen.py: materials, box meshes, furniture and fixtures (units: feet).
Textures and models come from ../assets (python3 fetch_assets.py)."""
import bpy, bmesh, json, math, os, sys
+import numpy as np
+import random
from mathutils import Vector, Matrix
HERE = os.path.dirname(os.path.abspath(__file__))
@@ -31,9 +33,40 @@ def tex_node(nt, path, non_color=False):
return n
+def _grey(img):
+ """the photo's weave and shading without its colour (mean brightness 0.8), so a tint can set any colour"""
+ w, h = img.size
+ px = np.empty(w * h * 4, np.float32)
+ img.pixels.foreach_get(px)
+ px = px.reshape(-1, 4)
+ lum = px[:, :3] @ np.array([0.2126, 0.7152, 0.0722], np.float32)
+ lum = np.clip(lum * (0.8 / max(float(lum.mean()), 1e-3)), 0, 1)
+ out = bpy.data.images.new(img.name + "_grey", w, h)
+ rgba = np.ones((w * h, 4), np.float32)
+ rgba[:, :3] = lum[:, None]
+ out.pixels.foreach_set(rgba.ravel())
+ out.pack()
+ return out
+
+
+def _brushed():
+ """brushed stainless steel: fine streaks along u (no such photo on Poly Haven)"""
+ rnd = np.random.default_rng(7)
+ n = 512
+ rows = rnd.normal(0, 1, (n, 1)) * 0.035 + rnd.normal(0, 1, (n, n)) * 0.012
+ k = np.ones(48, np.float32) / 48 # smear the speckle along u into streaks
+ rows = np.array([np.convolve(np.tile(r, 2), k, "same")[n // 2:n // 2 + n] for r in rows])
+ v = np.clip(0.72 + rows, 0, 1).astype(np.float32)
+ img = bpy.data.images.new("brushed_steel", n, n)
+ img.pixels.foreach_set(np.stack([v, v, v * 1.01, np.ones_like(v)], -1).clip(0, 1).ravel())
+ img.pack()
+ return img
+
+
def mat(name, color=(0.8, 0.8, 0.8), rough=0.5, metal=0.0, tex=None, tile=1.0, alpha=1.0,
- emit=0.0, tint=None, albedo=True):
- """tile = metres covered by one texture repeat (UVs are written in metres / tile)."""
+ emit=0.0, tint=None, albedo=True, grey=False, image=None):
+ """tile = metres covered by one texture repeat (UVs are written in metres / tile).
+ grey: drop the photo's own colour so tint is the colour; image: a generated image as the albedo."""
m = bpy.data.materials.new(name)
m.use_nodes = True
nt = m.node_tree
@@ -45,6 +78,8 @@ def mat(name, color=(0.8, 0.8, 0.8), rough=0.5, metal=0.0, tex=None, tile=1.0, a
d = os.path.join(ASSETS, "textures", tex)
if albedo and os.path.exists(os.path.join(d, "diff.jpg")): # albedo=False: bump only (smooth paint)
t = tex_node(nt, os.path.join(d, "diff.jpg"))
+ if grey:
+ t.image = _grey(t.image)
if tint: # multiply albedo by a tint colour
mix = nt.nodes.new("ShaderNodeMix")
mix.data_type = "RGBA"
@@ -63,6 +98,10 @@ def mat(name, color=(0.8, 0.8, 0.8), rough=0.5, metal=0.0, tex=None, tile=1.0, a
nm = nt.nodes.new("ShaderNodeNormalMap")
nt.links.new(n.outputs["Color"], nm.inputs["Color"])
nt.links.new(nm.outputs["Normal"], p.inputs["Normal"])
+ if image:
+ t = nt.nodes.new("ShaderNodeTexImage")
+ t.image = image
+ nt.links.new(t.outputs["Color"], p.inputs["Base Color"])
if alpha < 1:
p.inputs["Alpha"].default_value = alpha
if hasattr(m, "surface_render_method"):
@@ -93,6 +132,10 @@ mat("terracotta", tex="terracotta_floor_tiles", tile=1.2)
mat("concrete", tex="concrete_floor", tile=2.0)
mat("grass", tex="leafy_grass", tile=1.5, tint=(0.55, 0.8, 0.4))
mat("granite", rough=0.15, tex="marble_01", tile=1.5, tint=(0.12, 0.11, 0.11)) # black marble slab
+mat("stone_top", rough=0.2, tex="terrazzo_tiles", tile=0.9, grey=True, tint=(0.36, 0.35, 0.34)) # speckled granite worktop
+mat("stone_wall", rough=0.2, tex="marble_01", tile=1.0, tint=(0.95, 0.93, 0.9))
+mat("pebble_floor", rough=0.7, tex="dry_river_pebbles", tile=0.6)
+mat("marble_top", rough=0.15, tex="marble_01", tile=1.0)
mat("stair", (0.62, 0.58, 0.52), 0.4, tex="granite_tile", tile=1.0)
mat("glass", (0.75, 0.85, 0.9), 0.05, alpha=0.18)
mat("frame", (0.92, 0.92, 0.92), 0.4) # uPVC/powder-coated window frames
@@ -101,16 +144,21 @@ mat("teak", rough=0.4, tex="black_walnut_veneer_01", tile=1.0, tint=(0.5, 0.3, 0
mat("laminate_w", rough=0.4, tex="oak_veneer_01", tile=1.2)
mat("white_gloss", (0.93, 0.93, 0.92), 0.15)
mat("ceramic", (0.97, 0.97, 0.96), 0.08)
-mat("fabric_bed", rough=0.9, tex="cotton_jersey", tile=0.4, tint=(1.0, 0.98, 0.95))
+mat("sheet", rough=0.9, tex="stretch_poplin", tile=0.35, grey=True, tint=(1.0, 0.99, 0.97))
+mat("duvet", rough=0.95, tex="waffle_pique_cotton", tile=0.3, grey=True, tint=(0.93, 0.9, 0.85))
+mat("throw", rough=1.0, tex="knitted_fleece", tile=0.35, grey=True, tint=(0.62, 0.34, 0.24))
+mat("velvet", rough=0.8, tex="velour_velvet", tile=0.5, grey=True, tint=(0.3, 0.42, 0.4))
+mat("velvet_head", rough=0.8, tex="velour_velvet", tile=0.5, grey=True, tint=(0.62, 0.55, 0.48))
+mat("jacquard", rough=0.9, tex="quatrefoil_jacquard_fabric", tile=0.35, grey=True, tint=(0.95, 0.72, 0.35))
+mat("boucle", rough=1.0, tex="wool_boucle", tile=0.4, grey=True, tint=(0.95, 0.92, 0.86))
mat("fabric_blanket", rough=0.9, tex="floral_jacquard", tile=0.6, tint=(1.0, 0.75, 0.7))
-mat("fabric_blue", rough=0.9, tex="gingham_check", tile=0.5, tint=(0.6, 0.75, 1.0))
-mat("fabric_green", rough=0.95, tex="caban", tile=0.6, tint=(0.7, 0.85, 0.65))
mat("rug", rough=1.0, tex="hessian_380", tile=0.8, tint=(0.9, 0.75, 0.6))
-mat("curtain", rough=0.7, tex="cotton_jersey", tile=0.5, tint=(0.88, 0.82, 0.72))
+mat("curtain", rough=0.9, tex="rough_linen", tile=0.6, grey=True, tint=(0.95, 0.9, 0.8))
mat("black", (0.02, 0.02, 0.02), 0.3)
mat("screen", (0.01, 0.01, 0.015), 0.05)
mat("light", (1.0, 0.95, 0.85), 0.5, emit=6.0)
mat("appliance", (0.8, 0.8, 0.82), 0.3, 0.8)
+mat("steel_brushed", rough=0.3, metal=0.9, image=_brushed(), tile=0.6)
# ---------------------------------------------------------------- geometry helpers
COLL = {}
@@ -271,25 +319,39 @@ def group(name, boxes, x, y, rot=0, bevel=0.0, collide=True, z=0.0, seg=2):
# rot convention for procedural items: 0 -> front faces -y, 90 -> +x, 180 -> +y, 270 -> -x
-def bed(x, y, rot, w=5.0, l=6.6, blanket="fabric_blanket", panel=None):
- """panel: width of the wood panel on the wall behind the bed (default bed + 1.8 ft each side; 0 = none)"""
+def bed(x, y, rot, w=5.0, l=6.6, blanket="throw", panel=None):
+ """upholstered bed made up with sheet, duvet, a throw and pillows. blanket: material of the throw at the foot.
+ panel: width of the wood panel on the wall behind the bed (default bed + 1.8 ft each side; 0 = none)"""
hw = w / 2
yb, yf = l / 2, -l / 2 # head (back) at +y local
hp = hw + 1.8 if panel is None else panel / 2
if hp > 0:
group("accent_panel", [(-hp, hp, yb - 0.03, yb, 0, WALL_H - 0.01, "wall_accent")],
x, y, rot, collide=False) # panel sits flush on the wall behind the headboard
- group("bed_frame", [(-hw, hw, yf, yb - 0.25, 0.25, 1.1, "teak"),
- (-hw, hw, yb - 0.25, yb, 0, 3.6, "teak"),
- (-hw + 0.1, hw - 0.1, yb - 0.45, yb - 0.25, 1.6, 3.3, "fabric_bed")],
- x, y, rot, bevel=0.04)
- group("mattress", [(-hw + 0.1, hw - 0.1, yf + 0.1, yb - 0.3, 1.1, 1.75, "fabric_bed")],
- x, y, rot, bevel=0.12, seg=3, collide=False)
- group("blanket", [(-hw + 0.02, hw - 0.02, yf + 0.02, yb - 2.2, 1.6, 1.82, blanket)],
- x, y, rot, bevel=0.08, seg=3, collide=False)
- group("pillows", [(-hw + 0.3, -0.15, yb - 1.8, yb - 0.5, 1.7, 2.15, "fabric_bed"),
- (0.15, hw - 0.3, yb - 1.8, yb - 0.5, 1.7, 2.15, "fabric_bed")],
- x, y, rot, bevel=0.15, seg=3, collide=False)
+ if blanket not in MATS:
+ blanket = "throw"
+ seed = round(x * 7 + y * 13)
+ r = item("bed", x, y, rot)
+ p_box(r, "bed_plinth", w - 0.5, l - 0.8, 0.3, "black", (0, -0.2, 0), bevel=0.01)
+ p_box(r, "bed_base", w, l - 0.35, 0.75, "teak", (0, -0.175, 0.3), bevel=0.05)
+ p_box(r, "headboard_back", w + 0.3, 0.15, 3.9, "teak", (0, yb - 0.1, 0), bevel=0.03)
+ n = max(3, round((w + 0.3) / 0.9)) # channel-tufted upholstered headboard
+ cw = (w + 0.3) / n
+ for i in range(n):
+ p_soft(r, "headboard", cw - 0.02, 0.4, 2.9, "velvet_head", (-(w + 0.3) / 2 + cw * (i + 0.5), yb - 0.37, 0.95),
+ r=0.17)
+ p_soft(r, "mattress", w - 0.15, l - 0.55, 0.75, "sheet", (0, -0.225, 1.05), r=0.12)
+ p_drape(r, "duvet", -hw + 0.08, hw - 0.08, yf + 0.1, yb - 2.1, 1.86, 0.85, "duvet", "xXy", thick=0.06, seed=seed)
+ p_soft(r, "duvet_fold", w - 0.1, 0.55, 0.3, "duvet", (0, yb - 2.1, 1.72), r=0.14)
+ p_drape(r, "throw", -hw, hw, yf + 0.3, yf + 1.7, 1.94, 1.0, blanket, "xX", thick=0.04, seed=seed)
+ pw, xs = (w - 0.6, (0,)) if w < 4 else (hw - 0.3, (-w / 4, w / 4))
+ for px in xs: # sleeping pillows leaning on the headboard
+ p_soft(r, "pillow", pw, 0.55, 1.35, "sheet", (px, yb - 0.95, 1.75), (-18, 0, 0), r=0.26)
+ if w >= 4: # cushions in front of them
+ for k, s in enumerate((-1, 1)):
+ p_soft(r, "cushion", 1.25, 0.4, 1.25, "jacquard", (s * (w / 4 - 0.1), yb - 1.45, 1.8), (-22, 0, s * 6), r=0.2)
+ p_soft(r, "cushion", 1.1, 0.35, 0.8, "boucle", (0, yb - 1.6, 1.8), (-15, 0, 0), r=0.16)
+ return done(r)
def wardrobe(x, y, rot, w=6.0, d=2.0, h=7.0):
@@ -369,7 +431,21 @@ mat("water", (0.55, 0.7, 0.75), 0.02, alpha=0.5)
mat("blue_accent", (0.1, 0.35, 0.75), 0.3)
-def _mesh_obj(name, bm, mn, parent, loc=(0, 0, 0), rot=(0, 0, 0), smooth=40, bevel=0.0, seg=3, solid=0.0):
+def _box_uv(bm, tile):
+ """texture UVs in metres / tile, projected along each face's main axis (as mesh_from_boxes does)"""
+ uv = bm.loops.layers.uv.new("UVMap")
+ for f in bm.faces:
+ f.normal_update()
+ ax = max(range(3), key=lambda i: abs(f.normal[i]))
+ a, c = [(1, 2), (0, 2), (0, 1)][ax]
+ for lp in f.loops:
+ lp[uv].uv = (lp.vert.co[a] / tile, lp.vert.co[c] / tile)
+
+
+def _mesh_obj(name, bm, mn, parent, loc=(0, 0, 0), rot=(0, 0, 0), smooth=40, bevel=0.0, seg=3, solid=0.0, soft=0):
+ """soft: subdivision levels after the bevel, for upholstery and pillows"""
+ if not bm.loops.layers.uv:
+ _box_uv(bm, MATS[mn]["tile"])
me = bpy.data.meshes.new(name)
bm.to_mesh(me)
bm.free()
@@ -389,9 +465,70 @@ def _mesh_obj(name, bm, mn, parent, loc=(0, 0, 0), rot=(0, 0, 0), smooth=40, bev
md = ob.modifiers.new("bevel", "BEVEL")
md.width, md.segments, md.limit_method = bevel * F, seg, "ANGLE"
md.harden_normals = False
+ if soft:
+ md = ob.modifiers.new("soft", "SUBSURF")
+ md.levels = md.render_levels = soft
return ob
+def p_soft(root, name, sx, sy, sz, mn, loc=(0, 0, 0), rot=(0, 0, 0), r=0.15):
+ """upholstered block: a box with round edges r (feet), smoothed into a slightly puffy cushion"""
+ return p_box(root, name, sx, sy, sz, mn, loc, rot, bevel=min(r, sx / 2.2, sy / 2.2, sz / 2.2), seg=2, soft=2,
+ smooth=180)
+
+
+def p_drape(root, name, x0, x1, y0, y1, top, hang, mn, sides="xX y", thick=0.07, seed=0, step=0.12):
+ """cloth lying on the rectangle x0..x1, y0..y1 at height top and falling over the edges named in sides
+ (x = -x, X = +x, y = -y, Y = +y) by hang feet, with soft folds; local feet like p_box"""
+ rnd = random.Random(seed)
+ ex = [hang if "x" in sides else 0, hang if "X" in sides else 0, hang if "y" in sides else 0, hang if "Y" in sides else 0]
+ us = [x0 - ex[0] + i * step for i in range(int((x1 - x0 + ex[0] + ex[1]) / step) + 1)]
+ vs = [y0 - ex[2] + j * step for j in range(int((y1 - y0 + ex[2] + ex[3]) / step) + 1)]
+ ph = [rnd.uniform(0, 6.3) for _ in range(4)]
+ bm = bmesh.new()
+ uv = bm.loops.layers.uv.new("UVMap")
+ grid = []
+ for v in vs:
+ row = []
+ for u in us:
+ dx, dy = max(0, x0 - u, u - x1), max(0, y0 - v, v - y1)
+ drop = math.hypot(dx, dy)
+ flare = 0.04 + 0.1 * drop # cloth stands off the edge a little more as it falls
+ px = min(max(u, x0 - flare), x1 + flare)
+ py = min(max(v, y0 - flare), y1 + flare)
+ k = min(drop, 0.6) / 0.6 # vertical folds: they vary along the edge, not down it
+ px += 0.05 * k * math.sin(v * 3.1 + ph[0]) * (1 if u > x1 else -1 if u < x0 else 0)
+ py += 0.05 * k * math.sin(u * 3.1 + ph[1]) * (1 if v > y1 else -1 if v < y0 else 0)
+ pz = top - drop + (0.02 * math.sin(u * 2.3 + ph[2]) * math.sin(v * 1.9 + ph[3]) if drop == 0 else 0)
+ row.append(bm.verts.new((px * F, py * F, pz * F)))
+ grid.append(row)
+ for j in range(len(vs) - 1):
+ for i in range(len(us) - 1):
+ f = bm.faces.new((grid[j][i], grid[j][i + 1], grid[j + 1][i + 1], grid[j + 1][i]))
+ for lp, (a, b) in zip(f.loops, ((i, j), (i + 1, j), (i + 1, j + 1), (i, j + 1))):
+ lp[uv].uv = (us[a] * F / MATS[mn]["tile"], vs[b] * F / MATS[mn]["tile"])
+ return _mesh_obj(name, bm, mn, root, smooth=80, solid=thick, soft=1)
+
+
+def p_pleats(root, name, width, h, mn, loc=(0, 0, 0), rot=(0, 0, 0), depth=0.14, pitch=0.42):
+ """curtain panel hanging from its top edge: width along local x (centred), pleated in y, bottom at z=0"""
+ n = max(2, round(width / pitch * 8))
+ bm = bmesh.new()
+ uv = bm.loops.layers.uv.new("UVMap")
+ cols = []
+ for i in range(n + 1):
+ x = -width / 2 + width * i / n
+ y = depth / 2 * math.sin(2 * math.pi * x / pitch)
+ cols.append([bm.verts.new((x * F, (y + (depth * 0.4 * math.sin(x * 1.3) if z == 0 else 0)) * F, z * F))
+ for z in (0, h)])
+ t = MATS[mn]["tile"]
+ for i in range(n):
+ f = bm.faces.new((cols[i][0], cols[i + 1][0], cols[i + 1][1], cols[i][1]))
+ for lp, (a, b) in zip(f.loops, ((i, 0), (i + 1, 0), (i + 1, 1), (i, 1))):
+ lp[uv].uv = ((-width / 2 + width * a / n) * 1.3 * F / t, b * h * F / t)
+ return _mesh_obj(name, bm, mn, root, loc, rot, smooth=80, solid=0.03)
+
+
def _bm_xform(bm, scale=(1, 1, 1), lift=0.0):
for v in bm.verts:
v.co = Vector((v.co.x * scale[0], v.co.y * scale[1], v.co.z * scale[2] + lift))
@@ -410,8 +547,9 @@ def p_box(root, name, sx, sy, sz, mn, loc=(0, 0, 0), rot=(0, 0, 0), bevel=0.02,
"""box centred on x/y, base at z=0 (feet)."""
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0)
+ kw.setdefault("smooth", 30)
return _mesh_obj(name, _bm_xform(bm, (sx * F, sy * F, sz * F), sz * F / 2), mn, root, loc, rot,
- smooth=30, bevel=bevel, seg=seg, **kw)
+ bevel=bevel, seg=seg, **kw)
def p_frustum(root, name, w0, d0, w1, d1, h, mn, loc=(0, 0, 0), **kw):
@@ -543,12 +681,14 @@ def shower2(x, y, rot, glass=None):
r = item("shower", x, y, rot)
p_tube(r, "shower_arm", [(0, 0.0, 7.4), (0, -0.4, 7.4), (0, -0.9, 7.3), (0, -1.1, 7.15)], 0.05, "chrome")
p_box(r, "shower_head", 0.85, 0.85, 0.05, "chrome", (0, -1.1, 7.05), bevel=0.02)
- p_cyl(r, "mixer_plate", 0.28, 0.28, 0.04, "chrome", (0, 0.02, 3.8), rot=(90, 0, 0))
- p_box(r, "mixer_lever", 0.06, 0.12, 0.4, "chrome", (0, -0.06, 3.75), bevel=0.02)
- p_box(r, "floor_drain", 0.4, 0.4, 0.015, "steel", (0, -1.1, 0.0), bevel=0)
- p_cyl(r, "hand_shower", 0.05, 0.07, 0.6, "chrome", (0.5, -0.05, 3.9), rot=(0, 0, 0))
- p_tube(r, "hand_hose", [(0.5, -0.05, 3.9), (0.55, -0.15, 2.8), (0.4, -0.1, 2.2), (0.3, 0.0, 3.6)], 0.025,
+ p_cyl(r, "mixer_plate", 0.28, 0.28, 0.04, "chrome", (0, -0.09, 3.8), rot=(90, 0, 0))
+ p_box(r, "mixer_lever", 0.06, 0.12, 0.4, "chrome", (0, -0.16, 3.75), bevel=0.02)
+ p_box(r, "floor_drain", 0.4, 0.4, 0.015, "steel", (0, -1.1, 0.05), bevel=0)
+ p_cyl(r, "hand_shower", 0.05, 0.07, 0.6, "chrome", (0.5, -0.15, 3.9), rot=(0, 0, 0))
+ p_tube(r, "hand_hose", [(0.5, -0.15, 3.9), (0.55, -0.25, 2.8), (0.4, -0.2, 2.2), (0.3, -0.1, 3.6)], 0.025,
"chrome")
+ p_box(r, "shower_wall", 2.6, 0.04, 7.6, "stone_wall", (0, -0.07, 0), bevel=0) # in front of the 0.03 ft wall tiles
+ p_box(r, "shower_tray", 2.5, 2.5, 0.05, "pebble_floor", (0, -1.27, 0), bevel=0.005)
done(r, collide=False)
if glass:
x0, x1, y0, y1 = glass
@@ -604,7 +744,7 @@ def kitchen_run(x0, x1, y0, y1, front, sink=None, hob=None, doors=True):
holes.append((sx - 0.9, sx + 0.9, -0.55, 0.55, 2.0, 3.0))
top = subtract_all(top, holes)
for i, b in enumerate(top):
- p_box(r, "counter_top", b[1] - b[0], b[3] - b[2], 0.15, "granite",
+ p_box(r, "counter_top", b[1] - b[0], b[3] - b[2], 0.15, "stone_top",
((b[0] + b[1]) / 2, (b[2] + b[3]) / 2, 2.75), bevel=0.01)
p_box(r, "backsplash", L, 0.04, 2.0, "walltile", (0, Dp / 2 - 0.02, 2.9), bevel=0)
if sink is not None:
@@ -654,22 +794,39 @@ def chimney(x, y, rot):
def fridge2(x, y, rot):
+ """brushed steel French-door fridge with a freezer drawer"""
r = item("fridge", x, y, rot)
- p_box(r, "fridge_body", 2.3, 2.1, 5.8, "appliance", (0, 0.05, 0), bevel=0.1, seg=4)
+ p_box(r, "fridge_body", 2.3, 2.1, 5.8, "steel_brushed", (0, 0.05, 0), bevel=0.08, seg=3)
+ p_box(r, "fridge_gap", 2.2, 0.05, 5.6, "black", (0, -1.0, 0.1), bevel=0)
for s in (-1, 1):
- p_box(r, "fridge_door", 1.12, 0.12, 5.6, "appliance", (s * 0.58, -1.03, 0.1), bevel=0.06, seg=3)
- p_tube(r, "fridge_handle", [(s * 0.12, -1.22, 2.6), (s * 0.12, -1.22, 4.4)], 0.04, "chrome")
- p_box(r, "fridge_display", 0.4, 0.02, 0.5, "black_glass", (-0.6, -1.1, 3.8), bevel=0.01)
+ p_box(r, "fridge_door", 1.12, 0.14, 3.6, "steel_brushed", (s * 0.575, -1.05, 2.15), bevel=0.05, seg=3)
+ p_tube(r, "fridge_handle", [(s * 0.1, -1.25, 2.9), (s * 0.1, -1.25, 5.0)], 0.04, "chrome")
+ p_box(r, "freezer_drawer", 2.27, 0.14, 1.95, "steel_brushed", (0, -1.05, 0.15), bevel=0.05, seg=3)
+ p_tube(r, "freezer_handle", [(-0.7, -1.25, 1.85), (0.7, -1.25, 1.85)], 0.04, "chrome")
+ p_box(r, "fridge_display", 0.45, 0.02, 0.6, "black_glass", (-0.55, -1.13, 4.2), bevel=0.01)
+ p_box(r, "fridge_led", 0.25, 0.01, 0.06, "led", (-0.55, -1.145, 4.55), bevel=0)
return done(r)
def washer2(x, y, rot):
+ """front-loading washing machine: porthole door with a steel drum behind tinted glass, detergent drawer, dial"""
r = item("washing_machine", x, y, rot)
- p_box(r, "wm_body", 2.0, 1.9, 2.8, "white_gloss", (0, 0, 0), bevel=0.12, seg=4)
- p_torus(r, "wm_ring", 0.55, 0.07, "chrome", (0, -0.97, 1.25), rot=(90, 0, 0))
- p_cyl(r, "wm_glass", 0.5, 0.5, 0.05, "black_glass", (0, -0.93, 1.25), rot=(90, 0, 0))
- p_box(r, "wm_panel", 1.9, 0.02, 0.4, "black_glass", (0, -0.96, 2.3), bevel=0.01)
- p_cyl(r, "wm_knob", 0.12, 0.12, 0.05, "chrome", (0.6, -0.97, 2.5), rot=(90, 0, 0))
+ p_box(r, "wm_body", 2.0, 1.9, 2.75, "white_gloss", (0, 0, 0.05), bevel=0.1, seg=3)
+ for sx in (-1, 1):
+ for sy in (-1, 1):
+ p_cyl(r, "wm_foot", 0.08, 0.08, 0.06, "black", (sx * 0.8, sy * 0.75, 0), segs=12)
+ p_box(r, "wm_seam", 1.98, 0.02, 0.02, "plastic_white", (0, -0.955, 2.25), bevel=0)
+ p_cyl(r, "wm_drum", 0.5, 0.5, 0.01, "steel_brushed", (0, -0.952, 1.2), rot=(90, 0, 0))
+ p_cyl(r, "wm_drum_hub", 0.18, 0.18, 0.012, "cast_iron", (0, -0.958, 1.2), rot=(90, 0, 0), segs=24)
+ p_torus(r, "wm_bezel", 0.6, 0.08, "plastic_white", (0, -0.97, 1.2), rot=(90, 0, 0))
+ p_torus(r, "wm_ring", 0.52, 0.05, "chrome", (0, -1.03, 1.2), rot=(90, 0, 0))
+ p_cyl(r, "wm_glass", 0.5, 0.42, 0.1, "glass", (0, -0.97, 1.2), rot=(90, 0, 0))
+ p_box(r, "wm_handle", 0.1, 0.06, 0.35, "chrome", (0.52, -1.07, 1.05), bevel=0.02)
+ p_box(r, "wm_drawer", 0.6, 0.04, 0.32, "plastic_white", (-0.6, -0.97, 2.32), bevel=0.02)
+ p_box(r, "wm_drawer_grip", 0.3, 0.02, 0.05, "black", (-0.6, -0.995, 2.45), bevel=0)
+ p_box(r, "wm_display", 0.45, 0.02, 0.22, "black_glass", (0.1, -0.965, 2.37), bevel=0.01)
+ p_box(r, "wm_digits", 0.2, 0.01, 0.06, "led", (0.1, -0.978, 2.45), bevel=0)
+ p_cyl(r, "wm_dial", 0.15, 0.13, 0.08, "chrome", (0.65, -0.95, 2.48), rot=(90, 0, 0), segs=24)
return done(r)
diff --git a/blender/thumbs.py b/blender/thumbs.py
index 672ad8a..ff0f93c 100644
--- a/blender/thumbs.py
+++ b/blender/thumbs.py
@@ -7,9 +7,8 @@ from catalog import CATALOG, CELL # noqa: E402
out, F = sys.argv[sys.argv.index("--") + 1], 0.3048
sc = bpy.context.scene
-sc.render.engine = "BLENDER_WORKBENCH"
-sc.display.shading.light, sc.display.shading.color_type = "STUDIO", "TEXTURE"
-sc.display.shading.show_shadows = True
+eng = [e.identifier for e in bpy.types.RenderSettings.bl_rna.properties["engine"].enum_items]
+sc.render.engine = "BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in eng else "BLENDER_EEVEE" # real materials, quick
sc.render.resolution_x, sc.render.resolution_y = 480, 360
cam = bpy.data.objects.new("thumb", bpy.data.cameras.new("thumb"))
sc.collection.objects.link(cam)
diff --git a/docs/furniture.png b/docs/furniture.png
index 354d9bb..5129f9e 100644
Binary files a/docs/furniture.png and b/docs/furniture.png differ
diff --git a/docs/walk.png b/docs/walk.png
index 2db3f74..ffc7dc5 100644
Binary files a/docs/walk.png and b/docs/walk.png differ
diff --git a/fetch_assets.py b/fetch_assets.py
index 247d05e..39aa5f4 100644
--- a/fetch_assets.py
+++ b/fetch_assets.py
@@ -1,4 +1,4 @@
-"""Download the CC0 textures, models and sky this project builds with, from Poly Haven, into ./assets (about 60 MB).
+"""Download the CC0 textures, models and sky this project builds with, from Poly Haven, into ./assets (about 75 MB).
python3 fetch_assets.py [--tour] files already present are skipped; --tour adds the dusk sky for blender/cinema.py
The server's home page runs the same download from its "Download materials" button."""
import json, os, sys, urllib.request
@@ -6,10 +6,11 @@ import json, os, sys, urllib.request
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")
MODELS = ["covered_car", "outdoor_table_chair_set_01", "street_lamp_01"]
TEXTURES = ["american_walnut_veneer", "anti_skid_tiles", "asphalt_02", "black_walnut_veneer_01", "caban", "concrete_floor",
- "concrete_tiles", "cotton_jersey", "dry_river_pebbles", "fabric_pattern_07", "floral_jacquard", "gingham_check",
- "granite_tile", "herringbone_pavement", "hessian_380", "laminate_floor_02", "large_floor_tiles_02", "leafy_grass",
- "long_white_tiles", "marble_01", "oak_veneer_01", "square_concrete_pavers", "terracotta_floor_tiles",
- "white_plaster_02"]
+ "concrete_tiles", "cotton_jersey", "dry_river_pebbles", "floral_jacquard", "granite_tile",
+ "herringbone_pavement", "hessian_380", "knitted_fleece", "laminate_floor_02", "large_floor_tiles_02",
+ "leafy_grass", "long_white_tiles", "marble_01", "oak_veneer_01", "quatrefoil_jacquard_fabric",
+ "rough_linen", "square_concrete_pavers", "stretch_poplin", "terracotta_floor_tiles", "terrazzo_tiles",
+ "velour_velvet", "waffle_pique_cotton", "white_plaster_02", "wool_boucle"]
SKY, TOUR_SKY = "kloofendal_48d_partly_cloudy_puresky", "qwantani_dusk_2_puresky"
UA = {"User-Agent": "planto3d-fetch/1.0"}
diff --git a/furnish.py b/furnish.py
index 5ff97f2..eaad94d 100644
--- a/furnish.py
+++ b/furnish.py
@@ -237,7 +237,7 @@ def bedroom(R):
c = x if side in "NS" else y
iv = next(((a, b) for a, b in R.free[side]["tall"] if a - 0.01 <= c <= b + 0.01), (c - bw / 2, c + bw / 2))
panel = max(0.0, min(bw + 3.2 if stands else bw + 1.0, 2 * min(c - iv[0], iv[1] - c) - 0.2))
- R.add("bed", bb, x, y, rot, w=bw, l=bl, blanket="fabric_blanket", panel=round(panel, 2))
+ R.add("bed", bb, x, y, rot, w=bw, l=bl, panel=round(panel, 2))
if stands:
for s in (-1, 1):
off = (bw / 2 + 0.8) * s
diff --git a/web/index.html b/web/index.html
index e8f2750..9c1f4b2 100644
--- a/web/index.html
+++ b/web/index.html
@@ -71,7 +71,7 @@ const FIX = {
blender: (c) => (c.version ? `Blender ${c.version} found, but 4.2 or newer is needed.` : 'Blender 4.2 or newer was not found. Install it from blender.org (or: snap install blender --classic), then restart the server.'),
pdf_tools: () => 'The PDF tools were not found. Install poppler (apt install poppler-utils, or brew install poppler).',
viewer: () => 'The 3D viewer library is missing. Run "npm install" in the project folder.',
- materials: () => 'Textures and models are not downloaded yet (about 60 MB, free CC0 files from Poly Haven).',
+ materials: () => 'Textures and models are not downloaded yet (about 75 MB, free CC0 files from Poly Haven).',
};
async function checkSystem() {
const s = await fetch('/api/system').then((r) => r.json()), m = s.materials;