mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Read vessel, CCTV and FIRMS billboard state from the app's mirror
The three layers now add their billboards through addBillboard and write the mirrored fields through setBillboard, so selection, cards, queries, focus, view thinning and the FIRMS horizon cull read what was pushed from the app instead of from Cesium. Vessels and FIRMS state their sprites' own sizes (32 px ship artwork, the glow canvas at twice the core size), which the mirror needs. A vessel helper, iconPosition, replaces the repeated mirror-or-visual position lookups, and the vessel visibility pass writes show only when it changes, as CCTV and FIRMS already did. A billboard never given a position now has none in the mirror rather than the origin.
This commit is contained in:
1 parent
bb91688a62
commit
6639c4bb80
23 files changed
+152
-97
No files matched your search
@@ -61,9 +61,7 @@ export function createCards({
|
||||
return {
|
||||
id: vesselOverlayEntryId(record),
|
||||
actionable: Boolean(record?.mmsi),
|
||||
position:
|
||||
components.rendering.getVisual(record).billboard?.position ||
|
||||
components.rendering.getVisual(record).position,
|
||||
position: components.rendering.iconPosition(record),
|
||||
gapPx: 10,
|
||||
accent: accentForVesselType(record.type),
|
||||
title: trimHudValue(displayVesselName(record), 26),
|
||||
@@ -102,9 +100,7 @@ export function createCards({
|
||||
return {
|
||||
id: vesselOverlayEntryId(record),
|
||||
actionable: Boolean(record?.mmsi),
|
||||
position:
|
||||
components.rendering.getVisual(record).billboard?.position ||
|
||||
components.rendering.getVisual(record).position,
|
||||
position: components.rendering.iconPosition(record),
|
||||
gapPx: 12,
|
||||
accent: accentForVesselType(record.type),
|
||||
title: trimHudValue(displayVesselName(record), 32),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { FOCUS_EVIDENCE_DEV } from './policy.js';
|
||||
import { billboardState } from '../../data/billboardMirror.js';
|
||||
|
||||
export function createEvidence({
|
||||
vesselState,
|
||||
@@ -40,15 +41,16 @@ export function createEvidence({
|
||||
if (!FOCUS_EVIDENCE_DEV || !state.viewer) return [];
|
||||
return state.records.all.map((record) => {
|
||||
const bb = components.rendering.getVisual(record).billboard;
|
||||
const screen = bb?.position
|
||||
const icon = billboardState(bb);
|
||||
const screen = icon?.position
|
||||
? Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
state.viewer.scene,
|
||||
bb.position,
|
||||
icon.position,
|
||||
)
|
||||
: null;
|
||||
return {
|
||||
id: record.mmsi,
|
||||
show: bb?.show === true,
|
||||
show: icon?.show === true,
|
||||
alpha: bb?.color?.alpha ?? null,
|
||||
x: screen?.x ?? null,
|
||||
y: screen?.y ?? null,
|
||||
|
||||
@@ -292,7 +292,7 @@ test('refresh keeps pick identity and renderer geometry separate, and eviction r
|
||||
for (const key of ['position', 'surfacePosition', 'normal', 'billboard']) {
|
||||
assert.equal(Object.hasOwn(record, key), false);
|
||||
}
|
||||
assert.equal(layer.findByQuery('111').position, primitive.position);
|
||||
assert.deepEqual(layer.findByQuery('111').position, primitive.position);
|
||||
const oldPosition = primitive.position;
|
||||
current = snapshot([{ ...observation('111'), longitude: 4.06 }]);
|
||||
await layer.update();
|
||||
@@ -300,7 +300,7 @@ test('refresh keeps pick identity and renderer geometry separate, and eviction r
|
||||
assert.equal([...primitives][0], primitive);
|
||||
assert.equal(primitive.id, record);
|
||||
assert.notDeepEqual(primitive.position, oldPosition);
|
||||
assert.equal(layer.findByQuery('111').position, primitive.position);
|
||||
assert.deepEqual(layer.findByQuery('111').position, primitive.position);
|
||||
current = snapshot([observation('222')]);
|
||||
await layer.update();
|
||||
assert.equal(primitives.has(primitive), false);
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
REFRESH_MS,
|
||||
FOCUS_EVIDENCE_DEV,
|
||||
} from './policy.js';
|
||||
import { billboardState } from '../../data/billboardMirror.js';
|
||||
|
||||
export function createQueries({
|
||||
vesselState,
|
||||
@@ -295,9 +296,7 @@ export function createQueries({
|
||||
}
|
||||
if (!record) return null;
|
||||
|
||||
const position =
|
||||
components.rendering.getVisual(record).billboard?.position ||
|
||||
components.rendering.getVisual(record).position;
|
||||
const position = components.rendering.iconPosition(record);
|
||||
if (!position) return null;
|
||||
return {
|
||||
mmsi: record.mmsi,
|
||||
@@ -328,10 +327,9 @@ export function createQueries({
|
||||
|
||||
const entries = [];
|
||||
for (const record of records) {
|
||||
const visual = components.rendering.getVisual(record);
|
||||
if (!Number.isFinite(record.lat) || !Number.isFinite(record.lon))
|
||||
continue;
|
||||
const position = visual.billboard?.position || visual.position;
|
||||
const position = components.rendering.iconPosition(record);
|
||||
if (!position) continue;
|
||||
const distanceM = Cesium.Cartesian3.distance(centerCartesian, position);
|
||||
if (!Number.isFinite(distanceM) || distanceM > range) continue;
|
||||
@@ -381,9 +379,8 @@ export function createQueries({
|
||||
Number.isFinite(maxCount) && maxCount > 0 ? Math.floor(maxCount) : 800;
|
||||
|
||||
for (const record of records) {
|
||||
const visual = components.rendering.getVisual(record);
|
||||
if (result.length >= cap) break;
|
||||
const position = visual.billboard?.position || visual.position;
|
||||
const position = components.rendering.iconPosition(record);
|
||||
if (!position) continue;
|
||||
result.push({
|
||||
id: record.mmsi,
|
||||
@@ -495,8 +492,9 @@ export function createQueries({
|
||||
if ((idx - start) % stride !== 0) continue;
|
||||
const record = records[idx];
|
||||
const visual = components.rendering.getVisual(record);
|
||||
if (visual.billboard && !visual.billboard.show) continue;
|
||||
const position = visual.billboard?.position || visual.position;
|
||||
const icon = billboardState(visual.billboard);
|
||||
if (icon && !icon.show) continue;
|
||||
const position = icon?.position || visual.position;
|
||||
if (!position) continue;
|
||||
result.push({
|
||||
position,
|
||||
|
||||
@@ -20,6 +20,11 @@ import {
|
||||
LABEL_GRID_PX,
|
||||
CARD_MIN_SEP_PX,
|
||||
} from './policy.js';
|
||||
import {
|
||||
addBillboard,
|
||||
billboardState,
|
||||
setBillboard,
|
||||
} from '../../data/billboardMirror.js';
|
||||
|
||||
export function createRendering({
|
||||
vesselState,
|
||||
@@ -36,6 +41,12 @@ export function createRendering({
|
||||
return visualRecords.get(record) || record;
|
||||
}
|
||||
|
||||
/** Where a record's icon was drawn, from the app's mirror, else its visual position. */
|
||||
function iconPosition(record) {
|
||||
const visual = getVisual(record);
|
||||
return billboardState(visual.billboard)?.position || visual.position;
|
||||
}
|
||||
|
||||
function prepareRecordVisual(record) {
|
||||
let visual = visualRecords.get(record);
|
||||
if (!visual) {
|
||||
@@ -121,10 +132,13 @@ export function createRendering({
|
||||
const visible =
|
||||
state.feed.enabled &&
|
||||
isVisible(getVisual(record).surfacePosition, occluder);
|
||||
getVisual(record).billboard = state.billboardCollection.add({
|
||||
getVisual(record).billboard = addBillboard(state.billboardCollection, {
|
||||
position: getVisual(record).position,
|
||||
show: visible,
|
||||
image: shipIcon(record, false),
|
||||
// The ship artwork's own size, stated so the app's mirror knows it.
|
||||
width: 32,
|
||||
height: 32,
|
||||
scale: shipScale(record),
|
||||
// Screen-projected rotation lands on the next visibility/rotation pass.
|
||||
rotation: 0,
|
||||
@@ -286,19 +300,18 @@ export function createRendering({
|
||||
const visual = getVisual(record);
|
||||
const visible = isVisible(visual.surfacePosition, occluder);
|
||||
if (visual.billboard) {
|
||||
visual.billboard.show = visible;
|
||||
if (billboardState(visual.billboard).show !== visible)
|
||||
setBillboard(visual.billboard, 'show', visible);
|
||||
if (visible && doRotations && scene) {
|
||||
const { rotation } = billboardState(visual.billboard);
|
||||
const rot = screenProjectedRotation(
|
||||
scene,
|
||||
visual.position,
|
||||
vesselCourseDeg(record),
|
||||
visual.billboard.rotation,
|
||||
rotation,
|
||||
);
|
||||
if (
|
||||
rot !== null &&
|
||||
Math.abs(rot - visual.billboard.rotation) > 0.002
|
||||
) {
|
||||
visual.billboard.rotation = rot;
|
||||
if (rot !== null && Math.abs(rot - rotation) > 0.002) {
|
||||
setBillboard(visual.billboard, 'rotation', rot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,14 +366,15 @@ export function createRendering({
|
||||
for (const record of records || []) {
|
||||
const visual = getVisual(record);
|
||||
const bb = visual?.billboard;
|
||||
const position = bb?.position || visual?.position;
|
||||
const icon = billboardState(bb);
|
||||
const position = icon?.position || visual?.position;
|
||||
if (!bb || !position) continue;
|
||||
// Most of a worldwide feed sits behind the horizon. A hidden sprite with
|
||||
// no pending focus state and full alpha would advance to exactly what it
|
||||
// already is, so skip it instead of paying its distance and state work
|
||||
// every 80 ms while anything is tracked.
|
||||
if (
|
||||
bb.show === false &&
|
||||
icon.show === false &&
|
||||
spriteFocusAtRest(bb) &&
|
||||
!focusAlphaNeedsWrite(bb.color?.alpha, 1, params)
|
||||
)
|
||||
@@ -368,15 +382,16 @@ export function createRendering({
|
||||
const focus = advanceSpriteFocus(bb, {
|
||||
// Hidden/far-side sprites still finish any pending release so the active
|
||||
// count remains truthful and they cannot reappear with stale dim alpha.
|
||||
screenPosition: bb.show === false ? null : screenPositionFor(position),
|
||||
screenPosition:
|
||||
icon.show === false ? null : screenPositionFor(position),
|
||||
cameraDistance: cameraDistanceFor(position),
|
||||
nowMs,
|
||||
target,
|
||||
params,
|
||||
// Vessel artwork is 32 px before billboard scale. Including the
|
||||
// ambient chevron's own rendered extent prevents edge-overlap misses.
|
||||
spriteHalfWidthPx: (bb.width || 32) * (bb.scale || 1) * 0.5,
|
||||
spriteHalfHeightPx: (bb.height || 32) * (bb.scale || 1) * 0.5,
|
||||
spriteHalfWidthPx: (icon.width || 32) * (icon.scale || 1) * 0.5,
|
||||
spriteHalfHeightPx: (icon.height || 32) * (icon.scale || 1) * 0.5,
|
||||
});
|
||||
transitioning ||= focus.transitioning;
|
||||
if (focus.active) activeCount += 1;
|
||||
@@ -461,7 +476,7 @@ export function createRendering({
|
||||
if (selected) {
|
||||
const screen = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
getVisual(selected).billboard?.position || getVisual(selected).position,
|
||||
iconPosition(selected),
|
||||
);
|
||||
if (screen) accepted.push({ x: screen.x, y: screen.y });
|
||||
}
|
||||
@@ -561,6 +576,7 @@ export function createRendering({
|
||||
}
|
||||
return {
|
||||
getVisual,
|
||||
iconPosition,
|
||||
prepareRecordVisual,
|
||||
resetRecordVisuals,
|
||||
renderRowLimit,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
import { setBillboard } from '../../data/billboardMirror.js';
|
||||
|
||||
export function createSelection({
|
||||
vesselState,
|
||||
@@ -131,9 +132,7 @@ export function createSelection({
|
||||
kind: 'vessel',
|
||||
id: record.mmsi,
|
||||
label: record.name || record.mmsi,
|
||||
position:
|
||||
components.rendering.getVisual(record).billboard?.position ||
|
||||
components.rendering.getVisual(record).position,
|
||||
position: components.rendering.iconPosition(record),
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -174,8 +173,11 @@ export function createSelection({
|
||||
if (components.rendering.getVisual(record).billboard) {
|
||||
components.rendering.getVisual(record).billboard.image =
|
||||
components.rendering.shipIcon(record, true);
|
||||
components.rendering.getVisual(record).billboard.scale =
|
||||
components.rendering.shipScale(record) * 1.2;
|
||||
setBillboard(
|
||||
components.rendering.getVisual(record).billboard,
|
||||
'scale',
|
||||
components.rendering.shipScale(record) * 1.2,
|
||||
);
|
||||
}
|
||||
// Rebuild the card set immediately so the full-detail card appears on the
|
||||
// click, not up to VISIBILITY_UPDATE_MS later.
|
||||
@@ -230,8 +232,11 @@ export function createSelection({
|
||||
if (components.rendering.getVisual(record)?.billboard) {
|
||||
components.rendering.getVisual(record).billboard.image =
|
||||
components.rendering.shipIcon(record, false);
|
||||
components.rendering.getVisual(record).billboard.scale =
|
||||
components.rendering.shipScale(record);
|
||||
setBillboard(
|
||||
components.rendering.getVisual(record).billboard,
|
||||
'scale',
|
||||
components.rendering.shipScale(record),
|
||||
);
|
||||
}
|
||||
state.selectedRecord = null;
|
||||
// Drop the full-detail card right away (no-op when the layer is disabled —
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
/** Connect portable vessel reconciliation to scene and selection operations. */
|
||||
import { setBillboard } from '../../data/billboardMirror.js';
|
||||
|
||||
export function createVesselSnapshotRenderer({
|
||||
state,
|
||||
records,
|
||||
@@ -29,9 +31,12 @@ export function createVesselSnapshotRenderer({
|
||||
const selected = record === state.selectedRecord;
|
||||
const visual = rendering.prepareRecordVisual(record);
|
||||
if (visual.billboard) {
|
||||
visual.billboard.position = visual.position;
|
||||
visual.billboard.scale =
|
||||
rendering.shipScale(record) * (selected ? 1.2 : 1);
|
||||
setBillboard(visual.billboard, 'position', visual.position);
|
||||
setBillboard(
|
||||
visual.billboard,
|
||||
'scale',
|
||||
rendering.shipScale(record) * (selected ? 1.2 : 1),
|
||||
);
|
||||
const nextIcon = rendering.shipIcon(record, selected);
|
||||
if (nextIcon !== prevIcon) visual.billboard.image = nextIcon;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
TRAIL_MAX_POINTS,
|
||||
TRAIL_MIN_MOVE_M,
|
||||
} from './policy.js';
|
||||
import { setBillboard } from '../../data/billboardMirror.js';
|
||||
|
||||
export function createTracking({
|
||||
vesselState,
|
||||
@@ -71,7 +72,8 @@ export function createTracking({
|
||||
record.lat,
|
||||
heightM,
|
||||
);
|
||||
if (visual.billboard) visual.billboard.position = visual.position;
|
||||
if (visual.billboard)
|
||||
setBillboard(visual.billboard, 'position', visual.position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user