mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw the screen-space label overlay through the renderer's ports
The world overlay no longer imports Cesium. It reads the eye from the camera port's pose, builds its view-projection from the camera port's matrices, asks the query port whether a point is behind the globe, paints on the frame port's postRender and asks it for renders, and invalidates on the camera port's moveEnd. It still reads the viewer's container and canvas, which are DOM. It leaves the Cesium allow-list. The Cesium query port now keeps one horizon occluder per eye and a scratch point, so the overlay's per-label horizon test allocates nothing, as it did when the overlay held the occluder itself. The overlay tests bind camera, frame and query ports over their viewer doubles, the allocation probe using the Cesium port's own horizon test.
This commit is contained in:
1 parent
e34e923ddd
commit
dd4f19967d
10 files changed
+235
-72
No files matched your search
@@ -192,6 +192,12 @@ export function createCesiumQuery({
|
||||
: 'tiles';
|
||||
}
|
||||
|
||||
/** `isOccluded`'s horizon, rebuilt when the eye or ellipsoid moves. */
|
||||
let occluder = null;
|
||||
let occluderEllipsoid = null;
|
||||
const occluderEye = new Cesium.Cartesian3(NaN, NaN, NaN);
|
||||
const occludedPoint = new Cesium.Cartesian3();
|
||||
|
||||
const query = {
|
||||
pick(x, y, window = {}) {
|
||||
const owner = ownerOf(
|
||||
@@ -246,11 +252,23 @@ export function createCesiumQuery({
|
||||
}
|
||||
},
|
||||
isOccluded(position) {
|
||||
const occluder = new Cesium.EllipsoidalOccluder(
|
||||
scene.globe?.ellipsoid ?? Cesium.Ellipsoid.WGS84,
|
||||
camera.positionWC,
|
||||
);
|
||||
return !occluder.isPointVisible(toCartesian(position));
|
||||
// One occluder per eye and ellipsoid, and one scratch point, so a
|
||||
// per-frame pass over many labels allocates nothing.
|
||||
const ellipsoid = scene.globe?.ellipsoid ?? Cesium.Ellipsoid.WGS84;
|
||||
const eye = camera.positionWC;
|
||||
if (
|
||||
!occluder ||
|
||||
occluderEllipsoid !== ellipsoid ||
|
||||
!Cesium.Cartesian3.equals(occluderEye, eye)
|
||||
) {
|
||||
occluder = new Cesium.EllipsoidalOccluder(ellipsoid, eye);
|
||||
occluderEllipsoid = ellipsoid;
|
||||
Cesium.Cartesian3.clone(eye, occluderEye);
|
||||
}
|
||||
occludedPoint.x = position.x;
|
||||
occludedPoint.y = position.y;
|
||||
occludedPoint.z = position.z;
|
||||
return !occluder.isPointVisible(occludedPoint);
|
||||
},
|
||||
sampleHeightNow(point, { against = 'surface', exclude } = {}) {
|
||||
// Terrain answers from the globe's own tiles, without depth textures.
|
||||
|
||||
@@ -89,6 +89,11 @@ test('a viewer of its own, with no renderer bound, is queried through a built po
|
||||
assert.equal(query.pickEllipsoid(0, 0), null);
|
||||
assert.equal(query.isOccluded({ x: 6378137, y: 0, z: 0 }), false);
|
||||
assert.equal(query.isOccluded({ x: -6378137, y: 0, z: 0 }), true);
|
||||
// The horizon follows the eye.
|
||||
Cesium.Cartesian3.fromElements(-2e7, 0, 0, scene.camera.positionWC);
|
||||
assert.equal(query.isOccluded({ x: 6378137, y: 0, z: 0 }), true);
|
||||
assert.equal(query.isOccluded({ x: -6378137, y: 0, z: 0 }), false);
|
||||
Cesium.Cartesian3.fromElements(2e7, 0, 0, scene.camera.positionWC);
|
||||
|
||||
// A renderer bound later answers new callers.
|
||||
const unbind = bindRenderer(viewer, { query: { id: 'renderer' } });
|
||||
|
||||
Reference in new issue
Block a user