fix(cctv): retain far-side culling below ellipsoid

This commit is contained in:
brandonabyrd committed 2026-11-18 17:13:06 -06:00
1 parent b1b66e9717
commit 564383e4b5
2 files changed
+52 -28

No files matched your search

+14 -28
View File
@@ -1,5 +1,4 @@
import * as Cesium from 'cesium';
import { horizonOccluder } from '../../data/iconOrientation.js';
import {
FRAME_SIGNATURE_W,
FRAME_SIGNATURE_H,
@@ -45,9 +44,15 @@ export function fitToProjection(sourceW, sourceH) {
const _scratchPoints = [];
const _scratchSphere = new Cesium.BoundingSphere();
const _scratchCartographic = new Cesium.Cartographic();
// Close to the reference ellipsoid, it is not a reliable terrain horizon.
const LOW_VIEWER_HEIGHT_M = 1000;
// Keep the occluding surface below common negative geoid undulations.
const HORIZON_MARGIN_M = 200;
const _radii = Cesium.Ellipsoid.WGS84.radii;
const _horizonEllipsoid = new Cesium.Ellipsoid(
_radii.x - HORIZON_MARGIN_M,
_radii.y - HORIZON_MARGIN_M,
_radii.z - HORIZON_MARGIN_M,
);
const _horizonOccluder = new Cesium.EllipsoidalOccluder(_horizonEllipsoid);
export function createFrames({ state: layerState, services, parts, source }) {
/**
@@ -281,30 +286,11 @@ export function createFrames({ state: layerState, services, parts, source }) {
typeof camera.frustum?.computeCullingVolume !== 'function'
)
return true;
// The reference ellipsoid can lie above the actual street. Near the
// surface its horizon would incorrectly hide nearby below-ellipsoid planes;
// let the frustum alone decide at low altitude or when height is unknown.
const height = Cesium.Cartographic.fromCartesian(
camera.positionWC,
Cesium.Ellipsoid.WGS84,
_scratchCartographic,
)?.height;
const pointsAboveEllipsoid = points.every((point) => {
const h = Cesium.Cartographic.fromCartesian(
point,
Cesium.Ellipsoid.WGS84,
_scratchCartographic,
)?.height;
return Number.isFinite(h) && h >= 0;
});
if (
Number.isFinite(height) &&
height >= LOW_VIEWER_HEIGHT_M &&
pointsAboveEllipsoid
) {
const occluder = horizonOccluder(camera);
if (!points.some((point) => occluder.isPointVisible(point))) return false;
}
// WGS84 can be above the actual street; cull against a surface below it
// instead, while retaining far-side occlusion for low and high viewers.
_horizonOccluder.cameraPosition = camera.positionWC;
if (!points.some((point) => _horizonOccluder.isPointVisible(point)))
return false;
const culling = camera.frustum.computeCullingVolume(
camera.positionWC,
camera.directionWC,
+38
View File
@@ -290,6 +290,44 @@ test('a nearby plane below the ellipsoid still fetches for a low viewer', () =>
);
});
test('the horizon still rejects a negative-height plane on the far side', () => {
for (const altitude of [4, 30000, 2e7]) {
const record = planeRecord();
const mount = point(0, 0, -18);
const cap = point(0.00054, 0, -18);
record.billboard.position = mount;
record.frustumPositions = { mount, capCenter: cap };
const position = point(180, 0, altitude);
const direction = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.subtract(mount, position, new Cesium.Cartesian3()),
new Cesium.Cartesian3(),
);
const viewer = viewerAt(position, direction, Cesium.Cartesian3.UNIT_Z);
const sphere = Cesium.BoundingSphere.fromPoints([mount, cap]);
assert.notEqual(
viewer.camera.frustum
.computeCullingVolume(position, direction, viewer.camera.upWC)
.computeVisibility(sphere),
Cesium.Intersect.OUTSIDE,
);
assert.equal(framesFor(viewer).projectionInView(record), false);
}
});
test('a low viewer can see a plane beyond the WGS84 horizon', () => {
const record = planeRecord();
const mount = point(0, 0, 1);
record.billboard.position = mount;
record.frustumPositions = { mount };
const position = point(0.2, 0, 4);
const direction = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.subtract(mount, position, new Cesium.Cartesian3()),
new Cesium.Cartesian3(),
);
const viewer = viewerAt(position, direction, Cesium.Cartesian3.UNIT_Z);
assert.equal(framesFor(viewer).projectionInView(record), true);
});
test('a plane below the horizon is not fetched', () => {
const far = point(180, 0, 30000);
const viewer = viewerAt(