Draw CCTV cameras from a GPU icon set

This commit is contained in:
Sameh Khamis committed 2026-11-03 21:47:16 -08:00
1 parent e0eb771217
commit 8aaf5564d7
16 files changed
+291 -168

No files matched your search

+1
View File
@@ -65,6 +65,7 @@ export const materializeCctvVisibleCoverageEntities =
export const _extractPickedCameraIdForTest =
layer._extractPickedCameraIdForTest;
export const _setCctvCoverageStateForTest = layer._setCctvCoverageStateForTest;
export const _cctvIconsForTest = layer._cctvIconsForTest;
export const focusCctvRecord = layer.focusCctvRecord;
export const maybeAutoHop = layer.maybeAutoHop;
export const cctvCycleIndex = layer.cctvCycleIndex;
+16 -17
View File
@@ -32,6 +32,7 @@ import cctvLayer, {
_extractPickedCameraIdForTest,
_updateCctvProjectionPlaneForTest,
_setCctvCoverageStateForTest,
_cctvIconsForTest,
_pushAmbientCardEntriesForTest,
_setCctvOverlayHostForTest,
activationProbeClampRange,
@@ -79,7 +80,6 @@ import {
IDLE_CAMERA_COLOR,
LIVE_CAMERA_COLOR,
} from '../layers/cctv/policy.js';
import { mirrorBillboard } from './billboardMirror.js';
import { cctvPicks } from '../layers/cctv/pickState.js';
const ASPECT = 16 / 9;
@@ -357,7 +357,6 @@ test('default COVERAGE refresh materializes the active and visible camera frustu
test('camera icons are violet for video feeds, cyan for stills, amber when active', () => {
const record = (id, feedType) => ({
camera: { ...UNCLAMPED_CAMERA, id, feedType, groundElevationM: 0 },
billboard: mirrorBillboard({}),
coverageEntities: [],
projection: null,
});
@@ -377,9 +376,15 @@ test('camera icons are violet for video feeds, cyan for stills, amber when activ
coverageMode: 'off',
});
refreshCoverageStyles();
assert.equal(idleVideo.billboard.color, LIVE_CAMERA_COLOR);
assert.equal(idleStill.billboard.color, IDLE_CAMERA_COLOR);
assert.equal(activeVideo.billboard.color, ACTIVE_CAMERA_COLOR);
const icons = _cctvIconsForTest();
const color = (record) => icons.color(icons.row(record.camera.id));
const bytes = (c) =>
[c.red, c.green, c.blue, c.alpha].map(Cesium.Color.floatToByte);
assert.deepEqual(bytes(color(idleVideo)), bytes(LIVE_CAMERA_COLOR));
assert.deepEqual(bytes(color(idleStill)), bytes(IDLE_CAMERA_COLOR));
assert.deepEqual(bytes(color(activeVideo)), bytes(ACTIVE_CAMERA_COLOR));
assert.equal(icons.scale(icons.row(activeVideo.camera.id)), 1.25);
assert.equal(icons.scale(icons.row(idleVideo.camera.id)), 1);
} finally {
_setCctvCoverageStateForTest({ enabled: false });
}
@@ -684,7 +689,6 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
camera: { id: 'a' },
activationDone: true,
probeClampRangeM: 105,
billboard: mirrorBillboard({ color: 'keep-color', scale: 1.25 }),
coverageEntities: [{ show: true }, { show: true }],
projection: { planeEntity: { show: true } },
viewshedPrimitive: viewshedA,
@@ -693,7 +697,6 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
camera: { id: 'b' },
activationDone: true,
probeClampRangeM: 146,
billboard: mirrorBillboard({ color: 'keep-color', scale: 1 }),
projection: null,
viewshedPrimitive: viewshedB,
},
@@ -727,13 +730,6 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
records.map((record) => record.activationDone),
[false, true],
);
assert.deepEqual(
records.map((record) => record.billboard),
[
{ color: 'keep-color', scale: 1.25 },
{ color: 'keep-color', scale: 1 },
],
);
});
test('real active monitor plane owns one protected host label and no native label entity', () => {
@@ -1130,14 +1126,12 @@ test('CCTV empty-click gate excludes every identified scene object, ADJUST, and
});
test('CCTV camera extraction requires layer ownership, not a colliding sibling ID', () => {
const billboard = { id: 'shared-id' };
const ownedCoverageEntity = { id: 'cctv-shared-id-cap' };
cctvPicks.write(ownedCoverageEntity).cameraId = 'shared-id';
const strayEntity = { id: 'cctv-shared-id-stray' };
cctvPicks.write(strayEntity).cameraId = 'shared-id';
const record = {
...makeDeselectRecord('shared-id'),
billboard,
coverageEntities: [ownedCoverageEntity],
};
_setCctvCoverageStateForTest({
@@ -1146,12 +1140,17 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
});
try {
assert.equal(
_extractPickedCameraIdForTest({ id: 'shared-id', primitive: billboard }),
_extractPickedCameraIdForTest({
id: 'shared-id',
iconSet: _cctvIconsForTest(),
primitive: { id: 'shared-id' },
}),
'shared-id',
);
assert.equal(
_extractPickedCameraIdForTest({
id: 'shared-id',
iconSet: {},
primitive: { id: 'shared-id' },
}),
null,
+11 -5
View File
@@ -6,11 +6,11 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import cctvLayer, {
_cctvIconsForTest,
_setCctvCoverageStateForTest,
_viewRecordIdsForTest,
refreshHorizonCulling,
} from './cctv.js';
import { mirrorBillboard } from './billboardMirror.js';
const WIDTH = 800;
const HEIGHT = 600;
@@ -41,7 +41,6 @@ function recordsAt(
mountHeightM: 8,
},
position,
billboard: mirrorBillboard({ position, show: true }),
coverageEntities: [],
projection: null,
};
@@ -60,7 +59,7 @@ function viewerAt(heightM, screenByPosition, shiftX = 0) {
scene: {
canvas: { clientWidth: WIDTH, clientHeight: HEIGHT },
cartesianToCanvasCoordinates: (position) => {
// The mirror holds its own copy of each position, so match by value.
// Match by value: a record's position may be a copy of the fixture's.
const key = [...screenByPosition.keys()].find((candidate) =>
Cesium.Cartesian3.equals(candidate, position),
);
@@ -73,7 +72,10 @@ function viewerAt(heightM, screenByPosition, shiftX = 0) {
function shownIds(records) {
return records
.filter((record) => record.billboard.show)
.filter((record) => {
const icons = _cctvIconsForTest();
return icons.shown(icons.row(record.camera.id));
})
.map((record) => record.camera.id)
.sort();
}
@@ -165,7 +167,11 @@ test('the active camera always shows, even in a crowded cell', () => {
activeCameraId: active.camera.id,
});
refreshHorizonCulling();
assert.ok(active.billboard.show, `${active.camera.id} shows while active`);
const icons = _cctvIconsForTest();
assert.ok(
icons.shown(icons.row(active.camera.id)),
`${active.camera.id} shows while active`,
);
}
});
+32 -25
View File
@@ -4,7 +4,6 @@ import { applyVesselFocusDeemphasis } from './aisLiveVessels.js';
import { applyCctvFocusDeemphasis } from './cctv.js';
import { applySatellitePointFocusDeemphasis } from './satellites.js';
import { DEFAULT_FOCUS_DEEMPHASIS_PARAMS } from './focusDeemphasis.js';
import { mirrorBillboard } from './billboardMirror.js';
import { createIconSet } from './iconSet.js';
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
@@ -29,7 +28,11 @@ function assertResumeGate(name, makePass) {
const { pass, readAlpha } = makePass();
let activeCount = 0;
const tick = (nowMs, focusTarget) => {
const result = pass({ nowMs, target: focusTarget, previousActiveCount: activeCount });
const result = pass({
nowMs,
target: focusTarget,
previousActiveCount: activeCount,
});
activeCount = result.activeCount;
return result;
};
@@ -40,7 +43,11 @@ function assertResumeGate(name, makePass) {
assert.equal(readAlpha(), params.dimFloor);
const releaseStart = tick(params.attackMs + 1, null);
assert.equal(releaseStart.ran, true, 'active count keeps the no-target release pass alive');
assert.equal(
releaseStart.ran,
true,
'active count keeps the no-target release pass alive',
);
assert.equal(releaseStart.activeCount, 1);
const restored = tick(params.attackMs + params.releaseMs + 2, null);
@@ -48,16 +55,23 @@ function assertResumeGate(name, makePass) {
assert.equal(restored.activeCount, 0);
assert.equal(readAlpha(), 1);
assert.equal(tick(params.attackMs + params.releaseMs + 82, null).ran, false);
assert.equal(
tick(params.attackMs + params.releaseMs + 82, null).ran,
false,
);
});
}
assertResumeGate('vessel', () => {
const icons = createIconSet();
icons.setSize(icons.add('353136000', { id: '353136000' }), 32, 32);
const record = { iconId: '353136000', position: { x: 1, y: 2, z: 3 }, visible: true };
const record = {
iconId: '353136000',
position: { x: 1, y: 2, z: 3 },
visible: true,
};
return {
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
applyVesselFocusDeemphasis({
records: [record],
icons,
@@ -67,36 +81,30 @@ assertResumeGate('vessel', () => {
screenPositionFor: () => ({ x: 50, y: 50 }),
cameraDistanceFor: () => 1200,
params,
})
),
}),
readAlpha: () => icons.focus(icons.row('353136000')),
};
});
assertResumeGate('CCTV', () => {
const billboard = mirrorBillboard({
position: { x: 1, y: 2, z: 3 },
show: true,
width: 24,
height: 24,
scale: 1,
color: color(),
});
const record = { camera: { id: 'cam-1' }, billboard };
const icons = createIconSet();
const row = icons.add('cam-1', { id: 'cam-1' });
icons.setSize(row, 24, 24);
icons.setShown(row, true);
const record = { camera: { id: 'cam-1' }, position: { x: 1, y: 2, z: 3 } };
return {
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
applyCctvFocusDeemphasis({
records: [record],
icons,
target: focusTarget,
previousActiveCount,
nowMs,
screenPositionFor: () => ({ x: 50, y: 50 }),
cameraDistanceFor: () => 1200,
baseColorFor: () => color(),
params,
})
),
readAlpha: () => billboard.color.alpha,
}),
readAlpha: () => icons.focus(icons.row('cam-1')),
};
});
@@ -108,7 +116,7 @@ assertResumeGate('satellite', () => {
color: color(),
};
return {
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
applySatellitePointFocusDeemphasis({
points: new Map([[42, point]]),
trackedId: null,
@@ -119,8 +127,7 @@ assertResumeGate('satellite', () => {
cameraDistanceFor: () => 1200,
baseColorFor: () => color(),
params,
})
),
}),
readAlpha: () => point.color.alpha,
};
});
+8 -1
View File
@@ -259,10 +259,14 @@ export class IconSetPrimitive {
update(frameState) {
const set = this.set;
// Icons are screen overlays, not world surfaces: they stay out of the
// offscreen ray picks behind pickFromRay and sampleHeight, so a layer's
// ground and mesh probes never hit its own (or another layer's) icons.
if (
!this.show ||
!set.show ||
(!frameState.passes.render && !frameState.passes.pick)
(!frameState.passes.render && !frameState.passes.pick) ||
frameState.passes.offscreen
)
return;
const context = frameState.context;
@@ -446,6 +450,9 @@ export class IconSetPrimitive {
handle = {
pickId: context.createPickId({
id,
// Which set drew the pick: ownership for layers whose row ids are
// upstream ids a sibling may share.
iconSet: set,
get meta() {
const at = set.row(id);
return at >= 0 ? set.metaAt(at) : undefined;