mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Task 11a. The military flights logic no longer imports Cesium: it draws
through the shared aircraft renderer (src/layers/aircraft/render/cesium.js)
with the military's parameters in src/layers/military/render/cesium.js
(sprite-order slot 'military', jet.glb's 180° nose offset), registered for
'cesium' in the renderer registry and created at init(viewer, {engine}).
The same pure move as flights in 10a:
- Fleet: the BillboardCollection and its sprite-order slot (enable keeps
restoreSpriteOrder, as before); sprites stay Billboard handles.
- Models: fleet/tracked/preload glTF loads (asynchronous:false, MIX tint at
MODEL_COLOR_BLEND_AMOUNT, IR boost as `unlit` → the UNLIT CustomShader),
the model collection, setPose. The per-class specs keep their own nose
offset: setPose takes an optional offsetDeg (default the layer's), on
both aircraft renderers (same arithmetic, test added).
- Tracked: the ENU billboard Entity with its position/colour/rotation
callbacks (#FFD166, transparent amber once the model owns the visual),
viewFrom, followed through viewer.trackedEntity + the one exact tracked
frame; refocusTrackedById through follow.refocus.
- Trail: the entity trail and the floored live head segment.
- View: camera/scene reads, frame number, frustum and horizon tests,
render requests, frame events.
- Clicks and Escape go through the engine's selection dispatcher (the
ScreenSpaceEventHandler and keydown listener are gone); the cross-layer
untrack watches the renderer's follow. Same rules: cockpit clicks are
inert, the tracked visual/model is a no-op, another layer's pick is not
empty space, an unowned pick is.
- Colours are engine-neutral Rgba (MIL_ICON_COLOR #FFB800,
TRACKED_ICON_COLOR #FFD166, AMBER_TRANSPARENT), NearFarScalar →
nearFarScale; Cesium math → src/geo.
- check-import-directions: src/layers/military/ joins the rendered layers
(cesium only in render/cesium*.js).
- The military registry and the flights' duplicate suppression are
untouched.
Source-text tests updated with the moved code, same meaning:
- militaryAwareness.test: military's hasContact guard reads fleet.visible().
- trackingClickGesture.test: the military gesture rules are the
dispatcher's (selection gesture before select, click classifier before
the empty-space clear), military answers the empty click with a
user-origin clear — the same assertion flights already had.
- ownership.test: the services fixture names selection and renderer; the
app-composed services build the layer's Cesium renderer.
- renderers.test: flights and military have extracted Cesium renderers.
New tests: the military logic over a plain-data renderer and a fake engine
(amber fleet, click-select, #FFD166 tracked glyph, no-op on the tracked
visual, empty-click and Escape release, the keyboard left on destroy); the
plain-data renderer moved to src/testSupport for both aircraft layers;
setPose with a per-model offset.
W1 replay vs 7c7422e2 (the 10a reference run): every layer's counts, known
objects, screen points, tracking pose after 2 s, requests and the
city/global/orbit shots (sha256) identical. qa-military-names (it checks
the installations layer): the same verdict as 7c7422e2 (the zoom-markers
assertion fails on both). Main chunk 2,890,763 B (−2.9 KB).
161 lines
6.7 KiB
JavaScript
161 lines
6.7 KiB
JavaScript
// The aircraft renderer: what the aircraft layers' logic (flights now,
|
|
// military and local ADS-B after it) asks of an engine to draw a fleet of
|
|
// aircraft, its 3D models, the tracked aircraft, its trail, and to follow it.
|
|
// render/cesium.js implements it over Cesium (the objects the layers used
|
|
// to build themselves, one for one); render/navara.js implements it on the
|
|
// Navara engine over engine.movers / engine.lines / engine.camera.follow.
|
|
// Nothing here imports an engine.
|
|
//
|
|
// The logic holds HANDLES and writes plain fields on them; the field names
|
|
// are Cesium's (the extraction is a pure move), and an engine other than
|
|
// Cesium implements them as setters:
|
|
//
|
|
// SpriteHandle (fleet.add) — one aircraft glyph:
|
|
// position (Cartesian3), show, rotation (screen angle, rad),
|
|
// scale, width, height (CSS px), color ({red, green, blue, alpha} with
|
|
// withAlpha(); an Rgba of src/layers/shared/color.js or what the engine
|
|
// stored), image (canvas or URL), scaleByDistance ({near, nearValue,
|
|
// far, farValue}), id. Reads return what was last written (color and
|
|
// scaleByDistance as the engine's own copy). The logic may keep its own
|
|
// bookkeeping fields on a handle (prefixed _gev).
|
|
// ModelHandle (models.load*) — one glTF instance:
|
|
// show, ready (read-only), scale, computedScale (read-only: scale after
|
|
// minimumPixelSize), color, id, modelMatrix (16 numbers, column-major,
|
|
// written by models.setPose and read for anchors), sceneGraph? (Cesium).
|
|
// TrackedHandle (tracked.create) — the selected aircraft's glyph and the
|
|
// follow target: viewFrom (ENU offset, read), and the annotation fields
|
|
// the shell reads: gevSelectionOrigin, gevTrackedId, gevLabelModel,
|
|
// gevDisplayPosition(), gevVisualPosition().
|
|
// Trail (trails.create): setPositions(Cartesian3[]), setVisible(bool),
|
|
// clear(), destroy(). TrailHead (trails.createHead): show (bool).
|
|
//
|
|
// The view: what the logic reads of the camera and the frame. `camera` is
|
|
// camera-shaped (positionWC, positionCartographic, directionWC, upWC,
|
|
// rightWC, heading, pitch, roll, frustum.fovy) and `scene` scene-shaped
|
|
// ({ camera, canvas.clientHeight, frameState.frameNumber }) for the shared
|
|
// helpers that take them (iconOrientation, focusDeemphasis); on Navara
|
|
// they are adapters over engine.camera.pose(), with the engine registered
|
|
// for the scene (engineFromViewer) so projections go through its projector.
|
|
|
|
/**
|
|
* @typedef {object} AircraftView
|
|
* @property {object} camera
|
|
* @property {object} scene
|
|
* @property {() => number} frameNumber One value per rendered frame.
|
|
* @property {() => number} viewportHeightPx
|
|
* @property {() => ((position: object) => boolean)} frustumTester For this
|
|
* frame: is a point (1 m sphere) inside or on the view frustum.
|
|
* @property {() => { isPointVisible(position: object): boolean }} horizon
|
|
* For this frame: the ellipsoid horizon test.
|
|
* @property {(position: object, result?: object) => ({x: number, y: number} | undefined)} worldToWindow
|
|
* @property {() => void} requestRender
|
|
* @property {(event: 'preRender'|'preUpdate'|'moveEnd', listener: Function) => () => void} on
|
|
* @property {object} surfaceOwner What groundSnap/meshFloor sample through
|
|
* (a viewer registered with its engine, or the engine).
|
|
* @property {object} surfaceScene What sampleMeshFloorCells takes.
|
|
* @property {() => void} holdFrames Evidence capture: stop the engine's own
|
|
* frame loop (QA only).
|
|
* @property {() => void} closeFrameLatch Evidence capture, one task later:
|
|
* let manual renders start without waiting for the loop's next frame.
|
|
* @property {() => void} releaseFrames
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} AircraftRenderer
|
|
* @property {'cesium'|'navara'} kind
|
|
* @property {object|null} engine The globe engine (null in unit tests that
|
|
* drive a bare viewer).
|
|
* @property {AircraftView} view
|
|
* @property {object} fleet attach(), detach(), attached(), visible(),
|
|
* setVisible(bool), add(spec) → SpriteHandle, remove(sprite),
|
|
* restoreOrder(), restoreOrderOnEnable().
|
|
* @property {object} models live(), setVisible(bool), loadFleet(spec),
|
|
* loadTracked(spec), preload(url) → Promise<ModelHandle>, add(model),
|
|
* remove(model), destroy(model), setPose(model, position, headingDeg,
|
|
* offsetDeg?) (offsetDeg: the model's nose offset, default the layer's).
|
|
* spec: { url, minimumPixelSize, scale, color, blendAmount, unlit, id }.
|
|
* @property {object} tracked create(spec) → TrackedHandle, remove(handle),
|
|
* isLive(handle), setImage(handle, image), setViewFrom(handle, enu),
|
|
* billboardSize(handle) → { width, height, scale, scaleByDistance } | null.
|
|
* spec: { image, width, height, scale, scaleByDistance,
|
|
* disableDepthTestDistance, position(), color() → colour, rotation() }.
|
|
* @property {object} follow start(handle) → stop, refocus(handle) → stop,
|
|
* release(), isFollowing(handle), current(), onChanged(listener) → remove.
|
|
* @property {object} trails create({ color, width }) → Trail,
|
|
* createHead({ id, show, positions() → Cartesian3[], color, width }) →
|
|
* TrailHead, removeHead(head).
|
|
* @property {(objects: { sprites: Iterable, models: Iterable }) => object[]} surfaceExclusions
|
|
* What a vertical surface probe must not hit: the layer's own drawings.
|
|
* @property {() => void} destroy
|
|
*/
|
|
|
|
/** The members every aircraft renderer has (shape checks, tests). */
|
|
export const AIRCRAFT_RENDERER_SHAPE = Object.freeze({
|
|
view: [
|
|
'frameNumber',
|
|
'viewportHeightPx',
|
|
'frustumTester',
|
|
'horizon',
|
|
'worldToWindow',
|
|
'requestRender',
|
|
'on',
|
|
'holdFrames',
|
|
'closeFrameLatch',
|
|
'releaseFrames',
|
|
],
|
|
fleet: [
|
|
'attach',
|
|
'detach',
|
|
'attached',
|
|
'visible',
|
|
'setVisible',
|
|
'add',
|
|
'remove',
|
|
'restoreOrder',
|
|
'restoreOrderOnEnable',
|
|
],
|
|
models: [
|
|
'live',
|
|
'setVisible',
|
|
'loadFleet',
|
|
'loadTracked',
|
|
'preload',
|
|
'add',
|
|
'remove',
|
|
'destroy',
|
|
'setPose',
|
|
],
|
|
tracked: [
|
|
'create',
|
|
'remove',
|
|
'isLive',
|
|
'setImage',
|
|
'setViewFrom',
|
|
'billboardSize',
|
|
],
|
|
follow: [
|
|
'start',
|
|
'refocus',
|
|
'release',
|
|
'isFollowing',
|
|
'current',
|
|
'onChanged',
|
|
],
|
|
trails: ['create', 'createHead', 'removeHead'],
|
|
});
|
|
|
|
/**
|
|
* The members of AIRCRAFT_RENDERER_SHAPE that `renderer` lacks
|
|
* (['group.member', …]); empty for a complete renderer.
|
|
*/
|
|
export function missingAircraftRendererMembers(renderer) {
|
|
const missing = [];
|
|
for (const key of ['kind', 'view', 'surfaceExclusions', 'destroy'])
|
|
if (renderer?.[key] === undefined) missing.push(key);
|
|
for (const [group, members] of Object.entries(AIRCRAFT_RENDERER_SHAPE))
|
|
for (const member of members)
|
|
if (typeof renderer?.[group]?.[member] !== 'function')
|
|
missing.push(`${group}.${member}`);
|
|
return missing;
|
|
}
|