mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Keep a draw set made with pickable: false out of the pick pass
Ground fills of such a set are built as ground primitives that skip the pick pass, since a GroundPrimitive adds pick commands even with allowPicking off; draped lines are built with allowPicking off. Turning a set unpickable rebuilds it and lets its old ground go at once, so it stops hiding the ground from picks straight away.
This commit is contained in:
1 parent
96d860854f
commit
d30b89ac8e
2 files changed
+104
-4
No files matched your search
@@ -13,7 +13,9 @@
|
||||
* drawing its last ground primitives until the new ones are ready, so a
|
||||
* refresh never blinks. `horizonCull` hides a set's points and icons past
|
||||
* the ellipsoid's horizon, each frame before it draws, tested at the
|
||||
* position each was given (not where clamping put it).
|
||||
* position each was given (not where clamping put it). The ground fills and
|
||||
* draped lines of a set made with `pickable: false` stay out of the pick
|
||||
* pass, so they never hide the ground geometry drawn under them from picks.
|
||||
*
|
||||
* Built over a scene by `createCesiumPorts`, and on its own over a Cesium
|
||||
* viewer with no renderer bound, when code first asks
|
||||
@@ -85,6 +87,18 @@ const pointBlendOf = (blend) =>
|
||||
translucent: Cesium.BlendOption.TRANSLUCENT,
|
||||
})[blend] ?? Cesium.BlendOption.OPAQUE_AND_TRANSLUCENT;
|
||||
|
||||
/**
|
||||
* Ground fills of a set that never takes part in picks (`pickable: false`).
|
||||
* `allowPicking: false` drops their ids, but a ground primitive still draws
|
||||
* its stencil in the pick pass, which would erase picks of ground geometry
|
||||
* under it; these skip the pick pass altogether.
|
||||
*/
|
||||
class UnpickableGroundPrimitive extends Cesium.GroundPrimitive {
|
||||
update(frameState) {
|
||||
if (!frameState.passes.pick) super.update(frameState);
|
||||
}
|
||||
}
|
||||
|
||||
const ANCHORS = {
|
||||
center: Cesium.VerticalOrigin.CENTER,
|
||||
bottom: Cesium.VerticalOrigin.BOTTOM,
|
||||
@@ -172,9 +186,19 @@ export function createCesiumDraw({ scene, report }) {
|
||||
const culled = spec.horizonCull;
|
||||
const clampTo = spec.clampTo;
|
||||
const blend = spec.blend;
|
||||
const pickable = spec.pickable !== false;
|
||||
Object.assign(spec, options);
|
||||
// What clamped items clamp to, and how points blend, are built in.
|
||||
if (spec.clampTo !== clampTo || spec.blend !== blend) rebuild();
|
||||
// What clamped items clamp to, how points blend, and whether ground
|
||||
// primitives pick, are built into them.
|
||||
if (
|
||||
spec.clampTo !== clampTo ||
|
||||
spec.blend !== blend ||
|
||||
(spec.pickable !== false) !== pickable
|
||||
)
|
||||
rebuild();
|
||||
// A set that stops picking lets its old ground go now: still drawn
|
||||
// while the new builds, it would keep hiding the ground from picks.
|
||||
if (pickable && spec.pickable === false) retire(record);
|
||||
setsVersion += 1;
|
||||
showHosts(record);
|
||||
// No longer culled: what the cull hid comes back.
|
||||
@@ -643,6 +667,7 @@ export function createCesiumDraw({ scene, report }) {
|
||||
geometryInstances,
|
||||
appearance: new Cesium.PolylineColorAppearance(),
|
||||
classificationType: classificationOf(clampTo),
|
||||
allowPicking: record.spec.pickable !== false,
|
||||
}),
|
||||
);
|
||||
replaceHost(record, collect(host, ground), ground, host);
|
||||
@@ -797,11 +822,16 @@ export function createCesiumDraw({ scene, report }) {
|
||||
batch.rectangles.insert(String(batch.instances.length), rectangle);
|
||||
batch.instances.push(instance);
|
||||
}
|
||||
const pickable = record.spec.pickable !== false;
|
||||
const Ground = pickable
|
||||
? Cesium.GroundPrimitive
|
||||
: UnpickableGroundPrimitive;
|
||||
return batches.map(
|
||||
(batch) =>
|
||||
new Cesium.GroundPrimitive({
|
||||
new Ground({
|
||||
geometryInstances: batch.instances,
|
||||
classificationType: classificationOf(batch.clampTo),
|
||||
allowPicking: pickable,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -236,6 +236,76 @@ test('clamped fills are ground primitives packed so none overlap within one', ()
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('a set that never picks keeps its ground fills and draped lines out of picks', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const fills = draw.shapes({ id: 'cells', pickable: false });
|
||||
const square = {
|
||||
id: 'a',
|
||||
geometry: {
|
||||
kind: 'rectangle',
|
||||
rect: { west: 0, south: 0, east: 1, north: 1 },
|
||||
},
|
||||
fill: [1, 0, 0, 0.3],
|
||||
height: 'clampGround',
|
||||
};
|
||||
fills.set([square]);
|
||||
const groundOf = (host) => {
|
||||
for (let i = 0; i < host.length; i++)
|
||||
if (host.get(i) instanceof Cesium.GroundPrimitive) return host.get(i);
|
||||
return null;
|
||||
};
|
||||
const passes = (primitive) => {
|
||||
const seen = [];
|
||||
const update = Cesium.GroundPrimitive.prototype.update;
|
||||
Cesium.GroundPrimitive.prototype.update = function (frameState) {
|
||||
seen.push(frameState.passes.pick ? 'pick' : 'render');
|
||||
};
|
||||
try {
|
||||
primitive.update({ passes: { pick: true } });
|
||||
primitive.update({ passes: { render: true } });
|
||||
} finally {
|
||||
Cesium.GroundPrimitive.prototype.update = update;
|
||||
}
|
||||
return seen;
|
||||
};
|
||||
let ground = groundOf(scene.added[0]);
|
||||
assert.equal(ground.allowPicking, false);
|
||||
assert.deepEqual(passes(ground), ['render'], 'no pick pass at all');
|
||||
// Whether it picks is built into the primitives: a change rebuilds them.
|
||||
fills.setOptions({ pickable: true });
|
||||
ground = groundOf(scene.added.at(-1));
|
||||
assert.equal(ground.allowPicking, true);
|
||||
assert.deepEqual(passes(ground), ['pick', 'render']);
|
||||
// Stopping picks drops the old, pickable ground at once, before the new
|
||||
// ground is ready: kept drawing, it would still hide the ground from picks.
|
||||
fills.setOptions({ pickable: false });
|
||||
assert.equal(scene.added.length, 1, 'only the new host is drawn');
|
||||
assert.equal(groundOf(scene.added[0]).allowPicking, false);
|
||||
fills.dispose();
|
||||
|
||||
const lines = draw.lines({ id: 'edges', pickable: false });
|
||||
lines.set([
|
||||
{
|
||||
id: 'e',
|
||||
positions: [
|
||||
Cesium.Cartesian3.fromDegrees(0, 0),
|
||||
Cesium.Cartesian3.fromDegrees(1, 0),
|
||||
],
|
||||
widthPx: 2,
|
||||
mode: 'draped',
|
||||
style: { kind: 'solid', color: '#fff' },
|
||||
},
|
||||
]);
|
||||
const host = scene.added.at(-1);
|
||||
let draped = null;
|
||||
for (let i = 0; i < host.length; i++)
|
||||
if (host.get(i) instanceof Cesium.GroundPolylinePrimitive)
|
||||
draped = host.get(i);
|
||||
assert.equal(draped.allowPicking, false);
|
||||
lines.dispose();
|
||||
assert.equal(scene.added.length, 0);
|
||||
});
|
||||
|
||||
test('changing what a set clamps to rebuilds its items', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.points({ id: 'reclamp', clampTo: 'terrain' });
|
||||
|
||||
Reference in new issue
Block a user