mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Draw CCTV camera icons through the renderer ports and take rendering.js off the Cesium list
The camera icons are now a draw-port icon set kept by an icon book; only icons a view pass or restyle changes are written, in one write per pass. Picks read the renderer's hit, the view pass and focus pass project through the camera pose (geo/frustum.js poseProjector, matching the renderer's projection and near clip) and the query port, and tile readiness for ground sampling comes from the globe port.
This commit is contained in:
1 parent
2a607ec4d8
commit
1d08043bf9
20 files changed
+810
-457
No files matched your search
@@ -2556,6 +2556,8 @@
|
|||||||
"src/layers/cctv/projection.js",
|
"src/layers/cctv/projection.js",
|
||||||
"src/layers/cctv/videoPlayback.js",
|
"src/layers/cctv/videoPlayback.js",
|
||||||
"src/layers/cctv/rendering.js",
|
"src/layers/cctv/rendering.js",
|
||||||
|
"src/render/motion/iconBook.js",
|
||||||
|
"src/geo/frustum.js",
|
||||||
"src/render/cesium/iconOrientation.js",
|
"src/render/cesium/iconOrientation.js",
|
||||||
"src/render/cesium/iconSetPrimitive.js",
|
"src/render/cesium/iconSetPrimitive.js",
|
||||||
"src/data/iconSet.js",
|
"src/data/iconSet.js",
|
||||||
|
|||||||
+27
-24
@@ -349,6 +349,8 @@ 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 },
|
||||||
|
// Every catalog record is placed as it is made, and drawn there.
|
||||||
|
position: { x: 6378137, y: 0, z: 0 },
|
||||||
coverageEntities: [],
|
coverageEntities: [],
|
||||||
projection: null,
|
projection: null,
|
||||||
});
|
});
|
||||||
@@ -370,18 +372,12 @@ test('camera icons are violet for video feeds, cyan for stills, amber when activ
|
|||||||
});
|
});
|
||||||
refreshCoverageStyles();
|
refreshCoverageStyles();
|
||||||
const icons = _cctvIconsForTest();
|
const icons = _cctvIconsForTest();
|
||||||
const color = (record) => icons.color(icons.row(record.camera.id));
|
const color = (record) => icons.item(record.camera.id).color;
|
||||||
const bytes = (c) =>
|
assert.deepEqual(color(idleVideo), LIVE_CAMERA_COLOR);
|
||||||
[c.red, c.green, c.blue, c.alpha].map(Cesium.Color.floatToByte);
|
assert.deepEqual(color(idleStill), IDLE_CAMERA_COLOR);
|
||||||
const policyBytes = (rgba) => rgba.map(Cesium.Color.floatToByte);
|
assert.deepEqual(color(activeVideo), ACTIVE_CAMERA_COLOR);
|
||||||
assert.deepEqual(bytes(color(idleVideo)), policyBytes(LIVE_CAMERA_COLOR));
|
assert.equal(icons.item(activeVideo.camera.id).scale, 1.25);
|
||||||
assert.deepEqual(bytes(color(idleStill)), policyBytes(IDLE_CAMERA_COLOR));
|
assert.equal(icons.item(idleVideo.camera.id).scale, 1);
|
||||||
assert.deepEqual(
|
|
||||||
bytes(color(activeVideo)),
|
|
||||||
policyBytes(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 });
|
||||||
unbind();
|
unbind();
|
||||||
@@ -1154,29 +1150,36 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
|
|||||||
);
|
);
|
||||||
assert.ok(coverage.items.has('cctv-shared-id-cap'));
|
assert.ok(coverage.items.has('cctv-shared-id-cap'));
|
||||||
const lineHit = (set, id) => ({
|
const lineHit = (set, id) => ({
|
||||||
id: { set, id, meta: { cameraId: 'shared-id' } },
|
set,
|
||||||
|
id,
|
||||||
|
meta: { cameraId: 'shared-id' },
|
||||||
|
surface: false,
|
||||||
});
|
});
|
||||||
assert.equal(
|
assert.equal(
|
||||||
_extractPickedCameraIdForTest({
|
_extractPickedCameraIdForTest({
|
||||||
|
set: _cctvIconsForTest().setId,
|
||||||
id: 'shared-id',
|
id: 'shared-id',
|
||||||
iconSet: _cctvIconsForTest(),
|
surface: false,
|
||||||
primitive: { id: 'shared-id' },
|
|
||||||
}),
|
}),
|
||||||
'shared-id',
|
'shared-id',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
_extractPickedCameraIdForTest({
|
_extractPickedCameraIdForTest({
|
||||||
|
set: 'sibling:1:icons',
|
||||||
id: 'shared-id',
|
id: 'shared-id',
|
||||||
iconSet: {},
|
surface: false,
|
||||||
primitive: { id: 'shared-id' },
|
|
||||||
}),
|
}),
|
||||||
null,
|
null,
|
||||||
'a sibling primitive with the same canonical ID cannot activate CCTV',
|
"a sibling set's icon with the same canonical ID cannot activate CCTV",
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
_extractPickedCameraIdForTest({ id: { id: 'shared-id' } }),
|
_extractPickedCameraIdForTest({
|
||||||
|
set: _cctvIconsForTest().setId,
|
||||||
|
id: 'not-a-camera',
|
||||||
|
surface: false,
|
||||||
|
}),
|
||||||
null,
|
null,
|
||||||
'a sibling Entity with the same canonical ID cannot activate CCTV',
|
'an id the icon book does not draw is not a camera',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
_extractPickedCameraIdForTest(
|
_extractPickedCameraIdForTest(
|
||||||
@@ -1194,10 +1197,10 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
|
|||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
_extractPickedCameraIdForTest({
|
_extractPickedCameraIdForTest({
|
||||||
id: {
|
set: 'sibling:1:entities',
|
||||||
id: 'sibling-entity',
|
id: 'sibling-entity',
|
||||||
properties: { cctvCameraId: 'shared-id' },
|
meta: { cctvCameraId: 'shared-id', cameraId: 'shared-id' },
|
||||||
},
|
surface: false,
|
||||||
}),
|
}),
|
||||||
null,
|
null,
|
||||||
'a sibling cannot impersonate CCTV by copying its property shape',
|
'a sibling cannot impersonate CCTV by copying its property shape',
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
// near the screen show, a zoomed-out view keeps one camera per world-anchored
|
// near the screen show, a zoomed-out view keeps one camera per world-anchored
|
||||||
// cell, and the layer's UI state never rebuilds every camera for a listener
|
// cell, and the layer's UI state never rebuilds every camera for a listener
|
||||||
// that does not read the list.
|
// that does not read the list.
|
||||||
import { test } from 'node:test';
|
import { afterEach, 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 { bindRenderer } from '../render/rendererOf.js';
|
||||||
|
import { fakeCameraPort } from '../testSupport/fakeCameraPort.mjs';
|
||||||
import cctvLayer, {
|
import cctvLayer, {
|
||||||
_cctvIconsForTest,
|
_cctvIconsForTest,
|
||||||
_setCctvCoverageStateForTest,
|
_setCctvCoverageStateForTest,
|
||||||
@@ -15,18 +17,10 @@ import cctvLayer, {
|
|||||||
const WIDTH = 800;
|
const WIDTH = 800;
|
||||||
const HEIGHT = 600;
|
const HEIGHT = 600;
|
||||||
|
|
||||||
/**
|
/** Records at the given [lon, lat] degrees near the origin. */
|
||||||
* Records at the given [lon, lat] degrees near the origin, each drawn at the
|
function recordsAt(lonLats) {
|
||||||
* screen point `screenAt` gives it (default: the middle of the screen).
|
|
||||||
*/
|
|
||||||
function recordsAt(
|
|
||||||
lonLats,
|
|
||||||
screenAt = () => ({ x: WIDTH / 2, y: HEIGHT / 2 }),
|
|
||||||
) {
|
|
||||||
const screenByPosition = new Map();
|
|
||||||
const records = lonLats.map(([lon, lat], index) => {
|
const records = lonLats.map(([lon, lat], index) => {
|
||||||
const position = Cesium.Cartesian3.fromDegrees(lon, lat, 10);
|
const position = Cesium.Cartesian3.fromDegrees(lon, lat, 10);
|
||||||
screenByPosition.set(position, screenAt(index));
|
|
||||||
return {
|
return {
|
||||||
camera: {
|
camera: {
|
||||||
id: `cam-${index}`,
|
id: `cam-${index}`,
|
||||||
@@ -40,42 +34,62 @@ function recordsAt(
|
|||||||
rangeM: 145,
|
rangeM: 145,
|
||||||
mountHeightM: 8,
|
mountHeightM: 8,
|
||||||
},
|
},
|
||||||
position,
|
position: { x: position.x, y: position.y, z: position.z },
|
||||||
coverageEntities: [],
|
coverageEntities: [],
|
||||||
projection: null,
|
projection: null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return { records, screenByPosition };
|
return { records };
|
||||||
}
|
}
|
||||||
|
|
||||||
function viewerAt(heightM, screenByPosition, shiftX = 0) {
|
/**
|
||||||
return {
|
* A viewer looking straight down from `heightM` over `lonDeg` on the
|
||||||
isDestroyed: () => false,
|
* equator, north up, through a camera port: the view pass projects the
|
||||||
camera: {
|
* cameras from its pose.
|
||||||
positionWC: Cesium.Cartesian3.fromDegrees(0, 0, heightM),
|
*/
|
||||||
positionCartographic: { latitude: 0, longitude: 0, height: heightM },
|
function viewerAt(heightM, lonDeg = 0) {
|
||||||
frustum: { fovy: Math.PI / 3 },
|
const eye = Cesium.Cartesian3.fromDegrees(lonDeg, 0, heightM);
|
||||||
|
const down = Cesium.Cartesian3.normalize(
|
||||||
|
Cesium.Cartesian3.negate(eye, new Cesium.Cartesian3()),
|
||||||
|
new Cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
const north = { x: 0, y: 0, z: 1 };
|
||||||
|
const right = Cesium.Cartesian3.cross(down, north, new Cesium.Cartesian3());
|
||||||
|
const { port } = fakeCameraPort({
|
||||||
|
pose: {
|
||||||
|
lon: lonDeg,
|
||||||
|
lat: 0,
|
||||||
|
height: heightM,
|
||||||
|
position: { x: eye.x, y: eye.y, z: eye.z },
|
||||||
|
direction: { x: down.x, y: down.y, z: down.z },
|
||||||
|
up: north,
|
||||||
|
right: { x: right.x, y: right.y, z: right.z },
|
||||||
|
fovy: Math.PI / 3,
|
||||||
|
aspectRatio: WIDTH / HEIGHT,
|
||||||
|
near: 0.1,
|
||||||
|
far: 5e8,
|
||||||
},
|
},
|
||||||
scene: {
|
});
|
||||||
|
const viewer = {};
|
||||||
|
bindings.push(
|
||||||
|
bindRenderer(viewer, {
|
||||||
|
camera: port,
|
||||||
canvas: { clientWidth: WIDTH, clientHeight: HEIGHT },
|
canvas: { clientWidth: WIDTH, clientHeight: HEIGHT },
|
||||||
cartesianToCanvasCoordinates: (position) => {
|
}),
|
||||||
// Match by value: a record's position may be a copy of the fixture's.
|
);
|
||||||
const key = [...screenByPosition.keys()].find((candidate) =>
|
return viewer;
|
||||||
Cesium.Cartesian3.equals(candidate, position),
|
|
||||||
);
|
|
||||||
const screen = screenByPosition.get(key);
|
|
||||||
return screen && { x: screen.x + shiftX, y: screen.y };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The renderers bound for the running test, let go when it ends. */
|
||||||
|
const bindings = [];
|
||||||
|
afterEach(() => {
|
||||||
|
for (const unbind of bindings.splice(0)) unbind();
|
||||||
|
});
|
||||||
|
|
||||||
function shownIds(records) {
|
function shownIds(records) {
|
||||||
|
const icons = _cctvIconsForTest();
|
||||||
return records
|
return records
|
||||||
.filter((record) => {
|
.filter((record) => icons.item(record.camera.id)?.show === true)
|
||||||
const icons = _cctvIconsForTest();
|
|
||||||
return icons.shown(icons.row(record.camera.id));
|
|
||||||
})
|
|
||||||
.map((record) => record.camera.id)
|
.map((record) => record.camera.id)
|
||||||
.sort();
|
.sort();
|
||||||
}
|
}
|
||||||
@@ -89,9 +103,9 @@ const CLUSTER = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
test('zoomed out, cameras sharing a ground cell show one icon', () => {
|
test('zoomed out, cameras sharing a ground cell show one icon', () => {
|
||||||
const { records, screenByPosition } = recordsAt(CLUSTER);
|
const { records } = recordsAt(CLUSTER);
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(20_000, screenByPosition),
|
viewer: viewerAt(20_000),
|
||||||
records,
|
records,
|
||||||
});
|
});
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -106,34 +120,34 @@ test('zoomed out, cameras sharing a ground cell show one icon', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('a pan keeps the same winners, and an unchanged view keeps its list', () => {
|
test('a pan keeps the same winners, and an unchanged view keeps its list', () => {
|
||||||
const { records, screenByPosition } = recordsAt(CLUSTER, (index) => ({
|
const { records } = recordsAt(CLUSTER);
|
||||||
x: 100 + index * 7,
|
|
||||||
y: 300,
|
|
||||||
}));
|
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(20_000, screenByPosition),
|
viewer: viewerAt(20_000),
|
||||||
records,
|
records,
|
||||||
});
|
});
|
||||||
refreshHorizonCulling();
|
refreshHorizonCulling();
|
||||||
const before = shownIds(records);
|
const before = shownIds(records);
|
||||||
const list = _viewRecordIdsForTest();
|
const list = _viewRecordIdsForTest();
|
||||||
for (const shiftX of [3, 11, 20, 37]) {
|
// A pan of a few to some 40 px (a pixel is about 30 m from 20 km up).
|
||||||
|
for (const shiftM of [90, 330, 600, 1110]) {
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(20_000, screenByPosition, shiftX),
|
viewer: viewerAt(20_000, shiftM / 111_320),
|
||||||
records,
|
records,
|
||||||
});
|
});
|
||||||
refreshHorizonCulling();
|
refreshHorizonCulling();
|
||||||
assert.deepEqual(shownIds(records), before, `pan by ${shiftX} px`);
|
assert.deepEqual(shownIds(records), before, `pan by ${shiftM} m`);
|
||||||
}
|
}
|
||||||
|
_setCctvCoverageStateForTest({ viewer: viewerAt(20_000), records });
|
||||||
|
refreshHorizonCulling();
|
||||||
assert.equal(refreshHorizonCulling(), false, 'the same view changes nothing');
|
assert.equal(refreshHorizonCulling(), false, 'the same view changes nothing');
|
||||||
assert.deepEqual(_viewRecordIdsForTest(), list);
|
assert.deepEqual(_viewRecordIdsForTest(), list);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a small zoom within one cell size keeps the same winners', () => {
|
test('a small zoom within one cell size keeps the same winners', () => {
|
||||||
const { records, screenByPosition } = recordsAt(CLUSTER);
|
const { records } = recordsAt(CLUSTER);
|
||||||
const shownAt = (heightM) => {
|
const shownAt = (heightM) => {
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(heightM, screenByPosition),
|
viewer: viewerAt(heightM),
|
||||||
records,
|
records,
|
||||||
});
|
});
|
||||||
refreshHorizonCulling();
|
refreshHorizonCulling();
|
||||||
@@ -145,11 +159,11 @@ test('a small zoom within one cell size keeps the same winners', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('a healthy camera wins its cell over an unknown one', () => {
|
test('a healthy camera wins its cell over an unknown one', () => {
|
||||||
const { records, screenByPosition } = recordsAt(CLUSTER.slice(0, 2));
|
const { records } = recordsAt(CLUSTER.slice(0, 2));
|
||||||
// Whichever camera the id order would pick, the healthy one must win.
|
// Whichever camera the id order would pick, the healthy one must win.
|
||||||
for (const id of ['cam-0', 'cam-1']) {
|
for (const id of ['cam-0', 'cam-1']) {
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(20_000, screenByPosition),
|
viewer: viewerAt(20_000),
|
||||||
records,
|
records,
|
||||||
healthById: new Map([[id, { status: 'ok' }]]),
|
healthById: new Map([[id, { status: 'ok' }]]),
|
||||||
});
|
});
|
||||||
@@ -159,34 +173,31 @@ test('a healthy camera wins its cell over an unknown one', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('the active camera always shows, even in a crowded cell', () => {
|
test('the active camera always shows, even in a crowded cell', () => {
|
||||||
const { records, screenByPosition } = recordsAt(CLUSTER.slice(0, 3));
|
const { records } = recordsAt(CLUSTER.slice(0, 3));
|
||||||
for (const active of records) {
|
for (const active of records) {
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(20_000, screenByPosition),
|
viewer: viewerAt(20_000),
|
||||||
records,
|
records,
|
||||||
activeCameraId: active.camera.id,
|
activeCameraId: active.camera.id,
|
||||||
});
|
});
|
||||||
refreshHorizonCulling();
|
refreshHorizonCulling();
|
||||||
const icons = _cctvIconsForTest();
|
const icons = _cctvIconsForTest();
|
||||||
assert.ok(
|
assert.ok(
|
||||||
icons.shown(icons.row(active.camera.id)),
|
icons.item(active.camera.id).show,
|
||||||
`${active.camera.id} shows while active`,
|
`${active.camera.id} shows while active`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('close up, every camera near the screen shows and far-off ones hide', () => {
|
test('close up, every camera near the screen shows and far-off ones hide', () => {
|
||||||
const { records, screenByPosition } = recordsAt(
|
// From 300 m up the screen spans some 460 m: the third camera is 1.1 km off.
|
||||||
[
|
const { records } = recordsAt([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[0.0001, 0],
|
[0.0001, 0],
|
||||||
[0.0002, 0],
|
[0.01, 0],
|
||||||
],
|
]);
|
||||||
(index) =>
|
|
||||||
index === 2 ? { x: WIDTH * 3, y: HEIGHT / 2 } : { x: 100, y: 100 },
|
|
||||||
);
|
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(300, screenByPosition),
|
viewer: viewerAt(300),
|
||||||
records,
|
records,
|
||||||
});
|
});
|
||||||
refreshHorizonCulling();
|
refreshHorizonCulling();
|
||||||
@@ -194,9 +205,9 @@ test('close up, every camera near the screen shows and far-off ones hide', () =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('a disabled layer skips the view pass', () => {
|
test('a disabled layer skips the view pass', () => {
|
||||||
const { records, screenByPosition } = recordsAt(CLUSTER);
|
const { records } = recordsAt(CLUSTER);
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(20_000, screenByPosition),
|
viewer: viewerAt(20_000),
|
||||||
records,
|
records,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
});
|
});
|
||||||
@@ -205,9 +216,9 @@ test('a disabled layer skips the view pass', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('UI state builds the full camera list only when it is read', () => {
|
test('UI state builds the full camera list only when it is read', () => {
|
||||||
const { records, screenByPosition } = recordsAt(CLUSTER.slice(0, 2));
|
const { records } = recordsAt(CLUSTER.slice(0, 2));
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(300, screenByPosition),
|
viewer: viewerAt(300),
|
||||||
records,
|
records,
|
||||||
});
|
});
|
||||||
refreshHorizonCulling();
|
refreshHorizonCulling();
|
||||||
@@ -238,16 +249,13 @@ test('UI state builds the full camera list only when it is read', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('the camera picker lists the view, with the active camera first', () => {
|
test('the camera picker lists the view, with the active camera first', () => {
|
||||||
const { records, screenByPosition } = recordsAt(
|
const { records } = recordsAt([
|
||||||
[
|
[0, 0],
|
||||||
[0, 0],
|
[0.01, 0],
|
||||||
[0.0001, 0],
|
[0.0002, 0],
|
||||||
[0.0002, 0],
|
]);
|
||||||
],
|
|
||||||
(index) => (index === 1 ? { x: WIDTH * 3, y: 0 } : { x: 100, y: 100 }),
|
|
||||||
);
|
|
||||||
_setCctvCoverageStateForTest({
|
_setCctvCoverageStateForTest({
|
||||||
viewer: viewerAt(300, screenByPosition),
|
viewer: viewerAt(300),
|
||||||
records,
|
records,
|
||||||
activeCameraId: 'cam-1',
|
activeCameraId: 'cam-1',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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 { createIconSet } from './iconSet.js';
|
import { createIconBook } from '../render/motion/iconBook.js';
|
||||||
import { createVesselIconBook } from '../layers/vessels/iconBook.js';
|
import { createVesselIconBook } from '../layers/vessels/iconBook.js';
|
||||||
|
|
||||||
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
|
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
|
||||||
@@ -88,10 +88,13 @@ assertResumeGate('vessel', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assertResumeGate('CCTV', () => {
|
assertResumeGate('CCTV', () => {
|
||||||
const icons = createIconSet();
|
const icons = createIconBook();
|
||||||
const row = icons.add('cam-1', { id: 'cam-1' });
|
icons.put({
|
||||||
icons.setSize(row, 24, 24);
|
id: 'cam-1',
|
||||||
icons.setShown(row, true);
|
pos: { x: 1, y: 2, z: 3 },
|
||||||
|
size: [24, 24],
|
||||||
|
meta: { id: 'cam-1' },
|
||||||
|
});
|
||||||
const record = { camera: { id: 'cam-1' }, position: { x: 1, y: 2, z: 3 } };
|
const record = { camera: { id: 'cam-1' }, position: { x: 1, y: 2, z: 3 } };
|
||||||
return {
|
return {
|
||||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
|
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
|
||||||
@@ -105,7 +108,7 @@ assertResumeGate('CCTV', () => {
|
|||||||
cameraDistanceFor: () => 1200,
|
cameraDistanceFor: () => 1200,
|
||||||
params,
|
params,
|
||||||
}),
|
}),
|
||||||
readAlpha: () => icons.focus(icons.row('cam-1')),
|
readAlpha: () => icons.focus('cam-1'),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -60,3 +60,42 @@ export function sphereOutside(planes, center, radius) {
|
|||||||
if (dot(normal, center) + w < -radius) return true;
|
if (dot(normal, center) + w < -radius) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas coordinates (CSS px, origin top left) of world points on a `width`
|
||||||
|
* by `height` canvas, as the default renderer projects them from `pose`
|
||||||
|
* (its frustum's projection matrix times its view matrix, centred, no
|
||||||
|
* offset): one pose read for many points, rather than a renderer call per
|
||||||
|
* point. Null behind the eye and before the projection's clip plane at
|
||||||
|
* `2·far·near / (far + near)` (a little past `near`; `2·near` with no far
|
||||||
|
* plane), where the renderer's own projection answers nothing.
|
||||||
|
* @param {{position: object, direction: object, up: object, fovy: number,
|
||||||
|
* aspectRatio: number, near: number, far: number}} pose
|
||||||
|
* @param {number} width
|
||||||
|
* @param {number} height
|
||||||
|
* @param {{x: number, y: number}} [out] Written and returned by every call.
|
||||||
|
* @returns {(p: {x: number, y: number, z: number}) =>
|
||||||
|
* ({x: number, y: number}|null)}
|
||||||
|
*/
|
||||||
|
export function poseProjector(pose, width, height, out = { x: 0, y: 0 }) {
|
||||||
|
const { position: e, direction: d, up: u, near, far } = pose;
|
||||||
|
const r = cross(d, u);
|
||||||
|
const tanY = Math.tan(0.5 * pose.fovy);
|
||||||
|
const tanX = pose.aspectRatio * tanY;
|
||||||
|
// With no far plane the clip plane is at twice `near`, its limit.
|
||||||
|
const clipDepth = Number.isFinite(far)
|
||||||
|
? (2 * far * near) / (far + near)
|
||||||
|
: 2 * near;
|
||||||
|
return (p) => {
|
||||||
|
const vx = p.x - e.x;
|
||||||
|
const vy = p.y - e.y;
|
||||||
|
const vz = p.z - e.z;
|
||||||
|
const depth = vx * d.x + vy * d.y + vz * d.z;
|
||||||
|
if (!(depth > 0) || depth < clipDepth) return null;
|
||||||
|
const x = (vx * r.x + vy * r.y + vz * r.z) / (depth * tanX);
|
||||||
|
const y = (vx * u.x + vy * u.y + vz * u.z) / (depth * tanY);
|
||||||
|
out.x = (x + 1) * 0.5 * width;
|
||||||
|
out.y = (1 - y) * 0.5 * height;
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
}
|
||||||
+108
-1
@@ -1,7 +1,7 @@
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import * as Cesium from 'cesium';
|
import * as Cesium from 'cesium';
|
||||||
import { frustumPlanes, sphereOutside } from './frustum.js';
|
import { frustumPlanes, poseProjector, sphereOutside } from './frustum.js';
|
||||||
|
|
||||||
/** A camera pose and the Cesium frustum it describes. */
|
/** A camera pose and the Cesium frustum it describes. */
|
||||||
function camera({ position, direction, up, fovy, aspectRatio, near, far }) {
|
function camera({ position, direction, up, fovy, aspectRatio, near, far }) {
|
||||||
@@ -72,3 +72,110 @@ test('the frustum culls spheres as the default renderer does', () => {
|
|||||||
assert.equal(sphereOutside(planes, behind, 1), true);
|
assert.equal(sphereOutside(planes, behind, 1), true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('points project to the canvas as the default renderer projects them', () => {
|
||||||
|
const eye = Cesium.Cartesian3.fromDegrees(-0.12, 51.5, 600);
|
||||||
|
const target = Cesium.Cartesian3.fromDegrees(-0.11, 51.505, 0);
|
||||||
|
const direction = Cesium.Cartesian3.normalize(
|
||||||
|
Cesium.Cartesian3.subtract(target, eye, new Cesium.Cartesian3()),
|
||||||
|
new Cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
const east = unit(-eye.y, eye.x, 0);
|
||||||
|
const up = Cesium.Cartesian3.normalize(
|
||||||
|
Cesium.Cartesian3.cross(east, direction, new Cesium.Cartesian3()),
|
||||||
|
new Cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
// Landscape and portrait canvases, each at a near and a far `near`.
|
||||||
|
for (const [width, height, near] of [
|
||||||
|
[1280, 720, 0.1],
|
||||||
|
[1280, 720, 25],
|
||||||
|
[600, 900, 0.1],
|
||||||
|
]) {
|
||||||
|
const { pose } = camera({
|
||||||
|
position: { x: eye.x, y: eye.y, z: eye.z },
|
||||||
|
direction: { x: direction.x, y: direction.y, z: direction.z },
|
||||||
|
up: { x: up.x, y: up.y, z: up.z },
|
||||||
|
fovy: 0.9,
|
||||||
|
aspectRatio: width / height,
|
||||||
|
near,
|
||||||
|
far: 5e8,
|
||||||
|
});
|
||||||
|
// The renderer's view-projection: its frustum's projection matrix times
|
||||||
|
// the view matrix of the eye's right, up and direction.
|
||||||
|
const frustum = new Cesium.PerspectiveFrustum({
|
||||||
|
// Cesium's `fov` is across the canvas's wider side.
|
||||||
|
fov:
|
||||||
|
pose.aspectRatio <= 1
|
||||||
|
? pose.fovy
|
||||||
|
: 2 * Math.atan(Math.tan(pose.fovy / 2) * pose.aspectRatio),
|
||||||
|
aspectRatio: pose.aspectRatio,
|
||||||
|
near,
|
||||||
|
far: pose.far,
|
||||||
|
});
|
||||||
|
const right = Cesium.Cartesian3.cross(
|
||||||
|
direction,
|
||||||
|
up,
|
||||||
|
new Cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
const view = Cesium.Matrix4.computeView(
|
||||||
|
eye,
|
||||||
|
direction,
|
||||||
|
up,
|
||||||
|
right,
|
||||||
|
new Cesium.Matrix4(),
|
||||||
|
);
|
||||||
|
const m = Cesium.Matrix4.multiply(
|
||||||
|
frustum.projectionMatrix,
|
||||||
|
view,
|
||||||
|
new Cesium.Matrix4(),
|
||||||
|
);
|
||||||
|
const project = poseProjector(pose, width, height);
|
||||||
|
let shown = 0;
|
||||||
|
for (let i = 0; i < 400; i++) {
|
||||||
|
const p = Cesium.Cartesian3.fromDegrees(
|
||||||
|
-0.12 + ((i % 20) - 10) * 0.002,
|
||||||
|
51.5 + (Math.floor(i / 20) - 10) * 0.002,
|
||||||
|
(i % 9) * 80,
|
||||||
|
);
|
||||||
|
const clip = Cesium.Matrix4.multiplyByVector(
|
||||||
|
m,
|
||||||
|
new Cesium.Cartesian4(p.x, p.y, p.z, 1),
|
||||||
|
new Cesium.Cartesian4(),
|
||||||
|
);
|
||||||
|
const ours = project(p);
|
||||||
|
if (!(clip.w > 0) || clip.z < 0) {
|
||||||
|
assert.equal(ours, null, `${i} is not drawn`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
shown += 1;
|
||||||
|
const x = (clip.x / clip.w + 1) * 0.5 * width;
|
||||||
|
const y = (1 - clip.y / clip.w) * 0.5 * height;
|
||||||
|
// Off-screen points land far out: compared to a part in 1e9.
|
||||||
|
const close = (a, b) => Math.abs(a - b) <= 1e-6 + 1e-9 * Math.abs(b);
|
||||||
|
assert.ok(close(ours.x, x), `${i} x`);
|
||||||
|
assert.ok(close(ours.y, y), `${i} y`);
|
||||||
|
}
|
||||||
|
assert.ok(shown > 0 && shown < 400, 'some points in front, some not');
|
||||||
|
}
|
||||||
|
// Just before the clip plane past `near`: nothing, as the renderer.
|
||||||
|
const { pose } = camera({
|
||||||
|
position: { x: 0, y: 0, z: 0 },
|
||||||
|
direction: { x: 1, y: 0, z: 0 },
|
||||||
|
up: { x: 0, y: 0, z: 1 },
|
||||||
|
fovy: 1,
|
||||||
|
aspectRatio: 1,
|
||||||
|
near: 10,
|
||||||
|
far: 1000,
|
||||||
|
});
|
||||||
|
const project = poseProjector(pose, 100, 100);
|
||||||
|
const clipDepth = (2 * 1000 * 10) / 1010;
|
||||||
|
assert.equal(project({ x: clipDepth - 1e-6, y: 0, z: 0 }), null);
|
||||||
|
assert.deepEqual(project({ x: clipDepth + 1e-6, y: 0, z: 0 }), {
|
||||||
|
x: 50,
|
||||||
|
y: 50,
|
||||||
|
});
|
||||||
|
// An infinite far plane clips at twice `near`, the limit of the finite rule.
|
||||||
|
const endless = poseProjector({ ...pose, far: Infinity }, 100, 100);
|
||||||
|
assert.equal(endless({ x: 20 - 1e-6, y: 0, z: 0 }), null);
|
||||||
|
assert.deepEqual(endless({ x: 20 + 1e-6, y: 0, z: 0 }), { x: 50, y: 50 });
|
||||||
|
});
|
||||||
@@ -29,8 +29,8 @@ export function createIngestion({
|
|||||||
layerState._tilesReadyReenqueued = true;
|
layerState._tilesReadyReenqueued = true;
|
||||||
// Per-regime resolution (Task 5): only records unresolved for the
|
// Per-regime resolution (Task 5): only records unresolved for the
|
||||||
// CURRENT surface regime need the completion pass. On globe stacks
|
// CURRENT surface regime need the completion pass. On globe stacks
|
||||||
// projectionTilesReady() is false while a (hidden) Google tileset
|
// projectionTilesReady() is false (only drawn photoreal tiles can be
|
||||||
// exists, so this latch effectively fires for the google-3d regime —
|
// ready), so this latch fires for the google-3d regime alone —
|
||||||
// terrain-globe records resolve from the prior in their drain pass.
|
// terrain-globe records resolve from the prior in their drain pass.
|
||||||
const unresolved = parts.geometryQueue
|
const unresolved = parts.geometryQueue
|
||||||
.geometryWorkingSet()
|
.geometryWorkingSet()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function createLifecycle({
|
|||||||
parts,
|
parts,
|
||||||
source,
|
source,
|
||||||
}) {
|
}) {
|
||||||
const { registerSpriteCollection, restoreSpriteOrder } = services.sprites;
|
const { registerSpriteSet, restoreSpriteOrder } = services.sprites;
|
||||||
const { activateCctvCameraFromWorldClick } = services.activation;
|
const { activateCctvCameraFromWorldClick } = services.activation;
|
||||||
const { resolvePickId, registerPickOwner, unregisterPickOwner } =
|
const { resolvePickId, registerPickOwner, unregisterPickOwner } =
|
||||||
services.picking;
|
services.picking;
|
||||||
@@ -176,9 +176,6 @@ export function createLifecycle({
|
|||||||
layerState._lastError = null;
|
layerState._lastError = null;
|
||||||
layerState._lastFocusStyleAt = 0;
|
layerState._lastFocusStyleAt = 0;
|
||||||
layerState._activeFocusStyleCount = 0;
|
layerState._activeFocusStyleCount = 0;
|
||||||
// FIX ①/③: the discovered tileset handle is scene-scoped — drop it so a fresh
|
|
||||||
// init re-discovers against the current scene primitives.
|
|
||||||
layerState._activeTileset = null;
|
|
||||||
// Task 5: the applied-regime tracker is record-set-scoped — a fresh init
|
// Task 5: the applied-regime tracker is record-set-scoped — a fresh init
|
||||||
// recomputes it against the then-current scene.
|
// recomputes it against the then-current scene.
|
||||||
layerState._lastAppliedRegime = null;
|
layerState._lastAppliedRegime = null;
|
||||||
@@ -208,10 +205,10 @@ export function createLifecycle({
|
|||||||
layerState._lastViewContext = '';
|
layerState._lastViewContext = '';
|
||||||
layerState._calibrationById = parts.calibration.loadCalibrationStore();
|
layerState._calibrationById = parts.calibration.loadCalibrationStore();
|
||||||
|
|
||||||
registerSpriteCollection(
|
// A host without the sprite order still draws the icons, in the
|
||||||
'cctv',
|
// order they were added.
|
||||||
parts.rendering.createCameraIcons(layerState._viewer),
|
const iconSetId = parts.rendering.createCameraIcons(layerState._viewer);
|
||||||
);
|
registerSpriteSet?.('cctv', iconSetId);
|
||||||
|
|
||||||
const sources = await parts.catalog.loadCameraSources();
|
const sources = await parts.catalog.loadCameraSources();
|
||||||
const catalogFromSources = parts.catalog.buildCatalogFromSources(sources);
|
const catalogFromSources = parts.catalog.buildCatalogFromSources(sources);
|
||||||
@@ -399,7 +396,9 @@ export function createLifecycle({
|
|||||||
(event) => {
|
(event) => {
|
||||||
if (!layerState._enabled) return;
|
if (!layerState._enabled) return;
|
||||||
const picked = event.pick;
|
const picked = event.pick;
|
||||||
const cameraId = parts.selection.extractPickedCameraId(picked);
|
const cameraId = parts.selection.extractPickedCameraId(
|
||||||
|
event.drawHit ?? null,
|
||||||
|
);
|
||||||
if (cameraId) {
|
if (cameraId) {
|
||||||
activateCctvCameraFromWorldClick(
|
activateCctvCameraFromWorldClick(
|
||||||
cameraId,
|
cameraId,
|
||||||
|
|||||||
@@ -179,10 +179,14 @@ export const DEFAULT_CAMERA_CALIBRATION = Object.freeze({
|
|||||||
heightM: 0,
|
heightM: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Base64-encoded SVG camera icon for the camera icon rows. */
|
/**
|
||||||
|
* Base64-encoded SVG camera icon for the camera icons. Icons rasterise an
|
||||||
|
* SVG at its own size, so it is 48 px: drawn at 24 px, 1.25× near scale on a
|
||||||
|
* 2× display draws it at 60 device px, and it stays sharp there.
|
||||||
|
*/
|
||||||
|
|
||||||
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="48" height="48" viewBox="0 0 36 36">
|
||||||
<defs>
|
<defs>
|
||||||
<linearGradient id="lens" x1="0" y1="0" x2="1" y2="1">
|
<linearGradient id="lens" x1="0" y1="0" x2="1" y2="1">
|
||||||
<stop offset="0%" stop-color="#c9f6ff"/>
|
<stop offset="0%" stop-color="#c9f6ff"/>
|
||||||
|
|||||||
+220
-232
@@ -1,10 +1,9 @@
|
|||||||
import * as Cesium from 'cesium';
|
|
||||||
import { isHeadingEstimated } from './headingConfidence.js';
|
import { isHeadingEstimated } from './headingConfidence.js';
|
||||||
import {
|
import {
|
||||||
ACTIVE_CAMERA_COLOR as ACTIVE_CAMERA_RGBA,
|
ACTIVE_CAMERA_COLOR,
|
||||||
CAMERA_ICON,
|
CAMERA_ICON,
|
||||||
IDLE_CAMERA_COLOR as IDLE_CAMERA_RGBA,
|
IDLE_CAMERA_COLOR,
|
||||||
LIVE_CAMERA_COLOR as LIVE_CAMERA_RGBA,
|
LIVE_CAMERA_COLOR,
|
||||||
ACTIVE_COVERAGE_CENTER,
|
ACTIVE_COVERAGE_CENTER,
|
||||||
IDLE_COVERAGE_CENTER_MUTED,
|
IDLE_COVERAGE_CENTER_MUTED,
|
||||||
ACTIVE_COVERAGE_CENTER_DEPTHFAIL,
|
ACTIVE_COVERAGE_CENTER_DEPTHFAIL,
|
||||||
@@ -16,43 +15,49 @@ import {
|
|||||||
VIEW_ICON_MARGIN,
|
VIEW_ICON_MARGIN,
|
||||||
VIEW_MIN_CELL_M,
|
VIEW_MIN_CELL_M,
|
||||||
} from './policy.js';
|
} from './policy.js';
|
||||||
import { createIconSet } from '../../data/iconSet.js';
|
import { createIconBook } from '../../render/motion/iconBook.js';
|
||||||
import { writeHoldSegment } from '../../data/iconSegment.js';
|
|
||||||
import { IconSetPrimitive } from '../../render/cesium/iconSetPrimitive.js';
|
|
||||||
import { iconAtlas } from '../../data/iconAtlas.js';
|
|
||||||
import { horizonOccluder } from '../../render/cesium/iconOrientation.js';
|
|
||||||
import { frustumVolumeGeometryData } from '../../data/cctvViewshed.js';
|
import { frustumVolumeGeometryData } from '../../data/cctvViewshed.js';
|
||||||
import { toColor } from '../../render/cesium/draw.js';
|
import {
|
||||||
import { drawHitOf } from '../../render/cesium/drawHit.js';
|
canvasOf,
|
||||||
import { findQuery } from '../../render/rendererOf.js';
|
drawOf,
|
||||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
findCamera,
|
||||||
|
findGlobe,
|
||||||
|
findQuery,
|
||||||
|
} from '../../render/rendererOf.js';
|
||||||
|
import { fromDegrees, WGS84 } from '../../geo/ellipsoid.js';
|
||||||
import { eastNorthUp } from '../../geo/frames.js';
|
import { eastNorthUp } from '../../geo/frames.js';
|
||||||
// Loads the factory a viewer of a caller's own gets its camera port from,
|
import { poseProjector } from '../../geo/frustum.js';
|
||||||
// which the rest of the layer reads the eye through.
|
import { horizonFrom } from '../../geo/horizon.js';
|
||||||
import '../../render/cesium/camera.js';
|
import { distance } from '../../geo/vector.js';
|
||||||
import '../../render/cesium/globe.js';
|
|
||||||
|
|
||||||
// The policy's renderer colours as the Cesium colours the icons and lines take.
|
|
||||||
const ACTIVE_CAMERA_COLOR = toColor(ACTIVE_CAMERA_RGBA);
|
|
||||||
const IDLE_CAMERA_COLOR = toColor(IDLE_CAMERA_RGBA);
|
|
||||||
const LIVE_CAMERA_COLOR = toColor(LIVE_CAMERA_RGBA);
|
|
||||||
|
|
||||||
/** An RGBA colour with another alpha. */
|
/** An RGBA colour with another alpha. */
|
||||||
const withAlpha = (color, alpha) => [color[0], color[1], color[2], alpha];
|
const withAlpha = (color, alpha) => [color[0], color[1], color[2], alpha];
|
||||||
|
|
||||||
/** The camera icon's drawn size (px). */
|
/** Icon sets made so far, by every layer: set ids unique to each. */
|
||||||
const CAMERA_ICON_PX = 24;
|
let iconSets = 0;
|
||||||
|
|
||||||
|
/** A point's coordinates, as an item keeps them. */
|
||||||
|
const copyPoint = (p) => ({ x: p.x, y: p.y, z: p.z });
|
||||||
|
|
||||||
|
/** Whether two points are the same, coordinate for coordinate. */
|
||||||
|
const samePoint = (a, b) =>
|
||||||
|
!!a && !!b && a.x === b.x && a.y === b.y && a.z === b.z;
|
||||||
|
|
||||||
|
/** Degrees to radians. */
|
||||||
|
const toRadians = (degrees) => (degrees * Math.PI) / 180;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Its atlas raster: 1.25× near scale on a 2× display draws it at 60 device px,
|
* The camera icon's drawn size (px). Its SVG is 48 px (policy.js): 1.25×
|
||||||
* so it is rasterised past the drawn size to stay sharp there.
|
* 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_ICON_PX = 24;
|
||||||
const CAMERA_SCALE_BY_DISTANCE = new Cesium.NearFarScalar(
|
const CAMERA_SCALE_BY_DISTANCE = Object.freeze({
|
||||||
350,
|
near: 350,
|
||||||
1.25,
|
nearValue: 1.25,
|
||||||
4_000_000,
|
far: 4_000_000,
|
||||||
0.42,
|
farValue: 0.42,
|
||||||
);
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The translucent frustum volume of one camera, as a mesh item: the same 5
|
* The translucent frustum volume of one camera, as a mesh item: the same 5
|
||||||
@@ -104,70 +109,93 @@ 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,
|
* The catalog's camera icons: an icon draw set, and the book the layer
|
||||||
* so each row is a hold segment and the primitive's clock only keeps segment
|
* reads them back from (`render/motion/iconBook.js`), each item a camera
|
||||||
* times small. Rows draw depth-test-free (field-test fix 2026-07-06: the old
|
* by its id. Cameras hold still, so each item's motion is a hold at its
|
||||||
|
* mount. Items draw depth-test-free (field-test fix 2026-07-06: the old
|
||||||
* finite depth-test distance re-engaged at far zoom, where the COARSE
|
* finite depth-test distance re-engaged at far zoom, where the COARSE
|
||||||
* far-LOD Google-3D mesh sits above the true ground and swallowed
|
* 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
|
* ground-anchored icons); the set culls the far side of the globe and
|
||||||
* refreshHorizonCulling thins the rest.
|
* refreshHorizonCulling thins the rest.
|
||||||
* @param {Cesium.Viewer} viewer
|
* @param {object} viewer The layer's viewer.
|
||||||
|
* @returns {string} The icon set's id, for the sprite order.
|
||||||
*/
|
*/
|
||||||
function createCameraIcons(viewer) {
|
function createCameraIcons(viewer) {
|
||||||
// A re-init against a new viewer replaces the icons; the old ones go.
|
// A re-init against a new viewer replaces the icons; the old ones go.
|
||||||
destroyCameraIcons();
|
destroyCameraIcons();
|
||||||
const epoch = Cesium.JulianDate.now();
|
const set = drawOf(viewer).icons({
|
||||||
layerState._icons = createIconSet({ epoch });
|
id: `cctv:${++iconSets}:icons`,
|
||||||
layerState._iconPrimitive = new IconSetPrimitive({
|
horizonCull: true,
|
||||||
set: layerState._icons,
|
|
||||||
renderTime: () => epoch,
|
|
||||||
requestRender: () => layerState._viewer?.scene?.requestRender?.(),
|
|
||||||
});
|
});
|
||||||
viewer.scene.primitives.add(layerState._iconPrimitive);
|
// Columns of no rows put the set's host in the scene now, where the
|
||||||
iconScene = viewer.scene;
|
// sprite order finds it, rather than with its first camera.
|
||||||
return layerState._iconPrimitive;
|
set.setColumns?.({ ids: [] });
|
||||||
|
layerState._icons = createIconBook(set);
|
||||||
|
return set.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Let the icon draw set go, whichever viewer the caller tears down. */
|
||||||
* 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() {
|
function destroyCameraIcons() {
|
||||||
const primitive = layerState._iconPrimitive;
|
layerState._icons?.dispose();
|
||||||
if (primitive && iconScene && !iconScene.isDestroyed?.())
|
|
||||||
iconScene.primitives.remove(primitive);
|
|
||||||
if (primitive && !primitive.isDestroyed()) primitive.destroy();
|
|
||||||
iconScene = null;
|
|
||||||
layerState._iconPrimitive = null;
|
|
||||||
layerState._icons = null;
|
layerState._icons = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a camera record's icon row, idle and shown, at its position. */
|
/** The icon item a camera record draws, idle and shown, at its position. */
|
||||||
function addCameraIcon(record) {
|
function cameraIconItem(record) {
|
||||||
const set = layerState._icons;
|
|
||||||
const id = record.camera.id;
|
const id = record.camera.id;
|
||||||
const row = set.add(id, { layer: 'cctv', id });
|
return {
|
||||||
const slot = iconAtlas.slot(CAMERA_ICON, CAMERA_RASTER_PX);
|
id,
|
||||||
set.setImage(row, slot, slot);
|
pos: copyPoint(record.position),
|
||||||
set.setSize(row, CAMERA_ICON_PX, CAMERA_ICON_PX);
|
image: CAMERA_ICON,
|
||||||
set.setScaleByDistance(row, CAMERA_SCALE_BY_DISTANCE);
|
size: [CAMERA_ICON_PX, CAMERA_ICON_PX],
|
||||||
set.setColor(row, cameraColorFor(record));
|
color: cameraColorFor(record),
|
||||||
set.setShown(row, true);
|
scale: 1,
|
||||||
moveCameraIcon(record);
|
scaleByDistance: CAMERA_SCALE_BY_DISTANCE,
|
||||||
|
disableDepthTest: Infinity,
|
||||||
|
motion: { kind: 'hold' },
|
||||||
|
meta: { layer: 'cctv', id },
|
||||||
|
show: true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Hold a camera's row at its record's current position. */
|
/**
|
||||||
|
* A camera's icon item with `fields` changed, to write with the pass's
|
||||||
|
* others in one go (`writeCameraIcons`); null when none of them changes
|
||||||
|
* or it has no icon, so a large catalog writes only what changed.
|
||||||
|
*/
|
||||||
|
function patchedCameraIcon(id, fields) {
|
||||||
|
const item = layerState._icons?.item(id);
|
||||||
|
if (!item) return null;
|
||||||
|
for (const key in fields)
|
||||||
|
if (item[key] !== fields[key]) return { ...item, ...fields };
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Write a pass's changed icons, in one write to the set. */
|
||||||
|
function writeCameraIcons(items) {
|
||||||
|
if (items.length) layerState._icons?.putMany(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add a camera record's icon, idle and shown, once it has a position. */
|
||||||
|
function addCameraIcon(record) {
|
||||||
|
const icons = layerState._icons;
|
||||||
|
if (!icons || !record.position) return;
|
||||||
|
icons.put(cameraIconItem(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hold a camera's icon at its record's current position. */
|
||||||
function moveCameraIcon(record) {
|
function moveCameraIcon(record) {
|
||||||
const set = layerState._icons;
|
const icons = layerState._icons;
|
||||||
const row = set?.row(record.camera.id) ?? -1;
|
if (!icons || !record.position) return;
|
||||||
if (row < 0 || !record.position) return;
|
const item = icons.item(record.camera.id);
|
||||||
writeHoldSegment(set.segments, row, record.position, 0);
|
// A camera whose icon waited for a position is drawn now.
|
||||||
set.segmentWritten(row);
|
if (!item) {
|
||||||
|
icons.put(cameraIconItem(record));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (samePoint(item.pos, record.position)) return;
|
||||||
|
icons.put({ ...item, pos: copyPoint(record.position) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Icon color: active wins, then live-capable video feeds, then idle stills. */
|
/** Icon color: active wins, then live-capable video feeds, then idle stills. */
|
||||||
@@ -204,21 +232,16 @@ export function createRendering({
|
|||||||
return;
|
return;
|
||||||
if (nowMs - layerState._lastFocusStyleAt < 80) return;
|
if (nowMs - layerState._lastFocusStyleAt < 80) return;
|
||||||
layerState._lastFocusStyleAt = nowMs;
|
layerState._lastFocusStyleAt = nowMs;
|
||||||
const scene = layerState._viewer.scene;
|
const query = findQuery(layerState._viewer);
|
||||||
const camera = layerState._viewer.camera;
|
const eye = findCamera(layerState._viewer)?.pose()?.position;
|
||||||
|
if (!query || !eye) return;
|
||||||
const result = applyCctvFocusDeemphasis({
|
const result = applyCctvFocusDeemphasis({
|
||||||
records: layerState._records,
|
records: layerState._records,
|
||||||
target,
|
target,
|
||||||
previousActiveCount: layerState._activeFocusStyleCount,
|
previousActiveCount: layerState._activeFocusStyleCount,
|
||||||
nowMs,
|
nowMs,
|
||||||
screenPositionFor: (position) =>
|
screenPositionFor: (position) => query.project(position),
|
||||||
Cesium.SceneTransforms.worldToWindowCoordinates(
|
cameraDistanceFor: (position) => distance(eye, position),
|
||||||
scene,
|
|
||||||
position,
|
|
||||||
layerState._scratchFocusScreen,
|
|
||||||
),
|
|
||||||
cameraDistanceFor: (position) =>
|
|
||||||
Cesium.Cartesian3.distance(camera.positionWC, position),
|
|
||||||
});
|
});
|
||||||
layerState._activeFocusStyleCount = result.activeCount;
|
layerState._activeFocusStyleCount = result.activeCount;
|
||||||
}
|
}
|
||||||
@@ -227,7 +250,7 @@ export function createRendering({
|
|||||||
* Apply the gated CCTV focus pass through the set's focus column (the shader
|
* Apply the gated CCTV focus pass through the set's focus column (the shader
|
||||||
* multiplies it into the base color's alpha).
|
* 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).
|
* @param {object} [input.icons] The icon book (defaults to the layer's).
|
||||||
* @returns {{writes:number,transitioning:boolean,activeCount:number,ran:boolean}}
|
* @returns {{writes:number,transitioning:boolean,activeCount:number,ran:boolean}}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -248,28 +271,30 @@ 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 row = icons?.row(record.camera?.id) ?? -1;
|
const id = record.camera?.id;
|
||||||
if (row < 0) continue;
|
const item = icons?.item(id);
|
||||||
|
if (!item) continue;
|
||||||
const position = record.position;
|
const position = record.position;
|
||||||
|
const scale = item.scale ?? 1;
|
||||||
// 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(icons.metaAt(row), {
|
const focus = advanceSpriteFocus(item.meta, {
|
||||||
// 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:
|
||||||
!icons.shown(row) || !position ? null : screenPositionFor(position),
|
item.show === false || !position ? null : screenPositionFor(position),
|
||||||
cameraDistance: position ? cameraDistanceFor(position) : Number.NaN,
|
cameraDistance: position ? cameraDistanceFor(position) : Number.NaN,
|
||||||
nowMs,
|
nowMs,
|
||||||
target,
|
target,
|
||||||
params,
|
params,
|
||||||
spriteHalfWidthPx: icons.width(row) * icons.scale(row) * 0.5,
|
spriteHalfWidthPx: item.size[0] * scale * 0.5,
|
||||||
spriteHalfHeightPx: icons.height(row) * icons.scale(row) * 0.5,
|
spriteHalfHeightPx: item.size[1] * scale * 0.5,
|
||||||
});
|
});
|
||||||
transitioning ||= focus.transitioning;
|
transitioning ||= focus.transitioning;
|
||||||
if (focus.active) activeCount += 1;
|
if (focus.active) activeCount += 1;
|
||||||
// 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.
|
||||||
if (focusAlphaNeedsWrite(icons.focus(row), focus.factor, params)) {
|
if (focusAlphaNeedsWrite(icons.focus(id), focus.factor, params)) {
|
||||||
icons.setFocus(row, focus.factor);
|
icons.setFocus(id, focus.factor);
|
||||||
writes += 1;
|
writes += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,7 +309,7 @@ export function createRendering({
|
|||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Field-test fix (2026-07-06): horizon-culls camera icons on the CPU as the
|
* Field-test fix (2026-07-06): horizon-culls camera icons on the CPU as the
|
||||||
* icon shader does on the GPU. With the Cesium globe hidden (Google-3D
|
* icon shader does on the GPU. With the globe hidden (Google-3D
|
||||||
* regime) nothing writes far-side depth and the icons are always-on-top, so
|
* regime) nothing writes far-side depth and the icons are always-on-top, so
|
||||||
* the shown set (cards, geometry, the picker) must not include London's
|
* the shown set (cards, geometry, the picker) must not include London's
|
||||||
* cluster from a US viewpoint.
|
* cluster from a US viewpoint.
|
||||||
@@ -306,33 +331,32 @@ export function createRendering({
|
|||||||
if (
|
if (
|
||||||
!layerState._enabled ||
|
!layerState._enabled ||
|
||||||
!layerState._viewer ||
|
!layerState._viewer ||
|
||||||
layerState._viewer.isDestroyed() ||
|
|
||||||
!layerState._records.length
|
!layerState._records.length
|
||||||
)
|
)
|
||||||
return false;
|
return false;
|
||||||
const { camera, scene } = layerState._viewer;
|
const pose = findCamera(layerState._viewer)?.pose();
|
||||||
const width = scene.canvas.clientWidth || scene.canvas.width || 0;
|
if (!pose?.position) return false;
|
||||||
const height = scene.canvas.clientHeight || scene.canvas.height || 0;
|
const canvas = canvasOf(layerState._viewer);
|
||||||
|
const width = canvas?.clientWidth || canvas?.width || 0;
|
||||||
|
const height = canvas?.clientHeight || canvas?.height || 0;
|
||||||
const minX = -width * VIEW_ICON_MARGIN;
|
const minX = -width * VIEW_ICON_MARGIN;
|
||||||
const maxX = width * (1 + VIEW_ICON_MARGIN);
|
const maxX = width * (1 + VIEW_ICON_MARGIN);
|
||||||
const minY = -height * VIEW_ICON_MARGIN;
|
const minY = -height * VIEW_ICON_MARGIN;
|
||||||
const maxY = height * (1 + VIEW_ICON_MARGIN);
|
const maxY = height * (1 + VIEW_ICON_MARGIN);
|
||||||
// Ground metres one pixel covers per metre of distance from the viewer.
|
// Ground metres one pixel covers per metre of distance from the viewer.
|
||||||
const fovy = Number.isFinite(camera.frustum?.fovy)
|
const fovy = Number.isFinite(pose.fovy) ? pose.fovy : Math.PI / 3;
|
||||||
? camera.frustum.fovy
|
|
||||||
: Math.PI / 3;
|
|
||||||
const metresPerPixelPerMetre =
|
const metresPerPixelPerMetre =
|
||||||
(2 * Math.tan(fovy / 2)) / Math.max(1, height);
|
(2 * Math.tan(fovy / 2)) / Math.max(1, height);
|
||||||
const viewer = camera.positionWC;
|
const viewer = pose.position;
|
||||||
// The horizon test of Cesium's EllipsoidalOccluder, inlined: this loop
|
// The renderer's horizon test (geo/horizon.js), inlined: this loop
|
||||||
// visits every camera in the catalog.
|
// visits every camera in the catalog.
|
||||||
const inverseRadii = Cesium.Ellipsoid.WGS84.oneOverRadii;
|
const inverseRadii = WGS84.oneOverRadii;
|
||||||
const cx = viewer.x * inverseRadii.x;
|
const cx = viewer.x * inverseRadii.x;
|
||||||
const cy = viewer.y * inverseRadii.y;
|
const cy = viewer.y * inverseRadii.y;
|
||||||
const cz = viewer.z * inverseRadii.z;
|
const cz = viewer.z * inverseRadii.z;
|
||||||
const limbSquared = cx * cx + cy * cy + cz * cz - 1;
|
const limbSquared = cx * cx + cy * cy + cz * cz - 1;
|
||||||
const activeId = layerState._activeCameraId;
|
const activeId = layerState._activeCameraId;
|
||||||
const project = screenProjector(scene, camera, width, height);
|
const project = screenProjector(pose, width, height);
|
||||||
const pass = (layerState._viewPassId = (layerState._viewPassId || 0) + 1);
|
const pass = (layerState._viewPassId = (layerState._viewPassId || 0) + 1);
|
||||||
const shown = [];
|
const shown = [];
|
||||||
const cells = new Map();
|
const cells = new Map();
|
||||||
@@ -378,11 +402,14 @@ export function createRendering({
|
|||||||
record.viewPass = pass;
|
record.viewPass = pass;
|
||||||
shown.push(record);
|
shown.push(record);
|
||||||
}
|
}
|
||||||
const icons = layerState._icons;
|
const writes = [];
|
||||||
for (const record of layerState._records) {
|
for (const record of layerState._records) {
|
||||||
const row = icons?.row(record.camera.id) ?? -1;
|
const item = patchedCameraIcon(record.camera.id, {
|
||||||
if (row >= 0) icons.setShown(row, record.viewPass === pass);
|
show: record.viewPass === pass,
|
||||||
|
});
|
||||||
|
if (item) writes.push(item);
|
||||||
}
|
}
|
||||||
|
writeCameraIcons(writes);
|
||||||
const previous = layerState._viewRecords;
|
const previous = layerState._viewRecords;
|
||||||
const changed =
|
const changed =
|
||||||
previous.length !== shown.length ||
|
previous.length !== shown.length ||
|
||||||
@@ -392,37 +419,21 @@ export function createRendering({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Canvas coordinates for world positions. In 3D the pass multiplies by one
|
* Canvas coordinates for world positions, from the eye's pose by the
|
||||||
* view-projection matrix per call instead of Cesium's per-point
|
* renderer's perspective projection (geo/frustum.js): one pose read per
|
||||||
* cartesianToCanvasCoordinates, which dominated the pass on a large
|
* pass rather than a renderer projection per point, which dominated the
|
||||||
* catalog; other scene modes keep Cesium's projection.
|
* pass on a large catalog. Null behind the eye or before its near plane.
|
||||||
* @returns {(position: Cesium.Cartesian3) => ({x: number, y: number}|null)}
|
* A pose with no perspective field of view is projected by the renderer,
|
||||||
|
* point by point.
|
||||||
|
* @returns {(position: {x: number, y: number, z: number}) =>
|
||||||
|
* ({x: number, y: number}|null)}
|
||||||
*/
|
*/
|
||||||
function screenProjector(scene, camera, width, height) {
|
function screenProjector(pose, width, height) {
|
||||||
const out = layerState._scratchViewScreen;
|
if (Number.isFinite(pose.fovy) && Number.isFinite(pose.aspectRatio)) {
|
||||||
const projection = camera.frustum?.projectionMatrix;
|
return poseProjector(pose, width, height, layerState._scratchViewScreen);
|
||||||
if (
|
}
|
||||||
scene.mode !== Cesium.SceneMode.SCENE3D ||
|
const query = findQuery(layerState._viewer);
|
||||||
!projection ||
|
return (position) => query?.project(position) ?? null;
|
||||||
!camera.viewMatrix
|
|
||||||
)
|
|
||||||
return (position) => scene.cartesianToCanvasCoordinates(position, out);
|
|
||||||
const m = Cesium.Matrix4.multiply(
|
|
||||||
projection,
|
|
||||||
camera.viewMatrix,
|
|
||||||
layerState._scratchViewProjection,
|
|
||||||
);
|
|
||||||
return (p) => {
|
|
||||||
const w = m[3] * p.x + m[7] * p.y + m[11] * p.z + m[15];
|
|
||||||
const z = m[2] * p.x + m[6] * p.y + m[10] * p.z + m[14];
|
|
||||||
// Behind the eye or before the near plane: Cesium does not draw it.
|
|
||||||
if (!(w > 0) || z < 0) return null;
|
|
||||||
out.x =
|
|
||||||
((m[0] * p.x + m[4] * p.y + m[8] * p.z + m[12]) / w + 1) * 0.5 * width;
|
|
||||||
out.y =
|
|
||||||
(1 - (m[1] * p.x + m[5] * p.y + m[9] * p.z + m[13]) / w) * 0.5 * height;
|
|
||||||
return out;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -444,7 +455,7 @@ export function createRendering({
|
|||||||
return record.viewCellKey;
|
return record.viewCellKey;
|
||||||
const latStep = 2 ** level / 111_320;
|
const latStep = 2 ** level / 111_320;
|
||||||
const row = Math.floor(lat / latStep);
|
const row = Math.floor(lat / latStep);
|
||||||
const rowLat = Cesium.Math.toRadians((row + 0.5) * latStep);
|
const rowLat = toRadians((row + 0.5) * latStep);
|
||||||
const lonStep = latStep / Math.max(0.05, Math.cos(rowLat));
|
const lonStep = latStep / Math.max(0.05, Math.cos(rowLat));
|
||||||
record.viewCellLevel = level;
|
record.viewCellLevel = level;
|
||||||
record.viewCellLat = lat;
|
record.viewCellLat = lat;
|
||||||
@@ -530,16 +541,16 @@ export function createRendering({
|
|||||||
coverageVisible,
|
coverageVisible,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const icons = layerState._icons;
|
// Only changed icons are written, in one go after the pass, so across a
|
||||||
|
// large catalog only the changed rows upload.
|
||||||
|
const restyled = [];
|
||||||
for (const record of layerState._records) {
|
for (const record of layerState._records) {
|
||||||
const isActive = record.camera.id === activeId;
|
const isActive = record.camera.id === activeId;
|
||||||
const row = icons?.row(record.camera.id) ?? -1;
|
const icon = patchedCameraIcon(record.camera.id, {
|
||||||
if (row >= 0) {
|
color: cameraColorFor(record),
|
||||||
// The set skips unchanged writes, so across a large catalog only the
|
scale: isActive ? 1.25 : 1.0,
|
||||||
// changed rows upload.
|
});
|
||||||
icons.setColor(row, cameraColorFor(record));
|
if (icon) restyled.push(icon);
|
||||||
icons.setScale(row, isActive ? 1.25 : 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
layerState._enabled &&
|
layerState._enabled &&
|
||||||
@@ -632,48 +643,30 @@ export function createRendering({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeCameraIcons(restyled);
|
||||||
if (layerState._icons) layerState._icons.show = !!layerState._enabled;
|
if (layerState._icons) layerState._icons.show = !!layerState._enabled;
|
||||||
parts.projection.pauseInactiveProjectionFeeds(activeId);
|
parts.projection.pauseInactiveProjectionFeeds(activeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports whether the active Google Photorealistic 3D Tileset (if any) has
|
* Reports whether the photorealistic tiles the scene draws have finished
|
||||||
* finished loading the tiles in view. Shared mesh-floor sampling is gated on
|
* loading the tiles in view. Shared mesh-floor sampling is gated on this so
|
||||||
* this so a one-shot cell never bakes in a miss from still-streaming tiles.
|
* a one-shot cell never bakes in a miss from still-streaming tiles.
|
||||||
* Discovers + caches the tileset lazily from scene
|
|
||||||
* primitives (the CCTV module holds only a `_viewer` reference). When no
|
|
||||||
* tileset is present (OSM fallback) this returns true so ground sampling is
|
|
||||||
* not permanently blocked.
|
|
||||||
*
|
*
|
||||||
* Task 5 (review correction, spec §2): a HIDDEN tileset (`show === false`,
|
* Only the photoreal regime (the globe hidden under the tiles) can be
|
||||||
* i.e. a globe stack is active) must NOT report ready — Cesium 1.138's
|
* ready: on a globe stack the tiles are hidden, and the shared sampler can
|
||||||
* the shared sampler can only inspect *visible* 3D tilesets, so a sample taken
|
* only inspect tiles that are drawn, so a sample taken against them would
|
||||||
* against the hidden Google tileset would silently miss.
|
* silently miss (Task 5, spec §2). The tiles' readiness is the globe
|
||||||
|
* port's (`isSettled('tiles')`), true as well when no tiles are drawn.
|
||||||
*
|
*
|
||||||
* @returns {boolean} True when tiles are loaded AND visible (or no tileset
|
* @returns {boolean} True when the regime is photoreal and its tiles in
|
||||||
* exists to wait on).
|
* view have loaded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function projectionTilesReady() {
|
function projectionTilesReady() {
|
||||||
if (
|
const globe = layerState._viewer ? findGlobe(layerState._viewer) : null;
|
||||||
!layerState._activeTileset ||
|
if (!globe || globe.isGlobeVisible?.() !== false) return false;
|
||||||
layerState._activeTileset.isDestroyed?.()
|
return globe.isSettled('tiles') === true;
|
||||||
) {
|
|
||||||
layerState._activeTileset = null;
|
|
||||||
const primitives = layerState._viewer?.scene?.primitives;
|
|
||||||
if (primitives && typeof primitives.get === 'function') {
|
|
||||||
for (let i = 0; i < primitives.length; i++) {
|
|
||||||
const p = primitives.get(i);
|
|
||||||
if (p instanceof Cesium.Cesium3DTileset && !p.isDestroyed?.()) {
|
|
||||||
layerState._activeTileset = p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!layerState._activeTileset) return true;
|
|
||||||
if (layerState._activeTileset.show === false) return false;
|
|
||||||
return layerState._activeTileset.tilesLoaded === true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -803,66 +796,58 @@ export function createRendering({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts a camera ID from a scene pick result by checking icon row IDs,
|
* The camera a pick (a draw-port `Hit`: `event.drawHit`, `query.pick`)
|
||||||
* primitive IDs, and the camera ids the layer keeps for its coverage entities.
|
* names: an item of the layer's own sets that its record still draws.
|
||||||
* @param {Object|null} picked - Result from scene.pick().
|
* @param {{set: string, id: string, meta?: object}|null} hit
|
||||||
* @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 item.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function extractPickedCameraId(picked) {
|
function extractPickedCameraId(hit) {
|
||||||
if (!picked) return null;
|
if (!hit || typeof hit.set !== 'string' || typeof hit.id !== 'string')
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// A camera icon: its item id is the upstream camera id, so a sibling
|
||||||
|
// may legitimately use the same string. A bare id match is not
|
||||||
|
// ownership proof: the layer's own icon set must have drawn the pick.
|
||||||
|
const icons = layerState._icons;
|
||||||
|
if (icons && hit.set === icons.setId)
|
||||||
|
return icons.has(hit.id) && layerState._recordById.has(hit.id)
|
||||||
|
? hit.id
|
||||||
|
: null;
|
||||||
|
|
||||||
// A coverage line or monitor plane: an item of the layer's own sets
|
// A coverage line or monitor plane: an item of the layer's own sets
|
||||||
// that its record still draws.
|
// that its record still draws.
|
||||||
const hit = drawHitOf(picked);
|
const role = parts.drawSets.roleOfSet(hit.set);
|
||||||
const role = hit ? parts.drawSets.roleOfSet(hit.set) : null;
|
if (!role) return null;
|
||||||
if (role) {
|
const value = hit.meta?.cameraId;
|
||||||
const value = hit.meta?.cameraId;
|
|
||||||
const record =
|
|
||||||
typeof value === 'string' ? layerState._recordById.get(value) : null;
|
|
||||||
if (!record) return null;
|
|
||||||
const owns =
|
|
||||||
role === 'coverage'
|
|
||||||
? Boolean(record.coverageEntities?.some((h) => h?.id === hit.id))
|
|
||||||
: record.projection?.plane?.id === hit.id ||
|
|
||||||
layerState._projectionEntities.some(
|
|
||||||
(runtime) =>
|
|
||||||
runtime?.cameraId === value && runtime.plane?.id === hit.id,
|
|
||||||
);
|
|
||||||
return owns ? value : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
// ownership proof: require that this layer's icon set drew the pick.
|
|
||||||
const directId =
|
|
||||||
typeof picked.id === 'string'
|
|
||||||
? picked.id
|
|
||||||
: typeof picked.primitive?.id === 'string'
|
|
||||||
? picked.primitive.id
|
|
||||||
: null;
|
|
||||||
const record =
|
const record =
|
||||||
directId === null ? null : layerState._recordById.get(directId);
|
typeof value === 'string' ? layerState._recordById.get(value) : null;
|
||||||
if (!record) return null;
|
if (!record) return null;
|
||||||
return layerState._icons && picked.iconSet === layerState._icons
|
const owns =
|
||||||
? directId
|
role === 'coverage'
|
||||||
: null;
|
? Boolean(record.coverageEntities?.some((h) => h?.id === hit.id))
|
||||||
|
: record.projection?.plane?.id === hit.id ||
|
||||||
|
layerState._projectionEntities.some(
|
||||||
|
(runtime) =>
|
||||||
|
runtime?.cameraId === value && runtime.plane?.id === hit.id,
|
||||||
|
);
|
||||||
|
return owns ? value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The camera whose icon or coverage is under a screen position (CSS px),
|
* The camera whose icon or coverage is under a screen position (CSS px),
|
||||||
* from one scene pick; null when none is, or the pick throws.
|
* from one pick; null when none is, or the pick throws.
|
||||||
* @param {{x: number, y: number}} position
|
* @param {{x: number, y: number}} position
|
||||||
* @returns {string|null}
|
* @returns {string|null}
|
||||||
*/
|
*/
|
||||||
function pickCameraIdAt(position) {
|
function pickCameraIdAt(position) {
|
||||||
let picked = null;
|
let hit = null;
|
||||||
try {
|
try {
|
||||||
picked = layerState._viewer.scene.pick(position);
|
hit = findQuery(layerState._viewer)?.pick(position.x, position.y) ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
picked = null;
|
hit = null;
|
||||||
}
|
}
|
||||||
return extractPickedCameraId(picked);
|
return extractPickedCameraId(hit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -870,17 +855,20 @@ export function createRendering({
|
|||||||
* canvas position of a world point on the near side of the horizon (null
|
* canvas position of a world point on the near side of the horizon (null
|
||||||
* behind it or off the projection).
|
* behind it or off the projection).
|
||||||
* @returns {{width: number, height: number,
|
* @returns {{width: number, height: number,
|
||||||
* screenOf: (position: object) => ({x: number, y: number}|undefined|null)}}
|
* screenOf: (position: object) => ({x: number, y: number}|null)}}
|
||||||
*/
|
*/
|
||||||
function cardView() {
|
function cardView() {
|
||||||
const { camera, scene } = layerState._viewer;
|
const viewer = layerState._viewer;
|
||||||
const occluder = horizonOccluder(camera);
|
const canvas = canvasOf(viewer);
|
||||||
|
const query = findQuery(viewer);
|
||||||
|
const eye = findCamera(viewer)?.pose()?.position;
|
||||||
|
const horizon = eye ? horizonFrom(eye) : null;
|
||||||
return {
|
return {
|
||||||
width: scene.canvas.clientWidth || scene.canvas.width || 0,
|
width: canvas?.clientWidth || canvas?.width || 0,
|
||||||
height: scene.canvas.clientHeight || scene.canvas.height || 0,
|
height: canvas?.clientHeight || canvas?.height || 0,
|
||||||
screenOf: (position) =>
|
screenOf: (position) =>
|
||||||
occluder.isPointVisible(position)
|
query && horizon?.isPointVisible(position)
|
||||||
? scene.cartesianToCanvasCoordinates(position)
|
? query.project(position)
|
||||||
: null,
|
: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +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.
|
// Teardown lets go of the icon set of the viewer that drew it.
|
||||||
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';
|
||||||
@@ -13,86 +13,103 @@ import {
|
|||||||
} from './policy.js';
|
} from './policy.js';
|
||||||
import { isVideoFeedType } from '../../sources/cctvTypes.js';
|
import { isVideoFeedType } from '../../sources/cctvTypes.js';
|
||||||
import * as Cesium from 'cesium';
|
import * as Cesium from 'cesium';
|
||||||
import { createIconSet } from '../../data/iconSet.js';
|
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||||
|
import { fakeCameraPort } from '../../testSupport/fakeCameraPort.mjs';
|
||||||
import { bindRenderer } from '../../render/rendererOf.js';
|
import { bindRenderer } from '../../render/rendererOf.js';
|
||||||
|
|
||||||
const FOCUS_FACTOR = 0.5;
|
const FOCUS_FACTOR = 0.5;
|
||||||
|
|
||||||
function assertKeepsColor(icons, id, base, label) {
|
function assertKeepsColor(icons, id, base, label) {
|
||||||
const row = icons.row(id);
|
assert.deepEqual(icons.item(id).color, base, `${label}: base color kept`);
|
||||||
const actual = icons.color(row);
|
assert.equal(icons.focus(id), FOCUS_FACTOR, `${label}: focus`);
|
||||||
assert.deepEqual(
|
|
||||||
[actual.red, actual.green, actual.blue, actual.alpha].map(
|
|
||||||
Cesium.Color.floatToByte,
|
|
||||||
),
|
|
||||||
base.map(Cesium.Color.floatToByte),
|
|
||||||
`${label}: base color kept`,
|
|
||||||
);
|
|
||||||
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', () => {
|
||||||
const record = (id, feedType) => ({
|
const record = (id, feedType) => ({
|
||||||
camera: { id, feedType },
|
camera: { id, feedType },
|
||||||
// No position, so the pass skips screen projection; the focus stub below
|
position: { x: 6378137, y: 0, z: 0 },
|
||||||
// decides the factor on its own.
|
|
||||||
});
|
});
|
||||||
const idleVideo = record('idle-hls', 'hls');
|
const idleVideo = record('idle-hls', 'hls');
|
||||||
const idleStill = record('idle-image', 'image');
|
const idleStill = record('idle-image', 'image');
|
||||||
const activeVideo = record('active-hls', 'hls');
|
const activeVideo = record('active-hls', 'hls');
|
||||||
|
const viewer = {};
|
||||||
|
const camera = fakeCameraPort({
|
||||||
|
pose: { position: { x: 6378137 + 1000, y: 0, z: 0 } },
|
||||||
|
});
|
||||||
|
const projected = [];
|
||||||
|
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||||
|
camera: camera.port,
|
||||||
|
query: {
|
||||||
|
project: (position) => {
|
||||||
|
projected.push(position);
|
||||||
|
return { x: 10, y: 20 };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
const state = {
|
const state = {
|
||||||
_enabled: true,
|
_enabled: true,
|
||||||
_viewer: { scene: {}, camera: {} },
|
_viewer: viewer,
|
||||||
_records: [idleVideo, idleStill, activeVideo],
|
_records: [idleVideo, idleStill, activeVideo],
|
||||||
_activeCameraId: activeVideo.camera.id,
|
_activeCameraId: activeVideo.camera.id,
|
||||||
_activeFocusStyleCount: 0,
|
_activeFocusStyleCount: 0,
|
||||||
_lastFocusStyleAt: -Infinity,
|
_lastFocusStyleAt: -Infinity,
|
||||||
_icons: createIconSet(),
|
|
||||||
};
|
};
|
||||||
|
const distances = [];
|
||||||
const focus = {
|
const focus = {
|
||||||
focusNowMs: (nowMs) => nowMs,
|
focusNowMs: (nowMs) => nowMs,
|
||||||
getFocusTarget: () => ({}),
|
getFocusTarget: () => ({}),
|
||||||
focusPassIsNeeded: () => true,
|
focusPassIsNeeded: () => true,
|
||||||
advanceSpriteFocus: () => ({
|
advanceSpriteFocus: (meta, input) => {
|
||||||
factor: FOCUS_FACTOR,
|
distances.push(input.cameraDistance);
|
||||||
active: true,
|
return { factor: FOCUS_FACTOR, active: true, transitioning: false };
|
||||||
transitioning: false,
|
},
|
||||||
}),
|
|
||||||
focusAlphaNeedsWrite: () => true,
|
focusAlphaNeedsWrite: () => true,
|
||||||
};
|
};
|
||||||
const { addCameraIcon, refreshCctvFocusStyles } = createRendering({
|
const { createCameraIcons, addCameraIcon, refreshCctvFocusStyles } =
|
||||||
state,
|
createRendering({
|
||||||
services: { focus },
|
state,
|
||||||
parts: { model: { isVideoFeedType } },
|
services: { focus },
|
||||||
source: {},
|
parts: { model: { isVideoFeedType } },
|
||||||
});
|
source: {},
|
||||||
for (const r of state._records) addCameraIcon(r);
|
});
|
||||||
|
try {
|
||||||
|
const setId = createCameraIcons(viewer);
|
||||||
|
for (const r of state._records) addCameraIcon(r);
|
||||||
|
|
||||||
refreshCctvFocusStyles(1000);
|
refreshCctvFocusStyles(1000);
|
||||||
|
|
||||||
const icons = state._icons;
|
const icons = state._icons;
|
||||||
assertKeepsColor(icons, 'idle-hls', LIVE_CAMERA_COLOR, 'idle video');
|
assertKeepsColor(icons, 'idle-hls', LIVE_CAMERA_COLOR, 'idle video');
|
||||||
assertKeepsColor(icons, 'idle-image', IDLE_CAMERA_COLOR, 'idle still');
|
assertKeepsColor(icons, 'idle-image', IDLE_CAMERA_COLOR, 'idle still');
|
||||||
assertKeepsColor(icons, 'active-hls', ACTIVE_CAMERA_COLOR, 'active video');
|
assertKeepsColor(icons, 'active-hls', ACTIVE_CAMERA_COLOR, 'active video');
|
||||||
assert.equal(state._activeFocusStyleCount, 3);
|
assert.equal(state._activeFocusStyleCount, 3);
|
||||||
|
assert.equal(projected.length, 3, 'each shown icon is projected');
|
||||||
|
assert.deepEqual(distances, [1000, 1000, 1000], 'from the eye');
|
||||||
|
// What the set draws: depth-test-free, held at the mount, shrinking
|
||||||
|
// with distance as before.
|
||||||
|
const drawn = draw.set(setId).items.get('idle-hls');
|
||||||
|
assert.equal(drawn.disableDepthTest, Infinity);
|
||||||
|
assert.deepEqual(drawn.motion, { kind: 'hold' });
|
||||||
|
assert.deepEqual(drawn.pos, idleVideo.position);
|
||||||
|
assert.deepEqual(drawn.size, [24, 24]);
|
||||||
|
assert.deepEqual(drawn.scaleByDistance, {
|
||||||
|
near: 350,
|
||||||
|
nearValue: 1.25,
|
||||||
|
far: 4_000_000,
|
||||||
|
farValue: 0.42,
|
||||||
|
});
|
||||||
|
assert.equal(drawn.focus, FOCUS_FACTOR);
|
||||||
|
assert.equal(draw.set(setId).spec.horizonCull, true);
|
||||||
|
} finally {
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('icons leave the scene they were added to, whichever viewer tears down', () => {
|
test('the icons go with the viewer that drew them, whichever tears down', () => {
|
||||||
const viewer = () => {
|
const first = {};
|
||||||
const held = new Set();
|
const second = {};
|
||||||
return {
|
const one = bindFakeDraw(first);
|
||||||
held,
|
const two = bindFakeDraw(second);
|
||||||
scene: {
|
|
||||||
requestRender() {},
|
|
||||||
primitives: {
|
|
||||||
add: (p) => held.add(p),
|
|
||||||
remove: (p) => held.delete(p),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
const first = viewer();
|
|
||||||
const second = viewer();
|
|
||||||
const state = { _viewer: first };
|
const state = { _viewer: first };
|
||||||
const { createCameraIcons, destroyCameraIcons } = createRendering({
|
const { createCameraIcons, destroyCameraIcons } = createRendering({
|
||||||
state,
|
state,
|
||||||
@@ -100,17 +117,21 @@ test('icons leave the scene they were added to, whichever viewer tears down', ()
|
|||||||
parts: {},
|
parts: {},
|
||||||
source: {},
|
source: {},
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
const old = createCameraIcons(first);
|
||||||
|
state._viewer = second;
|
||||||
|
const current = createCameraIcons(second);
|
||||||
|
assert.notEqual(old, current);
|
||||||
|
assert.equal(one.draw.sets.get(old).disposed, true, 'a re-init lets go');
|
||||||
|
assert.equal(two.draw.sets.get(current).disposed, false);
|
||||||
|
|
||||||
const old = createCameraIcons(first);
|
destroyCameraIcons();
|
||||||
state._viewer = second;
|
assert.equal(two.draw.sets.get(current).disposed, true);
|
||||||
const current = createCameraIcons(second);
|
assert.equal(state._icons, null);
|
||||||
assert.equal(first.held.has(old), false, 'a re-init takes out the old icons');
|
} finally {
|
||||||
assert.equal(old.isDestroyed(), true);
|
one.unbind();
|
||||||
|
two.unbind();
|
||||||
destroyCameraIcons();
|
}
|
||||||
assert.equal(second.held.has(current), false);
|
|
||||||
assert.equal(current.isDestroyed(), true);
|
|
||||||
assert.equal(state._icons, null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the obstruction probe casts one ray through the query port', async () => {
|
test('the obstruction probe casts one ray through the query port', async () => {
|
||||||
@@ -159,22 +180,188 @@ test('cards go only where the horizon lets the camera see', () => {
|
|||||||
const eye = Cesium.Cartesian3.fromDegrees(0, 0, 20_000_000);
|
const eye = Cesium.Cartesian3.fromDegrees(0, 0, 20_000_000);
|
||||||
const front = Cesium.Cartesian3.fromDegrees(0, 0);
|
const front = Cesium.Cartesian3.fromDegrees(0, 0);
|
||||||
const back = Cesium.Cartesian3.fromDegrees(180, 0);
|
const back = Cesium.Cartesian3.fromDegrees(180, 0);
|
||||||
const state = {
|
const viewer = {};
|
||||||
_viewer: {
|
const camera = fakeCameraPort({
|
||||||
camera: { positionWC: eye },
|
pose: { position: { x: eye.x, y: eye.y, z: eye.z } },
|
||||||
scene: {
|
});
|
||||||
canvas: { clientWidth: 800, clientHeight: 0, height: 600 },
|
const unbind = bindRenderer(viewer, {
|
||||||
cartesianToCanvasCoordinates: () => ({ x: 10, y: 20 }),
|
camera: camera.port,
|
||||||
},
|
canvas: { clientWidth: 800, clientHeight: 0, height: 600 },
|
||||||
|
query: { project: () => ({ x: 10, y: 20 }) },
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const view = createRendering({
|
||||||
|
state: { _viewer: viewer },
|
||||||
|
services: { focus: {} },
|
||||||
|
parts: {},
|
||||||
|
}).cardView();
|
||||||
|
assert.equal(view.width, 800);
|
||||||
|
assert.equal(view.height, 600);
|
||||||
|
assert.deepEqual(view.screenOf(front), { x: 10, y: 20 });
|
||||||
|
assert.equal(view.screenOf(back), null);
|
||||||
|
} finally {
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the projection tiles are ready only when drawn and settled', () => {
|
||||||
|
const viewer = {};
|
||||||
|
let globeVisible = true;
|
||||||
|
let settled = true;
|
||||||
|
const unbind = bindRenderer(viewer, {
|
||||||
|
globe: {
|
||||||
|
isGlobeVisible: () => globeVisible,
|
||||||
|
isSettled: (kind) => kind === 'tiles' && settled,
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
const view = createRendering({
|
try {
|
||||||
state,
|
const { projectionTilesReady } = createRendering({
|
||||||
|
state: { _viewer: viewer },
|
||||||
|
services: { focus: {} },
|
||||||
|
parts: {},
|
||||||
|
});
|
||||||
|
assert.equal(projectionTilesReady(), false, 'a globe stack hides them');
|
||||||
|
globeVisible = false;
|
||||||
|
assert.equal(projectionTilesReady(), true);
|
||||||
|
settled = false;
|
||||||
|
assert.equal(projectionTilesReady(), false, 'still streaming');
|
||||||
|
} finally {
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
|
const bare = createRendering({
|
||||||
|
state: { _viewer: {} },
|
||||||
services: { focus: {} },
|
services: { focus: {} },
|
||||||
parts: {},
|
parts: {},
|
||||||
}).cardView();
|
});
|
||||||
assert.equal(view.width, 800);
|
assert.equal(bare.projectionTilesReady(), false, 'no globe, no tiles');
|
||||||
assert.equal(view.height, 600);
|
});
|
||||||
assert.deepEqual(view.screenOf(front), { x: 10, y: 20 });
|
|
||||||
assert.equal(view.screenOf(back), null);
|
test('a view pass writes only the icons it changes, in one write', () => {
|
||||||
|
const viewer = {};
|
||||||
|
const eye = Cesium.Cartesian3.fromDegrees(0, 0, 2000);
|
||||||
|
const down = Cesium.Cartesian3.normalize(
|
||||||
|
Cesium.Cartesian3.negate(eye, new Cesium.Cartesian3()),
|
||||||
|
new Cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
const camera = fakeCameraPort({
|
||||||
|
pose: {
|
||||||
|
position: { x: eye.x, y: eye.y, z: eye.z },
|
||||||
|
direction: { x: down.x, y: down.y, z: down.z },
|
||||||
|
up: { x: 0, y: 0, z: 1 },
|
||||||
|
fovy: Math.PI / 3,
|
||||||
|
aspectRatio: 4 / 3,
|
||||||
|
near: 0.1,
|
||||||
|
far: 5e8,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||||
|
camera: camera.port,
|
||||||
|
canvas: { clientWidth: 800, clientHeight: 600 },
|
||||||
|
});
|
||||||
|
const record = (id, lon) => {
|
||||||
|
const p = Cesium.Cartesian3.fromDegrees(lon, 0, 10);
|
||||||
|
return {
|
||||||
|
camera: { id, lat: 0, lon },
|
||||||
|
position: { x: p.x, y: p.y, z: p.z },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
// One in view, one far off it.
|
||||||
|
const near = record('near', 0);
|
||||||
|
const far = record('far', 1);
|
||||||
|
const state = {
|
||||||
|
_enabled: true,
|
||||||
|
_viewer: viewer,
|
||||||
|
_records: [near, far],
|
||||||
|
_viewRecords: [],
|
||||||
|
_healthById: new Map(),
|
||||||
|
_scratchViewScreen: { x: 0, y: 0 },
|
||||||
|
};
|
||||||
|
const rendering = createRendering({
|
||||||
|
state,
|
||||||
|
services: { focus: {} },
|
||||||
|
parts: {
|
||||||
|
model: { isVideoFeedType: () => false },
|
||||||
|
drawSets: { roleOfSet: () => null },
|
||||||
|
},
|
||||||
|
source: {},
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const setId = rendering.createCameraIcons(viewer);
|
||||||
|
for (const r of state._records) rendering.addCameraIcon(r);
|
||||||
|
const set = draw.set(setId);
|
||||||
|
const writes = set.writes;
|
||||||
|
|
||||||
|
assert.equal(rendering.refreshHorizonCulling(), true);
|
||||||
|
assert.equal(set.writes, writes + 1, 'one write for the pass');
|
||||||
|
assert.equal(set.items.get('near').show, true);
|
||||||
|
assert.equal(set.items.get('far').show, false);
|
||||||
|
|
||||||
|
assert.equal(rendering.refreshHorizonCulling(), false);
|
||||||
|
assert.equal(set.writes, writes + 1, 'an unchanged view writes nothing');
|
||||||
|
|
||||||
|
// Another layer on the same viewer draws its icons in a set of its own.
|
||||||
|
const other = createRendering({
|
||||||
|
state: { _viewer: viewer },
|
||||||
|
services: { focus: {} },
|
||||||
|
parts: {},
|
||||||
|
source: {},
|
||||||
|
});
|
||||||
|
const otherId = other.createCameraIcons(viewer);
|
||||||
|
assert.notEqual(otherId, setId);
|
||||||
|
assert.equal(
|
||||||
|
rendering.extractPickedCameraId({ set: otherId, id: 'near' }),
|
||||||
|
null,
|
||||||
|
"the other layer's icon is not this layer's camera",
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a pose with no perspective field of view is projected by the renderer', () => {
|
||||||
|
const viewer = {};
|
||||||
|
const camera = fakeCameraPort({
|
||||||
|
pose: { position: { x: 7e6, y: 0, z: 0 }, fovy: undefined },
|
||||||
|
});
|
||||||
|
const asked = [];
|
||||||
|
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||||
|
camera: camera.port,
|
||||||
|
canvas: { clientWidth: 800, clientHeight: 600 },
|
||||||
|
query: {
|
||||||
|
project: (position) => {
|
||||||
|
asked.push(position.y);
|
||||||
|
return position.y === 0 ? { x: 400, y: 300 } : null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// On the ground under the eye, in cells of their own.
|
||||||
|
const record = (id, y) => ({
|
||||||
|
camera: { id, lat: 0, lon: y / 1000 },
|
||||||
|
position: { x: 6378137, y, z: 0 },
|
||||||
|
});
|
||||||
|
const state = {
|
||||||
|
_enabled: true,
|
||||||
|
_viewer: viewer,
|
||||||
|
_records: [record('on', 0), record('off', 1000)],
|
||||||
|
_viewRecords: [],
|
||||||
|
_healthById: new Map(),
|
||||||
|
_scratchViewScreen: { x: 0, y: 0 },
|
||||||
|
};
|
||||||
|
const rendering = createRendering({
|
||||||
|
state,
|
||||||
|
services: { focus: {} },
|
||||||
|
parts: { model: { isVideoFeedType: () => false } },
|
||||||
|
source: {},
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const setId = rendering.createCameraIcons(viewer);
|
||||||
|
for (const r of state._records) rendering.addCameraIcon(r);
|
||||||
|
rendering.refreshHorizonCulling();
|
||||||
|
const set = draw.set(setId);
|
||||||
|
assert.deepEqual(asked.sort(), [0, 1000]);
|
||||||
|
assert.equal(set.items.get('on').show, true);
|
||||||
|
assert.equal(set.items.get('off').show, false);
|
||||||
|
} finally {
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { createCctvSource, createCctvLayer } from './index.js';
|
import { createCctvSource, createCctvLayer } from './index.js';
|
||||||
|
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||||
|
|
||||||
const camera = {
|
const camera = {
|
||||||
id: 'pack/camera ?x',
|
id: 'pack/camera ?x',
|
||||||
@@ -110,7 +111,7 @@ test('camera construction is inert and destruction cancels a pending catalog and
|
|||||||
setOverlayEntries: noop,
|
setOverlayEntries: noop,
|
||||||
setOverlaySourceVisible: noop,
|
setOverlaySourceVisible: noop,
|
||||||
},
|
},
|
||||||
sprites: { registerSpriteCollection: noop },
|
sprites: { registerSpriteSet: noop },
|
||||||
activation: {},
|
activation: {},
|
||||||
locations: {},
|
locations: {},
|
||||||
picking: { unregisterPickOwner: noop },
|
picking: { unregisterPickOwner: noop },
|
||||||
@@ -134,9 +135,9 @@ test('camera construction is inert and destruction cancels a pending catalog and
|
|||||||
const a = createCctvLayer({ services, source });
|
const a = createCctvLayer({ services, source });
|
||||||
const b = createCctvLayer({ services, source });
|
const b = createCctvLayer({ services, source });
|
||||||
assert.equal(listeners.size, 0);
|
assert.equal(listeners.size, 0);
|
||||||
const viewer = {
|
const viewer = {};
|
||||||
scene: { primitives: { add: (value) => value, remove: () => true } },
|
const { unbind } = bindFakeDraw(viewer);
|
||||||
};
|
t.after(unbind);
|
||||||
const initializing = a.init(viewer);
|
const initializing = a.init(viewer);
|
||||||
assert.equal(listeners.size, 1);
|
assert.equal(listeners.size, 1);
|
||||||
assert.equal(signal.aborted, false);
|
assert.equal(signal.aborted, false);
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ export function createState({ services }) {
|
|||||||
|
|
||||||
layerState._viewer = null;
|
layerState._viewer = null;
|
||||||
|
|
||||||
/** The catalog's icon set and the primitive that draws it. */
|
/** The catalog's camera icons: the icon book over their draw set. */
|
||||||
layerState._icons = null;
|
layerState._icons = null;
|
||||||
layerState._iconPrimitive = null;
|
|
||||||
|
|
||||||
layerState._records = [];
|
layerState._records = [];
|
||||||
|
|
||||||
@@ -74,14 +73,9 @@ export function createState({ services }) {
|
|||||||
|
|
||||||
layerState._activeFocusStyleCount = 0;
|
layerState._activeFocusStyleCount = 0;
|
||||||
|
|
||||||
// Screen-point scratches: the projections that fill them write only x and y.
|
// The view pass's screen-point scratch: its projection writes only x and y.
|
||||||
layerState._scratchFocusScreen = { x: 0, y: 0 };
|
|
||||||
|
|
||||||
layerState._scratchViewScreen = { x: 0, y: 0 };
|
layerState._scratchViewScreen = { x: 0, y: 0 };
|
||||||
|
|
||||||
/** The view pass's view-projection matrix, column-major. */
|
|
||||||
layerState._scratchViewProjection = new Float64Array(16);
|
|
||||||
|
|
||||||
// Counts view passes; a record shown by the latest pass carries its number.
|
// Counts view passes; a record shown by the latest pass carries its number.
|
||||||
|
|
||||||
layerState._viewPassId = 0;
|
layerState._viewPassId = 0;
|
||||||
@@ -166,13 +160,6 @@ export function createState({ services }) {
|
|||||||
|
|
||||||
layerState._lastTransientNotifyAt = 0;
|
layerState._lastTransientNotifyAt = 0;
|
||||||
|
|
||||||
// Cached handle on the active Google Photorealistic 3D Tileset, discovered
|
|
||||||
// lazily from scene.primitives. Shared mesh-floor sampling is gated on its
|
|
||||||
// tilesLoaded flag so a coarse-LOD miss is never baked in. Cleared when the
|
|
||||||
// tileset is destroyed / the layer tears down.
|
|
||||||
|
|
||||||
layerState._activeTileset = null;
|
|
||||||
|
|
||||||
// Task 5: last surface regime the record geometry was recomputed for. The
|
// Task 5: last surface regime the record geometry was recomputed for. The
|
||||||
// map-stack change listener compares the CURRENT regime (derived live from
|
// map-stack change listener compares the CURRENT regime (derived live from
|
||||||
// whether the renderer shows the globe) against this so bing→osm switches (same 'terrain-globe'
|
// whether the renderer shows the globe) against this so bing→osm switches (same 'terrain-globe'
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
import { createIconSet } from '../../data/iconSet.js';
|
import { createIconBook } from '../../render/motion/iconBook.js';
|
||||||
|
|
||||||
|
/** A draw set that draws nothing, for the icon book the tests read. */
|
||||||
|
const testIconSet = () => ({
|
||||||
|
id: 'cctv:test:icons',
|
||||||
|
show: true,
|
||||||
|
upsert() {},
|
||||||
|
remove() {},
|
||||||
|
dispose() {},
|
||||||
|
});
|
||||||
|
|
||||||
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
|
||||||
@@ -102,7 +111,6 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
|||||||
);
|
);
|
||||||
layerState._coverageEntities = [];
|
layerState._coverageEntities = [];
|
||||||
layerState._projectionEntities = [];
|
layerState._projectionEntities = [];
|
||||||
layerState._iconPrimitive = null;
|
|
||||||
layerState._activeCameraId = activeCameraId;
|
layerState._activeCameraId = activeCameraId;
|
||||||
layerState._autoHopSuspended = false;
|
layerState._autoHopSuspended = false;
|
||||||
layerState._enabled = !!enabled;
|
layerState._enabled = !!enabled;
|
||||||
@@ -116,8 +124,9 @@ 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.
|
// A real book (over a set that draws nothing): every record gets its
|
||||||
layerState._icons = createIconSet();
|
// icon as init adds it.
|
||||||
|
layerState._icons = createIconBook(testIconSet());
|
||||||
for (const record of layerState._records)
|
for (const record of layerState._records)
|
||||||
if (record?.camera?.id) parts.rendering.addCameraIcon(record);
|
if (record?.camera?.id) parts.rendering.addCameraIcon(record);
|
||||||
}
|
}
|
||||||
@@ -147,7 +156,7 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The layer's icon set, for tests that read what the rows draw. */
|
/** The layer's icon book, for tests that read what the icons draw. */
|
||||||
|
|
||||||
function _cctvIconsForTest() {
|
function _cctvIconsForTest() {
|
||||||
return layerState._icons;
|
return layerState._icons;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
"src/data/geoImportPins.js",
|
"src/data/geoImportPins.js",
|
||||||
"src/input/dispatcher.js",
|
"src/input/dispatcher.js",
|
||||||
"src/input/sensorPick.js",
|
"src/input/sensorPick.js",
|
||||||
"src/layers/cctv/rendering.js",
|
|
||||||
"src/layers/firms/rendering.js",
|
"src/layers/firms/rendering.js",
|
||||||
"src/layers/ghostMaps/index.js",
|
"src/layers/ghostMaps/index.js",
|
||||||
"src/layers/installations/rendering.js",
|
"src/layers/installations/rendering.js",
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ export function createIconBook(drawSet = null, { capabilities = null } = {}) {
|
|||||||
else if (expiresAt !== undefined) expiries.set(item.id, expiresAt);
|
else if (expiresAt !== undefined) expiries.set(item.id, expiresAt);
|
||||||
drawSet?.upsert([item]);
|
drawSet?.upsert([item]);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Draw several items at once, as `put` draws one (a restyle: each keeps
|
||||||
|
* its motion's expiry), in one write to the set.
|
||||||
|
*/
|
||||||
|
putMany(list) {
|
||||||
|
if (!list.length) return;
|
||||||
|
for (const item of list) items.set(item.id, item);
|
||||||
|
drawSet?.upsert(list);
|
||||||
|
},
|
||||||
remove(id) {
|
remove(id) {
|
||||||
expiries.delete(id);
|
expiries.delete(id);
|
||||||
if (items.delete(id)) drawSet?.remove([id]);
|
if (items.delete(id)) drawSet?.remove([id]);
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ const DRAW_FROM_CALLER = new Set([
|
|||||||
'./layers/street-level/panoramax',
|
'./layers/street-level/panoramax',
|
||||||
'./layers/air-quality',
|
'./layers/air-quality',
|
||||||
'./layers/directions',
|
'./layers/directions',
|
||||||
|
// Its icons, wireframes, volumes, plane and gizmo draw through `drawOf`;
|
||||||
|
// it picks, projects and reads the eye and the globe through the ports.
|
||||||
|
'./layers/cctv',
|
||||||
// Its data packs draw through `drawOf`; its flights ask `cameraOf`, which
|
// Its data packs draw through `drawOf`; its flights ask `cameraOf`, which
|
||||||
// throws until then too.
|
// throws until then too.
|
||||||
'./scenes',
|
'./scenes',
|
||||||
@@ -116,6 +119,9 @@ const CAMERA_FROM_CALLER = new Set([
|
|||||||
'./ui/navigation',
|
'./ui/navigation',
|
||||||
'./voice/commands',
|
'./voice/commands',
|
||||||
'./voice/controller',
|
'./voice/controller',
|
||||||
|
// It loaded the camera factory only through the CCTV layer it took a
|
||||||
|
// constant from.
|
||||||
|
'./voice/actions',
|
||||||
'./voice/realtime-session',
|
'./voice/realtime-session',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -140,10 +140,11 @@ const SAMPLE_WINDOW_MS = 250;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* True when the active photoreal tileset has finished streaming the tiles in
|
* True when the active photoreal tileset has finished streaming the tiles in
|
||||||
* view (cctv.js's projectionTilesReady pattern: first Cesium3DTileset found in
|
* view (the pattern CCTV's projectionTilesReady once used: first
|
||||||
* scene.primitives, duck-typed via its boolean tilesLoaded). Sampling before
|
* Cesium3DTileset found in scene.primitives, duck-typed via its boolean
|
||||||
* that both blows the frame budget on forced synchronous loads and produces
|
* tilesLoaded). Sampling before that both blows the frame budget on forced
|
||||||
* misses that would burn retry backoff for nothing. With NO tileset present
|
* synchronous loads and produces misses that would burn retry backoff for
|
||||||
|
* nothing. With NO tileset present
|
||||||
* (OSM fallback) this returns true so the sample path is not permanently
|
* (OSM fallback) this returns true so the sample path is not permanently
|
||||||
* blocked — the sample just misses and backs off.
|
* blocked — the sample just misses and backs off.
|
||||||
* @param {Cesium.Viewer} viewer
|
* @param {Cesium.Viewer} viewer
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ export function createMeshFloorSampler({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* True when a VISIBLE 3D tileset in the scene reports its streaming queue
|
* True when a VISIBLE 3D tileset in the scene reports its streaming queue
|
||||||
* drained (tilesLoaded) — the mirror of cctv.js's projectionTilesReady.
|
* drained (tilesLoaded) — as CCTV's projectionTilesReady once did (it now
|
||||||
|
* asks the globe port whether its drawn photoreal tiles have settled).
|
||||||
* Walks top-level primitives only (a handful; once per poll).
|
* Walks top-level primitives only (a handful; once per poll).
|
||||||
* @param {Cesium.Scene} scene
|
* @param {Cesium.Scene} scene
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import {
|
|||||||
getSelectedEntityContext,
|
getSelectedEntityContext,
|
||||||
isContextRecordActive,
|
isContextRecordActive,
|
||||||
} from '../data/contextStore.js';
|
} from '../data/contextStore.js';
|
||||||
import { CCTV_FOCUS_RESULT } from '../layers/cctv/index.js';
|
import { CCTV_FOCUS_RESULT } from '../layers/cctv/policy.js';
|
||||||
import {
|
import {
|
||||||
createAnalystEngine,
|
createAnalystEngine,
|
||||||
normalizeAnalystSpec,
|
normalizeAnalystSpec,
|
||||||
|
|||||||
Reference in new issue
Block a user