Campus pipeline hardening: backend parity, wall union, mullion grids, Draco tooling

Sandbox round (Linux):
- detect_sheet_frames.py: multi-frame sheet splitter (column AND row layouts),
  grid-vote per-floor offsets, section-elevation harvesting for storey heights
- dwg_dump_json.mjs + dwgjson_to_dxf.py: WASM libredwg DWG->DXF fallback
  (blocks/INSERT preserved, ATTRIB->TEXT so axis labels survive)
- assemble_campus.py: manifest-driven campus assembly with mandatory
  neighbour-gap gate (overlap = exit 3, 0.1-0.3m flagged as expansion joints)
- site_context_from_dump.py: site-context floors (ground/roads/parking/
  fence/trees/context massings) from site-plan dumps
- write_offline_viewer.py + assets/offline-viewer-libs/: fully-offline
  single-file viewer (vendored three r147 + pako, gzip-embedded GLB)
- audit: clip-scoped coverage figures; report: multi_frame_sheet warning;
  audit gate floors_aligned catches the diagonal-staircase failure mode

Mac round:
- build_blender_showcase.py now honors slab_bounds_fallback and prefers
  footprint polygons for generated roofs (bounds rects made roof plates jut
  past the facade and buried campuses under full-extent slabs); contract now
  matches spec_to_glb.py exactly
- merge_wall_solids (default off) in BOTH backends: shapely union in
  spec_to_glb.py, native delaunay_2d_cdt union in Blender; endpoint-shared
  wall ends pre-extended w/2 so L-corners close seamlessly (flat caps leave
  a notch a union alone cannot fill) while openings stay flat
- glazing_mullions (default off): curtain-wall panel grid (verticals every
  glazing_panel_w + floor-line transoms) as pseudo wall segments in the
  <floor>__walls node; glass pane kept
- build_showcase_variants.py keeps source_file=="site" floors intact in all
  variants (roads/trees live on filtered categories)
- web template: instanced low-poly trees from metadata site_trees,
  grade-level shadow catcher (was at basement depth), data-URI favicon
- tools/compress.mjs deps pinned (package.json); 15MB campus GLB -> 0.57MB
- tests: 24 -> 52 checks (wall union, mullions, byte-identical defaults)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 17:44:41 +08:00
parent 74cc7168f7
commit 6ace84ffba
27 changed files with 8515 additions and 85 deletions

View File

