refactor(pick): use the globe engine

pickGroundPosition takes the globe engine (picker.pickPosition, then
camera.pickEllipsoid) and still accepts a Cesium viewer from callers that
hold one (layers until phase 1c), with one shared ground-or-ellipsoid
rule. isSurfacePick classifies engine pick results exactly as the Cesium
picks they wrap.
This commit is contained in:
German Khokhlov committed 2026-10-15 18:32:45 +04:00
1 parent aaa6074663
commit c2a0d20f3d
2 files changed
+77 -15

No files matched your search

+46
View File
@@ -184,3 +184,49 @@ test('a surface pick is nothing, or Google 3D tile content without an id', async
assert.equal(isSurfacePick({ id: 'flight:1', content: {} }), false);
assert.equal(isSurfacePick({ primitive: {} }), false, 'an unnamed primitive');
});
test('on a globe engine the ground is the picked surface, else the ellipsoid, never the sky', async () => {
const { pickGroundPosition } = await import('./scenePick.js');
const { createFakeEngine } = await import('../globe/testing/fakeEngine.js');
const ground = { x: 6378137, y: 0, z: 0 };
const sky = { x: 500, y: 0, z: 0 };
const screen = { x: 10, y: 20 };
const engine = createFakeEngine();
engine.fake.script('pickPosition', ground);
engine.fake.script('pickEllipsoid', undefined);
assert.equal(pickGroundPosition(engine, screen), ground);
assert.deepEqual(engine.fake.callsOf('picker.pickPosition')[0].args, [screen]);
engine.fake.script('pickPosition', sky);
engine.fake.script('pickEllipsoid', ground);
assert.equal(pickGroundPosition(engine, screen), ground);
engine.fake.script('pickPosition', () => {
throw new Error('depth read failed');
});
assert.equal(pickGroundPosition(engine, screen), ground);
engine.fake.script('pickEllipsoid', undefined);
assert.equal(pickGroundPosition(engine, screen), null);
const unsupported = createFakeEngine();
unsupported.picker.pickPositionSupported = false;
unsupported.fake.script('pickEllipsoid', ground);
assert.equal(pickGroundPosition(unsupported, screen), ground);
assert.equal(unsupported.fake.callsOf('picker.pickPosition').length, 0);
});
test('engine pick results classify like the Cesium picks they wrap', async () => {
const { isSurfacePick } = await import('./scenePick.js');
const { createCesiumPicker } = await import('../globe/cesium/picker.js');
const { createFakeViewer } = await import('../globe/cesium/testing/fakeViewer.mjs');
const raws = [
undefined,
{ content: {}, primitive: {} },
{ primitive: { isCesium3DTileset: true } },
{ id: 'flight:1', content: {} },
{ primitive: {} },
];
for (const raw of raws) {
const viewer = createFakeViewer();
viewer.scene.pick = () => raw;
const { picker } = createCesiumPicker(viewer);
assert.equal(isSurfacePick(picker.pick({ x: 1, y: 2 })), isSurfacePick(raw), JSON.stringify(raw));
}
});