Skip to content

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

Python

Merge #3: download the walkthrough as a self-contained website

23f200563948b94e1e4b99
diff --cc README.md
index eac5f16,ecc15f7..885b3a4
--- a/README.md
+++ b/README.md
@@@ -160,10 -158,10 +161,11 @@@ sequenceDiagra
| `POST /api/upload` | Body: the PDF. Header `X-Filename`. Returns `{ id }` and starts detection |
| `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 |
+| `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}/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 |
+ | `POST /api/jobs/{id}/site` | Packs the walkthrough as a static website. Returns `{ url }` of the zip |
| `GET /web/view.html?job={id}` | The walkthrough. `&embed` hides the link back to the upload page |
| `GET /web/edit.html?job={id}` | The review page |
| `GET /api/jobs` | The 30 most recent plans |
diff --cc server.py
index eb00756,f6eb63c..15f3534
--- a/server.py
+++ b/server.py
@@@ -3,7 -3,7 +3,7 @@@ Standard library only. Run: python3 ser
Builds run one at a time in Blender (GPU) in a background thread; progress is polled by the pages.
--cors lets pages on another site call the API from the browser (ORIGIN such as https://example.com, or *).
There is no login: run it on a trusted network, or behind your own backend or proxy."""
- import importlib, json, math, os, queue, re, shutil, subprocess, sys, threading, time, traceback, uuid, zipfile
-import importlib, json, os, posixpath, queue, re, shutil, subprocess, sys, threading, time, traceback, uuid, zipfile
++import importlib, json, math, os, posixpath, queue, re, shutil, subprocess, sys, threading, time, traceback, uuid, zipfile
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse, unquote
diff --cc tests/test_server.py
index aac5493,8b5cc6e..17b4b5a
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@@ -1,7 -1,7 +1,8 @@@
"""The server's guards, without Blender: files outside the web folders stay hidden, a plan that is being read or built
-cannot be changed or deleted, bad request bodies get an answer, and a cover sheet before the plan is not taken for a
-scan. python3 tests/test_server.py"""
+cannot be changed or deleted, bad request bodies get an answer, furniture from the review page reaches Blender only
- as known items with plain values, and a cover sheet before the plan is not taken for a scan. python3 tests/test_server.py"""
- import json, os, shutil, subprocess, sys, tempfile, threading, urllib.error, urllib.request
++as known items with plain values, the website zip holds the viewer and the house only, and a cover sheet before the
++plan is not taken for a scan. python3 tests/test_server.py"""
+ import json, os, shutil, subprocess, sys, tempfile, threading, urllib.error, urllib.request, zipfile
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
@@@ -42,47 -42,25 +43,62 @@@ try
assert call("POST", f"/api/jobs/{done}/plan", b"not json")[0] == 400
assert call("POST", f"/api/jobs/{done}/plan", b'{"floors": [{"name": "G"}]}')[0] == 200
assert json.load(open(os.path.join(server.jdir(done), "plan.json")))["floors"][0]["name"] == "G"
+ # room finishes and wall colour reach Blender as material names and colours: only known values pass
+ plan = lambda room, **kw: json.dumps({"floors": [{"rooms": [room]}], **kw}).encode()
+ for bad in (plan({"floor": "lava"}), plan({"floor": ["wood"]}), plan({}, wall_color="red"), plan({}, wall_color="#12345g"),
+ plan({}, wall_color="#123456\n"), plan({}, wall_color=None)):
+ assert call("POST", f"/api/jobs/{done}/plan", bad)[0] == 400, bad
+ assert call("POST", f"/api/jobs/{done}/plan", plan({"floor": "wood"}, wall_color="#C3cdb4"))[0] == 200
+ saved = json.load(open(os.path.join(server.jdir(done), "plan.json")))
+ assert saved["floors"][0]["rooms"][0]["floor"] == "wood" and saved["wall_color"] == "#C3cdb4"
assert call("POST", f"/api/jobs/{done}/export")[0] == 400 # nothing built yet
+ assert call("POST", f"/api/jobs/{done}/site")[0] == 400 # nothing built yet
assert call("DELETE", f"/api/jobs/{done}")[0] == 200 and not os.path.exists(server.jdir(done))
- print("ok server: hidden files, busy plans, bad bodies")
+ print("ok server: hidden files, busy plans, bad bodies, room finishes")
+
+ # furniture: the rules' list until the review page sends its own; an empty list is an empty floor
+ jid = job("detected")
+ assert call("GET", f"/api/jobs/{jid}/furniture")[0] == 404 # not read yet
+ plan = detect.detect(os.path.join(ROOT, "examples", "sample_plan.pdf"))
+ json.dump(plan, open(os.path.join(server.jdir(jid), "plan.json"), "w"))
+ code, out = call("GET", f"/api/jobs/{jid}/furniture")
+ out = json.loads(out)
+ assert code == 200 and len(out["floors"]) == len(plan["floors"]) and "bed" in out["catalog"], out
+ rules = out["floors"][0]
+ assert {"bed", "kitchen_run", "wall_cab2"} <= {it["fn"] for it in rules}
+ post = lambda p: call("POST", f"/api/jobs/{jid}/plan", json.dumps(p).encode())[0]
+ plan["floors"][0]["items"] = rules # the rules' own items pass as they are
+ assert post(plan) == 200
+ plan["floors"][0]["items"] = []
+ assert post(plan) == 200 and json.loads(call("GET", f"/api/jobs/{jid}/furniture")[1])["floors"][0] == []
+ bed = next(it for it in rules if it["fn"] == "bed")
+ for bad in (dict(bed, fn="model", args=["../../x", 1, 1, 0]), dict(bed, fn="nope"), dict(bed, args=[1, "../x", 0]),
+ dict(bed, args=[1, float("nan"), 0]), dict(bed, box=[0, 1, 2]), dict(bed, kw={"w": [5]}),
+ dict(bed, kw={"a/b": 1}), dict(bed, kw={"m": "rug\n"}), dict(bed, kw=None), dict(bed, fn=[]), "bed"):
+ plan["floors"][0]["items"] = [bad]
+ assert post(plan) == 400, bad
+ plan["floors"][0]["items"] = [bed] * 401
+ assert post(plan) == 400
+ plan["floors"][0]["items"] = [dict(bed, args=[1, 2, 90])]
+ assert post(plan) == 200
+ plan["furnish"] = False
+ assert post(plan) == 200 and json.loads(call("GET", f"/api/jobs/{jid}/furniture")[1])["floors"] == [[]] * len(plan["floors"])
+ print("ok server: furniture lists, item checks")
+ # the website zip: the viewer, the three.js it loads and the house, and nothing else from the job folder
+ built = job("done")
+ for f, data in (("meta.json", b'{"lightmaps": {"bake_level_0": "lm_bake_level_0.webp"}}'), ("house.glb", b"glTF"),
+ ("lm_bake_level_0.webp", b"RIFF"), ("source.pdf", b"%PDF"), ("plan.json", b"{}")):
+ open(os.path.join(server.jdir(built), f), "wb").write(data)
+ code, body = call("POST", f"/api/jobs/{built}/site")
+ assert code == 200, body
+ names = zipfile.ZipFile(os.path.join(server.jdir(built), "house_site.zip")).namelist()
+ for f in ("index.html", "view.js", "walk.js", "three/build/three.module.js", "three/examples/jsm/libs/draco/draco_decoder.wasm",
+ "house/meta.json", "house/house.glb", "house/lm_bake_level_0.webp"):
+ assert f in names, f
+ assert not [f for f in names if f.endswith(("source.pdf", "plan.json", "status.json"))], names
+ print("ok server: website zip")
+
# a title sheet with no drawing before the plan: the plan on page 2 is found, and its page is the one drawn
cover = os.path.join(server.JOBS, "cover.pdf")
open(cover, "wb").write(M.pdf_page(b""))
diff --cc web/view.html
index c6cfe00,57c652b..1fe83f6
--- a/web/view.html
+++ b/web/view.html
@@@ -50,7 -48,7 +50,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="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="blend" title="Download this house as a Blender file (.zip)">Blender file</button><a href="/" id="newplan" style="color:#ccc;font-size:13px">Home</a><span id="fps"></span></div>
- <script type="module" src="/web/view.js"></script>
-<div id="bar"><button id="topbtn">Top view</button><span id="floors"></span><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="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="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="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>
+ <script type="module" src="view.js"></script>
</body>
</html>