refactor(cctv): isolate native rendering resources

Keep shared CCTV logic independent of Cesium, release the original renderer's resources, and guard retired initialization/media work. Preserve native marker, plane, volume, calibration and input behavior.

Record keyless dev/preview validation and retain unresolved shell idle/terrain and photoreal acceptance gaps. Routine QA builds use empty Google and Cesium credentials and block paid maps before navigation.
This commit is contained in:
German Khokhlov committed 2026-10-29 00:06:22 +04:00
1 parent f72bf6a774
commit 93c71ffc86
32 files changed
+1536 -740

No files matched your search

+35 -55
View File
@@ -6,17 +6,17 @@
*
* Two responsibilities, both pure of layer state:
* - Color identity: a stable per-camera hue (golden-angle spaced over the
* id-sorted catalog index) and the derived fill/line Cesium colors.
* - Volume geometry: a translucent frustum pyramid primitive built FROM the
* id-sorted catalog index) and the derived fill/line RGBA colors.
* - Volume geometry: frustum pyramid buffers built FROM the
* exact frustumCartesians positions the wireframe uses — welded by
* construction, never recomputed independently. 5 vertices, 6 triangles,
* synchronous build (trivially small), no picking.
* construction, never recomputed independently. 5 vertices, 6 triangles.
* The renderer owns primitive creation and picking policy.
*
* Nothing here queries the scene or persists anything: colors are
* presentation-only and volumes are rebuilt only at the moments the frustum
* wireframe already rewrites (pose edits / visible-set changes).
*/
import * as Cesium from 'cesium';
import { Rgba } from '../layers/shared/color.js';
/** Golden angle in degrees — maximally spreads consecutive indices around the hue wheel. */
const GOLDEN_ANGLE_DEG = 137.50776405003785;
@@ -39,19 +39,42 @@ export function cameraHue(index) {
return (i * GOLDEN_ANGLE_DEG) % 360;
}
// The same HSL arithmetic as the native reference, including operation order.
function viewshedHsl(hue, saturation, lightness, alpha) {
const high =
lightness < 0.5
? lightness * (1 + saturation)
: lightness + saturation - lightness * saturation;
const low = 2 * lightness - high;
const channel = (h) => {
if (h < 0) h += 1;
if (h > 1) h -= 1;
if (h * 6 < 1) return low + (high - low) * 6 * h;
if (h * 2 < 1) return high;
if (h * 3 < 2) return low + (high - low) * (2 / 3 - h) * 6;
return low;
};
return new Rgba(
channel(hue + 1 / 3),
channel(hue),
channel(hue - 1 / 3),
alpha,
);
}
/**
* Derived viewshed colors for a hue: translucent volume fills (idle/active)
* and wireframe line tints (idle/active), all in the same hue family.
* @param {number} hueDeg - Hue in degrees.
* @returns {{fill: Cesium.Color, fillActive: Cesium.Color, line: Cesium.Color, lineActive: Cesium.Color}}
* @returns {{fill: Rgba, fillActive: Rgba, line: Rgba, lineActive: Rgba}}
*/
export function viewshedColors(hueDeg) {
const hue = (((Number(hueDeg) % 360) + 360) % 360) / 360;
return {
fill: Cesium.Color.fromHsl(hue, 0.85, 0.6, FILL_ALPHA_IDLE),
fillActive: Cesium.Color.fromHsl(hue, 0.85, 0.6, FILL_ALPHA_ACTIVE),
line: Cesium.Color.fromHsl(hue, 0.9, 0.65, LINE_ALPHA_IDLE),
lineActive: Cesium.Color.fromHsl(hue, 0.9, 0.7, LINE_ALPHA_ACTIVE),
fill: viewshedHsl(hue, 0.85, 0.6, FILL_ALPHA_IDLE),
fillActive: viewshedHsl(hue, 0.85, 0.6, FILL_ALPHA_ACTIVE),
line: viewshedHsl(hue, 0.9, 0.65, LINE_ALPHA_IDLE),
lineActive: viewshedHsl(hue, 0.9, 0.7, LINE_ALPHA_ACTIVE),
};
}
@@ -61,8 +84,8 @@ export function viewshedColors(hueDeg) {
* the apex + the far cap split into 2 triangles. Pure — this is the ONLY
* geometry definition (weld-by-construction with the wireframe, which draws
* its rays/cap from the same 5 Cartesians).
* @param {{mount: Cesium.Cartesian3, tl: Cesium.Cartesian3, tr: Cesium.Cartesian3,
* br: Cesium.Cartesian3, bl: Cesium.Cartesian3}} positions - frustumCartesians shape.
* @param {{mount: Object, tl: Object, tr: Object,
* br: Object, bl: Object}} positions - ECEF frustumCartesians shape.
* @returns {{positions: Float64Array, indices: Uint16Array}}
*/
export function frustumVolumeGeometryData(positions) {
@@ -85,46 +108,3 @@ export function frustumVolumeGeometryData(positions) {
]);
return { positions: flat, indices };
}
/**
* Builds the translucent frustum-volume primitive for one camera.
* Synchronous (6 triangles — cheaper than the async geometry pipeline's
* bookkeeping), unlit flat color, both faces visible (the viewer is routinely
* inside or behind a cone), never pickable (clicks fall through to the
* billboard/wireframe/plane, whose pick semantics are established).
* @param {Object} positions - frustumCartesians shape (see frustumVolumeGeometryData).
* @param {Cesium.Color} color - Per-camera fill color (already alpha'd).
* @returns {Cesium.Primitive}
*/
export function createFrustumVolumePrimitive(positions, color) {
const { positions: flat, indices } = frustumVolumeGeometryData(positions);
const geometry = new Cesium.Geometry({
attributes: {
position: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.DOUBLE,
componentsPerAttribute: 3,
values: flat,
}),
},
indices,
primitiveType: Cesium.PrimitiveType.TRIANGLES,
boundingSphere: Cesium.BoundingSphere.fromVertices(Array.from(flat)),
});
return new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(color),
},
}),
appearance: new Cesium.PerInstanceColorAppearance({
flat: true,
translucent: true,
renderState: {
cull: { enabled: false },
},
}),
asynchronous: false,
allowPicking: false,
});
}