refactor(overlays): layer labels through the engine

The world overlay host already projects through engine.projector and tests
the horizon with projector.horizonVisible; the last Cesium value on its
path, the snapshot of an entry's cullPosition, is now a geo Cartesian3.

Navara's horizonVisible is Cesium's EllipsoidalOccluder.isPointVisible:
tested against Cesium's own on 8 000 eye/point pairs (600 m to 20 000 km,
points under, on and over the ellipsoid; no disagreement) and at the limb
(a label 40 m under the ellipsoid just past the horizon is hidden, with its
cullPosition lifted 100 m it is shown). It ran per label per frame with
three new vectors each call; it now uses scratch vectors. Micro-measure
(500 labels per frame, no scavenge during the run): 7 941 B per frame
before, 51 after.

The W1 sources that projected with Cesium's SceneTransforms themselves -
the icon orientation's exact projection and the launch replay overlay - go
through the engine's projector when their scene or viewer has a registered
engine. Satellites, vessel labels and aircraft recession project nothing
themselves (the host does).

scripts/qa-overlay-engines.mjs publishes the same labels on both engines at
a city, an orbital and a limb pose and compares the painted rectangles:
worst 0 / 2 / 0 px; on both, the far-side label is not painted, the lifted
limb label is and the buried one is not.
This commit is contained in:
German Khokhlov committed 2026-10-16 21:14:52 +04:00
1 parent 311722e6de
commit 7d5a484796
9 files changed
+139 -37

No files matched your search

+4 -2
View File
@@ -226,8 +226,10 @@ test('isOverlayPointVisible: horizon test prefers entry.cullPosition when presen
test('normalizeOverlayEntry: carries a valid cullPosition, nulls a junk one', () => {
const position = { x: 1, y: 2, z: 3 };
const kept = normalizeOverlayEntry('firms', { id: 'a', position, cullPosition: { x: 4, y: 5, z: 6 } });
assert.ok(kept.cullPosition instanceof Cesium.Cartesian3, 'stored as a host-owned Cartesian3');
const source = { x: 4, y: 5, z: 6 };
const kept = normalizeOverlayEntry('firms', { id: 'a', position, cullPosition: source });
assert.notEqual(kept.cullPosition, source, 'stored as a host-owned copy (a geo Cartesian3)');
assert.ok(!(kept.cullPosition instanceof Cesium.Cartesian3), 'not a Cesium value');
assert.deepEqual(
[kept.cullPosition.x, kept.cullPosition.y, kept.cullPosition.z],
[4, 5, 6],
+12 -10
View File
@@ -23,6 +23,16 @@
*/
import * as Cesium from 'cesium';
import * as geo from '../geo/index.js';
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
// A window position through the engine's projector when `scene` has a
// registered engine (engineFromViewer), else Cesium's SceneTransforms.
function worldToWindow(scene, position, result) {
const projector = engineFromViewer(scene)?.projector;
return projector
? projector.worldToWindow(position, result)
: Cesium.SceneTransforms.worldToWindowCoordinates(scene, position, result);
}
/** Meters used to give the course vector a stable projection magnitude. */
const FORWARD_PROBE_M = 2000;
@@ -331,16 +341,8 @@ export function perspectiveProjectedRotation(
);
geo.cartesian3.add(position, _scratchWorldForward, _scratchProbe);
const at = Cesium.SceneTransforms.worldToWindowCoordinates(
scene,
position,
_scratchWindowAt,
);
const ahead = Cesium.SceneTransforms.worldToWindowCoordinates(
scene,
_scratchProbe,
_scratchWindowAhead,
);
const at = worldToWindow(scene, position, _scratchWindowAt);
const ahead = worldToWindow(scene, _scratchProbe, _scratchWindowAhead);
if (!at || !ahead) {
return screenProjectedRotation(scene, position, courseDeg, previous);
}
+24
View File
@@ -745,3 +745,27 @@ test('the perspective helper is continuous through the sub-pixel band, not a 23
`exact alone at ${s.separation.toFixed(2)} px`,
);
});
test('the exact projection asks the engine projector of a registered scene', async () => {
const geo = await import('../geo/index.js');
const { registerViewerEngine } = await import('../globe/cesium/engineFromViewer.js');
const { perspectiveProjectedRotation: rotation } = await import('./iconOrientation.js');
const scene = { camera: { rightWC: { x: 0, y: 1, z: 0 }, upWC: { x: 0, y: 0, z: 1 } } };
const asked = [];
const unregister = registerViewerEngine({ scene }, {
projector: {
// Screen-right for every point further east (the probe), so 90° on screen.
worldToWindow(position, result = geo.cartesian2.create()) {
asked.push(position);
return Object.assign(result, { x: asked.length === 1 ? 100 : 120, y: 100 });
},
},
});
try {
const value = rotation(scene, geo.cartesian3.fromDegrees(0, 0, 0), 90, null);
assert.equal(asked.length, 2, 'the anchor and the probe');
assert.ok(Math.abs(value - -Math.PI / 2) < 1e-9, `rotation ${value}`);
} finally {
unregister();
}
});