From d0ca4603135efb4f9a739f78541f31c0fd1aac5f Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sun, 8 Nov 2026 05:56:09 -0800 Subject: [PATCH] Publish the tracked satellite's focus through the renderer ports The satellites layer publishes its focus rectangle with publishFocusTargetAt, projecting its cached position through the query port and measuring from the camera port's pose, as flights and military already do. The scene-taking publishFocusTargetFromCachedPosition and the unused advanceProjectedSpriteFocus go, and focusDeemphasis.js leaves the Cesium allow-list. The rectangle is the same; the target's frameNumber, which nothing reads, is now -1 as the other layers publish it. --- src/data/focusDeemphasis.js | 126 +-------------------------- src/layers/satellites/rendering.js | 8 +- src/layers/satellites/stale.test.mjs | 2 +- src/render/cesiumAllowList.json | 1 - 4 files changed, 6 insertions(+), 131 deletions(-) diff --git a/src/data/focusDeemphasis.js b/src/data/focusDeemphasis.js index a02323799..59ebfd87f 100644 --- a/src/data/focusDeemphasis.js +++ b/src/data/focusDeemphasis.js @@ -1,4 +1,3 @@ -import * as Cesium from 'cesium'; import { findCamera, findQuery } from '../render/rendererOf.js'; /** @@ -31,7 +30,6 @@ export const DEFAULT_FOCUS_DEEMPHASIS_PARAMS = Object.freeze({ let _params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS }; let _focusTarget = null; const _spriteStates = new WeakMap(); -const _scratchScreen = new Cesium.Cartesian2(); const _advanceResult = { factor: 1, changed: false, @@ -173,71 +171,15 @@ export function resetFocusDeemphasisParams() { /** * Publish a focus target from the exact world position already cached by its - * tracking/render path. Callers must never re-derive a position here: a second + * tracking/render path, through the renderer bound to `viewer`: its query + * port projects the position and its camera's pose gives the distance. + * Callers must never re-derive a position here: a second * propagation/dead-reckoning sample at a different frame phase recreates the * tracked-target jitter class this service is designed to avoid. * * @param {object} input * @param {string} input.ownerLayer * @param {string|number} input.id - * @param {Cesium.Scene} input.scene - * @param {Cesium.Camera} input.camera - * @param {Cesium.Cartesian3} input.displayPosition Cached display position. - * @param {number} [input.widthPx=24] Projected visual width before padding. - * @param {number} [input.heightPx=24] Projected visual height before padding. - * @param {Partial} [input.params] - * @returns {object|null} Published target, or null when it cannot be projected. - */ -export function publishFocusTargetFromCachedPosition({ - ownerLayer, - id, - scene, - camera, - displayPosition, - widthPx = 24, - heightPx = 24, - params, -}) { - if ( - !ownerLayer || - id === null || - id === undefined || - !scene || - !camera || - !displayPosition - ) { - clearFocusTarget(ownerLayer, id); - return null; - } - const screen = Cesium.SceneTransforms.worldToWindowCoordinates( - scene, - displayPosition, - _scratchScreen, - ); - return publishFocusRect({ - ownerLayer, - id, - screen, - cameraDistance: Cesium.Cartesian3.distance( - camera.positionWC, - displayPosition, - ), - frameNumber: scene.frameState?.frameNumber ?? -1, - widthPx, - heightPx, - params, - }); -} - -/** - * `publishFocusTargetFromCachedPosition` through the renderer bound to - * `viewer`: its query port projects the cached position and its camera's - * pose gives the distance. Same contract: the position must be the one the - * tracking/render path already cached this frame. - * - * @param {object} input - * @param {string} input.ownerLayer - * @param {string|number} input.id * @param {object} input.viewer The host the renderer is bound to. * @param {{x: number, y: number, z: number}} input.displayPosition Cached display position. * @param {number} [input.widthPx=24] @@ -523,68 +465,6 @@ export function advanceSpriteFocus( return _advanceResult; } -/** - * Project and advance one world-anchored sprite using an owning layer's - * existing render pass. - * @param {object} sprite Stable primitive identity. - * @param {Cesium.Cartesian3} position Current cached/rendered world position. - * @param {Cesium.Scene} scene - * @param {Cesium.Camera} camera - * @param {number} nowMs - * @param {object|null} [target] - * @param {Partial} [params] - * @param {number} [spriteHalfWidthPx=0] - * @param {number} [spriteHalfHeightPx=spriteHalfWidthPx] - * @returns {{factor:number, changed:boolean, transitioning:boolean,active:boolean,desired:number}} - */ -export function advanceProjectedSpriteFocus( - sprite, - position, - scene, - camera, - nowMs, - target = _focusTarget, - params, - spriteHalfWidthPx = 0, - spriteHalfHeightPx = spriteHalfWidthPx, -) { - // Common case: nothing tracked and this sprite holds no dimming state — - // advanceSpriteFocus would return identity without reading the projection, - // so skip the worldToWindowCoordinates round trip entirely (it was N - // wasted projections per fleet tick with nothing tracked). Sprites still - // relaxing keep their state entry until fully settled (see the delete at - // the transition tail), so they keep projecting until done. (perf item 8) - if (!target && !_spriteStates.has(sprite)) { - _advanceResult.factor = 1; - _advanceResult.changed = false; - _advanceResult.transitioning = false; - _advanceResult.active = false; - _advanceResult.desired = 1; - return _advanceResult; - } - const screen = - position && scene - ? Cesium.SceneTransforms.worldToWindowCoordinates( - scene, - position, - _scratchScreen, - ) - : null; - const cameraDistance = - position && camera?.positionWC - ? Cesium.Cartesian3.distance(camera.positionWC, position) - : Number.NaN; - return advanceSpriteFocus(sprite, { - screenPosition: screen, - cameraDistance, - nowMs, - target, - params, - spriteHalfWidthPx, - spriteHalfHeightPx, - }); -} - /** * A gated consumer must keep ticking until every previously dimmed sprite has * returned to identity, even when no target remains. diff --git a/src/layers/satellites/rendering.js b/src/layers/satellites/rendering.js index b51399f0e..93323635e 100644 --- a/src/layers/satellites/rendering.js +++ b/src/layers/satellites/rendering.js @@ -48,7 +48,7 @@ export function createRendering({ nearFarScalarValueAtDistance, advanceSpriteFocus, focusAlphaNeedsWrite, - publishFocusTargetFromCachedPosition, + publishFocusTargetAt, } = services.focus; const scratchFocusScreen = new Cesium.Cartesian2(); @@ -252,11 +252,7 @@ export function createRendering({ /** Publish the tracked satellite's focus rectangle from its cached position. */ function _publishTrackedFocus(target) { - publishFocusTargetFromCachedPosition({ - ...target, - scene: layerState._viewer?.scene, - camera: layerState._viewer?.camera, - }); + publishFocusTargetAt({ ...target, viewer: layerState._viewer }); } /** diff --git a/src/layers/satellites/stale.test.mjs b/src/layers/satellites/stale.test.mjs index 5c957e69b..71c41ef5d 100644 --- a/src/layers/satellites/stale.test.mjs +++ b/src/layers/satellites/stale.test.mjs @@ -78,7 +78,7 @@ async function fixture(t) { layerState: { isExplicitLayerStateOrigin: () => false }, focus: { clearFocusTarget: noop, - publishFocusTargetFromCachedPosition: noop, + publishFocusTargetAt: noop, getFocusTarget: () => null, }, context: { diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index 00d6a75a7..2099c2773 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -9,7 +9,6 @@ "src/cyberSonarScene.js", "src/data/cctvGizmo.js", "src/data/detection.js", - "src/data/focusDeemphasis.js", "src/data/geoImportPins.js", "src/input/dispatcher.js", "src/input/sensorPick.js",