@@ -95,6 +95,70 @@ def make_xref_shell_dxf(path: Path) -> None:
doc.saveas(path)
def make_multiframe_dxf(path: Path) -> None:
"""Chinese sheet-wall pattern: two floor-plan frames stacked 98100 apart.
Reproduces the 贝昂 failure mode: one DWG holds every floor; frames keep
their sheet positions, so extraction without per-frame offsets scatters
floors diagonally.
"""
doc = ezdxf.new("R2010", setup=True)
for layer in ("WALL", "DOTE", "PUB_TEXT"):
doc.layers.add(layer)
msp = doc.modelspace()
pitch = 98100.0
def draw_frame(oy: float, title: str) -> None:
# walls: 40m x 20m outline + interior partitions (>=10 lines for clip refine)
outline = [((0, 0), (40000, 0)), ((40000, 0), (40000, 20000)),
((40000, 20000), (0, 20000)), ((0, 20000), (0, 0))]
interior = [((8000 * i, 0), (8000 * i, 20000)) for i in range(1, 5)]
interior += [((0, 10000), (40000, 10000)), ((12000, 5000), (28000, 5000)),
((20000, 0), (20000, 10000)), ((30000, 10000), (30000, 20000))]
for (sx, sy), (ex, ey) in outline + interior:
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
for i in range(6): # vertical grid lines on DOTE (TArch convention)
x = i * 8000
msp.add_line((x, -3000 + oy), (x, 26000 + oy), dxfattribs={"layer": "DOTE"})
for j in range(3): # horizontal grid lines
y = j * 10000
msp.add_line((-3000, y + oy), (46000, y + oy), dxfattribs={"layer": "DOTE"})
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, oy - 6000))
draw_frame(0.0, "一层平面图")
draw_frame(-pitch, "二层平面图")
doc.saveas(path)
def make_rowframe_dxf(path: Path) -> None:
"""Row layout (3#辅房 pattern): frames side by side, pitch on X, titles same row."""
doc = ezdxf.new("R2010", setup=True)
for layer in ("WALL", "DOTE", "PUB_TEXT"):
doc.layers.add(layer)
msp = doc.modelspace()
pitch = 21000.0
def draw_frame(ox: float, title: str) -> None:
outline = [((0, 0), (8000, 0)), ((8000, 0), (8000, 16000)),
((8000, 16000), (0, 16000)), ((0, 16000), (0, 0))]
interior = [((0, 2000 * i), (8000, 2000 * i)) for i in range(1, 8)]
interior += [((4000, 0), (4000, 16000)), ((2000, 4000), (6000, 4000)),
((2000, 12000), (6000, 12000))]
for (sx, sy), (ex, ey) in outline + interior:
msp.add_line((sx + ox, sy), (ex + ox, ey), dxfattribs={"layer": "WALL"})
for i in range(3):
x = i * 4000
msp.add_line((x + ox, -2500), (x + ox, 18500), dxfattribs={"layer": "DOTE"})
for j in range(4):
y = j * 5000
msp.add_line((-2500 + ox, y), (10500 + ox, y), dxfattribs={"layer": "DOTE"})
msp.add_text(title, height=700, dxfattribs={"layer": "PUB_TEXT"}).set_placement((2500 + ox, -5200))
draw_frame(0.0, "一层平面图")
draw_frame(pitch, "二层平面图")
doc.saveas(path)
def run(cmd: list[str]) -> subprocess.CompletedProcess:
return subprocess.run(cmd, cwd=ROOT, text=True, capture_output=True)
@@ -195,6 +259,213 @@ def main() -> int:
gates_fail = {gate["name"]: gate["status"] for gate in audit_fail["gates"]}
check("glazing gate FAIL when blocks unexpanded", gates_fail.get("glazing_captured") == "FAIL", str(gates_fail))
# --- multi-frame sheet: detect frames, grid-align, alignment gate ---
mf_path = dxf_dir / "multiframe.dxf"
make_multiframe_dxf(mf_path)
proc = run([
sys.executable, "scripts/cad_dxf_report.py",
"--input", str(dxf_dir), "--work", str(WORK / "report_work2"),
"--output", str(WORK / "read_report2"), "--vendor-dir", str(VENDOR),
])
report2 = json.loads((WORK / "read_report2" / "cad_read_report.json").read_text(encoding="utf-8"))
mf_item = {item["file"]: item for item in report2["files"]}.get("multiframe.dxf", {})
check("multi_frame_sheet warning raised", any("multi_frame_sheet" in w for w in mf_item.get("warnings", [])), str(mf_item.get("warnings")))
proc = run([
sys.executable, "scripts/detect_sheet_frames.py",
"--dxf", str(mf_path), "--out-config", str(WORK / "frames.json"),
"--out-report", str(WORK / "frames.md"), "--vendor-dir", str(VENDOR),
])
check("detect_sheet_frames runs", proc.returncode == 0, proc.stderr[-800:])
frames = json.loads((WORK / "frames.json").read_text(encoding="utf-8"))
floors = frames["drawings"][0]["floors"]
keys = [floor["key"] for floor in floors]
check("two plan frames found", sorted(keys) == ["F1", "F2"], str(keys))
off = {floor["key"]: floor["offset"] for floor in floors}
ok_offset = abs(off["F2"][0] - 0.0) <= 120 and abs(off["F2"][1] - 98100.0) <= 120
check("grid alignment recovers frame offset", ok_offset, str(off))
frames.update({"scale": 0.001, "layers": {"walls": ["WALL"], "grid": ["DOTE"]}})
aligned_cfg = WORK / "config_frames.json"
aligned_cfg.write_text(json.dumps(frames, ensure_ascii=False), encoding="utf-8")
aligned_spec = WORK / "spec_frames.json"
proc = run([
sys.executable, "scripts/derive_showcase_spec.py",
"--dxf-dir", str(dxf_dir), "--config", str(aligned_cfg),
"--out", str(aligned_spec), "--vendor-dir", str(VENDOR),
])
check("derive multi-frame runs", proc.returncode == 0, proc.stderr[-800:])
proc = run([
sys.executable, "scripts/audit_showcase_extraction.py",
"--dxf-dir", str(dxf_dir), "--config", str(aligned_cfg), "--spec", str(aligned_spec),
"--out", str(WORK / "audit_frames"), "--vendor-dir", str(VENDOR),
])
audit_frames = json.loads((WORK / "audit_frames" / "extraction_audit.json").read_text(encoding="utf-8"))
gates_frames = {gate["name"]: gate["status"] for gate in audit_frames["gates"]}
check("floors_aligned gate PASS with offsets", gates_frames.get("floors_aligned") == "PASS", str(gates_frames))
# Same clips but WITHOUT offsets -> the diagonal-staircase bug -> gate FAIL.
bad = json.loads(aligned_cfg.read_text(encoding="utf-8"))
for floor in bad["drawings"][0]["floors"]:
floor["offset"] = [0.0, 0.0]
bad_cfg = WORK / "config_frames_bad.json"
bad_cfg.write_text(json.dumps(bad, ensure_ascii=False), encoding="utf-8")
bad_spec = WORK / "spec_frames_bad.json"
run([
sys.executable, "scripts/derive_showcase_spec.py",
"--dxf-dir", str(dxf_dir), "--config", str(bad_cfg),
"--out", str(bad_spec), "--vendor-dir", str(VENDOR),
])
proc = run([
sys.executable, "scripts/audit_showcase_extraction.py",
"--dxf-dir", str(dxf_dir), "--config", str(bad_cfg), "--spec", str(bad_spec),
"--out", str(WORK / "audit_frames_bad"), "--vendor-dir", str(VENDOR),
])
check("misaligned floors exit 3", proc.returncode == 3, f"rc={proc.returncode}")
audit_bad = json.loads((WORK / "audit_frames_bad" / "extraction_audit.json").read_text(encoding="utf-8"))
gates_bad = {gate["name"]: gate["status"] for gate in audit_bad["gates"]}
check("floors_aligned gate FAIL without offsets", gates_bad.get("floors_aligned") == "FAIL", str(gates_bad))
cov = audit_frames["coverage"]
check("clip-scoped coverage reported", cov.get("clipped_supported_length_coverage") is not None, str(cov))
# --- horizontal-row frames (3#辅房 pattern) ---
row_dir = WORK / "dxf_row"
row_dir.mkdir(parents=True, exist_ok=True)
make_rowframe_dxf(row_dir / "rowframes.dxf")
proc = run([
sys.executable, "scripts/detect_sheet_frames.py",
"--dxf", str(row_dir / "rowframes.dxf"), "--out-config", str(WORK / "frames_row.json"),
"--out-report", str(WORK / "frames_row.md"), "--vendor-dir", str(VENDOR),
])
check("detect handles row layout", proc.returncode == 0, proc.stderr[-600:])
frames_row = json.loads((WORK / "frames_row.json").read_text(encoding="utf-8"))
row_floors = frames_row["drawings"][0]["floors"]
row_off = {f["key"]: f["offset"] for f in row_floors}
check("row layout: two floors", sorted(row_off) == ["F1", "F2"], str(row_off))
ok_row = "F2" in row_off and abs(row_off["F2"][0] + 21000.0) <= 120 and abs(row_off["F2"][1]) <= 120
check("row layout: x-pitch offset recovered", ok_row, str(row_off))
# --- merge_wall_solids: shapely union of wall segments (spec_to_glb) ---
sys.path.insert(0, str(ROOT / "scripts"))
import spec_to_glb # noqa: E402
l_walls = [
{"start": [0, 0], "end": [10, 0], "width": 0.24, "layer": "WALL"},
{"start": [10, 0], "end": [10, 8], "width": 0.24, "layer": "WALL"},
]
check("spec_to_glb exposes merged_wall_polygons", hasattr(spec_to_glb, "merged_wall_polygons"))
if hasattr(spec_to_glb, "merged_wall_polygons"):
polys = spec_to_glb.merged_wall_polygons(l_walls)
check("L walls union to a single polygon", len(polys) == 1, f"{len(polys)} polygons")
if len(polys) == 1:
corner_count = len(list(polys[0].exterior.coords)) - 1
# A seamless right-angle corner is exactly 6 corners; 8 means the
# w/2 x w/2 notch at the shared endpoint was left open.
check("L union corner is seamless (6 corners)", corner_count == 6, f"{corner_count} corners")
minx, miny, maxx, maxy = polys[0].bounds
check(
"free wall ends are not extended",
abs(minx - 0.0) < 1e-6 and abs(maxy - 8.0) < 1e-6,
f"bounds={polys[0].bounds}",
)
wall_spec = {
"project": {"name": "wall-merge-test"},
"units": "meters",
"categories": {"walls": {"label": "墙体", "color": "#d4cbb8"}},
"source": {"config": {}},
"floors": {
"F1": {
"name": "首层", "z": 0.0, "height": 4.0,
"bounds": [0, 0, 12, 10],
"segments": {"walls": list(l_walls)},
}
},
}
def build_glb(tag: str, config: dict) -> tuple[bytes, dict]:
spec = json.loads(json.dumps(wall_spec))
spec["source"]["config"] = config
spec_file = WORK / f"wall_spec_{tag}.json"
spec_file.write_text(json.dumps(spec, ensure_ascii=False), encoding="utf-8")
out_file = WORK / f"wall_{tag}.glb"
proc = run([
sys.executable, "scripts/spec_to_glb.py",
"--spec", str(spec_file), "--out", str(out_file), "--name", tag,
])
check(f"spec_to_glb ({tag}) runs", proc.returncode == 0, proc.stderr[-400:])
info = json.loads(proc.stdout.strip().splitlines()[-1]) if proc.returncode == 0 else {}
return (out_file.read_bytes() if out_file.exists() else b""), info
default_bytes, default_info = build_glb("default", {})
off_bytes, _ = build_glb("off", {"merge_wall_solids": False})
on_bytes, on_info = build_glb("on", {"merge_wall_solids": True})
check("merge_wall_solids default matches explicit off byte-for-byte", default_bytes == off_bytes and len(default_bytes) > 0)
check("merge_wall_solids on changes the output", on_bytes not in (b"", default_bytes))
check(
"merged walls keep one node with valid triangles",
on_info.get("nodes") == default_info.get("nodes") and on_info.get("triangles", 0) > 0,
f"default={default_info} on={on_info}",
)
# --- glazing_mullions: panel grid over merged glazing bands ---
check("spec_to_glb exposes glazing_mullion_segments", hasattr(spec_to_glb, "glazing_mullion_segments"))
if hasattr(spec_to_glb, "glazing_mullion_segments"):
band = [{"start": [0, 0], "end": [6, 0], "width": 0.06, "layer": "CURTWALL"}]
msegs = spec_to_glb.glazing_mullion_segments(band, 0.0, 4.0, panel_w=1.5)
verticals = [s for s in msegs if "_z0" not in s]
transoms = [s for s in msegs if "_z0" in s]
check("6m band at 1.5m pitch gives 5 vertical mullions", len(verticals) == 5, f"{len(verticals)} verticals")
check("band gets top+bottom transoms", len(transoms) == 2, f"{len(transoms)} transoms")
if transoms:
zs = sorted(float(s["_z0"]) for s in transoms)
check("transoms sit at the floor lines", abs(zs[0] - 0.0) < 0.15 and abs(zs[-1] - 4.0) < 0.15, str(zs))
glaze_spec = {
"project": {"name": "mullion-test"},
"units": "meters",
"categories": {
"walls": {"label": "墙体", "color": "#d4cbb8"},
"glazing": {"label": "玻璃", "color": "#79b8c9"},
},
"source": {"config": {}},
"floors": {
"F1": {
"name": "首层", "z": 0.0, "height": 4.0,
"bounds": [0, 0, 8, 4],
"segments": {"glazing": [
{"start": [0, 0], "end": [6, 0], "width": 0.06, "layer": "CURTWALL"},
]},
}
},
}
def build_glaze_glb(tag: str, config: dict) -> tuple[bytes, dict]:
spec = json.loads(json.dumps(glaze_spec))
spec["source"]["config"] = config
spec_file = WORK / f"glaze_spec_{tag}.json"
spec_file.write_text(json.dumps(spec, ensure_ascii=False), encoding="utf-8")
out_file = WORK / f"glaze_{tag}.glb"
proc = run([
sys.executable, "scripts/spec_to_glb.py",
"--spec", str(spec_file), "--out", str(out_file), "--name", tag,
])
check(f"spec_to_glb ({tag}) runs", proc.returncode == 0, proc.stderr[-400:])
info = json.loads(proc.stdout.strip().splitlines()[-1]) if proc.returncode == 0 else {}
return (out_file.read_bytes() if out_file.exists() else b""), info
gdefault_bytes, gdefault_info = build_glaze_glb("default", {})
goff_bytes, _ = build_glaze_glb("off", {"glazing_mullions": False})
gon_bytes, gon_info = build_glaze_glb("on", {"glazing_mullions": True})
check("glazing_mullions default matches explicit off byte-for-byte", gdefault_bytes == goff_bytes and len(gdefault_bytes) > 0)
check("glazing_mullions on changes the output", gon_bytes not in (b"", gdefault_bytes))
check(
"mullions add a walls node and keep the glass pane",
gon_info.get("nodes", 0) == gdefault_info.get("nodes", 0) + 1
and gon_info.get("triangles", 0) > gdefault_info.get("triangles", 0),
f"default={gdefault_info} on={gon_info}",
)
print()
if FAILURES:
print(f"{len(FAILURES)} check(s) failed: {FAILURES}")