refactor(camera): use the globe engine

The startup fly-in, orbit, world-target focus, the arrival ground guard,
arrival ownership, camera sensitivity claims, landmark/viewport/globe
flights and place search (with its view bias and near-view recovery) take
the globe engine. Callers that still hold a viewer (voice, layers until
phase 1c) reach the same engine through engineFromViewer, and arrival
ownership is keyed by the engine whichever one a caller names.

The ground guard yields on camera.commanded instead of patching the
viewer camera itself; on Cesium that event hooks the same command methods
and tracking changes, so direct Cesium callers still end it. Landmark
framing reads the frustum fov from the pose's fovy and aspectRatio.

Tests that built viewer doubles now run on the fake engine (or on the
Cesium engine over the same double), with the same expectations.
This commit is contained in:
German Khokhlov committed 2026-10-15 19:47:43 +04:00
1 parent a3e929870d
commit 16e63f4c50
19 files changed
+601 -215

No files matched your search

+18 -6
View File
@@ -30,6 +30,12 @@ const _cameras = new WeakMap();
/** The value Cesium starts a camera at, used when the camera reports nothing. */
const DEFAULT_PERCENTAGE_CHANGED = 0.5;
/**
* A globe engine (or a viewer) claims through its camera; anything else is
* the camera itself (a camera has no `camera` of its own).
*/
const cameraOf = (target) => target?.camera ?? target;
function ledgerFor(camera) {
let ledger = _cameras.get(camera);
if (!ledger) {
@@ -53,12 +59,16 @@ function applyLedger(camera, ledger) {
/**
* Ask for a camera-change sensitivity at least as fine as `value`.
* @param {object|null|undefined} camera A Cesium camera (or anything with `percentageChanged`).
* @param {object|null|undefined} target A globe engine, its camera, or a
* Cesium camera (anything with `percentageChanged`). Layers still pass the
* viewer's Cesium camera until phase 1c; that is a separate claimant from
* the engine's camera, so one camera must not be claimed both ways.
* @param {string} owner Stable claim name, usually the layer id.
* @param {number} value Requested `percentageChanged`.
* @returns {number|null} The value now in force, or null when there is no camera.
*/
export function claimCameraSensitivity(camera, owner, value) {
export function claimCameraSensitivity(target, owner, value) {
const camera = cameraOf(target);
if (!camera || !owner || !Number.isFinite(value)) return null;
const ledger = ledgerFor(camera);
ledger.claims.set(owner, value);
@@ -68,11 +78,12 @@ export function claimCameraSensitivity(camera, owner, value) {
/**
* Give up one claim. The camera keeps the finest value still claimed by
* somebody else, and returns to its original only when none are left.
* @param {object|null|undefined} camera
* @param {object|null|undefined} target A globe engine or a camera.
* @param {string} owner
* @returns {number|null} The value now in force, or null when there is no camera.
*/
export function releaseCameraSensitivity(camera, owner) {
export function releaseCameraSensitivity(target, owner) {
const camera = cameraOf(target);
if (!camera || !owner) return null;
const ledger = _cameras.get(camera);
if (!ledger) return null;
@@ -84,10 +95,11 @@ export function releaseCameraSensitivity(camera, owner) {
/**
* Who currently holds a claim. For tests and diagnostics only.
* @param {object|null|undefined} camera
* @param {object|null|undefined} target A globe engine or a camera.
* @returns {Array<string>}
*/
export function cameraSensitivityClaims(camera) {
export function cameraSensitivityClaims(target) {
const camera = cameraOf(target);
const ledger = camera ? _cameras.get(camera) : null;
return ledger ? [...ledger.claims.keys()] : [];
}