Single place to convert your 2D floor plans to 3d model (no LLM)
Python
"""Furniture rules on small made-up rooms: a door-wide gap in a wall is kept clear like a doorway, plants stand at the
walls, a small living room gets no armchair or corner piece, and the vase stands on the unit at its scaled height.
python3 tests/test_furnish.py"""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import furnish, themes # noqa: E402
from furnish import overlap # noqa: E402
T = 0.33 # wall thickness
def room(kind, w, d, gaps=(), doors=()):
"""a w x d room of one type, walled all round; gaps: (x0, x1) left open in the north wall; doors: (x0, x1) there"""
holes = sorted(list(gaps) + list(doors))
north, x = [], 0.0
for a, b in holes:
north.append([x, a, d, d + T, 0])
x = b
north.append([x, w, d, d + T, 0])
walls = [[-T, w + T, -T, 0, 0], [-T, 0, 0, d, 0], [w, w + T, 0, d, 0]] + north
ops = [dict(type="door", rect=[a, b, d, d + T], axis="x") for a, b in doors]
return dict(walls=walls, openings=ops, rooms=[dict(type=kind, label=kind, rects=[[0, w, 0, d]])], stairs=[], floor_height=10.0)
def items(floor, theme="royal"):
its = furnish.furnish_floor(floor, themes.load(theme))
assert not furnish.clashes(its, floor), furnish.clashes(its, floor)
return its
# a kitchen with a door and, beside it, a gap with no door: the fridge keeps 3 ft clear of both
k = room("kitchen", 7.5, 10.5, gaps=[(4.0, 7.5)], doors=[(1.2, 3.7)])
fridge = [it for it in items(k) if it["fn"] == "fridge2"]
assert fridge and not overlap(fridge[0]["box"], (4.0, 7.5, 7.5, 10.5), 0.02), fridge
# a whole side open to the next room is open plan, not a doorway: it keeps nothing away
assert furnish.Room(room("puja", 7.5, 3.0, gaps=[(0.0, 7.5)])["rooms"][0], room("puja", 7.5, 3.0, gaps=[(0.0, 7.5)])).keepout == []
print("ok furnish: a gap in a wall is kept clear like a doorway")
# plants: in the corners and along the sides, never out in the middle
b = room("balcony", 26.0, 8.0)
for it in items(b):
if it["fn"] == "plant":
x0, x1, y0, y1 = it["box"]
assert min(x0, 26.0 - x1, y0, 8.0 - y1) < 0.2, it["box"]
print("ok furnish: plants stand at the walls")
# a 10 x 10 living room: sofa, table and a unit; the armchair and the corner piece only in a bigger one
small = {it["fn"] for it in items(room("living", 10.0, 10.0))}
big = {it["fn"] for it in items(room("living", 14.0, 14.0))}
assert {"sofa", "coffee_table", "tv_unit"} <= small and not small & {"armchair", "corner"}, small
assert {"armchair", "corner"} <= big, big
# the vase stands on the unit as built: a model scaled down to its box is lower than the library says
for n in (10.0, 12.0, 14.0):
its = items(room("living", n, n))
unit = [it for it in its if it["fn"] == "tv_unit"]
for vase in (it for it in its if it["fn"] == "decor"):
w, _, h = themes.size(themes.load("royal"), "tv_unit")
x0, x1, y0, y1 = unit[0]["box"]
assert abs(vase["kw"]["z"] - h * max(x1 - x0, y1 - y0) / w) < 0.02, (n, vase["kw"], unit[0]["box"])
print("ok furnish: a small living room is not crowded, the vase stands on its unit")