Single place to convert your 2D floor plans to 3d model (no LLM)
Python
"""Interior themes without Blender: the built-in themes only name pieces that exist, every library model is downloaded
by fetch_assets.py, the furniture rules furnish the sample in every theme without clashes (decor where a theme has it),
and people's own themes are checked before they are stored. python3 tests/test_themes.py"""
import json, os, sys, tempfile
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(HERE))
import detect, fetch_assets, furnish, themes # noqa: E402
for tid, t in themes.THEMES.items():
assert themes.check(t)["slots"] == t["slots"], tid # every piece is one the slot may hold
for m, (label, w, d, h, turn, slots) in themes.LIBRARY.items():
assert m in fetch_assets.MODELS and min(w, d, h) > 0 and turn in (0, 90, 180, 270), m
assert set(slots) <= set(themes.SLOTS), m
assert themes.load(None)["id"] == themes.load("nope")["id"] == themes.load("../royal")["id"] == "contemporary"
print("ok themes: built-in pieces exist, library models are downloaded")
plan = detect.detect(os.path.join(HERE, "..", "examples", "sample_plan.pdf"))
f = plan["floors"][0]
items = {tid: furnish.furnish_floor(f, themes.load(tid)) for tid in themes.THEMES}
for tid, its in items.items():
assert not furnish.clashes(its, f), (tid, furnish.clashes(its, f))
fns = {tid: {it["fn"] for it in its} for tid, its in items.items()}
assert not fns["contemporary"] & {"art", "mirror", "decor", "corner", "armchair", "bed_end"}, fns["contemporary"]
assert not any("piece" in it["kw"] for it in items["contemporary"])
assert {"art", "mirror", "decor", "corner", "armchair"} <= fns["royal"], fns["royal"]
assert {"bed_end", "corner", "armchair"} <= fns["rustic"], fns["rustic"]
bed = next(it for it in items["royal"] if it["fn"] == "bed")
dims = sorted((bed["box"][1] - bed["box"][0], bed["box"][3] - bed["box"][2]))
assert abs(dims[0] - 4.9) < 0.01 and abs(dims[1] - 6.69) < 0.01, bed["box"] # the model at its own size
print("ok themes: the sample furnished in every theme, decor where the theme has it")
themes.DIR = tempfile.mkdtemp()
for bad in ([], {}, {"label": ""}, {"label": "x" * 41}, {"label": "a", "slots": {"bed": "../../etc"}},
{"label": "a", "slots": {"sink": "@contemporary"}}, {"label": "a", "slots": {"bed": "sofa_03"}},
{"label": "a", "colours": {"wood": "brown"}}, {"label": "a", "colours": {"lava": "#123456"}},
{"label": "a", "floors": {"living": "lava"}}, {"label": "a", "wall": "#12345"}):
try:
themes.check(bad)
raise AssertionError(bad)
except ValueError:
pass
t = themes.check({"label": " Mine ", "slots": {"bed": "upload", "sofa": "sofa_03"}, "colours": {"wood": "#112233"}, "evil": 1})
assert t["label"] == "Mine" and "evil" not in t
json.dump(t, open(os.path.join(themes.DIR, "mine.json"), "w"))
m = themes.load("mine")
assert m["id"] == "mine" and m["slots"]["sofa"] == "sofa_03" and m["slots"]["bed"] == "@contemporary" # (no upload on disk)
assert themes.custom_ids() == ["mine"]
print("ok themes: own themes are checked, stored and loaded")