Skip to content

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

Python

Quantities sheet: floor area per finish, paint, tiles, doors, windows, furniture

23f2005639618955f3f0ef
diff --git a/AGENTS.md b/AGENTS.md
index 7549168..af4020e 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -21,6 +21,7 @@ Needs Python 3, Node 18+, Blender 4.2+ and poppler. If Blender is not on `PATH`,
| `vector.py` | PDF page -> line segments, curves, fills, words (poppler) |
| `detect.py` | segments -> plan JSON: walls, openings, rooms, stairs, scale. Units: feet, y up |
| `furnish.py` | plan JSON -> furniture items `{fn, args, kw, box}`. Pure Python, no Blender |
+| `quantities.py` | plan JSON -> areas, paint, tiles, doors, windows, furniture counts. Also holds `FLOOR_MAT` and `opening_heights`, which `gen.py` imports, so the sheet counts what is built |
| `catalog.py` | furniture that people may replace with their own `.glb` (`assets/custom/<name>.glb`) |
| `blender/gen.py` | plan JSON -> house (run inside Blender). `CALLS` maps item `fn` to the function that builds it |
| `blender/lib.py` | materials, box meshes, furniture parts. Feet in, metres out (`F = 0.3048`) |
diff --git a/README.md b/README.md
index b967edc..d1fa49f 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,7 @@ python server.py
| **Tour** (G) | Walks itself from the entrance through every room and up the stairs, looks around in each, and records it as one video. Any key or click stops it |
| **Your own furniture** | The Furniture models page shows each item and lets you replace it with your `.glb` model |
| **Sample plan, delete** | "Try the sample plan" on the home page; every plan in the list has Delete |
+| **Quantities** | A printable sheet from the review page or the walkthrough: floor area per finish, wall paint (less doors and windows), ceiling, toilet wall tiles, a door and window schedule with sizes, and a furniture count. In m² and sq ft |
| **Blender file** | The house as one `.blend` with every texture packed inside, in a zip |
| **Website** | The walkthrough as a static website in a zip, to share without this server (see below) |
| **Furniture models in the review page** | **Change furniture models** opens the furniture page in a window, so you can swap a model and then build |
@@ -164,6 +165,7 @@ sequenceDiagram
| `GET /api/jobs/{id}` | `{ stage, progress, message, floors, eta_left }`. Stages: `detecting`, `detected`, `queued`, `building`, `done`, `failed` |
| `GET /jobs/{id}/plan.json` | The detected plan (feet): walls, openings, rooms, stairs per storey |
| `POST /api/jobs/{id}/plan` | Save an edited plan. `"furnish": false` builds empty rooms. A floor's `items` list (furniture placed on the review page) replaces the rules for that floor |
+| `GET /api/jobs/{id}/quantities` | Areas in sq ft from the saved plan: `{ floors: [{ rooms: [{ name, finish, area, paint, tiles }] }], finishes, paint, ceiling, tiles, openings, furniture }`. `/web/quantities.html?job={id}` shows it as a page |
| `GET /api/jobs/{id}/furniture` | `{ floors, catalog }`: each floor's furniture items (its own `items`, else the rules' choice) and the items that can be added |
| `POST /api/jobs/{id}/build` | Body `{ "quality": "draft" \| "high" }`. Builds run one at a time |
| `POST /api/jobs/{id}/export` | Packs the Blender file. Returns `{ url }` of the zip |
@@ -191,6 +193,7 @@ server.py web server and build queue (standard library only)
detect.py plan PDF -> plan JSON
vector.py PDF lines, curves, fills and words (poppler)
furnish.py furniture rules (pure Python)
+quantities.py areas, paint, tiles, doors, windows and furniture counts (pure Python)
catalog.py furniture that can be replaced by your own models
fetch_assets.py downloads the CC0 textures, models and sky
blender/ gen.py (build), bake.py (light maps), lib.py (parts), cinema.py (video renderer)
@@ -206,7 +209,7 @@ assets/ downloaded materials (not in git)
## Tests
```bash
-tests/run_all.sh # detector on the sample, server guards, furniture clashes, stair and wall walking
+tests/run_all.sh # detector on the sample, quantities, server guards, furniture clashes, stair and wall walking
CHROME=/path/to/chromium node tests/test_site.mjs examples/sample_plan.pdf http://127.0.0.1:8080
```
diff --git a/blender/gen.py b/blender/gen.py
index d5224d5..75c71a3 100644
--- a/blender/gen.py
+++ b/blender/gen.py
@@ -15,6 +15,7 @@ import bpy # noqa: E402
from lib import * # noqa: E402,F401
import lib # noqa: E402
import furnish # noqa: E402
+from quantities import FLOOR_MAT, TILE_H, opening_heights, zone_at # noqa: E402 (shared with the quantities sheet)
from catalog import CATALOG # noqa: E402
from mathutils import Vector # noqa: E402
@@ -41,10 +42,6 @@ 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("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",
- wash="concrete", store="concrete", study="wood", passage="tile", balcony="terracotta",
- garden="turf", open="pebbles", parking="pavers", yard="pavers", stair="stair", room="tile",
- duct="concrete")
OPEN_SKY = {"open", "garden", "yard"} # no slab above these
FINISHES = ("marble", "wood", "tile", "bathtile", "terracotta", "concrete") # as server.py FINISHES: the walkthrough can swap these
wall_hex = plan.get("wall_color") # "#rrggbb" picked on the review page (sRGB); absent = lib's warm white
@@ -78,14 +75,6 @@ def window_parts(windows):
return out
-def zone_at(f, x, y):
- for z in f["rooms"]:
- for r in z["rects"]:
- if r[0] - 0.05 <= x <= r[1] + 0.05 and r[2] - 0.05 <= y <= r[3] + 0.05:
- return z
- return None
-
-
def bbox_of(rs):
return (min(r[0] for r in rs), max(r[1] for r in rs), min(r[2] for r in rs), max(r[3] for r in rs))
@@ -94,21 +83,6 @@ def boxes_minus(base, holes):
return disjoint(subtract_all([base], holes))
-VENT_MAX = 2.6
-
-
-def opening_heights(f, o):
- r = o["rect"]
- if o["type"] != "window":
- return (-1, 7.0)
- cx, cy = (r[0] + r[1]) / 2, (r[2] + r[3]) / 2
- sides = [zone_at(f, cx, cy - 1.0), zone_at(f, cx, cy + 1.0)] if o["axis"] == "x" else \
- [zone_at(f, cx - 1.0, cy), zone_at(f, cx + 1.0, cy)]
- wet = any(z and z["type"] == "toilet" for z in sides)
- width = max(r[1] - r[0], r[3] - r[2])
- 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"}
@@ -495,7 +469,7 @@ for k, f in enumerate(floors):
MATS[f"floor_{k}_{i}"]["finish"], m = m, f"floor_{k}_{i}"
fl += [(*b[:4], -0.02, 0.0, m) for r in zn["rects"] for b in subtract_all([(*r, -0.02, 0.0)], well)]
mesh_from_boxes(f"floor_{k}", fl)
- # wall tiles to 7 ft in toilets
+ # wall tiles to TILE_H (7 ft) in toilets
# (the room's cells stop a little short of the wall face, so door holes are widened across for the tiles,
# and edges shared by two slices of the same room are not walls)
tiles = []
@@ -508,8 +482,8 @@ for k, f in enumerate(floors):
x0, x1, y0, y1 = r
tt = 0.03
own = [(q[0] - 0.05, q[1] + 0.05, q[2] - 0.05, q[3] + 0.05, -1, 99) for q in zn["rects"] if q is not r]
- tiles += subtract_all([(x0, x1, y0, y0 + tt, 0, 7), (x0, x1, y1 - tt, y1, 0, 7),
- (x0, x0 + tt, y0, y1, 0, 7), (x1 - tt, x1, y0, y1, 0, 7)], own)
+ tiles += subtract_all([(x0, x1, y0, y0 + tt, 0, TILE_H), (x0, x1, y1 - tt, y1, 0, TILE_H),
+ (x0, x0 + tt, y0, y1, 0, TILE_H), (x1 - tt, x1, y0, y1, 0, TILE_H)], own)
if tiles:
mesh_from_boxes(f"toilet_tiles_{k}", [(*b, "walltile") for b in disjoint(subtract_all(tiles, door_holes))])
# slab under this storey (k >= 1): the plan outline minus open-to-sky zones and the stairwell below
diff --git a/quantities.py b/quantities.py
new file mode 100644
index 0000000..9a56aad
--- /dev/null
+++ b/quantities.py
@@ -0,0 +1,120 @@
+"""plan JSON -> quantities: floor area per finish, wall paint, toilet wall tiles, doors and windows, furniture.
+Pure Python, in feet. blender/gen.py takes FLOOR_MAT and opening_heights from here, so the sheet counts what is built.
+Run: python3 quantities.py plan.json"""
+import re
+from collections import Counter
+
+import furnish
+from catalog import CATALOG
+
+FLOOR_MAT = dict(dress="wood", bedroom="wood", toilet="bathtile", kitchen="marble", living="marble", dining="marble", puja="marble",
+ wash="concrete", store="concrete", study="wood", passage="tile", balcony="terracotta",
+ garden="turf", open="pebbles", parking="pavers", yard="pavers", stair="stair", room="tile",
+ duct="concrete")
+PAINTED = furnish.INDOOR | {"stair"}
+TILE_H = 7.0 # toilet walls are tiled to this height (gen.py builds them so), painted above
+VENT_MAX = 2.6
+LABELS = dict(shower2="Shower", geyser="Geyser", kitchen_run="Kitchen counter", chimney="Chimney", wall_cab2="Wall cabinet",
+ rug="Rug", car="Car", outdoor_set="Outdoor table set", bathtub="Bathtub", round_rug="Round rug")
+
+
+def zone_at(f, x, y):
+ for z in f["rooms"]:
+ for r in z["rects"]:
+ if r[0] - 0.05 <= x <= r[1] + 0.05 and r[2] - 0.05 <= y <= r[3] + 0.05:
+ return z
+ return None
+
+
+def opening_heights(f, o):
+ """(sill, head) in feet above the floor; a door or bare opening starts below the floor"""
+ r = o["rect"]
+ if o["type"] != "window":
+ return (-1, 7.0)
+ cx, cy = (r[0] + r[1]) / 2, (r[2] + r[3]) / 2
+ sides = [zone_at(f, cx, cy - 1.0), zone_at(f, cx, cy + 1.0)] if o["axis"] == "x" else \
+ [zone_at(f, cx - 1.0, cy), zone_at(f, cx + 1.0, cy)]
+ wet = any(z and z["type"] == "toilet" for z in sides)
+ width = max(r[1] - r[0], r[3] - r[2])
+ return (6.0, 7.5) if wet or width <= VENT_MAX else (3.0, 7.0)
+
+
+def room_name(z):
+ return " ".join(w for w in (z.get("label") or "").split() if not re.search(r"\d", w)).title() or z["type"].title()
+
+
+def walls_of(f, z):
+ """the room's wall faces: (length, openings in it as (width, sill, head)). Edges shared by two slices of the same
+ room are not walls; an opening counts on a face when its band touches the face's line."""
+ out = []
+ for r in z["rects"]:
+ x0, x1, y0, y1 = r
+ others = [q for q in z["rects"] if q is not r]
+ for ax, line, a, b in (("x", y0, x0, x1), ("x", y1, x0, x1), ("y", x0, y0, y1), ("y", x1, y0, y1)):
+ lo, hi = (2, 3) if ax == "x" else (0, 1) # across the face
+ al, ah = (0, 1) if ax == "x" else (2, 3) # along it
+ ivs = [(a, b)]
+ for q in others:
+ if q[lo] - 0.1 <= line <= q[hi] + 0.1:
+ ivs = furnish.subtract_iv(ivs, q[al], q[ah])
+ length = sum(q - p for p, q in ivs)
+ if length < 0.05:
+ continue
+ ops = []
+ for o in f["openings"]:
+ c = o["rect"]
+ w = sum(max(0.0, min(q, c[ah]) - max(p, c[al])) for p, q in ivs)
+ if o["axis"] == ax and c[lo] - 0.5 <= line <= c[hi] + 0.5 and w > 0.05:
+ ops.append((w, *opening_heights(f, o)))
+ out.append((length, ops))
+ return out
+
+
+def wall_area(faces, h0, h1):
+ """wall between heights h0 and h1, less the openings in that band"""
+ return sum(n * (h1 - h0) - sum(w * max(0.0, min(hd, h1) - max(s, h0)) for w, s, hd in ops) for n, ops in faces)
+
+
+def quantities(plan):
+ H = plan.get("floor_height", 10.0)
+ floors, finishes, openings, items = [], Counter(), Counter(), Counter()
+ for f in plan["floors"]:
+ rooms = []
+ for z in f["rooms"]:
+ if z["type"] == "duct":
+ continue
+ area = sum((r[1] - r[0]) * (r[3] - r[2]) for r in z["rects"])
+ fin = z.get("floor") or FLOOR_MAT.get(z["type"], "tile")
+ finishes[fin] += area
+ row = dict(name=room_name(z), type=z["type"], finish=fin, area=area, paint=0.0, tiles=0.0, ceiling=0.0)
+ if z["type"] in PAINTED:
+ faces = walls_of(f, z)
+ tiled = TILE_H if z["type"] == "toilet" else 0.0
+ row.update(paint=wall_area(faces, tiled, H), tiles=wall_area(faces, 0.0, tiled), ceiling=area)
+ rooms.append(row)
+ for o in f["openings"]:
+ r = o["rect"]
+ s, hd = opening_heights(f, o)
+ openings[(o["type"], round(max(r[1] - r[0], r[3] - r[2]) * 4) / 4, hd - max(s, 0))] += 1
+ # a "model" item is a downloaded model: count it by its asset name ("potted_plant_01" -> "potted_plant")
+ items.update(re.sub(r"_\d+$", "", str(it["args"][0])) if it["fn"] == "model" else it["fn"] for it in furnish.floor_items(plan, f))
+ floors.append(dict(name=f.get("name", ""), rooms=rooms))
+ return dict(
+ floor_height=H, floors=floors, finishes=dict(finishes.most_common()),
+ paint=sum(r["paint"] for f in floors for r in f["rooms"]), tiles=sum(r["tiles"] for f in floors for r in f["rooms"]),
+ ceiling=sum(r["ceiling"] for f in floors for r in f["rooms"]),
+ openings=[dict(type=t, width=w, height=h, count=n) for (t, w, h), n in sorted(openings.items())],
+ furniture=[dict(name=CATALOG[fn][0] if fn in CATALOG else LABELS.get(fn, fn.replace("_", " ").capitalize()), count=n)
+ for fn, n in items.most_common()])
+
+
+if __name__ == "__main__":
+ import json, sys
+ q = quantities(json.load(open(sys.argv[1])))
+ for f in q["floors"]:
+ for r in f["rooms"]:
+ print(f'{f["name"]:14} {r["name"]:12} {r["finish"]:10} floor {r["area"]:7.1f} paint {r["paint"]:7.1f} tiles {r["tiles"]:6.1f} sq ft')
+ print("finishes", {k: round(v, 1) for k, v in q["finishes"].items()})
+ print("paint", round(q["paint"], 1), "tiles", round(q["tiles"], 1), "ceiling", round(q["ceiling"], 1))
+ print("openings", q["openings"])
+ print("furniture", q["furniture"])
diff --git a/server.py b/server.py
index 9dcd3b5..8b4f1d9 100644
--- a/server.py
+++ b/server.py
@@ -16,7 +16,7 @@ MAX_UPLOAD = 200 * 1024 * 1024 # plans are small; recordings sent for MP4
BUILD_TIMEOUT = 2 * 3600 # seconds; a high-quality build of a large house takes well under an hour
ID = re.compile(r"^[a-f0-9]{12}$")
sys.path.insert(0, HERE)
-import catalog, detect, fetch_assets, furnish # noqa: E402
+import catalog, detect, fetch_assets, furnish, quantities # noqa: E402
os.makedirs(JOBS, exist_ok=True)
builds = queue.Queue()
@@ -394,6 +394,16 @@ class H(BaseHTTPRequestHandler):
except Exception:
traceback.print_exc()
return self.send(500, {"error": "The furniture could not be worked out - see the server log."})
+ m = re.match(r"^/api/jobs/([a-f0-9]{12})/quantities$", p)
+ if m:
+ f = os.path.join(jdir(m.group(1)), "plan.json")
+ if not os.path.exists(f):
+ return self.send(404, {"error": "no plan yet"})
+ try:
+ return self.send(200, quantities.quantities(json.load(open(f))))
+ except Exception:
+ traceback.print_exc()
+ return self.send(500, {"error": "The quantities could not be worked out - see the server log."})
if p == "/api/system":
return self.send(200, system())
if p == "/api/jobs":
diff --git a/tests/run_all.sh b/tests/run_all.sh
index 5116770..204aa70 100755
--- a/tests/run_all.sh
+++ b/tests/run_all.sh
@@ -1,11 +1,12 @@
#!/usr/bin/env bash
-# detector on the sample drawing (and on the private fixtures when present), furniture clashes on the sample and on
+# detector on the sample drawing (and on the private fixtures when present), its quantities sheet, furniture clashes on the sample and on
# every detected plan, and stair / wall walking on every built house. The browser test is separate: tests/test_site.mjs
cd "$(dirname "$0")/.."
set -e
python3 tests/test_sample.py
python3 tests/test_detect.py
python3 tests/test_server.py
+python3 tests/test_quantities.py
python3 detect.py examples/sample_plan.pdf /tmp/planto3d_sample.json > /dev/null
for p in /tmp/planto3d_sample.json jobs/*/plan.json; do
[ -f "$p" ] || continue
diff --git a/tests/test_quantities.py b/tests/test_quantities.py
new file mode 100644
index 0000000..49da007
--- /dev/null
+++ b/tests/test_quantities.py
@@ -0,0 +1,20 @@
+"""The quantities sheet on the sample drawing, against numbers worked out by hand (feet, walls 10 ft high).
+Bedroom 11'x12' (10.75 x 11.75 inside): 45 ft of wall x 10 = 450, less a 3x7 door and a 4x4 window = 413.
+Toilet (4.75 x 11.75): 33 ft x 7 ft of tiles = 231, less a 2.5x7 door and 1 ft of a 2 ft vent (6 to 7.5 ft) = 211.5;
+painted above 7 ft: 99 less the other half foot of the vent = 98."""
+import os, sys
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.dirname(HERE))
+import detect, quantities # noqa: E402
+
+q = quantities.quantities(detect.detect(os.path.join(HERE, "..", "examples", "sample_plan.pdf")))
+rooms = {r["name"] + str(round(r["area"])): r for r in q["floors"][0]["rooms"]}
+bed, wc = rooms["Bedroom126"], rooms["Toilet56"]
+assert (bed["paint"], bed["tiles"]) == (413.0, 0.0), bed
+assert (wc["paint"], wc["tiles"]) == (98.0, 211.5), wc
+assert sum(o["count"] for o in q["openings"] if o["type"] == "door") == 5
+assert sum(o["count"] for o in q["openings"] if o["type"] == "window") == 5
+assert abs(sum(q["finishes"].values()) - sum(r["area"] for r in q["floors"][0]["rooms"])) < 1e-6
+assert {"name": "Bed", "count": 2} in q["furniture"], q["furniture"]
+print("ok quantities: paint, tiles, doors, windows and furniture of the sample")
diff --git a/web/edit.html b/web/edit.html
index 42fbde6..10a02e2 100644
--- a/web/edit.html
+++ b/web/edit.html
@@ -75,6 +75,7 @@
<h3>Furniture</h3>
<label title="Untick to build empty rooms: walls, floors, doors, windows and lights only"><input type="checkbox" id="furn" checked> Furnish the rooms</label>
<button class="btn ghost" id="models" type="button" style="margin-top:8px;width:100%">Change furniture models</button>
+ <button class="btn ghost" id="qty" type="button" style="margin-top:8px;width:100%" title="Floor areas, wall paint and tiles, doors, windows and furniture">Quantities</button>
</div>
<div>
<h3>Floor</h3>
diff --git a/web/edit.js b/web/edit.js
index f4182cb..fc14d35 100644
--- a/web/edit.js
+++ b/web/edit.js
@@ -452,6 +452,12 @@ $('build').onclick = async () => {
buildStatus({ stage: 'queued', progress: 0, message: 'Queued' });
};
poll();
+$('qty').onclick = async () => { // saved first: the sheet is worked out from the saved plan
+ const w = open('about:blank'); // opened at the click, or a popup blocker may stop it after the wait
+ plan.furnish = $('furn').checked;
+ await fetch(`/api/jobs/${job}/plan`, { method: 'POST', body: JSON.stringify(plan) }).catch(() => {});
+ if (w) w.location = `/web/quantities.html?job=${job}`;
+};
$('models').onclick = () => { // the furniture page, inside this one: replace a model, then build
$('modelsframe').src = '/web/furniture.html?embed';
$('modelsdlg').showModal();
diff --git a/web/quantities.html b/web/quantities.html
new file mode 100644
index 0000000..d298918
--- /dev/null
+++ b/web/quantities.html
@@ -0,0 +1,79 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Quantities</title>
+<link rel="stylesheet" href="/web/style.css?v=2">
+<style>
+ .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 20px 0 8px; }
+ .cards div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
+ .cards b { display: block; font-size: 20px; }
+ .cards span { color: var(--muted); font-size: 13px; }
+ h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 8px; }
+ table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; font-size: 14px; }
+ th, td { text-align: left; padding: 8px 12px; border-top: 1px solid var(--line); }
+ th { border-top: 0; font-size: 12px; color: var(--muted); font-weight: 600; }
+ td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
+ @media print { .brand, #print { display: none; } .wrap { padding-top: 0; } body { background: #fff; } }
+</style>
+</head>
+<body class="home">
+<main class="wrap" style="max-width:900px">
+ <p class="brand"><a href="/" style="color:inherit;text-decoration:none">PlanTo3D</a> · <a href="/">Home</a></p>
+ <h1 id="title">Quantities</h1>
+ <p class="muted" id="sub">Loading…</p>
+ <button class="btn ghost" id="print" type="button">Print or save as PDF</button>
+ <div class="cards" id="cards"></div>
+ <h2>Floor finishes</h2><table id="finishes"></table>
+ <h2>Rooms</h2><table id="rooms"></table>
+ <h2>Doors and windows</h2><table id="openings"></table>
+ <h2>Furniture</h2><table id="furniture"></table>
+ <p class="muted" style="font-size:13px;margin-top:20px">Measured from the plan as it is saved now. Areas are inside the walls.
+ Wall paint and tiles leave out doors and windows; toilets are tiled to 7 ft and painted above. No allowance for waste or cutting.</p>
+</main>
+<script>
+const $ = (id) => document.getElementById(id);
+const job = new URLSearchParams(location.search).get('job');
+const M2 = 0.09290304;
+const area = (ft2) => `${(ft2 * M2).toFixed(1)} m² · ${Math.round(ft2)} sq ft`;
+const ftin = (ft) => { const i = Math.round(ft * 12); return `${Math.floor(i / 12)}'${i % 12}"`; };
+const NAMES = { bathtile: 'Bathroom tiles', tile: 'Tiles', turf: 'Grass', stair: 'Stair granite' };
+const finish = (n) => NAMES[n] || n[0].toUpperCase() + n.slice(1);
+// rows of text cells (textContent: room names come from the drawing); a cell starting with '#' is a number column
+function table(id, head, rows) {
+ const tr = (cells, tag) => {
+ const r = document.createElement('tr');
+ for (const c of cells) {
+ const e = document.createElement(tag), num = String(c).startsWith('#');
+ e.textContent = num ? String(c).slice(1) : c;
+ if (num) e.className = 'n';
+ r.append(e);
+ }
+ return r;
+ };
+ $(id).replaceChildren(tr(head, 'th'), ...(rows.length ? rows : [['None']]).map((r) => tr(r, 'td')));
+}
+(async () => {
+ const [q, st] = await Promise.all([fetch(`/api/jobs/${job}/quantities`).then((r) => r.json()), fetch(`/api/jobs/${job}`).then((r) => r.json())]);
+ if (q.error) { $('sub').textContent = q.error; return; }
+ if (st.name) { $('title').textContent = `Quantities · ${st.name}`; document.title = `Quantities · ${st.name}`; }
+ $('sub').textContent = `${q.floors.length} floor${q.floors.length > 1 ? 's' : ''} · walls ${ftin(q.floor_height)} high`;
+ const floor = Object.values(q.finishes).reduce((a, b) => a + b, 0);
+ $('cards').replaceChildren(...[['Floor area', floor], ['Wall paint', q.paint], ['Ceiling paint', q.ceiling], ['Toilet wall tiles', q.tiles]]
+ .map(([t, v]) => { const d = document.createElement('div'); d.append(Object.assign(document.createElement('span'), { textContent: t }),
+ Object.assign(document.createElement('b'), { textContent: `${(v * M2).toFixed(1)} m²` }),
+ Object.assign(document.createElement('span'), { textContent: `${Math.round(v)} sq ft` })); return d; }));
+ table('finishes', ['Finish', '#Area'], Object.entries(q.finishes).map(([n, a]) => [finish(n), '#' + area(a)]));
+ const many = q.floors.length > 1;
+ table('rooms', [...(many ? ['Floor'] : []), 'Room', 'Floor finish', '#Floor', '#Wall paint', '#Wall tiles'],
+ q.floors.flatMap((f) => f.rooms.map((r) => [...(many ? [f.name] : []), r.name, finish(r.finish), '#' + area(r.area),
+ '#' + (r.paint ? area(r.paint) : '–'), '#' + (r.tiles ? area(r.tiles) : '–')])));
+ table('openings', ['Type', '#Width', '#Height', '#Count'], q.openings.map((o) =>
+ [finish(o.type), `#${ftin(o.width)} · ${(o.width * 0.3048).toFixed(2)} m`, `#${ftin(o.height)} · ${(o.height * 0.3048).toFixed(2)} m`, '#' + o.count]));
+ table('furniture', ['Item', '#Count'], q.furniture.map((f) => [f.name, '#' + f.count]));
+})().catch(() => { $('sub').textContent = 'The quantities could not be loaded.'; });
+$('print').onclick = () => print();
+</script>
+</body>
+</html>
diff --git a/web/view.html b/web/view.html
index 30a3494..396f7ed 100644
--- a/web/view.html
+++ b/web/view.html
@@ -57,7 +57,7 @@
</div>
<div id="room"></div>
<div id="cross"></div>
-<div id="bar"><button id="topbtn">Top view</button><span id="floors"></span><button id="measure" title="Measure a distance: click two points (N)">Measure</button><button id="finbtn" title="Try another wall colour, or another floor in this room (F)">Finishes</button><button id="shot" title="Save a picture of this view (P)">Screenshot</button><button id="rec" title="Record a video of your walk (R)">Record</button><button id="tour" title="Walk through every room by itself and record it as a video where this browser can record (G); any key or click stops">Tour</button><button id="blend" title="Download this house as a Blender file (.zip)">Blender file</button><button id="site" title="Download this walkthrough as a website for any web host (.zip)">Website</button><a href="/" id="newplan" style="color:#ccc;font-size:13px">Home</a><span id="fps"></span></div>
+<div id="bar"><button id="topbtn">Top view</button><span id="floors"></span><button id="measure" title="Measure a distance: click two points (N)">Measure</button><button id="finbtn" title="Try another wall colour, or another floor in this room (F)">Finishes</button><button id="shot" title="Save a picture of this view (P)">Screenshot</button><button id="rec" title="Record a video of your walk (R)">Record</button><button id="tour" title="Walk through every room by itself and record it as a video where this browser can record (G); any key or click stops">Tour</button><button id="blend" title="Download this house as a Blender file (.zip)">Blender file</button><button id="qty" title="Floor areas, wall paint and tiles, doors, windows and furniture of this plan">Quantities</button><button id="site" title="Download this walkthrough as a website for any web host (.zip)">Website</button><a href="/" id="newplan" style="color:#ccc;font-size:13px">Home</a><span id="fps"></span></div>
<div id="fin" hidden>
<div class="r" id="fwrow"><span>Wall colour</span><input type="color" id="fwall"></div>
<div class="r" id="frow" hidden><span>Floor · <b id="froom"></b></span><select id="ffloor"></select></div>
diff --git a/web/view.js b/web/view.js
index a1d5694..fadde9b 100644
--- a/web/view.js
+++ b/web/view.js
@@ -524,7 +524,8 @@ $('site').onclick = async () => { // the walkthrough as a static website
b.disabled = false;
b.textContent = 'Website';
};
-if (site) ['blend', 'site', 'newplan'].forEach((id) => $(id).remove());
+$('qty').onclick = () => open(`/web/quantities.html?job=${job}`);
+if (site) ['blend', 'site', 'qty', 'newplan'].forEach((id) => $(id).remove());
$('shot').onclick = screenshot;
$('rec').onclick = toggleRec;
$('rec').hidden = !REC_TYPE; // this browser cannot record video