Single place to convert your 2D floor plans to 3d model (no LLM)
Python
"""Interior themes: which furniture, decor, colours and floors a house is built with. Pure Python: the server lists and
checks them, furnish.py sizes the furniture by them, blender/gen.py builds them.
Built-in themes are below. People's own themes are JSON files in assets/themes/<id>.json (made on the Themes page),
with their uploaded models next to them in assets/themes/<id>/<slot>.glb.
A slot is filled by one of
"@<style>" a piece blender/gen.py draws itself ("@contemporary" is the look PlanTo3D always built)
"<model>" a Poly Haven model from LIBRARY (downloaded by fetch_assets.py into assets/models/)
"upload" the person's own .glb (custom themes only)"""
import json, os, re
HERE = os.path.dirname(os.path.abspath(__file__))
DIR = os.path.join(HERE, "assets", "themes")
# slot -> label: the furniture rules' items (named as in their furniture lists), the dining chairs, the ceiling light,
# and the decor the rules add only when a theme has something for it
SLOTS = dict(bed="Bed", nightstand="Nightstand", wardrobe="Wardrobe", desk="Desk", sofa="Sofa", coffee_table="Coffee table",
tv_unit="TV unit", dining_set="Dining table", dining_chair="Dining chair", armchair="Armchair",
light="Ceiling light", art="Wall art", mirror="Mirror", decor="Decor piece", corner="Corner piece",
bed_end="Bed bench", fridge2="Fridge", washer2="Washing machine", wc2="WC", vanity="Basin",
puja_mandir="Mandir", plant="Plant")
# built-in pieces per slot ("@contemporary" everywhere it exists; a slot missing here has no built-in piece: empty)
STYLES = dict(
bed={"@contemporary": "Upholstered bed", "@low": "Low platform bed", "@farmhouse": "Farmhouse plank bed"},
nightstand={"@contemporary": "Nightstand with a drawer"},
wardrobe={"@contemporary": "Wardrobe with bar handles", "@flat": "Handleless white wardrobe", "@classic": "Carved walnut armoire",
"@farmhouse": "Painted plank wardrobe"},
desk={"@contemporary": "Writing desk"},
sofa={"@contemporary": "Cushioned velvet sofa", "@low": "Low linen sofa"},
coffee_table={"@contemporary": "Marble tea table", "@plank": "Reclaimed plank table"},
tv_unit={"@contemporary": "Low TV unit"},
dining_set={"@contemporary": "Four-leg dining table", "@oak": "Slim oak table", "@classic": "Turned-leg walnut table"},
dining_chair={"@contemporary": "Cushioned dining chair", "@plain": "Oak and linen chair"},
light={"@contemporary": "Flush ceiling light"},
fridge2={"@contemporary": "Steel fridge"}, washer2={"@contemporary": "Front-loading washer"}, wc2={"@contemporary": "Wall-hung WC"},
vanity={"@contemporary": "Basin on a vanity"}, puja_mandir={"@contemporary": "Wooden mandir"}, plant={"@contemporary": "Potted plant"},
)
# Poly Haven models (CC0): label, size in feet as built (w across the front, d front to back, h) after turning by
# `turn` degrees so the front faces -y, and the slots that may use it. Sizes measured from the imported models.
LIBRARY = {
# minimalist
"side_table_01": ("Oak side table", 1.8, 1.48, 1.81, 0, ("nightstand", "decor")),
"coffee_table_round_01": ("Round stone coffee table", 4.27, 4.27, 1.61, 0, ("coffee_table",)),
"modern_coffee_table_01": ("Stone and oak coffee table", 3.94, 1.97, 1.28, 90, ("coffee_table",)),
"modern_wooden_cabinet": ("Slatted walnut sideboard", 8.01, 1.71, 2.23, 0, ("tv_unit",)),
"modern_arm_chair_01": ("Leather and oak armchair", 2.69, 3.24, 3.36, 0, ("armchair",)),
"mid_century_lounge_chair": ("Mid-century lounge chair", 3.31, 3.91, 3.84, 0, ("armchair",)),
"modern_ceiling_lamp_01": ("Globe pendant lamp", 1.42, 1.42, 3.12, 0, ("light",)),
"hanging_picture_frame_01": ("Black frame print", 1.95, 0.05, 2.76, 180, ("art",)),
"ceramic_vase_01": ("White ceramic vase", 0.67, 0.67, 1.31, 0, ("decor",)),
"ceramic_vase_02": ("Stoneware vase", 0.72, 0.72, 1.01, 0, ("decor",)),
"wooden_display_shelves_01": ("Cube shelves", 3.54, 1.22, 5.11, 90, ("corner",)),
"Ottoman_01": ("Leather ottoman", 2.9, 2.04, 2.05, 0, ("bed_end",)),
# royal
"GothicBed_01": ("Carved four-poster bed", 4.9, 6.69, 5.03, 0, ("bed",)),
"ClassicNightstand_01": ("Carved nightstand", 1.86, 1.39, 2.3, 0, ("nightstand",)),
"GothicCommode_01": ("Carved commode", 3.94, 1.91, 3.98, 0, ("tv_unit",)),
"ClassicConsole_01": ("Carved console table", 5.06, 1.93, 3.11, 0, ("desk", "tv_unit")),
"sofa_03": ("Rolled-arm manor sofa", 8.96, 3.04, 3.67, 0, ("sofa",)),
"Sofa_01": ("Carved camelback sofa", 5.16, 2.16, 2.61, 0, ("sofa",)),
"ArmChair_01": ("Carved bergère armchair", 2.78, 2.51, 3.49, 0, ("armchair",)),
"GreenChair_01": ("Carved green armchair", 2.21, 2.18, 3.47, 0, ("dining_chair", "armchair")),
"gothic_coffee_table": ("Carved square coffee table", 4.73, 4.73, 1.83, 0, ("coffee_table",)),
"Chandelier_01": ("Brass chandelier", 2.45, 2.68, 2.62, 0, ("light",)),
"Chandelier_02": ("Small brass chandelier", 2.23, 2.03, 2.78, 0, ("light",)),
"fancy_picture_frame_01": ("Gilded oil painting", 1.98, 0.07, 1.52, 0, ("art",)),
"ornate_mirror_01": ("Gilded mirror", 1.6, 0.09, 2.44, 0, ("mirror", "art")),
"brass_vase_02": ("Brass vase", 0.69, 0.69, 1.73, 0, ("decor",)),
"marble_bust_01": ("Marble bust", 0.89, 0.98, 1.69, 0, ("decor",)),
"vintage_grandfather_clock_01": ("Grandfather clock", 2.05, 1.4, 7.19, 0, ("corner",)),
# rustic farmhouse
"painted_wooden_nightstand": ("Painted nightstand", 1.66, 1.67, 2.02, 0, ("nightstand",)),
"painted_wooden_cabinet": ("Distressed white cabinet", 3.92, 2.02, 3.88, 0, ("tv_unit",)),
"painted_wooden_sofa": ("Painted wooden settee", 8.04, 2.58, 4.2, 0, ("sofa",)),
"Rockingchair_01": ("Rocking chair", 2.32, 2.73, 3.26, 0, ("armchair",)),
"painted_wooden_table": ("Painted trestle table", 7.89, 3.73, 3.15, 0, ("dining_set",)),
"painted_wooden_chair_01": ("White painted chair", 1.42, 1.77, 3.14, 0, ("dining_chair",)),
"painted_wooden_chair_02": ("Blue ladder-back chair", 2.1, 2.17, 4.15, 0, ("dining_chair",)),
"lantern_chandelier_01": ("Iron lantern chandelier", 1.9, 1.89, 2.88, 0, ("light",)),
"hanging_picture_frame_02": ("Landscape in white frame", 2.47, 0.11, 1.64, 180, ("art",)),
"wicker_basket_02": ("Wicker basket", 1.23, 0.89, 0.72, 0, ("decor",)),
"metal_jug": ("Milk churn", 0.65, 0.64, 0.94, 0, ("decor",)),
"painted_wooden_bench": ("Painted bench", 3.82, 1.63, 2.92, 0, ("bed_end",)),
"painted_wooden_shelves": ("Painted wall shelf", 1.68, 1.2, 3.69, 0, ("corner",)),
}
# colours (sRGB "#rrggbb") of the built-in pieces' materials: wood, kitchen and wardrobe cabinets, upholstery,
# curtains, rugs, cushions and throws. A missing one keeps the contemporary material. Built-in themes may also name
# a texture per colour (tex), whose grain or weave is kept under the colour.
COLOURS = ("wood", "cabinet", "fabric", "curtain", "rug", "accent")
FINISHES = ("marble", "wood", "parquet", "tile", "bathtile", "terracotta", "concrete") # as server.py FINISHES
THEMES = {
"contemporary": dict(label="Contemporary", about="Warm modern: walnut, velvet and marble. The look PlanTo3D has always built.",
slots={}, colours={}, floors={}, wall=None, tv=True),
"minimalist": dict(
label="Minimalist", about="Pale oak, white and grey linen, stone, and nothing more than a room needs.",
slots=dict(bed="@low", nightstand="side_table_01", wardrobe="@flat", sofa="@low", coffee_table="coffee_table_round_01",
tv_unit="modern_wooden_cabinet", dining_set="@oak", dining_chair="@plain", armchair="modern_arm_chair_01",
light="modern_ceiling_lamp_01", art="hanging_picture_frame_01", decor="ceramic_vase_01"),
colours=dict(wood="#d9bf9c", cabinet="#f1efea", fabric="#c9c6bf", curtain="#f3f0ea", rug="#d8d3ca", accent="#8c8a85"),
floors=dict(living="tile", dining="tile", kitchen="tile", passage="tile", bedroom="wood", study="wood", dress="wood"),
wall="#f4f2ee", tv=True, tex=dict(wood="ash_veneer")),
"royal": dict(
label="Royal", about="A European palace: carved dark wood, curved sofas, brass chandeliers, gilded mirrors and oil paintings.",
slots=dict(bed="GothicBed_01", nightstand="ClassicNightstand_01", wardrobe="@classic", desk="ClassicConsole_01",
sofa="sofa_03", coffee_table="gothic_coffee_table", tv_unit="GothicCommode_01", dining_set="@classic",
dining_chair="GreenChair_01", armchair="ArmChair_01", light="Chandelier_01", art="fancy_picture_frame_01",
mirror="ornate_mirror_01", decor="brass_vase_02", corner="vintage_grandfather_clock_01"),
colours=dict(wood="#4a2c1d", cabinet="#efe4cc", fabric="#6f1d2a", curtain="#7a2333", rug="#8c3b2e", accent="#c9a24a"),
floors=dict(living="marble", dining="marble", passage="marble", kitchen="marble", bedroom="parquet", study="parquet",
dress="parquet"),
wall="#ece0c8", tv=False, tex=dict(curtain="velour_velvet", rug="floral_jacquard")),
"rustic": dict(
label="Rustic farmhouse", about="Painted and weathered wood, a trestle table, gingham and linen, iron lanterns.",
slots=dict(bed="@farmhouse", nightstand="painted_wooden_nightstand", wardrobe="@farmhouse", sofa="painted_wooden_sofa",
coffee_table="@plank", tv_unit="painted_wooden_cabinet", dining_set="painted_wooden_table",
dining_chair="painted_wooden_chair_02", armchair="Rockingchair_01", light="lantern_chandelier_01",
art="hanging_picture_frame_02", decor="wicker_basket_02", corner="painted_wooden_shelves",
bed_end="painted_wooden_bench"),
colours=dict(wood="#8b6a48", cabinet="#8fa386", fabric="#bfae90", curtain="#e4dccb", rug="#b89c78", accent="#7d4b3a"),
floors=dict(living="terracotta", dining="terracotta", kitchen="terracotta", passage="terracotta", bedroom="wood",
study="wood", dress="wood"),
wall="#efe6d6", tv=True, tex=dict(curtain="gingham_check")),
}
DEFAULT = "contemporary"
TEXTURES = {v for t in THEMES.values() for v in t.get("tex", {}).values()}
ID = re.compile(r"^[a-z0-9][a-z0-9_-]{0,29}$")
HEX = re.compile(r"^#[0-9a-fA-F]{6}$")
def choices(slot):
"""what a slot may hold: built-in pieces and library models (value -> label)"""
return {**STYLES.get(slot, {}), **{m: v[0] for m, v in LIBRARY.items() if slot in v[5]}}
def check(t):
"""a theme from a browser, made safe to store: -> clean dict, or ValueError with a message a person can read"""
if not isinstance(t, dict):
raise ValueError("A theme must be a JSON object.")
label = t.get("label")
if not (isinstance(label, str) and 0 < len(label.strip()) <= 40):
raise ValueError("Give the theme a name of up to 40 characters.")
slots = t.get("slots") or {}
if not isinstance(slots, dict) or any(s not in SLOTS or not isinstance(v, str) or (v != "upload" and v not in choices(s))
for s, v in slots.items()):
raise ValueError("Unknown furniture in the theme.")
colours = t.get("colours") or {}
if not isinstance(colours, dict) or any(k not in COLOURS or not (isinstance(v, str) and HEX.match(v)) for k, v in colours.items()):
raise ValueError("Colours must look like #rrggbb.")
floors = t.get("floors") or {}
if not isinstance(floors, dict) or any(not (isinstance(k, str) and re.fullmatch(r"[a-z]{1,12}", k)) or v not in FINISHES
for k, v in floors.items()):
raise ValueError("Unknown floor finish in the theme.")
wall = t.get("wall")
if wall is not None and not (isinstance(wall, str) and HEX.match(wall)):
raise ValueError("Wall colour must look like #rrggbb.")
tex = t.get("tex") or {} # (kept from the built-in theme a copy was made from)
if not isinstance(tex, dict) or any(k not in COLOURS or v not in TEXTURES for k, v in tex.items()):
raise ValueError("Unknown texture in the theme.")
return dict(label=label.strip(), about=str(t.get("about") or "")[:200], slots=slots, colours=colours, floors=floors,
wall=wall, tv=t.get("tv") is not False, tex=tex)
def custom_ids():
return sorted(f[:-5] for f in os.listdir(DIR) if f.endswith(".json") and ID.match(f[:-5])) if os.path.isdir(DIR) else []
def load(tid):
"""the theme to build with, every slot filled: a missing or unknown id is the contemporary theme"""
tid = tid if isinstance(tid, str) else DEFAULT
if tid in THEMES:
t = dict(THEMES[tid], builtin=True)
elif ID.match(tid) and os.path.exists(os.path.join(DIR, tid + ".json")):
try:
t = dict(check(json.load(open(os.path.join(DIR, tid + ".json")))), builtin=False)
except (ValueError, json.JSONDecodeError):
tid, t = DEFAULT, dict(THEMES[DEFAULT], builtin=True)
else:
tid, t = DEFAULT, dict(THEMES[DEFAULT], builtin=True)
slots = {s: "@contemporary" if "@contemporary" in STYLES.get(s, {}) else None for s in SLOTS}
slots.update(t["slots"])
for s, v in slots.items(): # an upload whose file is gone falls back to the built-in piece
if v == "upload" and not os.path.exists(upload_path(tid, s)):
slots[s] = "@contemporary" if "@contemporary" in STYLES.get(s, {}) else None
return dict(t, id=tid, slots=slots)
def upload_path(tid, slot):
return os.path.join(DIR, tid, slot + ".glb")
def size(theme, slot):
"""(w, d, h) in feet of a slot filled by a library model, else None (built-in pieces and uploads take the rules' sizes)"""
v = theme["slots"].get(slot)
return LIBRARY[v][1:4] if v in LIBRARY else None
def has(theme, slot):
"""the theme puts something in this decor slot (contemporary has none of them)"""
return theme["slots"].get(slot) not in (None, "@contemporary")
def label(theme, slot):
v = theme["slots"].get(slot)
return LIBRARY[v][0] if v in LIBRARY else STYLES.get(slot, {}).get(v) or SLOTS[slot]