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

+17 -14
View File
@@ -1,8 +1,8 @@
/**
* One-click camera transfer for layer-owned world targets.
*/
import * as Cesium from 'cesium';
import * as geo from './geo/index.js';
import { engineFromViewer } from './globe/cesium/engineFromViewer.js';
export const WORLD_FOCUS_REQUEST_EVENT = 'gev:world-request-focus';
export const WORLD_CLICK_FOCUS_DURATION_SEC = 1.9;
@@ -70,27 +70,30 @@ export function routeWorldFocusRequest(event, runExplicitFocus, fly) {
return runExplicitFocus(detail, () => fly(detail));
}
/** Fly to a world target after ownership has been released. */
export function flyToWorldTarget(viewer, target = {}) {
const camera = viewer?.camera;
/**
* Fly to a world target after ownership has been released.
* @param {import('./globe/contract.js').GlobeEngine | object | null} engine
* The globe engine, or a viewer registered for one.
*/
export function flyToWorldTarget(engine, target = {}) {
const camera = engineFromViewer(engine)?.camera;
const framing = WORLD_FOCUS_FRAMING[target.kind];
if (!camera || !framing || !isValidWorldFocusTarget(target)) return false;
const heading = Number.isFinite(camera.heading) ? camera.heading : 0;
const { heading: current } = camera.pose();
const heading = Number.isFinite(current) ? current : 0;
const duration =
target.durationSec > 0
? target.durationSec
: WORLD_CLICK_FOCUS_DURATION_SEC;
camera.cancelFlight?.();
camera.flyToBoundingSphere(
new Cesium.BoundingSphere(target.position, framing.radiusM),
camera.cancelFlight();
camera.flyToSphere(
{ center: target.position, radius: framing.radiusM },
{
offset: new Cesium.HeadingPitchRange(
heading,
geo.math.toRadians(framing.pitchDeg),
framing.rangeM,
),
heading,
pitch: geo.math.toRadians(framing.pitchDeg),
range: framing.rangeM,
duration,
easingFunction: Cesium.EasingFunction.CUBIC_IN_OUT,
easing: 'cubicInOut',
},
);
return true;