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

+59 -6
View File
@@ -9,13 +9,36 @@
const renderers = new WeakMap();
/**
* Bind a renderer to its scene object.
* Camera ports built for scene objects no renderer is bound to (a viewer of
* a caller's own, say), each `{port, dispose}` and kept for as long as its
* scene object lives, or until a renderer is bound to it.
*/
const unboundCameras = new WeakMap();
let buildUnboundCamera = null;
/**
* Provide the factory `cameraOf` builds a camera port with for a scene
* object no renderer is bound to. The renderer adapter provides it as it
* loads; a later call replaces it.
* @param {(host: object) => ({port: object, dispose: () => void} | null)} build
*/
export function provideUnboundCamera(build) {
buildUnboundCamera = build;
}
/**
* Bind a renderer to its scene object. A camera `cameraOf` built for it
* while it had no renderer is disposed: its listeners hear nothing more,
* and `cameraOf` answers with the renderer's camera from then on.
* @param {object} host The scene object callers hold.
* @param {object} renderer
* @returns {() => void} Unbinds, if the binding is still this one.
*/
export function bindRenderer(host, renderer) {
if (renderers.has(host)) throw new Error('This scene already has a renderer');
// The renderer's camera supersedes one built while there was none.
unboundCameras.get(host)?.dispose();
unboundCameras.delete(host);
renderers.set(host, renderer);
return () => {
if (renderers.get(host) === renderer) renderers.delete(host);
@@ -29,13 +52,43 @@ export function bindRenderer(host, renderer) {
export const rendererOf = (host) => (host && renderers.get(host)) || null;
/**
* The camera port of the renderer bound to `host`.
* The camera port of the renderer bound to `host`; with no renderer bound,
* one built over `host` by the provided factory and kept with it while
* `host` lives.
* @param {object|null|undefined} host
* @returns {import('./contract/camera').CameraPort | null} Null when `host`
* has no renderer and no camera can be built for it, or is destroyed.
*/
export function findCamera(host) {
const camera = rendererOf(host)?.camera;
if (camera) return camera;
if (!host || typeof host !== 'object') return null;
if (host.isDestroyed?.()) {
// Gone with its scene: let the built camera go with it.
unboundCameras.get(host)?.dispose();
unboundCameras.delete(host);
return null;
}
let built = unboundCameras.get(host);
if (!built && buildUnboundCamera) {
built = buildUnboundCamera(host);
if (built) unboundCameras.set(host, built);
}
return built?.port ?? null;
}
/**
* `findCamera`, for code that needs the camera.
* @param {object} host
* @returns {import('./contract/camera').CameraPort}
* @throws When no renderer is bound to `host`.
* @throws When there is no camera for `host`.
*/
export function cameraOf(host) {
const camera = rendererOf(host)?.camera;
if (!camera) throw new Error('This scene has no renderer camera');
return camera;
const camera = findCamera(host);
if (camera) return camera;
throw new Error(
host?.isDestroyed?.()
? 'This scene has been destroyed'
: 'This scene has no renderer camera',
);
}