fix(rail, transit): a train or vehicle a first-person view holds draws no 3D model either, since the view's eye is inside it; let go, its model draws again

The fleet models (#1714) draw nearby trains and vehicles under the 3D toggle. A
held one now leaves out its model as it does its icon, as the Vessels layer does
for its bridge subject: its model item is hidden, and handing the visual back
to its icon keeps the icon hidden while held. Tests drive each layer with the
real fleet-model layer and a stubbed glTF loader; both fail without the fix.
This commit is contained in:
Denis Groshev committed 2026-11-13 16:43:50 +01:00
1 parent 546ac22708
commit 974023510f
12 files changed
+212 -17

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
// Fleet models for a layer test (fleetModelInstances.js): the project's model
// set loaded from public/, a DISPLAY 3D toggle that is on, and Cesium's glTF
// loader replaced by one that answers at once with a ready model, recorded.
import * as Cesium from 'cesium';
import { loadFleetModelSet } from '../data/fleetModels.js';
import { fetchPublicFile } from './fleetGlb.mjs';
/** A model policy whose eligibility is read again on every frame. */
export const FLEET_TEST_POLICY = Object.freeze({
altitudeCeilingM: 800_000,
minimumPixelSize: 16,
cap: 4,
capAll: 8,
addM: 5_000,
addAllM: 20_000,
keepM: 6_000,
keepAllM: 24_000,
intervalMs: 0,
});
/**
* Load the fleet set (once a process, as the app does) and fake the loader
* for this test. Call it before the layer's harness, which replaces `fetch`.
* @param {import('node:test').TestContext} t
* @returns {Promise<{fleet: object, created: object[],
* drawn: (id: string) => object[]}>} `fleet` for the layer's services;
* `drawn(id)` the models drawn for the vehicle `id` now.
*/
export async function fleetModelFakes(t) {
const info = console.info;
console.info = () => {};
try {
await loadFleetModelSet({ fetchImpl: fetchPublicFile });
} finally {
console.info = info;
}
const created = [];
t.mock.method(Cesium.Model, 'fromGltfAsync', async (options) => {
const model = {
...options,
ready: true,
show: false,
modelMatrix: new Cesium.Matrix4(),
destroyed: false,
destroy() {
this.destroyed = true;
},
isDestroyed() {
return this.destroyed;
},
update() {},
};
created.push(model);
return model;
});
return {
fleet: {
policy: FLEET_TEST_POLICY,
display: () => ({ models3d: true, models3dMode: 'proximity' }),
resolveAsset: (url) => url,
},
created,
drawn: (id) =>
created.filter(
(model) => model.id === id && !model.destroyed && model.show,
),
};
}
+26 -2
View File
@@ -12,6 +12,24 @@ import { publicRailCatalog } from '../data/railFeeds.js';
export const RAIL_HARNESS_T0 = 1_789_000_000_000;
export const BOSTON = Object.freeze({ lat: 42.3601, lon: -71.0589 });
/** A camera's frame looking straight down from `altitude` over `at`. */
function lookingDown(at, altitude) {
const position = Cesium.Cartesian3.fromDegrees(at.lon, at.lat, altitude);
const up = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
position,
new Cesium.Cartesian3(),
);
return {
directionWC: Cesium.Cartesian3.negate(up, new Cesium.Cartesian3()),
upWC: Cesium.Cartesian3.UNIT_Z,
frustum: {
computeCullingVolume: () => ({
computeVisibility: () => Cesium.Intersect.INSIDE,
}),
},
};
}
/** A train as the rail proxy sends it. */
export function railTrain(id, lat, lon, extra = {}) {
return {
@@ -64,7 +82,7 @@ const headersOf = (values = {}) => ({
* catalog?: object[]|Promise<object[]>|Function|false,
* ground?: object,
* stops?: object|null, scheduleStops?: boolean,
* paths?: Record<string, object>|null}} [options]
* paths?: Record<string, object>|null, fleet?: object|null}} [options]
* `ground`: a floor service in place of the always-cold stub; `catalog`:
* the server's feed catalog (it may list fewer feeds than are bundled; a
* promise answers when it settles, a function is called per request and
@@ -74,7 +92,9 @@ const headersOf = (values = {}) => ({
* layer's own provider, its schedule tier, in its place;
* `paths`: feed id → the path pack the proxy serves, or a
* failure status it answers with (404 for any other feed; without it the
* source has no path route at all).
* source has no path route at all); `fleet`: the fleet-model services
* (testSupport/fleetModelFakes.mjs), with a camera that looks straight
* down for them (none by default: trains stay icons).
*/
export function railLayerHarness(
t,
@@ -86,6 +106,7 @@ export function railLayerHarness(
stops = null,
scheduleStops = false,
paths = null,
fleet = null,
} = {},
) {
const T0 = RAIL_HARNESS_T0;
@@ -179,6 +200,8 @@ export function railLayerHarness(
cancelFlight() {
this.flightsCancelled += 1;
},
// What the fleet models' eligibility reads: a camera looking down.
...(fleet ? lookingDown(at, altitude) : {}),
},
scene: {
canvas: { addEventListener() {}, removeEventListener() {} },
@@ -308,6 +331,7 @@ export function railLayerHarness(
cachedGroundFloor: () => null,
warmGroundFloor() {},
},
...(fleet ? { fleet } : {}),
camera: {
framing: WORLD_FOCUS_FRAMING.train,
requestWorldFocus(detail) {