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
@@ -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}`,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user