feat(flights): aircraft draw life-size fleet models chosen by type

Flights, Military Flights and Local ADS-B draw each aircraft with the fleet
model its ICAO type, class or emitter category selects, scaled to the type's
length, built from the up-front loaded bytes. The eight third-party aircraft
models and their attribution are removed; every shipped model is now the
project's own.
This commit is contained in:
Sameh Khamis committed 2026-11-13 07:16:25 -08:00
1 parent f6760ad96c
commit fcc44d0eaf
45 files changed
+970 -1371

No files matched your search

+10 -28
View File
@@ -1,5 +1,5 @@
import * as Cesium from 'cesium';
import { JET_MODEL_URL } from './policy.js';
import { loadFleetModelSet } from '../../data/fleetModels.js';
export function createLifecycle({
flightState,
@@ -47,29 +47,19 @@ export function createLifecycle({
registerSpriteCollection('military', flightState._billboardCollection);
flightState._modelCollection = new Cesium.PrimitiveCollection();
viewer.scene.primitives.add(flightState._modelCollection);
// Warm the glTF cache so the tracked plane's model instantiates instantly when first needed
// (keeps the retained instance referenced; never rendered). Captured against this epoch so a
// destroy/re-init mid-load doesn't flip the flag for a torn-down lifecycle.
if (!flightState._preloadModel) {
// Every fleet model loads once, up front, for every layer that draws
// them (fleetModels.js), so no model is fetched while the session runs.
// Captured against this epoch so a destroy/re-init mid-load doesn't flip
// the flag for a torn-down lifecycle.
{
const epoch = flightState._modelEpoch;
Cesium.Model.fromGltfAsync({
url: resolveAsset(JET_MODEL_URL),
asynchronous: false,
})
.then((m) => {
if (epoch === flightState._modelEpoch) {
flightState._preloadModel = m;
loadFleetModelSet({ resolveAsset })
.then(() => {
if (epoch === flightState._modelEpoch)
flightState._planeModelLoaded = true;
} else {
try {
m.destroy();
} catch {
/* gone */
}
}
})
.catch(() => {
/* tracked plane just stays a billboard a beat longer */
/* aircraft stay billboards */
});
}
flightState._billboards = new Map();
@@ -269,14 +259,6 @@ export function createLifecycle({
flightState._modelEpoch += 1; // invalidate any in-flight load from this lifecycle (settles post-destroy)
flightState._modelPending.clear();
flightState._modelGen.clear();
if (flightState._preloadModel) {
try {
flightState._preloadModel.destroy();
} catch {
/* gone */
}
flightState._preloadModel = null;
}
flightState._planeModelLoaded = false;
flightState._billboards.clear();
flightState._cullPositions.clear();
+4 -4
View File
@@ -301,7 +301,7 @@ export function createMotion({
const rangeM = Cesium.Cartesian3.distance(camera.positionWC, position);
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,
@@ -459,7 +459,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.modelMatrix,
@@ -502,7 +502,7 @@ export function createMotion({
)
return 0;
const spec = parts.rendering._modelSpec(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
);
const scale = Number.isFinite(flightState._trackedModel.computedScale)
? flightState._trackedModel.computedScale
@@ -519,7 +519,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 =
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 = MIL_ICON_COLOR.withAlpha(0);
+1 -3
View File
@@ -484,9 +484,7 @@ export function createQueries({
// contacts read the translation the fleet tick already wrote into their
// modelMatrix; sprite-owned contacts keep `bb.position`, where sprite 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() || bb.position
: modelOwnsVisual
+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,
+45 -79
View File
@@ -1,12 +1,9 @@
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 { createFleetModel } from '../../data/fleetModelInstances.js';
import * as Cesium from 'cesium';
import { selectModelEligible } from '../../data/modelEligibility.js';
import { cyberSonarBaseAlpha } from '../../cyberSonar.js';
@@ -20,14 +17,6 @@ import {
import { limitCourseStep, courseSlewCapDps } from '../../data/motionModel.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,
@@ -83,48 +72,20 @@ export function createRendering({
return Number.POSITIVE_INFINITY;
}
function _modelSpec(klass) {
let spec = flightState._specCache.get(klass);
/** The fleet model an aircraft draws with, by its type and emitter category
* (shared with flights.js), 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,
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,
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,
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;
}
@@ -312,7 +273,7 @@ export function createRendering({
Cesium.Ellipsoid.WGS84,
flightState._scratchGroundCarto,
);
carto.height = h + _modelSpec(meta.klass).bellyM;
carto.height = h + _modelSpec(meta).bellyM;
return Cesium.Cartesian3.fromRadians(
carto.longitude,
carto.latitude,
@@ -350,7 +311,7 @@ export function createRendering({
displayPos,
course,
model.modelMatrix,
_modelSpec(flightState.records.data.get(icao24)?.klass).headingOffsetDeg,
_modelSpec(flightState.records.data.get(icao24)).headingOffsetDeg,
);
if (!model.ready) {
model.show = false; // not loaded yet → keep the 2D icon, no half-model flash
@@ -385,20 +346,17 @@ export function createRendering({
return !!model && model.ready === true && model.show === true;
}
/** Spec identity for a LOADED model — mirror of flights.js: URL and scale
* together (same-URL classes differ by scale). */
/** Spec identity for a LOADED model — mirror of flights.js: the model and
* its scale together. */
const _specKeyFor = (klass) => {
const spec = _modelSpec(klass);
return `${spec.url}@${spec.scale}`;
};
const _specKeyFor = (meta) => _modelSpec(meta).key;
/** Class-change model sync — mirror of flights.js: drop a live model or
* in-flight load whose spec no longer matches the class, re-showing the
/** Type-change model sync — mirror of flights.js: drop a live model or
* in-flight load whose spec no longer matches the type, re-showing the
* fleet billboard FIRST (gap-proof) and covering the tracked standalone. */
function _syncModelToClass(icao24) {
const key = _specKeyFor(flightState.records.data.get(icao24)?.klass);
const key = _specKeyFor(flightState.records.data.get(icao24));
const current = flightState._models.get(icao24);
if (
(current && current._gevSpecKey !== key) ||
@@ -445,6 +403,11 @@ export function createRendering({
/** Lazily create the glTF model for an aircraft (fire-and-forget; billboard shows until ready). */
/** A Cesium Model of `spec` from the fleet set loaded up front (no fetch mid-session). */
function _createModel(spec, options) {
return createFleetModel(spec, options, { resolveAsset });
}
async function _ensureModel(icao24) {
// Never model the TRACKED aircraft — it owns a separate entity billboard, and the fleet
// tick skips it, so a model here would be orphaned + double-rendered.
@@ -461,6 +424,8 @@ export function createRendering({
_modelCap()
)
return;
// Until the fleet model set has loaded the aircraft stays a billboard.
if (!_modelSpec(flightState.records.data.get(icao24)).model) return;
const epoch = flightState._modelEpoch; // lifecycle token: if destroy() bumps it, this load is dead
const gen = flightState._modelGen.get(icao24) || 0; // capture; if it changes during the load, we're stale
flightState._modelPending.add(icao24);
@@ -468,12 +433,11 @@ export function createRendering({
// Spec identity captured at load START (mirror of flights.js): a mid-load
// reclassification makes the post-await admission reject the stale asset.
// Boost state likewise — creation options bake it in.
const specKey = _specKeyFor(flightState.records.data.get(icao24)?.klass);
const specKey = _specKeyFor(flightState.records.data.get(icao24));
const loadIrBoost = flightState._irBoost;
try {
const spec = _modelSpec(flightState.records.data.get(icao24)?.klass);
model = await Cesium.Model.fromGltfAsync({
url: resolveAsset(spec.url),
const spec = _modelSpec(flightState.records.data.get(icao24));
model = await _createModel(spec, {
asynchronous: false,
environmentMapOptions: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS,
minimumPixelSize: MODEL_MIN_PX,
@@ -522,7 +486,7 @@ export function createRendering({
flightState._models.has(icao24) ||
flightState._models.size >= _modelCap() ||
// Class reclassified mid-load → this GLB/scale is for the OLD class.
_specKeyFor(flightState.records.data.get(icao24)?.klass) !== specKey ||
_specKeyFor(flightState.records.data.get(icao24)) !== specKey ||
// IR boost flipped mid-load → this model baked the wrong shader/tint.
flightState._irBoost !== loadIrBoost;
if (stale) {
@@ -676,6 +640,9 @@ export function createRendering({
return;
}
if (
// Until the fleet model set has loaded the billboard carries it.
_modelSpec(flightState.records.data.get(flightState._trackedIcao))
.model &&
!flightState._trackedModel &&
!flightState._trackedModelLoading &&
parts.tracking._trackedModelLoadAllowed()
@@ -683,14 +650,13 @@ export function createRendering({
flightState._trackedModelLoading = true;
const gen = flightState._trackedModelGen;
const trackedSpec = _modelSpec(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
);
const trackedKey = _specKeyFor(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
);
const trackedIrBoost = flightState._irBoost;
Cesium.Model.fromGltfAsync({
url: resolveAsset(trackedSpec.url),
_createModel(trackedSpec, {
asynchronous: false,
environmentMapOptions: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS,
minimumPixelSize: TRACKED_MODEL_MIN_PX,
@@ -724,7 +690,7 @@ export function createRendering({
// _trackedModel was still null): drop the stale asset; driver reloads.
if (
_specKeyFor(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
) !== trackedKey ||
flightState._irBoost !== trackedIrBoost
) {
@@ -793,7 +759,7 @@ export function createRendering({
return;
}
const spec = _modelSpec(
flightState.records.data.get(flightState._trackedIcao)?.klass,
flightState.records.data.get(flightState._trackedIcao),
);
_modelMatrix(
displayPos,
+9 -4
View File
@@ -164,10 +164,15 @@ export function createMilitarySnapshotRenderer({
) {
rendering._applyFleetBillboardPresentation(icao24, bb);
}
// 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);
// Round 5: depth policy is uniform (always depth-test-free, see
// _groundDepthDistance) — nothing to flip on landing/takeoff.
} else {
+9 -16
View File
@@ -19,15 +19,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();
@@ -76,16 +74,11 @@ export function createFlightState({ source, services }) {
// throttle the "more planes in view than the cap" console notice
// The tracked entity's billboard goes transparent (rather than hidden) once the model takes
// over, so it keeps supplying a bounding sphere for follow-camera framing. We only drop its
// alpha after the GLB is preloaded so the model is ready to render the instant the billboard
// fades — no gap, no double-image. Preloaded once at init; the instance is retained (not
// destroyed) purely to keep Cesium's glTF cache warm for fast tracked-model instantiation.
// alpha after the fleet model set is loaded so the model is ready to render the instant the
// billboard fades — no gap, no double-image. The set loads once at init (fleetModels.js).
flightState._planeModelLoaded = false;
/** @type {Cesium.Model|null} retained preload that keeps the glTF cache warm */
flightState._preloadModel = null;
flightState._scratchModelHpr = new Cesium.HeadingPitchRoll(0, 0, 0);
flightState._scratchModelMtx = new Cesium.Matrix4();