Keep each mesh floor reading at its point and answer from the nearest one

Keeping a cell's lowest reading let a street probe pull a vehicle on a viaduct
or bridge in the same cell down to street level. Readings now stay at the point
they were taken (up to eight per cell, about 17 m apart), a read answers from
the reading nearest the vehicle, and two readings within about 5 m keep the
lower.
This commit is contained in:
Sameh Khamis committed 2026-11-08 23:19:16 -08:00
1 parent 18a9e0470d
commit 76b5d99e24
4 files changed
+100 -54

No files matched your search

+44 -16
View File
@@ -418,14 +418,21 @@ 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
// a few probes per coarse cell near the viewer, lowest passing reading kept
// (a probe can land on a roof) (scene.sampleHeight — the same
// at the callers' points, a few per coarse cell near the viewer, each kept
// where it was taken and read back from the nearest (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
// the instant global prior/fallback and the sanity gate for samples.
/** @type {Map<string, number>} coarse cell key -> rendered-surface height (m, ellipsoidal). */
/** @type {Map<string, Array<{lat: number, lon: number, h: number}>>}
* coarse cell key -> rendered-surface readings (m, ellipsoidal), each kept
* at the point it was probed. A read answers from the reading nearest the
* asked point, so a viaduct and the street beside it in one cell keep their
* own heights. */
const _meshCells = new Map();
/** @constant {number} Readings closer than this (degrees, about 5 m) are
* one spot: the lower one is kept there. */
const MESH_READING_SAME_SPOT_DEG = 0.00005;
/** @type {boolean} Whether mesh cells apply — true only in the google-3d
* regime (photoreal stack). On globe stacks the rendered surface IS the
* terrain provider (Re:Earth on keyless), so the DEM is already correct
@@ -445,8 +452,8 @@ export function createGroundFloor({ terrain, signal }) {
/**
* Records a sampled rendered-surface height for the cell containing the
* coordinate, unchecked; the first record wins. The sampler goes through
* `reportValidatedMeshFloorCell`, which keeps the lowest passing reading.
* coordinate, unchecked, when the cell has no reading yet. The sampler goes
* through `reportValidatedMeshFloorCell`, which keeps a reading per point.
* @param {number} lat @param {number} lon @param {number} heightM
*/
function reportMeshFloorCell(lat, lon, heightM) {
@@ -458,7 +465,7 @@ export function createGroundFloor({ terrain, signal }) {
return;
const c = coarseFloorCoord(lat, lon);
const key = `${c.lat},${c.lon}`;
if (!_meshCells.has(key)) _meshCells.set(key, heightM);
if (!_meshCells.has(key)) _meshCells.set(key, [{ lat, lon, h: heightM }]);
}
/** Return whether a rendered-mesh sample is plausible against a real DEM prior. */
@@ -475,8 +482,8 @@ 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
* 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.
* The reading is kept at the point it was taken; a second reading at the
* same spot (within about 5 m) keeps the lower of the two.
* @returns {boolean} Whether the sample passed and was reported.
*/
function reportValidatedMeshFloorCell(lat, lon, heightM) {
@@ -484,17 +491,26 @@ export function createGroundFloor({ terrain, signal }) {
const cell = coarseFloorCoord(lat, lon);
const prior = cachedRealEllipsoidalGround(cell.lat, cell.lon);
if (!meshFloorSampleWithinPrior(heightM, prior)) return false;
// 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);
const readings = _meshCells.get(key);
if (!readings) {
_meshCells.set(key, [{ lat, lon, h: heightM }]);
return true;
}
const same = readings.find(
(r) =>
Math.abs(r.lat - lat) < MESH_READING_SAME_SPOT_DEG &&
Math.abs(r.lon - lon) < MESH_READING_SAME_SPOT_DEG,
);
if (!same) readings.push({ lat, lon, h: heightM });
else if (heightM < same.h) same.h = heightM;
return true;
}
/**
* Synchronous mesh-cell read — null when the cell is unsampled OR the
* google-3d regime is inactive (globe stacks must floor on the DEM).
* Synchronous mesh-cell read — the cell's reading nearest the point, or
* null when the cell is unsampled OR the google-3d regime is inactive (globe
* stacks must floor on the DEM).
* @param {number} lat @param {number} lon
* @returns {number|null}
*/
@@ -502,8 +518,20 @@ export function createGroundFloor({ terrain, signal }) {
if (!_meshPreferred) return null;
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
const c = coarseFloorCoord(lat, lon);
const h = _meshCells.get(`${c.lat},${c.lon}`);
return h != null ? h : null;
const readings = _meshCells.get(`${c.lat},${c.lon}`);
if (!readings) return null;
if (readings.length === 1) return readings[0].h;
const k = Math.cos((lat * Math.PI) / 180) ** 2;
let best = readings[0],
bestD = Infinity;
for (const r of readings) {
const d = (r.lat - lat) ** 2 + k * (r.lon - lon) ** 2;
if (d < bestD) {
bestD = d;
best = r;
}
}
return best.h;
}
/** Test hook: clears mesh cells (never called at runtime — cells are valid all session). */
+10 -9
View File
@@ -26,8 +26,9 @@ export function createMeshFloorSampler({
// 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 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.
// per coarse cell, and reports them to groundFloor.js, which keeps each
// reading that passes its gate at its own point; cachedGroundFloor() then
// answers mesh-first, from the reading nearest the asked point.
//
// Rationing (the CCTV loading-jitter lesson): scene.sampleHeight forces
// tile-load prioritization at the probe point, so sampling is (a) gated to
@@ -53,10 +54,10 @@ 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} Readings per cell: a cell is probed at most this
* many times, each at a point apart from the others, and groundFloor keeps
* each reading at its point (a read answers from the nearest one). */
const MAX_PROBES_PER_CELL = 8;
/** @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;
@@ -149,8 +150,8 @@ export function createMeshFloorSampler({
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.
// ones already probed, a few times at most, so the cell's readings
// follow where its vehicles actually are.
const probes = _probedPoints.get(key);
if (
cachedMeshFloor(cell.lat, cell.lon) != null &&
@@ -211,7 +212,7 @@ export function createMeshFloorSampler({
// feasible and deliberately deferred — see the P2 in
// the project roadmap, which bundles it with the fly_route probe so
// one post-launch pass settles rendered-mesh sampling everywhere.
reportValidatedMeshFloorCell(cell.lat, cell.lon, height);
reportValidatedMeshFloorCell(p.lat, p.lon, height);
}
}