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

+61
View File
@@ -11,6 +11,7 @@ import {
VEHICLE_MAX_FIX_AGE_MS,
} from './policy.js';
import { FLOOR_WARM_PER_POLL } from './policy.js';
import { fleetModelFakes } from '../../testSupport/fleetModelFakes.mjs';
import {
FUTURE_STAMP_TOLERANCE_MS,
ORDER_REJECTS_BEFORE_RESET,
@@ -66,6 +67,25 @@ function snapshot(
};
}
/** A camera's place and frame looking straight down from `altitude` over `at`. */
function lookingDown(at, altitude) {
const positionWC = Cesium.Cartesian3.fromDegrees(at.lon, at.lat, altitude);
const up = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
positionWC,
new Cesium.Cartesian3(),
);
return {
positionWC,
directionWC: Cesium.Cartesian3.negate(up, new Cesium.Cartesian3()),
upWC: Cesium.Cartesian3.UNIT_Z,
frustum: {
computeCullingVolume: () => ({
computeVisibility: () => Cesium.Intersect.INSIDE,
}),
},
};
}
/** A vehicle record as the proxy emits it, with its timestamp source resolved. */
function vehicle(id, lat, lon, atSeconds, extra = {}) {
return {
@@ -160,6 +180,9 @@ function harness(
east: at.lon + 0.1,
north: at.lat + 0.1,
},
// Fleet-model services (testSupport/fleetModelFakes.mjs), with a camera
// looking straight down for them; without them vehicles stay icons.
fleet = null,
} = {},
) {
const viewRect = { ...view };
@@ -220,6 +243,7 @@ function harness(
viewRect.north,
);
},
...(fleet ? lookingDown(at, altitude) : {}),
},
scene: {
canvas: { addEventListener() {}, removeEventListener() {} },
@@ -266,6 +290,7 @@ function harness(
const layer = createTransitLayer({
source,
services: {
...(fleet ? { fleet } : {}),
ground,
mesh: {
sampleMeshFloorCells(scene, points, options) {
@@ -4217,6 +4242,42 @@ test('a vehicle read again while nothing changed is the snapshot read before', a
assert.equal(app.layer.getSelectedVehicle(), moved);
});
test('a held vehicle draws no 3D model either; let go, its model draws again', async (t) => {
const models = await fleetModelFakes(t);
const app = harness(t, { fleet: models.fleet, altitude: 1_000 });
const key = await busRunningNorth(app);
const [entry] = app.vehicles();
assert.notEqual(entry.mode, 'unknown', 'a mode its model is chosen by');
// The throttled sweep runs; a model's load answers off the frame and the
// next frames place it.
const frames = async () => {
app.advance(250);
app.settle();
for (let i = 0; i < 8; i += 1) await Promise.resolve();
app.settle();
};
await frames();
assert.equal(models.drawn(key).length, 1, 'near the camera: its model');
assert.equal(entry.modelOwnsVisual, true);
assert.equal(entry.marker.show, false, 'its icon hands over');
assert.equal(app.layer.setCockpitSubject(key), true);
app.frame();
// The view's eye is inside the vehicle.
assert.equal(models.drawn(key).length, 0, 'no model');
assert.equal(entry.modelOwnsVisual, false);
assert.equal(entry.marker.show, false, 'and no icon');
await frames();
assert.equal(models.drawn(key).length, 0, 'not on a later frame either');
assert.equal(entry.marker.show, false);
assert.equal(app.layer.setCockpitSubject(null), true);
await frames();
assert.equal(models.drawn(key).length, 1, 'let go: its model again');
assert.equal(entry.modelOwnsVisual, true);
assert.equal(entry.marker.show, false);
});
test('selectedAtMs is the user’s selection time; a hold and a deselection leave none', async (t) => {
const app = harness(t);
const key = await busRunningNorth(app);