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