mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Draw contact trails through the draw port
The shared trail renderer draws a trail's history and its live head as lines in a draw-port set, geodesic for the history and straight for the head, each dimmed behind the surface in its depth-fail colour, and leaves the Cesium allow-list. The flights and military trail heads are drawn through the trail each frame from the frame port instead of entity callbacks, and the local ADS-B head uses the same head line. A head given while its trail is hidden waits until the trail shows. Geodesic lines are cut a step a degree of arc, with at least 64 steps over the line, so a long trail of short legs costs its positions rather than 64 vertices a leg.
This commit is contained in:
1 parent
6bbe35f232
commit
8cefc8cc4a
12 files changed
+631
-350
No files matched your search
@@ -138,9 +138,10 @@ export function createLocalAdsbLayer({
|
||||
let viewer = null;
|
||||
/**
|
||||
* The layer's draw sets on its viewer's renderer (`drawOf`), made at
|
||||
* `init`: the markers, the 978 MHz rings and the selected aircraft's live
|
||||
* trail head. Shown while the layer is enabled.
|
||||
* @type {{markers: object, rings: object, head: object}|null}
|
||||
* `init`: the markers and the 978 MHz rings. Shown while the layer is
|
||||
* enabled. The selected aircraft's trail and its live head draw through
|
||||
* the shared trail renderer.
|
||||
* @type {{markers: object, rings: object}|null}
|
||||
*/
|
||||
let sets = null;
|
||||
let enabled = false;
|
||||
@@ -153,7 +154,6 @@ export function createLocalAdsbLayer({
|
||||
let renderHeld = false;
|
||||
let selectedId = null;
|
||||
let selectedTrail = null;
|
||||
let trailHeadSeq = 0;
|
||||
let models = null;
|
||||
let geoidReady = false;
|
||||
let rejectedFixes = 0;
|
||||
@@ -406,7 +406,6 @@ export function createLocalAdsbLayer({
|
||||
function releaseTrail() {
|
||||
if (!selectedTrail) return;
|
||||
selectedTrail.trail?.destroy();
|
||||
sets?.head.clear();
|
||||
selectedTrail = null;
|
||||
}
|
||||
|
||||
@@ -420,35 +419,24 @@ export function createLocalAdsbLayer({
|
||||
* costs nothing a frame.
|
||||
*/
|
||||
function drawTrailHead() {
|
||||
if (!sets || !selectedTrail?.headId) return;
|
||||
if (!selectedTrail?.trail?.setHead) return;
|
||||
const current = markers.get(selectedTrail.id);
|
||||
const from = selectedTrail.lastFix;
|
||||
const positions =
|
||||
current?.position && from ? [from, { ...current.position }] : [];
|
||||
const key = positions.map(({ x, y, z }) => `${x},${y},${z}`).join(';');
|
||||
if (key === selectedTrail.drawnKey) return;
|
||||
const at = now();
|
||||
if (
|
||||
positions.length &&
|
||||
from === selectedTrail.drawnFrom &&
|
||||
at - selectedTrail.drawnAt < HEAD_REDRAW_MS
|
||||
)
|
||||
return;
|
||||
selectedTrail.drawnKey = key;
|
||||
selectedTrail.drawnFrom = from;
|
||||
selectedTrail.drawnAt = at;
|
||||
sets.head.upsert([
|
||||
{
|
||||
// 'gev-trail' namespace: claimed by the trail pick owner so a click
|
||||
// on the head segment never reads as empty space.
|
||||
id: selectedTrail.headId,
|
||||
positions,
|
||||
widthPx: 2.5,
|
||||
// Metres to a few km: straight is the ellipsoid's arc to the pixel.
|
||||
mode: '3d',
|
||||
style: { kind: 'solid', color: hexColor(LOCAL_ADSB_COLOR, 0.9) },
|
||||
depthFailColor: hexColor(LOCAL_ADSB_COLOR, 0.45),
|
||||
},
|
||||
]);
|
||||
// The trail's head line: 'gev-trail' ids, claimed by the trail pick
|
||||
// owner so a click on it never reads as empty space; dimmed where the
|
||||
// surface hides it. A head that has not moved is not drawn again.
|
||||
selectedTrail.trail.setHead(positions);
|
||||
}
|
||||
|
||||
function refreshTrail() {
|
||||
@@ -464,15 +452,13 @@ export function createLocalAdsbLayer({
|
||||
function startTrail(marker) {
|
||||
releaseTrail();
|
||||
const createTrail = services.trails?.createTrail;
|
||||
if (typeof createTrail !== 'function' || !viewer || !sets) return;
|
||||
if (typeof createTrail !== 'function' || !viewer) return;
|
||||
selectedTrail = {
|
||||
id: marker.id,
|
||||
trail: createTrail(viewer, { color: LOCAL_ADSB_COLOR, width: 2.5 }),
|
||||
// Live head: last heard fix → the extrapolated marker, every frame.
|
||||
headId: `gev-trail:local-adsb-head-${++trailHeadSeq}`,
|
||||
lastFix: null,
|
||||
// Where, from which fix and when the head was last drawn.
|
||||
drawnKey: null,
|
||||
// From which fix and when the head was last drawn.
|
||||
drawnFrom: null,
|
||||
drawnAt: -Infinity,
|
||||
};
|
||||
@@ -772,7 +758,6 @@ export function createLocalAdsbLayer({
|
||||
show: false,
|
||||
pickable: false,
|
||||
}),
|
||||
head: draw.lines({ id: `${prefix}:trail-head`, show: false }),
|
||||
};
|
||||
models = createLocalAdsbModels({
|
||||
viewer,
|
||||
|
||||
@@ -445,6 +445,7 @@ test('selecting an aircraft draws a magenta trail of the fixes the receiver hear
|
||||
});
|
||||
|
||||
test('the trail head runs from the last fix to the marker every frame, dimmed behind the surface', async (t) => {
|
||||
const trails = await import('../../data/trailRenderer.js');
|
||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||
const clock = { now: 100_000 };
|
||||
const listeners = new Map();
|
||||
@@ -462,19 +463,24 @@ test('the trail head runs from the last fix to the marker every frame, dimmed be
|
||||
const input = fakeInput(viewer);
|
||||
const { layer } = await enabledLayer(receiver, clock, null, {
|
||||
viewer: { draw, viewer, input },
|
||||
services: {
|
||||
trails: {
|
||||
createTrail: () => ({ setPositions() {}, destroy() {} }),
|
||||
},
|
||||
},
|
||||
services: { trails },
|
||||
});
|
||||
t.after(() => layer.destroy());
|
||||
receiver.set({ aircraft: [record()] });
|
||||
await layer.update();
|
||||
assert.equal(layer.selectAircraft('abc123'), true);
|
||||
const heads = () => [...layerSet(draw, ':trail-head').items.values()];
|
||||
// The head is the shared trail's head line.
|
||||
const trailSet = () => draw.find('trail:');
|
||||
const heads = () =>
|
||||
[...(trailSet()?.items.values() ?? [])].filter(
|
||||
(line) => line.id.endsWith(':head') && line.show !== false,
|
||||
);
|
||||
// Selected at its fix, the head has no length yet.
|
||||
assert.equal(heads().length, 0);
|
||||
clock.now = 100_500;
|
||||
listeners.get('preRender')();
|
||||
const [head] = heads();
|
||||
assert.match(head.id, /^gev-trail:local-adsb-head-\d+$/);
|
||||
assert.match(head.id, /^gev-trail:\d+:head$/);
|
||||
assert.equal(head.mode, '3d');
|
||||
assert.equal(head.widthPx, 2.5);
|
||||
assert.deepEqual(head.style, {
|
||||
@@ -505,9 +511,9 @@ test('the trail head runs from the last fix to the marker every frame, dimmed be
|
||||
);
|
||||
|
||||
// A frame where nothing moved leaves the head alone.
|
||||
const writes = layerSet(draw, ':trail-head').writes;
|
||||
const writes = trailSet().writes;
|
||||
listeners.get('preRender')();
|
||||
assert.equal(layerSet(draw, ':trail-head').writes, writes);
|
||||
assert.equal(trailSet().writes, writes);
|
||||
|
||||
await layer.disable();
|
||||
assert.equal(listeners.has('preRender'), false, 'frames stop when off');
|
||||
@@ -889,7 +895,7 @@ test('the layer draws into sets of its own, shown while it is enabled and let go
|
||||
.filter((record) => !record.disposed)
|
||||
.map((record) => record.spec.id);
|
||||
const mine = ids(draw);
|
||||
assert.equal(mine.length, 3, 'markers, rings and the trail head');
|
||||
assert.equal(mine.length, 2, 'markers and rings');
|
||||
assert.ok(
|
||||
ids(other.draw).every((id) => !mine.includes(id)),
|
||||
'a second layer has ids of its own',
|
||||
|
||||
Reference in new issue
Block a user