Files
gods-eye-view/src/data/transitPresetStyle.js
T
Bilawal Sidhu 0bb61f53c6 fix(transit): keep the real silhouettes under sensor presets, make the selected trail visible, put Transit in Movement (#596)
## Changes

Follow-up to #587 after the owner's first look at the merged transit layer on Google 3D tiles.

- **Sensor presets keep the real silhouettes.** Under NVG, thermal (white-hot, black-hot, Ironbow) and noir, vehicles are the same silhouettes as in normal view, filled opaque white with a 2 px dark halo, at the CRT display sizes (26 px fleet, 39 px selected). The solid rounded "signature" bodies are gone.
- **The selected vehicle's trail is visible.** The retained history is now draped onto 3D tiles and terrain (`GroundPolylinePrimitive`, `ClassificationType.BOTH`, the way the traffic heat-lines are drawn), 3 px core over a 5 px dark backing, per-segment age colour, a short draped head clipped to the sprite. Two defects kept it off screen before: Cesium's per-instance attribute getters return copies, so the renderer's show/colour edits were discarded, and a marker did not recover after the camera jumped to it, which hid the trail with it. Trail geometry is now prepared on selection independent of floor resolution and marker visibility; sparse long intervals (rail) keep a bounded marker corridor instead of dropping the interval; classification survives map-source changes.
- **Transit sits in the Movement panel group** between Street Traffic and Bike Share (the panel orders by `PANEL_GROUPS`, not by catalog order; the catalog is moved too).

## How it was verified

- `npm run format:check` (854 files), `npm run check:boundaries`, `npm test` (4,062 passing), `npm run build` clean; tracking regression 109/109 in a real browser on Google 3D tiles.
- Browser harness (`scripts/qa-transit.mjs`), keyed on Google 3D tiles and keyless: keyed 194 pass, with the trail pixel check passing at 300, 600 and 900 m; the remaining keyed failures are the per-frame allocation gate already recorded as a follow-up from #587 (CPU and frame time within budget), four readability lines at threshold edges, and the card-anchor check now counting frames where the selected marker is legitimately off screen; keyless 193 pass with the remaining misses being threshold edges on the thin tram silhouette (centre 0.83–0.88 against 0.85) and one bus ring 0.28 against 0.25 on a pure-white roof.
- New harness checks: `Google 3D selected trail visible at 6 of 8 projected samples` (repeated off/on framebuffer captures at 300/600/900 m, samples outside the sprite footprint, a background-change negative control; fails on main, passes here), a camera-arrival check (select a moving vehicle, `setView` onto it, marker shown and trail body drawn within 2 s), `PANEL_ORDER` pinned, raster tests comparing every sensor raster's mask and aspect ratio to the normal silhouette.
- Direct look on a keyed build: a live CapMetro bus at 30 m/s selected through the layer API draws its draped trail along the highway lane (harness capture `keyed-600m-trail-visible.jpg`).
- Adversarial review by Codex Astra before the last two fix passes (stack-switch classification, marker corridor under the vertex cap, pixel-gate loophole), all three fixed with regressions.

Docs: `docs/CURRENT-STATE.md` and `CHANGELOG.md` updated in this PR. No data-source changes.
2026-09-15 13:26:41 -05:00

146 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file Preset-aware transit sprite styling — pure lookup tables mapping the
* active post-FX style to a sprite treatment the shaders cannot destroy, and
* the detection tier that carries each mode's colour above them.
*
* Why: transit sprites are in-scene billboards, so they pass THROUGH the
* post-FX chain. NVG and FLIR reduce the scene to luminance, and the mode
* palette's luma is middling — a green bus, a red metro and an amber tram all
* collapse to the same dim grey, on a road NVG's auto-gain has pushed to
* white. The owner's Boston test: "you can barely see these guys".
*
* Encoding per profile, the traffic-dot precedent applied to a glyph:
* - `mono` (surveillance/NVG, thermal/FLIR, noir, cockpit nvg/thermal): the
* sprite is WHITE — the hottest end of grayscale FLIR and of the Ironbow
* ramp, and the brightest phosphor under NVG — at CRT size, with a thin dark
* halo sized in SCREEN pixels so it keeps local contrast on a bright road
* through any luma mapping. Black-hot FLIR inverts it, deliberately: a
* black sprite with a light ring is what a hot object looks like there.
* - `crt` (retro): saturated per-mode colours that survive posterisation,
* a size boost to out-shout the pixel grid, and a thinner halo.
* - `normal` (normal/anime/snow/unknown): every lookup returns the shipped
* value — mode colour, shipped size, hairline edge only.
*
* Brackets are a different matter. The detection canvas composites ABOVE the
* post-FX chain, so a tier colour is literal screen RGB in every preset: the
* brackets carry the mode colour the sprites can no longer encode, the way
* traffic's brackets carry congestion. Tier colours per theme live in
* `src/overlays/worldOverlayTokens.js`.
*
* Cesium-free so the tables are unit-testable; the layer maps them to Cesium
* colours and billboard sizes at spawn and restyle time.
*
* @module data/transitPresetStyle
*/
/** @const {Object<string,'mono'|'crt'>} Style name → non-normal profile. */
const PROFILE_BY_STYLE = Object.freeze({
surveillance: 'mono', // NVG — P43 phosphor × luma
thermal: 'mono', // FLIR — grayscale/Ironbow × luma
noir: 'mono', // full desaturation
nvg: 'mono', // cockpit vision names its modes directly
retro: 'crt', // CRT — hue survives, small glyphs don't
});
/**
* Per-profile sprite treatment. `rgba` is [r,g,b] 0–255 + alpha 0–1;
* `scale` multiplies the shipped billboard size; `outlinePx` is the dark
* halo's width in FINAL SCREEN PIXELS, which is the only unit that means
* anything for a glyph rendered at eighteen pixels — the shipped 1.5-unit
* hairline in a 96-unit box is 0.28 px on screen, and vanishes.
*/
const SPRITE_STYLE = Object.freeze({
mono: Object.freeze({
rgba: Object.freeze([255, 255, 255, 1]),
scale: 1.3,
outlinePx: 2,
}),
crt: Object.freeze({
scale: 1.3,
outlinePx: 1.25,
rgbaByMode: Object.freeze({
bus: Object.freeze([0, 255, 102, 1]),
tram: Object.freeze([255, 179, 0, 1]),
subway: Object.freeze([255, 59, 48, 1]),
rail: Object.freeze([215, 139, 255, 1]),
ferry: Object.freeze([58, 208, 255, 1]),
unknown: Object.freeze([255, 255, 255, 1]),
}),
}),
});
/** Modes with a bracket tier of their own. */
const TIER_MODES = Object.freeze([
'bus',
'tram',
'subway',
'rail',
'ferry',
'unknown',
]);
/**
* Classify a style name into a transit styling profile.
* @param {string|null|undefined} styleName - Active style (e.g. 'thermal').
* @returns {'normal'|'mono'|'crt'} Styling profile; unknown → 'normal'.
*/
export function transitStyleProfile(styleName) {
return PROFILE_BY_STYLE[styleName] || 'normal';
}
/**
* Preset sprite colour, or null to keep the shipped mode colour.
* @param {string|null|undefined} styleName
* @param {string} mode Transit mode.
* @returns {number[]|null} [r,g,b,a] with rgb 0–255, alpha 0–1, or null.
*/
export function presetSpriteRgba(styleName, mode) {
const profile = transitStyleProfile(styleName);
if (profile === 'mono') return SPRITE_STYLE.mono.rgba;
if (profile === 'crt') {
return (
SPRITE_STYLE.crt.rgbaByMode[mode] || SPRITE_STYLE.crt.rgbaByMode.unknown
);
}
return null;
}
/**
* Multiplier a preset applies to the shipped billboard size.
* @param {string|null|undefined} styleName
* @returns {number} 1 under the normal profile.
*/
export function presetSpriteScale(styleName, selected = false) {
return SPRITE_STYLE[transitStyleProfile(styleName)]?.scale ?? 1;
}
/**
* Dark-halo width in final screen pixels, or 0 for the shipped hairline only.
* @param {string|null|undefined} styleName
* @returns {number}
*/
export function presetSpriteOutlinePx(styleName, selected = false) {
return (
SPRITE_STYLE[transitStyleProfile(styleName)]?.outlinePx ??
(selected ? 1.5 : 1)
);
}
/**
* Detection-overlay tier key for a transit mode. Every theme's `tiers`
* table carries these six, so the bracket colour is per mode in every
* preset. Unlike traffic, transit sets its tier keyless as well: the feeds
* are keyless, and there is no separate keyless experience to keep
* byte-identical.
* @param {string} mode
* @returns {string}
*/
export function transitModeTier(mode) {
return `transit_${TIER_MODES.includes(mode) ? mode : 'unknown'}`;
}
/** The tier keys this module can produce, for the tables that must carry them. */
export const TRANSIT_TIER_KEYS = Object.freeze(
TIER_MODES.map((mode) => `transit_${mode}`),
);