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

+9
View File
@@ -538,6 +538,15 @@ export function fleetModelSet() {
return loaded;
}
/**
* The load a layer has started (resolving to the set), or null when none
* has: for a view that needs the set but does not fetch it itself.
* @returns {Promise<object>|null}
*/
export function fleetModelSetLoading() {
return loading;
}
/**
* Fetch the model set once for every layer: `catalog.json`, `types.json` and
* every GLB the catalog names, all up front, so no model is fetched while a
+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. */
+13 -6
View File
@@ -1,6 +1,6 @@
<script setup>
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { aircraftModelSpec, fleetModelSet } from '../../../data/fleetModels.js';
import { aircraftModelSpec, fleetModelSet, fleetModelSetLoading } from '../../../data/fleetModels.js';
import { t } from '../../../i18n/index.js';
import { useEntityCardStore } from '../../stores/entityCard.js';
import PreviewHud from './PreviewHud.vue';
@@ -50,21 +50,27 @@ const shown = computed(() => {
});
const pad = (n) => String(n).padStart(2, '0');
/** The fleet model's spec and bytes, or null before the set has loaded. */
function fleetModel(aircraft) {
const set = fleetModelSet();
/** The fleet model's spec and bytes, or null when it has none. */
function fleetModel(set, aircraft) {
if (!set || !aircraft) return null;
const spec = aircraftModelSpec(set, aircraft);
const gltf = set.bytes.get(spec.model);
return gltf ? { gltf, basePath: spec.url } : null;
}
function show() {
let showing = 0;
async function show() {
preview?.destroy();
preview = null;
phase.value = 'plain';
const asked = ++showing;
// A card opened before the Flights layer's model set has loaded waits for
// that load rather than giving up.
let set = fleetModelSet();
if (!set) set = await fleetModelSetLoading()?.catch(() => null);
if (asked !== showing) return;
const previews = store.previews();
const model = fleetModel(props.aircraft);
const model = fleetModel(set, props.aircraft);
if (!previews?.model || !model || !host.value) {
failed.value = true;
return;
@@ -99,6 +105,7 @@ watch(
(active) => preview?.setActive(active),
);
onBeforeUnmount(() => {
showing++;
clearInterval(cycle);
preview?.destroy();
preview = null;
+1 -1
View File
@@ -84,7 +84,7 @@ const graph = computed(() => {
const line = points.map(([px, py], index) => `${index ? 'L' : 'M'}${px.toFixed(2)} ${py.toFixed(2)}`).join(' ');
const moved = last.m - first.m;
const feetScale = !SHOW[props.unit];
const change = feetScale ? feet(last.m) - feet(first.m) : Math.abs(moved) >= Math.max(1, last.m * 0.0005) ? moved : 0;
const change = feetScale ? feet(last.m) - feet(first.m) : Math.abs(moved) >= Math.max(1, last.m * (props.unit === 'metric' ? 0.005 : 0.0005)) ? moved : 0;
const changeText = feetScale ? t('{n} ft', { n: number(Math.abs(change)) }) : shown(Math.abs(moved));
const minutes = Math.floor((last.at - first.at) / 60_000);
return {
+4 -2
View File
@@ -208,7 +208,8 @@ watch(
// Anything else gets a quiet placeholder with its icon and its headline
// figures until it has imagery of its own. Previews stay mounted so switching
// shows the next one at once.
const routeKnown = computed(() => Boolean(card.value?.route?.fromAt && card.value?.route?.toAt));
const routeFailed = ref(false);
const routeKnown = computed(() => Boolean(card.value?.route?.fromAt && card.value?.route?.toAt) && !routeFailed.value);
const modelFailed = ref(false);
const cockpitFailed = ref(false);
const hasPosition = computed(() => Number.isFinite(card.value?.lat) && Number.isFinite(card.value?.lon));
@@ -302,6 +303,7 @@ watch(
() => card.value?.key,
() => {
preview.value = null;
routeFailed.value = false;
modelFailed.value = false;
cockpitFailed.value = false;
clearTimeout(turnTimer);
@@ -358,7 +360,7 @@ watch(
<img :src="photo.src" :alt="t('Photo of {name}', { name: shownTitle })" v-on="{ error: onPhotoError }" />
<small v-if="photo.credit">{{ photo.credit }}</small>
</a>
<RouteGlobe v-if="routeKnown" :key="`route-${card.key}`" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'route' }" :active="activeFlightPreview === 'route'" :from="card.route.fromAt" :to="card.route.toAt" :at="{ lat: card.lat, lon: card.lon }" />
<RouteGlobe v-if="routeKnown" :key="`route-${card.key}`" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'route' }" :active="activeFlightPreview === 'route'" :from="card.route.fromAt" :to="card.route.toAt" :at="{ lat: card.lat, lon: card.lon }" @failed="routeFailed = true" />
<AircraftModelHero v-if="modelKnown" :key="card.key" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'model' }" :active="activeFlightPreview === 'model'" :aircraft="card.aircraftModel" :heading="card.heading || 0" :callouts="callouts" @failed="modelFailed = true" @cycle="showOtherView" />
<FlightCockpitView v-if="cockpitMade && cockpitKnown" :key="`cockpit-${card.key}`" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'cockpit' }" :active="activeFlightPreview === 'cockpit'" :lat="card.lat" :lon="card.lon" :altitude-m="card.altitudeM" :heading="card.heading" :speed-mps="card.speedMps" @failed="onCockpitFailed" />
<div v-if="cockpitKnown || (routeKnown && modelKnown) || (photoAvailable && (routeKnown || modelKnown))" class="entity-card__preview-switch" role="group" :aria-label="t('Preview')">
+8
View File
@@ -19,11 +19,19 @@ const props = defineProps({
/** Whether the tile is the one showing; a hidden one stops drawing. */
active: { type: Boolean, default: true },
});
const emit = defineEmits(['failed']);
const store = useEntityCardStore();
const host = ref(null);
const failed = ref(false);
let preview = null;
// A globe that cannot draw tells the card, which then shows another view.
watch(failed, (now) => {
if (!now) return;
preview?.destroy();
preview = null;
emit('failed');
});
const place = (p) => ({ code: p?.code || '', lat: Number(p?.lat), lon: Number(p?.lon) });
const at = () =>