Download demo/plan_data.py from dellweb3/build3d: direct link, hf CLI and curl.
- Browser
- Download file 4.8 kB
-
https://huggingface.co/spaces/dellweb3/build3d/resolve/main/demo/plan_data.py
- Command line
-
hf download hf://spaces/dellweb3/build3d/demo/plan_data.py
-
curl -L -o plan_data.py https://huggingface.co/spaces/dellweb3/build3d/resolve/main/demo/plan_data.py
4.8 kB
| # -*- coding: utf-8 -*- | |
| """ | |
| 多视角图纸数据 —— 单一数据源(Single Source of Truth) | |
| 6 栋楼 × 5 个视角 = 30 张图纸,全部由本文件的参数派生: | |
| 平面图 / 标准层平面 / 正立面 / 侧立面 / A-A 剖面 | |
| 3D 建模(Blender bpy)读取同一份 JSON,保证"图即是数、数即是模"。 | |
| 单位:米;x 向右,y 向上,z 竖直。 | |
| """ | |
| import random | |
| ROOM_SETS = [ | |
| ["客厅", "卧室", "厨房"], | |
| ["客厅", "主卧", "次卧", "厨房"], | |
| ["门厅", "办公", "会议室"], | |
| ["客厅", "餐厅", "厨房", "书房"], | |
| ["值班室", "设备间", "储藏"], | |
| ["客厅", "卧室", "厨房", "卫生间"], | |
| ] | |
| NAMES = ["标准层住宅 A 型", "标准层住宅 B 型", "小型办公单元", "商住混合单元", | |
| "配套附属用房", "多层住宅 C 型"] | |
| def q(v, step=0.5): | |
| return round(round(v / step) * step, 2) | |
| def make_building(idx): | |
| """按固定种子参数化生成一栋楼(保证可复现)""" | |
| rng = random.Random(7000 + idx) | |
| W = q(rng.uniform(10.0, 15.0)) | |
| D = q(rng.uniform(7.5, 10.0)) | |
| floors = [2, 3, 1, 2, 1, 3][idx - 1] | |
| T, FH = 0.24, 3.0 | |
| wx = q(W * rng.uniform(0.46, 0.58)) # 竖向内墙位置 | |
| hy = min(q(D * rng.uniform(0.42, 0.55)), D - 2.6) # 右侧横墙 | |
| ridge_y = round(D / 2, 2) | |
| gable_h = q(rng.uniform(1.3, 1.9)) | |
| walls, openings = [], [] | |
| # 各层外墙 | |
| for lvl in range(floors): | |
| walls += [(0, 0, W, 0, lvl), (W, 0, W, D, lvl), | |
| (W, D, 0, D, lvl), (0, D, 0, 0, lvl)] | |
| # 内墙:一层竖墙 + 横墙,二层只需竖墙 | |
| walls += [(wx, 0, wx, D, 0), (wx, hy, W, hy, 0)] | |
| if floors > 1: | |
| walls += [(wx, 0, wx, D, 1)] | |
| if floors > 2: | |
| walls += [(wx, 0, wx, D, 2), (wx, hy, W, hy, 2)] | |
| rooms = [[(0, 0, wx, D, ROOM_SETS[idx - 1][0]), | |
| (wx, hy, W, D, ROOM_SETS[idx - 1][1]), | |
| (wx, 0, W, hy, ROOM_SETS[idx - 1][2])]] | |
| if len(ROOM_SETS[idx - 1]) > 3: | |
| rooms.append([(wx, 0, W, hy / 2, ROOM_SETS[idx - 1][3])]) | |
| # 入口门(前墙 y=0) | |
| dx1 = q(rng.uniform(0.30, 0.52) * wx) | |
| openings.append((dx1, 0, dx1 + 1.2, 0, "door", 0)) | |
| # 前墙窗(各层)——保证每层前立面至少一扇窗 | |
| for lvl in range(floors): | |
| span = wx if lvl == 0 else W | |
| n = rng.randint(1, 3) | |
| placed = 0 | |
| for k in range(n): | |
| a = q(span * (0.10 + 0.78 * k / max(n - 1, 1)) if n > 1 else span * 0.45) | |
| a = max(1.0, min(a, span - 1.8)) | |
| if all(abs(a - o[0]) > 1.8 for o in openings | |
| if o[5] == lvl and abs(o[1]) < 1e-6): | |
| openings.append((a, 0, a + 1.5, 0, "window", lvl)) | |
| placed += 1 | |
| if placed == 0: | |
| a = q(min(span - 2.0, (dx1 + 2.6) if lvl == 0 else span * 0.55)) | |
| a = max(1.0, a) | |
| openings.append((a, 0, a + 1.5, 0, "window", lvl)) | |
| # 左右侧墙窗 | |
| for lvl in range(floors): | |
| if idx % 2 == 1: | |
| a1 = q(rng.uniform(1.0, D - 3.0)) | |
| openings.append((0, a1, 0, a1 + 1.6, "window", lvl)) | |
| a2 = q(rng.uniform(0.8, max(1.2, hy - 2.0))) | |
| openings.append((W, a2, W, a2 + 1.4, "window", lvl)) | |
| a3 = q(min(rng.uniform(hy + 0.6, max(hy + 0.8, D - 2.0)), D - 1.8)) | |
| openings.append((W, a3, W, a3 + 1.5, "window", lvl)) | |
| # 后墙窗 | |
| for lvl in range(floors): | |
| b1 = q(rng.uniform(1.0, max(1.4, wx - 2.5))) | |
| openings.append((b1, D, b1 + 1.6, D, "window", lvl)) | |
| if idx % 3 != 0: | |
| b2 = q(min(rng.uniform(wx + 0.8, max(wx + 1.0, W - 2.0)), W - 1.8)) | |
| openings.append((b2, D, b2 + 1.5, D, "window", lvl)) | |
| # 内墙门洞 | |
| p1 = q(rng.uniform(0.35, 0.60) * D) | |
| openings.append((wx, p1, wx, p1 + 1.0, "passage", 0)) | |
| p2 = q(rng.uniform(0.30, 0.55) * (W - wx) + wx) | |
| openings.append((p2, hy, p2 + 0.9, hy, "passage", 0)) | |
| # 约束点统计:每张图代表一批机器人打点 | |
| pts_plan = int(W * D * 2 + len([o for o in openings if o[5] == 0]) * 3) | |
| pts_elev = int((W + D) * 2 * floors + floors * 6) | |
| pts_sect = int(D * 3 * floors + 12) | |
| return { | |
| "id": "BLD-%03d" % idx, | |
| "name": NAMES[idx - 1], | |
| "footprint": [W, D], "wall_t": T, "floor_h": FH, "floors": floors, | |
| "roof": {"ridge_y": ridge_y, "overhang": 0.6, "gable_h": gable_h}, | |
| "inner_y": hy, | |
| "walls": walls, "openings": openings, | |
| "rooms": rooms[0], | |
| "rooms_2f": rooms[1] if len(rooms) > 1 else [], | |
| "points": {"PLAN-01": pts_plan, "PLAN-02": int(pts_plan * 0.8), | |
| "ELEV-N": pts_elev, "ELEV-E": int(pts_elev * 0.75), | |
| "SECT-A": pts_sect}, | |
| } | |
| BUILDINGS = [make_building(i) for i in range(1, 7)] | |