Merge main through #1634 into the renderer seam

Brings in the CCTV opening camera, the Iceland, Giroc HLS, Taiwan, Quebec,
Ottawa and world camera packs, the world clock and timeline, the zoom-out
limit and registered-only layer state, ported onto the renderer contract:
the sky follows the world time through the frame port's setTime in
preUpdate, the Quebec overlay reads the eye, projects and redraws through
the camera, query and frame ports, launches hide pending missions through
their draw records, and mission orbit rings turn on the scene clock.
This commit is contained in:
Sameh Khamis committed 2026-11-10 00:31:23 -08:00
commit 2b60531c3c
170 files changed
+44096 -319

No files matched your search

+43
View File
@@ -2,6 +2,48 @@ import * as Cesium from 'cesium';
import { applyModelAtmosphereWorkaround } from '../../app/atmosphereCompat.js';
import { StarrySky } from './starrySky.js';
/**
* At the farthest a hand can zoom out, the globe is this share of the
* screen's height across. Cesium sets no limit, so zooming on left the globe
* a speck among the stars.
*/
const MIN_GLOBE_SHARE = 0.3;
/**
* The farthest a hand can zoom out, in metres above the ellipsoid, for a
* vertical field of view. It follows the screen's shape, as the app's own
* whole-globe view does, so that view always lies within it.
* @param {number} fovy Vertical field of view, radians.
*/
export function zoomOutLimit(fovy) {
const radius = Cesium.Ellipsoid.WGS84.maximumRadius;
const angular = Math.atan(MIN_GLOBE_SHARE * Math.tan(fovy / 2));
return radius / Math.sin(angular) - radius;
}
/**
* Hold a hand's zoom out to `zoomOutLimit` on the globe, each frame, since the
* field of view follows the screen's shape. The limit never sits below the
* camera: one already past it (a flight, a screen turned) stops there rather
* than jumping in at the next zoom. Flat maps keep Cesium's own, unlimited.
* @returns {() => void} Stop limiting.
*/
export function limitZoomOut(viewer) {
const { scene, camera } = viewer;
return scene.preRender.addEventListener(() => {
const controller = scene.screenSpaceCameraController;
const fovy = camera.frustum.fovy;
if (scene.mode !== Cesium.SceneMode.SCENE3D || !Number.isFinite(fovy)) {
controller.maximumZoomDistance = Number.POSITIVE_INFINITY;
return;
}
controller.maximumZoomDistance = Math.max(
zoomOutLimit(fovy),
camera.positionCartographic?.height ?? 0,
);
});
}
// Dev convenience: expose the app's Cesium instance for console/preview probing
// (single shared module instance — avoids dual-Cesium state bugs when testing).
if (typeof window !== 'undefined' && !window.__CESIUM__)
@@ -46,6 +88,7 @@ export function createApplicationViewer({ container, creditContainer }) {
// required on touch-first screens. Mouse/trackpad sensitivity stays native.
if (globalThis.matchMedia?.('(pointer: coarse)').matches)
viewer.scene.screenSpaceCameraController.zoomFactor *= 3;
limitZoomOut(viewer);
// Before any tile builds a draw command: Cesium's per-vertex model
// atmosphere fails to LINK on Apple's Metal backend and kills the
// render loop. See app/atmosphereCompat.js.
@@ -0,0 +1,73 @@
// A hand zooming out stops while the globe is still a fair share of the
// screen, on any screen's shape, rather than leaving it a speck.
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import { limitZoomOut, zoomOutLimit } from './applicationViewer.js';
// The share of the screen's height the globe spans from `altitude`.
function globeShare(altitude, fovy) {
const radius = Cesium.Ellipsoid.WGS84.maximumRadius;
const angular = Math.asin(radius / (radius + altitude));
return Math.tan(angular) / Math.tan(fovy / 2);
}
test("zooming out stops with the globe 30% of the screen's height across", () => {
for (const fovy of [Math.PI / 3, 0.4, 0.2]) {
const limit = zoomOutLimit(fovy);
assert.ok(Math.abs(globeShare(limit, fovy) - 0.3) < 1e-9, `fovy ${fovy}`);
}
});
test('a wide screen, whose view is narrower, may zoom out farther', () => {
assert.ok(zoomOutLimit(0.4) > zoomOutLimit(Math.PI / 3));
assert.ok(zoomOutLimit(Math.PI / 3) > 20_000_000, 'past the views a link opens');
});
function fakeViewer({ fovy = Math.PI / 3, height = 10_000_000 } = {}) {
const scene = {
mode: Cesium.SceneMode.SCENE3D,
preRender: new Cesium.Event(),
screenSpaceCameraController: { maximumZoomDistance: Infinity },
};
const camera = {
frustum: { fovy },
positionCartographic: { height },
};
return { scene, camera };
}
test('the limit follows the screen, and holds a camera already past it', () => {
const viewer = fakeViewer();
const controller = viewer.scene.screenSpaceCameraController;
const stop = limitZoomOut(viewer);
viewer.scene.preRender.raiseEvent();
assert.equal(controller.maximumZoomDistance, zoomOutLimit(Math.PI / 3));
// A wider screen narrows the view, and the globe may go farther.
viewer.camera.frustum.fovy = 0.4;
viewer.scene.preRender.raiseEvent();
assert.equal(controller.maximumZoomDistance, zoomOutLimit(0.4));
// Flown past it, the next zoom out stops there instead of jumping in.
viewer.camera.positionCartographic.height = zoomOutLimit(0.4) * 2;
viewer.scene.preRender.raiseEvent();
assert.equal(controller.maximumZoomDistance, zoomOutLimit(0.4) * 2);
stop();
viewer.camera.positionCartographic.height = 0;
viewer.scene.preRender.raiseEvent();
assert.equal(controller.maximumZoomDistance, zoomOutLimit(0.4) * 2);
});
test('flat maps keep zooming out unlimited', () => {
const viewer = fakeViewer();
const controller = viewer.scene.screenSpaceCameraController;
limitZoomOut(viewer);
viewer.scene.preRender.raiseEvent();
assert.ok(Number.isFinite(controller.maximumZoomDistance));
viewer.scene.mode = Cesium.SceneMode.SCENE2D;
viewer.camera.frustum = {};
viewer.scene.preRender.raiseEvent();
assert.equal(controller.maximumZoomDistance, Infinity);
});
+1
View File
@@ -2563,6 +2563,7 @@ test('the satellites layer draws its dots as one point collection and its rings
const scene = fakeScene();
const viewer = { scene };
const state = {
now: Date.now,
_points: new Map(),
_orbitPaths: new Map(),
_catalog: new Map([[25544, { satrec: {} }]]),
+19 -3
View File
@@ -126,6 +126,8 @@ export function createSceneFrame(viewer) {
const ownLoop = viewer.useDefaultRenderLoop !== false;
// The preUpdate FrameTime of the tick under way, until it settles.
let liveTick = null;
// The time Cesium stamps the frame in `preUpdate` with, while it runs.
let stampTime = null;
const settleTick = (drawn) => {
if (liveTick)
Object.defineProperty(liveTick, 'rendering', {
@@ -174,6 +176,7 @@ export function createSceneFrame(viewer) {
};
// Read as it is asked: what earlier listeners asked for counts.
if (phase === 'preUpdate') {
stampTime = time ?? null;
Object.defineProperty(t, 'rendering', {
enumerable: true,
configurable: true,
@@ -181,7 +184,11 @@ export function createSceneFrame(viewer) {
});
liveTick = t;
}
listeners[phase].fire(t);
try {
listeners[phase].fire(t);
} finally {
stampTime = null;
}
};
const removers = PHASES.map((phase) =>
scene[phase].addEventListener(onPhase(phase)),
@@ -259,8 +266,17 @@ export function createSceneFrame(viewer) {
viewer.targetFrameRate = fps > 0 ? fps : undefined;
},
setTime(ms) {
viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date(ms));
port.requestRender('time');
const clock = viewer.clock;
const time = Cesium.JulianDate.fromDate(new Date(ms));
const changed = !Cesium.JulianDate.equals(clock.currentTime, time);
clock.currentTime = time;
// In `preUpdate` the frame under way draws at it: Cesium stamps the
// frame with this object next.
if (stampTime) {
Cesium.JulianDate.clone(time, stampTime);
// Later preUpdate listeners read the frame's time from the tick.
if (liveTick) liveTick.time = ms;
} else if (changed) port.requestRender('time');
},
time: () => sceneTime(),
};
+21 -4
View File
@@ -130,6 +130,8 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
// The preUpdate FrameTime of the tick under way: its `rendering` reads
// live until the tick has drawn or not, then holds that answer.
let liveTick = null;
// The time Cesium stamps the frame in `preUpdate` with, while it runs.
let stampTime = null;
const settleTick = (drawn) => {
if (liveTick)
Object.defineProperty(liveTick, 'rendering', {
@@ -169,8 +171,13 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
get: () => willDraw(scene, time),
});
liveTick = t;
stampTime = time ?? null;
}
try {
frameListeners[phase].fire(t);
} finally {
stampTime = null;
}
frameListeners[phase].fire(t);
};
// Reasons given before a frame starts drawing are answered by it; one
// given while it draws waits for the next, as Cesium's own request does.
@@ -295,14 +302,24 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
widget.targetFrameRate = targetFps || undefined;
},
/**
* Moves the clock to `ms` and draws it. Whether the clock then runs on
* Moves the clock to `ms` and draws it; in `preUpdate`, the frame under
* way draws at it. Whether the clock then runs on
* is its owner's: the application's clock keeps running if it was (a
* clock on Cesium's real-time step moves to its multiplier step, as
* setting its time does in Cesium).
*/
setTime(ms) {
widget.clock.currentTime = Cesium.JulianDate.fromDate(new Date(ms));
frame.requestRender('time');
const clock = widget.clock;
const time = Cesium.JulianDate.fromDate(new Date(ms));
const changed = !Cesium.JulianDate.equals(clock.currentTime, time);
clock.currentTime = time;
// In `preUpdate` the frame under way draws at it: Cesium stamps the
// frame with this object next.
if (stampTime) {
Cesium.JulianDate.clone(time, stampTime);
// Later preUpdate listeners read the frame's time from the tick.
if (liveTick) liveTick.time = ms;
} else if (changed) frame.requestRender('time');
},
time: () => Cesium.JulianDate.toDate(widget.clock.currentTime).getTime(),
};