Fix the card previews' review findings

- A route globe that cannot draw tells the card, which shows another view.
- A card opened before the model set has loaded waits for that load.
- The model turns at the same rate on any display, and holds still under
  reduced motion.
- A hidden cockpit view stops drawing.
- The route plane keeps the craft's latest position through the fly-in.
- Metric altitude graphs keep main's 0.5% change threshold.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-16 15:57:40 -08:00
1 parent 7b53427a28
commit efffe3005c
6 files changed
+76 -22

No files matched your search

+41 -13
View File
@@ -91,6 +91,8 @@ const SCAN_TURNS = 0.3;
const REVEAL_TURNS = 0.07;
/** How long (ms) the plain model holds after the reveal before a cycle ends. */
const HOLD_MS = 700;
/** How fast the model turns, in radians a millisecond (about 0.3 a second). */
const TURN_PER_MS = 0.0003;
// Model space, normalised so the craft reaches about 1.7 from its centre.
// u_reveal runs 0 to 2: from 0 to 1 the edge grows from the centre and
@@ -201,7 +203,13 @@ function modelPreview(
const pitch = Cesium.Math.toRadians(-18);
const ease = (x) => x * x * (3 - 2 * x);
const frame = () => {
turn += 0.005;
// Only time spent drawing counts: a hidden preview stops drawing.
const now = performance.now();
const drawn = now - lastFrame < 250 ? now - lastFrame : 0;
lastFrame = now;
// A steady turn whatever the display's refresh rate; still under
// reduced motion.
if (!still) turn += TURN_PER_MS * drawn;
const turns = (turn - first) / (2 * Math.PI);
// Where in the scan it is, and from that how far each reveal has gone.
const into = (turns % (PLAIN_TURNS + SCAN_TURNS)) - PLAIN_TURNS;
@@ -214,11 +222,7 @@ function modelPreview(
else reveal = 1;
}
const next = reveal > 0 && reveal < 2 ? 'scan' : 'plain';
// Only time spent drawing counts: a hidden preview stops drawing.
const now = performance.now();
const drawn = now - lastFrame < 250 ? now - lastFrame : 0;
cycleMs += drawn;
lastFrame = now;
// The cycle ends once the reveal back to the model has finished and
// the plain model has held a moment, never mid-reveal.
if (phase === 'scan' && next === 'plain') holdMs = 0;
@@ -267,6 +271,15 @@ function modelPreview(
model.errorEvent?.addEventListener?.(fail);
}, fail);
function move(atNow) {
const at = onRoute(from, to, atNow);
if (!widget || !at || !plane || flyingIn) return;
pose(plane, at);
if (flownLine) flownLine.polyline.positions = arc(from, at, 48);
if (aheadLine) aheadLine.polyline.positions = arc(at, to);
widget.scene.requestRender();
}
return {
setActive: (active) => loop.set(active),
update() {},
@@ -440,6 +453,8 @@ function routePreview(container, route, { onFailed = () => {} } = {}) {
let removeGrow = null;
/** True while the plane flies in from the origin; moves wait for it. */
let flyingIn = false;
/** The craft's latest position, kept through the fly-in and the load. */
let latest = route.at;
const pose = (entity, where) => {
const next = planePose(where, bearing(where, to));
@@ -545,6 +560,8 @@ function routePreview(container, route, { onFailed = () => {} } = {}) {
flown.polyline.positions = arc(from, at, 48);
removeGrow?.();
removeGrow = null;
// The craft may have moved on while the plane flew in.
move(latest);
}
};
removeGrow = scene.preRender.addEventListener(grow);
@@ -593,11 +610,20 @@ function routePreview(container, route, { onFailed = () => {} } = {}) {
layer.brightness = 0.55;
layer.saturation = 0.35;
layer.contrast = 1.1;
draw(route.at);
draw(latest);
},
() => widget && onFailed(),
);
function move(atNow) {
const at = onRoute(from, to, atNow);
if (!widget || !at || !plane || flyingIn) return;
pose(plane, at);
if (flownLine) flownLine.polyline.positions = arc(from, at, 48);
if (aheadLine) aheadLine.polyline.positions = arc(at, to);
widget.scene.requestRender();
}
return {
setActive: (active) => loop.set(active),
/**
@@ -606,17 +632,13 @@ function routePreview(container, route, { onFailed = () => {} } = {}) {
*/
update(next) {
if (!widget) return;
latest = next.at;
if (next.from?.code !== from.code || next.to?.code !== to.code) {
({ from, to } = next);
draw(next.at);
draw(latest);
return;
}
const at = onRoute(from, to, next.at);
if (!at || !plane || flyingIn) return;
pose(plane, at);
if (flownLine) flownLine.polyline.positions = arc(from, at, 48);
if (aheadLine) aheadLine.polyline.positions = arc(at, to);
widget.scene.requestRender();
move(latest);
},
destroy() {
removeGrow?.();
@@ -645,6 +667,7 @@ const MIN_EYE_M = 60;
*/
function cockpitPreview(container, craft, { onFailed = () => {} } = {}) {
let widget = null;
let loop = null;
let active = false;
let at = craft;
const place = () => {
@@ -683,6 +706,9 @@ function cockpitPreview(container, craft, { onFailed = () => {} } = {}) {
scene.requestRender(),
);
place();
// Hidden, it draws nothing at all, not even as tiles arrive.
loop = renderLoopSwitch(widget);
loop.set(active);
} catch {
onFailed();
return { setActive() {}, update() {}, destroy() {} };
@@ -698,6 +724,8 @@ function cockpitPreview(container, craft, { onFailed = () => {} } = {}) {
return {
setActive(next) {
active = Boolean(next);
if (!widget) return;
loop.set(active);
if (active) place();
},
/** While it shows, the view keeps up with the craft. */