mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +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
@@ -2,7 +2,7 @@
|
||||
// Icon colors under focus de-emphasis (#1200): the focus pass fades each icon
|
||||
// from the same base color the coverage refresh assigns, so a video-feed camera
|
||||
// stays violet while it dims instead of falling back to the idle cyan.
|
||||
// Teardown takes the icons out of the scene that holds them.
|
||||
// Teardown lets go of the icon set of the viewer that drew it.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRendering } from './rendering.js';
|
||||
@@ -13,86 +13,103 @@ import {
|
||||
} from './policy.js';
|
||||
import { isVideoFeedType } from '../../sources/cctvTypes.js';
|
||||
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';
|
||||
|
||||
const FOCUS_FACTOR = 0.5;
|
||||
|
||||
function assertKeepsColor(icons, id, base, label) {
|
||||
const row = icons.row(id);
|
||||
const actual = icons.color(row);
|
||||
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`);
|
||||
assert.deepEqual(icons.item(id).color, base, `${label}: base color kept`);
|
||||
assert.equal(icons.focus(id), FOCUS_FACTOR, `${label}: focus`);
|
||||
}
|
||||
|
||||
test('focus de-emphasis fades each icon from its own color', () => {
|
||||
const record = (id, feedType) => ({
|
||||
camera: { id, feedType },
|
||||
// No position, so the pass skips screen projection; the focus stub below
|
||||
// decides the factor on its own.
|
||||
position: { x: 6378137, y: 0, z: 0 },
|
||||
});
|
||||
const idleVideo = record('idle-hls', 'hls');
|
||||
const idleStill = record('idle-image', 'image');
|
||||
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 = {
|
||||
_enabled: true,
|
||||
_viewer: { scene: {}, camera: {} },
|
||||
_viewer: viewer,
|
||||
_records: [idleVideo, idleStill, activeVideo],
|
||||
_activeCameraId: activeVideo.camera.id,
|
||||
_activeFocusStyleCount: 0,
|
||||
_lastFocusStyleAt: -Infinity,
|
||||
_icons: createIconSet(),
|
||||
};
|
||||
const distances = [];
|
||||
const focus = {
|
||||
focusNowMs: (nowMs) => nowMs,
|
||||
getFocusTarget: () => ({}),
|
||||
focusPassIsNeeded: () => true,
|
||||
advanceSpriteFocus: () => ({
|
||||
factor: FOCUS_FACTOR,
|
||||
active: true,
|
||||
transitioning: false,
|
||||
}),
|
||||
advanceSpriteFocus: (meta, input) => {
|
||||
distances.push(input.cameraDistance);
|
||||
return { factor: FOCUS_FACTOR, active: true, transitioning: false };
|
||||
},
|
||||
focusAlphaNeedsWrite: () => true,
|
||||
};
|
||||
const { addCameraIcon, refreshCctvFocusStyles } = createRendering({
|
||||
state,
|
||||
services: { focus },
|
||||
parts: { model: { isVideoFeedType } },
|
||||
source: {},
|
||||
});
|
||||
for (const r of state._records) addCameraIcon(r);
|
||||
const { createCameraIcons, addCameraIcon, refreshCctvFocusStyles } =
|
||||
createRendering({
|
||||
state,
|
||||
services: { focus },
|
||||
parts: { model: { isVideoFeedType } },
|
||||
source: {},
|
||||
});
|
||||
try {
|
||||
const setId = createCameraIcons(viewer);
|
||||
for (const r of state._records) addCameraIcon(r);
|
||||
|
||||
refreshCctvFocusStyles(1000);
|
||||
refreshCctvFocusStyles(1000);
|
||||
|
||||
const icons = state._icons;
|
||||
assertKeepsColor(icons, 'idle-hls', LIVE_CAMERA_COLOR, 'idle video');
|
||||
assertKeepsColor(icons, 'idle-image', IDLE_CAMERA_COLOR, 'idle still');
|
||||
assertKeepsColor(icons, 'active-hls', ACTIVE_CAMERA_COLOR, 'active video');
|
||||
assert.equal(state._activeFocusStyleCount, 3);
|
||||
const icons = state._icons;
|
||||
assertKeepsColor(icons, 'idle-hls', LIVE_CAMERA_COLOR, 'idle video');
|
||||
assertKeepsColor(icons, 'idle-image', IDLE_CAMERA_COLOR, 'idle still');
|
||||
assertKeepsColor(icons, 'active-hls', ACTIVE_CAMERA_COLOR, 'active video');
|
||||
assert.equal(state._activeFocusStyleCount, 3);
|
||||
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', () => {
|
||||
const viewer = () => {
|
||||
const held = new Set();
|
||||
return {
|
||||
held,
|
||||
scene: {
|
||||
requestRender() {},
|
||||
primitives: {
|
||||
add: (p) => held.add(p),
|
||||
remove: (p) => held.delete(p),
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
const first = viewer();
|
||||
const second = viewer();
|
||||
test('the icons go with the viewer that drew them, whichever tears down', () => {
|
||||
const first = {};
|
||||
const second = {};
|
||||
const one = bindFakeDraw(first);
|
||||
const two = bindFakeDraw(second);
|
||||
const state = { _viewer: first };
|
||||
const { createCameraIcons, destroyCameraIcons } = createRendering({
|
||||
state,
|
||||
@@ -100,17 +117,21 @@ test('icons leave the scene they were added to, whichever viewer tears down', ()
|
||||
parts: {},
|
||||
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);
|
||||
state._viewer = second;
|
||||
const current = createCameraIcons(second);
|
||||
assert.equal(first.held.has(old), false, 'a re-init takes out the old icons');
|
||||
assert.equal(old.isDestroyed(), true);
|
||||
|
||||
destroyCameraIcons();
|
||||
assert.equal(second.held.has(current), false);
|
||||
assert.equal(current.isDestroyed(), true);
|
||||
assert.equal(state._icons, null);
|
||||
destroyCameraIcons();
|
||||
assert.equal(two.draw.sets.get(current).disposed, true);
|
||||
assert.equal(state._icons, null);
|
||||
} finally {
|
||||
one.unbind();
|
||||
two.unbind();
|
||||
}
|
||||
});
|
||||
|
||||
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 front = Cesium.Cartesian3.fromDegrees(0, 0);
|
||||
const back = Cesium.Cartesian3.fromDegrees(180, 0);
|
||||
const state = {
|
||||
_viewer: {
|
||||
camera: { positionWC: eye },
|
||||
scene: {
|
||||
canvas: { clientWidth: 800, clientHeight: 0, height: 600 },
|
||||
cartesianToCanvasCoordinates: () => ({ x: 10, y: 20 }),
|
||||
},
|
||||
const viewer = {};
|
||||
const camera = fakeCameraPort({
|
||||
pose: { position: { x: eye.x, y: eye.y, z: eye.z } },
|
||||
});
|
||||
const unbind = bindRenderer(viewer, {
|
||||
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({
|
||||
state,
|
||||
});
|
||||
try {
|
||||
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: {} },
|
||||
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);
|
||||
});
|
||||
assert.equal(bare.projectionTilesReady(), false, 'no globe, no tiles');
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user