Skip to content

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

Python
2.8 KB
Raw Blame
"""The built-in pieces' default footprints (name -> label, width, depth in feet, extra arguments), and the preview row
of a theme's pieces that blender/thumbs.py photographs for the Themes page."""
CATALOG = {
    "bed": ("Bed", 5.0, 6.6, {}), "nightstand": ("Nightstand", 1.6, 1.5, {}), "wardrobe": ("Wardrobe", 6.0, 2.0, {}),
    "desk": ("Desk", 4.0, 2.0, {}), "sofa": ("Sofa", 7.0, 3.0, {}), "coffee_table": ("Coffee table", 3.6, 2.0, {}),
    "tv_unit": ("TV unit", 5.0, 1.4, {}), "dining_set": ("Dining set", 6.0, 6.4, {}), "fridge2": ("Fridge", 3.0, 2.4, {}),
    "washer2": ("Washing machine", 2.0, 2.0, {}), "wc2": ("WC", 1.5, 2.3, {}), "vanity": ("Basin", 2.6, 1.7, {}),
    "puja_mandir": ("Mandir", 3.6, 1.5, {}), "plant": ("Plant", 1.5, 1.5, {}),
}
CELL = 20.0        # the preview scene: one item in the middle of each 20 ft cell of a long room

import themes  # noqa: E402


def preview_plan(tid=None):
    """a plan with every piece of a theme standing in a row (wall pieces on the back wall, the light hung from the
    ceiling), built to render the pictures on the Themes page"""
    T = themes.load(tid)
    slots = [s for s in themes.SLOTS if T["slots"][s]]
    t, L = 0.75, len(slots) * CELL
    items = []
    for k, s in enumerate(slots):
        m = themes.size(T, s)
        w, d, h = m or (*({**{fn: (w, d) for fn, (_, w, d, _) in CATALOG.items()}, **EXTRA}[s]), 0.0)
        cx, cy, kw = k * CELL + CELL / 2, CELL / 2, {}
        if s in ("art", "mirror"):
            cy, kw = CELL - t - d / 2, dict(z=3.5)
        elif s == "light":
            kw = dict(z=round(10.0 - (h or 0.1), 2))
        elif s == "bed":
            kw = dict(w=w, l=d, **({"panel": 0.0} if themes.has(T, "art") else {}))     # as the rules build it
        elif s == "dining_set":
            kw = dict(w=w, d=d, seats=6)
        items.append(dict(fn=s, args=[cx, cy, 0], kw=kw, solid=False, room="", box=[cx - w / 2, cx + w / 2, cy - d / 2, cy + d / 2]))
    walls = [[0, L, 0, t, 0], [0, L, CELL - t, CELL, 0], [0, t, 0, CELL, 0], [L - t, L, 0, CELL, 0]]
    # an "open" room: no ceiling light of its own, and the sky lights the row evenly, as in a photo studio
    return dict(version=1, units="ft", floor_height=10.0, slab=0.5, theme=T["id"], floors=[dict(
        name="Preview", level=0, size=[L, CELL], walls=walls, openings=[], stairs=[], labels=[], items=items,
        rooms=[dict(type="open", label="", floor="wood", rects=[[t, L - t, t, CELL - t]], area=L * CELL)])])


# sizes (w, d in feet) of the theme slots that are not in CATALOG, for the preview row
EXTRA = dict(sofa=(7.0, 3.0), coffee_table=(3.6, 2.0), dining_set=(6.0, 3.2), dining_chair=(1.6, 1.7), armchair=(2.7, 3.0),
             light=(1.8, 1.8), art=(2.0, 0.1), mirror=(1.6, 0.1), decor=(0.7, 0.7), corner=(2.0, 1.4), bed_end=(3.8, 1.6))