Fly the remaining flights through the camera port, on any viewer

The embed view, the celestial-ring focus, the ground-guard lift, the
Bhote Koshi approach and orbit, launch selection and replay flights, and
the cockpit's view and takeover now drive the renderer's camera port.
The contract gains a sineInOut easing, pinned by a conformance trace.

A viewer with no renderer bound, such as one a caller of a public
export brings, now gets a camera port too, as it already got an input
port: cameraOf builds one over the viewer's own Cesium camera and keeps
it for the viewer's life, until a renderer is bound. The Cesium adapter
provides the factory as it loads; code that reaches Cesium takes cameraOf
from the adapter so the factory comes with it, and findCamera answers
null where a missing camera is not an error (HUD, share link, world
focus, Recent Imagery's ZOOM IN). A test walks every package export and
fails one that can reach the bridge without loading the factory.

A destroyed viewer gets no camera and lets go of a built one, and the
application renderer stays bound until its viewer is destroyed.
This commit is contained in:
Sameh Khamis committed 2026-11-06 08:21:57 -08:00
1 parent c5b716b107
commit 1d4e4ebe90
44 files changed
+1167 -344

No files matched your search

+3 -1
View File
@@ -121,11 +121,13 @@ export function createCesiumRendererPlugin({
},
destroy() {
try {
unbind();
input.dispose();
ports.dispose();
if (!viewer.isDestroyed()) viewer.destroy();
} finally {
// Bound until the viewer is gone: a late `cameraOf` must not
// build a camera of its own over the application's viewer.
unbind();
creditContainer.remove();
}
},
+25 -1
View File
@@ -6,8 +6,15 @@
*/
import * as Cesium from 'cesium';
import { createCameraEvents } from '../camera/events.js';
import { listenerList, toCartesian } from './common.js';
import { listenerList, toCartesian, uncaught } from './common.js';
import { cameraFlightActive } from './internals.js';
import { cameraOf, provideUnboundCamera } from '../rendererOf.js';
/**
* `cameraOf`, for code that already reaches Cesium: importing it from here
* loads the factory a viewer with no renderer bound gets its camera from.
*/
export { cameraOf };
/** The contract's easings as Cesium's. */
export const EASINGS = Object.freeze({
@@ -16,6 +23,7 @@ export const EASINGS = Object.freeze({
cubicInOut: Cesium.EasingFunction.CUBIC_IN_OUT,
cubicOut: Cesium.EasingFunction.CUBIC_OUT,
quinticInOut: Cesium.EasingFunction.QUINTIC_IN_OUT,
sineInOut: Cesium.EasingFunction.SINUSOIDAL_IN_OUT,
});
/** A contract destination as Cesium's: a Cartesian3, or a Rectangle. */
@@ -265,3 +273,19 @@ export function createCesiumCamera({ scene, camera, report }) {
},
};
}
// A Cesium viewer with no renderer bound to it gets a
// camera port over its camera when code first asks `cameraOf` for one.
provideUnboundCamera((viewer) =>
// By shape, not `instanceof`: the viewer may come from another
// copy of Cesium.
typeof viewer.camera?.flyTo === 'function' &&
typeof viewer.camera.moveStart?.addEventListener === 'function' &&
typeof viewer.scene?.postUpdate?.addEventListener === 'function'
? createCesiumCamera({
scene: viewer.scene,
camera: viewer.camera,
report: uncaught,
})
: null,
);
+1
View File
@@ -29,6 +29,7 @@ const EASINGS = {
cubicInOut: Cesium.EasingFunction.CUBIC_IN_OUT,
cubicOut: Cesium.EasingFunction.CUBIC_OUT,
quinticInOut: Cesium.EasingFunction.QUINTIC_IN_OUT,
sineInOut: Cesium.EasingFunction.SINUSOIDAL_IN_OUT,
};
/** One frame of the virtual clock, ms. */
+24
View File
@@ -15,6 +15,7 @@ import {
import { FRAME_MS, headlessCamera, withVirtualClock } from './cameraGoldens.js';
import { createCesiumCamera } from './camera.js';
import { createCesiumPorts } from './ports.js';
import { cameraOf } from '../rendererOf.js';
/** Records the headless scene cannot answer: they need the query port. */
const QUERY_RECORDS = new Set([
@@ -208,3 +209,26 @@ test('a flight Cesium does not start ends cancelled rather than never', async ()
assert.equal(await flight.done, 'cancelled');
assert.equal(port.flying, false);
});
test('a Cesium viewer with no renderer bound gets a camera port over its own camera', async () => {
await withVirtualClock(async () => {
const { scene, camera } = headlessCamera();
scene.postUpdate = new Cesium.Event();
scene.requestRender = () => {};
const viewer = { scene, camera };
const port = cameraOf(viewer);
assert.equal(cameraOf(viewer), port, 'one port per viewer');
let outcome = null;
port.flyTo(
{ lon: 2.35, lat: 48.86, height: 1500 },
{ durationS: 0, onComplete: () => (outcome = 'complete') },
);
assert.equal(outcome, 'complete');
const pose = port.pose();
assert.ok(
Math.abs(pose.lon - 2.35) < 1e-9 && Math.abs(pose.lat - 48.86) < 1e-9,
);
assert.ok(Math.abs(pose.height - 1500) < 1e-6);
assert.throws(() => cameraOf({ scene, camera: {} }), /no renderer camera/);
});
});
+15
View File
@@ -50,3 +50,18 @@ export function toCartesian(pos) {
if ('x' in pos) return new Cesium.Cartesian3(pos.x, pos.y, pos.z);
return Cesium.Cartesian3.fromDegrees(pos.lon, pos.lat, pos.height ?? 0);
}
/**
* Where a listener's throw goes with no `error` listener: the platform's
* `reportError` (or a rethrow on a microtask), as a browser reports an event
* listener's exception, loud, while the frame and the other listeners carry
* on.
*/
export function uncaught(error) {
if (typeof globalThis.reportError === 'function')
globalThis.reportError(error);
else
queueMicrotask(() => {
throw error;
});
}
+1 -16
View File
@@ -14,7 +14,7 @@
import * as Cesium from 'cesium';
import { heightsFor } from '../../queries/heights.js';
import { createCesiumCamera } from './camera.js';
import { listenerList, toCartesian } from './common.js';
import { listenerList, toCartesian, uncaught } from './common.js';
import {
atEndOfTick,
billboardLoadError,
@@ -25,21 +25,6 @@ import {
export { listenerList, toCartesian };
/**
* Where a listener's throw goes with no `error` listener: the platform's
* `reportError` (or a rethrow on a microtask), as a browser reports an event
* listener's exception, loud, while the frame and the other listeners carry
* on.
*/
function uncaught(error) {
if (typeof globalThis.reportError === 'function')
globalThis.reportError(error);
else
queueMicrotask(() => {
throw error;
});
}
/** The contract's colour as Cesium's. */
export function toColor(color, alpha = 1) {
if (color === undefined || color === null)