diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 9d90a27d8..d0e08fd37 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -1031,7 +1031,11 @@ "src/styles/surveillance.js", "src/styles/thermal.js", "src/ui/applicationShell.js", + "src/sky/starrySky.js", "src/render/cesium/effects.js", + "src/sky/stars.js", + "src/renderGovernor.js", + "src/data/bundledJson.js", "src/data/iconSetPrimitive.js", "src/data/aircraftRecession.js", "src/data/motionModel.js", diff --git a/src/annotations/worldAnnotationRenderer.js b/src/annotations/worldAnnotationRenderer.js index 17b56de0b..7cf59d02d 100644 --- a/src/annotations/worldAnnotationRenderer.js +++ b/src/annotations/worldAnnotationRenderer.js @@ -3,6 +3,10 @@ import { ringCentroid } from '../sources/featureGeometry.js'; import * as Cesium from 'cesium'; import { showOsmCredit, hideOsmCredit } from '../data/dataCredits.js'; import { heightsFor } from '../render/cesium/heights.js'; +// The annotations entry's Cesium side: it loads the factories that build +// the camera, frame and query ports the engine and screen renderer ask for +// on a viewer with no renderer bound. +import '../render/cesium/camera.js'; /** * World-space annotation renderer (Direction A). diff --git a/src/cameraGlobeRotation.test.mjs b/src/cameraGlobeRotation.test.mjs index febc84225..625f2b81f 100644 --- a/src/cameraGlobeRotation.test.mjs +++ b/src/cameraGlobeRotation.test.mjs @@ -1,4 +1,5 @@ import { bindFakeCesiumCamera } from './testSupport/fakeCameraPort.mjs'; +import { fakeSceneQuery } from './testSupport/fakeCesiumScene.mjs'; import { GLOBE_VIEW } from './locations.js'; import { projectEarthDiscToViewport } from './celestialRing.js'; import assert from 'node:assert/strict'; @@ -147,12 +148,15 @@ function harness( roll: radians(roll), }, }); - const viewer = bindFakeCesiumCamera({ + const double = { camera, scene, trackedEntity: undefined, trackedEntityChanged: new Cesium.Event(), clock: { onTick: new Cesium.Event() }, + }; + const viewer = bindFakeCesiumCamera(double, { + query: fakeSceneQuery(double), }); const target = Cesium.Cartesian3.fromDegrees( longitudeDeg, diff --git a/src/celestialRing.js b/src/celestialRing.js index 4cb6edbd2..8ff83ea47 100644 --- a/src/celestialRing.js +++ b/src/celestialRing.js @@ -1,6 +1,25 @@ -import * as Cesium from 'cesium'; import { governorRequestRender } from './renderGovernor.js'; -import { cameraOf } from './render/cesium/camera.js'; +import { + cameraOf, + findCamera, + findFrame, + findQuery, + rendererOf, +} from './render/rendererOf.js'; +import { + moonPositionInertial, + sunPositionInertial, + temeToPseudoFixed, +} from './geo/celestial.js'; +import { WGS84 } from './geo/ellipsoid.js'; +import { frameVector } from './geo/frames.js'; +import { + dot, + magnitude, + normalize, + PI_OVER_TWO, + toRadians, +} from './geo/vector.js'; /** Outer edge of the existing NVG/FLIR keyhole in normalized shader space. */ export const KEYHOLE_OUTER_RADIUS = 1.05; @@ -32,7 +51,13 @@ export const KEYHOLE_OUTSIDE_OPACITY_DEFAULT = 0.01; const RING_INSET_PX = 11; const MARKER_INSET_PX = 36; const COLLIDING_MARKER_EXTRA_INSET_PX = 32; -const MARKER_COLLISION_ANGLE = Cesium.Math.toRadians(6); +const MARKER_COLLISION_ANGLE = toRadians(6); +/** The ellipsoid's largest radius, metres. */ +const EARTH_MAX_RADIUS_M = Math.max( + WGS84.radii.x, + WGS84.radii.y, + WGS84.radii.z, +); const FULL_GLOBE_RADIUS_RATIO = 0.61; const TAU = Math.PI * 2; // This overlay is a secondary HUD treatment. Keep it smooth while reserving @@ -212,7 +237,7 @@ export function isFullGlobeInsideKeyhole(geometry, wasVisible = false) { /** Return the Earth-disc radius in CSS pixels for a perspective camera. */ export function earthDiscScreenRadius(cameraDistance, viewportHeight, fovy) { - const earthRadiusM = Cesium.Ellipsoid.WGS84.maximumRadius; + const earthRadiusM = EARTH_MAX_RADIUS_M; if ( !Number.isFinite(cameraDistance) || cameraDistance <= earthRadiusM || @@ -228,15 +253,19 @@ export function earthDiscScreenRadius(cameraDistance, viewportHeight, fovy) { return Number.isFinite(radius) && radius > 0 ? radius : null; } +const EARTH_CENTRE = Object.freeze({ x: 0, y: 0, z: 0 }); + /** - * Project the visible Earth disc into viewport coordinates. + * Project the visible Earth disc into viewport coordinates, through the + * renderer's camera pose and its query port's projection. * Shared by full-globe UI treatments that must agree on visual containment. * - * @param {object} viewer - Cesium Viewer-like object. + * @param {object} viewer - The scene object the renderer is found from. * @param {number} width - Viewport width in CSS pixels. * @param {number} height - Viewport height in CSS pixels. - * @param {object} [scratchCenter] - Reusable Cesium Cartesian2 result. - * @param {object} [scratchToCenter] - Reusable Cesium Cartesian3 result. + * @param {{x:number,y:number}} [scratchCenter] - Takes the projected centre. + * @param {{x:number,y:number,z:number}} [scratchToCenter] - Takes the + * vector from the eye to the Earth's centre. * @returns {object|null} */ export function projectEarthDiscToViewport( @@ -246,36 +275,32 @@ export function projectEarthDiscToViewport( scratchCenter = undefined, scratchToCenter = undefined, ) { - const camera = viewer?.camera; - const scene = viewer?.scene; - if (!camera || !scene || !(width > 0) || !(height > 0)) return null; + const camera = findCamera(viewer); + if (!camera || !(width > 0) || !(height > 0)) return null; + const pose = camera.pose(); + const eye = pose.position; - const distance = Cesium.Cartesian3.magnitude(camera.positionWC); + const distance = magnitude(eye); + if (!Number.isFinite(distance) || distance <= EARTH_MAX_RADIUS_M) return null; + + const toCenter = scratchToCenter || { x: 0, y: 0, z: 0 }; + toCenter.x = -eye.x; + toCenter.y = -eye.y; + toCenter.z = -eye.z; + if (dot(pose.direction, toCenter) <= 0) return null; + + const projected = findQuery(viewer)?.project(EARTH_CENTRE); if ( - !Number.isFinite(distance) || - distance <= Cesium.Ellipsoid.WGS84.maximumRadius + !projected || + !Number.isFinite(projected.x) || + !Number.isFinite(projected.y) ) return null; + const center = scratchCenter || { x: 0, y: 0 }; + center.x = projected.x; + center.y = projected.y; - const toCenter = Cesium.Cartesian3.negate( - camera.positionWC, - scratchToCenter || new Cesium.Cartesian3(), - ); - if (Cesium.Cartesian3.dot(camera.directionWC, toCenter) <= 0) return null; - - const center = Cesium.SceneTransforms.worldToWindowCoordinates( - scene, - Cesium.Cartesian3.ZERO, - scratchCenter, - ); - if (!center || !Number.isFinite(center.x) || !Number.isFinite(center.y)) - return null; - - const earthRadius = earthDiscScreenRadius( - distance, - height, - camera.frustum?.fovy, - ); + const earthRadius = earthDiscScreenRadius(distance, height, pose.fovy); if (!earthRadius) return null; const keyhole = getKeyholeGeometry(width, height); @@ -390,14 +415,23 @@ let rings = 0; */ export class CelestialRing { /** - * @param {Cesium.Viewer} viewer - * @param {{enabled?:boolean,onAutoDisable?:Function,store:object}} options + * @param {object} viewer - The scene object the renderer is found from; + * the ring reads its canvas and container (DOM) and reaches the rest + * through the renderer's camera, frame and query ports. + * @param {{enabled?:boolean,onAutoDisable?:Function,store:object,preciseFrameAt?:Function}} options * `store` is the celestial ring store (src/ui/stores/celestialRing.js); * the keyhole helpers here stay free of Vue for the packages that use - * them. + * them. `preciseFrameAt(ms)` gives the ICRF-to-fixed rotation as axes, + * or null while its tables have not loaded; without it, or while it has + * no answer, the ring uses the pseudo-fixed frame. */ - constructor(viewer, { enabled = true, onAutoDisable = null, store }) { + constructor( + viewer, + { enabled = true, onAutoDisable = null, store, preciseFrameAt = null }, + ) { this.viewer = viewer; + this._preciseFrameAt = + typeof preciseFrameAt === 'function' ? preciseFrameAt : null; this.enabled = !!enabled; this.visible = false; this._onAutoDisable = @@ -420,18 +454,14 @@ export class CelestialRing { this._moonCanvas = null; this._moonCtx = null; - this._sunInertial = new Cesium.Cartesian3(); - this._moonInertial = new Cesium.Cartesian3(); - this._sunFixed = new Cesium.Cartesian3(); - this._moonFixed = new Cesium.Cartesian3(); - this._toCenter = new Cesium.Cartesian3(); - this._screenCenter = new Cesium.Cartesian2(); - this._fixedMatrix = new Cesium.Matrix3(); + this._sunFixed = { x: 0, y: 0, z: 0 }; + this._moonFixed = { x: 0, y: 0, z: 0 }; + this._toCenter = { x: 0, y: 0, z: 0 }; + this._screenCenter = { x: 0, y: 0 }; this._initView(store); - this._removePostRender = viewer.scene.postRender.addEventListener(() => - this._draw(), - ); + this._removePostRender = + findFrame(viewer)?.on('postRender', () => this._draw()) ?? null; // Pre-existing staleness fix (perf wave 2 review): the ephemeris was // sampled once per visible-enable from the FROZEN app clock, so the // sun/moon markers aged with the app. Resample real wall time each @@ -534,9 +564,14 @@ export class CelestialRing { }); } + /** The renderer's canvas; a viewer with no renderer bound, its own. */ + _canvas() { + return rendererOf(this.viewer)?.canvas ?? this.viewer.canvas; + } + /** Whether the current camera already frames the complete globe inside the keyhole. */ isGlobeFullyVisible() { - const canvas = this.viewer.scene.canvas; + const canvas = this._canvas(); const width = canvas.clientWidth || canvas.width; const height = canvas.clientHeight || canvas.height; if (!(width > 0 && height > 0)) return false; @@ -551,13 +586,15 @@ export class CelestialRing { * @returns {boolean} Whether a valid camera flight was started. */ focusFullGlobe({ duration = 2.4 } = {}) { - const canvas = this.viewer.scene.canvas; + const canvas = this._canvas(); const height = canvas.clientHeight || canvas.height; - const cartographic = this.viewer.camera.positionCartographic; - const fovy = this.viewer.camera.frustum?.fovy; + const camera = cameraOf(this.viewer); + const pose = camera.pose(); + const fovy = pose.fovy; if ( !(height > 0) || - !cartographic || + !Number.isFinite(pose.lon) || + !Number.isFinite(pose.lat) || !Number.isFinite(fovy) || fovy <= 0 || fovy >= Math.PI @@ -565,7 +602,7 @@ export class CelestialRing { return false; } - const earthRadius = Cesium.Ellipsoid.WGS84.maximumRadius; + const earthRadius = EARTH_MAX_RADIUS_M; const keyholeRadius = getKeyholeGeometry( canvas.clientWidth || canvas.width, height, @@ -577,22 +614,17 @@ export class CelestialRing { const distance = earthRadius / Math.max(Math.sin(angularRadius), 1e-4); const altitude = Math.max(earthRadius * 1.55, distance - earthRadius); - const camera = cameraOf(this.viewer); this._focusInProgress = true; const finishFocus = () => { this._focusInProgress = false; - this.viewer.scene.requestRender?.(); + findFrame(this.viewer)?.requestRender('celestial-focus'); }; camera.flyTo( - Cesium.Cartesian3.fromRadians( - cartographic.longitude, - cartographic.latitude, - altitude, - ), + { lon: pose.lon, lat: pose.lat, height: altitude }, { orientation: { - heading: camera.pose().heading, - pitch: -Cesium.Math.PI_OVER_TWO, + heading: pose.heading, + pitch: -PI_OVER_TWO, roll: 0, }, durationS: duration, @@ -654,31 +686,16 @@ export class CelestialRing { /** * Sample Earth-fixed directions once per enable. Camera movement only * re-projects these cached vectors; it never re-runs the planetary model. + * The precise ICRF frame serves once its tables have loaded, the + * pseudo-fixed one before. + * @param {number} ms Epoch milliseconds. */ - _updateEphemeris(time) { + _updateEphemeris(ms) { if (!this._ephemerisDirty) return true; - Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame( - time, - this._sunInertial, - ); - Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame( - time, - this._moonInertial, - ); - const matrix = - Cesium.Transforms.computeIcrfToFixedMatrix(time, this._fixedMatrix) || - Cesium.Transforms.computeTemeToPseudoFixedMatrix(time, this._fixedMatrix); - if (!matrix) return false; - - Cesium.Matrix3.multiplyByVector(matrix, this._sunInertial, this._sunFixed); - Cesium.Matrix3.multiplyByVector( - matrix, - this._moonInertial, - this._moonFixed, - ); - Cesium.Cartesian3.normalize(this._sunFixed, this._sunFixed); - Cesium.Cartesian3.normalize(this._moonFixed, this._moonFixed); + const frame = this._preciseFrameAt?.(ms) ?? temeToPseudoFixed(ms); + this._sunFixed = normalize(frameVector(frame, sunPositionInertial(ms))); + this._moonFixed = normalize(frameVector(frame, moonPositionInertial(ms))); this._ephemerisDirty = false; this._ephemerisUpdateCount += 1; return true; @@ -775,7 +792,7 @@ export class CelestialRing { const now = performance.now(); if (now < this._nextDrawAt) return; this._nextDrawAt = now + 1000 / CELESTIAL_MAX_FRAME_RATE; - const canvas = this.viewer.scene.canvas; + const canvas = this._canvas(); const width = canvas.clientWidth || canvas.width; const height = canvas.clientHeight || canvas.height; if (!(width > 0 && height > 0)) return; @@ -805,18 +822,17 @@ export class CelestialRing { return; } - const time = Cesium.JulianDate.now(); - if (!this._updateEphemeris(time)) return; + if (!this._updateEphemeris(Date.now())) return; this._present({ ephemerisUpdates: String(this._ephemerisUpdateCount) }); - const camera = this.viewer.camera; + const pose = cameraOf(this.viewer).pose(); const sunProjection = celestialScreenAngle( - Cesium.Cartesian3.dot(this._sunFixed, camera.rightWC), - Cesium.Cartesian3.dot(this._sunFixed, camera.upWC), + dot(this._sunFixed, pose.right), + dot(this._sunFixed, pose.up), this._sunAngle, ); const moonProjection = celestialScreenAngle( - Cesium.Cartesian3.dot(this._moonFixed, camera.rightWC), - Cesium.Cartesian3.dot(this._moonFixed, camera.upWC), + dot(this._moonFixed, pose.right), + dot(this._moonFixed, pose.up), this._moonAngle, ); if (sunProjection.stable) this._sunAngle = sunProjection.angle; diff --git a/src/celestialRingView.test.mjs b/src/celestialRingView.test.mjs index c834ed53a..841f42d74 100644 --- a/src/celestialRingView.test.mjs +++ b/src/celestialRingView.test.mjs @@ -9,7 +9,14 @@ import { createPinia } from 'pinia'; import { useCelestialRingStore } from './ui/stores/celestialRing.js'; import CelestialRingView from './ui/views/panels/CelestialRing.vue'; import * as Cesium from 'cesium'; -import { CelestialRing } from './celestialRing.js'; +import { + CelestialRing, + earthDiscScreenRadius, + projectEarthDiscToViewport, +} from './celestialRing.js'; +import { bindRenderer } from './render/rendererOf.js'; +import { bindFakeCesiumCamera } from './testSupport/fakeCameraPort.mjs'; +import { fakeSceneFrame } from './testSupport/fakeCesiumScene.mjs'; // happy-dom has no 2D context; a stand-in takes every drawing call. const context = new Proxy( @@ -19,18 +26,26 @@ const context = new Proxy( globalThis.HTMLCanvasElement.prototype.getContext = () => context; function fakeViewer(container) { - return { + const canvas = { + clientWidth: 400, + clientHeight: 300, + width: 400, + height: 300, + }; + const viewer = { container, + canvas, camera: { rightWC: new Cesium.Cartesian3(1, 0, 0), upWC: new Cesium.Cartesian3(0, 1, 0), }, scene: { - canvas: { clientWidth: 400, clientHeight: 300, width: 400, height: 300 }, + canvas, postRender: { addEventListener: () => () => {} }, requestRender() {}, }, }; + return bindFakeCesiumCamera(viewer, { frame: fakeSceneFrame(viewer) }); } function fixture(t) { @@ -157,8 +172,7 @@ const FRAMED = { /** Run one rendered frame, past the frame-rate throttle. */ function frame(ring, disc) { ring._projectedEarthDisc = () => disc; - // Fixed sun and moon directions; Cesium's own model would fetch its - // orientation data. + // Fixed sun and moon directions, so markers do not move with the clock. ring._updateEphemeris = () => { if (ring._ephemerisDirty) { Cesium.Cartesian3.clone(new Cesium.Cartesian3(1, 0, 0), ring._sunFixed); @@ -249,3 +263,119 @@ test('a ring the store no longer shows stops drawing', async (t) => { assert.equal(earlier.enabled, true); assert.equal(disabled, 0); }); + +test('the sun and moon directions are the planetary model in the pseudo-fixed frame', () => { + const pinia = createPinia(); + const ring = new CelestialRing(fakeViewer({}), { + enabled: false, + store: useCelestialRingStore(pinia), + // The precise frame's tables have not loaded. + preciseFrameAt: () => null, + }); + const ms = Date.UTC(2026, 10, 7, 12, 30); + ring._ephemerisDirty = true; + assert.equal(ring._updateEphemeris(ms), true); + // Cesium's own, before the sky has loaded the precise frame's tables. + const time = Cesium.JulianDate.fromDate(new Date(ms)); + const matrix = Cesium.Transforms.computeTemeToPseudoFixedMatrix(time); + const expected = (inertial) => + Cesium.Cartesian3.normalize( + Cesium.Matrix3.multiplyByVector( + matrix, + inertial, + new Cesium.Cartesian3(), + ), + new Cesium.Cartesian3(), + ); + const sun = expected( + Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame( + time, + ), + ); + const moon = expected( + Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame( + time, + ), + ); + for (const [got, want] of [ + [ring._sunFixed, sun], + [ring._moonFixed, moon], + ]) + for (const axis of ['x', 'y', 'z']) + assert.ok(Object.is(got[axis], want[axis]), axis); + assert.equal(ring._ephemerisUpdateCount, 1); + ring.destroy(); +}); + +test('the projected disc reads the camera and query ports', () => { + const canvas = { clientWidth: 800, clientHeight: 600 }; + const viewer = { canvas }; + const distance = 3 * 6378137; + const pose = { + position: { x: distance, y: 0, z: 0 }, + direction: { x: -1, y: 0, z: 0 }, + fovy: Math.PI / 3, + }; + const unbind = bindRenderer(viewer, { + canvas, + camera: { pose: () => pose }, + query: { project: () => ({ x: 410, y: 290 }) }, + }); + const toCenter = { x: 0, y: 0, z: 0 }; + const centre = { x: 0, y: 0 }; + const disc = projectEarthDiscToViewport(viewer, 800, 600, centre, toCenter); + assert.equal(disc.earthCenterX, 410); + assert.equal(disc.earthCenterY, 290); + assert.deepEqual(centre, { x: 410, y: 290 }); + // The scratch takes the eye-to-centre vector, as callers read it after. + assert.deepEqual(toCenter, { x: -distance, y: -0, z: -0 }); + assert.ok( + Math.abs( + disc.earthRadius - earthDiscScreenRadius(distance, 600, pose.fovy), + ) < 1e-9, + ); + // Facing away: null, with the eye-to-centre vector still written, as + // radio navigation reads it after. + pose.direction = { x: 1, y: 0, z: 0 }; + const away = { x: 0, y: 0, z: 0 }; + assert.equal(projectEarthDiscToViewport(viewer, 800, 600, null, away), null); + assert.deepEqual(away, { x: -distance, y: -0, z: -0 }); + // Inside the ellipsoid's largest radius: null, the scratch untouched. + pose.position = { x: 6378137, y: 0, z: 0 }; + const inside = { x: 1, y: 2, z: 3 }; + assert.equal( + projectEarthDiscToViewport(viewer, 800, 600, null, inside), + null, + ); + assert.deepEqual(inside, { x: 1, y: 2, z: 3 }); + unbind(); +}); + +test('the precise frame serves once it answers', () => { + const pinia = createPinia(); + // A quarter turn about z: x goes to y. + const quarter = { + x: { x: 0, y: 1, z: 0 }, + y: { x: -1, y: 0, z: 0 }, + z: { x: 0, y: 0, z: 1 }, + }; + const ring = new CelestialRing(fakeViewer({}), { + enabled: false, + store: useCelestialRingStore(pinia), + preciseFrameAt: () => quarter, + }); + const ms = Date.UTC(2026, 10, 7, 12, 30); + ring._ephemerisDirty = true; + ring._updateEphemeris(ms); + const time = Cesium.JulianDate.fromDate(new Date(ms)); + const sun = Cesium.Cartesian3.normalize( + Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame( + time, + ), + new Cesium.Cartesian3(), + ); + assert.ok(Math.abs(ring._sunFixed.x + sun.y) < 1e-12); + assert.ok(Math.abs(ring._sunFixed.y - sun.x) < 1e-12); + assert.ok(Math.abs(ring._sunFixed.z - sun.z) < 1e-12); + ring.destroy(); +}); diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index ed971df7c..3ca1aec4a 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -6,7 +6,6 @@ "src/app/scene.js", "src/app/viewer.js", "src/cameraVerbs.js", - "src/celestialRing.js", "src/cockpitCloudEffects.js", "src/cyberSonarGpu.js", "src/cyberSonarScene.js", diff --git a/src/sky/starrySky.js b/src/sky/starrySky.js index 02e5c7ee3..cbf9d2044 100644 --- a/src/sky/starrySky.js +++ b/src/sky/starrySky.js @@ -128,6 +128,29 @@ export function computeSkyRotation(time, result) { }; } +const scratchIcrf = new Cesium.Matrix3(); + +/** + * The precise ICRF-to-fixed rotation at `ms` (epoch milliseconds) as its + * axes (the matrix's columns, the form `geo/frames` uses), or null while + * Cesium's IAU 2006 tables for that time have not loaded (the sky loads + * them while it shows). Callers fall back to `temeToPseudoFixed`. + * @param {number} ms + * @returns {{x: object, y: object, z: object} | null} + */ +export function icrfToFixedAxes(ms) { + const m = Cesium.Transforms.computeIcrfToFixedMatrix( + Cesium.JulianDate.fromDate(new Date(ms)), + scratchIcrf, + ); + if (!m) return null; + return { + x: { x: m[0], y: m[1], z: m[2] }, + y: { x: m[3], y: m[4], z: m[5] }, + z: { x: m[6], y: m[7], z: m[8] }, + }; +} + /** Whether a cached rotation at `cachedTime` still serves `time`. */ export function isSkyRotationCurrent(cachedTime, time) { return ( diff --git a/src/sky/starrySky.test.mjs b/src/sky/starrySky.test.mjs index 4febeb255..42b08fecc 100644 --- a/src/sky/starrySky.test.mjs +++ b/src/sky/starrySky.test.mjs @@ -7,6 +7,7 @@ import { SKY_ROTATION_EPSILON_SECONDS, StarrySky, computeSkyRotation, + icrfToFixedAxes, isSkyRotationCurrent, } from './starrySky.js'; @@ -198,3 +199,25 @@ test('a render update uploads six opaque black environment faces only once', () Cesium.ContextLimits._maximumCubeMapSize = previous; } }); + +test('the precise frame is given as its axes once its tables answer', (t) => { + const matrix = Cesium.Matrix3.fromRowMajorArray([1, 2, 3, 4, 5, 6, 7, 8, 9]); + let asked = null; + t.mock.method(Cesium.Transforms, 'computeIcrfToFixedMatrix', (time, out) => { + asked = time; + return Cesium.Matrix3.clone(matrix, out); + }); + const ms = Date.UTC(2026, 10, 7); + assert.deepEqual(icrfToFixedAxes(ms), { + x: { x: 1, y: 4, z: 7 }, + y: { x: 2, y: 5, z: 8 }, + z: { x: 3, y: 6, z: 9 }, + }); + assert.ok( + Cesium.JulianDate.equals(asked, Cesium.JulianDate.fromDate(new Date(ms))), + ); + Cesium.Transforms.computeIcrfToFixedMatrix.mock.mockImplementation( + () => undefined, + ); + assert.equal(icrfToFixedAxes(ms), null); +}); diff --git a/src/ui/applicationShell.js b/src/ui/applicationShell.js index b728f9e0e..8b1e2c4a3 100644 --- a/src/ui/applicationShell.js +++ b/src/ui/applicationShell.js @@ -60,6 +60,7 @@ import { applicationPinia, createUiRuntime } from './vueRuntime.js'; import { useContextStore } from './stores/context.js'; import { useMissionReplayStore } from './stores/missionReplay.js'; import { useCelestialRingStore } from './stores/celestialRing.js'; +import { icrfToFixedAxes } from '../sky/starrySky.js'; import { useWorldOverlayActionsStore } from './stores/worldOverlayActions.js'; import { useAwarenessDirectionStore } from './stores/awarenessDirection.js'; import { useHudStore } from './stores/hud.js'; @@ -433,6 +434,8 @@ export class StyleManager extends ShellFacade { this.celestialRing = new CelestialRing(viewer, { enabled: false, store: useCelestialRingStore(applicationPinia()), + // The precise frame, once the sky has loaded its tables. + preciseFrameAt: icrfToFixedAxes, onAutoDisable: () => this.setCelestialRingEnabled(false, { syncShare: !!this.shareLinkManager,