diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index a46153eaf..f91aaced8 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1130,6 +1130,22 @@ controller throws naming it. Whether the aircraft it flies still draws comes from its `trackedEntityDrawn` service (the application asks the viewer's entities); without one, Cockpit takes the aircraft as drawn. +## Rendered-mesh floor cells — November 8, 2026 + +On the photoreal stack the shared floor (`cachedGroundFloor`) answers from a +rendered-mesh reading per coarse cell (0.001°, about 110 × 80 m), sampled by +`src/services/meshFloorSampler.js` and gated against the DEM by +`reportValidatedMeshFloorCell` in `src/services/groundFloor.js`. The probe goes +where the caller's point is (a vehicle or contact), not to the cell's centre, +and a cell is read up to four times at points about 17 m or more apart; the +lowest reading that passes the gate is kept. Before this, one probe at the +cell's centre latched for the session, so a centre on a roof lifted everything +in the cell (a Haymarket bus drew 23.5 m above the street, on the garage roof) +and a centre in the river put Red Line trains on the Longfellow Bridge 6–9 m +under the deck. Accepted limit: a cell holds one floor, so a vehicle on a +bridge or viaduct whose cell also gets a street-level probe beneath it is drawn +at that lower level. + ## Vessel components and sources `src/data/aisLiveVessels.js` assembles `createVesselLayer` from the @@ -2542,7 +2558,7 @@ This is the current runtime/source-of-truth snapshot for the project. > `HELD_SNAP_CONTRADICTION_M` (5 m) ABOVE the held value drops the hold and the > contact is COLD again, back to the floored 2D billboard. The rule is > ONE-SIDED on purpose — it targets BURIAL. A cell reading BELOW a real sample -> is the floor chain's expected under-read (one-shot latch over ~111 m, +> is the floor chain's expected under-read (lowest of up to four probes over ~111 m, > neighbours lean lowest, `displayFloorHeightM` only ever raises), not evidence > of anything, and a two-sided cut was disproved on the track rig by a planted > cell 66.7 m below a real sample at the same spot. Accepted residual, stated diff --git a/src/data/meshFloorSampler.test.mjs b/src/data/meshFloorSampler.test.mjs index 18fa77135..f26e7254d 100644 --- a/src/data/meshFloorSampler.test.mjs +++ b/src/data/meshFloorSampler.test.mjs @@ -183,3 +183,57 @@ test('sampler: with `sets` the probe asks the query port, naming those sets', as assert.ok(Math.abs(asked[0].point.lat - cell.lat) < 0.05); assert.equal(cachedMeshFloor(cell.lat, cell.lon), 138.0); }); + +test('sampler: the probe goes where the point is, not to the cell centre', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + const asked = []; + const scene = fakeScene((carto) => { + asked.push(Cesium.Math.toDegrees(carto.longitude)); + return 122.0; + }); + const point = { lat: cell.lat + 0.0003, lon: cell.lon + 0.0004 }; + sampleMeshFloorCells(scene, [point], { viewerLat: cell.lat, viewerLon: cell.lon }); + assert.equal(asked.length, 1); + assert.ok(Math.abs(asked[0] - point.lon) < 1e-9, `probed at ${asked[0]}, not ${point.lon}`); +}); + +test('sampler: a rooftop reading gives way to a lower one from another point in the cell', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + // A roof 22 m up at the first point, the street at the others. + const roofLon = cell.lon + 0.0004; + let calls = 0; + const scene = fakeScene((carto) => { + calls += 1; + return Math.abs(Cesium.Math.toDegrees(carto.longitude) - roofLon) < 1e-7 ? 143.0 : 121.0; + }); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + sampleMeshFloorCells(scene, [{ lat: cell.lat, lon: roofLon }], opts); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), 143.0, 'the roof passes the +80 m window'); + sampleMeshFloorCells(scene, [{ lat: cell.lat, lon: roofLon + 0.00001 }], opts); + assert.equal(calls, 1, 'a point next to one already probed is not probed again'); + sampleMeshFloorCells(scene, [{ lat: cell.lat, lon: cell.lon - 0.0003 }], opts); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), 121.0, 'the street reading replaces it'); + assert.equal(cachedGroundFloor(cell.lat, cell.lon), 121.0); + sampleMeshFloorCells(scene, [{ lat: cell.lat + 0.0003, lon: cell.lon + 0.0001 }], opts); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), 121.0, 'a higher reading never raises it'); +}); + +test('sampler: a latched cell is read a few times at most', async () => { + reset(); + const cell = nextSite(); + await seedDem(cell, 120.0); + let calls = 0; + const scene = fakeScene(() => { + calls += 1; + return 125.0 - calls; + }); + const opts = { viewerLat: cell.lat, viewerLon: cell.lon }; + for (let i = 0; i < 10; i++) + sampleMeshFloorCells(scene, [{ lat: cell.lat - 0.0004 + i * 0.0001, lon: cell.lon }], opts); + assert.equal(calls, 4); + assert.equal(cachedMeshFloor(cell.lat, cell.lon), 121.0); +}); diff --git a/src/services/groundFloor.js b/src/services/groundFloor.js index 27b7dc5e4..d8bf59c6d 100644 --- a/src/services/groundFloor.js +++ b/src/services/groundFloor.js @@ -418,7 +418,8 @@ export function createGroundFloor({ terrain, signal }) { // is the photogrammetric MESH, which sits above it (measured ~17 m at the // Austin airport apron). DEM-flooring therefore still buried sprites/trails // inside the mesh. These cells hold the RENDERED surface height, sampled - // one-shot per coarse cell near the viewer (scene.sampleHeight — the same + // a few probes per coarse cell near the viewer, lowest passing reading kept + // (a probe can land on a roof) (scene.sampleHeight — the same // source groundSnap uses, which is why 3D models always looked right) and // reported here by meshFloorSampler.js. Design principle (owner): NEVER // below the visible surface; slightly above is always fine. The DEM stays @@ -444,7 +445,8 @@ export function createGroundFloor({ terrain, signal }) { /** * Records a sampled rendered-surface height for the cell containing the - * coordinate (one-shot latch — first accepted sample wins). + * coordinate, unchecked; the first record wins. The sampler goes through + * `reportValidatedMeshFloorCell`, which keeps the lowest passing reading. * @param {number} lat @param {number} lon @param {number} heightM */ function reportMeshFloorCell(lat, lon, heightM) { @@ -471,9 +473,10 @@ export function createGroundFloor({ terrain, signal }) { /** * Validate and record a rendered-mesh floor through the single shared gate. - * Callers must not bypass this with raw `reportMeshFloorCell`: a coarse-LOD, - * rooftop, or aircraft hit would otherwise win the session-long first-write - * latch and poison every floor consumer in the cell. + * Callers must not bypass this with raw `reportMeshFloorCell`: a coarse-LOD + * or aircraft hit would otherwise poison every floor consumer in the cell. + * The lowest passing reading is kept, so a rooftop hit within the window + * gives way to a later probe that reached the street. * @returns {boolean} Whether the sample passed and was reported. */ function reportValidatedMeshFloorCell(lat, lon, heightM) { @@ -481,7 +484,11 @@ export function createGroundFloor({ terrain, signal }) { const cell = coarseFloorCoord(lat, lon); const prior = cachedRealEllipsoidalGround(cell.lat, cell.lon); if (!meshFloorSampleWithinPrior(heightM, prior)) return false; - reportMeshFloorCell(cell.lat, cell.lon, heightM); + // The lowest passing reading wins: a probe that hit a roof is replaced + // by a later one that reached the street. + const key = `${cell.lat},${cell.lon}`; + const held = _meshCells.get(key); + if (held == null || heightM < held) _meshCells.set(key, heightM); return true; } diff --git a/src/services/meshFloorSampler.js b/src/services/meshFloorSampler.js index 20fca80e8..0548f25fd 100644 --- a/src/services/meshFloorSampler.js +++ b/src/services/meshFloorSampler.js @@ -25,13 +25,15 @@ export function createMeshFloorSampler({ // which sits above the Re:Earth bare-earth DEM (measured ~17 m at the Austin // airport apron) — so DEM-floored sprites/trails still buried themselves in // the mesh while 3D models (which groundSnap against the mesh) looked right. - // This module samples the mesh height ONE-SHOT per coarse cell and reports it - // to groundFloor.js, whose cachedGroundFloor() then answers mesh-first. + // This module samples the mesh height at the callers' points, a few probes + // per coarse cell, and reports them to groundFloor.js, which keeps the + // lowest that passes its gate; cachedGroundFloor() then answers mesh-first. // // Rationing (the CCTV loading-jitter lesson): scene.sampleHeight forces // tile-load prioritization at the probe point, so sampling is (a) gated to // cells NEAR the viewer — where tiles are streamed and where an error is - // visible at all, (b) capped per call, (c) one-shot per cell for the session, + // visible at all, (b) capped per call, (c) at most MAX_PROBES_PER_CELL + // readings per cell for the session, each at a point apart from the others, // (d) skipped entirely outside the google-3d regime. A returned-undefined // probe (tiles not streamed yet) is NOT latched — it retries on a later call. // @@ -51,6 +53,16 @@ export function createMeshFloorSampler({ * streamed LOD under a high camera is coarse everywhere, so every probe * would latch junk. */ const MAX_CAMERA_HEIGHT_M = 25_000; + /** @constant {number} Readings kept per cell: a cell is probed at most + * this many times, each at a different point, and the lowest reading + * that passes the DEM gate is the cell's floor. */ + const MAX_PROBES_PER_CELL = 4; + /** @constant {number} How far apart (degrees, about 17 m) a new probe must + * be from the cell's earlier ones to be worth taking. */ + const PROBE_APART_DEG = 0.00015; + /** @type {Map>} Points probed + * per cell that returned a reading. */ + const _probedPoints = new Map(); /** @type {Cesium.Cartographic} Scratch for probe coordinates. */ const _scratchProbe = new Cesium.Cartographic(); @@ -85,7 +97,7 @@ export function createMeshFloorSampler({ /** * Samples the rendered mesh height for the coarse cells containing `points`, - * one-shot per cell, budget-capped, viewer-proximity-gated. Call ONCE per + * a few probes per cell, budget-capped, viewer-proximity-gated. Call ONCE per * layer poll (never per contact, never per frame). Synchronous — Cesium's * sampleHeight is a CPU-side query against loaded tiles. * @@ -136,8 +148,21 @@ export function createMeshFloorSampler({ const cell = coarseFloorCoord(p.lat, p.lon); const key = `${cell.lat},${cell.lon}`; if (attempted.has(key)) continue; + // A latched cell is probed again only at a point well apart from the + // ones already probed, a few times at most: a later, lower reading + // replaces a rooftop the first probe may have hit. + const probes = _probedPoints.get(key); + if ( + cachedMeshFloor(cell.lat, cell.lon) != null && + (probes?.length >= MAX_PROBES_PER_CELL || + probes?.some( + (q) => + Math.abs(q.lat - p.lat) < PROBE_APART_DEG && + Math.abs(q.lon - p.lon) < PROBE_APART_DEG, + )) + ) + continue; attempted.add(key); - if (cachedMeshFloor(cell.lat, cell.lon) != null) continue; // one-shot latch if ( Number.isFinite(viewerLat) && Number.isFinite(viewerLon) && @@ -146,14 +171,18 @@ export function createMeshFloorSampler({ ) { continue; // too far: tiles not streamed there, probe would be a guaranteed miss } + // Probe where the caller's point is, not at the cell's centre: a + // centre that falls on a roof would lift everything in the cell. const height = heights.now( - Cesium.Cartographic.fromDegrees(cell.lon, cell.lat, 0, _scratchProbe), + Cesium.Cartographic.fromDegrees(p.lon, p.lat, 0, _scratchProbe), { exclude }, ); // A miss counts against the budget whatever its cause: past the support // gate a probe only throws mid-teardown, when every later cell would too. sampled += 1; if (height === null) continue; // tiles not loaded yet — no negative latch + if (probes) probes.push({ lat: p.lat, lon: p.lon }); + else _probedPoints.set(key, [{ lat: p.lat, lon: p.lon }]); // Round 5: a REAL Re:Earth prior is REQUIRED before any sample latches. // - A geoid-fallback prior (cached while the proxy was failing) is a // sea-level poison that rejected legitimate samples at elevated