Move the launches replay and selection cameras onto the camera port

Replay and selection no longer import Cesium. Their maths uses the geo
helpers; the full-globe framing reads the camera's position and field of
view from the port's pose. Choosing the selected entity, showing only the
selected mission's entities and reading the projected orbit for framing
move into the rendering part, which owns the entities, so selection no
longer touches them. The full-globe framing now checks the canvas size
before it asks for the camera.

The replay camera still steps in the scene's preUpdate, as before; it moves
onto the frame port once unbound viewers have one.

Replay and selection leave the allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-06 22:57:55 -08:00
1 parent a2503476de
commit e2dea507b9
4 files changed
+99 -104

No files matched your search

+17 -21
View File
@@ -1,8 +1,9 @@
import { stopFollowing } from '../../data/followed.js';
import * as Cesium from 'cesium';
import { toCartographicRadians } from '../../geo/ellipsoid.js';
import { clamp, distance, toRadians } from '../../geo/vector.js';
import { t } from '../../i18n/index.js';
import { cameraOf } from '../../render/cesium/camera.js';
import { findCamera } from '../../render/rendererOf.js';
import { cameraOf, findCamera } from '../../render/rendererOf.js';
import { lerp } from './geometry.js';
import {
REPLAY_ASCENT_FALLBACK_SEC,
REPLAY_ASCENT_MIN_SEC,
@@ -56,10 +57,10 @@ export function createReplay({ state: layerState, services, parts, source }) {
if (!previous || !next) return next;
const distance = Math.hypot(next.x - previous.x, next.y - previous.y);
if (!Number.isFinite(distance) || distance > snapDistance) return next;
const amount = Cesium.Math.clamp(Number(alpha) || 0, 0, 1);
const amount = clamp(Number(alpha) || 0, 0, 1);
return {
x: Cesium.Math.lerp(previous.x, next.x, amount),
y: Cesium.Math.lerp(previous.y, next.y, amount),
x: lerp(previous.x, next.x, amount),
y: lerp(previous.y, next.y, amount),
};
}
@@ -69,7 +70,8 @@ export function createReplay({ state: layerState, services, parts, source }) {
* SECO, or separation timing. Sparse records fall back to the reconstructed
* path length and a conservative ascent velocity estimate.
* @param {object} launch Normalized launch record.
* @param {Cesium.Cartesian3[]} ascentPath Reconstructed or supplied ascent.
* @param {Array<{x: number, y: number, z: number}>} ascentPath
* Reconstructed or supplied ascent, ECEF.
* @returns {number} Replay duration in seconds.
*/
@@ -80,14 +82,13 @@ export function createReplay({ state: layerState, services, parts, source }) {
const pathLength = ascentPath
.slice(1)
.reduce(
(total, point, index) =>
total + Cesium.Cartesian3.distance(ascentPath[index], point),
(total, point, index) => total + distance(ascentPath[index], point),
0,
);
realAscentSeconds = Math.max(180, pathLength / 9000);
}
if (!realAscentSeconds) realAscentSeconds = REPLAY_ASCENT_FALLBACK_SEC * 50;
return Cesium.Math.clamp(
return clamp(
REPLAY_ASCENT_FALLBACK_SEC * (realAscentSeconds / 600),
REPLAY_ASCENT_MIN_SEC,
REPLAY_ASCENT_MAX_SEC,
@@ -103,11 +104,7 @@ export function createReplay({ state: layerState, services, parts, source }) {
function normalizeReplaySpeed(value) {
const numeric = Number(value);
if (!Number.isFinite(numeric)) return 1;
const clamped = Cesium.Math.clamp(
numeric,
REPLAY_SPEED_MIN,
REPLAY_SPEED_MAX,
);
const clamped = clamp(numeric, REPLAY_SPEED_MIN, REPLAY_SPEED_MAX);
return Math.round(clamped / REPLAY_SPEED_STEP) * REPLAY_SPEED_STEP;
}
@@ -393,7 +390,7 @@ export function createReplay({ state: layerState, services, parts, source }) {
track.lastCameraHeading,
);
const orbitBlend = !state.ascending
? Cesium.Math.clamp(
? clamp(
(Number(state.phaseProgress) || 0) /
REPLAY_ORBIT_PULLBACK_FRACTION,
0,
@@ -407,16 +404,15 @@ export function createReplay({ state: layerState, services, parts, source }) {
if (state.ascending) track.orbitCameraWorldFrame = false;
const nowMs = performance.now();
const frameDurationMs = Number.isFinite(lastCameraUpdateMs)
? Cesium.Math.clamp(nowMs - lastCameraUpdateMs, 4, 50)
? clamp(nowMs - lastCameraUpdateMs, 4, 50)
: 1000 / 60;
lastCameraUpdateMs = nowMs;
track.lastCameraHeading = parts.camera.smoothReplayCameraHeading(
track.lastCameraHeading,
desiredHeading,
(Cesium.Math.toRadians(2) * frameDurationMs) / (1000 / 60),
(toRadians(2) * frameDurationMs) / (1000 / 60),
);
const cartographic =
Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
const cartographic = toCartographicRadians(position);
const altitude = Math.max(0, cartographic?.height || 0);
const cameraView = parts.camera.replayCameraView(state, altitude);
const defaultOrbitTarget = !state.ascending
@@ -492,7 +488,7 @@ export function createReplay({ state: layerState, services, parts, source }) {
{
offset: {
heading: initialHeading,
pitch: Cesium.Math.toRadians(-20),
pitch: toRadians(-20),
range: REPLAY_INITIAL_RANGE_M,
},
durationS: 1.4,