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

@@ -2,6 +2,7 @@ import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
@@ -67,14 +68,22 @@ controls.dampingFactor = 0.08;
controls.screenSpacePanning = true;
controls.maxPolarAngle = Math.PI * 0.49;
scene.add(new THREE.HemisphereLight(0xf7f3e8, 0x20262a, 1.45));
scene.add(new THREE.HemisphereLight(0xf7f3e8, 0x20262a, 0.9));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.6);
keyLight.position.set(-45, -62, 85);
// Image-based lighting: cheap, no HDR download, transforms material readability.
const pmrem = new THREE.PMREMGenerator(renderer);
scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
if ("environmentIntensity" in scene) scene.environmentIntensity = 0.85;
// Y-up scene: the sun must sit ABOVE the model (positive Y) or shadows break.
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-45, 85, 62);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9fd4ff, 1.15);
const fillLight = new THREE.DirectionalLight(0x9fd4ff, 0.9);
fillLight.position.set(80, 55, 48);
scene.add(fillLight);
@@ -260,6 +269,10 @@ function ingestModel(gltfScene, meta) {
modelRoot.add(mesh);
continue;
}
if (parsed.category === "trees" && meta.site_trees?.length) {
mesh.visible = false; // replaced by instanced trunk+crown trees below
continue;
}
mesh.castShadow = !["grid", "floor_lines", "detail_lines", "glazing"].includes(parsed.category);
mesh.receiveShadow = true;
mesh.userData.floor = parsed.floor;
@@ -273,7 +286,60 @@ function ingestModel(gltfScene, meta) {
floorGroups.get(parsed.floor).add(mesh);
}
if (meta.site_trees?.length) addInstancedTrees(meta.site_trees);
state.bounds = new THREE.Box3().setFromObject(modelRoot);
fitShadowsAndGround(state.bounds);
}
function addInstancedTrees(points) {
// spec plan coords (x, y) -> Y-up world (x, ?, -y), same mapping as the GLB export
const trunk = new THREE.InstancedMesh(
new THREE.CylinderGeometry(0.14, 0.2, 1.4, 6),
new THREE.MeshStandardMaterial({ color: 0x6b4a2e, roughness: 0.9, clippingPlanes: [sectionPlane] }),
points.length,
);
const crown = new THREE.InstancedMesh(
new THREE.IcosahedronGeometry(1.5, 1),
new THREE.MeshStandardMaterial({ color: 0x3e7d4f, roughness: 0.8, clippingPlanes: [sectionPlane] }),
points.length,
);
const matrix = new THREE.Matrix4();
points.forEach(([x, y], index) => {
matrix.setPosition(x, 0.7, -y);
trunk.setMatrixAt(index, matrix);
matrix.setPosition(x, 2.2, -y);
crown.setMatrixAt(index, matrix);
});
trunk.castShadow = crown.castShadow = true;
crown.receiveShadow = true;
const group = floorGroups.get("TREES");
(group || modelRoot).add(trunk, crown);
}
function fitShadowsAndGround(bounds) {
// Default directional-shadow frustum is ±5 m — useless for buildings.
const center = bounds.getCenter(new THREE.Vector3());
const size = bounds.getSize(new THREE.Vector3());
const radius = Math.max(size.x, size.z, 20) * 0.75;
keyLight.target.position.copy(center);
scene.add(keyLight.target);
Object.assign(keyLight.shadow.camera, {
left: -radius, right: radius, top: radius, bottom: -radius, near: 5, far: radius * 6,
});
keyLight.shadow.camera.updateProjectionMatrix();
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(radius * 8, radius * 8),
new THREE.ShadowMaterial({ opacity: 0.32 }),
);
ground.rotation.x = -Math.PI / 2;
// Grade sits at y=0 by spec convention; bounds.min.y is the BASEMENT floor
// when one exists, and a catcher 5 m below grade shows shadows detached
// from the building. Clamp to grade unless the whole model floats above it.
const groundY = Math.max(bounds.min.y, Math.min(0, bounds.max.y)) - 0.03;
ground.position.set(center.x, groundY, center.z);
ground.receiveShadow = true;
scene.add(ground);
}
function parseObjectName(name) {
@@ -291,6 +357,16 @@ function labelForObject({ floor, category }) {
function materialForCategory(category, meta) {
if (materialByCategory.has(category)) return materialByCategory.get(category);
const color = new THREE.Color(meta.categories[category]?.color || "#cccccc");
if (category === "glazing") {
// Physical glass (transmission) instead of flat alpha — key perceived-quality win.
const glass = new THREE.MeshPhysicalMaterial({
color, metalness: 0, roughness: 0.18, transmission: 0.7, ior: 1.5, thickness: 0.3,
transparent: true, depthWrite: false, side: THREE.DoubleSide, clippingPlanes: [sectionPlane],
});
glass.envMapIntensity = 1.2;
materialByCategory.set(category, glass);
return glass;
}
const opacity =
category === "slab"
? 0.64

View File

@@ -4,6 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{TITLE}}</title>
<link rel="icon" href="data:," /><!-- keep the console free of favicon 404s -->
<link rel="stylesheet" href="./styles.css" />
<script type="importmap">
{