mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Draw CCTV cameras from a GPU icon set
This commit is contained in:
1 parent
e0eb771217
commit
8aaf5564d7
16 files changed
+289
-166
No files matched your search
@@ -1890,6 +1890,12 @@
|
|||||||
"src/layers/cctv/videoPlayback.js",
|
"src/layers/cctv/videoPlayback.js",
|
||||||
"src/layers/cctv/rendering.js",
|
"src/layers/cctv/rendering.js",
|
||||||
"src/data/billboardMirror.js",
|
"src/data/billboardMirror.js",
|
||||||
|
"src/data/iconSetPrimitive.js",
|
||||||
|
"src/data/iconSet.js",
|
||||||
|
"src/data/iconSegment.js",
|
||||||
|
"src/data/iconAtlas.js",
|
||||||
|
"src/data/aircraftRecession.js",
|
||||||
|
"src/data/motionModel.js",
|
||||||
"src/layers/cctv/selection.js",
|
"src/layers/cctv/selection.js",
|
||||||
"src/layers/cctv/pickState.js",
|
"src/layers/cctv/pickState.js",
|
||||||
"src/layers/cctv/source.js",
|
"src/layers/cctv/source.js",
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export const materializeCctvVisibleCoverageEntities =
|
|||||||
export const _extractPickedCameraIdForTest =
|
export const _extractPickedCameraIdForTest =
|
||||||
layer._extractPickedCameraIdForTest;
|
layer._extractPickedCameraIdForTest;
|
||||||
export const _setCctvCoverageStateForTest = layer._setCctvCoverageStateForTest;
|
export const _setCctvCoverageStateForTest = layer._setCctvCoverageStateForTest;
|
||||||
|
export const _cctvIconsForTest = layer._cctvIconsForTest;
|
||||||
export const focusCctvRecord = layer.focusCctvRecord;
|
export const focusCctvRecord = layer.focusCctvRecord;
|
||||||
export const maybeAutoHop = layer.maybeAutoHop;
|
export const maybeAutoHop = layer.maybeAutoHop;
|
||||||
export const cctvCycleIndex = layer.cctvCycleIndex;
|
export const cctvCycleIndex = layer.cctvCycleIndex;
|
||||||
|
|||||||
+16
-17
@@ -32,6 +32,7 @@ import cctvLayer, {
|
|||||||
_extractPickedCameraIdForTest,
|
_extractPickedCameraIdForTest,
|
||||||
_updateCctvProjectionPlaneForTest,
|
_updateCctvProjectionPlaneForTest,
|
||||||
_setCctvCoverageStateForTest,
|
_setCctvCoverageStateForTest,
|
||||||
|
_cctvIconsForTest,
|
||||||
_pushAmbientCardEntriesForTest,
|
_pushAmbientCardEntriesForTest,
|
||||||
_setCctvOverlayHostForTest,
|
_setCctvOverlayHostForTest,
|
||||||
activationProbeClampRange,
|
activationProbeClampRange,
|
||||||
@@ -79,7 +80,6 @@ import {
|
|||||||
IDLE_CAMERA_COLOR,
|
IDLE_CAMERA_COLOR,
|
||||||
LIVE_CAMERA_COLOR,
|
LIVE_CAMERA_COLOR,
|
||||||
} from '../layers/cctv/policy.js';
|
} from '../layers/cctv/policy.js';
|
||||||
import { mirrorBillboard } from './billboardMirror.js';
|
|
||||||
import { cctvPicks } from '../layers/cctv/pickState.js';
|
import { cctvPicks } from '../layers/cctv/pickState.js';
|
||||||
|
|
||||||
const ASPECT = 16 / 9;
|
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', () => {
|
test('camera icons are violet for video feeds, cyan for stills, amber when active', () => {
|
||||||
const record = (id, feedType) => ({
|
const record = (id, feedType) => ({
|
||||||
camera: { ...UNCLAMPED_CAMERA, id, feedType, groundElevationM: 0 },
|
camera: { ...UNCLAMPED_CAMERA, id, feedType, groundElevationM: 0 },
|
||||||
billboard: mirrorBillboard({}),
|
|
||||||
coverageEntities: [],
|
coverageEntities: [],
|
||||||
projection: null,
|
projection: null,
|
||||||
});
|
});
|
||||||
@@ -377,9 +376,15 @@ test('camera icons are violet for video feeds, cyan for stills, amber when activ
|
|||||||
coverageMode: 'off',
|
coverageMode: 'off',
|
||||||
});
|
});
|
||||||
refreshCoverageStyles();
|
refreshCoverageStyles();
|
||||||
assert.equal(idleVideo.billboard.color, LIVE_CAMERA_COLOR);
|
const icons = _cctvIconsForTest();
|
||||||
assert.equal(idleStill.billboard.color, IDLE_CAMERA_COLOR);
|
const color = (record) => icons.color(icons.row(record.camera.id));
|
||||||
assert.equal(activeVideo.billboard.color, ACTIVE_CAMERA_COLOR);
|
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 {
|
} finally {
|
||||||
_setCctvCoverageStateForTest({ enabled: false });
|
_setCctvCoverageStateForTest({ enabled: false });
|
||||||
}
|
}
|
||||||
@@ -684,7 +689,6 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
|
|||||||
camera: { id: 'a' },
|
camera: { id: 'a' },
|
||||||
activationDone: true,
|
activationDone: true,
|
||||||
probeClampRangeM: 105,
|
probeClampRangeM: 105,
|
||||||
billboard: mirrorBillboard({ color: 'keep-color', scale: 1.25 }),
|
|
||||||
coverageEntities: [{ show: true }, { show: true }],
|
coverageEntities: [{ show: true }, { show: true }],
|
||||||
projection: { planeEntity: { show: true } },
|
projection: { planeEntity: { show: true } },
|
||||||
viewshedPrimitive: viewshedA,
|
viewshedPrimitive: viewshedA,
|
||||||
@@ -693,7 +697,6 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
|
|||||||
camera: { id: 'b' },
|
camera: { id: 'b' },
|
||||||
activationDone: true,
|
activationDone: true,
|
||||||
probeClampRangeM: 146,
|
probeClampRangeM: 146,
|
||||||
billboard: mirrorBillboard({ color: 'keep-color', scale: 1 }),
|
|
||||||
projection: null,
|
projection: null,
|
||||||
viewshedPrimitive: viewshedB,
|
viewshedPrimitive: viewshedB,
|
||||||
},
|
},
|
||||||
@@ -727,13 +730,6 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
|
|||||||
records.map((record) => record.activationDone),
|
records.map((record) => record.activationDone),
|
||||||
[false, true],
|
[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', () => {
|
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', () => {
|
test('CCTV camera extraction requires layer ownership, not a colliding sibling ID', () => {
|
||||||
const billboard = { id: 'shared-id' };
|
|
||||||
const ownedCoverageEntity = { id: 'cctv-shared-id-cap' };
|
const ownedCoverageEntity = { id: 'cctv-shared-id-cap' };
|
||||||
cctvPicks.write(ownedCoverageEntity).cameraId = 'shared-id';
|
cctvPicks.write(ownedCoverageEntity).cameraId = 'shared-id';
|
||||||
const strayEntity = { id: 'cctv-shared-id-stray' };
|
const strayEntity = { id: 'cctv-shared-id-stray' };
|
||||||
cctvPicks.write(strayEntity).cameraId = 'shared-id';
|
cctvPicks.write(strayEntity).cameraId = 'shared-id';
|
||||||
const record = {
|
const record = {
|
||||||
...makeDeselectRecord('shared-id'),
|
...makeDeselectRecord('shared-id'),
|
||||||
billboard,
|
|
||||||
coverageEntities: [ownedCoverageEntity],
|
coverageEntities: [ownedCoverageEntity],
|
||||||
};
|
};
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
@@ -1146,12 +1140,17 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
_extractPickedCameraIdForTest({ id: 'shared-id', primitive: billboard }),
|
_extractPickedCameraIdForTest({
|
||||||
|
id: 'shared-id',
|
||||||
|
iconSet: _cctvIconsForTest(),
|
||||||
|
primitive: { id: 'shared-id' },
|
||||||
|
}),
|
||||||
'shared-id',
|
'shared-id',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
_extractPickedCameraIdForTest({
|
_extractPickedCameraIdForTest({
|
||||||
id: 'shared-id',
|
id: 'shared-id',
|
||||||
|
iconSet: {},
|
||||||
primitive: { id: 'shared-id' },
|
primitive: { id: 'shared-id' },
|
||||||
}),
|
}),
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import { test } from 'node:test';
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import * as Cesium from 'cesium';
|
import * as Cesium from 'cesium';
|
||||||
import cctvLayer, {
|
import cctvLayer, {
|
||||||
|
_cctvIconsForTest,
|
||||||
_setCctvCoverageStateForTest,
|
_setCctvCoverageStateForTest,
|
||||||
_viewRecordIdsForTest,
|
_viewRecordIdsForTest,
|
||||||
refreshHorizonCulling,
|
refreshHorizonCulling,
|
||||||
} from './cctv.js';
|
} from './cctv.js';
|
||||||
import { mirrorBillboard } from './billboardMirror.js';
|
|
||||||
|
|
||||||
const WIDTH = 800;
|
const WIDTH = 800;
|
||||||
const HEIGHT = 600;
|
const HEIGHT = 600;
|
||||||
@@ -41,7 +41,6 @@ function recordsAt(
|
|||||||
mountHeightM: 8,
|
mountHeightM: 8,
|
||||||
},
|
},
|
||||||
position,
|
position,
|
||||||
billboard: mirrorBillboard({ position, show: true }),
|
|
||||||
coverageEntities: [],
|
coverageEntities: [],
|
||||||
projection: null,
|
projection: null,
|
||||||
};
|
};
|
||||||
@@ -60,7 +59,7 @@ function viewerAt(heightM, screenByPosition, shiftX = 0) {
|
|||||||
scene: {
|
scene: {
|
||||||
canvas: { clientWidth: WIDTH, clientHeight: HEIGHT },
|
canvas: { clientWidth: WIDTH, clientHeight: HEIGHT },
|
||||||
cartesianToCanvasCoordinates: (position) => {
|
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) =>
|
const key = [...screenByPosition.keys()].find((candidate) =>
|
||||||
Cesium.Cartesian3.equals(candidate, position),
|
Cesium.Cartesian3.equals(candidate, position),
|
||||||
);
|
);
|
||||||
@@ -73,7 +72,10 @@ function viewerAt(heightM, screenByPosition, shiftX = 0) {
|
|||||||
|
|
||||||
function shownIds(records) {
|
function shownIds(records) {
|
||||||
return 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)
|
.map((record) => record.camera.id)
|
||||||
.sort();
|
.sort();
|
||||||
}
|
}
|
||||||
@@ -165,7 +167,11 @@ test('the active camera always shows, even in a crowded cell', () => {
|
|||||||
activeCameraId: active.camera.id,
|
activeCameraId: active.camera.id,
|
||||||
});
|
});
|
||||||
refreshHorizonCulling();
|
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`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { applyVesselFocusDeemphasis } from './aisLiveVessels.js';
|
|||||||
import { applyCctvFocusDeemphasis } from './cctv.js';
|
import { applyCctvFocusDeemphasis } from './cctv.js';
|
||||||
import { applySatellitePointFocusDeemphasis } from './satellites.js';
|
import { applySatellitePointFocusDeemphasis } from './satellites.js';
|
||||||
import { DEFAULT_FOCUS_DEEMPHASIS_PARAMS } from './focusDeemphasis.js';
|
import { DEFAULT_FOCUS_DEEMPHASIS_PARAMS } from './focusDeemphasis.js';
|
||||||
import { mirrorBillboard } from './billboardMirror.js';
|
|
||||||
import { createIconSet } from './iconSet.js';
|
import { createIconSet } from './iconSet.js';
|
||||||
|
|
||||||
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
|
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
|
||||||
@@ -29,7 +28,11 @@ function assertResumeGate(name, makePass) {
|
|||||||
const { pass, readAlpha } = makePass();
|
const { pass, readAlpha } = makePass();
|
||||||
let activeCount = 0;
|
let activeCount = 0;
|
||||||
const tick = (nowMs, focusTarget) => {
|
const tick = (nowMs, focusTarget) => {
|
||||||
const result = pass({ nowMs, target: focusTarget, previousActiveCount: activeCount });
|
const result = pass({
|
||||||
|
nowMs,
|
||||||
|
target: focusTarget,
|
||||||
|
previousActiveCount: activeCount,
|
||||||
|
});
|
||||||
activeCount = result.activeCount;
|
activeCount = result.activeCount;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -40,7 +43,11 @@ function assertResumeGate(name, makePass) {
|
|||||||
assert.equal(readAlpha(), params.dimFloor);
|
assert.equal(readAlpha(), params.dimFloor);
|
||||||
|
|
||||||
const releaseStart = tick(params.attackMs + 1, null);
|
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);
|
assert.equal(releaseStart.activeCount, 1);
|
||||||
|
|
||||||
const restored = tick(params.attackMs + params.releaseMs + 2, null);
|
const restored = tick(params.attackMs + params.releaseMs + 2, null);
|
||||||
@@ -48,16 +55,23 @@ function assertResumeGate(name, makePass) {
|
|||||||
assert.equal(restored.activeCount, 0);
|
assert.equal(restored.activeCount, 0);
|
||||||
assert.equal(readAlpha(), 1);
|
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', () => {
|
assertResumeGate('vessel', () => {
|
||||||
const icons = createIconSet();
|
const icons = createIconSet();
|
||||||
icons.setSize(icons.add('353136000', { id: '353136000' }), 32, 32);
|
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 {
|
return {
|
||||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
|
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
|
||||||
applyVesselFocusDeemphasis({
|
applyVesselFocusDeemphasis({
|
||||||
records: [record],
|
records: [record],
|
||||||
icons,
|
icons,
|
||||||
@@ -67,36 +81,30 @@ assertResumeGate('vessel', () => {
|
|||||||
screenPositionFor: () => ({ x: 50, y: 50 }),
|
screenPositionFor: () => ({ x: 50, y: 50 }),
|
||||||
cameraDistanceFor: () => 1200,
|
cameraDistanceFor: () => 1200,
|
||||||
params,
|
params,
|
||||||
})
|
}),
|
||||||
),
|
|
||||||
readAlpha: () => icons.focus(icons.row('353136000')),
|
readAlpha: () => icons.focus(icons.row('353136000')),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
assertResumeGate('CCTV', () => {
|
assertResumeGate('CCTV', () => {
|
||||||
const billboard = mirrorBillboard({
|
const icons = createIconSet();
|
||||||
position: { x: 1, y: 2, z: 3 },
|
const row = icons.add('cam-1', { id: 'cam-1' });
|
||||||
show: true,
|
icons.setSize(row, 24, 24);
|
||||||
width: 24,
|
icons.setShown(row, true);
|
||||||
height: 24,
|
const record = { camera: { id: 'cam-1' }, position: { x: 1, y: 2, z: 3 } };
|
||||||
scale: 1,
|
|
||||||
color: color(),
|
|
||||||
});
|
|
||||||
const record = { camera: { id: 'cam-1' }, billboard };
|
|
||||||
return {
|
return {
|
||||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
|
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
|
||||||
applyCctvFocusDeemphasis({
|
applyCctvFocusDeemphasis({
|
||||||
records: [record],
|
records: [record],
|
||||||
|
icons,
|
||||||
target: focusTarget,
|
target: focusTarget,
|
||||||
previousActiveCount,
|
previousActiveCount,
|
||||||
nowMs,
|
nowMs,
|
||||||
screenPositionFor: () => ({ x: 50, y: 50 }),
|
screenPositionFor: () => ({ x: 50, y: 50 }),
|
||||||
cameraDistanceFor: () => 1200,
|
cameraDistanceFor: () => 1200,
|
||||||
baseColorFor: () => color(),
|
|
||||||
params,
|
params,
|
||||||
})
|
}),
|
||||||
),
|
readAlpha: () => icons.focus(icons.row('cam-1')),
|
||||||
readAlpha: () => billboard.color.alpha,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -108,7 +116,7 @@ assertResumeGate('satellite', () => {
|
|||||||
color: color(),
|
color: color(),
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
|
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
|
||||||
applySatellitePointFocusDeemphasis({
|
applySatellitePointFocusDeemphasis({
|
||||||
points: new Map([[42, point]]),
|
points: new Map([[42, point]]),
|
||||||
trackedId: null,
|
trackedId: null,
|
||||||
@@ -119,8 +127,7 @@ assertResumeGate('satellite', () => {
|
|||||||
cameraDistanceFor: () => 1200,
|
cameraDistanceFor: () => 1200,
|
||||||
baseColorFor: () => color(),
|
baseColorFor: () => color(),
|
||||||
params,
|
params,
|
||||||
})
|
}),
|
||||||
),
|
|
||||||
readAlpha: () => point.color.alpha,
|
readAlpha: () => point.color.alpha,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -259,10 +259,14 @@ export class IconSetPrimitive {
|
|||||||
|
|
||||||
update(frameState) {
|
update(frameState) {
|
||||||
const set = this.set;
|
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 (
|
if (
|
||||||
!this.show ||
|
!this.show ||
|
||||||
!set.show ||
|
!set.show ||
|
||||||
(!frameState.passes.render && !frameState.passes.pick)
|
(!frameState.passes.render && !frameState.passes.pick) ||
|
||||||
|
frameState.passes.offscreen
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
const context = frameState.context;
|
const context = frameState.context;
|
||||||
@@ -446,6 +450,9 @@ export class IconSetPrimitive {
|
|||||||
handle = {
|
handle = {
|
||||||
pickId: context.createPickId({
|
pickId: context.createPickId({
|
||||||
id,
|
id,
|
||||||
|
// Which set drew the pick: ownership for layers whose row ids are
|
||||||
|
// upstream ids a sibling may share.
|
||||||
|
iconSet: set,
|
||||||
get meta() {
|
get meta() {
|
||||||
const at = set.row(id);
|
const at = set.row(id);
|
||||||
return at >= 0 ? set.metaAt(at) : undefined;
|
return at >= 0 ? set.metaAt(at) : undefined;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
poseHash,
|
poseHash,
|
||||||
requiredPlaneLift,
|
requiredPlaneLift,
|
||||||
} from '../../data/cctvFootprint.js';
|
} from '../../data/cctvFootprint.js';
|
||||||
import { setBillboard } from '../../data/billboardMirror.js';
|
|
||||||
import { cctvPicks } from './pickState.js';
|
import { cctvPicks } from './pickState.js';
|
||||||
|
|
||||||
export function createGeometry({ state: layerState, services, parts, source }) {
|
export function createGeometry({ state: layerState, services, parts, source }) {
|
||||||
@@ -328,7 +327,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Recomputes the pure frustum geometry from the camera pose + the given ground
|
* Recomputes the pure frustum geometry from the camera pose + the given ground
|
||||||
* altitude and writes it into the scene: billboard position, the 5 wireframe
|
* altitude and writes it into the scene: icon position, the 5 wireframe
|
||||||
* polylines (4 corner rays + closed far-plane rectangle), and the monitor
|
* polylines (4 corner rays + closed far-plane rectangle), and the monitor
|
||||||
* plane placement. This is the ONLY place v2 geometry is written — called on
|
* plane placement. This is the ONLY place v2 geometry is written — called on
|
||||||
* slider input / save / activation / the one-shot ground snap, never per frame.
|
* slider input / save / activation / the one-shot ground snap, never per frame.
|
||||||
@@ -348,9 +347,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
|
|||||||
record.frustumPositions = positions;
|
record.frustumPositions = positions;
|
||||||
record.position = positions.mount;
|
record.position = positions.mount;
|
||||||
record.camera.absoluteHeightM = geometry.mount.alt;
|
record.camera.absoluteHeightM = geometry.mount.alt;
|
||||||
if (record.billboard) {
|
parts.rendering.moveCameraIcon(record);
|
||||||
setBillboard(record.billboard, 'position', positions.mount);
|
|
||||||
}
|
|
||||||
if (record.coverageEntities?.length >= 5) {
|
if (record.coverageEntities?.length >= 5) {
|
||||||
record.coverageEntities[0].polyline.positions = [
|
record.coverageEntities[0].polyline.positions = [
|
||||||
positions.mount,
|
positions.mount,
|
||||||
@@ -458,7 +455,6 @@ export function createGeometry({ state: layerState, services, parts, source }) {
|
|||||||
(record.groundMeshSampleRequestCount || 0) + 1;
|
(record.groundMeshSampleRequestCount || 0) + 1;
|
||||||
const viewerCarto = layerState._viewer?.camera?.positionCartographic;
|
const viewerCarto = layerState._viewer?.camera?.positionCartographic;
|
||||||
const excludeObjects = [...(record.coverageEntities || [])];
|
const excludeObjects = [...(record.coverageEntities || [])];
|
||||||
if (record.billboard) excludeObjects.push(record.billboard);
|
|
||||||
if (record.projection?.planeEntity)
|
if (record.projection?.planeEntity)
|
||||||
excludeObjects.push(record.projection.planeEntity);
|
excludeObjects.push(record.projection.planeEntity);
|
||||||
sampleMeshFloorCells(layerState._viewer?.scene, [point], {
|
sampleMeshFloorCells(layerState._viewer?.scene, [point], {
|
||||||
@@ -644,8 +640,9 @@ export function createGeometry({ state: layerState, services, parts, source }) {
|
|||||||
);
|
);
|
||||||
const { dir } = frustumFrameEcef(camera, mountPos);
|
const { dir } = frustumFrameEcef(camera, mountPos);
|
||||||
// Exclude everything the layer itself draws so the probe can only hit the
|
// Exclude everything the layer itself draws so the probe can only hit the
|
||||||
// world (3D tiles), not our own billboards/polylines/planes.
|
// world (3D tiles), not our own polylines/planes. Icons never draw into
|
||||||
const exclude = [layerState._billboards, ...layerState._coverageEntities];
|
// ray picks.
|
||||||
|
const exclude = [...layerState._coverageEntities];
|
||||||
for (const runtime of layerState._projectionEntities) {
|
for (const runtime of layerState._projectionEntities) {
|
||||||
if (runtime?.planeEntity) exclude.push(runtime.planeEntity);
|
if (runtime?.planeEntity) exclude.push(runtime.planeEntity);
|
||||||
}
|
}
|
||||||
@@ -699,6 +696,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
|
|||||||
record.frustumGeometry = geometry;
|
record.frustumGeometry = geometry;
|
||||||
record.frustumPositions = positions;
|
record.frustumPositions = positions;
|
||||||
record.position = positions.mount;
|
record.position = positions.mount;
|
||||||
|
parts.rendering.moveCameraIcon(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
const addPolyline = (role, linePositions) => {
|
const addPolyline = (role, linePositions) => {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
planeSupportPoints,
|
planeSupportPoints,
|
||||||
poseHash,
|
poseHash,
|
||||||
} from '../../data/cctvFootprint.js';
|
} from '../../data/cctvFootprint.js';
|
||||||
import { setBillboard } from '../../data/billboardMirror.js';
|
|
||||||
|
|
||||||
/** Cooldown before a provisional (geoid-fallback / partial) footprint is retried. */
|
/** Cooldown before a provisional (geoid-fallback / partial) footprint is retried. */
|
||||||
const FOOTPRINT_RETRY_MS = 60_000;
|
const FOOTPRINT_RETRY_MS = 60_000;
|
||||||
@@ -239,8 +238,7 @@ export function createGround({ state: layerState, services, parts, source }) {
|
|||||||
undefined,
|
undefined,
|
||||||
record.position,
|
record.position,
|
||||||
);
|
);
|
||||||
if (record.billboard)
|
parts.rendering.moveCameraIcon(record);
|
||||||
setBillboard(record.billboard, 'position', record.position);
|
|
||||||
moved += 1;
|
moved += 1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ export function createCctvLayer({ services, source }) {
|
|||||||
_extractPickedCameraIdForTest:
|
_extractPickedCameraIdForTest:
|
||||||
parts.testing._extractPickedCameraIdForTest,
|
parts.testing._extractPickedCameraIdForTest,
|
||||||
_setCctvCoverageStateForTest: parts.testing._setCctvCoverageStateForTest,
|
_setCctvCoverageStateForTest: parts.testing._setCctvCoverageStateForTest,
|
||||||
|
_cctvIconsForTest: parts.testing._cctvIconsForTest,
|
||||||
focusCctvRecord: parts.navigation.focusCctvRecord,
|
focusCctvRecord: parts.navigation.focusCctvRecord,
|
||||||
maybeAutoHop: parts.navigation.maybeAutoHop,
|
maybeAutoHop: parts.navigation.maybeAutoHop,
|
||||||
cctvCycleIndex: parts.navigation.cctvCycleIndex,
|
cctvCycleIndex: parts.navigation.cctvCycleIndex,
|
||||||
|
|||||||
@@ -4,15 +4,12 @@ import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
|||||||
import { GIZMO_ID_PREFIX } from '../../data/cctvGizmo.js';
|
import { GIZMO_ID_PREFIX } from '../../data/cctvGizmo.js';
|
||||||
import {
|
import {
|
||||||
GROUND_PRIOR_INIT_WAIT_MS,
|
GROUND_PRIOR_INIT_WAIT_MS,
|
||||||
CAMERA_ICON,
|
|
||||||
IDLE_CAMERA_COLOR,
|
|
||||||
CALIBRATION_RANGE_FLOOR_M,
|
CALIBRATION_RANGE_FLOOR_M,
|
||||||
VIEW_MOTION_REFRESH_MS,
|
VIEW_MOTION_REFRESH_MS,
|
||||||
VIEW_MOTION_MIN_MOVE_FRACTION,
|
VIEW_MOTION_MIN_MOVE_FRACTION,
|
||||||
VIEW_MOTION_MIN_TURN_DEG,
|
VIEW_MOTION_MIN_TURN_DEG,
|
||||||
VIEW_MOTION_COST_FACTOR,
|
VIEW_MOTION_COST_FACTOR,
|
||||||
} from './policy.js';
|
} from './policy.js';
|
||||||
import { addBillboard } from '../../data/billboardMirror.js';
|
|
||||||
|
|
||||||
const MIN_TURN_COS = Math.cos((VIEW_MOTION_MIN_TURN_DEG * Math.PI) / 180);
|
const MIN_TURN_COS = Math.cos((VIEW_MOTION_MIN_TURN_DEG * Math.PI) / 180);
|
||||||
|
|
||||||
@@ -134,7 +131,7 @@ export function createLifecycle({
|
|||||||
const methods = {
|
const methods = {
|
||||||
/**
|
/**
|
||||||
* Initializes the CCTV layer: loads camera sources, builds the catalog,
|
* Initializes the CCTV layer: loads camera sources, builds the catalog,
|
||||||
* restores calibration from localStorage, creates billboards, sets up click
|
* restores calibration from localStorage, creates camera icons, sets up click
|
||||||
* handling, and performs initial health sync. Coverage entities stay lazy.
|
* handling, and performs initial health sync. Coverage entities stay lazy.
|
||||||
* @param {Cesium.Viewer} viewer - The Cesium viewer instance.
|
* @param {Cesium.Viewer} viewer - The Cesium viewer instance.
|
||||||
*/
|
*/
|
||||||
@@ -156,16 +153,10 @@ export function createLifecycle({
|
|||||||
layerState._lastViewContext = '';
|
layerState._lastViewContext = '';
|
||||||
layerState._calibrationById = parts.calibration.loadCalibrationStore();
|
layerState._calibrationById = parts.calibration.loadCalibrationStore();
|
||||||
|
|
||||||
layerState._billboards = new Cesium.BillboardCollection();
|
registerSpriteCollection(
|
||||||
// Cesium switches a property's buffer-usage hint whenever it starts or
|
'cctv',
|
||||||
// stops changing from one frame to the next, and every switch rewrites
|
parts.rendering.createCameraIcons(layerState._viewer),
|
||||||
// the vertex data of every billboard. The view pass toggles `show` on a
|
);
|
||||||
// few icons of a large catalog at a time, so on a 33K catalog each pass
|
|
||||||
// cost two full rewrites. With the hint fixed, Cesium uploads only the
|
|
||||||
// icons that changed.
|
|
||||||
layerState._billboards.computeNewBuffersUsage = () => false;
|
|
||||||
layerState._viewer.scene.primitives.add(layerState._billboards);
|
|
||||||
registerSpriteCollection('cctv', layerState._billboards);
|
|
||||||
|
|
||||||
const sources = await parts.catalog.loadCameraSources();
|
const sources = await parts.catalog.loadCameraSources();
|
||||||
const catalogFromSources = parts.catalog.buildCatalogFromSources(sources);
|
const catalogFromSources = parts.catalog.buildCatalogFromSources(sources);
|
||||||
@@ -238,27 +229,9 @@ export function createLifecycle({
|
|||||||
camera.lat,
|
camera.lat,
|
||||||
camera.absoluteHeightM,
|
camera.absoluteHeightM,
|
||||||
);
|
);
|
||||||
const billboard = addBillboard(layerState._billboards, {
|
|
||||||
id: camera.id,
|
|
||||||
image: CAMERA_ICON,
|
|
||||||
position,
|
|
||||||
color: IDLE_CAMERA_COLOR,
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
// Field-test fix (2026-07-06): always-on-top. The old finite value
|
|
||||||
// (1800 m) re-engaged the depth test at far zoom, where the COARSE
|
|
||||||
// far-LOD Google-3D mesh sits above the true ground and swallowed
|
|
||||||
// ground-anchored icons ("submerged" pills over SF). Far-side-of-globe
|
|
||||||
// icons are handled by refreshHorizonCulling() (the flights-layer
|
|
||||||
// EllipsoidalOccluder pattern), not by the depth test.
|
|
||||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
||||||
scaleByDistance: new Cesium.NearFarScalar(350, 1.25, 4_000_000, 0.42),
|
|
||||||
});
|
|
||||||
|
|
||||||
const record = {
|
const record = {
|
||||||
camera,
|
camera,
|
||||||
position,
|
position,
|
||||||
billboard,
|
|
||||||
coverageEntities: [],
|
coverageEntities: [],
|
||||||
projection: null,
|
projection: null,
|
||||||
// Task 5 (height-datum fix): regime-aware ground resolution state.
|
// Task 5 (height-datum fix): regime-aware ground resolution state.
|
||||||
@@ -297,6 +270,7 @@ export function createLifecycle({
|
|||||||
};
|
};
|
||||||
layerState._records.push(record);
|
layerState._records.push(record);
|
||||||
layerState._recordById.set(camera.id, record);
|
layerState._recordById.set(camera.id, record);
|
||||||
|
parts.rendering.addCameraIcon(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
layerState._count = layerState._records.length;
|
layerState._count = layerState._records.length;
|
||||||
@@ -334,7 +308,7 @@ export function createLifecycle({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Field-test fix (2026-07-06): horizon-cull on camera settle (pairs with
|
// Field-test fix (2026-07-06): horizon-cull on camera settle (pairs with
|
||||||
// the billboards' always-on-top depth setting) + one initial pass so the
|
// the icons' always-on-top drawing) + one initial pass so the
|
||||||
// first paint is already culled.
|
// first paint is already culled.
|
||||||
// A re-init against a new viewer moves the move listeners to its camera.
|
// A re-init against a new viewer moves the move listeners to its camera.
|
||||||
if (
|
if (
|
||||||
@@ -493,7 +467,7 @@ export function createLifecycle({
|
|||||||
)
|
)
|
||||||
services.credits?.showOsmCredit?.(layerState._viewer, 'cctv');
|
services.credits?.showOsmCredit?.(layerState._viewer, 'cctv');
|
||||||
layerState._lastUpdate = Date.now();
|
layerState._lastUpdate = Date.now();
|
||||||
// Pick-ownership (H2): camera billboards use the camera id directly;
|
// Pick-ownership (H2): camera icons use the camera id directly;
|
||||||
// coverage polyline entities use `cctv-<cameraId>-<role>` entity ids.
|
// coverage polyline entities use `cctv-<cameraId>-<role>` entity ids.
|
||||||
registerPickOwner('cctv', (pickedId) => {
|
registerPickOwner('cctv', (pickedId) => {
|
||||||
if (layerState._recordById.has(pickedId)) return true;
|
if (layerState._recordById.has(pickedId)) return true;
|
||||||
@@ -565,7 +539,7 @@ export function createLifecycle({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tears down the layer: destroys click handler, projection loop, coverage
|
* Tears down the layer: destroys click handler, projection loop, coverage
|
||||||
* entities, billboards, and clears all runtime state and subscribers.
|
* entities, icons, and clears all runtime state and subscribers.
|
||||||
* @param {Cesium.Viewer} [viewer] - Viewer instance (falls back to stored ref).
|
* @param {Cesium.Viewer} [viewer] - Viewer instance (falls back to stored ref).
|
||||||
*/
|
*/
|
||||||
destroy(viewer) {
|
destroy(viewer) {
|
||||||
@@ -621,10 +595,7 @@ export function createLifecycle({
|
|||||||
parts.geometryQueue.stopGeometryLoadQueue();
|
parts.geometryQueue.stopGeometryLoadQueue();
|
||||||
parts.cards.teardownAmbientCards();
|
parts.cards.teardownAmbientCards();
|
||||||
parts.geometry.destroyCoverageEntities();
|
parts.geometry.destroyCoverageEntities();
|
||||||
if (layerState._billboards && teardownViewer) {
|
parts.rendering.destroyCameraIcons();
|
||||||
teardownViewer.scene.primitives.remove(layerState._billboards);
|
|
||||||
layerState._billboards = null;
|
|
||||||
}
|
|
||||||
clearRuntimeState();
|
clearRuntimeState();
|
||||||
layerState._viewer = null;
|
layerState._viewer = null;
|
||||||
layerState._enabled = false;
|
layerState._enabled = false;
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ export const DEFAULT_CAMERA_CALIBRATION = Object.freeze({
|
|||||||
heightM: 0,
|
heightM: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Base64-encoded SVG camera icon for billboard rendering. */
|
/** Base64-encoded SVG camera icon for the camera icon rows. */
|
||||||
|
|
||||||
export const CAMERA_ICON = (() => {
|
export const CAMERA_ICON = (() => {
|
||||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
|
||||||
|
|||||||
+121
-43
@@ -2,6 +2,7 @@ import * as Cesium from 'cesium';
|
|||||||
import { isHeadingEstimated } from './headingConfidence.js';
|
import { isHeadingEstimated } from './headingConfidence.js';
|
||||||
import {
|
import {
|
||||||
ACTIVE_CAMERA_COLOR,
|
ACTIVE_CAMERA_COLOR,
|
||||||
|
CAMERA_ICON,
|
||||||
IDLE_CAMERA_COLOR,
|
IDLE_CAMERA_COLOR,
|
||||||
LIVE_CAMERA_COLOR,
|
LIVE_CAMERA_COLOR,
|
||||||
ACTIVE_COVERAGE_CENTER,
|
ACTIVE_COVERAGE_CENTER,
|
||||||
@@ -14,7 +15,24 @@ import {
|
|||||||
VIEW_ICON_MARGIN,
|
VIEW_ICON_MARGIN,
|
||||||
VIEW_MIN_CELL_M,
|
VIEW_MIN_CELL_M,
|
||||||
} from './policy.js';
|
} from './policy.js';
|
||||||
import { billboardState, setBillboard } from '../../data/billboardMirror.js';
|
import { createIconSet } from '../../data/iconSet.js';
|
||||||
|
import { writeHoldSegment } from '../../data/iconSegment.js';
|
||||||
|
import { IconSetPrimitive } from '../../data/iconSetPrimitive.js';
|
||||||
|
import { iconAtlas } from '../../data/iconAtlas.js';
|
||||||
|
|
||||||
|
/** The camera icon's drawn size (px). */
|
||||||
|
const CAMERA_ICON_PX = 24;
|
||||||
|
/**
|
||||||
|
* Its atlas raster: 1.25× near scale on a 2× display draws it at 60 device px,
|
||||||
|
* so it is rasterised past the drawn size to stay sharp there.
|
||||||
|
*/
|
||||||
|
const CAMERA_RASTER_PX = 48;
|
||||||
|
const CAMERA_SCALE_BY_DISTANCE = new Cesium.NearFarScalar(
|
||||||
|
350,
|
||||||
|
1.25,
|
||||||
|
4_000_000,
|
||||||
|
0.42,
|
||||||
|
);
|
||||||
|
|
||||||
/** FNV-1a over a camera id: a stable, well-spread order for crowded cells. */
|
/** FNV-1a over a camera id: a stable, well-spread order for crowded cells. */
|
||||||
function idHash(id) {
|
function idHash(id) {
|
||||||
@@ -32,6 +50,72 @@ export function createRendering({
|
|||||||
parts,
|
parts,
|
||||||
source,
|
source,
|
||||||
}) {
|
}) {
|
||||||
|
/** The scene the icon primitive was added to. */
|
||||||
|
let iconScene = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The catalog's icon set and the primitive that draws it. Cameras hold still,
|
||||||
|
* so each row is a hold segment and the primitive's clock only keeps segment
|
||||||
|
* times small. Rows draw depth-test-free (field-test fix 2026-07-06: the old
|
||||||
|
* finite depth-test distance re-engaged at far zoom, where the COARSE
|
||||||
|
* far-LOD Google-3D mesh sits above the true ground and swallowed
|
||||||
|
* ground-anchored icons); the GPU culls the far side of the globe and
|
||||||
|
* refreshHorizonCulling thins the rest.
|
||||||
|
* @param {Cesium.Viewer} viewer
|
||||||
|
*/
|
||||||
|
function createCameraIcons(viewer) {
|
||||||
|
// A re-init against a new viewer replaces the icons; the old ones go.
|
||||||
|
destroyCameraIcons();
|
||||||
|
const epoch = Cesium.JulianDate.now();
|
||||||
|
layerState._icons = createIconSet({ epoch });
|
||||||
|
layerState._iconPrimitive = new IconSetPrimitive({
|
||||||
|
set: layerState._icons,
|
||||||
|
renderTime: () => epoch,
|
||||||
|
requestRender: () => layerState._viewer?.scene?.requestRender?.(),
|
||||||
|
});
|
||||||
|
viewer.scene.primitives.add(layerState._iconPrimitive);
|
||||||
|
iconScene = viewer.scene;
|
||||||
|
return layerState._iconPrimitive;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the icons out of the scene they were added to, whichever viewer the
|
||||||
|
* caller tears down, and free them: a destroyed primitive left in a live
|
||||||
|
* scene throws on its next frame.
|
||||||
|
*/
|
||||||
|
function destroyCameraIcons() {
|
||||||
|
const primitive = layerState._iconPrimitive;
|
||||||
|
if (primitive && iconScene && !iconScene.isDestroyed?.())
|
||||||
|
iconScene.primitives.remove(primitive);
|
||||||
|
if (primitive && !primitive.isDestroyed()) primitive.destroy();
|
||||||
|
iconScene = null;
|
||||||
|
layerState._iconPrimitive = null;
|
||||||
|
layerState._icons = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add a camera record's icon row, idle and shown, at its position. */
|
||||||
|
function addCameraIcon(record) {
|
||||||
|
const set = layerState._icons;
|
||||||
|
const id = record.camera.id;
|
||||||
|
const row = set.add(id, { layer: 'cctv', id });
|
||||||
|
const slot = iconAtlas.slot(CAMERA_ICON, CAMERA_RASTER_PX);
|
||||||
|
set.setImage(row, slot, slot);
|
||||||
|
set.setSize(row, CAMERA_ICON_PX, CAMERA_ICON_PX);
|
||||||
|
set.setScaleByDistance(row, CAMERA_SCALE_BY_DISTANCE);
|
||||||
|
set.setColor(row, cameraColorFor(record));
|
||||||
|
set.setShown(row, true);
|
||||||
|
moveCameraIcon(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hold a camera's row at its record's current position. */
|
||||||
|
function moveCameraIcon(record) {
|
||||||
|
const set = layerState._icons;
|
||||||
|
const row = set?.row(record.camera.id) ?? -1;
|
||||||
|
if (row < 0 || !record.position) return;
|
||||||
|
writeHoldSegment(set.segments, row, record.position, 0);
|
||||||
|
set.segmentWritten(row);
|
||||||
|
}
|
||||||
|
|
||||||
/** Icon color: active wins, then live-capable video feeds, then idle stills. */
|
/** Icon color: active wins, then live-capable video feeds, then idle stills. */
|
||||||
function cameraColorFor(record) {
|
function cameraColorFor(record) {
|
||||||
if (record.camera.id === layerState._activeCameraId)
|
if (record.camera.id === layerState._activeCameraId)
|
||||||
@@ -81,25 +165,26 @@ export function createRendering({
|
|||||||
),
|
),
|
||||||
cameraDistanceFor: (position) =>
|
cameraDistanceFor: (position) =>
|
||||||
Cesium.Cartesian3.distance(camera.positionWC, position),
|
Cesium.Cartesian3.distance(camera.positionWC, position),
|
||||||
baseColorFor: cameraColorFor,
|
|
||||||
});
|
});
|
||||||
layerState._activeFocusStyleCount = result.activeCount;
|
layerState._activeFocusStyleCount = result.activeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the gated CCTV focus pass through the production color path.
|
* Apply the gated CCTV focus pass through the set's focus column (the shader
|
||||||
|
* multiplies it into the base color's alpha).
|
||||||
* @param {object} input
|
* @param {object} input
|
||||||
|
* @param {object} [input.icons] The icon set (defaults to the layer's).
|
||||||
* @returns {{writes:number,transitioning:boolean,activeCount:number,ran:boolean}}
|
* @returns {{writes:number,transitioning:boolean,activeCount:number,ran:boolean}}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function applyCctvFocusDeemphasis({
|
function applyCctvFocusDeemphasis({
|
||||||
records,
|
records,
|
||||||
|
icons = layerState._icons,
|
||||||
target,
|
target,
|
||||||
previousActiveCount = 0,
|
previousActiveCount = 0,
|
||||||
nowMs,
|
nowMs,
|
||||||
screenPositionFor,
|
screenPositionFor,
|
||||||
cameraDistanceFor,
|
cameraDistanceFor,
|
||||||
baseColorFor,
|
|
||||||
params,
|
params,
|
||||||
}) {
|
}) {
|
||||||
if (!focusPassIsNeeded(target, previousActiveCount)) {
|
if (!focusPassIsNeeded(target, previousActiveCount)) {
|
||||||
@@ -109,31 +194,28 @@ export function createRendering({
|
|||||||
let transitioning = false;
|
let transitioning = false;
|
||||||
let activeCount = 0;
|
let activeCount = 0;
|
||||||
for (const record of records || []) {
|
for (const record of records || []) {
|
||||||
const bb = record.billboard;
|
const row = icons?.row(record.camera?.id) ?? -1;
|
||||||
if (!bb) continue;
|
if (row < 0) continue;
|
||||||
const icon = billboardState(bb);
|
const position = record.position;
|
||||||
const position = icon.position;
|
|
||||||
// CCTV never publishes a tracked focus target, so every icon is ambient.
|
// CCTV never publishes a tracked focus target, so every icon is ambient.
|
||||||
const focus = advanceSpriteFocus(bb, {
|
const focus = advanceSpriteFocus(icons.metaAt(row), {
|
||||||
// Keep hidden icons in the state/release pass so the active count cannot
|
// Keep hidden icons in the state/release pass so the active count cannot
|
||||||
// drop while a stale dim alpha remains waiting to reappear.
|
// drop while a stale dim alpha remains waiting to reappear.
|
||||||
screenPosition:
|
screenPosition:
|
||||||
icon.show === false || !position ? null : screenPositionFor(position),
|
!icons.shown(row) || !position ? null : screenPositionFor(position),
|
||||||
cameraDistance: position ? cameraDistanceFor(position) : Number.NaN,
|
cameraDistance: position ? cameraDistanceFor(position) : Number.NaN,
|
||||||
nowMs,
|
nowMs,
|
||||||
target,
|
target,
|
||||||
params,
|
params,
|
||||||
spriteHalfWidthPx: (icon.width || 24) * (icon.scale || 1) * 0.5,
|
spriteHalfWidthPx: icons.width(row) * icons.scale(row) * 0.5,
|
||||||
spriteHalfHeightPx: (icon.height || 24) * (icon.scale || 1) * 0.5,
|
spriteHalfHeightPx: icons.height(row) * icons.scale(row) * 0.5,
|
||||||
});
|
});
|
||||||
transitioning ||= focus.transitioning;
|
transitioning ||= focus.transitioning;
|
||||||
if (focus.active) activeCount += 1;
|
if (focus.active) activeCount += 1;
|
||||||
const base = baseColorFor(record);
|
|
||||||
const alpha = base.alpha * focus.factor;
|
|
||||||
if (focusAlphaNeedsWrite(bb.color?.alpha, alpha, params)) {
|
|
||||||
// Order-independent narrow amendment to always-visible icons: CCTV
|
// Order-independent narrow amendment to always-visible icons: CCTV
|
||||||
// contacts retain a non-zero floor while yielding near the tracked target.
|
// contacts retain a non-zero floor while yielding near the tracked target.
|
||||||
bb.color = base.withAlpha(alpha);
|
if (focusAlphaNeedsWrite(icons.focus(row), focus.factor, params)) {
|
||||||
|
icons.setFocus(row, focus.factor);
|
||||||
writes += 1;
|
writes += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,18 +223,17 @@ export function createRendering({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates visual styles (colors, widths, visibility) for all camera billboards,
|
* Updates visual styles (colors, widths, visibility) for all camera icons,
|
||||||
* coverage polylines, viewshed volumes, and projection entities based on which
|
* coverage polylines, viewshed volumes, and projection entities based on which
|
||||||
* camera is active, whether the layer is enabled, and the current
|
* camera is active, whether the layer is enabled, and the current
|
||||||
* coverage-mode/projection toggle states.
|
* coverage-mode/projection toggle states.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Field-test fix (2026-07-06): horizon-culls camera billboards, mirroring the
|
* Field-test fix (2026-07-06): horizon-culls camera icons on the CPU as the
|
||||||
* flights layer's EllipsoidalOccluder pass. With the Cesium globe hidden
|
* icon shader does on the GPU. With the Cesium globe hidden (Google-3D
|
||||||
* (Google-3D regime) nothing writes far-side depth, and the billboards are now
|
* regime) nothing writes far-side depth and the icons are always-on-top, so
|
||||||
* always-on-top (`disableDepthTestDistance: INFINITY` — the far-zoom submerge
|
* the shown set (cards, geometry, the picker) must not include London's
|
||||||
* fix), so without this pass London's cluster would shine through the planet
|
* cluster from a US viewpoint.
|
||||||
* from a US viewpoint.
|
|
||||||
*
|
*
|
||||||
* The same pass thins the view so a large catalog stays readable and cheap:
|
* The same pass thins the view so a large catalog stays readable and cheap:
|
||||||
* icons well off screen hide, and each camera competes for a world-anchored
|
* icons well off screen hide, and each camera competes for a world-anchored
|
||||||
@@ -202,7 +283,7 @@ export function createRendering({
|
|||||||
const shown = [];
|
const shown = [];
|
||||||
const cells = new Map();
|
const cells = new Map();
|
||||||
for (const record of layerState._records) {
|
for (const record of layerState._records) {
|
||||||
const position = billboardState(record.billboard)?.position;
|
const position = record.position;
|
||||||
if (!position) continue;
|
if (!position) continue;
|
||||||
const vx = position.x * inverseRadii.x - cx;
|
const vx = position.x * inverseRadii.x - cx;
|
||||||
const vy = position.y * inverseRadii.y - cy;
|
const vy = position.y * inverseRadii.y - cy;
|
||||||
@@ -243,12 +324,10 @@ export function createRendering({
|
|||||||
record.viewPass = pass;
|
record.viewPass = pass;
|
||||||
shown.push(record);
|
shown.push(record);
|
||||||
}
|
}
|
||||||
|
const icons = layerState._icons;
|
||||||
for (const record of layerState._records) {
|
for (const record of layerState._records) {
|
||||||
const bb = record.billboard;
|
const row = icons?.row(record.camera.id) ?? -1;
|
||||||
if (!bb) continue;
|
if (row >= 0) icons.setShown(row, record.viewPass === pass);
|
||||||
const visible = record.viewPass === pass;
|
|
||||||
if (billboardState(bb).show !== visible)
|
|
||||||
setBillboard(bb, 'show', visible);
|
|
||||||
}
|
}
|
||||||
const previous = layerState._viewRecords;
|
const previous = layerState._viewRecords;
|
||||||
const changed =
|
const changed =
|
||||||
@@ -369,7 +448,7 @@ export function createRendering({
|
|||||||
layerState._activeCameraId,
|
layerState._activeCameraId,
|
||||||
);
|
);
|
||||||
parts.projection.clearProjectionOverlay();
|
parts.projection.clearProjectionOverlay();
|
||||||
if (layerState._billboards) layerState._billboards.show = false;
|
if (layerState._icons) layerState._icons.show = false;
|
||||||
parts.projection.pauseInactiveProjectionFeeds(null);
|
parts.projection.pauseInactiveProjectionFeeds(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,19 +470,15 @@ export function createRendering({
|
|||||||
coverageVisible,
|
coverageVisible,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const icons = layerState._icons;
|
||||||
for (const record of layerState._records) {
|
for (const record of layerState._records) {
|
||||||
const isActive = record.camera.id === activeId;
|
const isActive = record.camera.id === activeId;
|
||||||
if (record.billboard) {
|
const row = icons?.row(record.camera.id) ?? -1;
|
||||||
// Unchanged writes still dirty the collection, which then rewrites
|
if (row >= 0) {
|
||||||
// every icon's vertices: across a large catalog, write only changes.
|
// The set skips unchanged writes, so across a large catalog only the
|
||||||
const color = cameraColorFor(record);
|
// changed rows upload.
|
||||||
if (!Cesium.Color.equals(record.billboard.color, color))
|
icons.setColor(row, cameraColorFor(record));
|
||||||
record.billboard.color = color;
|
icons.setScale(row, isActive ? 1.25 : 1.0);
|
||||||
const scale = isActive ? 1.25 : 1.0;
|
|
||||||
if (billboardState(record.billboard).scale !== scale)
|
|
||||||
setBillboard(record.billboard, 'scale', scale);
|
|
||||||
// disableDepthTestDistance stays POSITIVE_INFINITY for every billboard
|
|
||||||
// (set at creation) — see the field-test far-zoom submerge fix there.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -506,11 +581,14 @@ export function createRendering({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layerState._billboards)
|
if (layerState._icons) layerState._icons.show = !!layerState._enabled;
|
||||||
layerState._billboards.show = !!layerState._enabled;
|
|
||||||
parts.projection.pauseInactiveProjectionFeeds(activeId);
|
parts.projection.pauseInactiveProjectionFeeds(activeId);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
createCameraIcons,
|
||||||
|
destroyCameraIcons,
|
||||||
|
addCameraIcon,
|
||||||
|
moveCameraIcon,
|
||||||
refreshCctvFocusStyles,
|
refreshCctvFocusStyles,
|
||||||
applyCctvFocusDeemphasis,
|
applyCctvFocusDeemphasis,
|
||||||
refreshHorizonCulling,
|
refreshHorizonCulling,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Icon colors under focus de-emphasis (#1200): the focus pass fades each icon
|
// 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
|
// 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.
|
// 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 { test } from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { createRendering } from './rendering.js';
|
import { createRendering } from './rendering.js';
|
||||||
@@ -11,18 +12,22 @@ import {
|
|||||||
LIVE_CAMERA_COLOR,
|
LIVE_CAMERA_COLOR,
|
||||||
} from './policy.js';
|
} from './policy.js';
|
||||||
import { isVideoFeedType } from '../../sources/cctvTypes.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;
|
const FOCUS_FACTOR = 0.5;
|
||||||
|
|
||||||
function assertFadedFrom(actual, base, label) {
|
function assertKeepsColor(icons, id, base, label) {
|
||||||
assert.ok(actual, `${label}: color written`);
|
const row = icons.row(id);
|
||||||
|
const actual = icons.color(row);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
[actual.red, actual.green, actual.blue],
|
[actual.red, actual.green, actual.blue, actual.alpha].map(
|
||||||
[base.red, base.green, base.blue],
|
Cesium.Color.floatToByte,
|
||||||
`${label}: hue`,
|
),
|
||||||
|
[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', () => {
|
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 },
|
camera: { id, feedType },
|
||||||
// No position, so the pass skips screen projection; the focus stub below
|
// No position, so the pass skips screen projection; the focus stub below
|
||||||
// decides the factor on its own.
|
// decides the factor on its own.
|
||||||
billboard: mirrorBillboard({ show: true }),
|
|
||||||
});
|
});
|
||||||
const idleVideo = record('idle-hls', 'hls');
|
const idleVideo = record('idle-hls', 'hls');
|
||||||
const idleStill = record('idle-image', 'image');
|
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,
|
_activeCameraId: activeVideo.camera.id,
|
||||||
_activeFocusStyleCount: 0,
|
_activeFocusStyleCount: 0,
|
||||||
_lastFocusStyleAt: -Infinity,
|
_lastFocusStyleAt: -Infinity,
|
||||||
|
_icons: createIconSet(),
|
||||||
};
|
};
|
||||||
const focus = {
|
const focus = {
|
||||||
focusNowMs: (nowMs) => nowMs,
|
focusNowMs: (nowMs) => nowMs,
|
||||||
@@ -54,21 +59,55 @@ test('focus de-emphasis fades each icon from its own color', () => {
|
|||||||
}),
|
}),
|
||||||
focusAlphaNeedsWrite: () => true,
|
focusAlphaNeedsWrite: () => true,
|
||||||
};
|
};
|
||||||
const { refreshCctvFocusStyles } = createRendering({
|
const { addCameraIcon, refreshCctvFocusStyles } = createRendering({
|
||||||
state,
|
state,
|
||||||
services: { focus },
|
services: { focus },
|
||||||
parts: { model: { isVideoFeedType } },
|
parts: { model: { isVideoFeedType } },
|
||||||
source: {},
|
source: {},
|
||||||
});
|
});
|
||||||
|
for (const r of state._records) addCameraIcon(r);
|
||||||
|
|
||||||
refreshCctvFocusStyles(1000);
|
refreshCctvFocusStyles(1000);
|
||||||
|
|
||||||
assertFadedFrom(idleVideo.billboard.color, LIVE_CAMERA_COLOR, 'idle video');
|
const icons = state._icons;
|
||||||
assertFadedFrom(idleStill.billboard.color, IDLE_CAMERA_COLOR, 'idle still');
|
assertKeepsColor(icons, 'idle-hls', LIVE_CAMERA_COLOR, 'idle video');
|
||||||
assertFadedFrom(
|
assertKeepsColor(icons, 'idle-image', IDLE_CAMERA_COLOR, 'idle still');
|
||||||
activeVideo.billboard.color,
|
assertKeepsColor(icons, 'active-hls', ACTIVE_CAMERA_COLOR, 'active video');
|
||||||
ACTIVE_CAMERA_COLOR,
|
|
||||||
'active video',
|
|
||||||
);
|
|
||||||
assert.equal(state._activeFocusStyleCount, 3);
|
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);
|
||||||
|
});
|
||||||
@@ -207,7 +207,7 @@ export function createSelection({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts a camera ID from a Cesium pick result by checking billboard IDs,
|
* Extracts a camera ID from a Cesium pick result by checking icon row IDs,
|
||||||
* primitive IDs, and the camera ids the layer keeps for its coverage entities.
|
* primitive IDs, and the camera ids the layer keeps for its coverage entities.
|
||||||
* @param {Object|null} picked - Result from scene.pick().
|
* @param {Object|null} picked - Result from scene.pick().
|
||||||
* @returns {string|null} Camera ID, or null if the pick is not a CCTV entity.
|
* @returns {string|null} Camera ID, or null if the pick is not a CCTV entity.
|
||||||
@@ -237,10 +237,9 @@ export function createSelection({
|
|||||||
if (record && (ownsCoverageEntity || ownsProjectionEntity)) return value;
|
if (record && (ownsCoverageEntity || ownsProjectionEntity)) return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera billboard IDs are intentionally the upstream camera ID, so a
|
// Camera icon row IDs are intentionally the upstream camera ID, so a
|
||||||
// sibling may legitimately use the same string. A bare ID match is not
|
// sibling may legitimately use the same string. A bare ID match is not
|
||||||
// ownership proof: require this layer's billboard collection or the exact
|
// ownership proof: require that this layer's icon set drew the pick.
|
||||||
// billboard stored on the record.
|
|
||||||
const directId =
|
const directId =
|
||||||
typeof picked.id === 'string'
|
typeof picked.id === 'string'
|
||||||
? picked.id
|
? picked.id
|
||||||
@@ -250,8 +249,7 @@ export function createSelection({
|
|||||||
const record =
|
const record =
|
||||||
directId === null ? null : layerState._recordById.get(directId);
|
directId === null ? null : layerState._recordById.get(directId);
|
||||||
if (!record) return null;
|
if (!record) return null;
|
||||||
return picked.primitive === layerState._billboards ||
|
return layerState._icons && picked.iconSet === layerState._icons
|
||||||
picked.primitive === record.billboard
|
|
||||||
? directId
|
? directId
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ export function createState({ services }) {
|
|||||||
|
|
||||||
layerState._viewer = null;
|
layerState._viewer = null;
|
||||||
|
|
||||||
layerState._billboards = null;
|
/** The catalog's icon set and the primitive that draws it. */
|
||||||
|
layerState._icons = null;
|
||||||
|
layerState._iconPrimitive = null;
|
||||||
|
|
||||||
layerState._records = [];
|
layerState._records = [];
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as Cesium from 'cesium';
|
import * as Cesium from 'cesium';
|
||||||
|
import { createIconSet } from '../../data/iconSet.js';
|
||||||
|
|
||||||
export function createTesting({ state: layerState, services, parts, source }) {
|
export function createTesting({ state: layerState, services, parts, source }) {
|
||||||
/** Test seam: republishes host entries through the real push path, so tests
|
/** Test seam: republishes host entries through the real push path, so tests
|
||||||
@@ -101,7 +102,7 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
|||||||
);
|
);
|
||||||
layerState._coverageEntities = [];
|
layerState._coverageEntities = [];
|
||||||
layerState._projectionEntities = [];
|
layerState._projectionEntities = [];
|
||||||
layerState._billboards = null;
|
layerState._iconPrimitive = null;
|
||||||
layerState._activeCameraId = activeCameraId;
|
layerState._activeCameraId = activeCameraId;
|
||||||
layerState._autoHopSuspended = false;
|
layerState._autoHopSuspended = false;
|
||||||
layerState._enabled = !!enabled;
|
layerState._enabled = !!enabled;
|
||||||
@@ -115,6 +116,16 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
|||||||
layerState._cameraIndexCache = null;
|
layerState._cameraIndexCache = null;
|
||||||
layerState._coverageVisibleIds = new Set();
|
layerState._coverageVisibleIds = new Set();
|
||||||
layerState._neighborCountCache = null;
|
layerState._neighborCountCache = null;
|
||||||
|
// A real set (no primitive): every record gets its row as init adds it.
|
||||||
|
layerState._icons = createIconSet();
|
||||||
|
for (const record of layerState._records)
|
||||||
|
if (record?.camera?.id) parts.rendering.addCameraIcon(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The layer's icon set, for tests that read what the rows draw. */
|
||||||
|
|
||||||
|
function _cctvIconsForTest() {
|
||||||
|
return layerState._icons;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
_pushAmbientCardEntriesForTest,
|
_pushAmbientCardEntriesForTest,
|
||||||
@@ -123,5 +134,6 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
|||||||
_updateCctvProjectionPlaneForTest,
|
_updateCctvProjectionPlaneForTest,
|
||||||
_extractPickedCameraIdForTest,
|
_extractPickedCameraIdForTest,
|
||||||
_setCctvCoverageStateForTest,
|
_setCctvCoverageStateForTest,
|
||||||
|
_cctvIconsForTest,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user