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

+55 -16
View File
@@ -2,6 +2,7 @@
// Icon colors under focus de-emphasis (#1200): the focus pass fades each icon
// from the same base color the coverage refresh assigns, so a video-feed camera
// stays violet while it dims instead of falling back to the idle cyan.
// Teardown takes the icons out of the scene that holds them.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createRendering } from './rendering.js';
@@ -11,18 +12,22 @@ import {
LIVE_CAMERA_COLOR,
} from './policy.js';
import { isVideoFeedType } from '../../sources/cctvTypes.js';
import { mirrorBillboard } from '../../data/billboardMirror.js';
import * as Cesium from 'cesium';
import { createIconSet } from '../../data/iconSet.js';
const FOCUS_FACTOR = 0.5;
function assertFadedFrom(actual, base, label) {
assert.ok(actual, `${label}: color written`);
function assertKeepsColor(icons, id, base, label) {
const row = icons.row(id);
const actual = icons.color(row);
assert.deepEqual(
[actual.red, actual.green, actual.blue],
[base.red, base.green, base.blue],
`${label}: hue`,
[actual.red, actual.green, actual.blue, actual.alpha].map(
Cesium.Color.floatToByte,
),
[base.red, base.green, base.blue, base.alpha].map(Cesium.Color.floatToByte),
`${label}: base color kept`,
);
assert.equal(actual.alpha, base.alpha * FOCUS_FACTOR, `${label}: alpha`);
assert.equal(icons.focus(row), FOCUS_FACTOR, `${label}: focus`);
}
test('focus de-emphasis fades each icon from its own color', () => {
@@ -30,7 +35,6 @@ test('focus de-emphasis fades each icon from its own color', () => {
camera: { id, feedType },
// No position, so the pass skips screen projection; the focus stub below
// decides the factor on its own.
billboard: mirrorBillboard({ show: true }),
});
const idleVideo = record('idle-hls', 'hls');
const idleStill = record('idle-image', 'image');
@@ -42,6 +46,7 @@ test('focus de-emphasis fades each icon from its own color', () => {
_activeCameraId: activeVideo.camera.id,
_activeFocusStyleCount: 0,
_lastFocusStyleAt: -Infinity,
_icons: createIconSet(),
};
const focus = {
focusNowMs: (nowMs) => nowMs,
@@ -54,21 +59,55 @@ test('focus de-emphasis fades each icon from its own color', () => {
}),
focusAlphaNeedsWrite: () => true,
};
const { refreshCctvFocusStyles } = createRendering({
const { addCameraIcon, refreshCctvFocusStyles } = createRendering({
state,
services: { focus },
parts: { model: { isVideoFeedType } },
source: {},
});
for (const r of state._records) addCameraIcon(r);
refreshCctvFocusStyles(1000);
assertFadedFrom(idleVideo.billboard.color, LIVE_CAMERA_COLOR, 'idle video');
assertFadedFrom(idleStill.billboard.color, IDLE_CAMERA_COLOR, 'idle still');
assertFadedFrom(
activeVideo.billboard.color,
ACTIVE_CAMERA_COLOR,
'active video',
);
const icons = state._icons;
assertKeepsColor(icons, 'idle-hls', LIVE_CAMERA_COLOR, 'idle video');
assertKeepsColor(icons, 'idle-image', IDLE_CAMERA_COLOR, 'idle still');
assertKeepsColor(icons, 'active-hls', ACTIVE_CAMERA_COLOR, 'active video');
assert.equal(state._activeFocusStyleCount, 3);
});
test('icons leave the scene they were added to, whichever viewer tears down', () => {
const viewer = () => {
const held = new Set();
return {
held,
scene: {
requestRender() {},
primitives: {
add: (p) => held.add(p),
remove: (p) => held.delete(p),
},
},
};
};
const first = viewer();
const second = viewer();
const state = { _viewer: first };
const { createCameraIcons, destroyCameraIcons } = createRendering({
state,
services: { focus: {} },
parts: {},
source: {},
});
const old = createCameraIcons(first);
state._viewer = second;
const current = createCameraIcons(second);
assert.equal(first.held.has(old), false, 'a re-init takes out the old icons');
assert.equal(old.isDestroyed(), true);
destroyCameraIcons();
assert.equal(second.held.has(current), false);
assert.equal(current.isDestroyed(), true);
assert.equal(state._icons, null);
});