mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Draw the ALPR layer's markers through the renderer's ports
The ALPR badges were Cesium entities whose billboards the layer changed in place: the canvas overlay swapped a badge to a faint pick target at its anchor, selection swapped the image, and unresolved floors clamped to the ground. They are now one icon set from the draw port, updated in place through upsert, so selection and the overlay swap change the same billboard without a rebuild or a blink. Badges keep their scale by distance, ground clamping and depth-test settings. Marker state lives in the app (markerState.js): a plain carrier per camera, registered as the camera's context entity, and a marker set that batches changes and sends only the icons that draw differently. Clicks on native badges come from the dispatcher's draw hit. Projection, the on-screen count, height samples (excluding the layer's own set), the screen-centre ellipsoid pick and the camera reach the renderer through the query, camera and frame ports. A resync of the overlay now hands back only the cameras that leave it, so kept ones are not written twice. index.js, overlay.js and presentation.js leave the Cesium allow-list; the layer's entry is Cesium-free, and a caller's own viewer loads the unbound factories. Differences the contract does not let us avoid: - Double-clicking a badge no longer starts the viewer's entity follow, since draw items are not entities. - The terrain fallback for anchors is no longer skipped while the globe is hidden: the globe port has no visibility getter. - Without depth support the query port answers no heights, terrain included, so anchors wait for a cached floor there. - On a viewer with no renderer bound, the surface counts as settled when anchors are refined.
This commit is contained in:
1 parent
faded8a418
commit
2592289612
11 files changed
+722
-537
No files matched your search
@@ -1,14 +1,173 @@
|
||||
/**
|
||||
* @module alpr/markerState
|
||||
* @description The ALPR layer's own per-marker state, held in the app rather than on the
|
||||
* Cesium entities it draws:
|
||||
* @description The ALPR layer's markers: one icon per camera in a draw set,
|
||||
* and the layer's own per-marker state, held in the layer. Each marker is a
|
||||
* plain carrier object (`{ id, show }`) that the layer registers as the
|
||||
* camera's context entity; its state lives in `alprMarkers`:
|
||||
* - `record`: the camera record the marker shows.
|
||||
* - `clamped`: whether the marker sits on the surface rather than at its height.
|
||||
* - `position`, `clamped`: where the badge is drawn natively, and whether it
|
||||
* follows the ground there rather than sitting at its height.
|
||||
* - `selected`: drawn with the selected badge.
|
||||
* - `canvasPosition`, `displayPosition`: the canvas anchor and the position the card reads.
|
||||
* - `wedge`: the direction wedge's positions, plain ECEF.
|
||||
* - `nativeAppearance`, `pickPosition`: the native look saved while the canvas draws it.
|
||||
* - `shown`, `surfaceCheckedFor`: the last visibility applied and the anchor last checked.
|
||||
* - `canvasOwned`: the overlay canvas draws the badge; the icon stays as a
|
||||
* faint pick target at the canvas anchor.
|
||||
* - `shown`, `surfaceCheckedFor`: whether the icon shows and the anchor last checked.
|
||||
*/
|
||||
import { createEntityStore } from '../../data/entityRecords.js';
|
||||
import {
|
||||
MARKER_ICON_SIZE,
|
||||
MARKER_SCALE_BY_DISTANCE,
|
||||
SELECTED_MARKER_ICON_SIZE,
|
||||
} from './policy.js';
|
||||
import { MARKER_IMAGE, SELECTED_IMAGE } from './visuals.js';
|
||||
|
||||
export const alprMarkers = createEntityStore();
|
||||
|
||||
const [NEAR, NEAR_SCALE, FAR, FAR_SCALE] = MARKER_SCALE_BY_DISTANCE;
|
||||
/** City-wide views hold hundreds of badges; they shrink with distance. */
|
||||
const SCALE_BY_DISTANCE = Object.freeze({
|
||||
near: NEAR,
|
||||
nearValue: NEAR_SCALE,
|
||||
far: FAR,
|
||||
farValue: FAR_SCALE,
|
||||
});
|
||||
/** Under the canvas badge: faint, but still picked. */
|
||||
const PICK_TARGET_COLOR = Object.freeze([1, 1, 1, 0.01]);
|
||||
|
||||
/**
|
||||
* Where a marker's icon is drawn: the canvas anchor while the canvas owns
|
||||
* it, else its native position.
|
||||
* @param {{id: string}} carrier
|
||||
* @returns {import('../../render/contract/common').Ecef|null|undefined}
|
||||
*/
|
||||
export function alprIconPosition(carrier) {
|
||||
const marker = alprMarkers.read(carrier);
|
||||
if (!marker) return null;
|
||||
return marker.canvasOwned && marker.canvasPosition
|
||||
? marker.canvasPosition
|
||||
: marker.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* The icon a marker draws now.
|
||||
* @param {{id: string}} carrier
|
||||
* @returns {import('../../render/contract/draw').IconItem}
|
||||
*/
|
||||
export function alprIconItem(carrier) {
|
||||
const marker = alprMarkers.read(carrier) ?? {};
|
||||
const canvas = Boolean(marker.canvasOwned && marker.canvasPosition);
|
||||
const size = marker.selected ? SELECTED_MARKER_ICON_SIZE : MARKER_ICON_SIZE;
|
||||
return {
|
||||
id: carrier.id,
|
||||
pos: canvas ? marker.canvasPosition : marker.position,
|
||||
// Ground clamping is the placeholder until a marker's floor resolves.
|
||||
height: !canvas && marker.clamped ? 'clampGround' : 'absolute',
|
||||
image: marker.selected ? SELECTED_IMAGE : MARKER_IMAGE,
|
||||
size: [size, size],
|
||||
disableDepthTest: Number.POSITIVE_INFINITY,
|
||||
show: marker.shown !== false,
|
||||
...(canvas
|
||||
? { color: PICK_TARGET_COLOR }
|
||||
: { scaleByDistance: SCALE_BY_DISTANCE }),
|
||||
};
|
||||
}
|
||||
|
||||
/** What tells one drawn icon from another, so unchanged ones are not sent again. */
|
||||
function itemKey(item) {
|
||||
const { pos } = item;
|
||||
return [
|
||||
pos?.x,
|
||||
pos?.y,
|
||||
pos?.z,
|
||||
item.height,
|
||||
item.image,
|
||||
item.size[0],
|
||||
item.show,
|
||||
item.color ? 'pick' : 'badge',
|
||||
].join('|');
|
||||
}
|
||||
|
||||
/**
|
||||
* The layer's markers, drawn as one icon set: carriers by camera id, and
|
||||
* the writes to the set, batched until `flush`.
|
||||
* @returns {object}
|
||||
*/
|
||||
export function createAlprMarkerSet() {
|
||||
const carriers = new Map();
|
||||
/** The key of each icon last sent to the set, by id. */
|
||||
const sent = new Map();
|
||||
const dirty = new Set();
|
||||
let icons = null;
|
||||
|
||||
function flush() {
|
||||
if (!icons || !dirty.size) return;
|
||||
const items = [];
|
||||
for (const carrier of dirty) {
|
||||
if (carriers.get(carrier.id) !== carrier) continue;
|
||||
const item = alprIconItem(carrier);
|
||||
if (!item.pos) continue;
|
||||
const key = itemKey(item);
|
||||
if (sent.get(carrier.id) === key) continue;
|
||||
sent.set(carrier.id, key);
|
||||
items.push(item);
|
||||
}
|
||||
dirty.clear();
|
||||
if (items.length) icons.upsert(items);
|
||||
}
|
||||
|
||||
return {
|
||||
/** Draw the markers into `set`, an icon set made for them. */
|
||||
attach(set) {
|
||||
icons = set;
|
||||
},
|
||||
/** The icon set, while attached. */
|
||||
get icons() {
|
||||
return icons;
|
||||
},
|
||||
get size() {
|
||||
return carriers.size;
|
||||
},
|
||||
get(id) {
|
||||
return carriers.get(id) ?? null;
|
||||
},
|
||||
values() {
|
||||
return carriers.values();
|
||||
},
|
||||
/** A new marker for `id`, drawn at the next `flush`. */
|
||||
add(id) {
|
||||
const carrier = { id, show: true };
|
||||
carriers.set(id, carrier);
|
||||
dirty.add(carrier);
|
||||
return carrier;
|
||||
},
|
||||
/** Remove the markers with these ids now. */
|
||||
remove(ids) {
|
||||
const gone = [];
|
||||
for (const id of ids) {
|
||||
if (!carriers.delete(id)) continue;
|
||||
sent.delete(id);
|
||||
gone.push(id);
|
||||
}
|
||||
if (gone.length) icons?.remove(gone);
|
||||
},
|
||||
/** Redraw `carrier` at the next `flush`, if how it draws changed. */
|
||||
changed(carrier) {
|
||||
if (carrier) dirty.add(carrier);
|
||||
},
|
||||
flush,
|
||||
clear() {
|
||||
carriers.clear();
|
||||
sent.clear();
|
||||
dirty.clear();
|
||||
icons?.clear();
|
||||
},
|
||||
dispose() {
|
||||
carriers.clear();
|
||||
sent.clear();
|
||||
dirty.clear();
|
||||
icons?.dispose();
|
||||
icons = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user