Keep points and icons past the horizon hidden when they move in place

An in-place update now applies the horizon cull at once, so a set moved
by a frame listener that runs after the draw port's own cull no longer
shows items through the globe until the next frame.
This commit is contained in:
Sameh Khamis committed 2026-11-07 06:04:12 -08:00
1 parent 9de93b8d31
commit 84e6f13725
2 files changed
+60 -18

No files matched your search

+32 -18
View File
@@ -503,25 +503,42 @@ export function createCesiumDraw({
function cullHorizon() {
for (const record of sets.values()) {
if (!record.spec.horizonCull || !record.placed.length) continue;
const eye = scene.camera?.positionWC;
// The eye is ECEF in 3D only.
if (
!eye ||
(scene.mode ?? Cesium.SceneMode.SCENE3D) !== Cesium.SceneMode.SCENE3D
)
return;
occluder ??= new Cesium.EllipsoidalOccluder(
scene.globe?.ellipsoid ?? Cesium.Ellipsoid.WGS84,
eye,
);
occluder.cameraPosition = eye;
const horizon = horizonNow();
if (!horizon) return;
for (const placed of record.placed) {
const show = placed.shown && occluder.isPointVisible(placed.position);
const show = placed.shown && horizon.isPointVisible(placed.position);
if (placed.primitive.show !== show) placed.primitive.show = show;
}
}
}
/** The horizon from the eye as it is now; null where there is none (2D). */
function horizonNow() {
const eye = scene.camera?.positionWC;
// The eye is ECEF in 3D only.
if (
!eye ||
(scene.mode ?? Cesium.SceneMode.SCENE3D) !== Cesium.SceneMode.SCENE3D
)
return null;
occluder ??= new Cesium.EllipsoidalOccluder(
scene.globe?.ellipsoid ?? Cesium.Ellipsoid.WGS84,
eye,
);
occluder.cameraPosition = eye;
return occluder;
}
/**
* Whether a point or icon updated in place shows now: past the horizon
* of a culled set it stays hidden, even when the update comes after this
* frame's cull (a frame listener that moves its items).
*/
function shownNow(record, placed) {
if (!placed.shown || !record.spec.horizonCull) return placed.shown;
return horizonNow()?.isPointVisible(placed.position) ?? true;
}
/** Each frame, before it draws: the flow lines' clock. */
function runFlows() {
for (const record of sets.values()) {
@@ -690,9 +707,8 @@ export function createCesiumDraw({
billboard.id.meta = item.meta;
billboard.id.lodGroup = item.lodGroup;
placed.position = position;
// As a rebuild would; the horizon cull, where it runs, hides it again
// past the horizon before the next frame draws.
placed.shown = look.show;
billboard.show = shownNow(record, placed);
}
/**
@@ -905,9 +921,7 @@ export function createCesiumDraw({
Object.assign(was.primitive, pointLook(item));
was.primitive.id.meta = item.meta;
was.placed.shown = show;
// As a rebuild would; the horizon cull, where it runs, hides it again
// past the horizon before the next frame draws.
was.primitive.show = show;
was.primitive.show = shownNow(record, was.placed);
}
return true;
}
+28
View File
@@ -926,14 +926,42 @@ test('a point moved in place is horizon culled where it now is', () => {
assert.equal(point.show, true, 'under the eye');
set.upsert([dot(180)]);
assert.equal(scene.added[0].get(0), point, 'the same point');
assert.equal(
point.show,
false,
'hidden at once, as a frame listener moving it after the cull needs',
);
frame();
assert.equal(point.show, false, 'past the horizon');
set.upsert([dot(1)]);
assert.equal(point.show, true, 'shown at once');
frame();
assert.equal(point.show, true, 'back in view');
set.dispose();
});
test('an icon moved in place past the horizon is hidden at once', () => {
const { scene, draw, frame } = drawOver();
const set = draw.icons({ id: 'culled-icons', horizonCull: true });
const icon = (lon) => ({
id: 'a',
pos: { lon, lat: 0, height: 10 },
image: { svg: '<svg xmlns="http://www.w3.org/2000/svg"/>' },
size: [8, 8],
});
// The eye is over lon 0.
set.set([icon(0)]);
frame();
const billboard = scene.added[0].get(0);
assert.equal(billboard.show, true, 'under the eye');
set.upsert([icon(180)]);
assert.equal(scene.added[0].get(0), billboard, 'the same billboard');
assert.equal(billboard.show, false, 'past the horizon, before a frame');
set.upsert([icon(1)]);
assert.equal(billboard.show, true);
set.dispose();
});
test('points show only within their display range', () => {
const { scene, draw } = drawOver();
const set = draw.points({ id: 'ranged' });