Single place to convert your 2D floor plans to 3d model (no LLM)
Python
Sample plan and embed example
23f2005639ce15c27bc8e2
diff --git a/examples/embed.html b/examples/embed.htmlnew file mode 100644index 0000000..517f463--- /dev/null+++ b/examples/embed.html@@ -0,0 +1,49 @@+<!doctype html>+<!-- Minimal integration: your page uploads a plan to a PlanTo3D server, builds it and shows the walkthrough in an iframe.+ Start the server with --cors set to your site's origin (or * while trying this file from disk):+ ./run.sh --cors '*' then open this file in a browser. -->+<html lang="en">+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>PlanTo3D embed example</title>+<style>+ body { font: 15px/1.5 system-ui, sans-serif; max-width: 960px; margin: 32px auto; padding: 0 16px; }+ iframe { width: 100%; aspect-ratio: 16 / 9; border: 1px solid #ccc; border-radius: 10px; }+ #state { color: #555; }+</style>+<h1>Your site + PlanTo3D</h1>+<p><input type="file" id="file" accept="application/pdf"> <span id="state">Choose a CAD-exported plan PDF (try sample_plan.pdf).</span></p>+<iframe id="tour" hidden allow="fullscreen" title="3D walkthrough"></iframe>+<script>+const SERVER = 'http://127.0.0.1:8080'; // where PlanTo3D runs+const say = (t) => { document.getElementById('state').textContent = t; };+const api = (path, opts) => fetch(SERVER + path, opts).then(async (r) => {+ const j = await r.json();+ if (!r.ok) throw new Error(j.error);+ return j;+});+const until = async (id, stages) => { // poll the job until it reaches one of the stages+ for (;;) {+ const st = await api(`/api/jobs/${id}`);+ if (st.stage === 'failed') throw new Error(st.message);+ if (stages.includes(st.stage)) return st;+ say(st.eta_left != null ? `Building… about ${st.eta_left} s left` : st.message || 'Working…');+ await new Promise((r) => setTimeout(r, 1500));+ }+};+document.getElementById('file').onchange = async (e) => {+ try {+ say('Uploading…');+ const { id } = await api('/api/upload', { method: 'POST', body: e.target.files[0], headers: { 'X-Filename': encodeURIComponent(e.target.files[0].name) } });+ await until(id, ['detected']); // walls, doors, windows and rooms are found+ // (to let people correct the plan first, show `${SERVER}/web/edit.html?job=${id}` instead of building right away)+ await api(`/api/jobs/${id}/build`, { method: 'POST', body: JSON.stringify({ quality: 'draft' }) });+ await until(id, ['done']);+ say('Ready. Click the view, then walk with W A S D.');+ const tour = document.getElementById('tour');+ tour.src = `${SERVER}/web/view.html?job=${id}&embed`;+ tour.hidden = false;+ } catch (err) { say(`Failed: ${err.message}`); }+};+</script>+</html>diff --git a/examples/make_sample.py b/examples/make_sample.pynew file mode 100644index 0000000..b48417d--- /dev/null+++ b/examples/make_sample.py@@ -0,0 +1,99 @@+"""Draw examples/sample_plan.pdf: a made-up single-storey house in the style of a CAD export (double-line walls,+door swings, window glass lines, room names with sizes). It is the demo input and the fixture of tests/test_sample.py.+python3 examples/make_sample.py (standard library only; sizes in feet, 12 pt per foot on an A4 landscape sheet)"""+import math, os++S, OX, OY = 12.0, 205.0, 150.0 # points per foot, sheet position of the plan's lower-left corner+T, U = 0.75, 0.5 # outer / inner wall thickness+# wall runs (x0, x1, y0, y1) and the openings cut into them (kind, from, to, swing side) along their length+WALLS = [+ ((0, 36, 0, T), [("door", 9, 12.5, 1), ("window", 16.5, 20.5, 0)]), # bottom+ ((0, 36, 28 - T, 28), [("window", 13.75, 15.75, 0), ("window", 28, 33, 0)]), # top+ ((0, T, 0, 28), [("window", 22, 26, 0)]), # left+ ((36 - T, 36, 0, 28), [("window", 9.5, 13.5, 0)]), # right+ ((T, 36 - T, 14.75, 15.25), [("door", 8, 11, 1), ("door", 13.5, 16, 1), ("door", 18.75, 21.75, 1)]),+ ((22.75, 23.25, T, 14.75), [("door", 2, 5, 1)]), # living | kitchen+ ((11.75, 12.25, 15.25, 28 - T), []), # bedroom | toilet+ ((17.25, 17.75, 15.25, 28 - T), []), # toilet | bedroom+]+ROOMS = [("LIVING", "22'x14'", 11.75, 8.3), ("KITCHEN", "12'x14'", 29.25, 8.3), ("BEDROOM", "11'x12'", 6.25, 21.8),+ ("TOILET", "5'x12'", 14.75, 21.8), ("BEDROOM", "17'6x12'", 26.5, 21.8)]+EXPECT = dict(size=(36, 28), doors=5, windows=5, rooms=["bedroom", "bedroom", "kitchen", "living", "toilet"])++out = []+P = lambda x, y: (OX + x * S, OY + y * S)+pen = lambda width, grey: out.append(f"{width} w {grey} G")+line = lambda x0, y0, x1, y1: out.append("%.2f %.2f m %.2f %.2f l S" % (*P(x0, y0), *P(x1, y1)))+rect = lambda x0, x1, y0, y1: out.append("%.2f %.2f %.2f %.2f re S" % (*P(x0, y0), (x1 - x0) * S, (y1 - y0) * S))+++def text(x, y, s, size=8.0): # centred on x (Helvetica: about 0.56 em per character)+ px, py = P(x, y)+ out.append("BT /F1 %.1f Tf %.2f %.2f Td (%s) Tj ET" % (size, px - 0.28 * size * len(s), py, s))+++def swing(hx, hy, r, a0): # quarter circle from angle a0 to a0 + 90 deg around the hinge+ k, a1 = 0.5523 * r, a0 + math.pi / 2+ p0 = (hx + r * math.cos(a0), hy + r * math.sin(a0))+ p3 = (hx + r * math.cos(a1), hy + r * math.sin(a1))+ c1 = (p0[0] - k * math.sin(a0), p0[1] + k * math.cos(a0))+ c2 = (p3[0] + k * math.sin(a1), p3[1] - k * math.cos(a1))+ out.append("%.2f %.2f m %.2f %.2f %.2f %.2f %.2f %.2f c S" % (*P(*p0), *P(*c1), *P(*c2), *P(*p3)))+ line(hx, hy, *p3) # the door leaf, standing open+++for (x0, x1, y0, y1), cuts in WALLS:+ horiz = x1 - x0 > y1 - y0+ a, b = (x0, x1) if horiz else (y0, y1)+ pen(0.9, 0) # walls: the heaviest pen+ for p0, p1 in zip([a] + [c[2] for c in cuts], [c[1] for c in cuts] + [b]):+ rect(p0, p1, y0, y1) if horiz else rect(x0, x1, p0, p1)+ pen(0.3, 0.25)+ for kind, c0, c1, side in cuts:+ if kind == "window": # frame and glass lines inside the wall, jamb to jamb+ for f in (0.25, 0.5, 0.75):+ line(c0, y0 + f * (y1 - y0), c1, y0 + f * (y1 - y0)) if horiz else line(x0 + f * (x1 - x0), c0, x0 + f * (x1 - x0), c1)+ elif horiz: # door: hinged at the gap's low end, opening towards +y+ swing(c0, y1, c1 - c0, 0)+ else:+ swing(x1, c0, c1 - c0, 0)+pen(0.25, 0.78) # pale pen: floor tiles and furniture (the detector ignores pale lines)+for k in range(1, 5):+ line(12.25 + k, 15.25, 12.25 + k, 27.25)+for k in range(1, 12):+ line(12.25, 15.25 + k, 17.25, 15.25 + k)+for x0, x1, y0, y1 in ((1.2, 7.7, 20.2, 26.8), (1.5, 4.3, 24.6, 26.4), (4.6, 7.4, 24.6, 26.4), # bed, pillows+ (27.5, 34.8, 19.5, 26.8), (28, 31, 24.6, 26.4), (31.4, 34.4, 24.6, 26.4),+ (1.2, 4.2, 1.5, 4.5), (4.4, 12.4, 10.5, 13.5), (5.4, 11.4, 5.5, 8.5), # chair, sofa, table+ (33.2, 35.25, 0.75, 9), (23.25, 33.2, 12.7, 14.75), (25, 27.5, 13.1, 14.4), # counters, sink+ (12.6, 14.4, 25, 27), (15.2, 17, 24.8, 26.8), (12.6, 14.2, 15.6, 17.6)): # wc, basin, shower+ rect(x0, x1, y0, y1)+pen(0.3, 0.25) # sheet border, title box, overall sizes+out.append("20 20 802 555 re S")+out.append("600 28 214 64 re S")+for x0, y0, x1, y1 in ((0, -2.5, 36, -2.5), (0, -3, 0, -2), (36, -3, 36, -2), (-2.5, 0, -2.5, 28), (-3, 0, -2, 0), (-3, 28, -2, 28)):+ line(x0, y0, x1, y1)+out.append("0 g")+for name, size, x, y in ROOMS:+ text(x, y, name)+ text(x, y - 1.1, size, 7.0)+text(18, -5.2, "GROUND FLOOR PLAN", 12.0)+out.append("BT /F1 11 Tf 614 66 Td (SAMPLE HOUSE) Tj ET")+out.append("BT /F1 8 Tf 614 46 Td (PlanTo3D example drawing) Tj ET")++stream = "\n".join(out).encode()+objs = [b"<< /Type /Catalog /Pages 2 0 R >>", b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",+ b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 842 595] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>",+ b"<< /Length %d >>\nstream\n" % len(stream) + stream + b"\nendstream",+ b"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>"]+pdf, offs = b"%PDF-1.4\n", []+for i, o in enumerate(objs, 1):+ offs.append(len(pdf))+ pdf += b"%d 0 obj\n" % i + o + b"\nendobj\n"+xref = len(pdf)+pdf += b"xref\n0 %d\n0000000000 65535 f \n" % (len(objs) + 1) + b"".join(b"%010d 00000 n \n" % o for o in offs)+pdf += b"trailer\n<< /Size %d /Root 1 0 R >>\nstartxref\n%d\n%%%%EOF\n" % (len(objs) + 1, xref)+if __name__ == "__main__":+ path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sample_plan.pdf")+ open(path, "wb").write(pdf)+ print("wrote", path)diff --git a/examples/sample_plan.pdf b/examples/sample_plan.pdfnew file mode 100644index 0000000..5e29ab0--- /dev/null+++ b/examples/sample_plan.pdf@@ -0,0 +1,144 @@+%PDF-1.4+1 0 obj+<< /Type /Catalog /Pages 2 0 R >>+endobj+2 0 obj+<< /Type /Pages /Kids [3 0 R] /Count 1 >>+endobj+3 0 obj+<< /Type /Page /Parent 2 0 R /MediaBox [0 0 842 595] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>+endobj+4 0 obj+<< /Length 3597 >>+stream+0.9 w 0 G+205.00 150.00 108.00 9.00 re S+355.00 150.00 48.00 9.00 re S+451.00 150.00 186.00 9.00 re S+0.3 w 0.25 G+355.00 159.00 m 355.00 182.20 336.20 201.00 313.00 201.00 c S+313.00 159.00 m 313.00 201.00 l S+403.00 152.25 m 451.00 152.25 l S+403.00 154.50 m 451.00 154.50 l S+403.00 156.75 m 451.00 156.75 l S+0.9 w 0 G+205.00 477.00 165.00 9.00 re S+394.00 477.00 147.00 9.00 re S+601.00 477.00 36.00 9.00 re S+0.3 w 0.25 G+370.00 479.25 m 394.00 479.25 l S+370.00 481.50 m 394.00 481.50 l S+370.00 483.75 m 394.00 483.75 l S+541.00 479.25 m 601.00 479.25 l S+541.00 481.50 m 601.00 481.50 l S+541.00 483.75 m 601.00 483.75 l S+0.9 w 0 G+205.00 150.00 9.00 264.00 re S+205.00 462.00 9.00 24.00 re S+0.3 w 0.25 G+207.25 414.00 m 207.25 462.00 l S+209.50 414.00 m 209.50 462.00 l S+211.75 414.00 m 211.75 462.00 l S+0.9 w 0 G+628.00 150.00 9.00 114.00 re S+628.00 312.00 9.00 174.00 re S+0.3 w 0.25 G+630.25 264.00 m 630.25 312.00 l S+632.50 264.00 m 632.50 312.00 l S+634.75 264.00 m 634.75 312.00 l S+0.9 w 0 G+214.00 327.00 87.00 6.00 re S+337.00 327.00 30.00 6.00 re S+397.00 327.00 33.00 6.00 re S+466.00 327.00 162.00 6.00 re S+0.3 w 0.25 G+337.00 333.00 m 337.00 352.88 320.88 369.00 301.00 369.00 c S+301.00 333.00 m 301.00 369.00 l S+397.00 333.00 m 397.00 349.57 383.57 363.00 367.00 363.00 c S+367.00 333.00 m 367.00 363.00 l S+466.00 333.00 m 466.00 352.88 449.88 369.00 430.00 369.00 c S+430.00 333.00 m 430.00 369.00 l S+0.9 w 0 G+478.00 159.00 6.00 15.00 re S+478.00 210.00 6.00 117.00 re S+0.3 w 0.25 G+520.00 174.00 m 520.00 193.88 503.88 210.00 484.00 210.00 c S+484.00 174.00 m 484.00 210.00 l S+0.9 w 0 G+346.00 333.00 6.00 144.00 re S+0.3 w 0.25 G+0.9 w 0 G+412.00 333.00 6.00 144.00 re S+0.3 w 0.25 G+0.25 w 0.78 G+364.00 333.00 m 364.00 477.00 l S+376.00 333.00 m 376.00 477.00 l S+388.00 333.00 m 388.00 477.00 l S+400.00 333.00 m 400.00 477.00 l S+352.00 345.00 m 412.00 345.00 l S+352.00 357.00 m 412.00 357.00 l S+352.00 369.00 m 412.00 369.00 l S+352.00 381.00 m 412.00 381.00 l S+352.00 393.00 m 412.00 393.00 l S+352.00 405.00 m 412.00 405.00 l S+352.00 417.00 m 412.00 417.00 l S+352.00 429.00 m 412.00 429.00 l S+352.00 441.00 m 412.00 441.00 l S+352.00 453.00 m 412.00 453.00 l S+352.00 465.00 m 412.00 465.00 l S+219.40 392.40 78.00 79.20 re S+223.00 445.20 33.60 21.60 re S+260.20 445.20 33.60 21.60 re S+535.00 384.00 87.60 87.60 re S+541.00 445.20 36.00 21.60 re S+581.80 445.20 36.00 21.60 re S+219.40 168.00 36.00 36.00 re S+257.80 276.00 96.00 36.00 re S+269.80 216.00 72.00 36.00 re S+603.40 159.00 24.60 99.00 re S+484.00 302.40 119.40 24.60 re S+505.00 307.20 30.00 15.60 re S+356.20 450.00 21.60 24.00 re S+387.40 447.60 21.60 24.00 re S+356.20 337.20 19.20 24.00 re S+0.3 w 0.25 G+20 20 802 555 re S+600 28 214 64 re S+205.00 120.00 m 637.00 120.00 l S+205.00 114.00 m 205.00 126.00 l S+637.00 114.00 m 637.00 126.00 l S+175.00 150.00 m 175.00 486.00 l S+169.00 150.00 m 181.00 150.00 l S+169.00 486.00 m 181.00 486.00 l S+0 g+BT /F1 8.0 Tf 332.56 249.60 Td (LIVING) Tj ET+BT /F1 7.0 Tf 332.28 236.40 Td (22'x14') Tj ET+BT /F1 8.0 Tf 540.32 249.60 Td (KITCHEN) Tj ET+BT /F1 7.0 Tf 542.28 236.40 Td (12'x14') Tj ET+BT /F1 8.0 Tf 264.32 411.60 Td (BEDROOM) Tj ET+BT /F1 7.0 Tf 266.28 398.40 Td (11'x12') Tj ET+BT /F1 8.0 Tf 368.56 411.60 Td (TOILET) Tj ET+BT /F1 7.0 Tf 370.24 398.40 Td (5'x12') Tj ET+BT /F1 8.0 Tf 507.32 411.60 Td (BEDROOM) Tj ET+BT /F1 7.0 Tf 507.32 398.40 Td (17'6x12') Tj ET+BT /F1 12.0 Tf 363.88 87.60 Td (GROUND FLOOR PLAN) Tj ET+BT /F1 11 Tf 614 66 Td (SAMPLE HOUSE) Tj ET+BT /F1 8 Tf 614 46 Td (PlanTo3D example drawing) Tj ET+endstream+endobj+5 0 obj+<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>+endobj+xref+0 6+0000000000 65535 f+0000000009 00000 n+0000000058 00000 n+0000000115 00000 n+0000000241 00000 n+0000003890 00000 n+trailer+<< /Size 6 /Root 1 0 R >>+startxref+3960+%%EOF