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.
This commit is contained in:
Sameh Khamis committed 2026-11-14 00:35:32 -08:00
1 parent 1c036957cd
commit ca7a736456
2 files changed
+40 -3

No files matched your search

+20 -3
View File
@@ -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);
+20
View File
@@ -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',
);
}
});