Merge upstream main into feat/iss-3d-model

Translation files: kept both sides' new keys. public/models/README.md:
main's procedural fleet text, with a section for NASA's ISS model, the
one model outside the fleet set; DATA_SOURCES.md notes that exception.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Itallo BrandãoandClaude Opus 5.5 committed 2026-11-13 23:12:29 -03:00
commit becdbc9412
256 files changed
+10406 -2821

No files matched your search

-51
View File
@@ -467,54 +467,3 @@ export const CLASS_SCALE_2D = {
bizjet: 0.72,
uav: 0.75,
};
/** 3D model scale multipliers — clamped [0.75, 1.45] while every class shares
* the single airplane.glb (a jet mesh at C172 scale reads wrong). Widen when
* real per-class models land in CLASS_MODEL_URL. */
export const CLASS_SCALE_3D = {
light: 0.75,
glider: 0.75,
turboprop: 0.85,
airliner: 1.0,
widebody: 1.3,
quadjet: 1.45,
helicopter: 0.8,
fastjet: 0.8,
bizjet: 0.8,
uav: 0.8,
};
/** Per-class glTF — all the shared airplane today; drop real assets in here.
* NOTE for future models: each asset may need its own heading offset (the
* shared GLB uses MODEL_HEADING_OFFSET_DEG = 180 in both layers). */
export const CLASS_MODEL_URL = {
light: '/models/airplane.glb',
glider: '/models/airplane.glb',
turboprop: '/models/airplane.glb',
airliner: '/models/airplane.glb',
widebody: '/models/airplane.glb',
quadjet: '/models/airplane.glb',
helicopter: '/models/airplane.glb',
fastjet: '/models/airplane.glb',
bizjet: '/models/airplane.glb',
uav: '/models/airplane.glb',
};
/** Real per-class GLBs (2026-08-15 Hangar fleet, owner picks; CC-BY 4.0 —
* provenance in public/models/README.md). Every asset is vertex-baked to the
* airplane.glb convention: Y-up, X = length, Z = span, nose −X (so the layers'
* MODEL_HEADING_OFFSET_DEG = 180 applies unchanged), origin at bbox centre,
* REAL-WORLD METERS (render at scale 1 — no MODEL_SCALE, no CLASS_SCALE_3D).
* bellyM = origin→lowest-vertex distance (grounded-model lift, replaces the
* airplane.glb MODEL_BELLY_OFFSET_NATIVE formula); radiusM = bounding-sphere
* radius in meters (pixel-size math). Values measured from the shipped GLBs —
* pinned by modelScale.test.mjs. Classes NOT listed (airliner, quadjet,
* glider, fastjet) still render the shared airplane.glb via CLASS_MODEL_URL. */
export const CLASS_MODEL_REAL = {
helicopter: { url: '/models/bell206.glb', bellyM: 1.66, radiusM: 8.24 },
light: { url: '/models/c172.glb', bellyM: 1.36, radiusM: 7.0 },
bizjet: { url: '/models/citation2.glb', bellyM: 2.86, radiusM: 11.24 },
uav: { url: '/models/mq9.glb', bellyM: 2.02, radiusM: 12.0 },
widebody: { url: '/models/b789.glb', bellyM: 7.81, radiusM: 44.08 },
turboprop: { url: '/models/atr72.glb', bellyM: 3.81, radiusM: 19.49 },
};
+2 -13
View File
@@ -1,7 +1,7 @@
// src/data/aircraftClass.test.mjs
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { classifyAircraft, CLASS_SCALE_2D, CLASS_SCALE_3D, CLASS_MODEL_URL, CLASS_MODEL_REAL } from './aircraftClass.js';
import { classifyAircraft, CLASS_SCALE_2D } from './aircraftClass.js';
test('type-code classification (military layer path)', () => {
assert.equal(classifyAircraft({ typeCode: 'F16' }), 'fastjet');
@@ -48,19 +48,8 @@ test('typeCode outranks category; unknown → airliner', () => {
assert.equal(classifyAircraft({ typeCode: null, category: 0 }), 'airliner');
});
test('scale/url tables cover every class', () => {
test('the icon scale table covers every class', () => {
for (const kind of ['light','glider','turboprop','airliner','widebody','quadjet','helicopter','fastjet','bizjet','uav']) {
assert.ok(Number.isFinite(CLASS_SCALE_2D[kind]), kind);
assert.ok(CLASS_SCALE_3D[kind] >= 0.75 && CLASS_SCALE_3D[kind] <= 1.45, kind);
assert.ok(typeof CLASS_MODEL_URL[kind] === 'string', kind);
}
});
test('CLASS_MODEL_REAL entries carry the fields the layers consume', () => {
for (const [kind, spec] of Object.entries(CLASS_MODEL_REAL)) {
assert.ok(spec.url.startsWith('/models/') && spec.url.endsWith('.glb'), kind);
assert.ok(spec.radiusM > 0 && spec.bellyM > 0, kind);
// every real-model class must also exist in the classifier tables
assert.ok(Number.isFinite(CLASS_SCALE_2D[kind]), kind);
}
});
+2 -2
View File
@@ -160,8 +160,8 @@ const BODIES = {
L -3,31 L -8,34 L -8,30 L -6,16
L -27,26 L -27,20 L -5,-8
C -4.6,-16 -4,-24 -3.5,-30 Z" fill="white" ${STROKE}/>`,
// 2026-08-15 Hangar additions: two NEW classes shipped with the real-model
// fleet (CLASS_MODEL_REAL). Same contract as the set above: 96×96 nose-up,
// 2026-08-15 additions: two NEW classes (bizjet, uav). Same contract as
// the set above: 96×96 nose-up,
// white fill, hairline stroke, tint-safe.
// Business jet — slender fuselage, modest swept wing, aft engines, T-tail.
bizjet: `
+5 -4
View File
@@ -6,9 +6,8 @@ import { AIRCRAFT_ENVIRONMENT_MAP_OPTIONS } from './aircraftModelLighting.js';
/**
* Every aircraft model drawn in the scene skips Cesium's dynamic environment
* map (a sky render and GPU readback per model). The preload calls only warm
* the glTF cache and are never added to the scene, so they are left out:
* drawn models are the calls that set a minimum pixel size.
* map (a sky render and GPU readback per model). Drawn models are the calls
* that set a minimum pixel size.
*/
const SOURCES = [
{
@@ -36,7 +35,9 @@ test('the shared option turns the dynamic environment map off', () => {
for (const { name, source } of SOURCES) {
test(`${name}: every drawn aircraft model skips the dynamic environment map`, () => {
const calls = [
...source.matchAll(/(?:fromGltfAsync|loadModel)\(\{([\s\S]*?)\}\)/g),
...source.matchAll(
/(?:fromGltfAsync\(|loadModel\(|(?:_createModel|createFleetModel)\(\s*\w+,\s*)\{([\s\S]*?)\n\s*\}[,)]/g,
),
]
.map((match) => match[1])
.filter((options) => /\bminimumPixelSize:/.test(options));
+58
View File
@@ -258,3 +258,61 @@ test('partial static data keeps newer live metadata ahead of the old static cach
assert.equal(rowFor(mmsi).type, '80');
assert.equal(rowFor(mmsi).destination, 'HAMBURG');
});
// A static report's dimensions are the antenna's distances to bow (A), stern
// (B), port (C) and starboard (D): length A+B, beam C+D. Zero is AIS's "not
// available", so a vessel reporting none has no size, not a size of zero.
test('a static report gives a vessel its hull length and beam', () => {
ingestAisStreamEnvelope(positionReport('636019825', { Sog: 14 }));
ingestAisStreamEnvelope({
MessageType: 'ShipStaticData',
Message: {
ShipStaticData: {
UserID: 636019825,
Name: 'EVER GIVEN',
Type: 70,
Dimension: { A: 330, B: 70, C: 30, D: 29 },
},
},
MetaData: { MMSI: '636019825' },
});
const row = rowFor('636019825');
assert.equal(row.length, 400);
assert.equal(row.beam, 59);
ingestAisStreamEnvelope(positionReport('636019826', { Sog: 3 }));
ingestAisStreamEnvelope({
MessageType: 'ShipStaticData',
Message: {
ShipStaticData: {
UserID: 636019826,
Type: 52,
Dimension: { A: 0, B: 0, C: 0, D: 0 },
},
},
MetaData: { MMSI: '636019826' },
});
assert.equal(rowFor('636019826').length, null);
assert.equal(rowFor('636019826').beam, null);
});
test('a Class B report carries its dimensions in part B', () => {
ingestAisStreamEnvelope(positionReport('244000777', { Sog: 6 }));
ingestAisStreamEnvelope({
MessageType: 'StaticDataReport',
Message: {
StaticDataReport: {
UserID: 244000777,
ReportB: {
Valid: true,
ShipType: 37,
Dimension: { A: 8, B: 4, C: 2, D: 2 },
},
},
},
MetaData: { MMSI: '244000777' },
});
const row = rowFor('244000777');
assert.equal(row.length, 12);
assert.equal(row.beam, 4);
});
+1
View File
@@ -29,6 +29,7 @@ export const writeCalibrationStoreV2 = layer.writeCalibrationStoreV2;
export const deriveCalBadge = layer.deriveCalBadge;
export const computeFrustumGeometry = layer.computeFrustumGeometry;
export const activationProbeClampRange = layer.activationProbeClampRange;
export const flatGroundAxisDistance = layer.flatGroundAxisDistance;
export const frameSignatureFromPixels = layer.frameSignatureFromPixels;
export const _createCctvProjectionPlaneForTest =
layer._createCctvProjectionPlaneForTest;
+12
View File
@@ -35,6 +35,7 @@ import cctvLayer, {
_pushAmbientCardEntriesForTest,
_setCctvOverlayHostForTest,
activationProbeClampRange,
flatGroundAxisDistance,
bindCctvWorldClickGesture,
clearProbeClampOnDeactivation,
computeFrustumGeometry,
@@ -655,6 +656,17 @@ test('activation obstruction clamp uses the field-derived 12 m floor', () => {
assert.equal(activationProbeClampRange(210, 250), null);
});
test('on a globe map the axis ends on flat ground at the mount ground', () => {
// A 24 m mount pitched 30° down meets the ground 48 m along its axis.
assert.ok(Math.abs(flatGroundAxisDistance(24, -30) - 48) < 1e-9);
// The default 700 m range then clamps just short of that, not 700 m out.
const clamp = activationProbeClampRange(700, flatGroundAxisDistance(24, -30));
assert.ok(Math.abs(clamp - 44) < 1e-9);
assert.equal(flatGroundAxisDistance(24, 0), null);
assert.equal(flatGroundAxisDistance(24, 10), null);
assert.equal(flatGroundAxisDistance(0, -30), null);
});
test('deactivation clears the probe clamp and restores nominal frustum geometry', () => {
const record = {
camera: { ...UNCLAMPED_CAMERA },
+5 -3
View File
@@ -28,11 +28,13 @@ for (const layer of LAYERS) {
const source = readLayerSource(layer.path);
test(`${layer.name}: every GLB creation bypasses the tile-contended frame-spread queue`, () => {
const calls = [...source.matchAll(/Cesium\.Model\.fromGltfAsync\(\{([\s\S]*?)\}\)/g)];
assert.ok(calls.length >= 3, `expected fleet, tracked, and preload model calls; found ${calls.length}`);
const calls = [...source.matchAll(/_createModel\(\s*\w+,\s*\{([\s\S]*?)\n\s*\}\)/g)];
assert.ok(calls.length >= 2, `expected fleet and tracked model calls; found ${calls.length}`);
assert.doesNotMatch(source, /Cesium\.Model\.fromGltfAsync\(/,
'every model is built from the loaded fleet set through _createModel');
for (const [index, call] of calls.entries()) {
assert.match(call[1], /\basynchronous:\s*false\b/,
`Model.fromGltfAsync call ${index + 1} must keep bounded GLB readiness independent of tile jobs`);
`_createModel call ${index + 1} must keep bounded GLB readiness independent of tile jobs`);
}
});
+7
View File
@@ -141,6 +141,13 @@ export const DATA_CREDITS = [
'<a href="https://www.planespotters.net" target="_blank" rel="noopener">Planespotters.net</a> ' +
'· each photo is © its photographer, credited beside it',
},
{
key: 'openvesselphotos',
html:
'Vessel photos: ' +
'<a href="https://openvesselphotos.org" target="_blank" rel="noopener">Open Vessel Photos</a> ' +
"· each photo keeps its author's open licence, credited beside it",
},
{
key: 'aisstream',
html:
+7
View File
@@ -51,6 +51,13 @@ test('Planespotters is credited with a plain followable link', () => {
assert.doesNotMatch(credit.html, /nofollow/);
});
test('Open Vessel Photos is credited with a plain followable link', () => {
const credit = DATA_CREDITS.find((entry) => entry.key === 'openvesselphotos');
assert.ok(credit, 'the selected vessel photos come from Open Vessel Photos');
assert.match(credit.html, /href="https:\/\/openvesselphotos\.org"/);
assert.doesNotMatch(credit.html, /nofollow/);
});
test('the UCS Satellite Database is acknowledged with its version and webpage', () => {
// UCS database manual, section 3: references name the version (the Excel
// file's name) and link www.ucsusa.org/satellite_database.
+462
View File
@@ -0,0 +1,462 @@
import * as Cesium from 'cesium';
import { horizonOccluder } from './iconOrientation.js';
import { selectModelEligible } from './modelEligibility.js';
import { AIRCRAFT_ENVIRONMENT_MAP_OPTIONS } from './aircraftModelLighting.js';
import { fleetModelSet } from './fleetModels.js';
/**
* Cesium models of the procedural fleet set (`fleetModels.js`), and the
* icon-to-model handoff the Vessels, Transit and Rail layers share.
*/
/** Every fleet GLB is nose -X: opposite Cesium's heading 0. */
export const FLEET_HEADING_OFFSET_DEG = 180;
/**
* Create a Cesium Model of `spec` from the up-front loaded bytes, so no model
* is fetched mid-session. Each model keeps its own URL as its base path: the
* glTF cache keys by it, and two models sharing one would share geometry.
* Rejects when the set is not loaded or the model's GLB failed to load.
* @param {object} spec `fleetModelSpec`.
* @param {object} options Cesium `Model.fromGltfAsync` options.
* @param {{resolveAsset?: (url: string) => string, set?: object|null,
* load?: (options: object) => Promise<object>}} [context]
* @returns {Promise<object>} Cesium Model.
*/
export function createFleetModel(
spec,
options,
{
resolveAsset = (url) => url,
set = fleetModelSet(),
// Looked up when called, so a replaced `fromGltfAsync` (tests) is the one used.
load = (o) => Cesium.Model.fromGltfAsync(o),
} = {},
) {
const bytes = set?.bytes?.get(spec?.model);
if (!bytes)
return Promise.reject(new Error(`fleet model ${spec?.model} not loaded`));
return load({
environmentMapOptions: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS,
...options,
gltf: bytes,
basePath: resolveAsset(spec.url),
});
}
const tintShaders = new Map();
/** Models under the NVG/FLIR styles render unlit, as aircraft models do. */
const IR_UNLIT_SHADER = new Cesium.CustomShader({
lightingModel: Cesium.LightingModel.UNLIT,
});
/**
* The custom shader that paints a route colour where a transit model's
* `_TINT` vertex attribute marks it: drawn colour = vertex colour ×
* mix(1, colour, _TINT). One shader per colour, shared by every model drawn in
* it (Cesium compiles the program once; uniforms are per shader).
* @param {Cesium.Color} color
* @returns {Cesium.CustomShader}
*/
export function fleetTintShader(color) {
const key = color.toCssHexString();
let shader = tintShaders.get(key);
if (!shader) {
shader = new Cesium.CustomShader({
mode: Cesium.CustomShaderMode.MODIFY_MATERIAL,
uniforms: {
u_routeColor: {
type: Cesium.UniformType.VEC3,
value: new Cesium.Cartesian3(color.red, color.green, color.blue),
},
},
fragmentShaderText: `
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
vec3 route = czm_srgbToLinear(u_routeColor);
material.diffuse *= mix(vec3(1.0), route, fsInput.attributes.tint);
}
`,
});
tintShaders.set(key, shader);
}
return shader;
}
/**
* Write the world matrix of a fleet model standing at `position` heading
* `headingDeg` (clockwise from north) into `result`, stretched by the spec's
* beam and height scales relative to its length scale (a Model's own `scale`
* carries the length scale, so its minimum pixel size still applies).
* @param {Cesium.Cartesian3} position
* @param {number} headingDeg
* @param {object} spec `fleetModelSpec`.
* @param {Cesium.Matrix4} result
* @param {Cesium.HeadingPitchRoll} scratchHpr
* @returns {Cesium.Matrix4}
*/
export function fleetModelMatrix(
position,
headingDeg,
spec,
result,
scratchHpr,
) {
scratchHpr.heading = Cesium.Math.toRadians(
(headingDeg || 0) + FLEET_HEADING_OFFSET_DEG,
);
scratchHpr.pitch = 0;
scratchHpr.roll = 0;
Cesium.Transforms.headingPitchRollToFixedFrame(
position,
scratchHpr,
Cesium.Ellipsoid.WGS84,
undefined,
result,
);
const [sx, sy, sz] = spec.scaleXYZ;
if (sx > 0 && (sy !== sx || sz !== sx)) {
// Cesium's glTF axis correction puts the model's length on local Y, its
// beam on local X and its height on local Z.
scratchScale.x = sy / sx;
scratchScale.y = 1;
scratchScale.z = sz / sx;
Cesium.Matrix4.multiplyByScale(result, scratchScale, result);
}
return result;
}
const scratchScale = new Cesium.Cartesian3();
/**
* 3D models for one layer's vehicles under the DISPLAY rail's 3D toggle (the
* Flights layer's `models3d`/`models3dMode`), on the same rules the aircraft
* layers follow: models only below the camera altitude ceiling, for the
* nearest `cap` vehicles in the add/keep band, on-screen first. A vehicle's
* icon stays the visual until its model is loaded and placed; the layer reads
* `modelOwnsVisual` back from each item and hides that icon.
*
* Each frame the layer passes its vehicles as items:
* `{position, headingDeg, spec, tint, pickId, show, groundLiftM}`,
* `position` the point the model's origin stands on (the waterline, the road
* or rail top; the spec's `elevationM` is added here), `groundLiftM` any lift
* the layer's icon carries above that point (taken off again), `tint` a
* Cesium.Color for a tinted model's route colour (or null), `show` false to
* keep it hidden.
*
* Under the luminance-mapped NVG/FLIR styles (`irBoost`) models render
* unlit flat white, as aircraft models do. With `waterline`, each model is
* clipped at its origin's horizontal plane and only the part above it is
* drawn: a ship's hull below the waterline would otherwise show through a
* plain globe, which Cesium does not depth-test models against.
* @param {object} options
* @param {object} options.viewer Cesium viewer.
* @param {() => object|null} [options.display] `{models3d, models3dMode,
* irBoost}`.
* @param {object} options.policy `{altitudeCeilingM, minimumPixelSize,
* cap, capAll, addM, addAllM, keepM, keepAllM, intervalMs}`.
* @param {(url: string) => string} [options.resolveAsset]
* @param {(spec: object, options: object) => Promise<object>} [options.createModel]
* @param {boolean} [options.waterline] Clip each model at its waterline.
* @returns {object}
*/
export function createFleetModelLayer({
viewer,
display = () => null,
policy,
waterline = false,
resolveAsset = (url) => url,
createModel = (spec, options) =>
createFleetModel(spec, options, { resolveAsset }),
}) {
const collection = new Cesium.PrimitiveCollection();
viewer.scene.primitives.add(collection);
/** @type {Map<string, object>} id -> admitted model */
const models = new Map();
/** @type {Map<string, number>} id -> generation of an in-flight load */
const pending = new Map();
let generation = 0;
let destroyed = false;
let lastEligibilityAt = -Infinity;
let eligible = new Set();
let settling = 0;
/** Whether the models drawn now were built for the NVG/FLIR styles. */
let irBoost = false;
const scratchHpr = new Cesium.HeadingPitchRoll();
const scratchSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.ZERO, 1);
const scratchCarto = new Cesium.Cartographic();
const scratchPosition = new Cesium.Cartesian3();
function release(id) {
pending.delete(id);
const model = models.get(id);
if (!model) return;
models.delete(id);
if (!collection.isDestroyed()) collection.remove(model);
}
function releaseAll() {
for (const id of models.keys()) release(id);
pending.clear();
generation += 1;
}
function preferences() {
return display?.() || null;
}
function regime(prefs) {
if (!prefs?.models3d || !fleetModelSet()) return false;
const height = viewer.camera?.positionCartographic?.height ?? Infinity;
return height < policy.altitudeCeilingM;
}
function shaderFor(item) {
if (irBoost) return IR_UNLIT_SHADER;
return item.spec.tinted && item.tint
? fleetTintShader(item.tint)
: undefined;
}
/** The clipping that keeps a model's part above its waterline. */
function waterlineClipping() {
return new Cesium.ClippingPlaneCollection({
// The planes sit in the model matrix's frame: its origin is the
// waterline and its Z axis the local vertical, so the plane z = 0 with
// its normal up keeps the hull above the water.
planes: [new Cesium.ClippingPlane(Cesium.Cartesian3.UNIT_Z, 0)],
edgeWidth: 0,
});
}
async function ensure(id, item, cap) {
const key = item.spec.key;
const current = models.get(id);
if (current && current._gevSpecKey === key) return;
if (current) release(id);
if (pending.has(id) || models.size + pending.size >= cap) return;
const loadGeneration = generation;
pending.set(id, loadGeneration);
let model;
try {
model = await createModel(item.spec, {
asynchronous: false,
minimumPixelSize: policy.minimumPixelSize,
scale: item.spec.scale,
customShader: shaderFor(item),
...(irBoost
? {
color: Cesium.Color.WHITE,
colorBlendMode: Cesium.ColorBlendMode.MIX,
colorBlendAmount: 1,
}
: {}),
...(waterline ? { clippingPlanes: waterlineClipping() } : {}),
id: item.pickId ?? id,
});
} catch {
if (pending.get(id) === loadGeneration) pending.delete(id);
return;
}
const stale =
destroyed ||
pending.get(id) !== loadGeneration ||
generation !== loadGeneration ||
!eligible.has(id) ||
models.has(id);
if (pending.get(id) === loadGeneration) pending.delete(id);
if (stale) {
model.destroy?.();
return;
}
model.id = item.pickId ?? id;
model._gevSpecKey = key;
model._gevTint = item.spec.tinted && !irBoost ? item.tint : null;
model._gevIrBoost = irBoost;
// Admitted, not yet the visual: placement turns it on.
model.show = false;
collection.add(model);
models.set(id, model);
}
function refreshEligibility(items, prefs) {
const all = prefs.models3dMode === 'all';
const cap = all ? policy.capAll : policy.cap;
const addM = all ? policy.addAllM : policy.addM;
const keepM = all ? policy.keepAllM : policy.keepM;
const camera = viewer.camera;
const cameraPosition = camera.positionWC;
const cull = camera.frustum.computeCullingVolume(
cameraPosition,
camera.directionWC,
camera.upWC,
);
const candidates = [];
for (const [id, item] of items) {
if (!item.position || item.show === false || !item.spec) continue;
const distanceSq = Cesium.Cartesian3.distanceSquared(
cameraPosition,
item.position,
);
if (distanceSq > keepM * keepM) continue;
Cesium.Cartesian3.clone(item.position, scratchSphere.center);
candidates.push([
id,
distanceSq,
cull.computeVisibility(scratchSphere) !== Cesium.Intersect.OUTSIDE,
]);
}
candidates.sort((a, b) => a[1] - b[1]);
eligible = selectModelEligible(candidates, {
cap,
addDistSq: addM * addM,
isModeled: (id) => models.has(id),
});
for (const id of models.keys()) if (!eligible.has(id)) release(id);
for (const id of pending.keys()) if (!eligible.has(id)) release(id);
for (const id of eligible) void ensure(id, items.get(id), cap);
}
/** Where the model's origin stands: the item's point raised by the spec's elevation. */
function placement(item) {
const lift = (item.spec.elevationM || 0) - (item.groundLiftM || 0);
if (!lift) return item.position;
const carto = Cesium.Cartographic.fromCartesian(
item.position,
Cesium.Ellipsoid.WGS84,
scratchCarto,
);
if (!carto) return item.position;
return Cesium.Cartesian3.fromRadians(
carto.longitude,
carto.latitude,
carto.height + lift,
Cesium.Ellipsoid.WGS84,
scratchPosition,
);
}
return {
/** Ids whose model admission is current. */
get eligible() {
return eligible;
},
/**
* Per-frame pass: re-derive eligibility at the policy's cadence, then
* place every admitted model and hand each item's visual to its model
* only once the model is ready and placed (`item.modelOwnsVisual`).
* @param {Map<string, object>} items
* @param {number} nowMs
* @returns {boolean} Whether any model is drawn.
*/
frame(items, nowMs) {
if (destroyed) return false;
const prefs = preferences();
if (!regime(prefs)) {
settling = 0;
if (models.size || pending.size) releaseAll();
eligible = new Set();
for (const item of items.values()) item.modelOwnsVisual = false;
return false;
}
// A model's look under NVG/FLIR is set when it is built (a custom
// shader on a ready model does not take), so a style change rebuilds.
const boost = prefs.irBoost === true;
if (boost !== irBoost) {
releaseAll();
irBoost = boost;
lastEligibilityAt = -Infinity;
}
if (nowMs - lastEligibilityAt >= policy.intervalMs) {
lastEligibilityAt = nowMs;
refreshEligibility(items, prefs);
}
const occluder = horizonOccluder(viewer.camera);
let drawn = false;
settling = pending.size;
for (const [id, item] of items) {
const model = models.get(id);
item.modelOwnsVisual = false;
if (!model) continue;
if (
!item.position ||
item.show === false ||
!occluder.isPointVisible(item.position)
) {
model.show = false;
continue;
}
if (item.spec.key !== model._gevSpecKey) {
// A new type or size: the next eligibility pass loads it.
model.show = false;
lastEligibilityAt = -Infinity;
continue;
}
const tint = item.spec.tinted && !irBoost ? item.tint : null;
if (tint && !Cesium.Color.equals(tint, model._gevTint)) {
model.customShader = fleetTintShader(tint);
model._gevTint = tint;
}
fleetModelMatrix(
placement(item),
item.headingDeg,
item.spec,
model.modelMatrix,
scratchHpr,
);
if (!model.ready) {
model.show = false;
settling += 1;
continue;
}
model.show = true;
item.modelOwnsVisual = true;
drawn = true;
}
for (const id of models.keys()) if (!items.has(id)) release(id);
return drawn;
},
/**
* Models loading or not yet ready after the last frame: the layer keeps
* frames coming while any are, so each one takes over as soon as it can.
*/
get settling() {
return settling;
},
/**
* Whether models are drawn now: 3D on, the set loaded and the camera
* below the altitude ceiling. A layer skips building items while not.
* @returns {boolean}
*/
active() {
return !destroyed && regime(preferences());
},
/** The model drawing `id`, if one is admitted. */
modelFor(id) {
return models.get(id) || null;
},
/** Show or hide every model (the layer's own visibility). */
setVisible(show) {
if (!collection.isDestroyed()) collection.show = show;
},
/** Drop every model (3D off, layer disabled). */
clear: releaseAll,
/** Number of admitted models (tests and diagnostics). */
get size() {
return models.size;
},
destroy() {
destroyed = true;
releaseAll();
if (!viewer.isDestroyed?.() && !collection.isDestroyed())
viewer.scene.primitives.remove(collection);
},
};
}
+487
View File
@@ -0,0 +1,487 @@
// The icon-to-model handoff the Vessels, Transit and Rail layers share
// (fleetModelInstances.js): models only under the DISPLAY 3D toggle and the
// altitude ceiling, at most `cap` of the nearest, each vehicle's icon the
// visual until its model is loaded, ready and placed, and a tinted model
// painted with its route colour.
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import * as Cesium from 'cesium';
import {
createFleetModel,
createFleetModelLayer,
fleetModelMatrix,
fleetTintShader,
FLEET_HEADING_OFFSET_DEG,
} from './fleetModelInstances.js';
import {
loadFleetModelSet,
transitModelSpec,
vesselModelSpec,
} from './fleetModels.js';
import { fetchPublicFile } from '../testSupport/fleetGlb.mjs';
const realInfo = console.info;
console.info = () => {};
const set = await loadFleetModelSet({ fetchImpl: fetchPublicFile });
console.info = realInfo;
const POLICY = Object.freeze({
altitudeCeilingM: 800_000,
minimumPixelSize: 16,
cap: 2,
capAll: 4,
addM: 5_000,
addAllM: 20_000,
keepM: 6_000,
keepAllM: 24_000,
intervalMs: 80,
});
const CENTRE = Cesium.Cartesian3.fromDegrees(-122.4, 37.8, 0);
function fakeViewer(height = 1_000) {
const primitives = [];
const position = Cesium.Cartesian3.fromDegrees(-122.4, 37.8, height);
const up = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
position,
new Cesium.Cartesian3(),
);
const camera = {
positionWC: position,
positionCartographic: { height },
directionWC: Cesium.Cartesian3.negate(up, new Cesium.Cartesian3()),
upWC: Cesium.Cartesian3.UNIT_Z,
frustum: {
computeCullingVolume: () => ({
computeVisibility: () => Cesium.Intersect.INSIDE,
}),
},
};
return {
camera,
scene: {
primitives: {
add(p) {
primitives.push(p);
return p;
},
remove(p) {
const i = primitives.indexOf(p);
if (i >= 0) primitives.splice(i, 1);
return i >= 0;
},
},
},
primitives,
isDestroyed: () => false,
};
}
function fakeModel(options) {
return {
...options,
ready: false,
show: true,
modelMatrix: new Cesium.Matrix4(),
destroyed: false,
destroy() {
this.destroyed = true;
},
isDestroyed() {
return this.destroyed;
},
update() {},
};
}
/** A vehicle `metres` east of the camera's foot. */
function itemAt(metres, spec, extra = {}) {
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(CENTRE);
const position = Cesium.Matrix4.multiplyByPoint(
enu,
new Cesium.Cartesian3(metres, 0, 0),
new Cesium.Cartesian3(),
);
return { position, headingDeg: 90, spec, tint: null, pickId: null, ...extra };
}
const flush = () => new Promise((resolve) => setImmediate(resolve));
test('models load from the up-front set, never by URL', async () => {
const spec = vesselModelSpec(set, { type: '70', length: 200, beam: 32 });
let options = null;
await createFleetModel(
spec,
{ scale: spec.scale },
{
set,
resolveAsset: (url) => `/base${url}`,
load: async (o) => {
options = o;
return {};
},
},
);
assert.ok(options.gltf instanceof Uint8Array, 'the loaded GLB bytes');
assert.equal(options.gltf, set.bytes.get(spec.model));
assert.equal(options.basePath, `/base${spec.url}`);
assert.equal(options.url, undefined, 'no fetch by URL');
assert.deepEqual({ ...options.environmentMapOptions }, { enabled: false });
await assert.rejects(
createFleetModel({ model: 'missing' }, {}, { set, load: async () => ({}) }),
/not loaded/,
);
});
test('the icon stays the visual until the model is ready; only the nearest are drawn', async () => {
const viewer = fakeViewer();
const display = { models3d: true, models3dMode: 'proximity' };
const created = [];
const layer = createFleetModelLayer({
viewer,
display: () => display,
policy: POLICY,
createModel: async (spec, options) => {
const model = fakeModel({ spec, ...options });
created.push(model);
return model;
},
});
const spec = transitModelSpec(set, { mode: 'tram' });
const items = new Map([
['near', itemAt(100, spec, { pickId: 'near' })],
['mid', itemAt(1_000, spec, { pickId: 'mid' })],
['far', itemAt(4_000, spec, { pickId: 'far' })],
]);
layer.frame(items, 0);
await flush();
assert.equal(created.length, POLICY.cap, 'the cap holds');
assert.deepEqual(
created.map((m) => m.id).sort(),
['mid', 'near'],
'the nearest are modelled',
);
assert.equal(created[0].scale, spec.scale, 'drawn life size');
assert.equal(created[0].minimumPixelSize, POLICY.minimumPixelSize);
layer.frame(items, 100);
for (const item of items.values())
assert.equal(item.modelOwnsVisual, false, 'not ready: the icon draws');
assert.ok(
layer.settling > 0,
'the layer asks for frames while models settle',
);
for (const model of created) model.ready = true;
layer.frame(items, 200);
assert.equal(items.get('near').modelOwnsVisual, true);
assert.equal(items.get('mid').modelOwnsVisual, true);
assert.equal(items.get('far').modelOwnsVisual, false);
assert.equal(layer.settling, 0);
// A placed model stands on its item's point, nose along its heading.
const near = created.find((m) => m.id === 'near');
const origin = Cesium.Matrix4.getTranslation(
near.modelMatrix,
new Cesium.Cartesian3(),
);
assert.ok(
Cesium.Cartesian3.distance(origin, items.get('near').position) < 1e-6,
);
// 3D off: every model goes and every icon comes back.
display.models3d = false;
layer.frame(items, 300);
assert.equal(layer.size, 0);
for (const item of items.values()) assert.equal(item.modelOwnsVisual, false);
assert.ok(
created.every((m) => m.destroyed),
'released models are destroyed',
);
layer.destroy();
assert.equal(viewer.primitives.length, 0);
});
test('models stay off above the altitude ceiling', async () => {
const viewer = fakeViewer(POLICY.altitudeCeilingM + 1);
let calls = 0;
const layer = createFleetModelLayer({
viewer,
display: () => ({ models3d: true }),
policy: POLICY,
createModel: async (spec, options) => {
calls += 1;
return fakeModel(options);
},
});
assert.equal(layer.active(), false);
layer.frame(new Map([['a', itemAt(0, transitModelSpec(set, {}))]]), 0);
await flush();
assert.equal(calls, 0);
layer.destroy();
});
test('a tinted model is painted with its route colour; an untinted one is not', async () => {
const viewer = fakeViewer();
const created = [];
const layer = createFleetModelLayer({
viewer,
display: () => ({ models3d: true }),
policy: POLICY,
createModel: async (spec, options) => {
const model = fakeModel(options);
created.push(model);
return model;
},
});
const red = Cesium.Color.RED;
const tram = transitModelSpec(set, { mode: 'tram' });
const ship = vesselModelSpec(set, { type: '70', length: 180 });
assert.equal(tram.tinted, true);
assert.equal(ship.tinted, false);
layer.frame(
new Map([
['tram', itemAt(10, tram, { pickId: 'tram', tint: red })],
['ship', itemAt(20, ship, { pickId: 'ship', tint: red })],
]),
0,
);
await flush();
const byId = Object.fromEntries(created.map((m) => [m.id, m]));
assert.equal(byId.tram.customShader, fleetTintShader(red));
assert.equal(byId.ship.customShader, undefined);
assert.equal(
fleetTintShader(red),
fleetTintShader(Cesium.Color.RED),
'one shader per colour',
);
layer.destroy();
});
test('an elevated vehicle is raised by its type elevation', async () => {
const viewer = fakeViewer();
const created = [];
const layer = createFleetModelLayer({
viewer,
display: () => ({ models3d: true }),
policy: POLICY,
createModel: async (spec, options) => {
const model = fakeModel({ ...options, ready: true });
model.ready = true;
created.push(model);
return model;
},
});
const monorail = transitModelSpec(set, { mode: 'monorail' });
assert.equal(monorail.elevationM, set.types.transit.elevation.monorail);
const item = itemAt(10, monorail, { pickId: 'm' });
const items = new Map([['m', item]]);
layer.frame(items, 0);
await flush();
layer.frame(items, 100);
const origin = Cesium.Matrix4.getTranslation(
created[0].modelMatrix,
new Cesium.Cartesian3(),
);
const lifted = Cesium.Cartographic.fromCartesian(origin).height;
const ground = Cesium.Cartographic.fromCartesian(item.position).height;
assert.ok(Math.abs(lifted - ground - monorail.elevationM) < 1e-3);
layer.destroy();
});
test('a vessel stretched to its reported beam keeps its length scale on the model', () => {
const spec = vesselModelSpec(set, { type: '70', length: 200, beam: 60 });
assert.ok(spec.scaleXYZ[1] > spec.scaleXYZ[0], 'a wide hull for its length');
const matrix = fleetModelMatrix(
CENTRE,
0,
spec,
new Cesium.Matrix4(),
new Cesium.HeadingPitchRoll(),
);
const scale = Cesium.Matrix4.getScale(matrix, new Cesium.Cartesian3());
// Cesium's axis correction puts the beam on local X, the length on local Y.
assert.ok(Math.abs(scale.x - spec.scaleXYZ[1] / spec.scaleXYZ[0]) < 1e-9);
assert.ok(Math.abs(scale.y - 1) < 1e-9);
assert.equal(FLEET_HEADING_OFFSET_DEG, 180, 'fleet models are built nose -X');
});
test('Vessels, Transit and Rail draw fleet models under the shared 3D toggle', () => {
for (const file of [
'src/layers/vessels/rendering.js',
'src/layers/transit/rendering.js',
'src/layers/rail/rendering.js',
]) {
const source = fs.readFileSync(
new URL(`../../${file}`, import.meta.url),
'utf8',
);
assert.match(
source,
/createFleetModelLayer\(/,
`${file}: draws fleet models`,
);
assert.match(
source,
/loadFleetModelSet\(/,
`${file}: loads the set up front`,
);
assert.match(
source,
/modelOwnsVisual/,
`${file}: hands its icon to the model`,
);
}
for (const file of [
'src/app/layers/aisLiveVessels.js',
'src/app/layers/transit.js',
'src/app/layers/rail.js',
]) {
const source = fs.readFileSync(
new URL(`../../${file}`, import.meta.url),
'utf8',
);
assert.match(
source,
/fleet: fleetModelServices\(/,
`${file}: given the fleet service`,
);
}
const catalog = fs.readFileSync(
new URL('../app/constructCatalog.js', import.meta.url),
'utf8',
);
assert.equal(
catalog.match(/displayParams: \(\) => flights\.getParams\(\)/g)?.length,
4,
'Local ADS-B, Vessels, Transit and Rail follow the Flights 3D toggle',
);
});
/** A layer whose models are all ready as soon as they are created. */
function readyLayer({ display, waterline = false } = {}) {
const viewer = fakeViewer();
const created = [];
const layer = createFleetModelLayer({
viewer,
display: () => display,
policy: POLICY,
waterline,
createModel: async (spec, options) => {
const model = fakeModel(options);
model.ready = true;
created.push(model);
return model;
},
});
return { layer, created };
}
test('a model stands on the floor its icon is lifted above', async () => {
const { layer, created } = readyLayer({ display: { models3d: true } });
const tram = transitModelSpec(set, { mode: 'tram' });
const item = itemAt(10, tram, { pickId: 't', groundLiftM: 1.5 });
const items = new Map([['t', item]]);
layer.frame(items, 0);
await flush();
layer.frame(items, 100);
const origin = Cesium.Matrix4.getTranslation(
created[0].modelMatrix,
new Cesium.Cartesian3(),
);
const drop =
Cesium.Cartographic.fromCartesian(item.position).height -
Cesium.Cartographic.fromCartesian(origin).height;
assert.ok(Math.abs(drop - 1.5) < 1e-3, `dropped ${drop} m`);
layer.destroy();
});
test('under NVG/FLIR models are rebuilt unlit white, and rebuilt again on exit', async () => {
const display = { models3d: true, irBoost: false };
const { layer, created } = readyLayer({ display });
const tram = transitModelSpec(set, { mode: 'tram' });
const items = new Map([
['t', itemAt(10, tram, { pickId: 't', tint: Cesium.Color.RED })],
]);
layer.frame(items, 0);
await flush();
assert.equal(created[0].customShader, fleetTintShader(Cesium.Color.RED));
display.irBoost = true;
layer.frame(items, 100);
assert.ok(created[0].destroyed, 'the lit model is released');
await flush();
const boosted = created[1];
assert.equal(boosted.customShader.lightingModel, Cesium.LightingModel.UNLIT);
assert.ok(Cesium.Color.equals(boosted.color, Cesium.Color.WHITE));
assert.equal(boosted.colorBlendAmount, 1);
display.irBoost = false;
layer.frame(items, 200);
await flush();
assert.ok(boosted.destroyed);
assert.equal(created[2].customShader, fleetTintShader(Cesium.Color.RED));
layer.destroy();
});
test('a waterline layer clips each model at its origin, keeping the part above', async () => {
const { layer, created } = readyLayer({
display: { models3d: true },
waterline: true,
});
const ship = vesselModelSpec(set, { type: '70', length: 200, beam: 32 });
layer.frame(new Map([['s', itemAt(10, ship, { pickId: 's' })]]), 0);
await flush();
const planes = created[0].clippingPlanes;
assert.ok(planes instanceof Cesium.ClippingPlaneCollection);
assert.equal(planes.length, 1);
const plane = planes.get(0);
assert.equal(plane.distance, 0);
assert.ok(Cesium.Cartesian3.equals(plane.normal, Cesium.Cartesian3.UNIT_Z));
assert.equal(planes.unionClippingRegions, false);
// Cesium keeps a point where normal · p + distance >= 0: above the waterline.
const above = Cesium.Cartesian3.dot(
plane.normal,
new Cesium.Cartesian3(0, 0, 3),
);
const below = Cesium.Cartesian3.dot(
plane.normal,
new Cesium.Cartesian3(0, 0, -3),
);
assert.ok(above + plane.distance > 0 && below + plane.distance < 0);
layer.destroy();
const plain = readyLayer({ display: { models3d: true } });
plain.layer.frame(
new Map([['t', itemAt(10, transitModelSpec(set, { mode: 'tram' }))]]),
0,
);
await flush();
assert.equal(plain.created[0].clippingPlanes, undefined, 'others unclipped');
plain.layer.destroy();
});
test('a vehicle drawn as its model keeps its card and its detection entry', () => {
const read = (file) =>
fs.readFileSync(new URL(`../../${file}`, import.meta.url), 'utf8');
assert.match(
read('src/layers/transit/selection.js'),
/marker\?\.show !== false \|\| entry\.modelOwnsVisual === true/,
);
assert.match(
read('src/layers/rail/selection.js'),
/entry\.marker\?\.show !== false \|\| entry\.modelOwnsVisual === true/,
);
assert.match(
read('src/layers/transit/queries.js'),
/marker\.show === false && entry\.modelOwnsVisual !== true/,
);
assert.match(
read('src/layers/vessels/queries.js'),
/!visual\.billboard\.show &&\s*!visual\.modelOwnsVisual/,
);
assert.match(
read('src/layers/transit/rendering.js'),
/entry\.mode === 'unknown'/,
'a vehicle of unknown mode keeps its icon',
);
});
+481
View File
@@ -0,0 +1,481 @@
/**
* @module fleetModels
* @description The project's procedural fleet models (`public/models/fleet/`):
* which model draws an aircraft, a vessel or a transit or rail vehicle, and at
* what size, from the set's `catalog.json` (each model's file, bounds,
* length, beam, clearance and icon class) and `types.json` (which model
* draws which type, and the fallbacks).
*
* Every model is metres, glTF Y-up, nose toward local -X, origin at the body
* centre (an aircraft's fuselage axis, a vessel's waterline, a road or rail
* vehicle's road or rail top), and is drawn life size: a type's published
* length over the model's built length is its scale.
*
* The resolvers are plain functions over the parsed JSON; `loadFleetModelSet`
* fetches the JSON and every GLB once, up front, so no model is fetched
* mid-session.
*/
import { classifyAircraft } from './aircraftClass.js';
import { FLEET_TRAIL_ANCHORS } from './fleetTrailAnchors.js';
/** Where the model set is served, relative to the application base. */
export const FLEET_MODEL_BASE = '/models/fleet/';
/**
* Longest and widest hulls afloat, metres (Seawise Giant 458 m; the TI
* tankers 68 m abeam). AIS gives the bow and stern from the antenna in 9 bits
* and each side in 6, their largest values (511, 63) meaning "that or more"
* or a set never configured: a 30 m tug reported 511 m long would be drawn 17
* times its size.
*/
const MAX_HULL_LENGTH_M = 460;
const MAX_HULL_BEAM_M = 75;
/** The model a known aircraft class draws when its type has no entry. */
const CLASS_MODELS = Object.freeze({
light: 'c172',
glider: 'glider',
turboprop: 'at72',
widebody: 'b789',
quadjet: 'b744',
helicopter: 'generic_heli',
fastjet: 't38',
bizjet: 'c56x',
uav: 'mq9',
});
/** OpenSky's integer aircraft category (state vector index 17) → ADS-B emitter category. */
const OPENSKY_EMITTER_CATEGORY = Object.freeze({
2: 'A1',
3: 'A2',
4: 'A3',
5: 'A4',
6: 'A5',
7: 'A6',
8: 'A7',
9: 'B1',
10: 'B2',
11: 'B3',
12: 'B4',
14: 'B6',
15: 'B7',
16: 'C1',
17: 'C2',
18: 'C3',
19: 'C4',
20: 'C5',
});
/** A text vessel type (as some AIS sources name it) → a representative AIS ship-type code. */
const TEXT_SHIP_TYPES = [
[/tanker|lng|lpg|gas carrier/i, 80],
[/cargo|container|bulk|carrier|freighter|ro-?ro/i, 70],
[/passenger|ferry|cruise/i, 60],
[/high.?speed/i, 40],
[/fishing|trawler/i, 30],
[/tug|towing/i, 52],
[/pilot/i, 50],
[/search|rescue|\bsar\b/i, 51],
[/dredg/i, 33],
[/military|naval|navy/i, 35],
[/law|police|patrol|coast ?guard/i, 55],
[/sail/i, 36],
[/pleasure|yacht/i, 37],
];
/**
* The model for an aircraft of ICAO type `type` (A320, B738, R44) and ADS-B
* emitter category `category`: the type's, else the category's, else
* `default_aircraft`.
* @param {object} types Parsed `types.json`.
* @param {string} [type]
* @param {string} [category]
* @returns {{model: string, length: number|null}}
*/
export function resolveAircraft(types, type, category) {
const t = type?.trim().toUpperCase();
const [model, length] =
(t && (types.aircraft[t] ?? types.helicopters[t])) ||
(category && types.categories[category]) ||
types.default_aircraft;
return { model, length };
}
/**
* A reported length as one a hull can have, else undefined (drawn as built).
* @param {number} [length]
* @returns {number|undefined}
*/
export function hullLength(length) {
return length !== undefined &&
length !== null &&
length > 0 &&
length <= MAX_HULL_LENGTH_M
? length
: undefined;
}
/**
* A reported beam as one a hull can have, else undefined.
* @param {number} [beam]
* @returns {number|undefined}
*/
export function hullBeam(beam) {
return beam !== undefined &&
beam !== null &&
beam > 0 &&
beam <= MAX_HULL_BEAM_M
? beam
: undefined;
}
/**
* The model for a vessel of AIS ship type `shipType` and the reported length
* and beam (metres) and name: the first rule that matches in the first type
* range that has one, else `default_vessel`. Drawn at the reported length;
* when it is unknown (most live feeds send none), chosen and drawn at the
* range's `typical_len`, else as built.
* @param {object} types Parsed `types.json`.
* @param {number} [shipType]
* @param {number} [length]
* @param {number} [beam]
* @param {string} [name]
* @returns {{model: string, length: number|null}}
*/
export function resolveVessel(types, shipType, length, beam, name) {
const L = hullLength(length) ?? 0;
const B = hullBeam(beam) ?? 0;
if (shipType !== undefined && shipType !== null) {
for (const group of types.vessels) {
if (!(shipType >= group.types[0] && shipType <= group.types[1])) continue;
const len = L > 0 ? L : (group.typical_len ?? 0);
const drawn = len > 0 ? len : null;
for (const rule of group.rules) {
if (rule.min_len && len < rule.min_len) continue;
if (rule.max_len && len > rule.max_len) continue;
if (rule.name_re && !new RegExp(rule.name_re).test(name ?? ''))
continue;
if (rule.max_bl && !(B > 0 && L > 0 && B / L <= rule.max_bl)) continue;
return { model: rule.model, length: drawn };
}
}
}
return { model: types.default_vessel, length: L > 0 ? L : null };
}
/**
* The model for a public transport vehicle: a rail category and mode
* (`transit`/`local`/`regional`/`national`/`international` × `rail`/`metro`/
* `tram`), else a GTFS `route_type` (basic 0-12 or extended 100-1507), else a
* mode name (`bus`, `tram`, `subway`, `rail`, `ferry`, `light_rail`, …),
* else `transit.default`. Each comes with the length to draw it at.
* @param {object} types Parsed `types.json`.
* @param {{railCategory?: string, railMode?: string, routeType?: number|string,
* mode?: string}} vehicle
* @returns {{model: string, length: number|null}}
*/
export function resolveTransit(
types,
{ railCategory, railMode, routeType, mode } = {},
) {
const transit = types.transit;
const rail = railCategory ? transit.rail[railCategory] : null;
const routeKey =
routeType === undefined || routeType === null || routeType === ''
? null
: String(Number(routeType));
const [model, length] =
(rail && (rail[railMode || 'rail'] ?? rail.rail)) ||
(routeKey && transit.route_types[routeKey]) ||
(mode && transit.modes[mode]) ||
transit.default;
return { model, length };
}
/**
* An AIS ship type as its numeric code: a code as given ("70"), or the code
* of the family a text type names ("Cargo" → 70); undefined when it names
* none.
* @param {string|number|null|undefined} type
* @returns {number|undefined}
*/
export function aisShipTypeCode(type) {
const text = String(type ?? '').trim();
if (!text) return undefined;
if (/^\d+$/.test(text)) {
const code = Number(text);
return code > 0 && code < 100 ? code : undefined;
}
for (const [pattern, code] of TEXT_SHIP_TYPES)
if (pattern.test(text)) return code;
return undefined;
}
/**
* An aircraft category as an ADS-B emitter category: an emitter string as
* given ("A3"), or OpenSky's integer category mapped to one.
* @param {string|number|null|undefined} category
* @returns {string|undefined}
*/
export function emitterCategory(category) {
if (typeof category === 'number')
return OPENSKY_EMITTER_CATEGORY[category] || undefined;
const text = String(category ?? '')
.trim()
.toUpperCase();
if (/^\d+$/.test(text)) return OPENSKY_EMITTER_CATEGORY[Number(text)];
return /^[A-D][0-7]$/.test(text) ? text : undefined;
}
/**
* The scale of model `model` drawn `length` metres long, along the model's
* length, beam and height. A vessel's reported beam stretches it sideways;
* its height follows the mean of the two.
* @param {object} model Catalog entry.
* @param {number|null} length
* @param {number} [beam] A vessel's reported beam.
* @returns {[number, number, number]}
*/
export function placeScale(model, length, beam) {
if (length === null || length === undefined || !(model.length > 0))
return [1, 1, 1];
const sx = length / model.length;
const b = hullBeam(beam);
const sy = b !== undefined && model.beam > 0 ? b / model.beam : sx;
return [sx, sy, (sx + sy) / 2];
}
/** Half the diagonal of a model's bounds: the radius Cesium bounds it by. */
function boundingRadius(model) {
const [x0, y0, z0] = model.min;
const [x1, y1, z1] = model.max;
return Math.hypot(x1 - x0, y1 - y0, z1 - z0) / 2;
}
/**
* The drawing of model `name` at `length` metres: what the layers place.
*
* `scale` is the uniform scale (along the model's length) a Cesium Model
* takes; `scaleXYZ` the model's length, beam and height scales, for a vessel
* stretched to its reported beam. `clearanceM` is how far the model reaches
* below its origin at that scale (wheels below an aircraft's axis, a keel
* below the waterline): a grounded aircraft stands its origin that far up.
* `elevationM` lifts a vehicle off the route it follows (a monorail, a
* gondola). `tinted` models carry the `_TINT` vertex attribute marking where
* a route colour applies. `nativeRadiusM` (unscaled), `visualCenterNative`
* and `trailAnchorNative` (raw glTF axes, unscaled) serve the aircraft
* layers' pixel-size, bracket and trail geometry.
* @param {{catalog: object, types: object}} set
* @param {string} name Catalog model name.
* @param {number|null} length Metres along the body; null draws it as built.
* @param {{beam?: number}} [options]
* @returns {object}
*/
export function fleetModelSpec(set, name, length, { beam } = {}) {
const model = set.catalog[name];
// Ground vehicles, balloons and obstacles are built at the size their type
// names (a tower's 60 m is its height, not a length to scale to).
const drawnLength = model.category === 'other' ? null : length;
const scaleXYZ = placeScale(model, drawnLength, beam);
const elevationM = set.types.transit?.elevation?.[name] || 0;
return Object.freeze({
model: name,
url: FLEET_MODEL_BASE + model.file,
category: model.category,
icon: model.icon,
length: model.length * scaleXYZ[0],
scale: scaleXYZ[0],
scaleXYZ: Object.freeze(scaleXYZ),
clearanceM: model.clearance * scaleXYZ[2],
elevationM,
tinted: model.category === 'transit',
nativeRadiusM: boundingRadius(model),
visualCenterNative: CENTRED,
trailAnchorNative: FLEET_TRAIL_ANCHORS[name] || CENTRED,
key: `${name}@${scaleXYZ.map((s) => s.toFixed(4)).join('x')}`,
});
}
const CENTRED = Object.freeze([0, 0, 0]);
/** `resolved` drawn from `set`, its model replaced by `fallback` when the catalog lacks it. */
function specOf(set, resolved, fallback, options) {
const known = set.catalog[resolved.model] ? resolved : fallback(resolved);
return fleetModelSpec(set, known.model, known.length, options);
}
/**
* The model an aircraft is drawn with. The type's entry first; then, for a
* type the map lacks, the model of its class (a fast jet, a helicopter, a
* glider) when the type names one; then the emitter category's; then
* `default_aircraft`.
* @param {{catalog: object, types: object}} set
* @param {{typeCode?: string|null, type?: string|null,
* category?: string|number|null}} aircraft
* @returns {object} {@link fleetModelSpec}
*/
export function aircraftModelSpec(set, { typeCode, type, category } = {}) {
const { types, catalog } = set;
const code = String(typeCode ?? type ?? '')
.trim()
.toUpperCase();
const emitter = emitterCategory(category);
let resolved = resolveAircraft(types, code, emitter);
const typed = code && (types.aircraft[code] || types.helicopters[code]);
if (!typed && code) {
const model = CLASS_MODELS[classifyAircraft({ typeCode: code })];
if (model && catalog[model])
resolved = { model, length: catalog[model].length };
}
return specOf(set, resolved, () => ({
model: types.default_aircraft[0],
length: types.default_aircraft[1],
}));
}
/**
* The model a vessel is drawn with, from its AIS ship type (a code or a text
* family), reported length and beam (metres) and name.
* @param {{catalog: object, types: object}} set
* @param {{type?: string|number|null, length?: number|null,
* beam?: number|null, name?: string|null}} vessel
* @returns {object} {@link fleetModelSpec}
*/
export function vesselModelSpec(set, { type, length, beam, name } = {}) {
// A beam counts only beside a reported length: a vessel drawn at its type's
// typical length keeps the model's proportions.
const reported = hullLength(length ?? undefined);
const hullWidth = reported === undefined ? undefined : (beam ?? undefined);
const resolved = resolveVessel(
set.types,
aisShipTypeCode(type),
reported,
hullWidth,
name ?? undefined,
);
return specOf(
set,
resolved,
(r) => ({ model: set.types.default_vessel, length: r.length }),
{ beam: hullWidth },
);
}
/**
* The model a transit or rail vehicle is drawn with ({@link resolveTransit}).
* @param {{catalog: object, types: object}} set
* @param {object} vehicle
* @returns {object} {@link fleetModelSpec}
*/
export function transitModelSpec(set, vehicle) {
return specOf(set, resolveTransit(set.types, vehicle), () => ({
model: set.types.transit.default[0],
length: set.types.transit.default[1],
}));
}
/**
* Every model the type map names, defaults and fallbacks included.
* @param {object} types Parsed `types.json`.
* @returns {Set<string>}
*/
export function namedFleetModels(types) {
const pairs = (map) => Object.values(map).map(([model]) => model);
const transit = types.transit;
return new Set([
...pairs(types.aircraft),
...pairs(types.helicopters),
...pairs(types.categories),
...types.vessels.flatMap((group) => group.rules.map((rule) => rule.model)),
types.default_aircraft[0],
types.default_vessel,
...pairs(transit.modes),
...pairs(transit.route_types),
...Object.values(transit.rail).flatMap(pairs),
transit.default[0],
...Object.keys(transit.elevation),
...Object.values(CLASS_MODELS),
]);
}
let loading = null;
let loaded = null;
/**
* The model set once {@link loadFleetModelSet} has loaded it, else null.
* @returns {object|null}
*/
export function fleetModelSet() {
return loaded;
}
/**
* 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
* session runs. Resolves to `{catalog, types, bytes, loadMs, totalBytes}`,
* `bytes` holding each model's GLB by name; a GLB that fails to load is left
* out (that model then draws nothing and its entities stay icons).
* @param {{resolveAsset?: (url: string) => string,
* fetchImpl?: typeof fetch, now?: () => number}} [options]
* @returns {Promise<object>}
*/
export function loadFleetModelSet({
resolveAsset = (url) => url,
fetchImpl = globalThis.fetch,
now = () => globalThis.performance?.now?.() ?? Date.now(),
} = {}) {
if (loading) return loading;
const started = now();
const json = async (name) => {
const response = await fetchImpl(resolveAsset(FLEET_MODEL_BASE + name));
if (!response.ok) throw new Error(`${name}: HTTP ${response.status}`);
return response.json();
};
loading = (async () => {
const [catalog, types] = await Promise.all([
json('catalog.json'),
json('types.json'),
]);
const bytes = new Map();
let totalBytes = 0;
await Promise.all(
Object.entries(catalog).map(async ([name, model]) => {
try {
const response = await fetchImpl(
resolveAsset(FLEET_MODEL_BASE + model.file),
);
if (!response.ok) return;
const glb = new Uint8Array(await response.arrayBuffer());
bytes.set(name, glb);
totalBytes += glb.byteLength;
} catch {
/* that model draws nothing; its entities stay icons */
}
}),
);
loaded = Object.freeze({
catalog,
types,
bytes,
loadMs: now() - started,
totalBytes,
});
console.info(
`[Fleet] ${bytes.size}/${Object.keys(catalog).length} models ` +
`(${(totalBytes / 1048576).toFixed(2)} MB) loaded in ${Math.round(loaded.loadMs)} ms`,
);
return loaded;
})();
// A failed catalog load may be retried by the next layer that starts.
loading.catch(() => {
loading = null;
});
return loading;
}
/** Forget the loaded set (tests). */
export function resetFleetModelSet() {
loading = null;
loaded = null;
}
+457
View File
@@ -0,0 +1,457 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import {
FLEET_MODEL_BASE,
aircraftModelSpec,
aisShipTypeCode,
emitterCategory,
fleetModelSet,
fleetModelSpec,
hullBeam,
hullLength,
loadFleetModelSet,
namedFleetModels,
placeScale,
resetFleetModelSet,
resolveAircraft,
resolveTransit,
resolveVessel,
transitModelSpec,
vesselModelSpec,
} from './fleetModels.js';
import { FLEET_TRAIL_ANCHORS } from './fleetTrailAnchors.js';
import {
centrelineSegments,
distanceToSurface,
fleetMesh,
measuredTrailAnchor,
readGlb,
vertexBounds,
} from '../testSupport/fleetGlb.mjs';
const ROOT = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../..',
);
const DIR = path.join(ROOT, 'public', 'models', 'fleet');
const json = (name) =>
JSON.parse(fs.readFileSync(path.join(DIR, name), 'utf8'));
const catalog = json('catalog.json');
const types = json('types.json');
const set = { catalog, types };
// A slice of the set's types.json and catalog.json, as the resolver's own
// reference tests use, so these read independently of later model changes.
const sliceTypes = {
aircraft: {
A320: ['a320', 37.57],
A21N: ['a320', 44.51],
A319: ['a320', 33.84],
B38M: ['b738', 39.52],
},
helicopters: { EC35: ['ec35', 10.2] },
categories: { A1: ['c172', 8.3] },
vessels: [
{
types: [70, 79],
typical_len: 300,
rules: [
{ min_len: 70, max_len: 140, max_bl: 0.12, model: 'inland_cargo' },
{
name_re: '\\b(LEADER|HIGHWAY|ACE|GLOVIS|HOEGH|SPIRIT OF)\\b',
min_len: 150,
model: 'car_carrier',
},
{ min_len: 250, model: 'container_ship' },
{ model: 'general_cargo' },
],
},
{ types: [31, 32], rules: [{ model: 'tug' }] },
{ types: [52, 52], rules: [{ model: 'tug' }] },
{ types: [0, 99], rules: [{ model: 'generic_vessel' }] },
],
default_aircraft: ['generic_plane', 36],
default_vessel: 'generic_vessel',
};
const model = (category, file, length, beam, clearance) => ({
category,
file,
min: [0, 0, 0],
max: [0, 0, 0],
length,
beam,
clearance,
tris: 1,
icon: 'jet',
});
const sliceCatalog = {
a320: model('aircraft', 'aircraft/a320.glb', 37.57, 35.6, 3.063),
container_ship: model('ships', 'ships/container_ship.glb', 309.9, 48, 13.9),
};
test('aircraft resolve by type, then emitter category, then the generic plane', () => {
assert.deepEqual(resolveAircraft(sliceTypes, 'A320'), {
model: 'a320',
length: 37.57,
});
assert.deepEqual(resolveAircraft(sliceTypes, ' b38m '), {
model: 'b738',
length: 39.52,
});
assert.equal(resolveAircraft(sliceTypes, 'EC35').model, 'ec35');
assert.deepEqual(resolveAircraft(sliceTypes, 'ZZZZ', 'A1'), {
model: 'c172',
length: 8.3,
});
assert.deepEqual(resolveAircraft(sliceTypes, undefined, 'Q9'), {
model: 'generic_plane',
length: 36,
});
});
test('vessels: the first matching rule of the first type range with one, else the generic vessel', () => {
assert.equal(resolveVessel(sliceTypes, 70, 366, 51).model, 'container_ship');
assert.equal(
resolveVessel(sliceTypes, 71, 199, 32, 'GLOVIS SPIRIT').model,
'car_carrier',
);
assert.equal(resolveVessel(sliceTypes, 79, 110, 11.4).model, 'inland_cargo');
assert.equal(resolveVessel(sliceTypes, 70, 90, 15).model, 'general_cargo');
assert.deepEqual(resolveVessel(sliceTypes, 52, 30, 10), {
model: 'tug',
length: 30,
});
assert.deepEqual(resolveVessel(sliceTypes, undefined, 50), {
model: 'generic_vessel',
length: 50,
});
assert.deepEqual(resolveVessel(sliceTypes, 0), {
model: 'generic_vessel',
length: null,
});
});
test("vessels of unknown length are chosen and drawn at their range's typical length", () => {
assert.deepEqual(resolveVessel(sliceTypes, 70), {
model: 'container_ship',
length: 300,
});
assert.deepEqual(resolveVessel(sliceTypes, 70, 511, 126), {
model: 'container_ship',
length: 300,
});
assert.deepEqual(resolveVessel(sliceTypes, 70, 90, 15), {
model: 'general_cargo',
length: 90,
});
assert.deepEqual(resolveVessel(sliceTypes, 31), {
model: 'tug',
length: null,
});
// Every passenger, cargo and tanker range of the set has one.
for (const code of [60, 70, 80]) {
assert.ok(resolveVessel(types, code).length > 100, String(code));
}
});
test("vessels: AIS's out-of-range sizes (511 m long, 126 m abeam) are unknown, drawn as built", () => {
assert.deepEqual(resolveVessel(sliceTypes, 52, 511), {
model: 'tug',
length: null,
});
assert.equal(hullLength(511), undefined);
assert.equal(hullLength(0), undefined);
assert.equal(hullBeam(126), undefined);
assert.equal(hullBeam(32), 32);
const ship = sliceCatalog.container_ship;
assert.deepEqual(placeScale(ship, ship.length, 126), [1, 1, 1]);
});
test('scale: aircraft by the type length, vessels by length and beam', () => {
const a320 = sliceCatalog.a320;
const [sx, sy, sz] = placeScale(a320, 44.51);
assert.ok(Math.abs(sx - 44.51 / 37.57) < 1e-12);
assert.equal(sy, sx);
assert.equal(sz, sx);
const ship = sliceCatalog.container_ship;
assert.deepEqual(placeScale(ship, ship.length / 2, 24), [0.5, 0.5, 0.5]);
assert.deepEqual(placeScale(ship, null), [1, 1, 1]);
});
test('every model the type map names is in the catalog, and its file is a GLB on disk', () => {
for (const name of namedFleetModels(types))
assert.ok(
catalog[name],
`${name}: named by types.json but not in the catalog`,
);
assert.equal(catalog.generic_plane?.category, 'aircraft');
assert.equal(catalog.generic_vessel?.category, 'ships');
assert.equal(catalog.city_bus?.category, 'transit');
for (const [name, metres] of Object.entries(types.transit.elevation)) {
assert.ok(catalog[name], name);
assert.ok(metres > 0, name);
}
let total = 0;
for (const [name, entry] of Object.entries(catalog)) {
const file = path.join(DIR, entry.file);
assert.ok(fs.existsSync(file), `${name}: ${entry.file} is missing`);
const bytes = fs.readFileSync(file);
assert.equal(bytes.subarray(0, 4).toString('latin1'), 'glTF', name);
assert.ok(entry.length > 0, name);
assert.ok(entry.tris <= 50_000, name);
total += bytes.length;
}
// The set ships with the repository and loads up front: keep it small.
assert.ok(total < 3 * 1024 * 1024, `fleet GLBs total ${total} bytes`);
});
test('transit bodies mark the share of the route colour they take; other models mark none', () => {
for (const [name, entry] of Object.entries(catalog)) {
const { json: gltf } = readGlb(path.join(DIR, entry.file));
for (const mesh of gltf.meshes)
for (const primitive of mesh.primitives)
assert.equal(
'_TINT' in primitive.attributes,
entry.category === 'transit',
name,
);
assert.equal(
fleetModelSpec(set, name, null).tinted,
entry.category === 'transit',
);
}
});
test('aircraft specs: by type, then class for an unlisted type, then emitter category', () => {
assert.equal(aircraftModelSpec(set, { typeCode: 'A320' }).model, 'a320');
assert.equal(aircraftModelSpec(set, { type: 'b744' }).model, 'b744');
// An unlisted fast jet is still a fast jet, not the generic airliner.
assert.equal(
aircraftModelSpec(set, { typeCode: 'FA18', category: 'A3' }).model,
't38',
);
assert.equal(aircraftModelSpec(set, { typeCode: 'MQ9' }).model, 'mq9');
assert.equal(
aircraftModelSpec(set, { typeCode: 'PUMA' }).model,
'generic_heli',
);
// An unlisted type of no special class falls to its category.
assert.equal(
aircraftModelSpec(set, { typeCode: 'ZZZZ', category: 'A5' }).model,
'b77w',
);
// OpenSky's integer category: 8 is rotorcraft (A7), 2 light (A1).
assert.equal(emitterCategory(8), 'A7');
assert.equal(emitterCategory('a3'), 'A3');
assert.equal(emitterCategory(1), undefined);
assert.equal(aircraftModelSpec(set, { category: 8 }).model, 'generic_heli');
assert.equal(aircraftModelSpec(set, { category: 2 }).model, 'c172');
assert.equal(aircraftModelSpec(set, {}).model, types.default_aircraft[0]);
});
test('aircraft specs are life size, standing on their scaled clearance', () => {
const spec = aircraftModelSpec(set, { typeCode: 'A21N' });
const [, length] = types.aircraft.A21N;
assert.equal(spec.model, types.aircraft.A21N[0]);
assert.ok(Math.abs(spec.length - length) < 1e-9);
assert.ok(Math.abs(spec.scale - length / catalog[spec.model].length) < 1e-12);
assert.ok(
Math.abs(spec.clearanceM - catalog[spec.model].clearance * spec.scale) <
1e-12,
);
assert.equal(spec.url, `${FLEET_MODEL_BASE}${catalog[spec.model].file}`);
assert.equal(spec.tinted, false);
assert.equal(spec.elevationM, 0);
assert.ok(
spec.nativeRadiusM * spec.scale > 25 &&
spec.nativeRadiusM * spec.scale < 60,
);
assert.deepEqual(spec.trailAnchorNative, FLEET_TRAIL_ANCHORS[spec.model]);
// A grounded service vehicle and an obstacle are drawn as built: the
// tower's 60 m is its height, not a length to stretch it to.
const tower = aircraftModelSpec(set, { category: 'C3' });
assert.equal(tower.model, 'tower');
assert.equal(tower.scale, 1);
assert.equal(aircraftModelSpec(set, { category: 'C1' }).scale, 1);
});
test('vessel specs read AIS codes and text families, stretched to the reported beam', () => {
assert.equal(aisShipTypeCode('70'), 70);
assert.equal(aisShipTypeCode(' Cargo '), 70);
assert.equal(aisShipTypeCode('Tanker'), 80);
assert.equal(aisShipTypeCode('Tug'), 52);
assert.equal(aisShipTypeCode('0'), undefined);
assert.equal(aisShipTypeCode(''), undefined);
const box = vesselModelSpec(set, { type: '71', length: 366, beam: 51 });
assert.equal(box.model, 'container_ship');
assert.ok(Math.abs(box.length - 366) < 1e-9);
const [sx, sy, sz] = box.scaleXYZ;
assert.ok(Math.abs(sy - 51 / catalog.container_ship.beam) < 1e-12);
assert.ok(Math.abs(sz - (sx + sy) / 2) < 1e-12);
// A beam with no reported length: the type's typical length, in the model's
// own proportions, not a typical-length hull squeezed to that beam.
const unsized = vesselModelSpec(set, { type: '70', length: 0, beam: 14 });
assert.equal(unsized.model, 'container_ship');
const [ux, uy, uz] = unsized.scaleXYZ;
assert.ok(Math.abs(uy - ux) < 1e-12 && Math.abs(uz - ux) < 1e-12);
assert.equal(vesselModelSpec(set, { type: 'Tug', length: 30 }).model, 'tug');
assert.equal(vesselModelSpec(set, { type: '36' }).model, 'sailboat');
// No type, no size: the generic vessel as built.
const unknown = vesselModelSpec(set, {});
assert.equal(unknown.model, types.default_vessel);
assert.equal(unknown.scale, 1);
});
test('transit specs: rail category and mode, then route type, then mode, then the default', () => {
assert.deepEqual(resolveTransit(types, { railCategory: 'national' }), {
model: 'intercity',
length: types.transit.rail.national.rail[1],
});
assert.equal(
resolveTransit(types, { railCategory: 'transit', railMode: 'metro' }).model,
'metro',
);
assert.equal(
resolveTransit(types, { railCategory: 'regional', railMode: 'tram' }).model,
'light_rail',
);
assert.equal(resolveTransit(types, { routeType: 3 }).model, 'city_bus');
assert.equal(resolveTransit(types, { routeType: '0' }).model, 'tram');
assert.equal(resolveTransit(types, { routeType: 109 }).model, 'commuter_emu');
assert.equal(resolveTransit(types, { mode: 'subway' }).model, 'metro');
assert.equal(resolveTransit(types, { mode: 'ferry' }).model, 'fast_ferry');
assert.equal(
resolveTransit(types, { mode: 'unknown' }).model,
types.transit.default[0],
);
const tram = transitModelSpec(set, { mode: 'tram' });
assert.equal(tram.tinted, true);
assert.equal(tram.clearanceM, 0);
assert.ok(Math.abs(tram.length - types.transit.modes.tram[1]) < 1e-9);
assert.equal(
transitModelSpec(set, { routeType: 12 }).elevationM,
types.transit.elevation.monorail,
);
assert.equal(
transitModelSpec(set, { mode: 'gondola' }).elevationM,
types.transit.elevation.gondola,
);
assert.equal(transitModelSpec(set, { mode: 'ferry' }).tinted, false);
});
test('a model missing from the catalog falls back to the default of its kind', () => {
const thin = {
catalog: { ...catalog },
types: {
...types,
aircraft: { ...types.aircraft, XXXX: ['no_such_model', 20] },
},
};
assert.equal(
aircraftModelSpec(thin, { typeCode: 'XXXX' }).model,
types.default_aircraft[0],
);
});
const ANCHORED = Object.entries(catalog).filter(([, entry]) =>
['aircraft', 'helicopters', 'other'].includes(entry.category),
);
test('every aircraft-layer model has a trail anchor on its real aft-belly hull', async () => {
assert.deepEqual(
new Set(Object.keys(FLEET_TRAIL_ANCHORS)),
new Set(ANCHORED.map(([name]) => name)),
're-run scripts/measure-fleet-trail-anchors.mjs',
);
for (const [name, entry] of ANCHORED) {
const mesh = await fleetMesh(path.join(DIR, entry.file));
const { min, max } = vertexBounds(mesh.verts);
const anchor = FLEET_TRAIL_ANCHORS[name];
// On the hull, not in the air beside it.
const offHull = distanceToSurface(anchor, mesh.verts, mesh.tris);
assert.ok(
offHull <= 1e-3,
`${name}: trail anchor is ${offHull.toFixed(4)} m off the hull`,
);
// Aft of the middle, so the head segment does not run into the body.
assert.ok(
anchor[0] > (min[0] + max[0]) / 2,
`${name}: trail anchor is not aft`,
);
// Nothing of the centreline hangs lower at or behind its station.
const lowest = centrelineSegments(mesh.verts, mesh.tris)
.flat()
.filter((p) => p[0] >= anchor[0] - 1e-3)
.reduce((low, p) => Math.min(low, p[1]), Infinity);
assert.ok(
anchor[1] <= lowest + 1e-3,
`${name}: trail anchor is above the hull aft of it`,
);
assert.equal(anchor[2], 0, `${name}: trail anchor is off the centreline`);
// And it is the construction, re-derived.
const measured = measuredTrailAnchor(mesh);
for (const axis of [0, 1])
assert.ok(
Math.abs(anchor[axis] - measured[axis]) <= 1e-3,
`${name} axis ${axis}: table ${anchor[axis]} vs measured ${measured[axis].toFixed(4)}`,
);
}
});
test('catalog bounds match the GLBs they describe', async () => {
for (const [name, entry] of Object.entries(catalog)) {
const { min, max } = vertexBounds(
(await fleetMesh(path.join(DIR, entry.file))).verts,
);
// The catalog is Z up (glTF Y), glTF Z across.
const tolerance = 0.01 * Math.max(1, entry.length);
assert.ok(Math.abs(min[0] - entry.min[0]) <= tolerance, `${name} min x`);
assert.ok(Math.abs(max[0] - entry.max[0]) <= tolerance, `${name} max x`);
assert.ok(Math.abs(min[1] - entry.min[2]) <= tolerance, `${name} min up`);
assert.ok(
Math.abs(-min[1] - entry.clearance) <= tolerance,
`${name} clearance`,
);
assert.ok(
Math.abs(max[2] - min[2] - (entry.max[1] - entry.min[1])) <= tolerance,
`${name} beam`,
);
}
});
test('the model set loads once, every GLB up front, shared by every layer', async () => {
resetFleetModelSet();
const requested = [];
const fetchImpl = async (url) => {
requested.push(url);
const file = path.join(ROOT, 'public', url.replace(/^\/app/, ''));
if (!fs.existsSync(file)) return { ok: false, status: 404 };
const bytes = fs.readFileSync(file);
return {
ok: true,
json: async () => JSON.parse(bytes.toString('utf8')),
arrayBuffer: async () =>
bytes.buffer.slice(
bytes.byteOffset,
bytes.byteOffset + bytes.byteLength,
),
};
};
const resolveAsset = (url) => `/app${url}`;
const [first, second] = await Promise.all([
loadFleetModelSet({ resolveAsset, fetchImpl }),
loadFleetModelSet({ resolveAsset, fetchImpl }),
]);
assert.equal(first, second);
assert.equal(fleetModelSet(), first);
assert.equal(first.bytes.size, Object.keys(catalog).length);
assert.equal(requested.length, Object.keys(catalog).length + 2);
assert.ok(requested.every((url) => url.startsWith('/app/models/fleet/')));
assert.ok(first.totalBytes > 0 && Number.isFinite(first.loadMs));
await loadFleetModelSet({ resolveAsset, fetchImpl });
assert.equal(requested.length, Object.keys(catalog).length + 2);
resetFleetModelSet();
});
+66
View File
@@ -0,0 +1,66 @@
/**
* Aft-belly trail attachment points of the fleet models the aircraft layers
* draw, in raw glTF axes (X along the body, nose toward -X; Y up), metres
* before scale, node transforms applied. Each is the point of the model's
* centreline profile (its z = 0 slice) nearest its aft-belly bounding-box
* corner: on the hull, aft, and on the centreline (see modelVisualAnchor.js).
*
* Written by scripts/measure-fleet-trail-anchors.mjs; re-measured against the
* GLBs by fleetModels.test.mjs.
*/
export const FLEET_TRAIL_ANCHORS = Object.freeze({
a139: Object.freeze([6.8847, 0.2766, 0]),
a320: Object.freeze([17.2078, 0.7416, 0]),
a333: Object.freeze([29.7276, 1.1084, 0]),
a343: Object.freeze([30.0371, 1.2335, 0]),
a359: Object.freeze([31.0731, 1.1573, 0]),
a388: Object.freeze([34.3139, 1.9279, 0]),
as50: Object.freeze([5.2278, -0.0999, 0]),
at72: Object.freeze([12.8258, 0.6792, 0]),
b06: Object.freeze([4.62, -0.3002, 0]),
b407: Object.freeze([5.1264, -0.2797, 0]),
b738: Object.freeze([18.3819, 0.8391, 0]),
b744: Object.freeze([33.6232, 1.5411, 0]),
b763: Object.freeze([25.5464, 0.9889, 0]),
b77w: Object.freeze([34.4639, 1.2084, 0]),
b789: Object.freeze([29.0604, 1.0649, 0]),
balloon: Object.freeze([3.8215, -0.0009, 0]),
bcs3: Object.freeze([17.8658, 0.713, 0]),
be20: Object.freeze([6.6699, 0.5505, 0]),
blimp: Object.freeze([32.2493, -7.1382, 0]),
c17: Object.freeze([26.5207, 2.332, 0]),
c172: Object.freeze([4.0507, 0.4481, 0]),
c30j: Object.freeze([13.568, 0.9917, 0]),
c56x: Object.freeze([7.4627, 0.4526, 0]),
car: Object.freeze([2.3, 0.418, 0]),
cl35: Object.freeze([10.4607, 0.8247, 0]),
crj9: Object.freeze([17.8413, 0.8624, 0]),
dh8d: Object.freeze([15.7902, 0.7501, 0]),
e175: Object.freeze([14.697, 0.6077, 0]),
e55p: Object.freeze([7.6566, 0.503, 0]),
ec35: Object.freeze([5.1003, 0.1471, 0]),
ec45: Object.freeze([5.8004, 0.555, 0]),
fire_truck: Object.freeze([5.5, 0.6051, 0]),
generic_heli: Object.freeze([5.4997, 0.1604, 0]),
generic_plane: Object.freeze([16.5228, 0.712, 0]),
glf4: Object.freeze([13.4603, 0.8243, 0]),
glider: Object.freeze([3.3997, 0.1283, 0]),
h47: Object.freeze([7.7303, 0.0035, 0]),
h60: Object.freeze([7.6295, 0.1365, 0]),
h64: Object.freeze([6.9228, -0.5553, 0]),
k35r: Object.freeze([28.0221, -2.4508, 0]),
md11: Object.freeze([30.8002, 1.2291, 0]),
mq9: Object.freeze([5.8498, -0.062, 0]),
p28a: Object.freeze([3.3695, 0.3959, 0]),
pc12: Object.freeze([6.6416, 0.5288, 0]),
pushback: Object.freeze([3, 0.2499, 0]),
r44: Object.freeze([4.4219, -0.3001, 0]),
s76: Object.freeze([6.6001, 0.1915, 0]),
sr22: Object.freeze([3.6762, 0.2376, 0]),
t38: Object.freeze([7.0246, -0.3791, 0]),
tex2: Object.freeze([4.7383, 0.2302, 0]),
tower: Object.freeze([1.2952, -0.0007, 0]),
ultralight: Object.freeze([3.2271, 0.3259, 0]),
v22: Object.freeze([7.9868, 0.2956, 0]),
van: Object.freeze([2.75, 0.418, 0]),
});
File diff suppressed because it is too large. Load diff
+7 -87
View File
@@ -1,74 +1,15 @@
import * as Cesium from 'cesium';
/**
* Model-space visual centres measured from the shipped GLBs' scene-space AABBs.
* Model-space anchors on the aircraft layers' fleet models: where brackets
* and readouts sit (a model's visual centre) and where a tracked trail
* attaches (its aft-belly point, measured per model in fleetTrailAnchors.js
* and handed to the layers with each model's spec by fleetModels.js).
*
* glTF stores these assets Y-up. Cesium's model frame is Z-up, so a glTF
* centre `[x, y, z]` becomes `[x, -z, y]` before the layer's ENU modelMatrix
* is applied. Values remain in native model units; callers supply the Model's
* Values are native model units in raw glTF axes; callers supply the Model's
* effective rendered `computedScale` because Cesium does not bake it into
* modelMatrix and may raise it above `scale` to satisfy minimumPixelSize.
*/
const CENTERED_MODEL = Object.freeze([0, 0, 0]);
export const MODEL_VISUAL_CENTER_NATIVE = Object.freeze({
'/models/airplane.glb': CENTERED_MODEL,
'/models/jet.glb': CENTERED_MODEL,
});
/**
* Aft-belly trail attachment points, measured on each approved model's actual
* MESH SURFACE. Every bundled asset is baked to one convention (see
* aircraftClass.js): origin at the bbox centre, X = length with the NOSE at
* local −X, glTF Y = up (Cesium-local Z here).
*
* Each value is the point of the hull's CENTRELINE PROFILE (the y = 0 slice of
* the mesh) closest to that model's aft-belly AABB corner. Three things follow
* from that construction, and each is asserted rather than described in
* modelScale.test.mjs:
*
* ON THE HULL. This is the correction that matters. The previous round put
* the anchor ON the AABB corner itself, reasoning that an anchor aft of
* every vertex makes non-intersection geometric. It does — but an AABB
* corner is EMPTY SPACE, and on these airframes it is a long way from
* any of them: 4.80 m out for airplane.glb and 6.14 m for jet.glb in
* native units, which at the 450 m framing is a visible gap between the
* aircraft and the end of its own trail. The trail must terminate on the
* aeroplane, so the anchor is a surface point.
*
* AFT. The head segment is drawn from a point behind the aircraft to this
* anchor, so an anchor near the middle makes the segment enter at the
* tail and stop mid-fuselage — a line drawn through the airframe. These
* sit at 83–96 % of each model's aft extreme, on the aft-most hull the
* centreline has.
*
* BELOW. Nothing of the aircraft is lower than the anchor at or behind its
* own station, so the trail leaves from underneath the way a wake does
* rather than out of the roof. On most assets that is a frank belly
* point; on jet.glb the aft centreline profile has swept up into the
* tail cone by then, so the anchor sits just above the model's vertical
* centre (+0.13 native on a 5.63 m half-height) at the exhaust — which
* is where a fast jet's wake leaves it anyway.
*
* Y stays on the centreline — the profile is sliced at y = 0 rather than taking
* the nearest surface point in the round — so the attachment cannot drift
* screen-left or screen-right as the aircraft turns. (The unconstrained nearest
* point would put jet.glb's anchor 1.29 m off-axis.) Values are native model
* units; callers scale them by Cesium's effective `computedScale`.
*
* Locked against the shipped GLBs by modelScale.test.mjs, which re-reads the
* POSITION buffers and re-derives every property above — re-measure, never
* re-guess, when an asset changes.
*/
export const MODEL_TRAIL_ANCHOR_NATIVE = Object.freeze({
'/models/airplane.glb': Object.freeze([24.0879, -2.2163, 0]),
'/models/jet.glb': Object.freeze([18.9103, 0.1266, 0]),
'/models/bell206.glb': Object.freeze([5.2077, -0.0005, 0]),
'/models/c172.glb': Object.freeze([3.6816, -0.2425, 0]),
'/models/citation2.glb': Object.freeze([6.8804, -0.6136, 0]),
'/models/mq9.glb': Object.freeze([5.1951, -1.1516, 0]),
'/models/b789.glb': Object.freeze([30.1007, -3.4814, 0]),
'/models/atr72.glb': Object.freeze([12.9785, -1.2935, 0]),
});
/** @constant Cesium's OWN axis correction for a glTF loaded with the
* `Model.fromGltfAsync` defaults (upAxis Y, forwardAxis Z), assembled from its
@@ -134,27 +75,6 @@ export function modelAnchorWorld(model, nativeAnchor, result) {
return Cesium.Matrix4.multiplyByPoint(_chainScratch, _anchorScratch, result);
}
/**
* Return the model-local visual centre for an approved bundled GLB.
* Assets absent from the table were audited as origin-centred.
* @param {string} url Bundled model URL.
* @returns {readonly number[]} Cesium-local `[x, y, z]` native-unit offset.
*/
export function visualCenterForModel(url) {
return MODEL_VISUAL_CENTER_NATIVE[url] || CENTERED_MODEL;
}
/**
* Return the model-local aft-belly attachment point for a tracked trail.
* Unknown future assets safely fall back to their visual centre until their
* geometry is measured and added to the table.
* @param {string} url Bundled model URL.
* @returns {readonly number[]} Cesium-local `[x, y, z]` native-unit offset.
*/
export function trailAnchorForModel(url) {
return MODEL_TRAIL_ANCHOR_NATIVE[url] || visualCenterForModel(url);
}
/**
* Where a trail head segment should START being drawn: the whole segment, a
* shortened piece of it, or nothing at all.
@@ -171,7 +91,7 @@ export function trailAnchorForModel(url) {
* mistake matters:
*
* - Testing segment LENGTH against the radius hid real trail. With
* `airplane.glb`'s 34.41 m radius and 24.09 m tail anchor, a prior fix 58 m
* an airliner model's 34.41 m radius and 24.09 m tail anchor, a prior fix 58 m
* aft gives a 33.98 m segment — under the radius, so suppressed — even
* though ~23.6 m of it is in open air behind the aircraft. It also made the
* whole segment pop in at once on crossing ~58.4 m.
+135
View File
@@ -0,0 +1,135 @@
/**
* @module openVesselPhoto
* @description Reads an Open Vessel Photos answer into the one photo every
* surface shows. Open Vessel Photos (https://openvesselphotos.org) serves a
* free, keyless JSON and image API by MMSI. Every photo keeps the open licence
* its author chose (CC BY, CC BY-SA, CC0 or public domain), so it is shown
* with its credit and licence and links back to the vessel's page. A photo
* whose image is not on Open Vessel Photos' own host, or whose answer names
* no licence, is "no photo": nothing arbitrary is ever shown or linked.
*
* Accepts the upstream answer (`GET https://openvesselphotos.org/v1/mmsi/{mmsi}`,
* `{mmsi, photos: [...]}`) and an already-read photo
* (`{found, src, width, height, photographer, licence, link}`).
* Pure: no fetch, no DOM.
*/
/** The only host a photo may come from or link to. */
const HOST = 'openvesselphotos.org';
/** The API's per-vessel answer. */
const API = `https://${HOST}/v1/mmsi/`;
/** The image width asked for: sharp in the panel on a 2× screen, ~60 KB. */
const IMAGE_SIZE = '800';
const NO_PHOTO = Object.freeze({ found: false });
/** A vessel's MMSI: nine digits. */
export const MMSI = /^\d{9}$/;
/** The API answer for one MMSI. */
export function openVesselPhotosUrl(mmsi) {
return API + mmsi;
}
/** The vessel's page on Open Vessel Photos. */
function vesselPage(mmsi) {
return `https://${HOST}/vessels/mmsi/${mmsi}`;
}
/** The parsed `https:` URL on the Open Vessel Photos host, or null. */
function ownUrl(value) {
if (typeof value !== 'string' || !value) return null;
let url;
try {
url = new URL(value);
} catch {
return null;
}
return url.protocol === 'https:' &&
!url.username &&
!url.password &&
!url.port &&
url.hostname === HOST
? url
: null;
}
function dimension(value) {
const number = Number(value);
return value != null && Number.isFinite(number) && number > 0
? Math.round(number)
: null;
}
function text(value) {
return typeof value === 'string' ? value.trim() : '';
}
/** One upstream photo of the vessel `mmsi`, checked. */
function checkedUpstream(photo, mmsi) {
if (!photo || typeof photo !== 'object') return null;
const image = ownUrl(photo.urls?.mmsi);
const licence = text(photo.licenceName) || text(photo.licence);
if (!image || !licence) return null;
image.search = '';
image.hash = '';
image.searchParams.set('size', IMAGE_SIZE);
// The answer gives the full image's size; the 800 px one keeps its shape.
const width = dimension(photo.width);
const height = dimension(photo.height);
const scale =
width && width > Number(IMAGE_SIZE) ? Number(IMAGE_SIZE) / width : 1;
return {
found: true,
src: image.href,
width: width ? Math.round(width * scale) : null,
height: height ? Math.round(height * scale) : null,
photographer: text(photo.credit),
licence,
link: vesselPage(mmsi),
};
}
/** An already-read photo, checked again. */
function checkedRead(photo) {
const image = ownUrl(photo.src);
const page = ownUrl(photo.link);
const licence = text(photo.licence);
if (!image || !page || !licence) return null;
return {
found: true,
src: image.href,
width: dimension(photo.width),
height: dimension(photo.height),
photographer: text(photo.photographer),
licence,
link: page.href,
};
}
/**
* Read an Open Vessel Photos answer into the first photo that passes the
* checks.
* @param {*} payload Upstream answer or already-read photo.
* @param {?string} [requestedMmsi] The MMSI asked for; an upstream answer
* naming another is no photo.
* @returns {{found: true, src: string, width: ?number, height: ?number,
* photographer: string, licence: string, link: string} | {found: false}}
*/
export function parseOpenVesselPhoto(payload, requestedMmsi = null) {
if (!payload || typeof payload !== 'object') return NO_PHOTO;
if (Array.isArray(payload.photos)) {
const mmsi = String(payload.mmsi ?? '');
if (!MMSI.test(mmsi)) return NO_PHOTO;
// An answer about another vessel is no photo of this one.
if (requestedMmsi != null && mmsi !== String(requestedMmsi))
return NO_PHOTO;
for (const photo of payload.photos) {
const checked = checkedUpstream(photo, mmsi);
if (checked) return checked;
}
return NO_PHOTO;
}
if (payload.found !== true) return NO_PHOTO;
return checkedRead(payload) || NO_PHOTO;
}
+120
View File
@@ -0,0 +1,120 @@
// src/data/openVesselPhoto.test.mjs — an Open Vessel Photos answer is read
// into one credited, licensed photo, and nothing outside Open Vessel Photos'
// own host is ever shown or linked.
import test from 'node:test';
import assert from 'node:assert/strict';
import {
openVesselPhotosUrl,
parseOpenVesselPhoto,
} from './openVesselPhoto.js';
const UPSTREAM = Object.freeze({
mmsi: '366999709',
name: '01 USCGC Sockeye WPB87337',
photos: [
{
n: 1,
urls: {
cfr: null,
mmsi: 'https://openvesselphotos.org/v1/mmsi/366999709/photos/1.jpg',
},
credit: 'Gordon Leggett',
licence: 'CC-BY-4.0',
licenceName: 'CC BY 4.0',
width: 1600,
height: 1200,
},
],
});
const PHOTO = Object.freeze({
found: true,
src: 'https://openvesselphotos.org/v1/mmsi/366999709/photos/1.jpg?size=800',
width: 800,
height: 600,
photographer: 'Gordon Leggett',
licence: 'CC BY 4.0',
link: 'https://openvesselphotos.org/vessels/mmsi/366999709',
});
const withPhoto = (overrides) => ({
...UPSTREAM,
photos: [{ ...UPSTREAM.photos[0], ...overrides }],
});
test('the upstream answer maps to the 800 px image, its credit, licence and page', () => {
assert.deepEqual(parseOpenVesselPhoto(UPSTREAM), PHOTO);
assert.equal(
openVesselPhotosUrl('366999709'),
'https://openvesselphotos.org/v1/mmsi/366999709',
);
});
test('an image narrower than 800 px keeps its own size', () => {
const photo = parseOpenVesselPhoto(withPhoto({ width: 640, height: 480 }));
assert.equal(photo.width, 640);
assert.equal(photo.height, 480);
});
test('an already-read photo passes through its checks again', () => {
assert.deepEqual(parseOpenVesselPhoto(PHOTO), PHOTO);
assert.deepEqual(parseOpenVesselPhoto({ ...PHOTO, licence: '' }), {
found: false,
});
});
test('a photo off the Open Vessel Photos host, or without a licence, is no photo', () => {
for (const overrides of [
{ urls: { mmsi: 'https://example.com/1.jpg' } },
{
urls: {
mmsi: 'http://openvesselphotos.org/v1/mmsi/366999709/photos/1.jpg',
},
},
{ urls: { mmsi: 'https://openvesselphotos.org.evil.com/1.jpg' } },
{ urls: { mmsi: 'https://[email protected]/1.jpg' } },
{ licence: '', licenceName: '' },
])
assert.deepEqual(parseOpenVesselPhoto(withPhoto(overrides)), {
found: false,
});
assert.deepEqual(
parseOpenVesselPhoto({ ...PHOTO, link: 'https://example.com/' }),
{ found: false },
);
});
test('a vessel without photos, or an answer with a bad MMSI, is no photo', () => {
assert.deepEqual(parseOpenVesselPhoto({ ...UPSTREAM, photos: [] }), {
found: false,
});
assert.deepEqual(parseOpenVesselPhoto({ ...UPSTREAM, mmsi: '12/../x' }), {
found: false,
});
assert.deepEqual(parseOpenVesselPhoto(null), { found: false });
});
test('the next photo stands in when the first fails its checks', () => {
const second = {
...UPSTREAM.photos[0],
n: 2,
urls: {
mmsi: 'https://openvesselphotos.org/v1/mmsi/366999709/photos/2.jpg',
},
};
const photo = parseOpenVesselPhoto({
...UPSTREAM,
photos: [{ ...UPSTREAM.photos[0], licenceName: '', licence: '' }, second],
});
assert.equal(
photo.src,
'https://openvesselphotos.org/v1/mmsi/366999709/photos/2.jpg?size=800',
);
});
test('an answer about another vessel than the one asked for is no photo', () => {
assert.deepEqual(parseOpenVesselPhoto(UPSTREAM, '366999709'), PHOTO);
assert.deepEqual(parseOpenVesselPhoto(UPSTREAM, '227000101'), {
found: false,
});
});
+19 -6
View File
@@ -45,6 +45,18 @@ import militaryFlightsLayer, {
} from './militaryFlights.js';
import { clearTr3bRegistry, setTr3b } from './tr3bRegistry.js';
import { reportMeshFloorCell, _clearMeshFloorCellsForTest } from './groundFloor.js';
import { loadFleetModelSet } from './fleetModels.js';
import { aircraftLayerModelSpec } from '../layers/flights/modelSpec.js';
import { fetchPublicFile } from '../testSupport/fleetGlb.mjs';
// The layers draw only once the fleet model set has loaded; load it from disk.
// Model creation itself is stubbed per test through Cesium.Model.fromGltfAsync.
const _silentInfo = console.info;
console.info = () => {};
await loadFleetModelSet({ fetchImpl: fetchPublicFile });
console.info = _silentInfo;
const FLIGHTS_META = Object.freeze({ typeCode: 'A320', klass: 'airliner' });
const MILITARY_META = Object.freeze({ typeCode: 'F16', klass: 'fastjet' });
// Sample altitudes are expressed RELATIVE to the band rather than as absolute
// offsets. The thresholds have already been retuned once (1_000_000 → 150_000
@@ -201,7 +213,8 @@ const LAYERS = [
driveFleetModel: flightsDriveFleetModel,
ensureFleetModel: flightsEnsureFleetModel,
trackedBillboardColor: flightsTrackedBillboardColor,
bellyM: 6.719,
/** How far a grounded A320 stands its origin above the ground (scaled wheel clearance). */
bellyM: aircraftLayerModelSpec(FLIGHTS_META).bellyM,
seed({ viewer, tracked = true, icao24 = ICAO, modelCollection = null, onGround = false, models = [] }) {
const billboard = contactBillboard();
_setTrackedFlightRefreshStateForTest({
@@ -213,7 +226,7 @@ const LAYERS = [
tracked,
models,
modelCollection,
meta: { callsign: 'TEST123 ', altitude: 10_668, klass: 'airliner', onGround },
meta: { callsign: 'TEST123 ', altitude: 10_668, ...FLIGHTS_META, onGround },
});
return billboard;
},
@@ -226,7 +239,7 @@ const LAYERS = [
driveFleetModel: militaryDriveFleetModel,
ensureFleetModel: militaryEnsureFleetModel,
trackedBillboardColor: militaryTrackedBillboardColor,
bellyM: 5.631 * 0.8,
bellyM: aircraftLayerModelSpec(MILITARY_META).bellyM,
seed({ viewer, tracked = true, icao24 = ICAO, modelCollection = null, onGround = false, models = [] }) {
const billboard = contactBillboard();
_setTrackedMilitaryRefreshStateForTest({
@@ -238,7 +251,7 @@ const LAYERS = [
tracked,
models,
modelCollection,
meta: { callsign: 'TEST123 ', altitudeFt: 35_000, klass: 'fastjet', onGround },
meta: { callsign: 'TEST123 ', altitudeFt: 35_000, ...MILITARY_META, onGround },
});
return billboard;
},
@@ -841,8 +854,8 @@ for (const fixture of LAYERS) {
Date.now = () => now;
let attempts = 0;
const requested = [];
Cesium.Model.fromGltfAsync = ({ url }) => {
attempts++; requested.push(url);
Cesium.Model.fromGltfAsync = ({ basePath }) => {
attempts++; requested.push(basePath);
return Promise.reject(new Error('simulated missing GLB'));
};
// The give-up path warns once by design; keep the run's output clean.