mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
feat(satellites): ISS as a 3D model up close, NASA live video when selected
Within 1,500 km of the camera the ISS (NORAD 25544) is drawn as NASA 3D Resources' station model, at its real 109 m span with a 72 px floor, in its usual +XVV attitude from a per-frame SGP4 sample (the follow camera's sample while tracked). Farther out the dot stays; model and dots split the distance range. Selecting the ISS opens a panel beside the existing tracked card with NASA's official ISS live stream, embedded through youtube-nocookie with a fixed video id (no page scraping). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
10a788db78
commit
9aeabbacfb
32 files changed
+841
-17
No files matched your search
@@ -7,13 +7,19 @@ import { createRendering } from './rendering.js';
|
||||
import { createTracking } from './tracking.js';
|
||||
import { createTesting } from './testing.js';
|
||||
import { createInteraction } from './interaction.js';
|
||||
import { createIssLive } from './issLive.js';
|
||||
import { createIssModel } from './issModel.js';
|
||||
import { createLifecycle } from './lifecycle.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
import { createRecords } from './records.js';
|
||||
import { createState } from './state.js';
|
||||
|
||||
/** Construct one layer with its own scene state and supplied application services. */
|
||||
export function createSatellitesLayer({ services, source }) {
|
||||
export function createSatellitesLayer({
|
||||
services,
|
||||
source,
|
||||
resolveAsset = (url) => url,
|
||||
}) {
|
||||
if (typeof source?.readGroup !== 'function')
|
||||
throw new TypeError('A satellites source is required');
|
||||
const state = createState({ services });
|
||||
@@ -25,6 +31,8 @@ export function createSatellitesLayer({ services, source }) {
|
||||
parts.orbits = createOrbits(context);
|
||||
parts.records = createRecords(context);
|
||||
parts.rendering = createRendering(context);
|
||||
parts.issModel = createIssModel({ ...context, resolveAsset });
|
||||
parts.issLive = createIssLive(context);
|
||||
parts.tracking = createTracking(context);
|
||||
parts.testing = createTesting(context);
|
||||
parts.interaction = createInteraction(context);
|
||||
|
||||
@@ -65,6 +65,8 @@ export function createInteraction({
|
||||
const prim = picked.primitive;
|
||||
if (prim && prim.id != null) {
|
||||
const noradId = Number(prim.id);
|
||||
// A click on the tracked ISS's own model: it is already tracked.
|
||||
if (noradId === layerState._trackedNorad) return;
|
||||
if (!isNaN(noradId) && layerState._catalog.has(noradId)) {
|
||||
parts.tracking._cancelPendingTrackingRestore();
|
||||
parts.tracking._trackSatellite(noradId, { origin: 'user' });
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { ISS_LIVE_VIDEO_ID, ISS_NORAD } from './policy.js';
|
||||
|
||||
/**
|
||||
* The player address for a YouTube video: the privacy-enhanced host the
|
||||
* page's frame-src allows, muted so the browser lets it start on its own.
|
||||
* @param {string} videoId
|
||||
* @returns {string}
|
||||
*/
|
||||
export function issLiveEmbedUrl(videoId) {
|
||||
const params = new URLSearchParams({
|
||||
autoplay: '1',
|
||||
mute: '1',
|
||||
playsinline: '1',
|
||||
rel: '0',
|
||||
});
|
||||
return `https://www.youtube-nocookie.com/embed/${encodeURIComponent(videoId)}?${params}`;
|
||||
}
|
||||
|
||||
/** The video's own page, for the "Open on YouTube" link. */
|
||||
export function issLiveWatchUrl(videoId) {
|
||||
return `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the live panel shows: the ISS selected (tracked), the layer on, the
|
||||
* Cockpit not riding it, and the viewer not having closed it for this pick.
|
||||
* @param {{enabled: boolean, trackedNorad: number|null, cockpitHeld: boolean,
|
||||
* dismissed: boolean}} input
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function issLiveShouldShow({
|
||||
enabled,
|
||||
trackedNorad,
|
||||
cockpitHeld,
|
||||
dismissed,
|
||||
}) {
|
||||
return (
|
||||
Boolean(enabled) && trackedNorad === ISS_NORAD && !cockpitHeld && !dismissed
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* NASA's live view from the ISS, in a panel beside the existing tracked card
|
||||
* while the ISS is selected. The player is created on show and removed on
|
||||
* hide, so nothing streams while the panel is closed.
|
||||
*/
|
||||
export function createIssLive({ state: layerState, parts }) {
|
||||
let panel = null;
|
||||
let dismissed = false;
|
||||
let lastTracked = null;
|
||||
|
||||
function _build(documentRef) {
|
||||
const root = documentRef.createElement('section');
|
||||
root.className = 'iss-live-panel';
|
||||
root.setAttribute('role', 'region');
|
||||
root.setAttribute('aria-label', t('ISS live video'));
|
||||
|
||||
const header = documentRef.createElement('header');
|
||||
header.className = 'iss-live-header';
|
||||
const title = documentRef.createElement('span');
|
||||
title.className = 'iss-live-title';
|
||||
const dotMark = documentRef.createElement('span');
|
||||
dotMark.className = 'iss-live-dot';
|
||||
dotMark.setAttribute('aria-hidden', 'true');
|
||||
title.append(dotMark, documentRef.createTextNode(t('ISS LIVE · NASA')));
|
||||
const link = documentRef.createElement('a');
|
||||
link.className = 'iss-live-link';
|
||||
link.href = issLiveWatchUrl(ISS_LIVE_VIDEO_ID);
|
||||
link.target = '_blank';
|
||||
link.rel = 'noopener noreferrer';
|
||||
link.textContent = t('Open on YouTube');
|
||||
const close = documentRef.createElement('button');
|
||||
close.type = 'button';
|
||||
close.className = 'iss-live-close';
|
||||
close.textContent = '×';
|
||||
close.title = t('Close ISS live video');
|
||||
close.setAttribute('aria-label', t('Close ISS live video'));
|
||||
close.addEventListener('click', () => {
|
||||
dismissed = true;
|
||||
_syncIssLive();
|
||||
});
|
||||
header.append(title, link, close);
|
||||
|
||||
const frame = documentRef.createElement('div');
|
||||
frame.className = 'iss-live-frame';
|
||||
const iframe = documentRef.createElement('iframe');
|
||||
iframe.src = issLiveEmbedUrl(ISS_LIVE_VIDEO_ID);
|
||||
iframe.title = t('Live views from the International Space Station (NASA)');
|
||||
iframe.allow = 'autoplay; encrypted-media; picture-in-picture; fullscreen';
|
||||
iframe.allowFullscreen = true;
|
||||
iframe.referrerPolicy = 'strict-origin-when-cross-origin';
|
||||
iframe.loading = 'eager';
|
||||
frame.append(iframe);
|
||||
|
||||
root.append(header, frame);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or hide the panel for the current selection. Cheap when nothing
|
||||
* changed, so the tracking and Cockpit paths can call it freely.
|
||||
* @returns {void}
|
||||
*/
|
||||
function _syncIssLive() {
|
||||
const tracked = layerState._trackedNorad;
|
||||
// A new pick of the ISS brings back a panel closed on an earlier one.
|
||||
if (tracked !== lastTracked) {
|
||||
dismissed = false;
|
||||
lastTracked = tracked;
|
||||
}
|
||||
const show = issLiveShouldShow({
|
||||
enabled: layerState._enabled,
|
||||
trackedNorad: tracked,
|
||||
cockpitHeld: Boolean(parts.cockpit?._cockpitHeld()),
|
||||
dismissed,
|
||||
});
|
||||
if (!show) {
|
||||
_removePanel();
|
||||
return;
|
||||
}
|
||||
if (panel) return;
|
||||
const documentRef = globalThis.document;
|
||||
if (!documentRef?.body) return;
|
||||
panel = _build(documentRef);
|
||||
documentRef.body.append(panel);
|
||||
}
|
||||
|
||||
function _removePanel() {
|
||||
if (!panel) return;
|
||||
panel.remove(); // the player goes with it, so the stream stops
|
||||
panel = null;
|
||||
}
|
||||
|
||||
/** Drop the panel and forget the selection (layer destroy). */
|
||||
function _destroyIssLive() {
|
||||
_removePanel();
|
||||
dismissed = false;
|
||||
lastTracked = null;
|
||||
}
|
||||
|
||||
return { _syncIssLive, _destroyIssLive };
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { eciToGeodetic, gstime, propagate } from 'satellite.js';
|
||||
import {
|
||||
ISS_MODEL_MAX_DISTANCE_M,
|
||||
ISS_MODEL_MIN_PX,
|
||||
ISS_MODEL_NATIVE_SPAN,
|
||||
ISS_MODEL_URL,
|
||||
ISS_NORAD,
|
||||
ISS_SPAN_M,
|
||||
} from './policy.js';
|
||||
|
||||
/** The model's scale for the real 109 m truss. */
|
||||
export const ISS_MODEL_SCALE = ISS_SPAN_M / ISS_MODEL_NATIVE_SPAN;
|
||||
|
||||
/**
|
||||
* Whether the ISS model may be drawn: the dot's own rules (layer on, points
|
||||
* on, the ISS loaded and its class shown or the ISS tracked), and not while
|
||||
* the Cockpit rides the ISS or hides it as a docked companion.
|
||||
* @param {{enabled: boolean, showPoints: boolean, hasIss: boolean,
|
||||
* classVisible: boolean, tracked: boolean, cockpitHidden: boolean}} input
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function issModelShouldShow({
|
||||
enabled,
|
||||
showPoints,
|
||||
hasIss,
|
||||
classVisible,
|
||||
tracked,
|
||||
cockpitHidden,
|
||||
}) {
|
||||
return (
|
||||
Boolean(enabled) &&
|
||||
Boolean(showPoints) &&
|
||||
Boolean(hasIss) &&
|
||||
(Boolean(classVisible) || Boolean(tracked)) &&
|
||||
!cockpitHidden
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The station's flight axes in the Earth-fixed frame, from one SGP4 state:
|
||||
* the ISS normally flies "+XVV", its modules along the velocity, the truss
|
||||
* across the orbit plane, the same side always to the Earth. Returned as the
|
||||
* model's local axes: x along-track, y the orbit normal (along the truss), z
|
||||
* zenith (away from the Earth's centre).
|
||||
* @param {{x:number,y:number,z:number}} positionEcef Earth-fixed position.
|
||||
* @param {{x:number,y:number,z:number}} velocityEcefAxes Inertial velocity,
|
||||
* turned onto the Earth-fixed axes (direction only matters).
|
||||
* @returns {{x:number[], y:number[], z:number[]}|null} Unit vectors, or null
|
||||
* for a degenerate state (zero position or velocity along it).
|
||||
*/
|
||||
export function issFlightAxes(positionEcef, velocityEcefAxes) {
|
||||
const r = [positionEcef.x, positionEcef.y, positionEcef.z];
|
||||
const v = [velocityEcefAxes.x, velocityEcefAxes.y, velocityEcefAxes.z];
|
||||
const z = unit(r);
|
||||
const y = unit(cross(r, v));
|
||||
if (!z || !y) return null;
|
||||
const x = cross(y, z);
|
||||
return { x, y, z };
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn an inertial (TEME) vector onto the Earth-fixed axes at `gmst`: the same
|
||||
* rotation `eciToGeodetic` applies to the position.
|
||||
* @param {{x:number,y:number,z:number}} v
|
||||
* @param {number} gmst Radians.
|
||||
* @returns {{x:number,y:number,z:number}}
|
||||
*/
|
||||
export function temeToEcefAxes(v, gmst) {
|
||||
const c = Math.cos(gmst);
|
||||
const s = Math.sin(gmst);
|
||||
return { x: c * v.x + s * v.y, y: -s * v.x + c * v.y, z: v.z };
|
||||
}
|
||||
|
||||
function cross(a, b) {
|
||||
return [
|
||||
a[1] * b[2] - a[2] * b[1],
|
||||
a[2] * b[0] - a[0] * b[2],
|
||||
a[0] * b[1] - a[1] * b[0],
|
||||
];
|
||||
}
|
||||
|
||||
function unit(a) {
|
||||
const n = Math.hypot(a[0], a[1], a[2]);
|
||||
if (!(n > 0)) return null;
|
||||
return [a[0] / n, a[1] / n, a[2] / n];
|
||||
}
|
||||
|
||||
/**
|
||||
* The ISS as a 3D model when the camera is close. Far out the dot stays: the
|
||||
* model and the dot (ambient and tracked) split the distance range, so exactly
|
||||
* one of them draws. The model loads on first need and only if the ISS is
|
||||
* shown, and positions itself every frame from its own SGP4 sample (the dot
|
||||
* moves once a second, which at model range would show as a jump).
|
||||
*/
|
||||
export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
let model = null;
|
||||
let loading = false;
|
||||
let failed = false;
|
||||
let generation = 0;
|
||||
const nearCondition = new Cesium.DistanceDisplayCondition(
|
||||
0,
|
||||
ISS_MODEL_MAX_DISTANCE_M,
|
||||
);
|
||||
const farCondition = new Cesium.DistanceDisplayCondition(
|
||||
ISS_MODEL_MAX_DISTANCE_M,
|
||||
Number.MAX_VALUE,
|
||||
);
|
||||
const scratchPosition = new Cesium.Cartesian3();
|
||||
const scratchRotation = new Cesium.Matrix3();
|
||||
const scratchColumn = new Cesium.Cartesian3();
|
||||
|
||||
function _shouldShow() {
|
||||
const tracked = layerState._trackedNorad === ISS_NORAD;
|
||||
return issModelShouldShow({
|
||||
enabled: layerState._enabled,
|
||||
showPoints: layerState._params.showPoints,
|
||||
hasIss: layerState._catalog.has(ISS_NORAD),
|
||||
classVisible: parts.controls._classVisible(ISS_NORAD),
|
||||
tracked,
|
||||
cockpitHidden:
|
||||
(tracked && parts.cockpit?._cockpitHeld()) ||
|
||||
layerState._cockpitHiddenPoints?.has(ISS_NORAD),
|
||||
});
|
||||
}
|
||||
|
||||
async function _load() {
|
||||
loading = true;
|
||||
const loadGeneration = generation;
|
||||
try {
|
||||
const loaded = await Cesium.Model.fromGltfAsync({
|
||||
url: resolveAsset(ISS_MODEL_URL),
|
||||
scale: ISS_MODEL_SCALE,
|
||||
minimumPixelSize: ISS_MODEL_MIN_PX,
|
||||
distanceDisplayCondition: nearCondition,
|
||||
// So a click on the model tracks the ISS, as a click on its dot does.
|
||||
id: ISS_NORAD,
|
||||
show: false,
|
||||
});
|
||||
const viewer = layerState._viewer;
|
||||
if (loadGeneration !== generation || !viewer) {
|
||||
loaded.destroy();
|
||||
return;
|
||||
}
|
||||
viewer.scene.primitives.add(loaded);
|
||||
model = loaded;
|
||||
} catch (error) {
|
||||
// The dot keeps drawing at every distance; nothing else depends on this.
|
||||
failed = true;
|
||||
console.warn('[Data:Satellites] ISS model failed to load:', error);
|
||||
} finally {
|
||||
if (loadGeneration === generation) loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Leave the near range to the model: the dots draw only beyond it. */
|
||||
function _handOverDots() {
|
||||
const point = layerState._points.get(ISS_NORAD);
|
||||
if (point && point.distanceDisplayCondition !== farCondition)
|
||||
point.distanceDisplayCondition = farCondition;
|
||||
const dot =
|
||||
layerState._trackedNorad === ISS_NORAD
|
||||
? layerState._trackedEntity?.point
|
||||
: null;
|
||||
if (dot && !dot.distanceDisplayCondition)
|
||||
dot.distanceDisplayCondition = farCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-frame update from the layer's preRender tick.
|
||||
* @returns {void}
|
||||
*/
|
||||
function _updateIssModel() {
|
||||
const show = _shouldShow();
|
||||
if (!show) {
|
||||
if (model) model.show = false;
|
||||
return;
|
||||
}
|
||||
if (!model) {
|
||||
if (!loading && !failed && resolveAsset) _load();
|
||||
return;
|
||||
}
|
||||
_handOverDots();
|
||||
|
||||
const point = layerState._points.get(ISS_NORAD);
|
||||
const camera = layerState._viewer?.camera;
|
||||
// Out of range the model would not draw anyway: skip the SGP4 sample.
|
||||
if (
|
||||
point?.position &&
|
||||
camera &&
|
||||
Cesium.Cartesian3.distance(camera.positionWC, point.position) >
|
||||
ISS_MODEL_MAX_DISTANCE_M * 1.5
|
||||
) {
|
||||
model.show = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const sat = layerState._catalog.get(ISS_NORAD);
|
||||
const trackedSample =
|
||||
layerState._trackedNorad === ISS_NORAD &&
|
||||
Number.isFinite(layerState._trackedFrameGeo?.atMs)
|
||||
? layerState._trackedFrameGeo
|
||||
: null;
|
||||
const date = new Date(
|
||||
trackedSample ? trackedSample.atMs : layerState.now(),
|
||||
);
|
||||
let posVel;
|
||||
try {
|
||||
posVel = propagate(sat.satrec, date);
|
||||
} catch {
|
||||
posVel = null;
|
||||
}
|
||||
if (
|
||||
!posVel?.position ||
|
||||
typeof posVel.position === 'boolean' ||
|
||||
!posVel.velocity ||
|
||||
typeof posVel.velocity === 'boolean'
|
||||
) {
|
||||
model.show = false;
|
||||
return;
|
||||
}
|
||||
const gmst = gstime(date);
|
||||
if (trackedSample) {
|
||||
// The sample the follow camera and the tracked dot were placed from.
|
||||
Cesium.Cartesian3.clone(
|
||||
layerState._trackedFrameCartesian,
|
||||
scratchPosition,
|
||||
);
|
||||
} else {
|
||||
const geo = eciToGeodetic(posVel.position, gmst);
|
||||
Cesium.Cartesian3.fromRadians(
|
||||
geo.longitude,
|
||||
geo.latitude,
|
||||
geo.height * 1000,
|
||||
undefined,
|
||||
scratchPosition,
|
||||
);
|
||||
}
|
||||
const axes = issFlightAxes(
|
||||
scratchPosition,
|
||||
temeToEcefAxes(posVel.velocity, gmst),
|
||||
);
|
||||
if (!axes) {
|
||||
model.show = false;
|
||||
return;
|
||||
}
|
||||
['x', 'y', 'z'].forEach((key, column) => {
|
||||
scratchColumn.x = axes[key][0];
|
||||
scratchColumn.y = axes[key][1];
|
||||
scratchColumn.z = axes[key][2];
|
||||
Cesium.Matrix3.setColumn(
|
||||
scratchRotation,
|
||||
column,
|
||||
scratchColumn,
|
||||
scratchRotation,
|
||||
);
|
||||
});
|
||||
Cesium.Matrix4.fromRotationTranslation(
|
||||
scratchRotation,
|
||||
scratchPosition,
|
||||
model.modelMatrix,
|
||||
);
|
||||
model.show = true;
|
||||
}
|
||||
|
||||
/** Drop the model (destroy or a fresh init); the next need reloads it. */
|
||||
function _destroyIssModel() {
|
||||
generation += 1;
|
||||
loading = false;
|
||||
failed = false;
|
||||
if (model) {
|
||||
const scene = layerState._viewer?.scene;
|
||||
if (scene && scene.primitives.contains(model))
|
||||
scene.primitives.remove(model); // remove() destroys
|
||||
else if (!model.isDestroyed()) model.destroy();
|
||||
model = null;
|
||||
}
|
||||
}
|
||||
|
||||
return { _updateIssModel, _destroyIssModel };
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { gstime, propagate, twoline2satrec } from 'satellite.js';
|
||||
import {
|
||||
ISS_MODEL_SCALE,
|
||||
issFlightAxes,
|
||||
issModelShouldShow,
|
||||
temeToEcefAxes,
|
||||
} from './issModel.js';
|
||||
import {
|
||||
ISS_MODEL_NATIVE_SPAN,
|
||||
ISS_MODEL_URL,
|
||||
ISS_NORAD,
|
||||
ISS_SPAN_M,
|
||||
} from './policy.js';
|
||||
|
||||
const ISS_TLE = [
|
||||
'1 25544U 98067A 24001.50000000 .00016717 00000-0 10270-3 0 9002',
|
||||
'2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.50377579 1234',
|
||||
];
|
||||
|
||||
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||
const norm = (a) => Math.hypot(a[0], a[1], a[2]);
|
||||
|
||||
const shown = {
|
||||
enabled: true,
|
||||
showPoints: true,
|
||||
hasIss: true,
|
||||
classVisible: true,
|
||||
tracked: false,
|
||||
cockpitHidden: false,
|
||||
};
|
||||
|
||||
test('the ISS model shows on the same terms as its dot', () => {
|
||||
assert.equal(issModelShouldShow(shown), true);
|
||||
assert.equal(issModelShouldShow({ ...shown, enabled: false }), false);
|
||||
assert.equal(issModelShouldShow({ ...shown, showPoints: false }), false);
|
||||
assert.equal(issModelShouldShow({ ...shown, hasIss: false }), false);
|
||||
assert.equal(issModelShouldShow({ ...shown, classVisible: false }), false);
|
||||
});
|
||||
|
||||
test('a tracked ISS keeps its model with its class hidden', () => {
|
||||
assert.equal(
|
||||
issModelShouldShow({ ...shown, classVisible: false, tracked: true }),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('the Cockpit hold hides the model', () => {
|
||||
assert.equal(
|
||||
issModelShouldShow({ ...shown, tracked: true, cockpitHidden: true }),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('the model is the ISS by NORAD number, at its real 109 m span', () => {
|
||||
assert.equal(ISS_NORAD, 25544);
|
||||
assert.ok(
|
||||
Math.abs(ISS_MODEL_SCALE * ISS_MODEL_NATIVE_SPAN - ISS_SPAN_M) < 1e-9,
|
||||
);
|
||||
});
|
||||
|
||||
test('the native span matches the shipped asset', () => {
|
||||
const glb = readFileSync(
|
||||
new URL(`../../../public${ISS_MODEL_URL}`, import.meta.url),
|
||||
);
|
||||
const jsonLength = glb.readUInt32LE(12);
|
||||
const gltf = JSON.parse(glb.subarray(20, 20 + jsonLength).toString('utf8'));
|
||||
let minX = Infinity;
|
||||
let maxX = -Infinity;
|
||||
for (const node of gltf.nodes.filter((n) => n.mesh !== undefined)) {
|
||||
for (const primitive of gltf.meshes[node.mesh].primitives) {
|
||||
const accessor = gltf.accessors[primitive.attributes.POSITION];
|
||||
minX = Math.min(minX, accessor.min[0] * (node.scale?.[0] ?? 1));
|
||||
maxX = Math.max(maxX, accessor.max[0] * (node.scale?.[0] ?? 1));
|
||||
}
|
||||
}
|
||||
assert.ok(Math.abs(maxX - minX - ISS_MODEL_NATIVE_SPAN) < 0.01);
|
||||
});
|
||||
|
||||
test('flight axes: orthonormal, z away from the Earth, x along the motion', () => {
|
||||
const satrec = twoline2satrec(ISS_TLE[0], ISS_TLE[1]);
|
||||
for (const minutes of [0, 17, 46, 80]) {
|
||||
const date = new Date(Date.UTC(2024, 0, 1, 12, minutes));
|
||||
const { position, velocity } = propagate(satrec, date);
|
||||
const gmst = gstime(date);
|
||||
const r = temeToEcefAxes(position, gmst);
|
||||
const v = temeToEcefAxes(velocity, gmst);
|
||||
const axes = issFlightAxes(r, v);
|
||||
for (const key of ['x', 'y', 'z'])
|
||||
assert.ok(Math.abs(norm(axes[key]) - 1) < 1e-9);
|
||||
assert.ok(Math.abs(dot(axes.x, axes.y)) < 1e-9);
|
||||
assert.ok(Math.abs(dot(axes.y, axes.z)) < 1e-9);
|
||||
assert.ok(Math.abs(dot(axes.x, axes.z)) < 1e-9);
|
||||
const rUnit = [r.x, r.y, r.z].map((c) => c / norm([r.x, r.y, r.z]));
|
||||
assert.ok(dot(axes.z, rUnit) > 0.999999);
|
||||
// A near-circular orbit: the along-track axis is almost the velocity.
|
||||
const vUnit = [v.x, v.y, v.z].map((c) => c / norm([v.x, v.y, v.z]));
|
||||
assert.ok(dot(axes.x, vUnit) > 0.999);
|
||||
// Right-handed: x × y = z.
|
||||
const cross = [
|
||||
axes.x[1] * axes.y[2] - axes.x[2] * axes.y[1],
|
||||
axes.x[2] * axes.y[0] - axes.x[0] * axes.y[2],
|
||||
axes.x[0] * axes.y[1] - axes.x[1] * axes.y[0],
|
||||
];
|
||||
assert.ok(dot(cross, axes.z) > 0.999999);
|
||||
}
|
||||
});
|
||||
|
||||
test('flight axes refuse a degenerate state', () => {
|
||||
assert.equal(issFlightAxes({ x: 0, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }), null);
|
||||
assert.equal(issFlightAxes({ x: 1, y: 0, z: 0 }, { x: 2, y: 0, z: 0 }), null);
|
||||
});
|
||||
|
||||
test('TEME to Earth-fixed axes keeps the position eciToGeodetic uses', () => {
|
||||
const v = temeToEcefAxes({ x: 1, y: 0, z: 0 }, Math.PI / 2);
|
||||
assert.ok(Math.abs(v.x) < 1e-12);
|
||||
assert.ok(Math.abs(v.y + 1) < 1e-12);
|
||||
});
|
||||
|
||||
test('the ISS live panel follows the ISS selection', async () => {
|
||||
const { issLiveShouldShow } = await import('./issLive.js');
|
||||
const base = {
|
||||
enabled: true,
|
||||
trackedNorad: ISS_NORAD,
|
||||
cockpitHeld: false,
|
||||
dismissed: false,
|
||||
};
|
||||
assert.equal(issLiveShouldShow(base), true);
|
||||
assert.equal(issLiveShouldShow({ ...base, trackedNorad: 48274 }), false);
|
||||
assert.equal(issLiveShouldShow({ ...base, trackedNorad: null }), false);
|
||||
assert.equal(issLiveShouldShow({ ...base, enabled: false }), false);
|
||||
assert.equal(issLiveShouldShow({ ...base, cockpitHeld: true }), false);
|
||||
assert.equal(issLiveShouldShow({ ...base, dismissed: true }), false);
|
||||
});
|
||||
|
||||
test("the ISS live player is NASA's stream on the privacy-enhanced host", async () => {
|
||||
const { issLiveEmbedUrl, issLiveWatchUrl } = await import('./issLive.js');
|
||||
const { ISS_LIVE_VIDEO_ID } = await import('./policy.js');
|
||||
const embed = new URL(issLiveEmbedUrl(ISS_LIVE_VIDEO_ID));
|
||||
assert.equal(embed.origin, 'https://www.youtube-nocookie.com');
|
||||
assert.equal(embed.pathname, `/embed/${ISS_LIVE_VIDEO_ID}`);
|
||||
// Muted, or the browser will not start it on its own.
|
||||
assert.equal(embed.searchParams.get('mute'), '1');
|
||||
assert.equal(embed.searchParams.get('autoplay'), '1');
|
||||
assert.equal(
|
||||
issLiveWatchUrl(ISS_LIVE_VIDEO_ID),
|
||||
`https://www.youtube.com/watch?v=${ISS_LIVE_VIDEO_ID}`,
|
||||
);
|
||||
});
|
||||
@@ -36,6 +36,7 @@ export function createLifecycle({
|
||||
async init(viewer) {
|
||||
parts.catalog._abortActiveUpdates();
|
||||
clearFocusTarget('satellites');
|
||||
parts.issModel?._destroyIssModel();
|
||||
layerState._viewer = viewer;
|
||||
layerState._catalog = new Map();
|
||||
layerState._points = new Map();
|
||||
@@ -130,7 +131,9 @@ export function createLifecycle({
|
||||
if (layerState._pointCollection) layerState._pointCollection.show = false;
|
||||
for (const path of layerState._orbitPaths.values())
|
||||
path.primitive.show = false;
|
||||
parts.issModel?._updateIssModel(); // off: hides the model
|
||||
parts.tracking._clearTracking();
|
||||
parts.issLive?._syncIssLive(); // off: closes the live video
|
||||
parts.labels._syncIssOverlay();
|
||||
// Remove click handler + keydown listener + preRender propagation while disabled
|
||||
if (layerState._clickHandler) {
|
||||
@@ -172,6 +175,8 @@ export function createLifecycle({
|
||||
}
|
||||
layerState._overlayHost.clearSource(ISS_OVERLAY_SOURCE_ID);
|
||||
layerState._overlayHost.setVisible(ISS_OVERLAY_SOURCE_ID, false);
|
||||
parts.issModel?._destroyIssModel();
|
||||
parts.issLive?._destroyIssLive();
|
||||
if (layerState._pointCollection) {
|
||||
viewer.scene.primitives.remove(layerState._pointCollection);
|
||||
layerState._pointCollection = null;
|
||||
|
||||
@@ -19,6 +19,42 @@ import { SATELLITE_CLASS_DISPLAY, SATELLITE_CLASS_IDS } from './classes.js';
|
||||
|
||||
export const ISS_NORAD = 25544;
|
||||
|
||||
/**
|
||||
* The ISS drawn as a 3D model up close (issModel.js): NASA's "International
|
||||
* Space Station (ISS) (A)" from NASA 3D Resources, shipped unmodified.
|
||||
*/
|
||||
export const ISS_MODEL_URL = '/models/iss.glb';
|
||||
|
||||
/** The real station across its main truss, end to end, in meters. */
|
||||
export const ISS_SPAN_M = 109;
|
||||
|
||||
/**
|
||||
* The asset's truss length in its own units: the mesh's X extent (37.772)
|
||||
* times the root node's scale (0.678121), read from the file's accessors.
|
||||
*/
|
||||
export const ISS_MODEL_NATIVE_SPAN = 25.614;
|
||||
|
||||
/**
|
||||
* Within this camera distance the model replaces the dot; farther out the dot
|
||||
* stays. Covers the tracked view (~726 km back for LEO) with room to spare.
|
||||
*/
|
||||
export const ISS_MODEL_MAX_DISTANCE_M = 1_500_000;
|
||||
|
||||
/**
|
||||
* The model is never drawn smaller than this, in pixels. At true size the
|
||||
* station is under a pixel from the tracked view, so the floor is what makes
|
||||
* it readable there; within a few kilometres the true size takes over.
|
||||
*/
|
||||
export const ISS_MODEL_MIN_PX = 72;
|
||||
|
||||
/**
|
||||
* NASA's official live stream from the ISS on YouTube ("Live High-Definition
|
||||
* Views from the International Space Station", channel @NASA), shown in a
|
||||
* panel while the ISS is selected (issLive.js). A YouTube live keeps its id
|
||||
* while the broadcast runs; if NASA restarts it under a new id, change it here.
|
||||
*/
|
||||
export const ISS_LIVE_VIDEO_ID = 'ROboUHfPUrU';
|
||||
|
||||
export const ISS_OVERLAY_SOURCE_ID = 'satellites-iss';
|
||||
|
||||
export const ISS_OVERLAY_SOURCE_OPTIONS = Object.freeze({
|
||||
|
||||
@@ -200,6 +200,11 @@ export function createRendering({
|
||||
if (!layerState._enabled) return;
|
||||
const now = focusNowMs(Date.now());
|
||||
|
||||
// The ISS as a 3D model up close. First, before the tracked sample below
|
||||
// is refreshed: the follow camera and the tracked dot were placed this
|
||||
// frame from the sample still cached, and the model must sit on it too.
|
||||
parts.issModel?._updateIssModel();
|
||||
|
||||
const interval = layerState._trackedNorad ? 200 : POSITION_UPDATE_MS;
|
||||
// Space Missions keeps this layer enabled for TLE lookup while deliberately
|
||||
// hiding its standalone fleet. Do not rebuild hidden point buffers on the
|
||||
@@ -229,6 +234,9 @@ export function createRendering({
|
||||
if (layerState._cockpitSubjectNorad !== null)
|
||||
parts.cockpit?._syncCockpitSubjectVisuals();
|
||||
|
||||
// NASA's live video beside the card while the ISS is selected.
|
||||
parts.issLive?._syncIssLive();
|
||||
|
||||
_updatePointFocus(now);
|
||||
|
||||
// Hidden standalone orbit primitives do not need GMST matrix writes while
|
||||
|
||||
Reference in new issue
Block a user