mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Draw CCTV coverage, viewsheds and the monitor plane through the renderer ports and take projection.js off the Cesium list
The frustum wireframes, viewshed volumes and the active camera's monitor plane are now line, mesh and quad items of the layer's own draw sets (layers/cctv/drawSets.js), written from plain handles only as they change. The plane takes its canvas double buffer or its video as a quad source. Picks of lines and planes are matched by set, item id and the record that draws them. The activation obstruction probe casts through the query port's rayCast; its clamp lands a microtask later, rewrites the geometry and asks again for the footprint ground, and a newer activation, a range edit, a deactivation or a re-init drops an answer still to come.
This commit is contained in:
1 parent
bbad02b73e
commit
2a607ec4d8
20 files changed
+918
-492
No files matched your search
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* @module layers/cctv/drawSets
|
||||
* @description The CCTV layer's draw sets: the frustum wireframes
|
||||
* (`coverage`, lines), the viewshed volumes (`viewshed`, meshes) and the
|
||||
* active camera's monitor plane (`plane`, a quad), made through the draw
|
||||
* port of the viewer the layer is on. They are made when first drawn into
|
||||
* and made again on another viewer. Item ids keep the layer's
|
||||
* `cctv-<cameraId>-<role>` scheme the shared pick registry reads, and each
|
||||
* line's and plane's `meta.cameraId` names its camera (volumes are never
|
||||
* picked and carry none).
|
||||
*
|
||||
* Coverage lines and the plane are written from handles the layer keeps
|
||||
* (a record's `coverageEntities`, a projection runtime's `plane`): plain
|
||||
* objects the layer changes and then writes, only what changed reaching
|
||||
* the set.
|
||||
*/
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
|
||||
/** Layer instances, for set ids unique to each. */
|
||||
let instances = 0;
|
||||
|
||||
/** A line handle's item, or null for a handle that names no line yet. */
|
||||
function lineItemOf(handle) {
|
||||
if (!handle?.id || !Array.isArray(handle.positions)) return null;
|
||||
const color = handle.color;
|
||||
return {
|
||||
id: handle.id,
|
||||
positions: handle.positions,
|
||||
widthPx: handle.widthPx,
|
||||
// As a polyline entity runs: along the ellipsoid between its positions.
|
||||
mode: 'geodesic',
|
||||
style: handle.dashed
|
||||
? { kind: 'dash', color, length: 16, pattern16: 255 }
|
||||
: { kind: 'solid', color },
|
||||
depthFailColor: handle.depthFailColor ?? null,
|
||||
meta: { cameraId: handle.cameraId },
|
||||
show: handle.show !== false,
|
||||
};
|
||||
}
|
||||
|
||||
/** What a line item draws, as a key: an unchanged key is not written. */
|
||||
const lineKey = (item) =>
|
||||
[
|
||||
item.positions.map((p) => `${p.x},${p.y},${p.z}`).join(';'),
|
||||
item.widthPx,
|
||||
item.style.kind,
|
||||
item.style.color.join(','),
|
||||
item.depthFailColor ? item.depthFailColor.join(',') : '',
|
||||
item.show,
|
||||
].join('|');
|
||||
|
||||
/** The plane handle's quad item. */
|
||||
function quadItemOf(plane) {
|
||||
return {
|
||||
id: plane.id,
|
||||
center: plane.center,
|
||||
orientation: plane.orientation,
|
||||
size: plane.size,
|
||||
source: plane.source,
|
||||
alpha: plane.alpha,
|
||||
outline: plane.outline,
|
||||
meta: { cameraId: plane.cameraId },
|
||||
show: plane.show === true,
|
||||
};
|
||||
}
|
||||
|
||||
export function createDrawSets({ state: layerState }) {
|
||||
/** The live sets and the viewer they draw on, or null. */
|
||||
let current = null;
|
||||
/** Viewshed volumes written, ever (the QA harness checks for churn). */
|
||||
let volumeWrites = 0;
|
||||
|
||||
/** The layer's sets on its viewer now, made if need be; null with none. */
|
||||
function sets() {
|
||||
const viewer = layerState._viewer;
|
||||
if (!viewer) return null;
|
||||
if (current?.viewer === viewer) return current;
|
||||
dispose();
|
||||
const draw = drawOf(viewer);
|
||||
const n = ++instances;
|
||||
current = {
|
||||
viewer,
|
||||
coverage: draw.lines({ id: `cctv:${n}:coverage` }),
|
||||
viewshed: draw.meshes({ id: `cctv:${n}:viewshed`, pickable: false }),
|
||||
plane: draw.quads({ id: `cctv:${n}:plane` }),
|
||||
// What each line item was last written as, by id.
|
||||
lineKeys: new Map(),
|
||||
};
|
||||
return current;
|
||||
}
|
||||
|
||||
/** The live sets, without making them. */
|
||||
const live = () =>
|
||||
current && current.viewer === layerState._viewer ? current : null;
|
||||
|
||||
/** Let the sets go (the layer leaves its viewer, or moves to another). */
|
||||
function dispose() {
|
||||
if (!current) return;
|
||||
for (const set of [current.coverage, current.viewshed, current.plane])
|
||||
try {
|
||||
set.dispose();
|
||||
} catch {
|
||||
// Its viewer went first.
|
||||
}
|
||||
current = null;
|
||||
}
|
||||
|
||||
/** The ids of the sets that draw the layer's lines and plane. */
|
||||
function pickableSetIds() {
|
||||
const s = live();
|
||||
return s ? [s.coverage.id, s.plane.id] : [];
|
||||
}
|
||||
|
||||
/** Which of the layer's sets a set id is: 'coverage', 'plane' or null. */
|
||||
function roleOfSet(setId) {
|
||||
const s = live();
|
||||
if (!s) return null;
|
||||
if (setId === s.coverage.id) return 'coverage';
|
||||
if (setId === s.plane.id) return 'plane';
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Write line handles that changed since they were last written. */
|
||||
function writeLines(handles) {
|
||||
if (!handles?.length) return;
|
||||
const s = handles.some((h) => h?.id) ? sets() : null;
|
||||
if (!s) return;
|
||||
const changed = [];
|
||||
for (const handle of handles) {
|
||||
const item = lineItemOf(handle);
|
||||
if (!item) continue;
|
||||
const key = lineKey(item);
|
||||
if (s.lineKeys.get(item.id) === key) continue;
|
||||
s.lineKeys.set(item.id, key);
|
||||
changed.push(item);
|
||||
}
|
||||
if (changed.length) s.coverage.upsert(changed);
|
||||
}
|
||||
|
||||
/** Take every line out. */
|
||||
function clearLines() {
|
||||
const s = live();
|
||||
if (!s) return;
|
||||
s.coverage.clear();
|
||||
s.lineKeys.clear();
|
||||
}
|
||||
|
||||
/** Write the plane handle as it is now. */
|
||||
function writePlane(plane) {
|
||||
if (!plane?.id) return;
|
||||
sets()?.plane.upsert([quadItemOf(plane)]);
|
||||
}
|
||||
|
||||
/** Take a plane out. */
|
||||
function removePlane(plane) {
|
||||
if (plane?.id) live()?.plane.remove([plane.id]);
|
||||
}
|
||||
|
||||
/** Write a viewshed volume. */
|
||||
function writeVolume(item) {
|
||||
const s = sets();
|
||||
if (!s) return;
|
||||
s.viewshed.upsert([item]);
|
||||
volumeWrites += 1;
|
||||
}
|
||||
|
||||
/** Take a viewshed volume out. */
|
||||
function removeVolume(id) {
|
||||
if (id) live()?.viewshed.remove([id]);
|
||||
}
|
||||
|
||||
/** How many viewshed volumes were written, for the QA harness. */
|
||||
const volumeWritesForTest = () => volumeWrites;
|
||||
|
||||
return {
|
||||
sets,
|
||||
dispose,
|
||||
pickableSetIds,
|
||||
roleOfSet,
|
||||
writeLines,
|
||||
clearLines,
|
||||
writePlane,
|
||||
removePlane,
|
||||
writeVolume,
|
||||
removeVolume,
|
||||
volumeWritesForTest,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user