From 8c024f5ea74708a0702c6afb2d5be0864ef55ebb Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 7 Nov 2026 04:19:56 -0800 Subject: [PATCH] Ask heights through the gateway at the flight sites, and load the camera factory from ground snapping The camera ground guard, place and landmark flights and imported-file flights read terrain and surface heights through heightsOf, the one place the app's height queries go, rather than asking the query port themselves. With the annotation resolver off the allow-list, ground snapping, which the application operations entry also reaches and which stays listed, loads the Cesium camera factory for a viewer with no renderer bound. The height docs say what the Cesium renderer answers without depth textures: no surface or tiles height, and terrain from the loaded tiles. --- docs/APPLICATION.md | 5 +++-- src/cameraGroundGuard.js | 20 +++++++++++--------- src/locations.js | 9 +++++---- src/queries/heights.js | 7 ++++--- src/services/groundSnap.js | 6 ++++++ src/ui/flyToDataSource.js | 9 +++++---- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/docs/APPLICATION.md b/docs/APPLICATION.md index 026c76432..ec92aaf56 100644 --- a/docs/APPLICATION.md +++ b/docs/APPLICATION.md @@ -166,8 +166,9 @@ with `includeInHeightQueries`; `clampNow` and `clampBatch` always clamp to the surface. `exclude` lists draw set ids to see through, of those drawn with `includeInHeightQueries`; every other draw set is seen through already. Every miss is `null`, and every caller treats it as one; `batch` and `clampBatch` -reject when the query itself fails. The Cesium renderer answers no height, -terrain included, without depth-texture support. +reject when the query itself fails. Without depth-texture support the Cesium +renderer answers no `surface` or `tiles` height; `now` still answers +`terrain` from the loaded tiles. ## Cesium internals diff --git a/src/cameraGroundGuard.js b/src/cameraGroundGuard.js index a93456d18..9ba67be47 100644 --- a/src/cameraGroundGuard.js +++ b/src/cameraGroundGuard.js @@ -17,7 +17,8 @@ import { onFollowChanged } from './data/followed.js'; import { ownCameraArrival } from './data/cameraArrival.js'; import { distance, dot, fromDegrees, toLonLatH } from './geo/index.js'; -import { findCamera, findQuery } from './render/rendererOf.js'; +import { heightsOf } from './queries/heights.js'; +import { findCamera } from './render/rendererOf.js'; /** Minimum eye height above the rendered surface for a usable view. */ export const MIN_EYE_CLEARANCE_M = 120; @@ -33,17 +34,18 @@ const TURNED_COS = 1 - 1e-9; /** * Highest rendered surface across a few cells, with how many cells answered. * A cell whose tiles are not streamed yet contributes nothing. - * @param {object|null} query The scene's query port. + * @param {import('./queries/heights.js').HeightService|null} heights The + * scene's height service. * @param {Array<{lat: number, lon: number}>} cells Cells to probe. * @returns {{heightM: number, sampled: number}} Reading. */ -function sampleSurfaceM(query, cells) { +function sampleSurfaceM(heights, cells) { let heightM = Number.NaN; let sampled = 0; - if (!query) return { heightM, sampled }; + if (!heights) return { heightM, sampled }; for (const cell of cells) { // A miss is a cell whose tiles are not ready. - const height = query.sampleHeightNow({ lon: cell.lon, lat: cell.lat }); + const height = heights.now(cell); if (!Number.isFinite(height)) continue; sampled += 1; heightM = Number.isFinite(heightM) ? Math.max(heightM, height) : height; @@ -180,10 +182,10 @@ export function guardCameraAboveGround(viewer, at, options = {}) { remaining -= 1; // The eye must clear both the framed target and the ground beneath it. const below = { lat: now.lat, lon: now.lon }; - const { heightM, sampled } = sampleSurfaceM(findQuery(viewer), [ - { lat: at.lat, lon: at.lon }, - below, - ]); + const { heightM, sampled } = sampleSurfaceM( + viewer ? heightsOf(viewer) : null, + [{ lat: at.lat, lon: at.lon }, below], + ); if (sampled > 0 && Number.isFinite(heightM)) { const deficit = groundClearanceDeficitM(now.height, heightM, clearanceM); if (deficit > 0) { diff --git a/src/locations.js b/src/locations.js index 9857f156d..c2834ba8e 100644 --- a/src/locations.js +++ b/src/locations.js @@ -12,7 +12,8 @@ import { cancelCameraArrival } from './data/cameraArrival.js'; import { guardCameraAboveGround } from './cameraGroundGuard.js'; import { CITY_POIS } from './cityPois.js'; import { fromDegrees, toRadians } from './geo/index.js'; -import { cameraOf, findQuery } from './render/rendererOf.js'; +import { heightsOf } from './queries/heights.js'; +import { cameraOf } from './render/rendererOf.js'; /** Newest landmark arrival; an older post-arrival ground guard yields to it. */ let arrivalGeneration = 0; @@ -102,9 +103,9 @@ export function flyToLandmark(viewer, lat, lon, options = {}) { } = options; // Sample terrain height (sync — uses loaded tiles; 0 if globe/terrain not ready) - const sampledHeight = - findQuery(viewer)?.sampleHeightNow({ lon, lat }, { against: 'terrain' }) ?? - null; + const sampledHeight = viewer + ? heightsOf(viewer).now({ lon, lat }, { against: 'terrain' }) + : null; // Use sampled height if available, otherwise the cached ground-floor // elevation (same ellipsoidal datum), then the pre-baked city elevation. diff --git a/src/queries/heights.js b/src/queries/heights.js index eddb525e0..692fdbc11 100644 --- a/src/queries/heights.js +++ b/src/queries/heights.js @@ -12,9 +12,10 @@ * request error, a destroyed scene), so a caller can tell a failure from * points that are merely uncovered. * - * What the renderer cannot answer is a miss: the Cesium renderer answers no - * height, terrain included, without depth textures (its `sampleHeight` - * capability). + * What the renderer cannot answer is a miss: without depth textures (its + * `sampleHeight` capability) the Cesium renderer answers no `'surface'` or + * `'tiles'` height; `now()` still answers `'terrain'` from the globe's + * loaded tiles. * * `against` picks the surface: `'surface'` is what is drawn (tiles, the * globe, and draw sets drawn as ground), `'terrain'` the terrain alone, diff --git a/src/services/groundSnap.js b/src/services/groundSnap.js index 4f97463dd..39235923c 100644 --- a/src/services/groundSnap.js +++ b/src/services/groundSnap.js @@ -48,6 +48,12 @@ import * as Cesium from 'cesium'; import { heightsFor } from '../render/cesium/heights.js'; +// The application operations entry reaches the annotation resolver and +// locations.js, whose flights and heights go through the camera and query +// ports and which cannot load the Cesium adapter themselves; this listed +// module, on the same entry, loads the factories a viewer with no renderer +// bound gets them from. +import '../render/cesium/camera.js'; /** Taxi threshold: a cached snap answers directly for moves up to this far from * the sampled spot (m). Past it the value is demoted to a held last-known and a diff --git a/src/ui/flyToDataSource.js b/src/ui/flyToDataSource.js index b929f7dbd..122158dd2 100644 --- a/src/ui/flyToDataSource.js +++ b/src/ui/flyToDataSource.js @@ -4,7 +4,8 @@ import { rangeForBoundingSphere } from '../data/cameraFraming.js'; import { cancelCameraArrival } from '../data/cameraArrival.js'; import { distance, fromDegrees, toLonLatH } from '../geo/index.js'; import { sphereFromPoints } from '../geo/sphere.js'; -import { findCamera, findQuery } from '../render/rendererOf.js'; +import { heightsOf } from '../queries/heights.js'; +import { findCamera } from '../render/rendererOf.js'; /** * Fly synchronously to a footprint, `[lon, lat, height]` points (degrees, @@ -30,9 +31,9 @@ export function flyToFootprint( height: 0, }; const { lat, lon } = center; - const terrain = - findQuery(viewer)?.sampleHeightNow({ lon, lat }, { against: 'terrain' }) ?? - null; + const terrain = viewer + ? heightsOf(viewer).now({ lon, lat }, { against: 'terrain' }) + : null; const cached = ground?.cachedGroundFloor?.(lat, lon); const height = Number.isFinite(terrain) && terrain > 0