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:
@@ -8,7 +8,7 @@ a Blender install. The Web viewer recolours meshes by category from
|
||||
model_metadata.json, so only correct node names + geometry are required.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse, json, math
|
||||
import argparse, json, math, sys
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
import trimesh
|
||||
@@ -66,6 +66,9 @@ def mesh_from_segments(segments, z0, z1):
|
||||
if not V: return None
|
||||
return trimesh.Trimesh(vertices=np.vstack(V), faces=np.vstack(F), process=False)
|
||||
|
||||
_POLY_FAILS = {"n": 0}
|
||||
|
||||
|
||||
def mesh_from_polygons(polygons, z0, z1):
|
||||
parts=[]
|
||||
for coords in polygons:
|
||||
@@ -79,7 +82,13 @@ def mesh_from_polygons(polygons, z0, z1):
|
||||
m=trimesh.creation.extrude_polygon(poly, height=max(z1-z0,1e-4))
|
||||
m.apply_translation((0,0,z0))
|
||||
parts.append(m)
|
||||
except Exception:
|
||||
except Exception as exc:
|
||||
# Silent drops here erase slabs/caps/roofs wholesale (e.g. trimesh
|
||||
# cannot triangulate without mapbox_earcut/manifold3d installed).
|
||||
_POLY_FAILS["n"] += 1
|
||||
if _POLY_FAILS["n"] <= 3:
|
||||
print(f"WARNING mesh_from_polygons failed ({exc}); slabs/caps/roofs may be "
|
||||
"missing - pip install mapbox_earcut", file=sys.stderr)
|
||||
continue
|
||||
if not parts: return None
|
||||
return trimesh.util.concatenate(parts) if len(parts)>1 else parts[0]
|
||||
@@ -126,6 +135,111 @@ def merge_collinear(segs, angle_tol_deg=6.0, offset_tol=0.30, gap_tol=3.6):
|
||||
out.append({"start":[p0[0],p0[1]],"end":[p1[0],p1[1]],"width":w,"layer":layer,"source_type":"merged"})
|
||||
return out
|
||||
|
||||
def extend_shared_wall_ends(segments, tol=1e-3):
|
||||
"""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
|
||||
makes the corner rectangles overlap (union -> clean square corner) while
|
||||
free ends (door/window openings) stay flat. T-joints need nothing: the
|
||||
ending wall already reaches the crossing wall's centerline.
|
||||
"""
|
||||
from collections import Counter
|
||||
pts=[]
|
||||
for s in segments:
|
||||
pts.append((float(s["start"][0]), float(s["start"][1])))
|
||||
pts.append((float(s["end"][0]), float(s["end"][1])))
|
||||
scale=1.0/max(tol,1e-9)
|
||||
buckets=Counter((round(x*scale), round(y*scale)) for x,y in pts)
|
||||
def shared(p):
|
||||
cx,cy=round(p[0]*scale), round(p[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 s in segments:
|
||||
a=[float(s["start"][0]), float(s["start"][1])]
|
||||
b=[float(s["end"][0]), float(s["end"][1])]
|
||||
dx,dy=b[0]-a[0],b[1]-a[1]; L=math.hypot(dx,dy)
|
||||
if L<1e-7:
|
||||
out.append(s); continue
|
||||
ux,uy=dx/L,dy/L
|
||||
half=max(float(s.get("width",0.1)),0.005)/2.0
|
||||
item=dict(s)
|
||||
if shared((a[0],a[1])): a=[a[0]-ux*half, a[1]-uy*half]
|
||||
if shared((b[0],b[1])): b=[b[0]+ux*half, b[1]+uy*half]
|
||||
item["start"]=a; item["end"]=b
|
||||
out.append(item)
|
||||
return out
|
||||
|
||||
def merged_wall_polygons(segments):
|
||||
"""Union per-segment wall rectangles into continuous solids (shapely).
|
||||
|
||||
Shared endpoints are pre-extended (see extend_shared_wall_ends), then each
|
||||
segment becomes a flat-capped rectangle (LineString.buffer, cap_style=2,
|
||||
half its own width) and unary_union removes corner seams and z-fighting at
|
||||
junctions. Returns shapely Polygons (holes preserved for courtyard walls).
|
||||
Enabled via config {"merge_wall_solids": true}.
|
||||
"""
|
||||
from shapely.geometry import LineString
|
||||
from shapely.ops import unary_union
|
||||
rects=[]
|
||||
for s in extend_shared_wall_ends(segments):
|
||||
a=s["start"]; b=s["end"]
|
||||
if math.hypot(b[0]-a[0], b[1]-a[1])<1e-7: continue
|
||||
w=max(float(s.get("width",0.1)), 0.005)
|
||||
rects.append(LineString([tuple(a), tuple(b)]).buffer(w/2.0, cap_style=2))
|
||||
if not rects: return []
|
||||
union=unary_union(rects)
|
||||
geoms=[union] if union.geom_type=="Polygon" else list(getattr(union,"geoms",[]))
|
||||
# simplify(0) drops the collinear vertices GEOS noding leaves on straight edges
|
||||
return [g.simplify(0) for g in geoms if g.geom_type=="Polygon" and g.area>1e-6]
|
||||
|
||||
def mesh_from_shapely(polys, z0, z1):
|
||||
"""Extrude shapely Polygons directly (keeps interior holes, unlike mesh_from_polygons)."""
|
||||
parts=[]
|
||||
for poly in polys:
|
||||
try:
|
||||
m=trimesh.creation.extrude_polygon(poly, height=max(z1-z0,1e-4))
|
||||
m.apply_translation((0,0,z0))
|
||||
parts.append(m)
|
||||
except Exception as exc:
|
||||
_POLY_FAILS["n"] += 1
|
||||
if _POLY_FAILS["n"] <= 3:
|
||||
print(f"WARNING mesh_from_polygons failed ({exc}); merged walls may be "
|
||||
"missing - pip install mapbox_earcut", file=sys.stderr)
|
||||
continue
|
||||
if not parts: return None
|
||||
return trimesh.util.concatenate(parts) if len(parts)>1 else parts[0]
|
||||
|
||||
def glazing_mullion_segments(bands, z0, z1, panel_w=1.5, profile=0.06, depth=0.10):
|
||||
"""Curtain-wall panel grid over merged glazing bands.
|
||||
|
||||
Emits pseudo wall segments (thin box profiles, walls material via the
|
||||
<floor>__walls node): vertical mullions evenly spaced ~panel_w along each
|
||||
band (posts at both ends included) plus a horizontal transom at the band's
|
||||
bottom and top floor lines (carrying _z0/_z1). The glass pane itself stays.
|
||||
Config {"glazing_mullions": true}, pitch {"glazing_panel_w": 1.5}.
|
||||
"""
|
||||
out=[]
|
||||
for s in bands:
|
||||
a=s["start"]; b=s["end"]
|
||||
dx,dy=b[0]-a[0],b[1]-a[1]; L=math.hypot(dx,dy)
|
||||
if L<max(profile*2, 0.3): continue
|
||||
ux,uy=dx/L,dy/L
|
||||
n=max(1, round(L/max(panel_w, 0.2)))
|
||||
step=L/n
|
||||
for i in range(n+1):
|
||||
t=i*step
|
||||
cx,cy=a[0]+ux*t, a[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":s.get("layer",""), "source_type":"mullion"})
|
||||
th=0.08
|
||||
for tz0,tz1 in ((z0, z0+th), (z1-th, z1)):
|
||||
out.append({"start":[float(a[0]),float(a[1])], "end":[float(b[0]),float(b[1])],
|
||||
"width":depth, "layer":s.get("layer",""), "source_type":"transom",
|
||||
"_z0":tz0, "_z1":tz1})
|
||||
return out
|
||||
|
||||
def _shapely_union(polys):
|
||||
from shapely.geometry import Polygon
|
||||
from shapely.ops import unary_union
|
||||
@@ -157,6 +271,10 @@ def setback_cap_polys(spec, fk, fl, own_polys):
|
||||
if abs(float(ot.get("z",0.0))-ftop)>0.8: continue
|
||||
upper.extend(ot.get("footprint",{}).get("polygons",[]))
|
||||
own_u=_shapely_union(own_polys)
|
||||
cfg=spec.get("source",{}).get("config",{})
|
||||
# 1.3 suits colonnade buildings (A208); ordinary facades want ~0.1 or the
|
||||
# cap ring reads as a slab overhanging every floor. Config: cap_buffer.
|
||||
buf=float(cfg.get("cap_buffer",1.3))
|
||||
if not upper:
|
||||
# top of a basement stack -> cap the WHOLE footprint (ground / podium deck over parking)
|
||||
if grp=="BASE" and own_u is not None:
|
||||
@@ -165,8 +283,7 @@ def setback_cap_polys(spec, fk, fl, own_polys):
|
||||
up_u=_shapely_union(upper)
|
||||
if own_u is None or up_u is None: return []
|
||||
try:
|
||||
# buffer own footprint outward so the cap also covers perimeter colonnade columns
|
||||
ring=own_u.buffer(1.3).difference(up_u.buffer(0.05))
|
||||
ring=own_u.buffer(buf).difference(up_u.buffer(0.05))
|
||||
except Exception:
|
||||
return []
|
||||
return _shapely_to_polys(ring, min_area=3.0)
|
||||
@@ -321,7 +438,10 @@ def build_scene(spec, categories):
|
||||
cap_polys=setback_cap_polys(spec, fk, fl, polys)
|
||||
if cap_polys:
|
||||
parts.append(mesh_from_polygons(cap_polys, z+h-slab_th, z+h))
|
||||
else:
|
||||
elif cfg.get("slab_bounds_fallback", True):
|
||||
# Rectangular fallback can fake a full-cover plate on floors
|
||||
# like parapet-only roof plans; disable via config
|
||||
# {"slab_bounds_fallback": false} when footprints are trusted.
|
||||
b=fl["bounds"]; mg=1.2
|
||||
parts.append(mesh_from_polygons(
|
||||
[[[b[0]-mg,b[1]-mg],[b[2]+mg,b[1]-mg],[b[2]+mg,b[3]+mg],[b[0]-mg,b[3]+mg]]],
|
||||
@@ -330,6 +450,13 @@ def build_scene(spec, categories):
|
||||
if parts:
|
||||
add(f"{fk}__slab", parts[0] if len(parts)==1 else trimesh.util.concatenate(parts), "slab")
|
||||
segs=fl.get("segments",{})
|
||||
mullion_mesh=None
|
||||
if cfg.get("glazing_mullions", False) and segs.get("glazing") and (want is None or "walls" in want):
|
||||
gz0,gz1=z_window("glazing",z,h,fk,fl)
|
||||
mullion_mesh=mesh_from_segments(
|
||||
glazing_mullion_segments(merge_collinear(segs["glazing"]), gz0, gz1,
|
||||
panel_w=float(cfg.get("glazing_panel_w",1.5))),
|
||||
gz0, gz1)
|
||||
present=[c for c in CATEGORY_DRAW_ORDER if segs.get(c)]
|
||||
extra=sorted(c for c in segs if c not in CATEGORY_DRAW_ORDER and segs.get(c))
|
||||
for cat in present+extra:
|
||||
@@ -340,7 +467,22 @@ def build_scene(spec, categories):
|
||||
seglist=adjust_columns(seglist, fk, fl, spec, cfg, roofs)
|
||||
if cat=="glazing":
|
||||
seglist=merge_collinear(seglist)
|
||||
if cat=="walls":
|
||||
wall_mesh=None
|
||||
if cfg.get("merge_wall_solids", False):
|
||||
wall_mesh=mesh_from_shapely(merged_wall_polygons(seglist), z0, z1)
|
||||
if wall_mesh is None:
|
||||
wall_mesh=mesh_from_segments(seglist, z0, z1)
|
||||
if mullion_mesh is not None:
|
||||
parts=[p for p in (wall_mesh, mullion_mesh) if p is not None]
|
||||
wall_mesh=trimesh.util.concatenate(parts) if len(parts)>1 else (parts[0] if parts else None)
|
||||
mullion_mesh=None
|
||||
add(f"{fk}__walls", wall_mesh, "walls")
|
||||
continue
|
||||
add(f"{fk}__{cat}", mesh_from_segments(seglist, z0, z1), cat)
|
||||
if mullion_mesh is not None:
|
||||
# glazing-only floor: the panel grid still needs a walls node
|
||||
add(f"{fk}__walls", mullion_mesh, "walls")
|
||||
# generated roofs
|
||||
if want is None or "roof" in want:
|
||||
for r in roof_specs(spec):
|
||||
|
||||
Reference in New Issue
Block a user