mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
feat(satellites): current ISS model with moving parts and a command panel
The ISS model is now NASA/JSC IGOAL's current-configuration station (Nauka, Prichal, Bishop, roll-out arrays), reduced from 96 MB to 3 MB with its joints kept as nodes. NASA's file is a mirror image of the station and marks 15 materials as blended; both are corrected. Its parts move by computation, never telemetry: arrays and radiators by the Sun (feathered in the Earth's shadow), the Ku-band dishes toward the TDRS nominal slots, and the robotic arms as an illustrative sway. Selecting the ISS shows a collapsed command panel: zoom to the station, Automatic (default, with a lit/shadow status line) and Manual controls for the Sun's position, arrays, radiators, dishes and Canadarm2. Also: docked objects are found by comparing both orbits at one instant, the tracked card keeps clear of the model, the model file loads only near its range, and both ISS panels follow a language change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
9aeabbacfb
commit
a75993a66b
35 files changed
+2636
-119
No files matched your search
Vendored
+7
@@ -254,6 +254,13 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
// that card instead. Only members of the tracked cluster are affected —
|
||||
// unrelated nearby satellites are never suppressed.
|
||||
if (!isTracked && layerState._dockedCompanions.has(noradId)) continue;
|
||||
// Up close the ISS is its 3D model: no mark on it, nor on what is
|
||||
// docked to it.
|
||||
if (
|
||||
parts.issModel?._issStandsInFor?.(noradId) ||
|
||||
(noradId === ISS_NORAD && parts.issModel?._issVisualPosition?.())
|
||||
)
|
||||
continue;
|
||||
// The Cockpit camera rides a held subject; a bracket on it would sit
|
||||
// on the lens.
|
||||
if (isTracked && parts.cockpit?._cockpitHeld()) continue;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { createRendering } from './rendering.js';
|
||||
import { createTracking } from './tracking.js';
|
||||
import { createTesting } from './testing.js';
|
||||
import { createInteraction } from './interaction.js';
|
||||
import { createIssCommand } from './issCommand.js';
|
||||
import { createIssLive } from './issLive.js';
|
||||
import { createIssModel } from './issModel.js';
|
||||
import { createLifecycle } from './lifecycle.js';
|
||||
@@ -33,6 +34,7 @@ export function createSatellitesLayer({
|
||||
parts.rendering = createRendering(context);
|
||||
parts.issModel = createIssModel({ ...context, resolveAsset });
|
||||
parts.issLive = createIssLive(context);
|
||||
parts.issCommand = createIssCommand(context);
|
||||
parts.tracking = createTracking(context);
|
||||
parts.testing = createTesting(context);
|
||||
parts.interaction = createInteraction(context);
|
||||
|
||||
@@ -0,0 +1,761 @@
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
/**
|
||||
* The ISS model's moving parts. NASA's file names its joints; the build keeps
|
||||
* each one as a node of its own, with the parts it carries beneath it, all in
|
||||
* the model's rest frame (glTF axes, meters: X port, Y zenith, Z forward), so
|
||||
* a joint turns by rotating its node about `pivot`.
|
||||
*
|
||||
* The angles are computed from where the Sun is, not read from telemetry: the
|
||||
* two alpha joints turn the outboard truss about the truss axis, each array's
|
||||
* beta joint turns it about its mast, and the two radiator joints keep the
|
||||
* radiators edge-on to the Sun. In the Earth's shadow the arrays feather:
|
||||
* masts along the flight direction, edge into it.
|
||||
*/
|
||||
|
||||
/** Alpha joints (SARJ): rotate about the truss, glTF X. */
|
||||
export const ISS_ALPHA_JOINTS = Object.freeze([
|
||||
Object.freeze({ node: 'PORT_ALPHA_ROT', pivot: [19.533, 0, 0] }),
|
||||
Object.freeze({ node: 'STBD_ALPHA_ROT', pivot: [-19.533, 0, 0] }),
|
||||
]);
|
||||
|
||||
/**
|
||||
* Beta joints (BGA): rotate about the mast, glTF Z at rest. `face` is the
|
||||
* sign of the cell side's normal along X at rest (the roll-out arrays sit on
|
||||
* that side).
|
||||
*/
|
||||
export const ISS_BETA_JOINTS = Object.freeze([
|
||||
Object.freeze({
|
||||
node: 'PORT_BETA_ROT_2A',
|
||||
pivot: [36.7319, 0.7256, -3.0077],
|
||||
face: -1,
|
||||
}),
|
||||
Object.freeze({
|
||||
node: 'PORT_BETA_ROT_4A',
|
||||
pivot: [36.7319, -0.7258, 2.2332],
|
||||
face: -1,
|
||||
}),
|
||||
Object.freeze({
|
||||
node: 'PORT_BETA_ROT_2B',
|
||||
pivot: [53.223, -0.7196, 2.2335],
|
||||
face: -1,
|
||||
}),
|
||||
Object.freeze({
|
||||
node: 'PORT_BETA_ROT_4B',
|
||||
pivot: [53.2219, 0.7294, -3.0076],
|
||||
face: -1,
|
||||
}),
|
||||
Object.freeze({
|
||||
node: 'STBD_BETA_ROT_1A',
|
||||
pivot: [-36.6608, 0.7257, 3.0224],
|
||||
face: 1,
|
||||
}),
|
||||
Object.freeze({
|
||||
node: 'STBD_BETA_ROT_3A',
|
||||
pivot: [-36.6608, -0.7257, -2.2408],
|
||||
face: 1,
|
||||
}),
|
||||
Object.freeze({
|
||||
node: 'STBD_BETA_ROT_1B',
|
||||
pivot: [-53.2219, -0.7294, -2.2408],
|
||||
face: 1,
|
||||
}),
|
||||
Object.freeze({
|
||||
node: 'STBD_BETA_ROT_3B',
|
||||
pivot: [-53.2232, 0.722, 3.0223],
|
||||
face: 1,
|
||||
}),
|
||||
]);
|
||||
|
||||
/** Radiator joints (TRRJ): rotate about glTF Z; the panels face Y at rest. */
|
||||
export const ISS_RADIATOR_JOINTS = Object.freeze([
|
||||
Object.freeze({ node: 'PORT_TRRJ_GAMMA_ROT', pivot: [16.1287, 0, -7.4432] }),
|
||||
Object.freeze({ node: 'STBD_TRRJ_GAMMA_ROT', pivot: [-16.1287, 0, -7.4432] }),
|
||||
]);
|
||||
|
||||
/** How fast a joint may turn on screen, radians per second of wall time. */
|
||||
export const ISS_JOINT_RATE = (12 * Math.PI) / 180;
|
||||
|
||||
/** Below this the Sun is too close to a joint's axis to steer by it. */
|
||||
const MIN_STEER = 0.05;
|
||||
const EARTH_RADIUS_M = 6_371_000;
|
||||
|
||||
/** The signed difference b - a, wrapped to (-π, π]. */
|
||||
function wrap(delta) {
|
||||
let d = delta % (2 * Math.PI);
|
||||
if (d > Math.PI) d -= 2 * Math.PI;
|
||||
if (d <= -Math.PI) d += 2 * Math.PI;
|
||||
return d;
|
||||
}
|
||||
|
||||
/** Of `angle` and `angle + π`, the one nearer to `previous`. */
|
||||
function nearestHalfTurn(angle, previous) {
|
||||
const flipped = angle + Math.PI;
|
||||
return Math.abs(wrap(angle - previous)) <= Math.abs(wrap(flipped - previous))
|
||||
? angle
|
||||
: flipped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a point is in the Earth's shadow, taken as a cylinder.
|
||||
* @param {number[]} positionEcef Meters.
|
||||
* @param {number[]} sunEcef Unit vector toward the Sun.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function issInShadow(positionEcef, sunEcef) {
|
||||
const along =
|
||||
positionEcef[0] * sunEcef[0] +
|
||||
positionEcef[1] * sunEcef[1] +
|
||||
positionEcef[2] * sunEcef[2];
|
||||
if (along >= 0) return false;
|
||||
const off = Math.hypot(
|
||||
positionEcef[0] - along * sunEcef[0],
|
||||
positionEcef[1] - along * sunEcef[1],
|
||||
positionEcef[2] - along * sunEcef[2],
|
||||
);
|
||||
return off < EARTH_RADIUS_M;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Sun's direction on the model's glTF axes, from the flight axes the
|
||||
* model is oriented by (x along-track, y orbit normal, z zenith).
|
||||
* @param {number[]} sunEcef Unit vector toward the Sun, Earth-fixed.
|
||||
* @param {{x:number[], y:number[], z:number[]}} axes
|
||||
* @returns {number[]} [port, zenith, forward].
|
||||
*/
|
||||
export function issSunInModelFrame(sunEcef, axes) {
|
||||
const dot = (a) => a[0] * sunEcef[0] + a[1] * sunEcef[1] + a[2] * sunEcef[2];
|
||||
return [dot(axes.y), dot(axes.z), dot(axes.x)];
|
||||
}
|
||||
|
||||
/**
|
||||
* The joint angles that point the arrays at the Sun.
|
||||
* @param {number[]} sun Unit vector toward the Sun on the model's glTF axes.
|
||||
* @param {boolean} sunlit False in the Earth's shadow: the arrays feather.
|
||||
* @param {{alpha:number, gamma:number}} [previous] The last targets, so a
|
||||
* joint with two equivalent answers keeps the nearer one.
|
||||
* @returns {{alpha:number, beta:number[], gamma:number}} Radians: `alpha`
|
||||
* about +X for both alpha joints, `beta` about +Z per ISS_BETA_JOINTS entry,
|
||||
* `gamma` about +Z for both radiator joints.
|
||||
*/
|
||||
export function issJointTargets(
|
||||
sun,
|
||||
sunlit,
|
||||
previous = { alpha: 0, gamma: 0 },
|
||||
) {
|
||||
const [sx, sy, sz] = sun;
|
||||
// Radiators: the panel normal, Y at rest, perpendicular to the Sun.
|
||||
const gamma =
|
||||
Math.hypot(sx, sy) < MIN_STEER
|
||||
? previous.gamma
|
||||
: nearestHalfTurn(Math.atan2(sy, sx), previous.gamma);
|
||||
if (!sunlit) {
|
||||
return {
|
||||
alpha: nearestHalfTurn(0, previous.alpha),
|
||||
beta: ISS_BETA_JOINTS.map(() => 0),
|
||||
gamma,
|
||||
};
|
||||
}
|
||||
// Alpha: the masts, ±Z at rest, perpendicular to the Sun.
|
||||
const alpha =
|
||||
Math.hypot(sy, sz) < MIN_STEER
|
||||
? previous.alpha
|
||||
: nearestHalfTurn(Math.atan2(sz, sy), previous.alpha);
|
||||
// The Sun as the arrays see it before the alpha turn.
|
||||
const c = Math.cos(alpha);
|
||||
const s = Math.sin(alpha);
|
||||
const lx = sx;
|
||||
const ly = c * sy + s * sz;
|
||||
// Beta: the cell side's normal, ±X at rest, onto the Sun.
|
||||
const beta = ISS_BETA_JOINTS.map(({ face }) =>
|
||||
Math.atan2(face * ly, face * lx),
|
||||
);
|
||||
return { alpha, beta, gamma };
|
||||
}
|
||||
|
||||
/**
|
||||
* Step `current` toward `target` the short way round, by at most `maxStep`.
|
||||
* @returns {number}
|
||||
*/
|
||||
export function issStepAngle(current, target, maxStep) {
|
||||
const delta = wrap(target - current);
|
||||
if (Math.abs(delta) <= maxStep) return current + delta;
|
||||
return current + Math.sign(delta) * maxStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* A node's matrix for a turn of `angle` about `axis` ('x' or 'z') through
|
||||
* `pivot`, column-major.
|
||||
* @param {'x'|'z'} axis
|
||||
* @param {number[]} pivot
|
||||
* @param {number} angle Radians.
|
||||
* @param {Cesium.Matrix4} result
|
||||
* @returns {Cesium.Matrix4}
|
||||
*/
|
||||
export function issJointMatrix(axis, pivot, angle, result) {
|
||||
const c = Math.cos(angle);
|
||||
const s = Math.sin(angle);
|
||||
const [px, py, pz] = pivot;
|
||||
// Row-major arguments.
|
||||
if (axis === 'x')
|
||||
return set(result, [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
c,
|
||||
-s,
|
||||
py - (c * py - s * pz),
|
||||
0,
|
||||
s,
|
||||
c,
|
||||
pz - (s * py + c * pz),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
]);
|
||||
return set(result, [
|
||||
c,
|
||||
-s,
|
||||
0,
|
||||
px - (c * px - s * py),
|
||||
s,
|
||||
c,
|
||||
0,
|
||||
py - (s * px + c * py),
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
]);
|
||||
}
|
||||
|
||||
function set(result, rowMajor) {
|
||||
return Cesium.Matrix4.fromRowMajorArray(rowMajor, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Canadarm2's seven joints as NASA's file names them, base to tip: each
|
||||
* node's pivot and its local Z axis on the model's axes. Where the real arm
|
||||
* is at any moment is not public, so its motion here is ILLUSTRATIVE: a slow
|
||||
* sway of `sway` radians about the pose in NASA's file, over `period`
|
||||
* seconds. Joints with no sway stay as filed.
|
||||
*/
|
||||
export const ISS_ARM_JOINTS = Object.freeze(
|
||||
[
|
||||
['SHR', [0.6732, -9.3793, 8.3367], [-0.0942, -0.0136, 0.9955], 0, 0],
|
||||
['SHY', [0.6004, -9.3899, 9.105], [-0.2949, 0.9554, -0.0148], 8, 97],
|
||||
['SHP_PRIME', [0.7848, -9.9873, 9.1143], [-0.2949, 0.9554, -0.0148], 6, 71],
|
||||
[
|
||||
'ELP_PRIME',
|
||||
[-2.9987, -11.8039, 2.5061],
|
||||
[-0.2949, 0.9554, -0.0148],
|
||||
12,
|
||||
53,
|
||||
],
|
||||
['WRP', [-3.8898, -12.6132, 10.249], [-0.2949, 0.9554, -0.0148], 10, 41],
|
||||
['WRY', [-3.9961, -12.6341, 11.0132], [-0.2949, 0.9554, -0.0148], 0, 0],
|
||||
['WRR', [-4.2995, -12.7285, 10.9684], [0.2874, -0.5533, -0.7818], 0, 0],
|
||||
].map(([node, pivot, axis, swayDeg, period]) =>
|
||||
Object.freeze({
|
||||
node,
|
||||
pivot,
|
||||
axis,
|
||||
sway: (swayDeg * Math.PI) / 180,
|
||||
period,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* The station's smaller arms, swayed the same illustrative way: Dextre's two
|
||||
* arms (shoulder and elbow pitch each) and the Japanese arm on Kibo
|
||||
* (shoulder, elbow and wrist pitch). The European arm on Nauka has no joints
|
||||
* in NASA's file, so it stays as filed.
|
||||
*/
|
||||
export const ISS_SMALL_ARM_JOINTS = Object.freeze(
|
||||
[
|
||||
[
|
||||
'SPDM_Arm1_SHP',
|
||||
[4.3019, -8.7313, 2.9551],
|
||||
[-0.5183, -0.8218, -0.2366],
|
||||
5,
|
||||
61,
|
||||
],
|
||||
[
|
||||
'SPDM_Arm1_ELP',
|
||||
[4.763, -7.9839, 3.1897],
|
||||
[0.2256, 0.4303, -0.874],
|
||||
7,
|
||||
43,
|
||||
],
|
||||
[
|
||||
'SPDM_Arm2_SHP',
|
||||
[1.8182, -9.8753, 5.2105],
|
||||
[-0.27, -0.522, -0.8091],
|
||||
5,
|
||||
67,
|
||||
],
|
||||
[
|
||||
'SPDM_Arm2_ELP',
|
||||
[1.8575, -9.4898, 6.0546],
|
||||
[-0.3202, -0.5495, -0.7717],
|
||||
7,
|
||||
47,
|
||||
],
|
||||
['JEM_SP_ROT', [14.2188, -3.6716, 13.394], [-0.001, 0, -1], 5, 83],
|
||||
['JEM_EP_ROT', [14.2223, 0.6479, 13.394], [-0.0011, 0, -1], 8, 59],
|
||||
['JEM_WP_ROT', [16.4495, -3.0694, 13.3917], [-0.001, 0, -1], 8, 37],
|
||||
].map(([node, pivot, axis, swayDeg, period]) =>
|
||||
Object.freeze({
|
||||
node,
|
||||
pivot,
|
||||
axis,
|
||||
sway: (swayDeg * Math.PI) / 180,
|
||||
period,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
/** Every joint that sways. */
|
||||
const ISS_SWAY_JOINTS = [...ISS_ARM_JOINTS, ...ISS_SMALL_ARM_JOINTS];
|
||||
|
||||
/**
|
||||
* The arm's illustrative joint angles at a wall-clock time.
|
||||
* @param {number} seconds
|
||||
* @returns {number[]} Radians, one per ISS_ARM_JOINTS entry.
|
||||
*/
|
||||
export function issArmAngles(seconds, joints = ISS_ARM_JOINTS) {
|
||||
return joints.map(({ sway, period }) =>
|
||||
sway ? sway * Math.sin((2 * Math.PI * seconds) / period) : 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The two Ku-band dishes on the Z1 truss. NASA's file has them welded into
|
||||
* the truss; the build cuts out everything above each gimbal. At rest a dish
|
||||
* looks along +Y (zenith).
|
||||
*/
|
||||
export const ISS_DISH_JOINTS = Object.freeze([
|
||||
Object.freeze({ node: 'SGANT_ROT_1', pivot: [-1.105, 4.5, -4.885] }),
|
||||
Object.freeze({ node: 'SGANT_ROT_2', pivot: [4.56, 4.64, -5.235] }),
|
||||
]);
|
||||
|
||||
/**
|
||||
* The relay satellites the dishes talk to (NASA's TDRS) sit over the equator
|
||||
* at fixed longitudes, so each is a fixed point in the Earth-fixed frame.
|
||||
* These are the fleet's nominal slots (Atlantic, Pacific, Indian Ocean), not
|
||||
* a live roster: which satellite the station uses at a given moment is not
|
||||
* public in real time.
|
||||
*/
|
||||
export const ISS_RELAY_LONGITUDES_DEG = Object.freeze([-41, -171, 85]);
|
||||
const GEOSTATIONARY_RADIUS_M = 42_164_000;
|
||||
/** A dish does not look below this much above the station's horizon plane. */
|
||||
const DISH_MIN_UP = 0.15;
|
||||
|
||||
/**
|
||||
* Where the relay satellites are from the station, on the model's axes, the
|
||||
* highest above the station first.
|
||||
* @param {number[]} positionEcef Meters.
|
||||
* @param {{x:number[], y:number[], z:number[]}} axes Flight axes.
|
||||
* @returns {number[][]} Unit vectors [port, zenith, forward].
|
||||
*/
|
||||
export function issRelayDirections(positionEcef, axes) {
|
||||
return ISS_RELAY_LONGITUDES_DEG.map((longitude) => {
|
||||
const lon = (longitude * Math.PI) / 180;
|
||||
const to = [
|
||||
GEOSTATIONARY_RADIUS_M * Math.cos(lon) - positionEcef[0],
|
||||
GEOSTATIONARY_RADIUS_M * Math.sin(lon) - positionEcef[1],
|
||||
-positionEcef[2],
|
||||
];
|
||||
const length = Math.hypot(to[0], to[1], to[2]);
|
||||
return issSunInModelFrame(
|
||||
to.map((c) => c / length),
|
||||
axes,
|
||||
);
|
||||
}).sort((a, b) => b[1] - a[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn the unit vector `current` toward `target` by at most `maxStep` radians.
|
||||
* @returns {number[]}
|
||||
*/
|
||||
export function issStepDirection(current, target, maxStep) {
|
||||
const cos = Math.min(
|
||||
1,
|
||||
Math.max(
|
||||
-1,
|
||||
current[0] * target[0] + current[1] * target[1] + current[2] * target[2],
|
||||
),
|
||||
);
|
||||
const angle = Math.acos(cos);
|
||||
if (angle <= maxStep || angle < 1e-6) return target;
|
||||
const sin = Math.sin(angle);
|
||||
// Opposite vectors have no single arc between them: nudge off the line.
|
||||
if (sin < 1e-6)
|
||||
return issStepDirection(
|
||||
[current[2], current[0], current[1]],
|
||||
target,
|
||||
maxStep,
|
||||
);
|
||||
const t = maxStep / angle;
|
||||
const a = Math.sin((1 - t) * angle) / sin;
|
||||
const b = Math.sin(t * angle) / sin;
|
||||
return [0, 1, 2].map((i) => a * current[i] + b * target[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A node's matrix for a turn of `angle` about the unit vector `axis` through
|
||||
* `pivot`.
|
||||
* @param {number[]} pivot
|
||||
* @param {number[]} axis Unit vector.
|
||||
* @param {number} angle Radians.
|
||||
* @param {Cesium.Matrix4} result
|
||||
* @returns {Cesium.Matrix4}
|
||||
*/
|
||||
export function issAxisMatrix(pivot, axis, angle, result) {
|
||||
const [x, y, z] = axis;
|
||||
const c = Math.cos(angle);
|
||||
const s = Math.sin(angle);
|
||||
const t = 1 - c;
|
||||
const r = [
|
||||
[t * x * x + c, t * x * y - s * z, t * x * z + s * y],
|
||||
[t * x * y + s * z, t * y * y + c, t * y * z - s * x],
|
||||
[t * x * z - s * y, t * y * z + s * x, t * z * z + c],
|
||||
];
|
||||
const rows = r.map((row, i) => [
|
||||
...row,
|
||||
pivot[i] - (row[0] * pivot[0] + row[1] * pivot[1] + row[2] * pivot[2]),
|
||||
]);
|
||||
return set(result, [...rows[0], ...rows[1], ...rows[2], 0, 0, 0, 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A dish node's matrix that turns its rest boresight (+Y) onto `direction`.
|
||||
* @param {number[]} pivot
|
||||
* @param {number[]} direction Unit vector on the model's axes.
|
||||
* @param {Cesium.Matrix4} result
|
||||
* @returns {Cesium.Matrix4}
|
||||
*/
|
||||
export function issAimMatrix(pivot, direction, result) {
|
||||
// Y × direction
|
||||
const kx = direction[2];
|
||||
const kz = -direction[0];
|
||||
const length = Math.hypot(kx, kz);
|
||||
if (length < 1e-9)
|
||||
return issAxisMatrix(
|
||||
pivot,
|
||||
[1, 0, 0],
|
||||
direction[1] > 0 ? 0 : Math.PI,
|
||||
result,
|
||||
);
|
||||
const angle = Math.acos(Math.min(1, Math.max(-1, direction[1])));
|
||||
return issAxisMatrix(pivot, [kx / length, 0, kz / length], angle, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drives the loaded model's joints. Stateless about the model: `update` looks
|
||||
* the nodes up once per model and only writes a node whose angle moved.
|
||||
*/
|
||||
export function createIssArticulation() {
|
||||
let boundModel = null;
|
||||
let nodes = null;
|
||||
let angles = null;
|
||||
let targets = { alpha: 0, gamma: 0 };
|
||||
let lastMs = 0;
|
||||
let override = null;
|
||||
let dishOverride = null;
|
||||
/** Whether the last update had the station in sunlight; null before one. */
|
||||
let lastSunlit = null;
|
||||
/** Command panel state: the arm is being posed by hand, so the sway is off. */
|
||||
let armManual = false;
|
||||
let armNodes = null;
|
||||
/** Command panel state: how far the arrays are rolled out, 0.05 to 1. */
|
||||
let deploy = 1;
|
||||
let deployTarget = 1;
|
||||
let radiatorDeploy = 1;
|
||||
let radiatorTarget = 1;
|
||||
/** The truss face the radiators fold back to, on the model's Z axis. */
|
||||
const RADIATOR_ROOT_Z = -1.9;
|
||||
/** The power modules' radiators, cut out by the build, and their root. */
|
||||
const SMALL_RADIATOR_NODES = [
|
||||
'PVR_FOLD_P4',
|
||||
'PVR_FOLD_P6',
|
||||
'PVR_FOLD_S4',
|
||||
'PVR_FOLD_S6',
|
||||
];
|
||||
const SMALL_RADIATOR_ROOT_Y = -1.6;
|
||||
/** Where each dish looks now, on the model's axes. */
|
||||
let dishes = null;
|
||||
const scratchJulian = new Cesium.JulianDate();
|
||||
const scratchSun = new Cesium.Cartesian3();
|
||||
const scratchToFixed = new Cesium.Matrix3();
|
||||
const scratchMatrix = new Cesium.Matrix4();
|
||||
|
||||
function bind(model) {
|
||||
boundModel = model;
|
||||
const get = (joint) => model.getNode(joint.node) ?? null;
|
||||
nodes = {
|
||||
alpha: ISS_ALPHA_JOINTS.map(get),
|
||||
beta: ISS_BETA_JOINTS.map(get),
|
||||
gamma: ISS_RADIATOR_JOINTS.map(get),
|
||||
dish: ISS_DISH_JOINTS.map(get),
|
||||
};
|
||||
angles = null;
|
||||
dishes = null;
|
||||
armNodes = null;
|
||||
}
|
||||
|
||||
function sunEcef(date) {
|
||||
const julian = Cesium.JulianDate.fromDate(date, scratchJulian);
|
||||
const inertial =
|
||||
Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame(
|
||||
julian,
|
||||
scratchSun,
|
||||
);
|
||||
const toFixed =
|
||||
Cesium.Transforms.computeIcrfToFixedMatrix(julian, scratchToFixed) ??
|
||||
Cesium.Transforms.computeTemeToPseudoFixedMatrix(julian, scratchToFixed);
|
||||
Cesium.Matrix3.multiplyByVector(toFixed, inertial, scratchSun);
|
||||
Cesium.Cartesian3.normalize(scratchSun, scratchSun);
|
||||
return [scratchSun.x, scratchSun.y, scratchSun.z];
|
||||
}
|
||||
|
||||
function write(node, axis, pivot, angle) {
|
||||
if (!node) return;
|
||||
node.matrix = issJointMatrix(axis, pivot, angle, scratchMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Cesium.Model} model A ready model.
|
||||
* @param {Date} date The instant the model is placed at.
|
||||
* @param {Cesium.Cartesian3} position Earth-fixed station position.
|
||||
* @param {{x:number[], y:number[], z:number[]}} axes Its flight axes.
|
||||
* @param {number} [nowMs] Wall clock, for the turn rate.
|
||||
*/
|
||||
function update(model, date, position, axes, nowMs = Date.now()) {
|
||||
if (!model.ready) return;
|
||||
if (model !== boundModel) bind(model);
|
||||
const forced = override?.(nowMs) ?? null;
|
||||
if (forced) {
|
||||
lastSunlit = Boolean(forced.sunlit);
|
||||
targets = issJointTargets(forced.sun, forced.sunlit, targets);
|
||||
} else {
|
||||
const sun = sunEcef(date);
|
||||
const sunlit = !issInShadow([position.x, position.y, position.z], sun);
|
||||
lastSunlit = sunlit;
|
||||
targets = issJointTargets(issSunInModelFrame(sun, axes), sunlit, targets);
|
||||
}
|
||||
// A first frame, or one after a pause, goes straight to the pose.
|
||||
const elapsed = (nowMs - lastMs) / 1000;
|
||||
lastMs = nowMs;
|
||||
const maxStep =
|
||||
!angles || !(elapsed >= 0) || elapsed > 2
|
||||
? Number.POSITIVE_INFINITY
|
||||
: ISS_JOINT_RATE * elapsed;
|
||||
const next = {
|
||||
alpha: issStepAngle(angles?.alpha ?? 0, targets.alpha, maxStep),
|
||||
beta: targets.beta.map((target, i) =>
|
||||
issStepAngle(angles?.beta[i] ?? 0, target, maxStep),
|
||||
),
|
||||
gamma: issStepAngle(angles?.gamma ?? 0, targets.gamma, maxStep),
|
||||
};
|
||||
if (!angles || next.alpha !== angles.alpha)
|
||||
ISS_ALPHA_JOINTS.forEach((joint, i) =>
|
||||
write(nodes.alpha[i], 'x', joint.pivot, next.alpha),
|
||||
);
|
||||
// Command panel: squash the arrays along their masts (see setDeploy).
|
||||
const deployStep = Number.isFinite(maxStep) ? elapsed / 8 : 1;
|
||||
const nextDeploy =
|
||||
deploy +
|
||||
Math.sign(deployTarget - deploy) *
|
||||
Math.min(Math.abs(deployTarget - deploy), deployStep);
|
||||
ISS_BETA_JOINTS.forEach((joint, i) => {
|
||||
if (
|
||||
!angles ||
|
||||
next.beta[i] !== angles.beta[i] ||
|
||||
nextDeploy !== deploy ||
|
||||
nextDeploy !== 1
|
||||
) {
|
||||
const node = nodes.beta[i];
|
||||
if (!node) return;
|
||||
const m = issJointMatrix('z', joint.pivot, next.beta[i], scratchMatrix);
|
||||
m[10] = nextDeploy;
|
||||
m[14] = joint.pivot[2] * (1 - nextDeploy);
|
||||
node.matrix = m;
|
||||
}
|
||||
});
|
||||
deploy = nextDeploy;
|
||||
// Command panel: fold the radiators toward the truss.
|
||||
const nextRadiator =
|
||||
radiatorDeploy +
|
||||
Math.sign(radiatorTarget - radiatorDeploy) *
|
||||
Math.min(Math.abs(radiatorTarget - radiatorDeploy), deployStep);
|
||||
if (
|
||||
!angles ||
|
||||
next.gamma !== angles.gamma ||
|
||||
nextRadiator !== radiatorDeploy
|
||||
)
|
||||
ISS_RADIATOR_JOINTS.forEach((joint, i) => {
|
||||
const node = nodes.gamma[i];
|
||||
if (!node) return;
|
||||
const m = issJointMatrix('z', joint.pivot, next.gamma, scratchMatrix);
|
||||
m[10] = nextRadiator;
|
||||
m[14] = RADIATOR_ROOT_Z * (1 - nextRadiator);
|
||||
node.matrix = m;
|
||||
});
|
||||
// The four small radiators fold up to the truss, along Y.
|
||||
if (nextRadiator !== radiatorDeploy)
|
||||
for (const name of SMALL_RADIATOR_NODES) {
|
||||
const node = model.getNode(name);
|
||||
if (!node) continue;
|
||||
node.matrix = Cesium.Matrix4.fromRowMajorArray(
|
||||
[
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
nextRadiator,
|
||||
0,
|
||||
SMALL_RADIATOR_ROOT_Y * (1 - nextRadiator),
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
],
|
||||
scratchMatrix,
|
||||
);
|
||||
}
|
||||
radiatorDeploy = nextRadiator;
|
||||
angles = next;
|
||||
|
||||
// Dishes: the highest relay satellite for the first, the next for the
|
||||
// second; one below the station's horizon plane keeps its last aim.
|
||||
const relays = dishOverride
|
||||
? [dishOverride, dishOverride]
|
||||
: issRelayDirections([position.x, position.y, position.z], axes);
|
||||
const nextDishes = ISS_DISH_JOINTS.map((joint, i) => {
|
||||
const current = dishes?.[i] ?? [0, 1, 0];
|
||||
const wanted = relays[i];
|
||||
const target = wanted && wanted[1] >= DISH_MIN_UP ? wanted : current;
|
||||
const stepped = issStepDirection(current, target, maxStep);
|
||||
const moved =
|
||||
!dishes || stepped.some((c, k) => Math.abs(c - current[k]) > 1e-9);
|
||||
if (moved)
|
||||
if (nodes.dish[i])
|
||||
nodes.dish[i].matrix = issAimMatrix(
|
||||
joint.pivot,
|
||||
stepped,
|
||||
scratchMatrix,
|
||||
);
|
||||
return stepped;
|
||||
});
|
||||
dishes = nextDishes;
|
||||
|
||||
// Arm: an illustrative sway (see ISS_ARM_JOINTS).
|
||||
if (!armManual) {
|
||||
const arm = issArmAngles(nowMs / 1000, ISS_SWAY_JOINTS);
|
||||
ISS_SWAY_JOINTS.forEach((joint, i) => {
|
||||
if (!joint.sway) return;
|
||||
const node = (armNodes ??= ISS_SWAY_JOINTS.map(
|
||||
(entry) => model.getNode(entry.node) ?? null,
|
||||
))[i];
|
||||
if (node)
|
||||
node.matrix = issAxisMatrix(
|
||||
joint.pivot,
|
||||
joint.axis,
|
||||
arm[i],
|
||||
scratchMatrix,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Command panel: turn any named node about an axis through a pivot.
|
||||
* @param {string} name
|
||||
* @param {number[]} pivot
|
||||
* @param {number[]} axis Unit vector.
|
||||
* @param {number} angle Radians.
|
||||
*/
|
||||
function setJoint(name, pivot, axis, angle) {
|
||||
armManual = true;
|
||||
const node = boundModel?.getNode(name);
|
||||
if (node) node.matrix = issAxisMatrix(pivot, axis, angle, scratchMatrix);
|
||||
}
|
||||
|
||||
function reset() {
|
||||
boundModel = null;
|
||||
nodes = null;
|
||||
angles = null;
|
||||
dishes = null;
|
||||
armNodes = null;
|
||||
targets = { alpha: 0, gamma: 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Command panel: a function giving the Sun on the model's axes (and whether the
|
||||
* station is lit) in place of the real one, or null for the real one.
|
||||
* @param {((nowMs:number)=>{sun:number[], sunlit:boolean}|null)|null} fn
|
||||
*/
|
||||
function setOverride(fn) {
|
||||
override = fn;
|
||||
}
|
||||
|
||||
/** Whether the station is in sunlight, as of the last update. */
|
||||
function isSunlit() {
|
||||
return lastSunlit;
|
||||
}
|
||||
|
||||
/** Command panel: aim both dishes along a unit vector, or null for the relays. */
|
||||
function setDishOverride(direction) {
|
||||
dishOverride = direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command panel: squash the arrays toward their bases, or let them
|
||||
* out again. The real arrays do not retract in service.
|
||||
* @param {boolean} out
|
||||
*/
|
||||
function setDeploy(out) {
|
||||
deployTarget = out ? 1 : 0.05;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command panel: fold the radiators toward the truss, or let them
|
||||
* out. The real ones are accordion panels that can do this, but stay out
|
||||
* in service.
|
||||
* @param {boolean} out
|
||||
*/
|
||||
function setRadiatorDeploy(out) {
|
||||
radiatorTarget = out ? 1 : 0.08;
|
||||
}
|
||||
|
||||
/** Command panel: hand the arm back to its sway. */
|
||||
function resumeArm() {
|
||||
armManual = false;
|
||||
}
|
||||
|
||||
return {
|
||||
update,
|
||||
reset,
|
||||
setOverride,
|
||||
setDishOverride,
|
||||
setJoint,
|
||||
resumeArm,
|
||||
setDeploy,
|
||||
setRadiatorDeploy,
|
||||
isSunlit,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
ISS_ALPHA_JOINTS,
|
||||
ISS_BETA_JOINTS,
|
||||
ISS_RADIATOR_JOINTS,
|
||||
issInShadow,
|
||||
issJointMatrix,
|
||||
issJointTargets,
|
||||
issStepAngle,
|
||||
issSunInModelFrame,
|
||||
} from './issArticulation.js';
|
||||
|
||||
const rotX = (a, [x, y, z]) => [
|
||||
x,
|
||||
Math.cos(a) * y - Math.sin(a) * z,
|
||||
Math.sin(a) * y + Math.cos(a) * z,
|
||||
];
|
||||
const rotZ = (a, [x, y, z]) => [
|
||||
Math.cos(a) * x - Math.sin(a) * y,
|
||||
Math.sin(a) * x + Math.cos(a) * y,
|
||||
z,
|
||||
];
|
||||
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||
const unit = (v) => v.map((c) => c / Math.hypot(...v));
|
||||
|
||||
const SUNS = [
|
||||
[0, 1, 0],
|
||||
[0, -1, 0],
|
||||
[0, 0, 1],
|
||||
[0.5, 0.5, 0.7],
|
||||
[-0.6, 0.2, -0.77],
|
||||
[0.3, -0.9, 0.3],
|
||||
[0.9, 0.1, -0.4],
|
||||
].map(unit);
|
||||
|
||||
test('in sunlight every array faces the Sun, masts across it', () => {
|
||||
for (const sun of SUNS) {
|
||||
const { alpha, beta } = issJointTargets(sun, true);
|
||||
assert.ok(Math.abs(dot(rotX(alpha, [0, 0, 1]), sun)) < 1e-9);
|
||||
ISS_BETA_JOINTS.forEach(({ face }, i) => {
|
||||
// The beta joint hangs from the alpha joint: beta turns first.
|
||||
const normal = rotX(alpha, rotZ(beta[i], [face, 0, 0]));
|
||||
assert.ok(dot(normal, sun) > 1 - 1e-9, `${sun} array ${i}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('the radiators stay edge-on to the Sun', () => {
|
||||
for (const sun of SUNS) {
|
||||
const { gamma } = issJointTargets(sun, true);
|
||||
assert.ok(Math.abs(dot(rotZ(gamma, [0, 1, 0]), sun)) < 1e-9);
|
||||
}
|
||||
});
|
||||
|
||||
test('in the shadow the arrays feather along the flight direction', () => {
|
||||
const { alpha, beta } = issJointTargets(unit([0.2, -0.9, 0.3]), false, {
|
||||
alpha: 3,
|
||||
gamma: 0,
|
||||
});
|
||||
assert.ok(Math.abs(Math.sin(alpha)) < 1e-9); // masts back along ±Z
|
||||
assert.ok(Math.abs(alpha - Math.PI) < 1e-9); // the nearer half turn
|
||||
assert.deepEqual(
|
||||
beta,
|
||||
ISS_BETA_JOINTS.map(() => 0),
|
||||
);
|
||||
});
|
||||
|
||||
test('a joint keeps the answer nearer its last one, and holds near its axis', () => {
|
||||
const first = issJointTargets(unit([0, 1, 0.01]), true);
|
||||
const next = issJointTargets(unit([0, 1, -0.01]), true, first);
|
||||
assert.ok(Math.abs(next.alpha - first.alpha) < 0.05);
|
||||
// Sun along the truss: nothing to steer the alpha joint by.
|
||||
const held = issJointTargets([1, 0, 0], true, { alpha: 1.2, gamma: 0.4 });
|
||||
assert.equal(held.alpha, 1.2);
|
||||
});
|
||||
|
||||
test('angles step the short way round, capped', () => {
|
||||
assert.equal(issStepAngle(0, 1, 0.25), 0.25);
|
||||
assert.ok(issStepAngle(3, -3, 0.1) > 3); // through π, not back through 0
|
||||
assert.equal(issStepAngle(0.2, 0.3, 1), 0.3);
|
||||
});
|
||||
|
||||
test('a joint matrix leaves its pivot in place', () => {
|
||||
for (const axis of ['x', 'z']) {
|
||||
const pivot = [3, -2, 5];
|
||||
const m = issJointMatrix(axis, pivot, 0.7, undefined);
|
||||
const moved = [0, 1, 2].map(
|
||||
(r) =>
|
||||
m[r] * pivot[0] + m[4 + r] * pivot[1] + m[8 + r] * pivot[2] + m[12 + r],
|
||||
);
|
||||
moved.forEach((v, i) => assert.ok(Math.abs(v - pivot[i]) < 1e-12));
|
||||
}
|
||||
});
|
||||
|
||||
test('the shadow is the cylinder behind the Earth', () => {
|
||||
const sun = [1, 0, 0];
|
||||
assert.equal(issInShadow([6_790_000, 0, 0], sun), false);
|
||||
assert.equal(issInShadow([-6_790_000, 0, 0], sun), true);
|
||||
assert.equal(issInShadow([-1_000_000, 6_700_000, 0], sun), false);
|
||||
});
|
||||
|
||||
test('the Sun lands on the model axes: port, zenith, forward', () => {
|
||||
const axes = { x: [1, 0, 0], y: [0, 1, 0], z: [0, 0, 1] };
|
||||
assert.deepEqual(issSunInModelFrame([0.1, 0.2, 0.3], axes), [0.2, 0.3, 0.1]);
|
||||
});
|
||||
|
||||
test('the model file has every joint node, beta joints under their alpha', () => {
|
||||
const buf = fs.readFileSync(
|
||||
new URL('../../../public/models/iss.glb', import.meta.url),
|
||||
);
|
||||
const json = JSON.parse(
|
||||
buf.subarray(20, 20 + buf.readUInt32LE(12)).toString('utf8'),
|
||||
);
|
||||
const byName = new Map(json.nodes.map((n) => [n.name, n]));
|
||||
for (const { node } of [
|
||||
...ISS_ALPHA_JOINTS,
|
||||
...ISS_BETA_JOINTS,
|
||||
...ISS_RADIATOR_JOINTS,
|
||||
]) {
|
||||
const n = byName.get(node);
|
||||
assert.ok(n, node);
|
||||
// Joints rest at identity: the pivots above are in the model's own frame.
|
||||
assert.equal(n.rotation, undefined);
|
||||
assert.equal(n.translation, undefined);
|
||||
assert.equal(n.matrix, undefined);
|
||||
}
|
||||
for (const side of ['PORT', 'STBD']) {
|
||||
const kids = byName
|
||||
.get(`${side}_ALPHA_ROT`)
|
||||
.children.map((i) => json.nodes[i].name);
|
||||
for (const { node } of ISS_BETA_JOINTS)
|
||||
if (node.startsWith(side)) assert.ok(kids.includes(node), node);
|
||||
}
|
||||
});
|
||||
|
||||
test('a dish aims its rest boresight (+Y) at the direction, pivot in place', async () => {
|
||||
const { issAimMatrix, ISS_DISH_JOINTS } =
|
||||
await import('./issArticulation.js');
|
||||
for (const direction of SUNS) {
|
||||
const m = issAimMatrix(ISS_DISH_JOINTS[0].pivot, direction, undefined);
|
||||
// Column 1 is where +Y goes.
|
||||
[m[4], m[5], m[6]].forEach((v, i) =>
|
||||
assert.ok(Math.abs(v - direction[i]) < 1e-9),
|
||||
);
|
||||
const p = ISS_DISH_JOINTS[0].pivot;
|
||||
[0, 1, 2].forEach((r) =>
|
||||
assert.ok(
|
||||
Math.abs(
|
||||
m[r] * p[0] + m[4 + r] * p[1] + m[8 + r] * p[2] + m[12 + r] - p[r],
|
||||
) < 1e-9,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('relay directions are unit vectors, highest above the station first', async () => {
|
||||
const { issRelayDirections } = await import('./issArticulation.js');
|
||||
// Over the equator at 41°W, flying east: the Atlantic relay is overhead.
|
||||
const lon = (-41 * Math.PI) / 180;
|
||||
const r = 6_790_000;
|
||||
const position = [r * Math.cos(lon), r * Math.sin(lon), 0];
|
||||
const zenith = [Math.cos(lon), Math.sin(lon), 0];
|
||||
const east = [-Math.sin(lon), Math.cos(lon), 0];
|
||||
const axes = { x: east, y: [0, 0, 1], z: zenith };
|
||||
const relays = issRelayDirections(position, axes);
|
||||
assert.equal(relays.length, 3);
|
||||
relays.forEach((d) => assert.ok(Math.abs(Math.hypot(...d) - 1) < 1e-9));
|
||||
assert.ok(relays[0][1] > 0.999);
|
||||
assert.ok(relays[0][1] >= relays[1][1] && relays[1][1] >= relays[2][1]);
|
||||
});
|
||||
|
||||
test('a direction steps along the arc, capped, and lands on the target', async () => {
|
||||
const { issStepDirection } = await import('./issArticulation.js');
|
||||
const stepped = issStepDirection([0, 1, 0], [1, 0, 0], 0.1);
|
||||
assert.ok(Math.abs(Math.hypot(...stepped) - 1) < 1e-9);
|
||||
assert.ok(Math.abs(Math.acos(stepped[1]) - 0.1) < 1e-9);
|
||||
assert.deepEqual(issStepDirection([0, 1, 0], [1, 0, 0], 2), [1, 0, 0]);
|
||||
});
|
||||
|
||||
test('the model file has both dish nodes', async () => {
|
||||
const { ISS_DISH_JOINTS } = await import('./issArticulation.js');
|
||||
const buf = fs.readFileSync(
|
||||
new URL('../../../public/models/iss.glb', import.meta.url),
|
||||
);
|
||||
const json = JSON.parse(
|
||||
buf.subarray(20, 20 + buf.readUInt32LE(12)).toString('utf8'),
|
||||
);
|
||||
for (const { node } of ISS_DISH_JOINTS) {
|
||||
const n = json.nodes.find((candidate) => candidate.name === node);
|
||||
assert.ok(n?.children?.length, node);
|
||||
}
|
||||
});
|
||||
|
||||
test('the arm sways gently about the filed pose, and only where it is set to', async () => {
|
||||
const { ISS_ARM_JOINTS, issArmAngles } = await import('./issArticulation.js');
|
||||
assert.equal(ISS_ARM_JOINTS.length, 7);
|
||||
for (let seconds = 0; seconds < 400; seconds += 7) {
|
||||
issArmAngles(seconds).forEach((angle, i) => {
|
||||
assert.ok(Math.abs(angle) <= ISS_ARM_JOINTS[i].sway + 1e-12);
|
||||
// Illustrative, so kept small.
|
||||
assert.ok(Math.abs(angle) <= (12 * Math.PI) / 180 + 1e-12);
|
||||
});
|
||||
}
|
||||
assert.deepEqual(issArmAngles(0), [0, 0, 0, 0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
test('the smaller arms sway too, and their joints are in the model file', async () => {
|
||||
const { ISS_SMALL_ARM_JOINTS, ISS_ARM_JOINTS, issArmAngles } =
|
||||
await import('./issArticulation.js');
|
||||
const buf = fs.readFileSync(
|
||||
new URL('../../../public/models/iss.glb', import.meta.url),
|
||||
);
|
||||
const json = JSON.parse(
|
||||
buf.subarray(20, 20 + buf.readUInt32LE(12)).toString('utf8'),
|
||||
);
|
||||
const names = new Set(json.nodes.map((n) => n.name));
|
||||
for (const { node, sway, axis } of [
|
||||
...ISS_ARM_JOINTS,
|
||||
...ISS_SMALL_ARM_JOINTS,
|
||||
]) {
|
||||
assert.ok(names.has(node), node);
|
||||
assert.ok(sway <= (12 * Math.PI) / 180 + 1e-12);
|
||||
assert.ok(Math.abs(Math.hypot(...axis) - 1) < 1e-3);
|
||||
}
|
||||
assert.equal(
|
||||
issArmAngles(10, ISS_SMALL_ARM_JOINTS).length,
|
||||
ISS_SMALL_ARM_JOINTS.length,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,481 @@
|
||||
import { onLocaleChange, t } from '../../i18n/index.js';
|
||||
import { ISS_ARM_JOINTS } from './issArticulation.js';
|
||||
import { makePanelDraggable } from './issLive.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { ISS_NORAD } from './policy.js';
|
||||
|
||||
/**
|
||||
* Whether the command panel shows: the ISS selected (tracked), the layer on
|
||||
* and the Cockpit not riding it.
|
||||
* @param {{enabled: boolean, trackedNorad: number|null, cockpitHeld: boolean}} input
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function issCommandShouldShow({ enabled, trackedNorad, cockpitHeld }) {
|
||||
return Boolean(enabled) && trackedNorad === ISS_NORAD && !cockpitHeld;
|
||||
}
|
||||
|
||||
const unit = (v) => {
|
||||
const n = Math.hypot(...v);
|
||||
return v.map((c) => c / n);
|
||||
};
|
||||
|
||||
/**
|
||||
* The Sun positions Manual offers, on the model's axes (port, zenith,
|
||||
* forward), and whether the station is lit there.
|
||||
* @returns {Array<{label: string, sun: number[], sunlit: boolean}>}
|
||||
*/
|
||||
export function issCommandSunPoses() {
|
||||
return [
|
||||
{ label: t('Overhead'), sun: [0, 1, 0], sunlit: true },
|
||||
{ label: t('Ahead'), sun: unit([0, 0.05, 1]), sunlit: true },
|
||||
{ label: t('Behind'), sun: unit([0, 0.05, -1]), sunlit: true },
|
||||
{ label: t('Below'), sun: unit([0, -1, 0.05]), sunlit: true },
|
||||
{ label: t('Port side'), sun: unit([0.8, 0.5, 0.3]), sunlit: true },
|
||||
{ label: t('Starboard side'), sun: unit([-0.8, 0.5, 0.3]), sunlit: true },
|
||||
{ label: t('Night (shadow)'), sun: [0, -1, 0], sunlit: false },
|
||||
];
|
||||
}
|
||||
|
||||
/** Where "Zoom to the ISS" stops: the whole 109 m station fills the view. */
|
||||
export const ISS_COMMAND_ZOOM_RANGE_M = 260;
|
||||
|
||||
/**
|
||||
* The Automatic mode's status line.
|
||||
* @param {boolean|null} sunlit Null while the model has not been placed yet.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function issCommandStatusText(sunlit) {
|
||||
if (sunlit === null) return '';
|
||||
return sunlit ? t('Now: in sunlight') : t("Now: in the Earth's shadow");
|
||||
}
|
||||
|
||||
/** Beyond this the camera counts as far, and the zoom button is offered. */
|
||||
export const ISS_COMMAND_FAR_M = 1000;
|
||||
|
||||
/**
|
||||
* Whether "Zoom to the ISS" is offered: only from far away, so it goes once
|
||||
* the camera is in close (by the button or by hand) and returns on zooming
|
||||
* back out.
|
||||
* @param {number} distance Meters from the camera to the station.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function issCommandOffersZoom(distance) {
|
||||
return distance > ISS_COMMAND_FAR_M;
|
||||
}
|
||||
|
||||
/**
|
||||
* One step of the zoom: how far to move in from `distance`, easing out as
|
||||
* the target range nears, never past it.
|
||||
* @param {number} distance Meters from the camera to the station.
|
||||
* @returns {number} Meters to move in; 0 once close enough.
|
||||
*/
|
||||
export function issCommandZoomStep(distance) {
|
||||
const left = distance - ISS_COMMAND_ZOOM_RANGE_M;
|
||||
if (!(left > ISS_COMMAND_ZOOM_RANGE_M * 0.02)) return 0;
|
||||
return left * 0.14;
|
||||
}
|
||||
|
||||
/** How long one lap of the "fast orbit" takes, and its share in shadow. */
|
||||
const FAST_ORBIT_MS = 40_000;
|
||||
|
||||
/**
|
||||
* The Sun over one accelerated orbit: it circles the truss, a third of the
|
||||
* lap in the Earth's shadow.
|
||||
* @param {number} elapsedMs
|
||||
* @returns {{sun: number[], sunlit: boolean}}
|
||||
*/
|
||||
export function issCommandFastOrbit(elapsedMs) {
|
||||
const angle = (elapsedMs / FAST_ORBIT_MS) * 2 * Math.PI;
|
||||
return {
|
||||
sun: unit([0.35, Math.cos(angle), Math.sin(angle)]),
|
||||
sunlit: Math.cos(angle) > -0.5,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The ISS command panel: shown collapsed while the ISS is selected. Automatic
|
||||
* (the default) leaves the model to its own rules: arrays and radiators by the
|
||||
* Sun, dishes at the relay satellites, arms swaying. Manual opens the
|
||||
* controls and hands the joints to the viewer; going back to Automatic
|
||||
* returns every joint to its rule.
|
||||
*/
|
||||
export function createIssCommand({ state: layerState, parts }) {
|
||||
let panel = null;
|
||||
let renderTimer = null;
|
||||
let renderUntil = 0;
|
||||
|
||||
const joints = () => parts.issModel?._issArticulation ?? null;
|
||||
|
||||
/** Keep frames coming while a joint is on its way to a new pose. */
|
||||
function _renderFor(ms) {
|
||||
renderUntil = Math.max(renderUntil, Date.now() + ms);
|
||||
if (renderTimer) return;
|
||||
renderTimer = setInterval(() => {
|
||||
layerState._viewer?.scene?.requestRender?.();
|
||||
if (Date.now() > renderUntil) _stopRendering();
|
||||
}, 33);
|
||||
}
|
||||
|
||||
function _stopRendering() {
|
||||
if (renderTimer) clearInterval(renderTimer);
|
||||
renderTimer = null;
|
||||
renderUntil = 0;
|
||||
}
|
||||
|
||||
let zoomTimer = null;
|
||||
let zoomButton = null;
|
||||
/** Stops listening for language changes; set while the panel is open. */
|
||||
let stopLocale = null;
|
||||
let statusLine = null;
|
||||
/** The lit/shadow state the status line last showed. */
|
||||
let shownSunlit;
|
||||
|
||||
/** Say whether the station is in sunlight right now, when that changes. */
|
||||
function _syncStatus() {
|
||||
if (!statusLine) return;
|
||||
const sunlit = joints()?.isSunlit() ?? null;
|
||||
if (sunlit === shownSunlit) return;
|
||||
shownSunlit = sunlit;
|
||||
statusLine.textContent = issCommandStatusText(sunlit);
|
||||
}
|
||||
|
||||
/** Meters from the camera to the station, or null when unknown. */
|
||||
function _stationDistance() {
|
||||
const viewer = layerState._viewer;
|
||||
const target =
|
||||
parts.issModel?._issVisualPosition?.() ??
|
||||
layerState._trackedFrameCartesian ??
|
||||
layerState._points.get(ISS_NORAD)?.position;
|
||||
if (!viewer || !target) return null;
|
||||
return Cesium.Cartesian3.distance(viewer.camera.positionWC, target);
|
||||
}
|
||||
|
||||
function _syncZoomButton() {
|
||||
if (!zoomButton) return;
|
||||
const distance = _stationDistance();
|
||||
const offered = distance !== null && issCommandOffersZoom(distance);
|
||||
if (zoomButton.hidden === offered) zoomButton.hidden = !offered;
|
||||
}
|
||||
|
||||
function _stopZoom() {
|
||||
if (zoomTimer) clearInterval(zoomTimer);
|
||||
zoomTimer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring the follow camera in to the station. The camera already tracks the
|
||||
* ISS, so this only shortens its range, a step per frame.
|
||||
*/
|
||||
function _zoomToStation() {
|
||||
_stopZoom();
|
||||
let steps = 0;
|
||||
zoomTimer = setInterval(() => {
|
||||
const viewer = layerState._viewer;
|
||||
const target =
|
||||
parts.issModel?._issVisualPosition?.() ??
|
||||
layerState._trackedFrameCartesian ??
|
||||
layerState._points.get(ISS_NORAD)?.position;
|
||||
steps += 1;
|
||||
if (
|
||||
!viewer ||
|
||||
!target ||
|
||||
layerState._trackedNorad !== ISS_NORAD ||
|
||||
steps > 400
|
||||
) {
|
||||
_stopZoom();
|
||||
return;
|
||||
}
|
||||
const step = issCommandZoomStep(
|
||||
Cesium.Cartesian3.distance(viewer.camera.positionWC, target),
|
||||
);
|
||||
if (!step) {
|
||||
_stopZoom();
|
||||
return;
|
||||
}
|
||||
viewer.camera.zoomIn(step);
|
||||
viewer.scene.requestRender?.();
|
||||
}, 16);
|
||||
}
|
||||
|
||||
/** Every joint back to its own rule. */
|
||||
function _automatic() {
|
||||
const articulation = joints();
|
||||
if (!articulation) return;
|
||||
articulation.setOverride(null);
|
||||
articulation.setDishOverride(null);
|
||||
articulation.setDeploy(true);
|
||||
articulation.setRadiatorDeploy(true);
|
||||
articulation.resumeArm();
|
||||
_renderFor(20_000);
|
||||
}
|
||||
|
||||
function _build(documentRef) {
|
||||
const el = (tag, className, text) => {
|
||||
const node = documentRef.createElement(tag);
|
||||
if (className) node.className = className;
|
||||
if (text !== undefined) node.textContent = text;
|
||||
return node;
|
||||
};
|
||||
const root = el('section', 'qci-panel iss-command-panel');
|
||||
root.setAttribute('role', 'region');
|
||||
root.setAttribute('aria-label', t('ISS command panel'));
|
||||
|
||||
const header = el('header', 'qci-header');
|
||||
const title = el('strong', 'iss-command-title', t('ISS · COMMAND PANEL'));
|
||||
const toggle = el('button', 'iss-command-toggle');
|
||||
toggle.type = 'button';
|
||||
header.append(title, toggle);
|
||||
|
||||
const body = el('div', 'iss-command-body');
|
||||
body.hidden = true;
|
||||
const setCollapsed = (collapsed) => {
|
||||
body.hidden = collapsed;
|
||||
toggle.textContent = collapsed ? '▸' : '▾';
|
||||
toggle.setAttribute('aria-expanded', String(!collapsed));
|
||||
toggle.setAttribute(
|
||||
'aria-label',
|
||||
collapsed ? t('Expand command panel') : t('Collapse command panel'),
|
||||
);
|
||||
};
|
||||
toggle.addEventListener('click', () => setCollapsed(!body.hidden));
|
||||
setCollapsed(true);
|
||||
|
||||
// Mode
|
||||
const modes = el('div', 'iss-command-modes');
|
||||
modes.setAttribute('role', 'radiogroup');
|
||||
const autoButton = el('button', 'iss-command-mode', t('Automatic'));
|
||||
const manualButton = el('button', 'iss-command-mode', t('Manual'));
|
||||
const status = el('p', 'iss-command-status');
|
||||
statusLine = status;
|
||||
const autoNote = el(
|
||||
'p',
|
||||
'qci-note',
|
||||
t(
|
||||
'Arrays and radiators follow the Sun, the dishes aim at relay satellites and the arms sway for illustration. Computed, not live telemetry.',
|
||||
),
|
||||
);
|
||||
const manual = el('div', 'iss-command-manual');
|
||||
manual.hidden = true;
|
||||
const setMode = (isManual) => {
|
||||
for (const [button, on] of [
|
||||
[autoButton, !isManual],
|
||||
[manualButton, isManual],
|
||||
]) {
|
||||
button.type = 'button';
|
||||
button.setAttribute('role', 'radio');
|
||||
button.setAttribute('aria-checked', String(on));
|
||||
button.classList.toggle('is-active', on);
|
||||
}
|
||||
manual.hidden = !isManual;
|
||||
autoNote.hidden = isManual;
|
||||
status.hidden = isManual;
|
||||
};
|
||||
const resetControls = () => {
|
||||
manual
|
||||
.querySelectorAll('input[type="range"]')
|
||||
.forEach((slider) => (slider.value = '0'));
|
||||
// Back to what Automatic does: each row's own default lit.
|
||||
manual
|
||||
.querySelectorAll('.iss-command-button')
|
||||
.forEach((button) =>
|
||||
button.classList.toggle('is-active', button.dataset.default === '1'),
|
||||
);
|
||||
};
|
||||
autoButton.addEventListener('click', () => {
|
||||
setMode(false);
|
||||
resetControls();
|
||||
_automatic();
|
||||
});
|
||||
manualButton.addEventListener('click', () => setMode(true));
|
||||
modes.append(autoButton, manualButton);
|
||||
setMode(false);
|
||||
|
||||
// Manual controls
|
||||
const group = (label, note) => {
|
||||
const box = el('div', 'iss-command-group');
|
||||
box.append(el('div', 'iss-command-label', label));
|
||||
const row = el('div', 'iss-command-row');
|
||||
box.append(row);
|
||||
if (note) box.append(el('p', 'qci-note', note));
|
||||
manual.append(box);
|
||||
return row;
|
||||
};
|
||||
/** A row of buttons where the last one pressed stays lit. */
|
||||
const choices = (row, entries) => {
|
||||
for (const [label, action, isDefault] of entries) {
|
||||
const button = el('button', 'iss-command-button', label);
|
||||
button.type = 'button';
|
||||
// What Automatic is doing starts lit, so the row shows what holds.
|
||||
if (isDefault) {
|
||||
button.dataset.default = '1';
|
||||
button.classList.add('is-active');
|
||||
}
|
||||
button.addEventListener('click', () => {
|
||||
row
|
||||
.querySelectorAll('.is-active')
|
||||
.forEach((other) => other.classList.remove('is-active'));
|
||||
button.classList.add('is-active');
|
||||
const articulation = joints();
|
||||
if (!articulation) return;
|
||||
action(articulation);
|
||||
_renderFor(20_000);
|
||||
});
|
||||
row.append(button);
|
||||
}
|
||||
};
|
||||
|
||||
choices(group(t('Sun position')), [
|
||||
[t('Follow the Sun'), (a) => a.setOverride(null), true],
|
||||
...issCommandSunPoses().map(({ label, sun, sunlit }) => [
|
||||
label,
|
||||
(a) => {
|
||||
const fixed = { sun, sunlit };
|
||||
a.setOverride(() => fixed);
|
||||
},
|
||||
]),
|
||||
[
|
||||
t('Fast orbit (40 s)'),
|
||||
(a) => {
|
||||
const start = Date.now();
|
||||
a.setOverride((nowMs) => issCommandFastOrbit(nowMs - start));
|
||||
_renderFor(10 * 60_000);
|
||||
},
|
||||
],
|
||||
]);
|
||||
choices(
|
||||
group(
|
||||
t('Solar arrays'),
|
||||
t('Demonstration: the real arrays stay extended.'),
|
||||
),
|
||||
[
|
||||
[t('Retract'), (a) => a.setDeploy(false)],
|
||||
[t('Extend'), (a) => a.setDeploy(true), true],
|
||||
],
|
||||
);
|
||||
choices(
|
||||
group(
|
||||
t('Radiators'),
|
||||
t('Demonstration: the real radiators can fold but stay extended.'),
|
||||
),
|
||||
[
|
||||
[t('Retract'), (a) => a.setRadiatorDeploy(false)],
|
||||
[t('Extend'), (a) => a.setRadiatorDeploy(true), true],
|
||||
],
|
||||
);
|
||||
choices(group(t('Dishes')), [
|
||||
[t('Relay satellites'), (a) => a.setDishOverride(null), true],
|
||||
[t('Up'), (a) => a.setDishOverride([0, 1, 0])],
|
||||
[t('Forward'), (a) => a.setDishOverride(unit([0, 0.35, 0.94]))],
|
||||
[t('Sideways'), (a) => a.setDishOverride(unit([0.94, 0.35, 0]))],
|
||||
]);
|
||||
|
||||
const armLabels = [
|
||||
t('Shoulder roll'),
|
||||
t('Shoulder yaw'),
|
||||
t('Shoulder pitch'),
|
||||
t('Elbow'),
|
||||
t('Wrist pitch'),
|
||||
t('Wrist yaw'),
|
||||
t('Wrist roll'),
|
||||
];
|
||||
const arm = group(t('Canadarm2 (degrees)'));
|
||||
arm.classList.add('iss-command-sliders');
|
||||
ISS_ARM_JOINTS.forEach((joint, i) => {
|
||||
const row = el('label', 'iss-command-slider');
|
||||
const slider = el('input');
|
||||
slider.type = 'range';
|
||||
slider.min = '-120';
|
||||
slider.max = '120';
|
||||
slider.value = '0';
|
||||
slider.addEventListener('input', () => {
|
||||
joints()?.setJoint(
|
||||
joint.node,
|
||||
joint.pivot,
|
||||
joint.axis,
|
||||
(Number(slider.value) * Math.PI) / 180,
|
||||
);
|
||||
_renderFor(2000);
|
||||
});
|
||||
row.append(el('span', '', armLabels[i]), slider);
|
||||
arm.append(row);
|
||||
});
|
||||
const resume = el('button', 'iss-command-button', t('Resume sway'));
|
||||
resume.type = 'button';
|
||||
resume.addEventListener('click', () => {
|
||||
arm
|
||||
.querySelectorAll('input[type="range"]')
|
||||
.forEach((slider) => (slider.value = '0'));
|
||||
joints()?.resumeArm();
|
||||
_renderFor(20_000);
|
||||
});
|
||||
arm.append(resume);
|
||||
|
||||
const zoom = el('button', 'iss-command-button iss-command-zoom');
|
||||
zoom.type = 'button';
|
||||
zoom.textContent = t('Zoom to the ISS');
|
||||
zoom.addEventListener('click', _zoomToStation);
|
||||
zoomButton = zoom;
|
||||
body.append(zoom, modes, status, autoNote, manual);
|
||||
root.append(header, body);
|
||||
makePanelDraggable(root, header);
|
||||
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 _syncIssCommand() {
|
||||
const show = issCommandShouldShow({
|
||||
enabled: layerState._enabled,
|
||||
trackedNorad: layerState._trackedNorad,
|
||||
cockpitHeld: Boolean(parts.cockpit?._cockpitHeld()),
|
||||
});
|
||||
if (!show) {
|
||||
_removePanel();
|
||||
return;
|
||||
}
|
||||
if (panel) {
|
||||
_syncZoomButton();
|
||||
_syncStatus();
|
||||
return;
|
||||
}
|
||||
const documentRef = globalThis.document;
|
||||
if (!documentRef?.body) return;
|
||||
panel = _build(documentRef);
|
||||
documentRef.body.append(panel);
|
||||
stopLocale = onLocaleChange(_onLocaleChange);
|
||||
_syncZoomButton();
|
||||
_syncStatus();
|
||||
}
|
||||
|
||||
/** Closing the panel hands the joints back, so no manual pose lingers. */
|
||||
function _removePanel() {
|
||||
if (!panel) return;
|
||||
panel.remove();
|
||||
panel = null;
|
||||
zoomButton = null;
|
||||
stopLocale?.();
|
||||
stopLocale = null;
|
||||
statusLine = null;
|
||||
shownSunlit = undefined;
|
||||
_stopZoom();
|
||||
_automatic();
|
||||
_stopRendering();
|
||||
}
|
||||
|
||||
// A language change rebuilds the panel in the new language. It comes back
|
||||
// collapsed and on Automatic, as on a fresh selection.
|
||||
function _onLocaleChange() {
|
||||
if (!panel) return;
|
||||
_removePanel();
|
||||
_syncIssCommand();
|
||||
}
|
||||
|
||||
function _destroyIssCommand() {
|
||||
_removePanel();
|
||||
}
|
||||
|
||||
return { _syncIssCommand, _destroyIssCommand };
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
ISS_COMMAND_ZOOM_RANGE_M,
|
||||
issCommandFastOrbit,
|
||||
issCommandShouldShow,
|
||||
issCommandZoomStep,
|
||||
} from './issCommand.js';
|
||||
import { ISS_NORAD } from './policy.js';
|
||||
|
||||
test('the panel shows only while the ISS is selected, layer on, Cockpit off', () => {
|
||||
const base = { enabled: true, trackedNorad: ISS_NORAD, cockpitHeld: false };
|
||||
assert.equal(issCommandShouldShow(base), true);
|
||||
assert.equal(issCommandShouldShow({ ...base, enabled: false }), false);
|
||||
assert.equal(issCommandShouldShow({ ...base, trackedNorad: 20580 }), false);
|
||||
assert.equal(issCommandShouldShow({ ...base, trackedNorad: null }), false);
|
||||
assert.equal(issCommandShouldShow({ ...base, cockpitHeld: true }), false);
|
||||
});
|
||||
|
||||
test('the zoom eases in to its range and stops there, never past it', () => {
|
||||
let distance = 726_000;
|
||||
let steps = 0;
|
||||
for (; steps < 400; steps++) {
|
||||
const step = issCommandZoomStep(distance);
|
||||
if (!step) break;
|
||||
assert.ok(step > 0 && step < distance - ISS_COMMAND_ZOOM_RANGE_M);
|
||||
distance -= step;
|
||||
}
|
||||
assert.ok(steps < 120); // under two seconds at 60 frames a second
|
||||
assert.ok(distance >= ISS_COMMAND_ZOOM_RANGE_M);
|
||||
assert.ok(distance <= ISS_COMMAND_ZOOM_RANGE_M * 1.02 + 1e-6);
|
||||
// Already closer: nothing to do, and it never pushes the camera back out.
|
||||
assert.equal(issCommandZoomStep(180), 0);
|
||||
});
|
||||
|
||||
test('the fast orbit turns the Sun once per lap, part of it in shadow', () => {
|
||||
const start = issCommandFastOrbit(0);
|
||||
assert.ok(Math.abs(Math.hypot(...start.sun) - 1) < 1e-9);
|
||||
assert.equal(start.sunlit, true);
|
||||
assert.equal(issCommandFastOrbit(20_000).sunlit, false); // half a lap: below
|
||||
const lap = issCommandFastOrbit(40_000);
|
||||
lap.sun.forEach((v, i) => assert.ok(Math.abs(v - start.sun[i]) < 1e-9));
|
||||
});
|
||||
|
||||
test('the zoom is offered only from far away', async () => {
|
||||
const { ISS_COMMAND_FAR_M, issCommandOffersZoom } =
|
||||
await import('./issCommand.js');
|
||||
assert.equal(issCommandOffersZoom(726_000), true);
|
||||
assert.equal(issCommandOffersZoom(ISS_COMMAND_FAR_M + 1), true);
|
||||
// Where the zoom itself stops, and anywhere closer, it is gone.
|
||||
assert.equal(issCommandOffersZoom(ISS_COMMAND_ZOOM_RANGE_M * 1.02), false);
|
||||
assert.equal(issCommandOffersZoom(150), false);
|
||||
});
|
||||
|
||||
test('the status line says lit or in shadow, and nothing before the model is placed', async () => {
|
||||
const { issCommandStatusText } = await import('./issCommand.js');
|
||||
assert.equal(issCommandStatusText(null), '');
|
||||
assert.notEqual(issCommandStatusText(true), issCommandStatusText(false));
|
||||
assert.ok(issCommandStatusText(true).length > 0);
|
||||
assert.ok(issCommandStatusText(false).length > 0);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { onLocaleChange, t } from '../../i18n/index.js';
|
||||
import { ISS_LIVE_VIDEO_ID, ISS_NORAD } from './policy.js';
|
||||
|
||||
/**
|
||||
@@ -40,6 +40,37 @@ export function issLiveShouldShow({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drag a floating panel by its header, kept inside the window (as the Québec
|
||||
* player).
|
||||
* @param {HTMLElement} root
|
||||
* @param {HTMLElement} header
|
||||
*/
|
||||
export function makePanelDraggable(root, header) {
|
||||
header.addEventListener('pointerdown', (event) => {
|
||||
if (event.target.closest('button')) return;
|
||||
const rect = root.getBoundingClientRect();
|
||||
const offsetX = event.clientX - rect.left;
|
||||
const offsetY = event.clientY - rect.top;
|
||||
header.setPointerCapture?.(event.pointerId);
|
||||
const view = root.ownerDocument.defaultView;
|
||||
const move = (moveEvent) => {
|
||||
root.style.left = `${Math.max(0, Math.min(view.innerWidth - root.offsetWidth, moveEvent.clientX - offsetX))}px`;
|
||||
root.style.top = `${Math.max(0, Math.min(view.innerHeight - root.offsetHeight, moveEvent.clientY - offsetY))}px`;
|
||||
root.style.right = 'auto';
|
||||
root.style.bottom = 'auto';
|
||||
};
|
||||
const stop = () => {
|
||||
header.removeEventListener('pointermove', move);
|
||||
header.removeEventListener('pointerup', stop);
|
||||
header.removeEventListener('pointercancel', stop);
|
||||
};
|
||||
header.addEventListener('pointermove', move);
|
||||
header.addEventListener('pointerup', stop, { once: true });
|
||||
header.addEventListener('pointercancel', stop, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -49,51 +80,86 @@ export function createIssLive({ state: layerState, parts }) {
|
||||
let panel = null;
|
||||
let dismissed = false;
|
||||
let lastTracked = null;
|
||||
/** Rewrites the open panel's text in the current language. */
|
||||
let reword = null;
|
||||
/** Stops listening for language changes; set while the panel is open. */
|
||||
let stopLocale = null;
|
||||
|
||||
/**
|
||||
* The project's floating video window (the Québec CCTV player,
|
||||
* src/ui/quebecCctvOverlay.js): its `qci-` classes, a header that drags it,
|
||||
* × and Escape to close, the source's credit, the privacy note and a link
|
||||
* to the provider's page.
|
||||
*/
|
||||
function _build(documentRef) {
|
||||
const root = documentRef.createElement('section');
|
||||
root.className = 'iss-live-panel';
|
||||
root.className = 'qci-panel iss-live-panel';
|
||||
root.setAttribute('role', 'region');
|
||||
root.setAttribute('aria-label', t('ISS live video'));
|
||||
// Worded again on a language change, without restarting the player.
|
||||
const word = [];
|
||||
const worded = (apply) => {
|
||||
word.push(apply);
|
||||
apply();
|
||||
};
|
||||
worded(() => root.setAttribute('aria-label', t('ISS live video')));
|
||||
|
||||
const header = documentRef.createElement('header');
|
||||
header.className = 'iss-live-header';
|
||||
const title = documentRef.createElement('span');
|
||||
header.className = 'qci-header';
|
||||
const title = documentRef.createElement('strong');
|
||||
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 titleText = documentRef.createTextNode('');
|
||||
worded(() => (titleText.data = t('ISS LIVE · NASA')));
|
||||
title.append(dotMark, titleText);
|
||||
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'));
|
||||
worded(() => close.setAttribute('aria-label', t('Close ISS live video')));
|
||||
close.addEventListener('click', () => {
|
||||
dismissed = true;
|
||||
_syncIssLive();
|
||||
});
|
||||
header.append(title, link, close);
|
||||
header.append(title, close);
|
||||
|
||||
const frame = documentRef.createElement('div');
|
||||
frame.className = 'iss-live-frame';
|
||||
const iframe = documentRef.createElement('iframe');
|
||||
iframe.className = 'qci-live';
|
||||
iframe.src = issLiveEmbedUrl(ISS_LIVE_VIDEO_ID);
|
||||
iframe.title = t('Live views from the International Space Station (NASA)');
|
||||
worded(
|
||||
() =>
|
||||
(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);
|
||||
const credit = documentRef.createElement('p');
|
||||
credit.className = 'qci-credit';
|
||||
credit.textContent = 'NASA · YouTube'; // i18n-ignore: provider names
|
||||
const note = documentRef.createElement('p');
|
||||
note.className = 'qci-note';
|
||||
worded(
|
||||
() =>
|
||||
(note.textContent = t(
|
||||
'Video plays from YouTube, which sees your IP address.',
|
||||
)),
|
||||
);
|
||||
const link = documentRef.createElement('a');
|
||||
link.href = issLiveWatchUrl(ISS_LIVE_VIDEO_ID);
|
||||
link.target = '_blank';
|
||||
link.rel = 'noopener noreferrer';
|
||||
worded(() => (link.textContent = t('Open on YouTube')));
|
||||
reword = () => word.forEach((apply) => apply());
|
||||
|
||||
root.append(header, iframe, credit, note, link);
|
||||
root.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Escape') close.click();
|
||||
});
|
||||
makePanelDraggable(root, header);
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -124,12 +190,16 @@ export function createIssLive({ state: layerState, parts }) {
|
||||
if (!documentRef?.body) return;
|
||||
panel = _build(documentRef);
|
||||
documentRef.body.append(panel);
|
||||
stopLocale = onLocaleChange(() => reword?.());
|
||||
}
|
||||
|
||||
function _removePanel() {
|
||||
if (!panel) return;
|
||||
panel.remove(); // the player goes with it, so the stream stops
|
||||
panel = null;
|
||||
reword = null;
|
||||
stopLocale?.();
|
||||
stopLocale = null;
|
||||
}
|
||||
|
||||
/** Drop the panel and forget the selection (layer destroy). */
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { eciToGeodetic, gstime, propagate } from 'satellite.js';
|
||||
import { createIssArticulation } from './issArticulation.js';
|
||||
import {
|
||||
ISS_COMPANION_COARSE_M,
|
||||
ISS_COMPANION_RADIUS_M,
|
||||
ISS_COMPANION_SCAN_MS,
|
||||
ISS_CARD_CLEAR_M,
|
||||
ISS_MODEL_LOCAL_AXES,
|
||||
ISS_MODEL_MAX_DISTANCE_M,
|
||||
ISS_MODEL_MIN_PX,
|
||||
ISS_MODEL_NATIVE_SPAN,
|
||||
ISS_MODEL_URL,
|
||||
ISS_NORAD,
|
||||
ISS_ORBIT_HIDE_M,
|
||||
ISS_SPAN_M,
|
||||
} from './policy.js';
|
||||
|
||||
@@ -98,6 +105,8 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
let loading = false;
|
||||
let failed = false;
|
||||
let generation = 0;
|
||||
/** Turns the solar arrays and radiators by where the Sun is. */
|
||||
const articulation = createIssArticulation();
|
||||
const nearCondition = new Cesium.DistanceDisplayCondition(
|
||||
0,
|
||||
ISS_MODEL_MAX_DISTANCE_M,
|
||||
@@ -106,7 +115,15 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
ISS_MODEL_MAX_DISTANCE_M,
|
||||
Number.MAX_VALUE,
|
||||
);
|
||||
/** @type {Set<number>} Docked objects whose dots the model stands in for. */
|
||||
const handedCompanions = new Set();
|
||||
let lastCompanionScanMs = Number.NEGATIVE_INFINITY;
|
||||
/** Whether the ISS's orbit ring is hidden for the close-up. */
|
||||
let orbitHidden = false;
|
||||
const scratchPosition = new Cesium.Cartesian3();
|
||||
/** The station centre the model last rendered at (for the tracked card). */
|
||||
const visualPosition = new Cesium.Cartesian3();
|
||||
let visualValid = false;
|
||||
const scratchRotation = new Cesium.Matrix3();
|
||||
const scratchColumn = new Cesium.Cartesian3();
|
||||
|
||||
@@ -153,6 +170,17 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
}
|
||||
}
|
||||
|
||||
/** An object's inertial position at `date`, km, or null. */
|
||||
function _temeKm(satrec, date) {
|
||||
if (!satrec) return null;
|
||||
try {
|
||||
const position = propagate(satrec, date)?.position;
|
||||
return position && typeof position !== 'boolean' ? position : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Leave the near range to the model: the dots draw only beyond it. */
|
||||
function _handOverDots() {
|
||||
const point = layerState._points.get(ISS_NORAD);
|
||||
@@ -166,31 +194,119 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
dot.distanceDisplayCondition = farCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Objects docked to the ISS (Nauka, a Soyuz, a Dragon…) have dots of their
|
||||
* own at the station's position. Near the model they are part of it, and
|
||||
* their dots, moved only a few times a second, jump across the model at
|
||||
* 7.6 km/s. While the model shows, their dots draw only beyond its range
|
||||
* too. Rescanned once a second: a vehicle that undocks gets its dot back,
|
||||
* and a catalog rebuild's new dots are picked up.
|
||||
* @param {number} nowMs
|
||||
*/
|
||||
function _handOverCompanions(nowMs) {
|
||||
if (nowMs - lastCompanionScanMs < ISS_COMPANION_SCAN_MS) return;
|
||||
lastCompanionScanMs = nowMs;
|
||||
const issPosition = layerState._points.get(ISS_NORAD)?.position;
|
||||
// The dots are placed at different moments (far apart with the clock sped
|
||||
// up), so their spacing only rules out what is nowhere near. Whether an
|
||||
// object is docked is read from both orbits at one instant.
|
||||
const date = new Date(layerState.now());
|
||||
const issTeme = _temeKm(layerState._catalog.get(ISS_NORAD)?.satrec, date);
|
||||
if (!issPosition || !issTeme) return;
|
||||
for (const [noradId, point] of layerState._points) {
|
||||
if (noradId === ISS_NORAD || !point?.position) continue;
|
||||
const entry = layerState._catalog.get(noradId);
|
||||
if (entry?.group === 'dense') continue;
|
||||
let docked = false;
|
||||
if (
|
||||
Cesium.Cartesian3.distance(point.position, issPosition) <=
|
||||
ISS_COMPANION_COARSE_M
|
||||
) {
|
||||
const teme = _temeKm(entry?.satrec, date);
|
||||
docked =
|
||||
Boolean(teme) &&
|
||||
Math.hypot(
|
||||
teme.x - issTeme.x,
|
||||
teme.y - issTeme.y,
|
||||
teme.z - issTeme.z,
|
||||
) *
|
||||
1000 <=
|
||||
ISS_COMPANION_RADIUS_M;
|
||||
}
|
||||
if (docked) {
|
||||
point.distanceDisplayCondition = farCondition; // no-op when equal
|
||||
handedCompanions.add(noradId);
|
||||
} else if (handedCompanions.has(noradId)) {
|
||||
point.distanceDisplayCondition = undefined;
|
||||
handedCompanions.delete(noradId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Give docked objects their dots back at every distance. */
|
||||
function _releaseCompanions() {
|
||||
for (const noradId of handedCompanions) {
|
||||
const point = layerState._points.get(noradId);
|
||||
if (point) point.distanceDisplayCondition = undefined;
|
||||
}
|
||||
handedCompanions.clear();
|
||||
lastCompanionScanMs = Number.NEGATIVE_INFINITY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Up close the orbit ring (polyline chords, turned once a second) runs off
|
||||
* the model and jumps across it, so it is hidden there.
|
||||
* @param {boolean} near Camera within ISS_ORBIT_HIDE_M of the station.
|
||||
*/
|
||||
function _syncOrbitCloseUp(near) {
|
||||
const path = layerState._orbitPaths.get(ISS_NORAD);
|
||||
if (near) {
|
||||
if (path) path.primitive.show = false;
|
||||
orbitHidden = true;
|
||||
} else if (orbitHidden) {
|
||||
orbitHidden = false;
|
||||
// Back to the ring's own rules, unless the Cockpit holds it hidden.
|
||||
if (layerState._cockpitHiddenPath !== ISS_NORAD)
|
||||
parts.controls._syncIssOrbit?.();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-frame update from the layer's preRender tick.
|
||||
* @returns {void}
|
||||
*/
|
||||
function _updateIssModel() {
|
||||
visualValid = false;
|
||||
const show = _shouldShow();
|
||||
if (!show) {
|
||||
if (model) model.show = false;
|
||||
if (handedCompanions.size) _releaseCompanions();
|
||||
_syncOrbitCloseUp(false);
|
||||
return;
|
||||
}
|
||||
const point = layerState._points.get(ISS_NORAD);
|
||||
const camera = layerState._viewer?.camera;
|
||||
const cameraDistance =
|
||||
point?.position && camera
|
||||
? Cesium.Cartesian3.distance(camera.positionWC, point.position)
|
||||
: Number.POSITIVE_INFINITY;
|
||||
if (!model) {
|
||||
if (!loading && !failed && resolveAsset) _load();
|
||||
// The file is fetched only once the camera nears the model's range, so
|
||||
// a globe-wide view of the layer never downloads it.
|
||||
if (
|
||||
!loading &&
|
||||
!failed &&
|
||||
resolveAsset &&
|
||||
cameraDistance <= ISS_MODEL_MAX_DISTANCE_M * 1.5
|
||||
)
|
||||
_load();
|
||||
return;
|
||||
}
|
||||
_handOverDots();
|
||||
|
||||
const point = layerState._points.get(ISS_NORAD);
|
||||
const camera = layerState._viewer?.camera;
|
||||
_handOverCompanions(Date.now());
|
||||
_syncOrbitCloseUp(cameraDistance < ISS_ORBIT_HIDE_M);
|
||||
// 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
|
||||
) {
|
||||
if (cameraDistance > ISS_MODEL_MAX_DISTANCE_M * 1.5) {
|
||||
model.show = false;
|
||||
return;
|
||||
}
|
||||
@@ -236,6 +352,7 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
scratchPosition,
|
||||
);
|
||||
}
|
||||
Cesium.Cartesian3.clone(scratchPosition, visualPosition);
|
||||
const axes = issFlightAxes(
|
||||
scratchPosition,
|
||||
temeToEcefAxes(posVel.velocity, gmst),
|
||||
@@ -244,7 +361,7 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
model.show = false;
|
||||
return;
|
||||
}
|
||||
['x', 'y', 'z'].forEach((key, column) => {
|
||||
ISS_MODEL_LOCAL_AXES.forEach((key, column) => {
|
||||
scratchColumn.x = axes[key][0];
|
||||
scratchColumn.y = axes[key][1];
|
||||
scratchColumn.z = axes[key][2];
|
||||
@@ -260,14 +377,58 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
scratchPosition,
|
||||
model.modelMatrix,
|
||||
);
|
||||
articulation.update(model, date, scratchPosition, axes);
|
||||
model.show = true;
|
||||
visualValid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the tracked card should anchor: the station centre the model is
|
||||
* rendering at this frame, or null while the model is not drawn (the card
|
||||
* then keeps the dot's position). Up close the dot's cache can be a frame
|
||||
* ahead of the rendered model, ~130 m of orbit, which shook the card.
|
||||
* @returns {Cesium.Cartesian3|null}
|
||||
*/
|
||||
function _issVisualPosition() {
|
||||
if (!visualValid || !model?.show) return null;
|
||||
const camera = layerState._viewer?.camera;
|
||||
if (
|
||||
camera &&
|
||||
Cesium.Cartesian3.distance(camera.positionWC, visualPosition) >
|
||||
ISS_MODEL_MAX_DISTANCE_M
|
||||
)
|
||||
return null;
|
||||
return visualPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* How far the tracked card must stay from its anchor to clear the model, in
|
||||
* pixels, or null while the dot shows.
|
||||
*/
|
||||
function _issCardClearPx() {
|
||||
const position = _issVisualPosition();
|
||||
const viewer = layerState._viewer;
|
||||
const camera = viewer?.camera;
|
||||
const height = viewer?.scene?.canvas?.clientHeight;
|
||||
const fovy = camera?.frustum?.fovy;
|
||||
if (!position || !height || !fovy) return null;
|
||||
const distance = Cesium.Cartesian3.distance(camera.positionWC, position);
|
||||
if (!(distance > 0)) return null;
|
||||
const pixelsPerMeter = height / (2 * Math.tan(fovy / 2)) / distance;
|
||||
return Math.min(
|
||||
height * 0.45,
|
||||
Math.max(ISS_MODEL_MIN_PX * 0.35, ISS_CARD_CLEAR_M * pixelsPerMeter),
|
||||
);
|
||||
}
|
||||
|
||||
/** Drop the model (destroy or a fresh init); the next need reloads it. */
|
||||
function _destroyIssModel() {
|
||||
generation += 1;
|
||||
loading = false;
|
||||
failed = false;
|
||||
visualValid = false;
|
||||
articulation.reset();
|
||||
_releaseCompanions();
|
||||
_syncOrbitCloseUp(false);
|
||||
if (model) {
|
||||
const scene = layerState._viewer?.scene;
|
||||
if (scene && scene.primitives.contains(model))
|
||||
@@ -277,5 +438,18 @@ export function createIssModel({ state: layerState, parts, resolveAsset }) {
|
||||
}
|
||||
}
|
||||
|
||||
return { _updateIssModel, _destroyIssModel };
|
||||
/** Whether the model is standing in for this docked object's dot. */
|
||||
function _issStandsInFor(noradId) {
|
||||
return handedCompanions.has(noradId) && _issVisualPosition() !== null;
|
||||
}
|
||||
|
||||
return {
|
||||
_updateIssModel,
|
||||
_destroyIssModel,
|
||||
_issVisualPosition,
|
||||
_issCardClearPx,
|
||||
_issStandsInFor,
|
||||
/** The joint driver, for the command panel. */
|
||||
_issArticulation: articulation,
|
||||
};
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
temeToEcefAxes,
|
||||
} from './issModel.js';
|
||||
import {
|
||||
ISS_MODEL_CENTER_NATIVE,
|
||||
ISS_MODEL_LOCAL_AXES,
|
||||
ISS_MODEL_NATIVE_SPAN,
|
||||
ISS_MODEL_URL,
|
||||
ISS_NORAD,
|
||||
@@ -61,22 +63,53 @@ test('the model is the ISS by NORAD number, at its real 109 m span', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('the native span matches the shipped asset', () => {
|
||||
test('the native span and centre match 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 root = gltf.nodes[gltf.scenes[0].nodes[0]];
|
||||
const min = [Infinity, Infinity, Infinity];
|
||||
const max = [-Infinity, -Infinity, -Infinity];
|
||||
// Every node below the root rests untransformed (joint nodes included), so
|
||||
// each mesh's bounds are already in the root's frame.
|
||||
const visit = (index) => {
|
||||
const node = gltf.nodes[index];
|
||||
assert.equal(node.rotation ?? null, null);
|
||||
assert.equal(node.scale ?? null, null);
|
||||
assert.equal(node.translation ?? null, null);
|
||||
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));
|
||||
for (let i = 0; i < 3; i++) {
|
||||
min[i] = Math.min(min[i], accessor.min[i]);
|
||||
max[i] = Math.max(max[i], accessor.max[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.ok(Math.abs(maxX - minX - ISS_MODEL_NATIVE_SPAN) < 0.01);
|
||||
(node.children ?? []).forEach(visit);
|
||||
};
|
||||
root.children.forEach(visit);
|
||||
// The truss is the longest axis, glTF X.
|
||||
assert.ok(Math.abs(max[0] - min[0] - ISS_MODEL_NATIVE_SPAN) < 0.01);
|
||||
assert.ok(max[0] - min[0] > max[1] - min[1]);
|
||||
assert.ok(max[0] - min[0] > max[2] - min[2]);
|
||||
ISS_MODEL_CENTER_NATIVE.forEach((value, i) =>
|
||||
assert.ok(Math.abs((min[i] + max[i]) / 2 - value) < 0.01),
|
||||
);
|
||||
// The scene root moves that centre to the origin: minimumPixelSize scales
|
||||
// the model about its origin, so the far-range model stays centred.
|
||||
assert.deepEqual(
|
||||
root.translation.map((value, i) => value + ISS_MODEL_CENTER_NATIVE[i]),
|
||||
[0, 0, 0],
|
||||
);
|
||||
// NASA's own textures ship with it.
|
||||
assert.ok(gltf.textures.length > 0);
|
||||
});
|
||||
|
||||
test('the model axes are a proper rotation of the flight axes', () => {
|
||||
// A cyclic order of x, y, z keeps the frame right-handed (no mirroring).
|
||||
const order = ISS_MODEL_LOCAL_AXES.join('');
|
||||
assert.ok(['xyz', 'yzx', 'zxy'].includes(order));
|
||||
});
|
||||
|
||||
test('flight axes: orthonormal, z away from the Earth, x along the motion', () => {
|
||||
|
||||
@@ -134,6 +134,7 @@ export function createLifecycle({
|
||||
parts.issModel?._updateIssModel(); // off: hides the model
|
||||
parts.tracking._clearTracking();
|
||||
parts.issLive?._syncIssLive(); // off: closes the live video
|
||||
parts.issCommand?._syncIssCommand(); // off: closes the command panel
|
||||
parts.labels._syncIssOverlay();
|
||||
// Remove click handler + keydown listener + preRender propagation while disabled
|
||||
if (layerState._clickHandler) {
|
||||
@@ -177,6 +178,7 @@ export function createLifecycle({
|
||||
layerState._overlayHost.setVisible(ISS_OVERLAY_SOURCE_ID, false);
|
||||
parts.issModel?._destroyIssModel();
|
||||
parts.issLive?._destroyIssLive();
|
||||
parts.issCommand?._destroyIssCommand();
|
||||
if (layerState._pointCollection) {
|
||||
viewer.scene.primitives.remove(layerState._pointCollection);
|
||||
layerState._pointCollection = null;
|
||||
|
||||
@@ -21,7 +21,10 @@ 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.
|
||||
* Space Station (ISS) (D) (IGOAL)" from NASA 3D Resources, the station's
|
||||
* current configuration (Nauka, Prichal, Bishop, the roll-out solar arrays),
|
||||
* with NASA's own textures. The shipped file is that model reduced for the
|
||||
* web and put in one frame, in meters (public/models/README.md says how).
|
||||
*/
|
||||
export const ISS_MODEL_URL = '/models/iss.glb';
|
||||
|
||||
@@ -29,10 +32,28 @@ export const ISS_MODEL_URL = '/models/iss.glb';
|
||||
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.
|
||||
* The asset's span along its truss (glTF X, solar array to solar array) in
|
||||
* its own units, read from the file's accessors. The file is in meters.
|
||||
*/
|
||||
export const ISS_MODEL_NATIVE_SPAN = 25.614;
|
||||
export const ISS_MODEL_NATIVE_SPAN = 109;
|
||||
|
||||
/**
|
||||
* The station's bounding-box centre in the file's coordinates, whose origin is
|
||||
* NASA's (the middle of the S0 truss). The scene root is translated by minus
|
||||
* this, so the model's origin is the station's centre. That is what
|
||||
* minimumPixelSize scales about, so the enlarged far-range model stays
|
||||
* centred on the orbital position (and on the tracked card's leader).
|
||||
*/
|
||||
export const ISS_MODEL_CENTER_NATIVE = Object.freeze([0, -7.38, 0.001]);
|
||||
|
||||
/**
|
||||
* Which flight axis each of the model's local axes (Cesium's, after its glTF
|
||||
* axis correction: local X = glTF Z, Y = glTF X, Z = glTF Y) points along.
|
||||
* The file has the U.S. segment at +Z (forward), Kibo at +X (port) and the Z1
|
||||
* truss at +Y (zenith; the Cupola faces -Y), so: local X → along-track, local
|
||||
* Y → orbit normal, local Z → zenith.
|
||||
*/
|
||||
export const ISS_MODEL_LOCAL_AXES = Object.freeze(['x', 'y', 'z']);
|
||||
|
||||
/**
|
||||
* Within this camera distance the model replaces the dot; farther out the dot
|
||||
@@ -47,6 +68,38 @@ export const ISS_MODEL_MAX_DISTANCE_M = 1_500_000;
|
||||
*/
|
||||
export const ISS_MODEL_MIN_PX = 72;
|
||||
|
||||
/**
|
||||
* Objects within this distance of the ISS are docked to it (their element
|
||||
* sets put them within a few hundred meters); while the model shows, their
|
||||
* dots give way to it inside its range (issModel.js).
|
||||
*/
|
||||
export const ISS_COMPANION_RADIUS_M = 5_000;
|
||||
|
||||
/**
|
||||
* Dots are moved at different moments, so with the clock sped up a docked
|
||||
* object's dot can trail the ISS's by a long way. Only objects whose dots are
|
||||
* within this distance are checked orbit against orbit (issModel.js).
|
||||
*/
|
||||
export const ISS_COMPANION_COARSE_M = 3_000_000;
|
||||
|
||||
/** How often the docked set is rescanned, ms. */
|
||||
export const ISS_COMPANION_SCAN_MS = 1_000;
|
||||
|
||||
/**
|
||||
* Within this camera distance of the ISS its orbit ring is hidden. The ring is
|
||||
* drawn as ~230 km chords and turned with the Earth once a second, so up close
|
||||
* it runs metres to kilometres off the model and jumps; at the tracked view
|
||||
* (~726 km) and beyond it stays.
|
||||
*/
|
||||
export const ISS_ORBIT_HIDE_M = 50_000;
|
||||
|
||||
/**
|
||||
* The tracked card keeps clear of the model: its gap from the anchor is this
|
||||
* many meters of the station as drawn on screen (about its reach from its
|
||||
* centre in an oblique view), so up close the card sits beside the station, not on it.
|
||||
*/
|
||||
export const ISS_CARD_CLEAR_M = 40;
|
||||
|
||||
/**
|
||||
* NASA's official live stream from the ISS on YouTube ("Live High-Definition
|
||||
* Views from the International Space Station", channel @NASA), shown in a
|
||||
|
||||
@@ -236,6 +236,7 @@ export function createRendering({
|
||||
|
||||
// NASA's live video beside the card while the ISS is selected.
|
||||
parts.issLive?._syncIssLive();
|
||||
parts.issCommand?._syncIssCommand();
|
||||
|
||||
_updatePointFocus(now);
|
||||
|
||||
|
||||
@@ -389,11 +389,21 @@ export function createTracking({ state: layerState, services, parts, source }) {
|
||||
: t('DOCKED · {name}', { name: companions[0] }),
|
||||
);
|
||||
}
|
||||
// While the ISS model shows, the card keeps clear of it: the gap follows
|
||||
// the station's size on screen, in steps so the card is not republished
|
||||
// every frame.
|
||||
const clearPx =
|
||||
layerState._trackedNorad === ISS_NORAD
|
||||
? parts.issModel?._issCardClearPx?.()
|
||||
: null;
|
||||
// The overlay's gap is twice the anchor radius, so half the clearance.
|
||||
const anchorRadiusPx = clearPx ? Math.round(clearPx / 8) * 4 : null;
|
||||
const current = layerState._trackedEntity.gevLabelModel;
|
||||
// Compare the WHOLE detail array: comparing only `details[0]` swallowed any
|
||||
// change confined to the companions line, so the card would never republish.
|
||||
const unchanged =
|
||||
current?.title === title &&
|
||||
(current?.anchorRadiusPx ?? null) === anchorRadiusPx &&
|
||||
current?.details?.length === details.length &&
|
||||
details.every((line, index) => current.details[index] === line);
|
||||
if (unchanged) return;
|
||||
@@ -401,6 +411,7 @@ export function createTracking({ state: layerState, services, parts, source }) {
|
||||
title,
|
||||
details,
|
||||
accent: '#ffd84d',
|
||||
...(anchorRadiusPx ? { anchorRadiusPx, anchorRadiusScale: null } : {}),
|
||||
};
|
||||
refreshTrackedReadout(layerState._trackedEntity);
|
||||
}
|
||||
@@ -468,6 +479,10 @@ export function createTracking({ state: layerState, services, parts, source }) {
|
||||
layerState._trackedEntity.gevSelectionOrigin = origin;
|
||||
layerState._trackedEntity.gevTrackedId = `satellites:${noradId}`;
|
||||
layerState._trackedEntity.gevDisplayPosition = _trackedDisplayCached;
|
||||
// Up close the ISS is a 3D model: the card welds to where it is drawn.
|
||||
if (noradId === ISS_NORAD)
|
||||
layerState._trackedEntity.gevVisualPosition = () =>
|
||||
parts.issModel?._issVisualPosition?.() ?? null;
|
||||
_updateTrackedSatelliteLabelModel(initialPos?.altitude ?? null);
|
||||
|
||||
_emitAwarenessEvent('gev:awareness-subject-selected', {
|
||||
|
||||
Reference in new issue
Block a user