diff --git a/src/layers/cctv/frames.js b/src/layers/cctv/frames.js index 41c59f0e24..c0a820dd3d 100644 --- a/src/layers/cctv/frames.js +++ b/src/layers/cctv/frames.js @@ -43,6 +43,7 @@ export function fitToProjection(sourceW, sourceH) { } const _scratchPoints = []; +const HORIZON_MARGIN_M = 200; export function createFrames({ state: layerState, services, parts, source }) { /** @@ -267,7 +268,7 @@ export function createFrames({ state: layerState, services, parts, source }) { if (placed?.br) points.push(placed.br); if (placed?.bl) points.push(placed.bl); // Unknown modes or unsupported cameras must not suppress pictures. - return camera.visiblePoints(points, 200) !== false; + return camera.visiblePoints(points, HORIZON_MARGIN_M) !== false; } /** diff --git a/src/render/cesium/camera.js b/src/render/cesium/camera.js index e589de38d6..bcf251224f 100644 --- a/src/render/cesium/camera.js +++ b/src/render/cesium/camera.js @@ -433,7 +433,6 @@ export function createCesiumCamera({ } const cameraPort = { - visiblePoints: createPointsVisibility(scene, camera), on: (event, cb, options) => cameraEvents.on(event, cb, options), onCommand: (cb) => commandHooks.on(cb), setView(spec) { @@ -753,6 +752,8 @@ export function createCesiumCamera({ }); // Cesium keeps the eye in `camera.transform`: a tracked entity's frame, a // `lookAt` target's, or the identity. + if (!capabilities || capabilities.has('pointVisibility')) + cameraPort.visiblePoints = createPointsVisibility(scene, camera); if (!capabilities || capabilities.has('followFrame')) cameraPort.followFrame = () => { if (!lastFollowFrame || !sameMatrix(lastFollowFrame, camera.transform)) diff --git a/src/render/cesium/controlledCamera.test.mjs b/src/render/cesium/controlledCamera.test.mjs index 54945e31a3..e92f74c8da 100644 --- a/src/render/cesium/controlledCamera.test.mjs +++ b/src/render/cesium/controlledCamera.test.mjs @@ -321,6 +321,8 @@ test('the application’s Cesium renderer runs the controller around its preUpda const renderer = await plugin.create({ container: {} }); assert.equal(scene.screenSpaceCameraController.enableInputs, false); assert.equal(typeof renderer.camera.native.setPose, 'function'); + assert.equal(renderer.capabilities.has('pointVisibility'), true); + assert.equal(renderer.camera.visiblePoints([], 200), null); renderer.frame.on('preUpdate', () => order.push('preUpdate')); scene.preUpdate.raise(scene, Cesium.JulianDate.fromDate(new Date(5000))); assert.deepEqual(order, [['before', 5000], 'preUpdate', 'after']); diff --git a/src/render/cesium/ports.js b/src/render/cesium/ports.js index 5f73daa482..ba69cb1991 100644 --- a/src/render/cesium/ports.js +++ b/src/render/cesium/ports.js @@ -13,7 +13,7 @@ * absent, never stubbed. */ import * as Cesium from 'cesium'; -import { createCesiumCamera } from './camera.js'; +import { createCesiumCamera, createPointsVisibility } from './camera.js'; import { createControlledCamera } from './controlledCamera.js'; import { listenerList, toCartesian, uncaught } from './common.js'; import { createCesiumCredits } from './credits.js'; @@ -80,6 +80,7 @@ export function cesiumCapabilities(scene, only) { // Raster shells; other field kinds are refused. 'fields', 'followFrame', + 'pointVisibility', // Cesium's AUTODETECT tracking frame (`follow.js`). 'followAutodetect', 'cameraChangeThreshold', @@ -484,6 +485,8 @@ export function createCesiumPorts( : {}), }); const cameraPort = cameraPart.port; + if (controlled && capabilities.has('pointVisibility')) + cameraPort.visiblePoints = createPointsVisibility(scene, camera); measureCameraChanged = cameraPart.measureChanged ?? null; const effectsPart = createCesiumEffects(scene, { capabilities, diff --git a/src/render/cesium/ports.test.mjs b/src/render/cesium/ports.test.mjs index fc0e40bff2..e7cb9582a2 100644 --- a/src/render/cesium/ports.test.mjs +++ b/src/render/cesium/ports.test.mjs @@ -12,6 +12,7 @@ import { createNativeClick } from './nativeClick.js'; test('capabilities follow what the scene supports', () => { const effects = [ 'followFrame', + 'pointVisibility', 'followAutodetect', 'cameraChangeThreshold', 'columns', diff --git a/src/render/contract/common.d.ts b/src/render/contract/common.d.ts index df585c2484..09b15c4acd 100644 --- a/src/render/contract/common.d.ts +++ b/src/render/contract/common.d.ts @@ -179,6 +179,8 @@ export type Capability = | 'pickPosition' /** Points tested against the frame's depth (`query.occlusionTest`). */ | 'occlusionTest' + /** Conservative camera visibility of a point set (`camera.visiblePoints`). */ + | 'pointVisibility' /** Outward user zooms that keep the Earth framed (`controls.keepEarthFramed`). */ | 'keepEarthFramed' /** Height sampling against tiles and terrain. */ diff --git a/src/render/contract/index.js b/src/render/contract/index.js index 2198b6226c..c18e0e5cb2 100644 --- a/src/render/contract/index.js +++ b/src/render/contract/index.js @@ -48,6 +48,7 @@ export const CAPABILITIES = Object.freeze([ 'followFrame', 'cameraChangeThreshold', 'occlusionTest', + 'pointVisibility', 'keepEarthFramed', ]); @@ -207,6 +208,7 @@ export const PORTS = deepFreeze({ 'matrices', ), ['followFrame', 'followFrame'], + ['visiblePoints', 'pointVisibility'], ['controls.keepEarthFramed', 'keepEarthFramed'], ]), query: Object.fromEntries([ diff --git a/src/render/stub/index.js b/src/render/stub/index.js index 9eb21cfc58..85451d63c3 100644 --- a/src/render/stub/index.js +++ b/src/render/stub/index.js @@ -261,6 +261,8 @@ export function createStubRenderer(options = {}) { camera.setViewRectangle(viewRectangle); if (capabilities.has('followFrame')) camera.port.followFrame = camera.eyeFrame; + if (capabilities.has('pointVisibility')) + camera.port.visiblePoints = () => null; camera.port.setView({ destination: { lon: -97.7431, lat: 30.2672, height: 15000000 }, }); diff --git a/src/render/stub/stub.test.mjs b/src/render/stub/stub.test.mjs index d2da3f359d..04517dd6fe 100644 --- a/src/render/stub/stub.test.mjs +++ b/src/render/stub/stub.test.mjs @@ -40,6 +40,15 @@ test('the stub passes the conformance suite', async () => { ]); }); +test('point visibility capability is optional and the stub reports unknown', () => { + const without = createStubRenderer({ capabilities: [] }); + const withVisibility = createStubRenderer({ + capabilities: ['pointVisibility'], + }); + assert.equal(without.camera.visiblePoints, undefined); + assert.equal(withVisibility.camera.visiblePoints([], 200), null); +}); + test('a frame runs the contract’s steps in order', () => { const r = createStubRenderer(); r.frame.requestRender('test');