mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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:
1 parent
311722e6de
commit
7d5a484796
9 files changed
+139
-37
No files matched your search
@@ -221,20 +221,27 @@ export function pickEllipsoid(camera, screen) {
|
||||
return intersectEllipsoid(camera.position, pickRay(camera, screen).direction);
|
||||
}
|
||||
|
||||
// horizonVisible runs per label per frame (worldOverlay): no allocation.
|
||||
const horizonCamera = cartesian3.create();
|
||||
const horizonTarget = cartesian3.create();
|
||||
const horizonVt = cartesian3.create();
|
||||
|
||||
/** Cesium's EllipsoidalOccluder.isPointVisible from `eye`. */
|
||||
export function horizonVisible(eye, position) {
|
||||
const camera = cartesian3.create(
|
||||
const camera = cartesian3.fromElements(
|
||||
eye.x / RADII.x,
|
||||
eye.y / RADII.y,
|
||||
eye.z / RADII.z,
|
||||
horizonCamera,
|
||||
);
|
||||
const limbSquared = cartesian3.magnitudeSquared(camera) - 1;
|
||||
const target = cartesian3.create(
|
||||
const target = cartesian3.fromElements(
|
||||
position.x / RADII.x,
|
||||
position.y / RADII.y,
|
||||
position.z / RADII.z,
|
||||
horizonTarget,
|
||||
);
|
||||
const vt = cartesian3.subtract(target, camera, cartesian3.create());
|
||||
const vt = cartesian3.subtract(target, camera, horizonVt);
|
||||
const vtDotVc = -cartesian3.dot(vt, camera);
|
||||
const occluded =
|
||||
limbSquared < 0
|
||||
|
||||
@@ -313,3 +313,48 @@ test('cartographic heights of the math agree with src/geo', () => {
|
||||
'height',
|
||||
);
|
||||
});
|
||||
|
||||
test("horizonVisible agrees with Cesium's EllipsoidalOccluder, also at the limb", async () => {
|
||||
const Cesium = await import('cesium');
|
||||
const occluder = new Cesium.EllipsoidalOccluder(Cesium.Ellipsoid.WGS84);
|
||||
let seed = 7;
|
||||
const random = () => {
|
||||
seed = (seed * 16807) % 2147483647;
|
||||
return seed / 2147483647;
|
||||
};
|
||||
let disagreements = 0;
|
||||
let checked = 0;
|
||||
for (let i = 0; i < 400; i++) {
|
||||
const eye = cartesian3.fromDegrees(
|
||||
random() * 360 - 180,
|
||||
random() * 160 - 80,
|
||||
[600, 15_000, 400_000, 20_000_000][i % 4],
|
||||
);
|
||||
occluder.cameraPosition = new Cesium.Cartesian3(eye.x, eye.y, eye.z);
|
||||
for (let j = 0; j < 20; j++) {
|
||||
// Points on the ground and above it, many near the horizon of the eye.
|
||||
const point = cartesian3.fromDegrees(
|
||||
random() * 360 - 180,
|
||||
random() * 160 - 80,
|
||||
[0, -40, 50, 10_000][j % 4],
|
||||
);
|
||||
checked++;
|
||||
if (
|
||||
horizonVisible(eye, point) !==
|
||||
occluder.isPointVisible(
|
||||
new Cesium.Cartesian3(point.x, point.y, point.z),
|
||||
)
|
||||
)
|
||||
disagreements++;
|
||||
}
|
||||
}
|
||||
assert.equal(disagreements, 0, `${disagreements}/${checked} disagree`);
|
||||
// At the limb: a point 40 m under the ellipsoid just past the horizon is
|
||||
// hidden, its cullPosition lifted 100 m is visible (worldOverlay's rule).
|
||||
const eye = cartesian3.fromDegrees(0, 0, 10_000);
|
||||
const horizonDeg = math.toDegrees(Math.acos(6378137 / (6378137 + 10_000)));
|
||||
const buried = cartesian3.fromDegrees(horizonDeg + 0.02, 0, -40);
|
||||
const lifted = cartesian3.fromDegrees(horizonDeg + 0.02, 0, 100);
|
||||
assert.equal(horizonVisible(eye, buried), false);
|
||||
assert.equal(horizonVisible(eye, lifted), true);
|
||||
});
|
||||
Reference in new issue
Block a user