mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Draw CCTV lines on a renderer without meshes or quads
Meshes and quads are capabilities, so the CCTV layer asks for its viewshed and plane sets only where the renderer has them and draws the rest of its items without them.
This commit is contained in:
1 parent
3bca55831f
commit
94138d9698
2 files changed
+39
-9
No files matched your search
@@ -13,6 +13,9 @@
|
|||||||
* (a record's `coverageEntities`, a projection runtime's `plane`): plain
|
* (a record's `coverageEntities`, a projection runtime's `plane`): plain
|
||||||
* objects the layer changes and then writes, only what changed reaching
|
* objects the layer changes and then writes, only what changed reaching
|
||||||
* the set.
|
* the set.
|
||||||
|
*
|
||||||
|
* Meshes and quads are capabilities: on a renderer without them there are
|
||||||
|
* no viewshed volumes or monitor plane, and the lines still draw.
|
||||||
*/
|
*/
|
||||||
import { drawOf } from '../../render/rendererOf.js';
|
import { drawOf } from '../../render/rendererOf.js';
|
||||||
|
|
||||||
@@ -83,8 +86,9 @@ export function createDrawSets({ state: layerState }) {
|
|||||||
current = {
|
current = {
|
||||||
viewer,
|
viewer,
|
||||||
coverage: draw.lines({ id: `cctv:${n}:coverage` }),
|
coverage: draw.lines({ id: `cctv:${n}:coverage` }),
|
||||||
viewshed: draw.meshes({ id: `cctv:${n}:viewshed`, pickable: false }),
|
viewshed:
|
||||||
plane: draw.quads({ id: `cctv:${n}:plane` }),
|
draw.meshes?.({ id: `cctv:${n}:viewshed`, pickable: false }) ?? null,
|
||||||
|
plane: draw.quads?.({ id: `cctv:${n}:plane` }) ?? null,
|
||||||
// What each line item was last written as, by id.
|
// What each line item was last written as, by id.
|
||||||
lineKeys: new Map(),
|
lineKeys: new Map(),
|
||||||
};
|
};
|
||||||
@@ -100,7 +104,7 @@ export function createDrawSets({ state: layerState }) {
|
|||||||
if (!current) return;
|
if (!current) return;
|
||||||
for (const set of [current.coverage, current.viewshed, current.plane])
|
for (const set of [current.coverage, current.viewshed, current.plane])
|
||||||
try {
|
try {
|
||||||
set.dispose();
|
set?.dispose();
|
||||||
} catch {
|
} catch {
|
||||||
// Its viewer went first.
|
// Its viewer went first.
|
||||||
}
|
}
|
||||||
@@ -110,7 +114,8 @@ export function createDrawSets({ state: layerState }) {
|
|||||||
/** The ids of the sets that draw the layer's lines and plane. */
|
/** The ids of the sets that draw the layer's lines and plane. */
|
||||||
function pickableSetIds() {
|
function pickableSetIds() {
|
||||||
const s = live();
|
const s = live();
|
||||||
return s ? [s.coverage.id, s.plane.id] : [];
|
if (!s) return [];
|
||||||
|
return s.plane ? [s.coverage.id, s.plane.id] : [s.coverage.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Which of the layer's sets a set id is: 'coverage', 'plane' or null. */
|
/** Which of the layer's sets a set id is: 'coverage', 'plane' or null. */
|
||||||
@@ -118,7 +123,7 @@ export function createDrawSets({ state: layerState }) {
|
|||||||
const s = live();
|
const s = live();
|
||||||
if (!s) return null;
|
if (!s) return null;
|
||||||
if (setId === s.coverage.id) return 'coverage';
|
if (setId === s.coverage.id) return 'coverage';
|
||||||
if (setId === s.plane.id) return 'plane';
|
if (setId === s.plane?.id) return 'plane';
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,25 +155,25 @@ export function createDrawSets({ state: layerState }) {
|
|||||||
/** Write the plane handle as it is now. */
|
/** Write the plane handle as it is now. */
|
||||||
function writePlane(plane) {
|
function writePlane(plane) {
|
||||||
if (!plane?.id) return;
|
if (!plane?.id) return;
|
||||||
sets()?.plane.upsert([quadItemOf(plane)]);
|
sets()?.plane?.upsert([quadItemOf(plane)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Take a plane out. */
|
/** Take a plane out. */
|
||||||
function removePlane(plane) {
|
function removePlane(plane) {
|
||||||
if (plane?.id) live()?.plane.remove([plane.id]);
|
if (plane?.id) live()?.plane?.remove([plane.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Write a viewshed volume. */
|
/** Write a viewshed volume. */
|
||||||
function writeVolume(item) {
|
function writeVolume(item) {
|
||||||
const s = sets();
|
const s = sets();
|
||||||
if (!s) return;
|
if (!s?.viewshed) return;
|
||||||
s.viewshed.upsert([item]);
|
s.viewshed.upsert([item]);
|
||||||
volumeWrites += 1;
|
volumeWrites += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Take a viewshed volume out. */
|
/** Take a viewshed volume out. */
|
||||||
function removeVolume(id) {
|
function removeVolume(id) {
|
||||||
if (id) live()?.viewshed.remove([id]);
|
if (id) live()?.viewshed?.remove([id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** How many viewshed volumes were written, for the QA harness. */
|
/** How many viewshed volumes were written, for the QA harness. */
|
||||||
|
|||||||
@@ -108,3 +108,28 @@ test('another viewer gets sets of its own; dispose lets them go', () => {
|
|||||||
two.unbind();
|
two.unbind();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a renderer without meshes or quads still draws the lines', () => {
|
||||||
|
const viewer = {};
|
||||||
|
const { draw, unbind } = bindFakeDraw(viewer);
|
||||||
|
delete draw.meshes;
|
||||||
|
delete draw.quads;
|
||||||
|
const drawSets = createDrawSets({ state: { _viewer: viewer } });
|
||||||
|
try {
|
||||||
|
drawSets.writeLines([line('cctv-cam-ray-tl')]);
|
||||||
|
const coverage = draw.find('cctv:');
|
||||||
|
assert.equal(coverage.items.size, 1);
|
||||||
|
// No viewshed volumes and no monitor plane: their writes do nothing.
|
||||||
|
drawSets.writeVolume({ id: 'cctv-cam-viewshed' });
|
||||||
|
drawSets.removeVolume('cctv-cam-viewshed');
|
||||||
|
const plane = { id: 'cctv-cam-plane', cameraId: 'cam', show: true };
|
||||||
|
drawSets.writePlane(plane);
|
||||||
|
drawSets.removePlane(plane);
|
||||||
|
assert.equal(drawSets.volumeWritesForTest(), 0);
|
||||||
|
assert.deepEqual(drawSets.pickableSetIds(), [coverage.spec.id]);
|
||||||
|
assert.equal(drawSets.roleOfSet(coverage.spec.id), 'coverage');
|
||||||
|
drawSets.dispose();
|
||||||
|
} finally {
|
||||||
|
unbind();
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in new issue
Block a user