Merge origin/main into the renderer-contract branch: the procedural fleet models drawn through the renderer's model sets

Aircraft, military, local ADS-B, vessel, transit and rail models come from
the fleet model set, loaded up front and drawn life size through the draw
port's models sets; no layer touches the viewer or Cesium outside
src/render/cesium/. The models capability gains glTF bytes (gltf), a
per-axis stretch (axisScale), a colour for tinted parts (maskColor) and a
cut below the origin (clip: 'belowOrigin'), with conformance checks.

Main's rail layer and Data Library are ported to the ports; the CCTV
footprint probe keeps the globe-terrain clamp through the query port.
This commit is contained in:
Sameh Khamis committed 2026-11-13 14:14:42 -08:00
commit e3865f462f
533 files changed
+55738 -2518

No files matched your search

+3 -3
View File
@@ -167,10 +167,10 @@ export function createEnrichment({
if (klass !== meta.klass) {
meta.klass = klass;
parts.icons._applyIconPresentation(icao24);
// Hangar fleet: the class's GLB/scale may have changed — resync the
// live model, any in-flight load, and the tracked standalone model.
parts.rendering._syncModelToClass(icao24);
}
// The type picks the fleet model and its length — resync the live
// model, any in-flight load, and the tracked standalone model.
parts.rendering._syncModelToClass(icao24);
}
if (icao24 === flightState._trackedIcao && flightState._trackedEntity)
parts.tracking._updateTrackedLabelModel(icao24);
+7 -5
View File
@@ -1,5 +1,5 @@
import { findCamera, findFrame } from '../../render/rendererOf.js';
import { PLANE_MODEL_URL } from './policy.js';
import { loadFleetModelSet } from '../../data/fleetModels.js';
export function createLifecycle({
flightState,
@@ -44,10 +44,12 @@ export function createLifecycle({
flightState._focusEvidenceIds.clear();
flightState._viewer = viewer;
parts.icons._createIcons(viewer);
// The models' draw sets; a hidden item keeps the tracked asset loaded so
// the tracked plane's model draws as soon as it is wanted.
parts.rendering._createModelSets(viewer, {
preloadUrl: resolveAsset(PLANE_MODEL_URL),
// The models' draw sets. Every fleet model loads once, up front, for
// every layer that draws them (fleetModels.js), so no model is fetched
// while the session runs; until the set has loaded aircraft stay icons.
parts.rendering._createModelSets(viewer);
loadFleetModelSet({ resolveAsset }).catch(() => {
/* aircraft stay icons */
});
flightState._grounded.clear();
flightState._floorPinned.clear();
+64 -46
View File
@@ -1,52 +1,70 @@
import {
CLASS_MODEL_REAL,
CLASS_MODEL_URL,
CLASS_SCALE_3D,
} from '../../data/aircraftClass.js';
import {
trailAnchorForModel,
visualCenterForModel,
} from '../../data/modelVisualAnchor.js';
import {
MODEL_BELLY_OFFSET_NATIVE,
MODEL_COLOR_BLEND_AMOUNT,
MODEL_NATIVE_RADIUS_M,
MODEL_SCALE,
PLANE_MODEL_URL,
} from './policy.js';
import { aircraftModelSpec, fleetModelSet } from '../../data/fleetModels.js';
import { MODEL_COLOR_BLEND_AMOUNT } from './policy.js';
/**
* The glTF asset, scale and measured geometry a civil aircraft class renders
* with. Real per-class GLBs are baked to real-world meters (scale 1, measured
* belly and radius); classes without one share airplane.glb at the class's
* 3D scale. Shared by the Flights layer and the Local ADS-B layer so both draw
* the same model for the same class.
* @param {string} klass Aircraft class from `classifyAircraft`.
* @returns {{url:string, scale:number, nativeRadiusM:number, bellyM:number,
* blendAmount:number, visualCenterNative:object, trailAnchorNative:object}}
* 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 function civilAircraftModelSpec(klass) {
const real = CLASS_MODEL_REAL[klass];
if (real) {
return {
url: real.url,
scale: 1,
nativeRadiusM: real.radiusM,
bellyM: real.bellyM,
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,
visualCenterNative: visualCenterForModel(real.url),
trailAnchorNative: trailAnchorForModel(real.url),
};
});
cache.set(key, layerSpec);
}
const scale = MODEL_SCALE * (CLASS_SCALE_3D[klass] || 1);
const url = CLASS_MODEL_URL[klass] || PLANE_MODEL_URL;
return {
url,
scale,
nativeRadiusM: MODEL_NATIVE_RADIUS_M,
bellyM: MODEL_BELLY_OFFSET_NATIVE * scale,
blendAmount: MODEL_COLOR_BLEND_AMOUNT,
visualCenterNative: visualCenterForModel(url),
trailAnchorNative: trailAnchorForModel(url),
};
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 ?? ''}`;
}
+4 -4
View File
@@ -373,7 +373,7 @@ export function createMotion({
const viewportHeightPx = _viewportHeightPx();
if (parts.rendering._modelOwnsVisual(icao24)) {
const spec = parts.rendering._modelSpec(
flightState.records.data.get(icao24)?.klass,
flightState.records.data.get(icao24),
);
const scale = trackedModelScaleForPixelCap({
baseScale: spec.scale,
@@ -549,7 +549,7 @@ export function createMotion({
parts.rendering._modelOwnsVisual(flightState._trackedIcao)
) {
const spec = parts.rendering._modelSpec(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
);
return modelVisualAnchor(
flightState._trackedModel.matrix,
@@ -594,7 +594,7 @@ export function createMotion({
)
return 0;
const spec = parts.rendering._modelSpec(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
);
return (
spec.nativeRadiusM *
@@ -608,7 +608,7 @@ export function createMotion({
parts.rendering._modelOwnsVisual(flightState._trackedIcao)
) {
const spec = parts.rendering._modelSpec(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
);
// Through the model's OWN render chain (modelVisualAnchor's hand-rolled
// half-correction put this offset on the lateral axis — see
+20 -17
View File
@@ -44,8 +44,6 @@ export const GROUND_SCALE = 0.8;
// the slots go to either the nearest planes ('proximity') or every in-view plane ('all'), each
// backed by a hard cap so a draw-call explosion can't tank the frame (no instancing yet).
export const PLANE_MODEL_URL = '/models/airplane.glb';
export const MODEL_ALT_CEIL_M = 800000;
// m: below this camera altitude, draw 3D models (raised so it's easy to trigger)
@@ -60,10 +58,6 @@ export const TRACKED_MODEL_MIN_PX = 40;
export const TRACKED_MODEL_MAX_PX = 200;
// owner-selected close-range tracked-target feel
export const MODEL_NATIVE_RADIUS_M = 34.41;
export const MODEL_SCALE = 1;
// airplane.glb is transform-applied and baked to real-world meters
// Per-mode caps. Each model is its own draw call (no instancing yet), so these bound the frame cost.
export const MODEL_MAX = 150;
@@ -95,21 +89,12 @@ export const MODEL_ALL_KEEP_M = 450000;
// all: KEEP modeled planes out to 450 km
export const MODEL_HEADING_OFFSET_DEG = 180;
// airplane.glb nose is opposite the renderer's heading 0
// every fleet model is nose -X: opposite the renderer's heading 0
// Owner launch-polish direction: models should read as clean light silhouettes,
// with only a weak diffuse contribution from the existing approved textures.
// with only a weak diffuse contribution from the models' own colours.
export const MODEL_COLOR_BLEND_AMOUNT = 0.94;
// Grounded-model belly offset: airplane.glb's centred origin sits 6.719 m ABOVE its
// lowest vertex (glTF Y-up scene AABB with node transforms applied — same reader as
// modelScale.test.mjs, measured after its 24× transform bake). × class multiplier ≈ 5.0–9.7 m
// of lift, so a ground-snapped model rests its lowest geometry (gear/belly) ON the sampled
// tile skin instead of sinking to the fuselage-centerline origin. Locked against the GLB
// by modelScale.test.mjs.
export const MODEL_BELLY_OFFSET_NATIVE = 6.719;
/** The tracked contact's tint, and its billboard once a model takes over. */
export const TRACKED_CYAN = rgba('#00FFFF');
export const CYAN_TRANSPARENT = rgba('#00FFFF', 0);
@@ -210,6 +195,24 @@ export const LANDED_SPEED_MAX_MPS = 23;
export const FLEET_DR_INTERVAL_MS = 80;
/**
* The icon-to-model rules the aircraft layers follow, as the Vessels, Transit
* and Rail layers take them (`createFleetModelLayer`): the same altitude
* ceiling, minimum pixel size, proximity/all caps, add/keep radii and
* eligibility cadence, so every layer turns icons into models at one distance.
*/
export const FLEET_MODEL_POLICY = Object.freeze({
altitudeCeilingM: MODEL_ALT_CEIL_M,
minimumPixelSize: MODEL_MIN_PX,
cap: MODEL_MAX,
capAll: MODEL_MAX_ALL,
addM: MODEL_PROX_ADD_M,
addAllM: MODEL_ALL_ADD_M,
keepM: MODEL_PROX_KEEP_M,
keepAllM: MODEL_ALL_KEEP_M,
intervalMs: FLEET_DR_INTERVAL_MS,
});
/** Max course slew (deg/s) — well above real turns (≤4°/s), hides fix-boundary
* steps. Scaled down toward COURSE_MIN_DPS at low speed (courseSlewCapDps). */
+1 -3
View File
@@ -474,9 +474,7 @@ export function createQueries({
// and rises only as the coarse ground-floor cell warms. Zero extra sampling and
// no `_modelDisplayPosition` call from postRender. Icon-owned contacts keep
// the drawn icon position — icon and bracket are co-located there.
const spec = modelOwnsVisual
? parts.rendering._modelSpec(info?.klass)
: null;
const spec = modelOwnsVisual ? parts.rendering._modelSpec(info) : null;
const pos = isTracked
? parts.motion._trackedVisualCached() ||
icons.position(icao24, t, object._iconPos)
+11 -5
View File
@@ -1,4 +1,7 @@
import { civilAircraftModelSpec } from './modelSpec.js';
import {
aircraftLayerModelSpec,
aircraftModelSpecCacheKey,
} from './modelSpec.js';
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
import { isEmergency } from '../../data/aircraftEmergency.js';
import {
@@ -59,11 +62,14 @@ export function createRendering({
);
}
function _modelSpec(klass) {
const cached = flightState._specCache.get(klass);
/** The fleet model an aircraft draws with, by its type and emitter category. */
function _modelSpec(meta) {
const key = aircraftModelSpecCacheKey(meta);
const cached = flightState._specCache.get(key);
if (cached) return cached;
const spec = civilAircraftModelSpec(klass);
flightState._specCache.set(klass, spec);
const spec = aircraftLayerModelSpec(meta);
// Not cached before the model set loads: the answer changes once it has.
if (spec.model) flightState._specCache.set(key, spec);
return spec;
}
+8 -3
View File
@@ -175,9 +175,14 @@ export function createFlightSnapshotRenderer({
// style; motion re-plans from the updated history.
icons._applyIconPresentation(icao24);
icons._planIcon(icao24);
// Poll-path class change (category updates): same model resync rule
// as the enrichment path — the class's GLB/scale may have changed.
if (prevMeta?.klass !== meta.klass) rendering._syncModelToClass(icao24);
// Poll-path type or category change: same model resync rule as the
// enrichment path — the fleet model or its scale may have changed.
if (
prevMeta?.klass !== meta.klass ||
prevMeta?.category !== meta.category ||
prevMeta?.typeCode !== meta.typeCode
)
rendering._syncModelToClass(icao24);
} else {
// Hidden while tracked: the tracked entity replaces it.
icons._addIcon(icao24);
+7 -11
View File
@@ -18,17 +18,13 @@ export function createFlightState({ source, services }) {
* layer); see followsClock and displayDelayMs in policy.js. */
flightState.timeline = null;
/** Per-class model spec. Hangar-fleet classes (CLASS_MODEL_REAL) ship GLBs
* vertex-baked to real-world METERS in the airplane.glb axis convention, so
* they render at scale 1 with their own measured belly lift and bounding
* radius. Every other class keeps the shared-airplane.glb formula
* (MODEL_SCALE × CLASS_SCALE_3D). nativeRadiusM is PER SCALE UNIT — pixel-cap
* math multiplies it by `scale`, so world radius = nativeRadiusM × scale in
* both branches. The code-side MIX tint dominates every existing asset so
* class silhouettes stay light without modifying third-party GLBs/textures. */
/* Specs are static per class, and the detection weld now asks for one per
* MODELED contact per frame (up to the fleet cap) on top of the 12 Hz fleet
* pass — so this is memoized, as militaryFlights.js already does. */
/** Model spec per aircraft type and emitter category (aircraftLayerModelSpec in
* flights/modelSpec.js): the procedural fleet model that draws the type, life size,
* with its measured clearance, bounding radius and trail anchor. nativeRadiusM is PER
* SCALE UNIT — pixel-cap math multiplies it by `scale`. The code-side MIX tint dominates
* every model so silhouettes stay light (and this layer's own colour). Memoized: the
* detection weld asks for one per MODELED contact per frame on top of the 12 Hz fleet
* pass. */
flightState._specCache = new Map();
+4 -4
View File
@@ -65,10 +65,10 @@ export function createTesting({
*/
/** Turn a test's model fields into the contact's model record, in place. */
function _modelRecordForTest(fields, klass) {
const spec = parts.rendering._modelSpec(klass);
function _modelRecordForTest(fields, meta) {
const spec = parts.rendering._modelSpec(meta);
const base = createModelRecord({
specKey: parts.rendering._specKeyFor(klass),
specKey: parts.rendering._specKeyFor(meta),
bellyM: spec.bellyM,
scale: spec.scale,
});
@@ -110,7 +110,7 @@ export function createTesting({
_seedIconForTest(icao24, icon, tracked);
flightState._models.clear();
for (const [key, model] of models)
flightState._models.set(key, _modelRecordForTest(model, meta?.klass));
flightState._models.set(key, _modelRecordForTest(model, meta));
flightState._detectionObjects = new Map();
flightState.records.data = new Map([[icao24, meta]]);
flightState._positionHistory = new Map([[icao24, history]]);