"""Plan SVGs and 3D scene data for the invented sample house (no imagery).""" import json from shapely.geometry import Polygon import model as M D = json.load(open("model.json")); F = M.FACES T = M.T LOT = [T(p) for p in [(-6.0, -1.3), (26.0, -1.3), (26.0, 12.5), (-6.0, 12.5)]] STREET_X = max(p[0] for p in LOT) # lot's east line = street edge def plan_svg(design, w=900, h=600): s = 24.0; ox, oy = 232, 430 P = lambda x, y: (ox + x*s, oy - y*s) pts = lambda L: " ".join("%.1f,%.1f" % P(*p) for p in L) o = [f'', ''.format(design), f''] sx = P(STREET_X, 0)[0] o.append(f'') o.append(f'STREET') o.append(f'') o.append('Lot line (sample house, invented)' % P(min(p[0] for p in LOT)+0.2, 12.8)) for L, lab in [(D["front"], "Porch"), (D["patio"], "Patio")]: o.append(f'') c = Polygon(L).centroid; x, y = P(c.x, c.y) o.append(f'{lab}') used = {m["face"] for m in D["designs"][design]}; meta = D["meta"][design] for fid, f in F.items(): free = f.get("keep_free") and fid not in used o.append(f'') if free: o.append(f'') for k in meta["keepouts"]: o.append(f'') for fid in used: f = F[fid]; poly, _, org = M.usable(f, meta["clear"], [tuple(map(tuple, k)) for k in meta["keepouts"]], meta.get("vents", True)) for g in ([poly] if poly.geom_type == "Polygon" else list(poly.geoms)): o.append(f'') for m in D["designs"][design]: o.append(f'') x, y = P(m["cx"], m["cy"]); o.append(f'{m["id"]}') for v in D["vents"]: x, y = P(*v); o.append(f'') for fid, f in F.items(): c = Polygon(f["pts"]).representative_point(); x, y = P(c.x, c.y) if f.get("keep_free") and fid not in used: o.append(f'{fid} · pathway') else: o.append(f'{fid}') o.append(f'N') o.append(f'05 m10 m') c = meta["clear"] lg = [("#1f2a38", "Module 1722 × 1134 mm (ASSUMED)"), ("hatch", "Kept free: 36 in fire access pathway"), ("none", f"Setback limit: eave/rake {c['eave']} m, hip/valley {c['hip']} m, ridge {c['ridge']} m"), ("#fff", "Roof vent, 0.35 m keep-out" if meta.get("vents", True) else "Roof vent, rerouted under the array")] for i, (col, t) in enumerate(lg): yy = h - 98 + i*17 if col == "none": o.append(f'') elif col == "#fff": o.append(f'') else: o.append(f'') o.append(f'{t}') o.append(''); return "\n".join(o) def r3(L): return [[round(a, 3) for a in p] for p in L] def scene(design): faces = [] for fid, f in F.items(): org = M.origin_of(f) faces.append(dict(id=fid, pts=r3([M.from_face(f, M.to_face(f, p, org), org) for p in f["pts"]]))) mods = [dict(id=m["id"], c=r3(m["corners"])) for m in D["designs"][design]] return dict(faces=faces, mods=mods) UPPER = [T(p) for p in [(3.2,4.3),(3.2,11.5),(17.2,11.5),(17.2,4.3),(13,4.3),(13,0),(5.8,0),(5.8,4.3)]] GARAGE = [T(p) for p in [(0,0.1),(5.4,0.1),(5.4,6.9),(0,6.9)]] REAR = [T(p) for p in [(13,0),(17.2,0),(17.2,4.3)]] H = M.UPPER_EAVE_H; h = M.LOWER_EAVE_H; ridge = H + 3.6*M.TANP BODY = dict( ground=r3([(x, y, 0) for x, y in LOT]), street=r3([(STREET_X, -8, -0.01), (STREET_X+8, -8, -0.01), (STREET_X+8, 20, -0.01), (STREET_X, 20, -0.01)]), walls=[dict(poly=UPPER, h0=0, h1=H, closed=True), dict(poly=GARAGE, h0=0, h1=h, closed=True), dict(poly=REAR, h0=0, h1=h, closed=False), dict(poly=D["front"], h0=0, h1=h, closed=True)], flats=[r3([(x, y, h+0.05) for x, y in D["front"]])], tris=[r3([(*T((5.8, 0)), H), (*T((13, 0)), H), (*T((9.4, 0)), ridge)]), r3([(*T((17.2, 0)), h), (*T((17.2, 4.3)), h + 4.3*M.TANP), (*T((17.2, 4.3)), h)])], centre=[round(sum(p[0] for p in UPPER)/len(UPPER), 2), 5.7, 3], street_label=[STREET_X + 4, 6, 0]) if __name__ == "__main__": for k in "ABCDE": open(f"plan_{k}.svg", "w").write(plan_svg(k)) json.dump(dict(body=BODY, designs={k: scene(k) for k in "ABCDE"}), open("scene.json", "w")) print("ok", STREET_X)