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

@@ -245,6 +245,137 @@ def create_segment_mesh(bpy, name: str, segments: list[dict], z0: float, z1: flo
return obj
def extend_shared_wall_ends(segments: list[dict], tol: float = 1e-3) -> list[dict]:
"""Extend wall ends that meet another wall's endpoint by half their own width.
Flat-capped rectangles stop exactly at the endpoint, so an L-corner leaves
a w/2 x w/2 notch that even a union keeps open. Extending only SHARED ends
closes the corner while free ends (door/window openings) stay flat.
Mirror of spec_to_glb.extend_shared_wall_ends.
"""
from collections import Counter
pts = []
for segment in segments:
pts.append((float(segment["start"][0]), float(segment["start"][1])))
pts.append((float(segment["end"][0]), float(segment["end"][1])))
scale = 1.0 / max(tol, 1e-9)
buckets = Counter((round(x * scale), round(y * scale)) for x, y in pts)
def shared(point):
cx, cy = round(point[0] * scale), round(point[1] * scale)
return sum(buckets.get((gx, gy), 0) for gx in (cx - 1, cx, cx + 1) for gy in (cy - 1, cy, cy + 1)) >= 2
out = []
for segment in segments:
start = [float(segment["start"][0]), float(segment["start"][1])]
end = [float(segment["end"][0]), float(segment["end"][1])]
dx, dy = end[0] - start[0], end[1] - start[1]
length = math.hypot(dx, dy)
if length < 1e-7:
out.append(segment)
continue
ux, uy = dx / length, dy / length
half = max(float(segment.get("width", 0.1)), 0.005) / 2.0
item = dict(segment)
if shared((start[0], start[1])):
start = [start[0] - ux * half, start[1] - uy * half]
if shared((end[0], end[1])):
end = [end[0] + ux * half, end[1] + uy * half]
item["start"] = start
item["end"] = end
out.append(item)
return out
def create_merged_wall_mesh(bpy, name: str, segments: list[dict], z0: float, z1: float, material, floor_key: str, category: str):
"""Union wall-segment rectangles into one continuous solid (config
{"merge_wall_solids": true}) — removes corner seams and z-fighting at
junctions. Blender-native: delaunay_2d_cdt (output_type=1) triangulates the
union of the overlapping rectangles; edges used by exactly one triangle are
the union outline and become the side faces. Same visual contract as
spec_to_glb.py's shapely union, without needing shapely in Blender python.
"""
from mathutils import Vector
from mathutils.geometry import delaunay_2d_cdt
points = []
rects = []
for segment in extend_shared_wall_ends(segments):
prism = segment_prism(segment, z0, z1)
if not prism:
continue
idx = len(points)
points.extend(Vector((vert[0], vert[1])) for vert in prism[:4])
rects.append((idx, idx + 1, idx + 2, idx + 3))
if not rects:
return None
verts2d, _edges, tris = delaunay_2d_cdt(points, [], rects, 1, 1e-5)[:3]
if not tris:
return None
count = len(verts2d)
verts = [(v.x, v.y, z0) for v in verts2d] + [(v.x, v.y, z1) for v in verts2d]
edge_use: dict[tuple[int, int], int] = {}
for tri in tris:
for a, b in ((tri[0], tri[1]), (tri[1], tri[2]), (tri[2], tri[0])):
key = (min(a, b), max(a, b))
edge_use[key] = edge_use.get(key, 0) + 1
faces = [tuple(reversed(tri)) for tri in tris] # bottom, facing down
faces += [tuple(i + count for i in tri) for tri in tris] # top, facing up
for tri in tris:
# CCW triangles keep the interior left of a->b, so (a,b,b',a') faces outward.
for a, b in ((tri[0], tri[1]), (tri[1], tri[2]), (tri[2], tri[0])):
if edge_use[(min(a, b), max(a, b))] == 1:
faces.append((a, b, b + count, a + count))
mesh = bpy.data.meshes.new(f"{name}Mesh")
mesh.from_pydata(verts, [], faces)
mesh.update()
mesh.validate(verbose=False)
obj = bpy.data.objects.new(name, mesh)
bpy.context.collection.objects.link(obj)
obj.data.materials.append(material)
obj["floor"] = floor_key
obj["category"] = category
return obj
def glazing_mullion_segments(bands: list[dict], z0: float, z1: float, panel_w: float = 1.5, profile: float = 0.06, depth: float = 0.10) -> list[dict]:
"""Curtain-wall panel grid over glazing bands (mirror of spec_to_glb).
Emits pseudo wall segments (thin box profiles, rendered into the
<floor>__walls object): vertical mullions evenly spaced ~panel_w per band
plus a horizontal transom at the band's bottom and top floor lines
(via _z0/_z1). Config {"glazing_mullions": true, "glazing_panel_w": 1.5}.
"""
out = []
for segment in bands:
start = segment["start"]
end = segment["end"]
dx, dy = end[0] - start[0], end[1] - start[1]
length = math.hypot(dx, dy)
if length < max(profile * 2, 0.3):
continue
ux, uy = dx / length, dy / length
panels = max(1, round(length / max(panel_w, 0.2)))
step = length / panels
for i in range(panels + 1):
t = i * step
cx, cy = start[0] + ux * t, start[1] + uy * t
out.append({
"start": [cx - ux * profile / 2.0, cy - uy * profile / 2.0],
"end": [cx + ux * profile / 2.0, cy + uy * profile / 2.0],
"width": depth, "layer": segment.get("layer", ""), "source_type": "mullion",
})
thickness = 0.08
for tz0, tz1 in ((z0, z0 + thickness), (z1 - thickness, z1)):
out.append({
"start": [float(start[0]), float(start[1])], "end": [float(end[0]), float(end[1])],
"width": depth, "layer": segment.get("layer", ""), "source_type": "transom",
"_z0": tz0, "_z1": tz1,
})
return out
def create_label(bpy, name: str, body: str, location: tuple[float, float, float], size: float, material):
curve = bpy.data.curves.new(f"{name}Curve", "FONT")
curve.body = body
@@ -328,11 +459,11 @@ def generated_roof_bounds(spec: dict) -> list[dict]:
continue
bounds_from = list(roof.get("bounds_from", [floor_key]))
footprint_from = list(roof.get("footprint_from", bounds_from))
footprint_polygons = (
footprint_polygons_from_floor_keys(spec, footprint_from)
if config.get("use_footprint_roofs", False) or roof.get("use_footprint", False)
else []
)
# Footprint polygons take priority over rectangular bounds whenever the
# source floors carry them (same contract as spec_to_glb.py); a bounds
# rect for e.g. a PH machine-room roof covers the whole building bbox
# and reads as a plate jutting past the facade.
footprint_polygons = footprint_polygons_from_floor_keys(spec, footprint_from)
bounds = roof.get("bounds") or bounds_from_floor_keys(spec, bounds_from)
if not bounds:
bounds = floor.get("bounds")
@@ -519,7 +650,11 @@ def add_floor(bpy, floor_key: str, floor: dict, materials: dict[str, object], sp
floor_key,
"slab",
)
else:
elif config.get("slab_bounds_fallback", True):
# Rectangular fallback can fake a full-cover plate on floors like
# parapet-only roof plans or campus context floors (roads/fence/trees);
# disable via config {"slab_bounds_fallback": false} when footprints
# are trusted (same contract as spec_to_glb.py).
create_box_mesh(bpy, f"{floor_key}__slab", [slab_box], materials["slab"], floor_key, "slab")
# Cap slabs close the tops of columns at setbacks and over basement parking
# (computed by derive_showcase_spec.py and stored as floor["caps"]). They share
@@ -540,15 +675,34 @@ def add_floor(bpy, floor_key: str, floor: dict, materials: dict[str, object], sp
"slab",
)
floor_segments = floor.get("segments", {})
mullion_segments: list[dict] = []
if config.get("glazing_mullions", False) and floor_segments.get("glazing"):
gz0, gz1 = z_window_for_category("glazing", z, height, floor_key, floor)
mullion_segments = glazing_mullion_segments(
floor_segments["glazing"], gz0, gz1, panel_w=float(config.get("glazing_panel_w", 1.5)),
)
known = [category for category in CATEGORY_DRAW_ORDER if floor_segments.get(category)]
extra = sorted(category for category in floor_segments if category not in CATEGORY_DRAW_ORDER and floor_segments.get(category))
if mullion_segments and "walls" not in known:
known.append("walls") # glazing-only floor still needs a walls object for the grid
for category in known + extra:
segments = floor.get("segments", {}).get(category, [])
if not segments:
if not segments and category != "walls":
continue
if category == "columns":
segments = adjusted_column_segments(segments, floor_key, floor, spec)
z0, z1 = z_window_for_category(category, z, height, floor_key, floor)
if category == "walls" and config.get("merge_wall_solids", False) and segments:
merged = create_merged_wall_mesh(
bpy, f"{floor_key}__walls", segments, z0, z1, materials[category], floor_key, category,
)
if merged is not None:
segments = [] # walls handled; mullions (if any) get their own pass below
if category == "walls":
segments = list(segments) + mullion_segments
mullion_segments = []
if not segments:
continue
create_segment_mesh(
bpy,
f"{floor_key}__{category}",