Skip to content

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

Python

Audit of detector, bake, film renderer and tools

23f2005639a7ea115bb14a
diff --git a/blender/bake.py b/blender/bake.py
index 91e9cad..e0d8978 100644
--- a/blender/bake.py
+++ b/blender/bake.py
@@ -59,7 +59,6 @@ def _join(name, objs):
for o in vl.objects:
o.select_set(False)
target = objs[0]
- coll = target.users_collection[0]
for o in objs:
o.select_set(True)
vl.objects.active = target
@@ -126,8 +125,9 @@ def _unwrap(ob):
bpy.ops.object.mode_set(mode="OBJECT")
-def _cool_down(progress, limit=78, resume=65):
- """laptop GPUs overheat on long bakes: pause between bakes while the GPU is hot"""
+def _cool_down(progress, limit=78, resume=65, most=900):
+ """laptop GPUs overheat on long bakes: pause between bakes while the GPU is hot (at most `most` seconds:
+ a GPU kept warm by another program must not stall the build)"""
import subprocess, time
def temp():
try:
@@ -139,7 +139,8 @@ def _cool_down(progress, limit=78, resume=65):
t = temp()
if t >= limit:
progress(None, f"GPU at {t}C - cooling down")
- while temp() > resume:
+ end = time.time() + most
+ while temp() > resume and time.time() < end:
time.sleep(5)
diff --git a/blender/cinema.py b/blender/cinema.py
index 17c0abb..d4b40c5 100644
--- a/blender/cinema.py
+++ b/blender/cinema.py
@@ -1,5 +1,5 @@
"""Cinematic dusk tour of a built house (house.blend from gen.py): blue-hour sky, warm interior light with LED coves,
-garden uplights, one continuous camera glide through every room (route = tour.json), rendered frame by frame with
+one continuous camera glide through every room (route = tour.json), rendered frame by frame with
heat locks on the GPU and CPU. Resumable: frames already on disk are skipped.
blender -b JOB/house.blend -P blender/cinema.py -- TOUR.json OUTDIR [--stills t1,t2,..] [--shots SHOTS.json] [--save OUT.blend] [--frames] [--res 1920x1080]
@@ -83,7 +83,8 @@ def light(name, kind, loc, energy, color, size=None, rot=None, coll=sc.collectio
WARM, LED = (1.0, 0.72, 0.47), (1.0, 0.66, 0.38)
H = TOUR.get("ceiling", 10.0)
plan = json.load(open(TOUR["plan"]))
-INDOOR = {"bedroom", "toilet", "kitchen", "living", "dining", "puja", "study", "store", "passage", "room", "wash", "dress"}
+sys.path.insert(0, os.path.join(HERE, ".."))
+from furnish import INDOOR # noqa: E402
led = bpy.data.materials.new("cove_led")
led.use_nodes = True
em = led.node_tree.nodes.new("ShaderNodeEmission")
@@ -136,16 +137,6 @@ except Exception as e: # older Blender: shadows instead
print("light linking unavailable:", e)
for c in COVES:
c.data.use_shadow = True
-# garden: warm uplights at the trees / shrubs, wall washers on the courtyard faces
-for o in sc.objects:
- n = o.name.split("_at_")[0]
- if o.type == "EMPTY" and n in ("island_tree_01", "shrub_02", "shrub_03", "planter_box_01", "planter_pot_clay"):
- x, y = o.location.x / F, o.location.y / F
- if "tree" not in n:
- up = light("uplight", "SPOT", (x + 0.8, y - 0.6, 0.4), 60, (1.0, 0.75, 0.5),
- rot=(-20, 0, 0), spot_size=math.radians(70), spot_blend=0.8)
- up.data.use_shadow = False
-
# ------------------------------------------------------------------ restyle: warm neutrals like the reference
def tint(name, rgb, rough=None):
m = bpy.data.materials.get(name)
@@ -180,11 +171,10 @@ def recolour(name, rgb, rough=None):
n.inputs["Roughness"].default_value = rough
-for name, rgb in (("cushion", (0.5, 0.45, 0.38)), ("sofa_fabric", (0.78, 0.75, 0.7)), ("rug_round", (0.62, 0.58, 0.52)),
+for name, rgb in (("cushion", (0.5, 0.45, 0.38)), ("sofa_fabric", (1.05, 1.02, 0.97)), ("rug_round", (0.62, 0.58, 0.52)),
("rug", (0.55, 0.5, 0.44)), ("terrace", (0.82, 0.8, 0.77)), ("ceiling", (0.85, 0.83, 0.8))):
recolour(name, rgb)
-for name, rgb, rough in (("marble", (1.0, 0.97, 0.92), 0.12), ("sofa_fabric", (1.05, 1.02, 0.97), None),
- ("marble", (1.0, 0.97, 0.92), 0.12),
+for name, rgb, rough in (("marble", (1.0, 0.9409, 0.8464), 0.12), # (the tint squared: it used to be applied twice)
("tile", (1.0, 0.96, 0.9), 0.2)):
tint(name, rgb, rough)
for o in sc.objects: # flat white roof like a modern villa
@@ -192,66 +182,6 @@ for o in sc.objects: # flat white roof like a moder
o.data.materials.clear()
o.data.materials.append(bpy.data.materials["exterior"])
-# procedural date palms instead of the broad-leaf tree (lighter and right for a courtyard)
-foliage = bpy.data.materials.get("foliage")
-bark = bpy.data.materials.get("bark") or foliage
-
-
-def palm(x, y, h=15.0, seed=0):
- import random
- rnd = random.Random(seed)
- bm = bmesh.new()
- lean = Vector((rnd.uniform(-0.6, 0.6), rnd.uniform(-0.6, 0.6), 0))
- pts = [Vector((x, y, 0)) + lean * (k / 10) ** 2 + Vector((0, 0, h * k / 10)) for k in range(11)]
- for k in range(10):
- r0, r1 = 0.62 - 0.03 * k, 0.6 - 0.03 * (k + 1)
- bmesh.ops.create_cone(bm, cap_ends=False, segments=12, radius1=r0 * F, radius2=r1 * F, depth=(h / 10) * F,
- matrix=Matrix.Translation(((pts[k] + pts[k + 1]) / 2) * F))
- trunk = bpy.data.meshes.new("palm_trunk")
- bm.to_mesh(trunk)
- ob = bpy.data.objects.new("palm_trunk", trunk)
- ob.data.materials.append(bark)
- sc.collection.objects.link(ob)
- top = pts[-1]
- bm = bmesh.new()
- for i in range(16):
- az = 2 * math.pi * i / 16 + rnd.uniform(-0.15, 0.15)
- L = rnd.uniform(5.0, 6.3)
- lift = rnd.uniform(0.25, 0.6)
- dirv = Vector((math.cos(az), math.sin(az), 0))
- side = Vector((-math.sin(az), math.cos(az), 0))
- prev = None
- for k in range(13):
- sct = k / 12
- c = top + dirv * (L * sct) + Vector((0, 0, L * (lift * math.sin(math.pi * sct * 0.8) - 0.55 * sct * sct)))
- w = 1.3 * math.sin(math.pi * min(sct, 0.98)) ** 0.6 + 0.05
- a = bm.verts.new((c - side * w) * F)
- b = bm.verts.new((c + side * w) * F)
- m = bm.verts.new((c + Vector((0, 0, 0.12 * w))) * F)
- if prev:
- bm.faces.new((prev[0], a, m, prev[2]))
- bm.faces.new((prev[2], m, b, prev[1]))
- prev = (a, b, m)
- leaves = bpy.data.meshes.new("palm_leaves")
- bm.to_mesh(leaves)
- lo = bpy.data.objects.new("palm_leaves", leaves)
- lo.data.materials.append(foliage)
- sc.collection.objects.link(lo)
- return top
-
-
-PALMS = []
-for o in list(sc.objects):
- if o.type == "EMPTY" and o.name.startswith("island_tree_01"):
- x, y = o.location.x / F, o.location.y / F
- for c in o.children_recursive:
- c.hide_render = c.hide_viewport = True
- PALMS.append((x, y, palm(x, y, 15.5, seed=len(PALMS))))
-for x, y, top in PALMS:
- light("palm_up", "SPOT", (x + 1.6, y - 1.2, 0.3), 420, (1.0, 0.74, 0.48), rot=(-14, 0, 0),
- spot_size=math.radians(55), spot_blend=0.9)
-
-
# ------------------------------------------------------------------ renderer
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"
@@ -366,6 +296,9 @@ if "--frames" in argv:
sc.frame_start, sc.frame_end, sc.frame_step = opt("--start", 0), n - 1, opt("--step", 1) # step 2: odd frames blended later
sc.render.filepath = os.path.join(fd, "f_#####")
sc.render.use_overwrite, sc.render.use_placeholder = False, True # resumable: done frames are skipped
+ for f in glob.glob(os.path.join(fd, "f_*")): # an empty placeholder is a frame cut off by a stop: render it again
+ if os.path.getsize(f) == 0:
+ os.remove(f)
stamp = [time.time()]
def heat_lock(scene, *_):
diff --git a/detect.py b/detect.py
index 657b524..d7f8fbf 100644
--- a/detect.py
+++ b/detect.py
@@ -241,6 +241,8 @@ def thickness_mode(walls):
h = defaultdict(float)
for c0, c1, a0, a1 in walls:
h[round(c1 - c0, 1)] += a1 - a0
+ if not h:
+ raise PlanError("no double-line walls on this page")
best = max(h, key=lambda g: sum(v for k, v in h.items() if abs(k - g) <= 0.3))
return best
@@ -349,7 +351,6 @@ def arcs(curves):
res = []
for a, pts in merged:
cx, cy, r = a[:3]
- angs = sorted(math.atan2(p[1] - cy, p[0] - cx) for p in pts)
res.append((cx, cy, r, pts))
return res
@@ -363,6 +364,8 @@ def wall_pens(segs):
ink[col, round(w, 2)] += abs(x1 - x0) + abs(y1 - y0)
total = sum(ink.values()) or 1
big = {k: v for k, v in ink.items() if v >= 0.05 * total}
+ if not big: # no straight lines worth a wall (a rotated site plan, a sketch)
+ raise PlanError("no straight wall lines on this page")
wmax = max(k[1] for k in big)
pens = {k for k in ink if k[1] >= 0.6 * wmax}
# walls are plotted in black / grey; coloured wide pens are window frames, columns, beams
@@ -970,8 +973,8 @@ def detect(pdf):
pg = detect_page(page)
except PlanError:
continue
- for f in pg["floors"]:
- f["page"] = k
+ for f in pg["floors"]: # pages of one PDF can be drawn at different scales
+ f.update(page=k, scale_pt_per_ft=round(pg["scale"], 4), scale_source=pg["scale_source"])
pages.append(pg)
if lines < 150: # any page of a CAD plan has thousands of lines; a cover sheet before the plans does not count
raise PlanError("This PDF has almost no vector lines - it looks like a scan or photo. "
@@ -992,7 +995,7 @@ def detect(pdf):
f["name"] = (f["title"] or f"Floor {i}").title().replace(" Plan", "")
p0 = pages[0]
return dict(version=1, source=pdf.rsplit("/", 1)[-1], units="ft", scale_pt_per_ft=round(p0["scale"], 4),
- scale_source=p0["scale_source"], wall_pt=round(p0["T"], 2), floor_height=10.0, slab=0.5,
+ scale_source="labels" if all(p["scale_source"] == "labels" for p in pages) else "assumed", wall_pt=round(p0["T"], 2), floor_height=10.0, slab=0.5,
floors=floors)
diff --git a/examples/make_sample.py b/examples/make_sample.py
index b48417d..2c0883d 100644
--- a/examples/make_sample.py
+++ b/examples/make_sample.py
@@ -82,17 +82,24 @@ 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)
+
+
+def pdf_page(stream):
+ """a one-page A4 landscape PDF drawing `stream` (PDF drawing operators; font F1 = Helvetica)"""
+ 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)
+ return pdf + b"trailer\n<< /Size %d /Root 1 0 R >>\nstartxref\n%d\n%%%%EOF\n" % (len(objs) + 1, xref)
+
+
+pdf = pdf_page(stream)
if __name__ == "__main__":
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sample_plan.pdf")
open(path, "wb").write(pdf)
diff --git a/tests/test_sample.py b/tests/test_sample.py
index 162d4b5..a4abad4 100644
--- a/tests/test_sample.py
+++ b/tests/test_sample.py
@@ -22,3 +22,19 @@ for k, *r in drawn:
assert any(o["type"] == k and all(abs(a - b) < 0.1 for a, b in zip(o["rect"], r)) for o in f["openings"]), (k, r)
print("ok sample plan: %d walls, %d doors, %d windows, %d rooms, scale %.1f pt/ft" % (
len(f["walls"]), kinds.count("door"), kinds.count("window"), len(f["rooms"]), plan["scale_pt_per_ft"]))
+
+# more pages: a sheet of slanted lines (a rotated site plan) is skipped, and a page drawn at another scale keeps it
+import subprocess, tempfile # noqa: E402
+with tempfile.TemporaryDirectory() as d:
+ pages = [os.path.join(HERE, "..", "examples", "sample_plan.pdf")]
+ for k, stream in enumerate((b"".join(b"%d 10 m %d 400 l S\n" % (10 + 2 * i, 60 + 2 * i) for i in range(200)),
+ b"q 0.75 0 0 0.75 0 0 cm\n" + M.stream + b"\nQ")):
+ pages.append(os.path.join(d, f"p{k}.pdf"))
+ open(pages[-1], "wb").write(M.pdf_page(stream))
+ subprocess.run(["pdfunite", *pages, os.path.join(d, "all.pdf")], check=True)
+ many = detect.detect(os.path.join(d, "all.pdf"))
+fs = many["floors"]
+assert [f["page"] for f in fs] == [1, 3], [f["page"] for f in fs]
+assert abs(fs[0]["scale_pt_per_ft"] - M.S) < 0.02 * M.S and abs(fs[1]["scale_pt_per_ft"] - 0.75 * M.S) < 0.02 * M.S, fs
+assert all(abs(a - b) < 0.1 for f in fs for a, b in zip(f["size"], M.EXPECT["size"])), [f["size"] for f in fs]
+print("ok more pages: a sheet without walls skipped, each page read at its own scale")
diff --git a/tests/test_server.py b/tests/test_server.py
index ac58f07..6b2d201 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -5,7 +5,8 @@ import json, os, shutil, subprocess, sys, tempfile, threading, urllib.error, url
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
-sys.path.insert(0, ROOT)
+sys.path[:0] = [ROOT, os.path.join(ROOT, "examples")]
+import make_sample as M # noqa: E402
import server # noqa: E402
server.JOBS = tempfile.mkdtemp() # never touch the real jobs folder
@@ -47,16 +48,7 @@ try:
# 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")
- 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 612 792]>>"]
- pdf, offs = b"%PDF-1.4\n", []
- for k, o in enumerate(objs, 1):
- offs.append(len(pdf))
- pdf += b"%d 0 obj%s endobj\n" % (k, o)
- xref = len(pdf)
- pdf += b"xref\n0 4\n0000000000 65535 f \n" + b"".join(b"%010d 00000 n \n" % o for o in offs)
- pdf += b"trailer<</Size 4/Root 1 0 R>>\nstartxref\n%d\n%%%%EOF\n" % xref
- open(cover, "wb").write(pdf)
+ open(cover, "wb").write(M.pdf_page(b""))
jid = job("uploaded")
subprocess.run(["pdfunite", cover, os.path.join(ROOT, "examples", "sample_plan.pdf"),
os.path.join(server.jdir(jid), "source.pdf")], check=True)
diff --git a/tools/dbg_plan.py b/tools/dbg_plan.py
index efc63aa..a2da900 100644
--- a/tools/dbg_plan.py
+++ b/tools/dbg_plan.py
@@ -5,11 +5,11 @@ import debug_draw, detect, vector # noqa: E402
pdf, js, out = sys.argv[1:4]
P = json.load(open(js))
-s = P["scale_pt_per_ft"]
layers = []
COL = dict(door=(0, 170, 0, 200), window=(0, 90, 255, 200), opening=(255, 200, 0, 220))
for f in P["floors"]:
X0, Y1 = f["origin_pt"]
+ s = f.get("scale_pt_per_ft", P["scale_pt_per_ft"])
R = lambda r: (X0 + r[0] * s, X0 + r[1] * s, Y1 - r[3] * s, Y1 - r[2] * s)
random.seed(1)
for rm in f["rooms"]:
diff --git a/tools/debug_draw.py b/tools/debug_draw.py
index 275f1bd..afaa124 100644
--- a/tools/debug_draw.py
+++ b/tools/debug_draw.py
@@ -4,10 +4,10 @@ from PIL import Image, ImageDraw
def page_image(pdf, page=1, dpi=150):
- d = tempfile.mkdtemp()
- subprocess.run(["pdftocairo", "-png", "-r", str(dpi), "-f", str(page), "-l", str(page), "-singlefile",
- pdf, os.path.join(d, "p")], check=True)
- return Image.open(os.path.join(d, "p.png")).convert("RGB")
+ with tempfile.TemporaryDirectory() as d:
+ subprocess.run(["pdftocairo", "-png", "-r", str(dpi), "-f", str(page), "-l", str(page), "-singlefile",
+ pdf, os.path.join(d, "p")], check=True)
+ return Image.open(os.path.join(d, "p.png")).convert("RGB")
def draw(pdf, layers, out, page=1, dpi=150, crop=None):
diff --git a/tools/record.mjs b/tools/record.mjs
index 3c81099..f210c56 100644
--- a/tools/record.mjs
+++ b/tools/record.mjs
@@ -9,6 +9,7 @@ const CH = process.env.CHROME || 'chromium';
const port = 9400 + Math.floor(Math.random() * 400);
const ch = spawn(CH, ['--headless=new', '--no-sandbox', `--remote-debugging-port=${port}`, '--window-size=1280,720',
'--hide-scrollbars', '--use-angle=gl-egl', '--ignore-gpu-blocklist', '--enable-gpu', 'about:blank'], { stdio: 'ignore' });
+process.on('exit', () => ch.kill()); // also when a frame fails: no headless Chrome left on the GPU
const sleep = (t) => new Promise((r) => setTimeout(r, t));
let targets;
for (let i = 0; i < 100 && !targets; i++) { try { targets = await (await fetch(`http://127.0.0.1:${port}/json`)).json(); } catch { await sleep(200); } }
@@ -36,5 +37,4 @@ for (let i = 0; i < frames.length; i++) {
if (i % 500 === 0) console.log(`frame ${i}/${frames.length} ${((Date.now() - t0) / 1000).toFixed(0)} s`);
}
console.log(`done ${frames.length} frames in ${((Date.now() - t0) / 1000).toFixed(1)} s`);
-ch.kill();
process.exit(0);
diff --git a/web/edit.js b/web/edit.js
index dff19fe..6f75960 100644
--- a/web/edit.js
+++ b/web/edit.js
@@ -83,6 +83,7 @@ function buildStatus(st) {
// ---------------------------------------------------------------- geometry helpers
const F = () => plan.floors[fi];
+const scaleOf = (f) => f.scale_pt_per_ft || plan.scale_pt_per_ft; // each page of the PDF has its own (older plans: one)
const toC = (x, y) => [view.ox + x * view.k, view.oy - y * view.k];
const toP = (X, Y) => [(X - view.ox) / view.k, (view.oy - Y) / view.k];
const inR = (r, x, y, m = 0) => x >= r[0] - m && x <= r[1] + m && y >= r[2] - m && y <= r[3] + m;
@@ -103,7 +104,7 @@ function snapshot() { history.push(JSON.stringify(plan)); if (history.length > 5
function rectC(r) { const [a, b] = toC(r[0], r[3]), [c, d] = toC(r[1], r[2]); return [a, b, c - a, d - b]; }
// floor j's plan coordinates -> the current floor's (both are measured from their own lower-left corner)
function offsetOf(j) {
- const s = plan.scale_pt_per_ft, a = F().origin_pt, b = plan.floors[j].origin_pt;
+ const s = scaleOf(F()), a = F().origin_pt, b = plan.floors[j].origin_pt; // (j is on the same page)
return [(b[0] - a[0]) / s, (a[1] - b[1]) / s];
}
function drawFloor(f, dx, dy, active) {
@@ -142,7 +143,7 @@ function draw() {
cv.width = cv.clientWidth * dpr; cv.height = cv.clientHeight * dpr;
g.setTransform(dpr, 0, 0, dpr, 0, 0);
g.clearRect(0, 0, cv.clientWidth, cv.clientHeight);
- const f = F(), s = plan.scale_pt_per_ft, im = img[f.page || 1];
+ const f = F(), s = scaleOf(f), im = img[f.page || 1];
if (im?.complete) {
const sc = view.k / (s * D);
g.globalAlpha = 0.45;
@@ -161,8 +162,9 @@ function ui() {
document.querySelectorAll('#tabs button').forEach((b, i) => b.classList.toggle('on', i === fi));
const f = F();
$('fname').value = f.name;
- $('scale').textContent = `${plan.floors.length} floor${plan.floors.length > 1 ? 's' : ''} · scale ${plan.scale_source === 'labels'
- ? 'read from room sizes' : 'GUESSED - use Set scale'}`;
+ const src = f.scale_source || plan.scale_source;
+ $('scale').textContent = `${plan.floors.length} floor${plan.floors.length > 1 ? 's' : ''} · scale ${src === 'labels'
+ ? 'read from room sizes' : src === 'user' ? 'set by you' : 'GUESSED - use Set scale'}`;
const P = $('props');
P.innerHTML = '';
if (!sel) { P.innerHTML = `<h3>Selection</h3><p class="muted" style="font-size:13px">${f.walls.length} walls, ${f.openings.length} openings, ${f.rooms.length} rooms</p>`; draw(); return; }
@@ -245,15 +247,16 @@ function parseFeet(s) {
function rescale(k) {
snapshot();
const R = (r) => { for (let i = 0; i < 4; i++) r[i] *= k; };
- for (const f of plan.floors) {
+ const page = F().page || 1;
+ for (const f of plan.floors.filter((o) => (o.page || 1) === page)) { // the other pages keep their own scale
f.walls.forEach(R); f.openings.forEach((o) => { R(o.rect); if (o.hinge) o.hinge = o.hinge.map((v) => v * k); });
f.rooms.forEach((z) => { z.rects.forEach(R); z.area = +(z.area * k * k).toFixed(1); });
(f.stairs || []).forEach((s) => { R(s.rect); s.words = s.words.map(([t, x, y]) => [t, x * k, y * k]); });
(f.labels || []).forEach((l) => { l.at = l.at.map((v) => v * k); });
f.size = f.size.map((v) => v * k);
+ f.scale_pt_per_ft = scaleOf(f) / k;
+ f.scale_source = 'user';
}
- plan.scale_pt_per_ft /= k;
- plan.scale_source = 'user';
}
let drag = null;