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

+7 -5
View File
@@ -1,5 +1,5 @@
import { findCamera, findFrame } from '../../render/rendererOf.js';
import { JET_MODEL_URL } from './policy.js';
import { loadFleetModelSet } from '../../data/fleetModels.js';
export function createLifecycle({
flightState,
@@ -42,10 +42,12 @@ export function createLifecycle({
clearFocusTarget('militaryFlights');
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(JET_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._iconFocusActive = 0;
flightState._detectionObjects = new Map();
+4 -4
View File
@@ -273,7 +273,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,
@@ -424,7 +424,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,
@@ -467,7 +467,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 *
@@ -484,7 +484,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
+7 -41
View File
@@ -58,20 +58,18 @@ export const EMERGENCY_ICON_COLOR = rgba(EMERGENCY_TINT_CSS);
export const GROUND_SCALE = 0.8;
// --- 3D model rendering (mirrors flights.js) -----------------------------------------
// When enabled, military aircraft render as 3D glTF jet models once the camera is below
// When enabled, military aircraft render as 3D glTF models once the camera is below
// MODEL_ALT_CEIL_M (zoomed in); higher up they stay flat billboards. Eligibility is
// FRUSTUM-based (on-screen), and 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). Distinct asset + amber tint set this layer
// apart from the commercial flights layer.
export const JET_MODEL_URL = '/models/jet.glb';
// can't tank the frame (no instancing yet). Each aircraft draws the fleet model of its
// type, as the flights layer does; the amber tint sets this layer apart.
export const MODEL_ALT_CEIL_M = 800000;
// m: below this camera altitude, draw 3D models (raised so it's easy to trigger)
export const MODEL_MIN_PX = 24;
// floor so distant models stay visible without ballooning into a min-pixel blob (mirror of flights.js, whose models now share this layer's ~30 m world size)
// floor so distant models stay visible without ballooning into a min-pixel blob (mirror of flights.js)
export const TRACKED_MODEL_MIN_PX = 40;
// keep the glTF silhouette comparable to the selected 2D glyph at handoff
@@ -79,17 +77,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 = 29.83;
// jet.glb is transform-applied at real-world scale — native bounding radius
// 29.83 m at scale 1. ×1 → ~22–43 m aircraft across CLASS_SCALE_3D, matching
// flights.js world sizes. At the old copied ×24, models rendered
// 600–1000 m across (invisible at the ~6 km follow range where minimumPixelSize
// dominates, but zoom under ~1 km put the camera INSIDE the plane). Locked by
// modelScale.test.mjs.
export const MODEL_SCALE = 1;
// Per-mode caps + radii — mirror of flights.js. Modes differ by RADIUS (not just cap) so Proximity
// and All aren't identical when few planes are in range; on-screen planes win the cap (see flights.js).
@@ -119,33 +106,12 @@ export const MODEL_ALL_KEEP_M = 450000;
// all: KEEP modeled planes out to 450 km
export const MODEL_HEADING_OFFSET_DEG = 180;
// every aircraft GLB is exported nose -X in the shared transform-applied convention
// Preserve the layer's amber identity while reducing approved texture/livery
// contribution to a weak diffuse hint, matching civilian launch presentation.
// every fleet model is nose -X: opposite Cesium heading 0
// Preserve the layer's amber identity while reducing the models' own colours
// to a weak diffuse hint, matching civilian launch presentation.
export const MODEL_COLOR_BLEND_AMOUNT = 0.94;
// airplane.glb (the shared 747) constants for this layer's heavy classes. The
// asset has its former 24× runtime calibration baked into transform-applied
// meter-scale geometry; these values mirror flights.js and are regression-pinned.
export const PLANE_MODEL_URL = '/models/airplane.glb';
export const PLANE_MODEL_SCALE = 1;
export const PLANE_NATIVE_RADIUS_M = 34.41;
export const PLANE_BELLY_OFFSET_NATIVE = 6.719;
// Grounded-model belly offset: jet.glb's centred origin sits 5.631 native units (= meters — this
// asset is real-world scale) ABOVE its lowest vertex (glTF Y-up scene AABB with node
// transforms applied — same reader as modelScale.test.mjs, measured 2026-07-03).
// × MODEL_SCALE(1) × class multiplier ≈ 4.4–8.6 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 = 5.631;
/** Amber fade target for the tracked billboard once the model takes over (mirrors flights.js CYAN_TRANSPARENT). */
export const AMBER_TRANSPARENT = rgba('#FFB800', 0);
+1 -3
View File
@@ -474,9 +474,7 @@ export function createQueries({
// contacts read the translation the fleet tick already wrote into their
// modelMatrix; icon-owned contacts keep the drawn icon position, where icon and
// bracket are co-located anyway.
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)
+2
View File
@@ -181,6 +181,8 @@ export class MilitaryFlightRecords {
newestFixMs: this._noteFix(icao24, prevMeta, fixEpochMs),
callsign: stickyText(callsign, prevMeta?.callsign),
type: stickyType,
// The emitter category, kept for the fleet model a type-less row draws.
category: aircraft?.category ?? prevMeta?.category ?? null,
// Type outranks category automatically inside classifyAircraft.
klass: classifyAircraft({
typeCode: stickyType,
+17 -60
View File
@@ -1,22 +1,10 @@
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
import {
CLASS_MODEL_REAL,
CLASS_SCALE_3D,
CLASS_SCALE_2D,
} from '../../data/aircraftClass.js';
import {
visualCenterForModel,
trailAnchorForModel,
} from '../../data/modelVisualAnchor.js';
aircraftLayerModelSpec,
aircraftModelSpecCacheKey,
} from '../flights/modelSpec.js';
import { isEmergency } from '../../data/aircraftEmergency.js';
import {
PLANE_MODEL_SCALE,
PLANE_MODEL_URL,
PLANE_NATIVE_RADIUS_M,
PLANE_BELLY_OFFSET_NATIVE,
MODEL_SCALE,
JET_MODEL_URL,
MODEL_NATIVE_RADIUS_M,
MODEL_BELLY_OFFSET_NATIVE,
MODEL_HEADING_OFFSET_DEG,
BILLBOARD_SCALE,
GROUND_SCALE,
@@ -37,51 +25,20 @@ export function createRendering({
}) {
const { tr3bIconKind } = services.aircraftPresentation;
function _modelSpec(klass) {
let spec = flightState._specCache.get(klass);
/** The fleet model an aircraft draws with, by its type and emitter category
* (shared with the flights layer), in this layer's own tint. */
function _modelSpec(meta) {
const key = aircraftModelSpecCacheKey(meta);
let spec = flightState._specCache.get(key);
if (spec) return spec;
const real = CLASS_MODEL_REAL[klass];
if (real) {
spec = {
url: real.url,
scale: 1,
nativeRadiusM: real.radiusM,
bellyM: real.bellyM,
headingOffsetDeg: 180,
blendAmount: MODEL_COLOR_BLEND_AMOUNT,
visualCenterNative: visualCenterForModel(real.url),
trailAnchorNative: trailAnchorForModel(real.url),
};
} else if (
klass === 'airliner' ||
klass === 'quadjet' ||
klass === 'glider'
) {
const scale = PLANE_MODEL_SCALE * (CLASS_SCALE_3D[klass] || 1);
spec = {
url: PLANE_MODEL_URL,
scale,
nativeRadiusM: PLANE_NATIVE_RADIUS_M,
bellyM: PLANE_BELLY_OFFSET_NATIVE * scale,
headingOffsetDeg: 180,
blendAmount: MODEL_COLOR_BLEND_AMOUNT,
visualCenterNative: visualCenterForModel(PLANE_MODEL_URL),
trailAnchorNative: trailAnchorForModel(PLANE_MODEL_URL),
};
} else {
const scale = MODEL_SCALE * (CLASS_SCALE_3D[klass] || 1);
spec = {
url: JET_MODEL_URL,
scale,
nativeRadiusM: MODEL_NATIVE_RADIUS_M,
bellyM: MODEL_BELLY_OFFSET_NATIVE * scale,
headingOffsetDeg: MODEL_HEADING_OFFSET_DEG,
blendAmount: MODEL_COLOR_BLEND_AMOUNT,
visualCenterNative: visualCenterForModel(JET_MODEL_URL),
trailAnchorNative: trailAnchorForModel(JET_MODEL_URL),
};
}
flightState._specCache.set(klass, spec);
const base = aircraftLayerModelSpec(meta);
spec = Object.freeze({
...base,
blendAmount: MODEL_COLOR_BLEND_AMOUNT,
headingOffsetDeg: MODEL_HEADING_OFFSET_DEG,
});
// Not cached before the model set loads: the answer changes once it has.
if (spec.model) flightState._specCache.set(key, spec);
return spec;
}
+9 -4
View File
@@ -145,10 +145,15 @@ export function createMilitarySnapshotRenderer({
// style; motion re-plans from the updated history.
icons._applyIconPresentation(icao24);
icons._planIcon(icao24);
// Per-class GLBs: a class change can mean a different asset OR scale —
// resync the live model, any in-flight load, and the tracked
// standalone (mirror of flights.js).
if (prevMeta?.klass !== meta.klass) rendering._syncModelToClass(icao24);
// Per-type fleet models: a type or category change can mean a
// different model OR scale — resync the live model, any in-flight
// load, and the tracked standalone (mirror of flights.js).
if (
prevMeta?.klass !== meta.klass ||
prevMeta?.type !== meta.type ||
prevMeta?.category !== meta.category
)
rendering._syncModelToClass(icao24);
} else {
// Hidden while tracked: the tracked entity replaces it.
icons._addIcon(icao24);
+7 -9
View File
@@ -17,15 +17,13 @@ export function createFlightState({ source, services }) {
* layer); see followsClock and displayDelayMs in policy.js. */
flightState.timeline = null;
/** Per-class model spec for THIS layer (2026-08-16, owner playtest ask:
* military contacts should read as their WEIGHT CLASS, always in this layer's
* amber). Real Hangar GLBs serve the classes they cover (meters, nose −X →
* 180° offset); airliner/quadjet/glider get the shared 747 silhouette
* (airplane.glb — C-5M/RC-135-style heavies stop rendering as bizjets);
* fastjet and unknown keep jet.glb with the same 180° offset. The MIX tint stays
* dominant everywhere — military is amber, tracked is TRACKED_ICON_COLOR,
* and the tint must dominate any livery (owner: "stays yellow"). Specs are
* static per class — memoized (the fleet pass asks at 12 Hz per model). */
/** 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 in 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
@@ -37,10 +37,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,
});
@@ -80,7 +80,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]]);