From ca7a736456fa8edb78a163651e1647b6e4cc48f4 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 14 Nov 2026 00:35:32 -0800 Subject: [PATCH] fix(alpr): no height sample is spent without sampling, and no terrain anchor under a hidden globe On Cesium the overlay sampled the drawn surface only where the scene supported height sampling (depth textures), and fell back to the globe's terrain only while the globe was shown. On the ports, a renderer without sampling spent the paint's sample budget on misses and the refine pass kept asking every paint, and a hidden globe's stale terrain could anchor a marker under photoreal tiles. Both rules are back, through the renderer's sampleHeight capability and the globe's visibility. --- src/layers/alpr/overlay.js | 23 ++++++++++++++++++++--- src/layers/alpr/overlay.test.mjs | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/layers/alpr/overlay.js b/src/layers/alpr/overlay.js index 9bb93c18c..a99684818 100644 --- a/src/layers/alpr/overlay.js +++ b/src/layers/alpr/overlay.js @@ -106,19 +106,36 @@ export function createAlprOverlay({ record.longitude, ); if (validAlprGroundHeight(floor)) height = floor + MARKER_FLOOR_LIFT_M; - else if (query) { + else if (query && canSampleHeight()) { if (budget.samples <= 0) return null; budget.samples -= 1; // A miss is tiles still streaming. height = query.sampleHeightNow(point, { exclude: [markers.icons?.id] }); } - if (!validAlprGroundHeight(height)) + // The globe's terrain, while the globe is drawn (hidden under photoreal + // tiles, its height is not what shows). + if (!validAlprGroundHeight(height) && globeShown()) height = query?.sampleHeightNow(point, { against: 'terrain' }); if (!validAlprGroundHeight(height)) return null; setAnchor(record, carrier, height); return alprMarkers.read(carrier)?.canvasPosition; } + /** + * Whether the renderer samples the drawn surface's height (Cesium needs + * depth textures). Without, nothing is sampled or spent from the budget, + * and a marker with no floor yet anchors on the terrain. + */ + function canSampleHeight() { + const capabilities = rendererOf(state.viewer)?.capabilities; + return !capabilities || capabilities.has('sampleHeight'); + } + + /** Whether the globe surface is drawn; true where the renderer cannot say. */ + function globeShown() { + return rendererOf(state.viewer)?.globe?.isGlobeVisible?.() !== false; + } + function floorHeightAt(latitude, longitude) { const floor = services.groundFloor.cachedGroundFloor(latitude, longitude); return validAlprGroundHeight(floor) ? floor + MARKER_FLOOR_LIFT_M : null; @@ -162,7 +179,7 @@ export function createAlprOverlay({ direction: { ...pose.direction }, }; const query = findQuery(state.viewer); - if (!query) return false; + if (!query || !canSampleHeight()) return false; let pending = false; for (const record of records) { const carrier = markers.get(record.id); diff --git a/src/layers/alpr/overlay.test.mjs b/src/layers/alpr/overlay.test.mjs index f8fc003a7..a938373ee 100644 --- a/src/layers/alpr/overlay.test.mjs +++ b/src/layers/alpr/overlay.test.mjs @@ -360,3 +360,23 @@ test('anchors wait for the surface heights answer from: the globe’s terrain wh h.paint(); assert.ok(samples > 0, 'sampled once it has loaded'); }); + +test('without height sampling no sample is spent, and the terrain anchors only while the globe is drawn', (t) => { + for (const shown of [true, false]) { + const h = harness(t, 1); + let samples = 0; + h.state.viewer.scene.sampleHeight = () => (samples++, 172); + const renderer = rendererOf(h.state.viewer); + renderer.capabilities = new Set(); + renderer.globe = { isSettled: () => true, isGlobeVisible: () => shown }; + h.overlay.sync(h.records); + h.paint(); + h.paint(); + assert.equal(samples, 0, 'nothing sampled without the capability'); + assert.equal( + Boolean(alprMarkers.read(h.carrier('camera:0'))?.canvasPosition), + shown, + shown ? 'anchored on the terrain' : 'no terrain under hidden globe', + ); + } +});