diff --git a/docs/CODE-BOUNDARIES.md b/docs/CODE-BOUNDARIES.md index c8cdf742b..3df85b7a4 100644 --- a/docs/CODE-BOUNDARIES.md +++ b/docs/CODE-BOUNDARIES.md @@ -468,6 +468,10 @@ release listeners; pending action feedback is limited to its current owner. rendering, HUD and share operations. `src/standalone/controls.js` provides the running application's instances. The shell imports no standalone bootstrap or concrete live layer implementation. +The celestial ring's precise ICRF rotation comes from the renderer +(`src/sky/icrf.js`): the application's renderer provides it; a shell given a +viewer with no renderer bound gets it once `./render/cesium/unbound` has loaded, and +falls back to the TEME approximation until then. Panel layout, position/drag, notices, recording and deferred UI work have separate owners with synchronous cleanup. Existing scene, share and HUD engines retain their entry points. `ui/styles` loads the ordered stylesheet entry; component diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 8987bd96e..36999824d 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1502,10 +1502,11 @@ The clear control presents busy state while its existing action owns the transac ## Sky background -`src/sky/starrySky.js` fills Cesium's `Scene#skyBox` slot with 9,096 Yale +`src/render/cesium/starrySky.js` fills Cesium's `Scene#skyBox` slot with 9,096 Yale Bright Star Catalogue stars and a soft ESO/S. Brunier Milky Way. Both layers rotate from ICRF/J2000 into the Earth-fixed frame at the scene clock, with -a TEME fallback while Cesium's IAU 2006 tables load. Bundled assets and +a TEME fallback while Cesium's IAU 2006 tables load. The precise rotation reaches +Cesium-free code (the celestial ring) through `src/sky/icrf.js`. Bundled assets and their provenance are documented in `src/data/local_data/sky/README.md`. Anime fades out the Milky Way with its style intensity to avoid cel-shaded diff --git a/package.json b/package.json index b3869d6cd..3938f784f 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "./infrastructure/geojson": "./src/data/localGeojsonCore.js", "./infrastructure/lod": "./src/data/localGeojsonLod.js", "./application": "./src/app/application.js", - "./application/viewer": "./src/app/viewer.js", + "./application/viewer": "./src/render/cesium/applicationViewer.js", "./build/vite": { "node": "./build/vite.js" }, diff --git a/scripts/format-scope.json b/scripts/format-scope.json index 7a27f1494..d025857ca 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -84,7 +84,8 @@ "src/app/application.test.mjs", "src/app/mapLifecycle.test.mjs", "src/app/startupCamera.test.mjs", - "src/app/viewer.js", + "src/render/cesium/applicationViewer.js", + "src/sky/icrf.js", "src/app/atmosphereCompat.test.mjs", "src/standalone/application.js", "src/standalone/controls.js", @@ -1145,7 +1146,7 @@ "scripts/build-bright-stars.mjs", "scripts/build-milky-way.mjs", "src/sky/stars.test.mjs", - "src/sky/starrySky.test.mjs", + "src/render/cesium/starrySky.test.mjs", "src/tooling/skyAssets.test.mjs", "src/tooling/skyAssets.paintOut.test.mjs", "scripts/qa-anime-sky.mjs", diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index dbe74defb..adeec3baa 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -204,12 +204,13 @@ "viewer": { "exports": ["./application/viewer"], "modules": [ - "src/app/viewer.js", + "src/render/cesium/applicationViewer.js", "src/app/atmosphereCompat.js", - "src/sky/starrySky.js", + "src/render/cesium/starrySky.js", "src/sky/stars.js", "src/data/bundledJson.js", - "src/renderGovernor.js" + "src/renderGovernor.js", + "src/sky/icrf.js" ], "external": ["cesium"] }, @@ -1045,7 +1046,6 @@ "src/styles/surveillance.js", "src/styles/thermal.js", "src/ui/applicationShell.js", - "src/sky/starrySky.js", "src/render/cesium/effects.js", "src/render/cesium/screenModulation.js", "src/render/cesium/globe.js", @@ -1286,7 +1286,8 @@ "src/render/cesium/input.js", "src/render/input/wheel.js", "src/render/cesium/ctrlWheelZoom.js", - "src/render/input/router.js" + "src/render/input/router.js", + "src/sky/icrf.js" ], "external": ["cesium", "vue", "pinia", "vue-i18n"] }, @@ -1900,7 +1901,12 @@ "src/render/cesium/mapImagery.js", "src/maps/terrainRetry.js", "src/render/cesium/mapTerrain.js", - "src/render/cesium/mapEngine.js" + "src/render/cesium/mapEngine.js", + "src/data/bundledJson.js", + "src/renderGovernor.js", + "src/sky/icrf.js", + "src/sky/stars.js", + "src/render/cesium/starrySky.js" ], "external": ["cesium"] }, @@ -3342,9 +3348,9 @@ "src/app/surfaceServices.js", "src/app/tools.js", "src/data/followed.js", - "src/app/viewer.js", + "src/render/cesium/applicationViewer.js", "src/render/cesium/ctrlWheelZoom.js", - "src/sky/starrySky.js", + "src/render/cesium/starrySky.js", "src/sky/stars.js", "src/app/atmosphereCompat.js", "src/bloom.js", @@ -4288,7 +4294,8 @@ "src/maps/startupRoute.js", "src/maps/engine.js", "src/maps/attribution.js", - "src/render/cesium/mapEngine.js" + "src/render/cesium/mapEngine.js", + "src/sky/icrf.js" ], "external": [ "hls.js", diff --git a/scripts/qa-sky-model-lighting.mjs b/scripts/qa-sky-model-lighting.mjs index 2f401506b..74514842c 100644 --- a/scripts/qa-sky-model-lighting.mjs +++ b/scripts/qa-sky-model-lighting.mjs @@ -32,13 +32,15 @@ try { const results = await page.evaluate(async () => { window.CESIUM_BASE_URL = '/cesium/'; // Use StarrySky's exact Vite dependency URL, including its version query. - const source = await fetch('/src/sky/starrySky.js').then((r) => r.text()); + const source = await fetch('/src/render/cesium/starrySky.js').then((r) => + r.text(), + ); const cesiumUrl = source.match( /from ["']([^"']*\/cesium\.js[^"']*)["']/, )?.[1]; if (!cesiumUrl) throw new Error('run against the Vite dev server'); const C = await import(cesiumUrl); - const { StarrySky } = await import('/src/sky/starrySky.js'); + const { StarrySky } = await import('/src/render/cesium/starrySky.js'); const time = C.JulianDate.fromIso8601('2026-10-19T00:00:00Z'); const results = {}; for (const kind of ['black', 'starry', 'white']) { diff --git a/src/app/application.test.mjs b/src/app/application.test.mjs index d756e967c..88722edff 100644 --- a/src/app/application.test.mjs +++ b/src/app/application.test.mjs @@ -222,8 +222,9 @@ test('the separate viewer export imports without constructing a browser viewer', }); test('the viewer gets the starry sky as an option, which keeps the Sun and Moon', async () => { - const { applicationViewerOptions } = await import('./viewer.js'); - const { StarrySky } = await import('../sky/starrySky.js'); + const { applicationViewerOptions } = + await import('../render/cesium/applicationViewer.js'); + const { StarrySky } = await import('../render/cesium/starrySky.js'); const creditContainer = {}; const options = applicationViewerOptions(creditContainer); // CesiumWidget skips scene.sun and scene.moon when skyBox is false. diff --git a/src/data/local_data/sky/README.md b/src/data/local_data/sky/README.md index 9bf106d31..0f468ee62 100644 --- a/src/data/local_data/sky/README.md +++ b/src/data/local_data/sky/README.md @@ -1,6 +1,6 @@ # Sky background -Catalogue stars over a soft Milky Way, drawn by `src/sky/starrySky.js` in +Catalogue stars over a soft Milky Way, drawn by `src/render/cesium/starrySky.js` in place of Cesium's blocky Tycho-2 sky box. | File | Content | Size | diff --git a/src/render/cesium/appRenderer.js b/src/render/cesium/appRenderer.js index 6d4bdd6ce..18251d251 100644 --- a/src/render/cesium/appRenderer.js +++ b/src/render/cesium/appRenderer.js @@ -17,7 +17,7 @@ * crosses the contract and each call marks code still to port. Ported code * that still holds the viewer reaches the renderer through `rendererOf`. */ -import { createApplicationViewer } from '../../app/viewer.js'; +import { createApplicationViewer } from './applicationViewer.js'; import { CONTRACT_VERSION } from '../contract/index.js'; import { bindRenderer } from '../rendererOf.js'; import { createCesiumInput } from './input.js'; diff --git a/src/app/viewer.js b/src/render/cesium/applicationViewer.js similarity index 94% rename from src/app/viewer.js rename to src/render/cesium/applicationViewer.js index 550363ddd..cc32e069b 100644 --- a/src/app/viewer.js +++ b/src/render/cesium/applicationViewer.js @@ -1,6 +1,6 @@ import * as Cesium from 'cesium'; -import { applyModelAtmosphereWorkaround } from './atmosphereCompat.js'; -import { StarrySky } from '../sky/starrySky.js'; +import { applyModelAtmosphereWorkaround } from '../../app/atmosphereCompat.js'; +import { StarrySky } from './starrySky.js'; // Dev convenience: expose the app's Cesium instance for console/preview probing // (single shared module instance — avoids dual-Cesium state bugs when testing). diff --git a/src/sky/starrySky.js b/src/render/cesium/starrySky.js similarity index 95% rename from src/sky/starrySky.js rename to src/render/cesium/starrySky.js index cbf9d2044..868139f85 100644 --- a/src/sky/starrySky.js +++ b/src/render/cesium/starrySky.js @@ -1,7 +1,8 @@ import * as Cesium from 'cesium'; -import { loadBundledJson } from '../data/bundledJson.js'; -import { governorRequestRender } from '../renderGovernor.js'; -import { buildStarVertices, STAR_VERTEX_FLOATS } from './stars.js'; +import { loadBundledJson } from '../../data/bundledJson.js'; +import { governorRequestRender } from '../../renderGovernor.js'; +import { buildStarVertices, STAR_VERTEX_FLOATS } from '../../sky/stars.js'; +import { provideIcrfToFixed } from '../../sky/icrf.js'; /** * Space background in the `Scene#skyBox` slot: catalogue stars as point @@ -18,32 +19,32 @@ export const MILKY_WAY_INTENSITY = 0.4; export const SKY_ROTATION_EPSILON_SECONDS = 1; const STAR_PACK_URL = new URL( - '../data/local_data/sky/bright_stars.json', + '../../data/local_data/sky/bright_stars.json', import.meta.url, ); const MILKY_WAY_FACE_URLS = Object.freeze({ positiveX: new URL( - '../data/local_data/sky/milkyway_px.webp', + '../../data/local_data/sky/milkyway_px.webp', import.meta.url, ), negativeX: new URL( - '../data/local_data/sky/milkyway_nx.webp', + '../../data/local_data/sky/milkyway_nx.webp', import.meta.url, ), positiveY: new URL( - '../data/local_data/sky/milkyway_py.webp', + '../../data/local_data/sky/milkyway_py.webp', import.meta.url, ), negativeY: new URL( - '../data/local_data/sky/milkyway_ny.webp', + '../../data/local_data/sky/milkyway_ny.webp', import.meta.url, ), positiveZ: new URL( - '../data/local_data/sky/milkyway_pz.webp', + '../../data/local_data/sky/milkyway_pz.webp', import.meta.url, ), negativeZ: new URL( - '../data/local_data/sky/milkyway_nz.webp', + '../../data/local_data/sky/milkyway_nz.webp', import.meta.url, ), }); @@ -151,6 +152,9 @@ export function icrfToFixedAxes(ms) { }; } +// Cesium-free code asks for it through `src/sky/icrf.js`. +provideIcrfToFixed(icrfToFixedAxes); + /** 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/render/cesium/starrySky.test.mjs similarity index 90% rename from src/sky/starrySky.test.mjs rename to src/render/cesium/starrySky.test.mjs index 42b08fecc..c1dc5b080 100644 --- a/src/sky/starrySky.test.mjs +++ b/src/render/cesium/starrySky.test.mjs @@ -10,6 +10,7 @@ import { icrfToFixedAxes, isSkyRotationCurrent, } from './starrySky.js'; +import * as neutral from '../../sky/icrf.js'; const close = (actual, expected, epsilon = 1e-9) => assert.ok(Math.abs(actual - expected) <= epsilon, `${actual} vs ${expected}`); @@ -221,3 +222,26 @@ test('the precise frame is given as its axes once its tables answer', (t) => { ); assert.equal(icrfToFixedAxes(ms), null); }); + +test('loading the sky provides its precise rotation to Cesium-free code', () => { + const ms = Date.parse('2026-10-19T00:00:00Z'); + const original = Cesium.Transforms.computeIcrfToFixedMatrix; + Cesium.Transforms.computeIcrfToFixedMatrix = (_time, result) => + Cesium.Matrix3.clone(Cesium.Matrix3.fromRotationZ(0.3), result); + try { + const axes = neutral.icrfToFixedAxes(ms); + assert.notEqual(axes, null); + assert.deepEqual(axes, icrfToFixedAxes(ms)); + } finally { + Cesium.Transforms.computeIcrfToFixedMatrix = original; + } +}); + +test('the neutral rotation answers null with nothing provided', () => { + neutral.provideIcrfToFixed(null); + try { + assert.equal(neutral.icrfToFixedAxes(0), null); + } finally { + neutral.provideIcrfToFixed(icrfToFixedAxes); + } +}); diff --git a/src/render/cesium/unbound.js b/src/render/cesium/unbound.js index b05d0be6b..54fa4892c 100644 --- a/src/render/cesium/unbound.js +++ b/src/render/cesium/unbound.js @@ -4,8 +4,9 @@ * layers a Cesium viewer with no renderer bound: the factories * that build a camera, credits, effects, draw, frame, globe, input and query * port over such a viewer when code first asks for one, a click's own - * Cesium picks (`rendererOf.js`), and the map engine the map stacks switch - * through (`src/maps/engine.js`). + * Cesium picks (`rendererOf.js`), the map engine the map stacks switch + * through (`src/maps/engine.js`), and the sky's precise ICRF rotation + * (`src/sky/icrf.js`). */ import './camera.js'; import './effects.js'; @@ -15,3 +16,4 @@ import './input.js'; import './mapEngine.js'; import './nativeClick.js'; import './query.js'; +import './starrySky.js'; diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index 1e84430f1..b234f44d5 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -2,8 +2,6 @@ "dev/conformance/main.js", "src/app/embed.js", "src/app/scene.js", - "src/app/viewer.js", "src/data/geoImportPins.js", - "src/sky/starrySky.js", "src/ui/applicationShell.js" ] diff --git a/src/sky/icrf.js b/src/sky/icrf.js new file mode 100644 index 000000000..41b18d72a --- /dev/null +++ b/src/sky/icrf.js @@ -0,0 +1,28 @@ +/** + * @module sky/icrf + * @description The precise ICRF-to-fixed rotation, from the renderer that + * has the tables for it (the Cesium adapter's starry sky provides it as it + * loads, `src/render/cesium/starrySky.js`). Cesium-free: with none + * provided, or before its tables load, it answers null and callers fall + * back to `temeToPseudoFixed` (`src/geo/frames.js`). + */ + +let provided = null; + +/** + * Provide the precise rotation; a later call replaces it. + * @param {(ms: number) => ({x: object, y: object, z: object} | null)} axesAt + */ +export function provideIcrfToFixed(axesAt) { + provided = axesAt; +} + +/** + * The precise ICRF-to-fixed rotation at `ms` (epoch milliseconds) as its + * axes (the matrix's columns), or null while it is unknown. + * @param {number} ms + * @returns {{x: object, y: object, z: object} | null} + */ +export function icrfToFixedAxes(ms) { + return provided ? provided(ms) : null; +} diff --git a/src/ui/applicationShell.js b/src/ui/applicationShell.js index 2b5d61fd1..f3e663e7a 100644 --- a/src/ui/applicationShell.js +++ b/src/ui/applicationShell.js @@ -63,7 +63,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 { icrfToFixedAxes } from '../sky/icrf.js'; import { useWorldOverlayActionsStore } from './stores/worldOverlayActions.js'; import { useAwarenessDirectionStore } from './stores/awarenessDirection.js'; import { useHudStore } from './stores/hud.js'; diff --git a/src/ui/visualEffects.test.mjs b/src/ui/visualEffects.test.mjs index bd0cb8b4c..264befdb7 100644 --- a/src/ui/visualEffects.test.mjs +++ b/src/ui/visualEffects.test.mjs @@ -4,7 +4,7 @@ import { VisualEffects } from './visualEffects.js'; import { createCesiumEffects } from '../render/cesium/effects.js'; import { styleStagesOf } from '../styles/styleStages.js'; import { createCesiumGlobe } from '../render/cesium/globe.js'; -import { MILKY_WAY_INTENSITY, StarrySky } from '../sky/starrySky.js'; +import { MILKY_WAY_INTENSITY, StarrySky } from '../render/cesium/starrySky.js'; import { GLOBAL_POST_DEFAULTS, STYLE_PRESET_DEFAULTS,