From 564383e4b53f8944b183154b28430bb992ad637d Mon Sep 17 00:00:00 2001 From: brandonabyrd Date: Mon, 9 Nov 2026 06:35:22 -0600 Subject: [PATCH] fix(cctv): retain far-side culling below ellipsoid --- src/layers/cctv/frames.js | 42 +++++++++++---------------------- src/layers/cctv/frames.test.mjs | 38 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/src/layers/cctv/frames.js b/src/layers/cctv/frames.js index 7040d242ed..95ef0a9794 100644 --- a/src/layers/cctv/frames.js +++ b/src/layers/cctv/frames.js @@ -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, diff --git a/src/layers/cctv/frames.test.mjs b/src/layers/cctv/frames.test.mjs index c297311af4..d12bd401fb 100644 --- a/src/layers/cctv/frames.test.mjs +++ b/src/layers/cctv/frames.test.mjs @@ -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(