fix: cull a district by where it stands, not by where its footprint is at sea level
Two independent reviewers found the same defect in `a2a04e0`, which is the only reason it is being fixed rather than shipped. `DetailRange.r` is `reach` from the lattice sweep: the half-diagonal of the district's lat/lng bounding box plus a lot. That is a **plan** radius, and it is a good one — measured over all 59,166 instances, every lot is inside its own district's `r` of the centre with metres to spare. It was then used as the radius of a sphere pinned at `y = 0`, which is a different claim, and one this board does not support: a lot's local y is the ground under it times `verticalExaggeration`, and that is 15 on the merged board. **39 of 97 district ranges had lots outside their own cull sphere**, the worst by 4.78 units — 9.2 km of scene height, in the San Gabriel foothills. Swept over 32,400 poses built the way `scene.ts` builds them, 61 dropped lots that project strictly inside the NDC cube. Hillside buildings vanishing while you look at them. So the range carries `y0`/`y1` — walked once per district at build, over lots that were just pushed — and the test is `Frustum.intersectsBox` instead of `intersectsSphere`. Same six plane tests, and exact for the volume being described rather than right in x/z and wrong in y. Measured, SF 2.5 km: 215,598 → 216,392 triangles. The fix *adds* 794, which is the shape of a correct answer here — it stops discarding geometry that was on screen. The whole-board pose is unchanged and draws are unchanged at 437. The doc comments that asserted the invariant this violated are rewritten rather than deleted; they were the part most likely to survive a fix and mislead. Also corrected there: the pack declares 99 detail districts but ten emit no lot and carry no range, so the quoted reach statistics are over 89, not 99 — the file and the hand-off report disagreed. `blocksDetail.test.ts` gains a peak board, because the existing fixture cannot express this: it exaggerates by 2 with a 200 m hill, so every district's height is a rounding error next to its plan radius and a y=0 volume contains it by accident. The new board is one small district on a 3,000 m peak at 15x — lots at y 36.09-39.28 on a 2.70-unit footprint. Verified to fail against the old volume and pass against the box, rather than assumed to.
This commit is contained in:
@@ -192,3 +192,82 @@ test("a board with no detail districts is never repacked at all", async () => {
|
||||
updateBlocksDetail(blocks, 0, 0, 0, looking(plain, 36.05, -122.95, 0.2), 1);
|
||||
assert.equal(blocks.count, drawn, "a board with no detail districts must not move");
|
||||
});
|
||||
|
||||
/**
|
||||
* A district on high ground is culled by where it *is*, not by where its
|
||||
* footprint would be at sea level.
|
||||
*
|
||||
* This is a regression test for a real defect, and it is written as a separate
|
||||
* board because the fixture above cannot express it: that board exaggerates by
|
||||
* 2 and its tallest hill is 200 m, so every district's height above the ground
|
||||
* plane is a rounding error next to its own plan radius and a cull volume
|
||||
* pinned at y=0 contains it by accident.
|
||||
*
|
||||
* The merged California board exaggerates by 15. A lot's local y is the terrain
|
||||
* under it times that, so a district in the San Gabriel foothills stands
|
||||
* kilometres of scene height above y=0 while its plan radius stays a few units.
|
||||
* Tested against a sphere centred on the ground plane, **39 of the merged
|
||||
* board's 97 district ranges had lots outside their own cull volume** — the
|
||||
* worst by 4.78 units, 9.2 km — and the picture that produces is hillside
|
||||
* buildings vanishing while they are on screen.
|
||||
*
|
||||
* The board below reproduces that geometry rather than that city: one small
|
||||
* detail district on a 3,000 m peak, exaggerated 15x, so its lots sit about
|
||||
* forty units up on a footprint about three units across. A camera at the
|
||||
* summit looking at the summit contains every one of those lots and misses a
|
||||
* y=0 sphere entirely.
|
||||
*/
|
||||
const PEAK_CITY: City = {
|
||||
...CITY,
|
||||
id: "peak-board",
|
||||
verticalExaggeration: 15,
|
||||
districts: [district("summit", 37, -122, 0.02, true)],
|
||||
hills: [{ name: "peak", lat: 37, lng: -122, elevation: 3_000, radius: 0.25 }],
|
||||
};
|
||||
|
||||
test("a district on high ground survives a frustum that contains it", async () => {
|
||||
const world = new World(PEAK_CITY);
|
||||
assert.equal(await world.ready(), true, "the peak board failed to build a heightfield");
|
||||
const blocks = createBlocks(world);
|
||||
const store = blocks.userData.detail as { ranges: { r: number; y0: number; y1: number }[] };
|
||||
assert.ok(store !== undefined && store.ranges.length > 0, "the peak board built no district");
|
||||
|
||||
/*
|
||||
* The fixture is only a test while this holds. If a pack edit ever flattens
|
||||
* this board, the assertion below would pass against a y=0 volume too and
|
||||
* would quietly stop testing anything.
|
||||
*/
|
||||
const range = store.ranges[0]!;
|
||||
assert.ok(
|
||||
range.y0 > range.r,
|
||||
`the fixture is not off the ground plane: y0 ${range.y0.toFixed(2)} against r ${range.r.toFixed(2)}`,
|
||||
);
|
||||
|
||||
/*
|
||||
* Aimed at the summit, and reaching only as far as the summit.
|
||||
*
|
||||
* `looking()` above aims every camera at `y = 0` with a far plane ten times
|
||||
* the stand-off, which is right for that board and useless here: it puts the
|
||||
* ground plane in the middle of the frustum, so a cull volume pinned to the
|
||||
* ground plane is contained whatever the terrain does and the defect cannot
|
||||
* be expressed. This camera hangs eight units over the peak, looks at the
|
||||
* peak, and stops twelve units short — so the lots at y 36.09-39.28 are in
|
||||
* frame and the plane at y = 0, thirty-seven units below them, is not.
|
||||
*/
|
||||
const [x, z] = world.project(37, -122);
|
||||
const summitY = world.groundAt(37, -122);
|
||||
const camera = new THREE.PerspectiveCamera(42, 1, 0.01, 12);
|
||||
camera.position.set(x, summitY + 8, z);
|
||||
camera.lookAt(new THREE.Vector3(x, summitY, z));
|
||||
camera.updateMatrixWorld(true);
|
||||
camera.updateProjectionMatrix();
|
||||
const view = new THREE.Frustum().setFromProjectionMatrix(
|
||||
new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse),
|
||||
);
|
||||
|
||||
updateBlocksDetail(blocks, x, z, REACH, view, 0);
|
||||
assert.ok(
|
||||
blocks.count > 0,
|
||||
"a district standing on a peak was culled by a frustum aimed straight at it",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user