Files
gods-eye-view/src/layers/flights/modelSpec.js
T
Sameh Khamis a44c42eb94 fix(vessels, transit, rail): fleet models keep their cards and detection, stand on the floor, clip ships at the waterline and follow NVG/FLIR
- a vehicle drawn as a model keeps its selected card and stays in the detection overlay
- transit and rail models drop the 1.5 m floor lift their icons carry
- vessel models are clipped below the waterline
- models switch to an unlit white look under NVG/FLIR and back
- unknown transit modes keep their icon
- aircraft model specs are cached per set; no key-array copies per frame
2026-11-13 07:16:25 -08:00

71 lines
2.5 KiB
JavaScript

import { aircraftModelSpec, fleetModelSet } from '../../data/fleetModels.js';
import { MODEL_COLOR_BLEND_AMOUNT } from './policy.js';
/**
* What an aircraft draws with before the fleet model set has loaded: no
* model (its billboard stays the visual), with neutral geometry for any
* reader that asks.
*/
export const UNLOADED_AIRCRAFT_MODEL_SPEC = Object.freeze({
model: null,
url: null,
scale: 1,
scaleXYZ: Object.freeze([1, 1, 1]),
length: 0,
nativeRadiusM: 20,
clearanceM: 0,
bellyM: 0,
elevationM: 0,
tinted: false,
blendAmount: MODEL_COLOR_BLEND_AMOUNT,
visualCenterNative: Object.freeze([0, 0, 0]),
trailAnchorNative: Object.freeze([0, 0, 0]),
key: 'unloaded',
});
/**
* The fleet model, life-size scale and measured geometry an aircraft draws
* with, chosen by its ICAO type and emitter category (`fleetModels.js`).
* Shared by the Flights, Military Flights and Local ADS-B layers so all three
* draw the same model for the same aircraft. `bellyM` is the model's scaled
* clearance: how far a grounded aircraft's origin stands above the ground.
* @param {{typeCode?: string|null, type?: string|null,
* category?: string|number|null}|null|undefined} aircraft
* @param {object|null} [set] The loaded fleet model set.
* @returns {object} The spec, or {@link UNLOADED_AIRCRAFT_MODEL_SPEC} before
* the set has loaded.
*/
export function aircraftLayerModelSpec(aircraft, set = fleetModelSet()) {
if (!set) return UNLOADED_AIRCRAFT_MODEL_SPEC;
// Layers ask on every tick; each type and category is resolved once per set.
let cache = specCaches.get(set);
if (!cache) specCaches.set(set, (cache = new Map()));
const key = aircraftModelSpecCacheKey(aircraft);
let layerSpec = cache.get(key);
if (!layerSpec) {
const spec = aircraftModelSpec(set, {
typeCode: aircraft?.typeCode ?? aircraft?.type ?? null,
category: aircraft?.category ?? null,
});
layerSpec = Object.freeze({
...spec,
bellyM: spec.clearanceM,
blendAmount: MODEL_COLOR_BLEND_AMOUNT,
});
cache.set(key, layerSpec);
}
return layerSpec;
}
/** @type {WeakMap<object, Map<string, object>>} set -> cache key -> spec */
const specCaches = new WeakMap();
/**
* Cache key of an aircraft's model spec: what selects its model.
* @param {object|null|undefined} aircraft
* @returns {string}
*/
export function aircraftModelSpecCacheKey(aircraft) {
return `${aircraft?.typeCode ?? aircraft?.type ?? ''}|${aircraft?.category ?? ''}`;
}