Draw CCTV coverage, viewsheds and the monitor plane through the renderer ports and take projection.js off the Cesium list

The frustum wireframes, viewshed volumes and the active camera's monitor
plane are now line, mesh and quad items of the layer's own draw sets
(layers/cctv/drawSets.js), written from plain handles only as they change.
The plane takes its canvas double buffer or its video as a quad source.
Picks of lines and planes are matched by set, item id and the record that
draws them. The activation obstruction probe casts through the query
port's rayCast; its clamp lands a microtask later, rewrites the geometry
and asks again for the footprint ground, and a newer activation, a range
edit, a deactivation or a re-init drops an answer still to come.
This commit is contained in:
Sameh Khamis committed 2026-11-08 08:35:12 -08:00
1 parent bbad02b73e
commit 2a607ec4d8
20 files changed
+918 -492

No files matched your search

+85 -48
View File
@@ -81,7 +81,7 @@ import {
IDLE_CAMERA_COLOR,
LIVE_CAMERA_COLOR,
} from '../layers/cctv/policy.js';
import { cctvPicks } from '../layers/cctv/pickState.js';
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
import { FAKE_EVENT_TYPES, fakeInput } from '../input/testDoubles.mjs';
const ASPECT = 16 / 9;
@@ -277,15 +277,9 @@ test('default COVERAGE refresh materializes the active and visible camera frustu
coverageEntities: [],
projection: null,
}));
const inserted = [];
const viewer = {
entities: {
add(entity) {
inserted.push(entity);
return entity;
},
},
};
const viewer = {};
const { draw, unbind } = bindFakeDraw(viewer);
const inserted = () => draw.find('cctv:')?.items ?? new Map();
const activeRecord = records.at(-1);
try {
@@ -300,10 +294,16 @@ test('default COVERAGE refresh materializes the active and visible camera frustu
(record) => record.coverageEntities.length > 0,
);
assert.equal(
inserted.length,
inserted().size,
14 * 5,
'default COVERAGE ON builds the 14-camera visible cohort',
);
assert.ok(
[...inserted().keys()].every((id) =>
/^cctv-cam-\d+-(ray-..|cap)$/.test(id),
),
'coverage lines keep the cctv-<id>-<role> ids',
);
assert.equal(materialized.length, 14);
assert.equal(
activeRecord.coverageEntities.length,
@@ -319,7 +319,7 @@ test('default COVERAGE refresh materializes the active and visible camera frustu
...records[0],
camera: { ...records[0].camera, id: 'projection-only' },
coverageEntities: [],
projection: { planeEntity: { show: false } },
projection: { plane: { show: false } },
};
_setCctvCoverageStateForTest({
viewer,
@@ -334,8 +334,15 @@ test('default COVERAGE refresh materializes the active and visible camera frustu
projectionOnly.coverageEntities.every((entity) => entity.show),
'COVERAGE OFF keeps the active projection frustum materialized and visible',
);
assert.ok(
projectionOnly.coverageEntities.every(
(entity) => inserted().get(entity.id)?.show === true,
),
'and draws it',
);
} finally {
_setCctvCoverageStateForTest({ enabled: false });
unbind();
}
});
@@ -348,7 +355,8 @@ test('camera icons are violet for video feeds, cyan for stills, amber when activ
const idleVideo = record('idle-hls', 'hls');
const idleStill = record('idle-image', 'image');
const activeVideo = record('active-hls', 'hls');
const viewer = { entities: { add: (entity) => entity } };
const viewer = {};
const { unbind } = bindFakeDraw(viewer);
try {
// Disabled keeps the active video camera from opening a real projection;
@@ -376,6 +384,7 @@ test('camera icons are violet for video feeds, cyan for stills, amber when activ
assert.equal(icons.scale(icons.row(idleVideo.camera.id)), 1);
} finally {
_setCctvCoverageStateForTest({ enabled: false });
unbind();
}
});
@@ -679,15 +688,15 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
activationDone: true,
probeClampRangeM: 105,
coverageEntities: [{ show: true }, { show: true }],
projection: { planeEntity: { show: true } },
viewshedPrimitive: viewshedA,
projection: { plane: { show: true } },
viewshedVolume: viewshedA,
},
{
camera: { id: 'b' },
activationDone: true,
probeClampRangeM: 146,
projection: null,
viewshedPrimitive: viewshedB,
viewshedVolume: viewshedB,
},
];
const destroyed = [];
@@ -696,7 +705,7 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
records,
(record) => {
destroyed.push(record.camera.id);
record.viewshedPrimitive = null;
record.viewshedVolume = null;
},
'a',
);
@@ -707,10 +716,10 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
),
[false, false],
);
assert.equal(records[0].projection.planeEntity.show, false);
assert.equal(records[0].projection.plane.show, false);
assert.deepEqual(destroyed, ['a', 'b']);
assert.equal(records[0].viewshedPrimitive, null);
assert.equal(records[1].viewshedPrimitive, null);
assert.equal(records[0].viewshedVolume, null);
assert.equal(records[1].viewshedVolume, null);
assert.deepEqual(
records.map((record) => record.probeClampRangeM),
[null, null],
@@ -728,7 +737,8 @@ test('real active monitor plane owns one protected host label and no native labe
setVisible: (...args) => calls.push(['visible', ...args]),
clearSource: (...args) => calls.push(['clear', ...args]),
};
const viewer = { entities: new Cesium.EntityCollection() };
const viewer = {};
const { draw, unbind } = bindFakeDraw(viewer);
const record = {
camera: {
...UNCLAMPED_CAMERA,
@@ -752,17 +762,23 @@ test('real active monitor plane owns one protected host label and no native labe
});
refreshCoverageStyles();
assert.ok(runtime.plane, 'runtime guard requires a real monitor plane');
const planes = draw.find('cctv:')
? [...draw.sets.values()].filter((set) => set.kind === 'quads')
: [];
assert.equal(planes.length, 1, 'the plane draws as a quad');
const quad = planes[0].items.get(`cctv-${record.camera.id}-plane`);
assert.ok(quad, 'under its cctv-<id>-plane id');
assert.equal(quad.alpha, 0.95);
assert.deepEqual(quad.size, [
record.frustumGeometry.halfW * 2,
record.frustumGeometry.halfH * 2,
]);
assert.ok(quad.outline, 'with its outline');
assert.equal(quad.meta.cameraId, record.camera.id);
assert.ok(
runtime.planeEntity,
'runtime guard requires a real monitor-plane entity',
);
assert.equal(runtime.planeEntity.label, undefined);
assert.ok(
runtime.planeEntity.plane,
'monitor plane geometry remains native',
);
assert.ok(
viewer.entities.values.every((entity) => entity.label === undefined),
[...draw.sets.values()].every((set) => set.kind !== 'labels'),
'and no native label',
);
const publication = calls.find(
([type, sourceId]) =>
@@ -778,7 +794,8 @@ test('real active monitor plane owns one protected host label and no native labe
assert.equal(entry.position(), runtime.labelPosition);
assert.equal(entry.protected, true);
assert.equal(entry.paintLane, 'selected');
assert.equal(runtime.planeEntity.show, true);
assert.equal(runtime.plane.show, true);
assert.equal(quad.show, true, 'shown once projected');
const cachedPosition = runtime.labelPosition;
record.frustumPositions.label = Cesium.Cartesian3.add(
@@ -806,7 +823,8 @@ test('real active monitor plane owns one protected host label and no native labe
showProjection: false,
});
refreshCoverageStyles();
assert.equal(runtime.planeEntity.show, false);
assert.equal(runtime.plane.show, false);
assert.equal(planes[0].items.get(quad.id).show, false);
assert.deepEqual(calls.slice(-2), [
['clear', 'cctv-projection'],
['visible', 'cctv-projection', false],
@@ -814,6 +832,7 @@ test('real active monitor plane owns one protected host label and no native labe
} finally {
_setCctvCoverageStateForTest({ enabled: false });
_setCctvOverlayHostForTest();
unbind();
}
});
@@ -1002,8 +1021,7 @@ test('CCTV repeated in-world clicks dispatch focus only for the one real activat
// ─── Empty-space deselection and stable null-active state ──────────────────
function makeDeselectViewer() {
return {
entities: new Cesium.EntityCollection(),
const viewer = {
isDestroyed: () => false,
trackedEntity: { id: 'sibling-track-owner' },
camera: {
@@ -1028,6 +1046,9 @@ function makeDeselectViewer() {
requestRender() {},
},
};
// The layer's lines and plane draw through this.
viewer.draw = bindFakeDraw(viewer).draw;
return viewer;
}
function makeDeselectRecord(id, index = 0) {
@@ -1118,19 +1139,23 @@ 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 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'),
coverageEntities: [ownedCoverageEntity],
};
const viewer = {};
const { draw, unbind } = bindFakeDraw(viewer);
const record = makeDeselectRecord('shared-id');
_setCctvCoverageStateForTest({
viewer,
records: [record],
activeCameraId: 'shared-id',
});
try {
refreshCoverageStyles();
const coverage = [...draw.sets.values()].find(
(set) => set.kind === 'lines' && set.spec.id.startsWith('cctv:'),
);
assert.ok(coverage.items.has('cctv-shared-id-cap'));
const lineHit = (set, id) => ({
id: { set, id, meta: { cameraId: 'shared-id' } },
});
assert.equal(
_extractPickedCameraIdForTest({
id: 'shared-id',
@@ -1154,9 +1179,18 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
'a sibling Entity with the same canonical ID cannot activate CCTV',
);
assert.equal(
_extractPickedCameraIdForTest({ id: ownedCoverageEntity }),
_extractPickedCameraIdForTest(
lineHit(coverage.spec.id, 'cctv-shared-id-cap'),
),
'shared-id',
'an exact stored CCTV coverage Entity retains activation ownership',
'a coverage line the record draws retains activation ownership',
);
assert.equal(
_extractPickedCameraIdForTest(
lineHit('sibling:1:lines', 'cctv-shared-id-cap'),
),
null,
"a sibling set's item with a CCTV id and meta cannot activate CCTV",
);
assert.equal(
_extractPickedCameraIdForTest({
@@ -1169,12 +1203,15 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
'a sibling cannot impersonate CCTV by copying its property shape',
);
assert.equal(
_extractPickedCameraIdForTest({ id: strayEntity }),
_extractPickedCameraIdForTest(
lineHit(coverage.spec.id, 'cctv-shared-id-stray'),
),
null,
'a camera id alone is not ownership: the record must hold the entity',
'a camera id alone is not ownership: the record must draw the item',
);
} finally {
_setCctvCoverageStateForTest({ enabled: false });
unbind();
}
});
@@ -1228,7 +1265,7 @@ test('CCTV deselect publishes one null state and leaves the complete camera pose
assert.equal(publications.at(-1).activeCameraId, null);
assert.equal(publications.at(-1).activeCamera, null);
assert.equal(publications.at(-1).enabled, true);
assert.equal(runtime.planeEntity.show, false);
assert.equal(runtime.plane.show, false);
assert.equal(record.probeClampRangeM, null);
assert.equal(record.activationDone, false);
assert.deepEqual(viewer.camera.positionWC, pose.positionWC);