Move satellites every frame between SGP4 samples

Satellite points were propagated once a second and held still in between,
so while the world clock plays faster than real time they jumped: at
1 min/s, about 45 px once a second at globe scale.

Each SGP4 call now keeps a sample of the satellite's inertial position,
velocity, gravity and its rate of change (src/layers/satellites/motion.js).
Every frame each shown point is reckoned from its sample to the world time
and turned into the Earth-fixed frame by the sidereal angle, so points
glide at any play speed. Core satellites still take a fresh sample every
second, and at once when the world time is 30 s from it (fast play, a
seek), which keeps every point within about 10 m of SGP4. Starlink extras
take their first sample as they load and are resampled round-robin, more
per frame the faster time plays (up to 2,000 a frame); a point more than
two minutes from its sample waits for the next one. Hidden points are
moved when shown again, and the tracked satellite keeps its per-frame path.

Measured at globe scale: at 1 min/s points move on every frame, 0.4 px a
frame and at most 1.4 px (before: once a second, 45 px). With 11,880
satellites (Starlink on) the scene holds 60 fps, frames 16.7 ms median and
19.7 ms p95; reckoning costs 0.02 ms a frame for 1,342 points.
This commit is contained in:
Sameh Khamis committed 2026-11-14 23:18:28 -08:00
1 parent e4708a815d
commit e31de29ccc
11 files changed
+466 -60

No files matched your search

+67 -22
View File
@@ -1,12 +1,18 @@
import * as Cesium from 'cesium';
import { gstime } from 'satellite.js';
import { reckonEarthFixed, sampleOrbit } from './motion.js';
import {
ISS_NORAD,
ORBIT_REBAKE_MS,
ORBIT_RECKON_LIMIT_MS,
ORBIT_SAMPLE_HORIZON_MS,
POSITION_UPDATE_MS,
RING_ROTATION_MS,
} from './policy.js';
/** Scratch for a point's reckoned position. */
const _reckoned = new Cesium.Cartesian3();
export function createRendering({
state: layerState,
services,
@@ -158,40 +164,73 @@ export function createRendering({
}
/**
* Propagate all CORE satellite positions and update point primitives.
* (About 1,300 core satellites: ~840 measured at ≈ 1.6 ms/pass, so ≈ 2.5 ms,
* fine at the 1s/200ms cadence.) Dense extras are
* excluded: they refresh on the round-robin budget in _propagateDenseChunk.
* Take a fresh SGP4 sample of every CORE satellite (motion.js); the points
* move from these each frame in _reckonPoints. (About 1,300 core
* satellites: ~840 measured at ≈ 1.6 ms/pass, so ≈ 2.5 ms, fine at the
* 1s/200ms cadence.) Dense extras are excluded: they are sampled on the
* round-robin budget in _propagateDenseChunk.
* @returns {number} How many satellites were sampled.
*/
function _propagateAll() {
const now = new Date(layerState.now());
const nowMs = layerState.now();
let updated = 0;
for (const [noradId, sat] of layerState._catalog) {
for (const sat of layerState._catalog.values()) {
if (sat.group === 'dense') continue;
const pos = parts.orbits.propagatePosition(sat.satrec, now);
if (!pos) continue;
const cartesian = Cesium.Cartesian3.fromDegrees(
pos.longitude,
pos.latitude,
pos.altitude,
);
const point = layerState._points.get(noradId);
if (point) {
point.position = cartesian;
updated++;
}
if (_sample(sat, nowMs)) updated++;
}
return updated;
}
/**
* Sample one satellite's orbit at `atMs` into its reused sample.
* @returns {boolean} Whether SGP4 had a state for that time.
*/
function _sample(sat, atMs) {
const sample = sampleOrbit(sat.satrec, atMs, sat.orbitSample);
if (!sample) return false;
sat.orbitSample = sample;
return true;
}
/**
* Move every shown point to where its satellite is at the world time,
* reckoned from its last sample, so points glide every frame between
* samples instead of stepping once a second. A core sample more than
* ORBIT_SAMPLE_HORIZON_MS from the world time (time playing fast, or a
* seek) is taken again first; dense extras are resampled by their own
* round-robin. A hidden point is moved when it is shown again, and the
* tracked satellite is placed by its per-frame path.
* @param {number} nowMs World time, epoch ms.
*/
function _reckonPoints(nowMs) {
const gmst = gstime(new Date(nowMs));
for (const [noradId, point] of layerState._points) {
if (!point.show || noradId === layerState._trackedNorad) continue;
const sat = layerState._catalog.get(noradId);
if (!sat || sat.reckonedAtMs === nowMs) continue;
let sample = sat.orbitSample;
if (
sat.group !== 'dense' &&
(!sample || Math.abs(nowMs - sample[0]) > ORBIT_SAMPLE_HORIZON_MS)
)
sample = _sample(sat, nowMs) ? sat.orbitSample : null;
if (!sample || Math.abs(nowMs - sample[0]) > ORBIT_RECKON_LIMIT_MS)
continue;
point.position = reckonEarthFixed(sample, nowMs, gmst, _reckoned); // setter clones
sat.reckonedAtMs = nowMs;
}
}
/**
* Shared scene.preRender tick (single definition for init + enable):
* - core fleet propagation at 200ms-tracked / 1s-idle cadence,
* - dense extras on a per-frame round-robin budget,
* - core fleet SGP4 samples at 200ms-tracked / 1s-idle cadence,
* - dense extras sampled on a per-frame round-robin budget,
* - every point reckoned from its sample each frame (motion.js),
* - tracked satellite's point primitive per frame (WS-D2),
* - orbit ring GMST re-alignment every ~1s (WS-D1).
*/
@@ -213,7 +252,12 @@ export function createRendering({
layerState._lastPropagation = now;
}
if (layerState._params.showPoints) parts.catalog._propagateDenseChunk();
if (layerState._params.showPoints) {
const worldMs = layerState.now();
parts.catalog._propagateDenseChunk(worldMs - layerState._lastReckonMs);
layerState._lastReckonMs = worldMs;
_reckonPoints(worldMs);
}
// Keep the tracked dot on the per-frame epoch shared with label + camera —
// runs after _propagateAll so the per-frame sample wins over the 200ms one.
@@ -339,6 +383,7 @@ export function createRendering({
_updateOrbitPathRotations,
_hideOrbitPath,
_propagateAll,
_reckonPoints,
_preRenderTick,
_updatePointFocus,
applySatellitePointFocusDeemphasis,