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

+183
View File
@@ -0,0 +1,183 @@
import {
RAIL_SELECTED_OVERLAY_SOURCE_ID,
RAIL_SELECTED_OVERLAY_SOURCE_OPTIONS,
SELECTED_CARD_REFRESH_MS,
buildRailSelectionCopy,
createRailSelectedOverlayEntry,
} from './policy.js';
import { getRegisteredRailFeed } from '../../data/railFeeds.js';
import { inputFor } from '../../input/dispatcher.js';
import { t } from '../../i18n/index.js';
/**
* Click-to-select one train, a card that follows it, and the camera handed
* to it (follow.js). Escape or a click on anything else deselects it.
* @param {object} context
* @returns {object}
*/
export function createSelection({ state, services, parts }) {
const { governorRequestRender } = services.render;
/**
* The card's anchor: the marker's current position, read on every paint,
* whether the train is drawn as its marker or as its 3D model.
*/
function anchorFor(entry) {
return () => {
const drawn =
entry.marker?.show !== false || entry.modelOwnsVisual === true;
const p = drawn ? entry.marker?.position : null;
return p && Number.isFinite(p.x) && Number.isFinite(p.y) ? p : null;
};
}
function refreshSelectedCard(force) {
const entry = state._trains.get(state._selectedKey);
if (!entry) return;
const now = Date.now();
if (!force && now - state._selectedCardAt < SELECTED_CARD_REFRESH_MS)
return;
state._selectedCardAt = now;
const feed = getRegisteredRailFeed(entry.feedId);
if (!feed) return;
const copy = buildRailSelectionCopy(
feed,
entry.record,
now,
entry.fetchedAt,
entry,
t,
state._trip,
);
const text = JSON.stringify(copy);
if (!force && text === state._selectedCardText) return;
state._selectedCardText = text;
const card = createRailSelectedOverlayEntry(
entry.key,
anchorFor(entry),
copy,
entry.category,
);
state._overlayHost.setEntries(
RAIL_SELECTED_OVERLAY_SOURCE_ID,
card ? [card] : [],
RAIL_SELECTED_OVERLAY_SOURCE_OPTIONS,
);
}
/**
* Select a train without touching the camera. Called by a click (through
* selectAndFocusTrain) and by the duplicate filter, which moves the
* selection to another feed's copy of the same train; a follow on the old
* copy then glides to the new one.
* @param {string} key
*/
function selectTrain(key) {
if (!state._trains.has(key)) return;
const hadSelection = state._selectedKey !== null;
const previous = state._trains.get(state._selectedKey);
state._selectedKey = key;
const entry = state._trains.get(key);
if (previous && previous !== entry) parts.follow.handover(entry);
// The first selection dims every other train; a change of selection only
// swaps the two trains involved.
if (!hadSelection) parts.rendering.paintAll();
else {
if (previous) parts.rendering.paint(previous);
parts.rendering.paint(entry);
}
// Line and stops first, so the card is built with this trip's stops.
parts.routes.onSelectionChanged();
refreshSelectedCard(true);
// Its feed is polled for it at any distance from now on.
parts.viewport.requestProximityCheck();
governorRequestRender('rail-select');
}
/**
* Select the train the user picked and give it the camera (follow.js): a
* moving train is followed, any other flown to once. Picking the train
* already followed keeps the follow as it is.
* @param {string} key
*/
function selectAndFocusTrain(key) {
if (!state._trains.has(key)) return;
const following = parts.follow.isFollowing(key);
// Another train's follow lets go first, so this is never taken for a
// move between two copies of one train.
if (!following) parts.follow.release();
selectTrain(key);
if (!following) parts.follow.focus(state._trains.get(key));
}
/**
* Deselect, letting go of the camera where it is.
* @param {{untrack?: boolean}} [options] `untrack: false` when another
* camera owner took over and what the camera follows must stay.
*/
function clearSelection({ untrack = true } = {}) {
const hadSelection = state._selectedKey !== null;
parts.follow.release({ untrack });
state._selectedKey = null;
state._selectedCardText = null;
if (hadSelection) {
parts.rendering.paintAll();
parts.routes.onSelectionChanged();
// A feed held for the train goes back to the viewport's rules.
parts.viewport.requestProximityCheck();
}
state._overlayHost.setEntries(
RAIL_SELECTED_OVERLAY_SOURCE_ID,
[],
RAIL_SELECTED_OVERLAY_SOURCE_OPTIONS,
);
governorRequestRender('rail-deselect');
}
function onKeyDown(event) {
if (event.key === 'Escape' && state._selectedKey) clearSelection();
}
/**
* The train a click's hit names: one of this layer's icons, or a train's
* 3D model (its pick meta is the train's key); null for anything else.
*/
function trainKeyOf(hit) {
if (!hit) return null;
if (hit.set && hit.set === state._icons?.id)
return state._trains.has(hit.id) ? hit.id : null;
const meta = hit.meta;
return typeof meta === 'string' && state._trains.has(meta) ? meta : null;
}
function installClickHandler(viewer) {
if (state._clickSubscription) return;
// The dispatcher maps a sensor-style click back into the pick buffer
// and skips it while a tool holds the pointer.
state._clickSubscription = inputFor(viewer).onClick((event) => {
if (!state._enabled) return;
const key = trainKeyOf(event.drawHit);
if (key) selectAndFocusTrain(key);
else if (state._selectedKey) clearSelection();
});
globalThis.document?.addEventListener?.('keydown', onKeyDown);
parts.follow.install(viewer);
}
function removeClickHandler() {
state._clickSubscription?.();
state._clickSubscription = null;
globalThis.document?.removeEventListener?.('keydown', onKeyDown);
parts.follow.uninstall();
}
return {
refreshSelectedCard,
selectTrain,
selectAndFocusTrain,
clearSelection,
onKeyDown,
installClickHandler,
removeClickHandler,
};
}