diff --git a/docs/RENDERER-CONTRACT.md b/docs/RENDERER-CONTRACT.md index 5a2c7f644..f95d6fce6 100644 --- a/docs/RENDERER-CONTRACT.md +++ b/docs/RENDERER-CONTRACT.md @@ -42,6 +42,9 @@ optional, so a renderer written before it still conforms: target's east-north-up frame, or the identity. `setView` keeps that frame while it places a world pose. A share link's follow offset is re-expressed in it, satellites included. +- `camera.on('changed', cb, { threshold })` measures each listener by its + own threshold under the capability `cameraChangeThreshold`; a renderer + without it fires every `changed` listener at 0.5. - A line item's `depthFailDash` (`{ length, pattern16? }`) dashes the parts behind the surface in `depthFailColor`, as the Draw tool's rubber band is. A renderer that predates it draws those parts solid. @@ -72,6 +75,12 @@ The rules that hold everywhere: its documentation names first. A required member that names a capability always exists, and without the capability it answers null or empty. Quality support is listed by `quality.knobs()`, not by capabilities. +- **Picks see the scene before effects.** A style that moves pixels does not + move what is picked, so the application maps a pointer through its own + style first + (`src/input/sensorPick.js`). A bounded `drillPick` (`limit`) also bounds + its work: it looks through at most `max(limit, 16)` things under the + pointer. - **Heights are physical.** All heights are metres above the ellipsoid, unexaggerated. Only drawing follows exaggerated terrain. - **Listeners** run in subscription order. A listener removed during diff --git a/src/render/camera/events.js b/src/render/camera/events.js index db31e6949..9b40fc3cb 100644 --- a/src/render/camera/events.js +++ b/src/render/camera/events.js @@ -28,10 +28,12 @@ const angleDelta = (a, b) => { /** * @param {{pose: () => import('../contract/camera').CameraPose, - * report: (error: unknown) => void}} options `pose` is read only while a - * `changed` listener is registered. + * report: (error: unknown) => void, thresholds?: boolean}} options `pose` + * is read only while a `changed` listener is registered; `thresholds` + * false (a renderer without `cameraChangeThreshold`) ignores a listener's + * own threshold, so every listener fires at 0.5. */ -export function createCameraEvents({ pose, report }) { +export function createCameraEvents({ pose, report, thresholds = true }) { const listeners = Object.fromEntries(CAMERA_EVENTS.map((e) => [e, []])); function deliver(entry) { @@ -56,7 +58,8 @@ export function createCameraEvents({ pose, report }) { function on(event, cb, options = {}) { const list = listeners[event]; if (!list) throw new Error(`Unknown camera event: ${event}`); - const entry = { cb, live: true, threshold: options.threshold ?? 0.5 }; + const threshold = thresholds ? (options.threshold ?? 0.5) : 0.5; + const entry = { cb, live: true, threshold }; list.push(entry); return () => { entry.live = false; diff --git a/src/render/cesium/camera.js b/src/render/cesium/camera.js index e4da681d5..5d18ce25d 100644 --- a/src/render/cesium/camera.js +++ b/src/render/cesium/camera.js @@ -101,10 +101,13 @@ export function createCesiumCamera({ const removers = []; // Camera events: Cesium's own moveStart and moveEnd (500 ms after the // last change, never while following), and `changed` measured per - // listener on every tick, where Cesium measures its single threshold. + // listener on every tick, where Cesium measures its single threshold + // (`camera.percentageChanged`, which this leaves as it is for everyone + // else listening to Cesium's own event). const cameraEvents = createCameraEvents({ pose: () => cameraPort.pose(), report, + thresholds: capabilities?.has('cameraChangeThreshold') ?? true, }); removers.push( scene.postUpdate.addEventListener(() => { diff --git a/src/render/cesium/cameraPort.test.mjs b/src/render/cesium/cameraPort.test.mjs index 4630ee558..327e2c842 100644 --- a/src/render/cesium/cameraPort.test.mjs +++ b/src/render/cesium/cameraPort.test.mjs @@ -52,11 +52,13 @@ function headlessHarness(clock) { scene.primitives = { add() {}, remove() {} }; scene.requestRender = () => {}; clock.now = 0; + const capabilities = new Set(['cameraChangeThreshold']); const ports = createCesiumPorts( { scene, clock: { currentTime: Cesium.JulianDate.now() } }, - { capabilities: new Set() }, + { capabilities }, ); return { + capabilities, camera: ports.camera, query: ports.query, destroy: () => ports.dispose(), diff --git a/src/render/cesium/harness.js b/src/render/cesium/harness.js index 3e9d304a9..f5852fd10 100644 --- a/src/render/cesium/harness.js +++ b/src/render/cesium/harness.js @@ -83,6 +83,7 @@ export const CESIUM_CHECKS = new Set([ 'input.lease.grab', 'input.lease.press', 'query.heights', + 'query.pickBeforeStyles', 'query.heights.sets', 'query.projectMany', 'query.rays', diff --git a/src/render/cesium/input.js b/src/render/cesium/input.js index 5daf19737..22991cc8e 100644 --- a/src/render/cesium/input.js +++ b/src/render/cesium/input.js @@ -257,7 +257,7 @@ export function createCesiumInput( let picked = false; let ground; let grounded = false; - /** @type {Map} */ + /** @type {Map} */ const drills = new Map(); ev.pick = () => { if (!picked) { @@ -269,22 +269,20 @@ export function createCesiumInput( ev.drill = (options = {}) => { const { limit, ...window } = options; const want = limit ?? Infinity; - const key = `${window.width ?? ''}x${window.height ?? ''}:${window.purpose ?? ''}`; - let pass = drills.get(key); - // A pass that found fewer than it asked for found everything. - if (!pass || (pass.hits.length >= pass.limit && want > pass.limit)) { - const depth = - want === Infinity ? Infinity : Math.max(want, DRILL_DEPTH); - pass = { - limit: depth, - hits: query.drillPick(x, y, { - ...window, - ...(depth === Infinity ? {} : { limit: depth }), - }), - }; - drills.set(key, pass); + // A bounded drill looks only so deep (`drillPick`'s limit bounds the + // work), so each depth is its own pass: a deeper one could name items + // a shallower one never reaches. + const depth = want === Infinity ? Infinity : Math.max(want, DRILL_DEPTH); + const key = `${window.width ?? ''}x${window.height ?? ''}:${window.purpose ?? ''}:${depth}`; + let hits = drills.get(key); + if (!hits) { + hits = query.drillPick(x, y, { + ...window, + ...(depth === Infinity ? {} : { limit: depth }), + }); + drills.set(key, hits); } - return want === Infinity ? pass.hits.slice() : pass.hits.slice(0, want); + return want === Infinity ? hits.slice() : hits.slice(0, want); }; ev.ground = () => { if (!grounded) { diff --git a/src/render/cesium/input.test.mjs b/src/render/cesium/input.test.mjs index dffb468dc..2536d2e14 100644 --- a/src/render/cesium/input.test.mjs +++ b/src/render/cesium/input.test.mjs @@ -203,7 +203,10 @@ test('a click carries its gesture and one pick, drill and ground', () => { ev.drill().map((h) => h.id), ['a', 'b', 'c'], ); - assert.equal(s.passes.drill, 1, 'a short pass found everything'); + // Each depth is a pass of its own: a bounded one looks only so deep. + assert.equal(s.passes.drill, 2, 'a bounded pass is drilled again for more'); + ev.drill({ limit: 2 }); + assert.equal(s.passes.drill, 2, 'the same depth is drilled once'); assert.deepEqual(ev.ground(), { x: 1, y: 2, z: 3 }); s.handler.fire(T.LEFT_CLICK, { position: s.at(3, 4) }); assert.deepEqual( diff --git a/src/render/cesium/ports.js b/src/render/cesium/ports.js index 273eefc59..fee62ab4c 100644 --- a/src/render/cesium/ports.js +++ b/src/render/cesium/ports.js @@ -63,6 +63,7 @@ export function cesiumCapabilities(scene, only) { 'quads', 'meshes', 'followFrame', + 'cameraChangeThreshold', ...GPU_ICON_CAPABILITIES, 'styles', 'bloom', diff --git a/src/render/cesium/ports.test.mjs b/src/render/cesium/ports.test.mjs index 395bcd9aa..e42e43473 100644 --- a/src/render/cesium/ports.test.mjs +++ b/src/render/cesium/ports.test.mjs @@ -11,6 +11,7 @@ import { updateCameraChanged } from './internals.js'; test('capabilities follow what the scene supports', () => { const effects = [ 'followFrame', + 'cameraChangeThreshold', 'columns', 'motionSegments', 'courseGlide', @@ -568,7 +569,9 @@ test('changed fires per listener, at each threshold as Cesium would', () => { ]; const { widget, scene, raise } = tickingWidget(); cityView(scene.camera); - const ports = createCesiumPorts(widget, { capabilities: all }); + const ports = createCesiumPorts(widget, { + capabilities: new Set([...all, 'cameraChangeThreshold']), + }); const counts = { 0.5: 0, 0.1: 0 }; for (const t of [0.5, 0.1]) ports.camera.on('changed', () => (counts[t] += 1), { threshold: t }); @@ -583,6 +586,27 @@ test('changed fires per listener, at each threshold as Cesium would', () => { ports.dispose(); }); +test('without cameraChangeThreshold every changed listener fires at 0.5', () => { + const steps = Array.from({ length: 24 }, () => (c) => c.lookRight(0.05)); + const { widget, scene, raise } = tickingWidget(); + cityView(scene.camera); + const before = scene.camera.percentageChanged; + const ports = createCesiumPorts(widget, { capabilities: all }); + const counts = { 0.5: 0, 0.1: 0 }; + for (const t of [0.5, 0.1]) + ports.camera.on('changed', () => (counts[t] += 1), { threshold: t }); + raise('postUpdate'); + for (const step of steps) { + step(scene.camera); + raise('postUpdate'); + } + assert.equal(counts[0.1], counts[0.5], JSON.stringify(counts)); + assert.equal(counts[0.5], cesiumChangedCount(0.5, steps)); + // Cesium's own threshold, shared with everyone else, is left as it was. + assert.equal(scene.camera.percentageChanged, before); + ports.dispose(); +}); + test('camera events: Cesium’s moves relayed, a throw reported, off and dispose stop them', () => { const { widget, scene, raise } = tickingWidget(); cityView(scene.camera); diff --git a/src/render/cesium/query.js b/src/render/cesium/query.js index b8241ffb0..98a796a4f 100644 --- a/src/render/cesium/query.js +++ b/src/render/cesium/query.js @@ -18,6 +18,9 @@ import { toCartesian } from './common.js'; import { unboundDrawPart } from './draw.js'; import { drawHitOf } from './drawHit.js'; +/** The fewest things a bounded drill looks through (`QueryPort.drillPick`). */ +const DRILL_DEPTH = 16; + /** * The query capabilities a Cesium scene has: depth picks, height samples * and ray casts all need depth textures, which `pickPositionSupported` and @@ -80,15 +83,24 @@ export function createCesiumQuery({ * The pickable draw-set items under a pixel, nearest first, once each (a * shape's fill and outline share one id). `untilForeign` stops at the first * thing that is not a draw-set item (a tile, the app's own primitives): - * what is behind it is hidden. + * what is behind it is hidden. With a `limit`, Cesium looks through at + * most `max(limit, 16)` things of any kind (each a pick pass), as the + * contract bounds the work; without one, or with `unbounded` (a `pick` + * looking under something unpickable), it picks until nothing is left. */ - function drill(x, y, { width = 3, height = 3, limit, untilForeign } = {}) { + function drill( + x, + y, + { width = 3, height = 3, limit, untilForeign, unbounded = false } = {}, + ) { const hits = []; if (limit === 0) return hits; const seen = new Set(); for (const picked of scene.drillPick( screen(x, y), - undefined, + limit === undefined || unbounded + ? undefined + : Math.max(limit, DRILL_DEPTH), width, height, )) { @@ -269,6 +281,7 @@ export function createCesiumQuery({ ...window, limit: 1, untilForeign: true, + unbounded: true, }); if (under) return under; } diff --git a/src/render/conformance/cameraScripts.js b/src/render/conformance/cameraScripts.js index 837365e20..31d224110 100644 --- a/src/render/conformance/cameraScripts.js +++ b/src/render/conformance/cameraScripts.js @@ -428,6 +428,7 @@ export const CAMERA_SCRIPTS = Object.freeze([ }, { name: 'changed fires by each listener’s threshold', + capability: 'cameraChangeThreshold', steps: [ START, city(2000, 0, -0.5), diff --git a/src/render/conformance/checks/camera.js b/src/render/conformance/checks/camera.js index 1e00a0904..3976005a8 100644 --- a/src/render/conformance/checks/camera.js +++ b/src/render/conformance/checks/camera.js @@ -138,6 +138,8 @@ export function cameraChecks() { ok(expected, `no reference trace for ${script.name}`); const r = await fresh(h); try { + if (script.capability && !r.capabilities.has(script.capability)) + return { skip: `no ${script.capability}` }; const run = await runCameraScript( contractDriver(r, { frame: () => h.frame(r), diff --git a/src/render/conformance/checks/ports.js b/src/render/conformance/checks/ports.js index 317fa3758..10f2d38cd 100644 --- a/src/render/conformance/checks/ports.js +++ b/src/render/conformance/checks/ports.js @@ -207,6 +207,29 @@ fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f { }, }); +/** A style that mirrors the image left to right: it moves every pixel. */ +const mirrorStyle = (id) => ({ + id, + params: [], + animated: false, + shader: { + glsl: `uniform sampler2D colorTexture; +uniform float intensity; +in vec2 v_textureCoordinates; +void main() { + vec2 uv = v_textureCoordinates; + vec2 mirrored = vec2(1.0 - uv.x, uv.y); + out_FragColor = vec4(texture(colorTexture, mix(uv, mirrored, step(0.5, intensity))).rgb, 1.0); +}`, + wgsl: `@fragment +fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f { + let mirrored = vec2f(1.0 - uv.x, uv.y); + let at = mix(uv, mirrored, step(0.5, params.intensity)); + return vec4f(textureSample(colorTexture, colorSampler, at).rgb, 1.0); +}`, + }, +}); + export function portChecks() { return [ // --- Shape ------------------------------------------------------------- @@ -644,8 +667,94 @@ export function portChecks() { .sort(); deepEqual(ids, ['a', 'b'], 'both hits'); equal(r.query.drillPick(s.x, s.y, { limit: 1 }).length, 1, 'limit'); + equal( + r.query.drillPick(s.x, s.y, { limit: 0 }).length, + 0, + 'a limit of 0 picks nothing', + ); + ok( + r.query.drillPick(s.x, s.y).every((hit) => hit.surface === false), + 'never the surface', + ); + deepEqual( + r.query.drillPick(s.x + 120, s.y + 120), + [], + 'nothing over the bare globe', + ); + // An unpickable set over them is looked through, never named. + const cover = r.draw.points({ + id: 'conf:drill-cover', + pickable: false, + }); + cover.set([{ id: 'c', pos, pixelSize: 30, color: '#00f' }]); + await drawn(h, r); + const through = r.query.drillPick(s.x, s.y, { limit: 2 }); + ok( + through.every((hit) => hit.set === 'conf:drill'), + 'an unpickable set is not named', + ); + equal(through.length, 2, 'the items under it are'); + cover.dispose(); + set.dispose(); + // Nearest first: stacked under a downward eye, the highest is nearest. + const stack = r.draw.points({ id: 'conf:drill-stack' }); + stack.set( + [0, 300, 600].map((height) => ({ + id: `h${height}`, + pos: h.toEcef({ ...AUSTIN, height }), + pixelSize: 20, + color: '#f0f', + })), + ); + await drawn(h, r); + const top = r.query.project(h.toEcef({ ...AUSTIN, height: 600 })); + const all = r.query + .drillPick(top.x, top.y) + .filter((x) => x.set === 'conf:drill-stack') + .map((x) => x.id); + deepEqual(all, ['h600', 'h300', 'h0'], 'nearest first'); + const bounded = r.query + .drillPick(top.x, top.y, { limit: 2 }) + .map((x) => x.id); + ok(bounded.length <= 2, 'no more than the limit'); + deepEqual(bounded, all.slice(0, bounded.length), 'the nearest of them'); + stack.dispose(); + }, + ), + check( + 'query.pickBeforeStyles', + 'picks answer against the scene as drawn before styles', + async (h, r) => { + await overAustin(h, r); + const set = r.draw.icons({ id: 'conf:pick-styled' }); + // Off centre, so a style that mirrors the image moves it. + const pos = h.toEcef({ + lon: AUSTIN.lon + 0.004, + lat: AUSTIN.lat, + height: 0, + }); + set.set([{ id: 'one', pos, image: DOT, size: [24, 24] }]); + await drawn(h, r); + await settled(r); + const s = r.query.project(pos); + ok(s, 'the icon projects'); + const off = r.effects.defineStyle(mirrorStyle('conf:mirror')); + r.effects.setStyle('conf:mirror'); + r.effects.setStyleIntensity('conf:mirror', 1); + await drawn(h, r); + equal(r.effects.diagnostics().style, 'conf:mirror', 'the style is on'); + const hit = r.query.pick(s.x, s.y); + equal( + hit?.set, + 'conf:pick-styled', + 'picked where it is, not where it shows', + ); + equal(hit?.id, 'one', 'Hit.id'); + r.effects.setStyle(null); + off(); set.dispose(); }, + { capability: 'styles' }, ), check( 'draw.motion', diff --git a/src/render/contract/camera.d.ts b/src/render/contract/camera.d.ts index dc48ebff4..a504d8ef9 100644 --- a/src/render/contract/camera.d.ts +++ b/src/render/contract/camera.d.ts @@ -9,7 +9,9 @@ * - `lookAt` orbits the target (the user can still rotate and zoom about it); * `release` returns to the world frame. * - `changed` fires when the view has moved by more than the listener's own - * `threshold` (default 0.5) since it last fired, measured per listener: + * `threshold` (`cameraChangeThreshold`; default 0.5, and 0.5 for every + * listener without the capability) since it last fired, measured per + * listener, without changing what any other listener is measured by: * heading and roll each by their change over π since they last fired; the * view by the larger of the direction's turn over half the vertical field * of view and the eye's travel over its height, since the view last @@ -45,7 +47,13 @@ export interface CameraPose { direction: Vec3; up: Vec3; right: Vec3; - /** Vertical field of view, radians. */ + /** + * Vertical field of view, radians. `fovy` and `aspectRatio` describe a + * centred perspective frustum. Where the renderer's frustum is off-centre or + * orthographic reports the nearest centred one here and its exact + * projection only in `matrices()`; code that culls or projects exactly + * reads `matrices()`. + */ fovy: number; aspectRatio: number; near: number; @@ -259,6 +267,12 @@ export interface CameraPort { */ followFrame?(): Float64Array; readonly controls: CameraControls; + /** + * `threshold` (`cameraChangeThreshold`): the fraction of change, as the + * header measures it, that fires this `changed` listener; ignored for the + * other events, and without the capability (every listener then fires at + * 0.5). + */ on(event: CameraEvent, cb: () => void, options?: { threshold?: number }): Off; /** Runs before each camera command, so an owner can yield to another. */ onCommand(cb: (command: CameraCommand) => void): Off; diff --git a/src/render/contract/common.d.ts b/src/render/contract/common.d.ts index 2e8dab2e2..02ad50adf 100644 --- a/src/render/contract/common.d.ts +++ b/src/render/contract/common.d.ts @@ -210,5 +210,7 @@ export type Capability = | 'globeVisibility' /** Reading the frame the eye is placed in (`camera.followFrame`). */ | 'followFrame' + /** A `threshold` per `changed` listener (`camera.on`). */ + | 'cameraChangeThreshold' /** A built-in quality benchmark. */ | 'benchmark'; diff --git a/src/render/contract/index.js b/src/render/contract/index.js index 15be4b58b..da0eff940 100644 --- a/src/render/contract/index.js +++ b/src/render/contract/index.js @@ -48,6 +48,7 @@ export const CAPABILITIES = Object.freeze([ 'followAutodetect', 'globeVisibility', 'followFrame', + 'cameraChangeThreshold', 'benchmark', ]); diff --git a/src/render/contract/query.d.ts b/src/render/contract/query.d.ts index df585e6ed..0153ae710 100644 --- a/src/render/contract/query.d.ts +++ b/src/render/contract/query.d.ts @@ -4,6 +4,10 @@ * Picks, projection and rays are synchronous and answer against the last * presented frame. Heights have a synchronous cache-only form that may * return null, and asynchronous forms that load what they need. + * + * Picks, depth picks and rays answer against the scene as drawn before + * effects: a style that moves pixels does not move what is picked, so the application + * maps a pointer through its own style before it picks. */ import type { Ecef, LonLat, Meta, Ray, ScreenXY } from './common'; @@ -60,6 +64,16 @@ export interface HeightSample { export interface QueryPort { pick(x: number, y: number, window?: PickWindow): Hit | null; + /** + * The pickable draw-set items under the pointer, nearest first, each once: + * never the surface (`surface` is always false) and never anything that is + * not a draw-set item. `limit`, a whole number of 0 or more, bounds the + * work as well as the answer: the renderer stops at `limit` hits and + * looks through at most `max(limit, 16)` things of any kind under the pointer that its picks + * see (tiles, unpickable items it still picks, its own), so it may return + * fewer than `limit` when more lie above them. Omitted: every item, at + * whatever cost. + */ drillPick( x: number, y: number, diff --git a/src/render/stub/camera.js b/src/render/stub/camera.js index 7d37ae3f9..69f081f4b 100644 --- a/src/render/stub/camera.js +++ b/src/render/stub/camera.js @@ -75,6 +75,8 @@ const ONE_DEGREE = Math.PI / 180; * @param {() => number} options.sceneTime Scene time, epoch ms. * @param {(reason: string) => void} options.requestRender * @param {(error: Error) => void} options.report + * @param {boolean} [options.thresholds] `cameraChangeThreshold`: each + * `changed` listener's own threshold (default true). */ export function createStubCamera({ viewport, @@ -83,6 +85,7 @@ export function createStubCamera({ requestRender, report, drawnPosition = () => null, + thresholds = true, }) { // Local frame values; world values are `frame` applied to them. let frame = IDENTITY; @@ -95,7 +98,7 @@ export function createStubCamera({ const near = 1; const far = 5e8; - const events = createCameraEvents({ pose, report }); + const events = createCameraEvents({ pose, report, thresholds }); const { emit, on, stepChanged } = events; const commandHooks = []; const holds = new Map(); diff --git a/src/render/stub/index.js b/src/render/stub/index.js index e0821c47c..36df31bff 100644 --- a/src/render/stub/index.js +++ b/src/render/stub/index.js @@ -172,6 +172,7 @@ export function createStubRenderer(options = {}) { requestRender, report, drawnPosition: (ref, aheadMs) => drawnPosition(ref, aheadMs), + thresholds: capabilities.has('cameraChangeThreshold'), }); camera.setViewRectangle(viewRectangle); if (capabilities.has('followFrame')) @@ -675,16 +676,24 @@ export function createStubRenderer(options = {}) { ); } - function hitsAt(x, y, win = {}) { + /** + * The pickable items under a pixel, nearest first. With a `depth`, only + * the nearest `depth` things drawn there are looked through, unpickable + * ones included (as a bounded `drillPick` does). + */ + function hitsAt(x, y, win = {}, depth = undefined) { if (scriptedPicks) return scriptedPicks(x, y, win) ?? []; const halfW = (win.width ?? 3) / 2; const halfH = (win.height ?? 3) / 2; const hits = []; for (const [setId, set] of sets) { - if (!set.show || set.spec.pickable === false) continue; + if (!set.show) continue; + // Drawn but never picked: it still takes up a place under the pointer. + const setBlocked = set.spec.pickable === false; + const blockedItem = (item) => setBlocked || item.pickable === false; if (set.kind === 'lines') { for (const item of set.items.values()) { - if (item.show === false || item.pickable === false) continue; + if (item.show === false) continue; // Lines in the sky's frame are not picked where they are drawn. if (item.frame === 'inertial') continue; const p = lineHit(item, x, y, Math.max(halfW, halfH)); @@ -696,6 +705,7 @@ export function createStubRenderer(options = {}) { surface: false, position: p, depth: magnitude(sub(p, eye().position)), + blocked: blockedItem(item), }); } continue; @@ -707,7 +717,7 @@ export function createStubRenderer(options = {}) { const at = ground && toCartographicRadians(ground); if (!at) continue; for (const item of set.items.values()) { - if (item.show === false || item.pickable === false) continue; + if (item.show === false) continue; if (!item.fill || item.outlineOnly) continue; if (item.height !== 'clampGround') continue; if (item.geometry?.kind !== 'rectangle') continue; @@ -720,6 +730,7 @@ export function createStubRenderer(options = {}) { surface: false, position: ground, depth: magnitude(sub(ground, eye().position)), + blocked: blockedItem(item), }); } continue; @@ -732,7 +743,7 @@ export function createStubRenderer(options = {}) { ) continue; for (const item of set.items.values()) { - if (item.show === false || item.pickable === false) continue; + if (item.show === false) continue; const p = itemPosition(set, item); if (!p || isOccluded(p)) continue; const distance = magnitude(sub(p, eye().position)); @@ -769,12 +780,18 @@ export function createStubRenderer(options = {}) { surface: false, position: p, depth: magnitude(sub(p, eye().position)), + blocked: blockedItem(item), }); } } hits.sort((a, b) => a.depth - b.depth); - for (const hit of hits) delete hit.depth; - return hits; + const looked = depth === undefined ? hits : hits.slice(0, depth); + const out = looked.filter((hit) => !hit.blocked); + for (const hit of out) { + delete hit.depth; + delete hit.blocked; + } + return out; } /** @@ -869,8 +886,8 @@ export function createStubRenderer(options = {}) { return hitsAt(x, y, win)[0] ?? surfaceHit(x, y); }, drillPick(x, y, opts = {}) { - const hits = hitsAt(x, y, opts); - return opts.limit === undefined ? hits : hits.slice(0, opts.limit); + if (opts.limit === undefined) return hitsAt(x, y, opts); + return hitsAt(x, y, opts, Math.max(opts.limit, 16)).slice(0, opts.limit); }, pickPosition(x, y) { if (!capabilities.has('pickPosition')) return null; @@ -962,7 +979,7 @@ export function createStubRenderer(options = {}) { const hits = () => (picked ??= hitsAt(x, y)); ev.pick = () => hits()[0] ?? surfaceHit(x, y); ev.drill = (opts = {}) => - opts.limit === undefined ? hits().slice() : hits().slice(0, opts.limit); + opts.limit === undefined ? hits().slice() : query.drillPick(x, y, opts); ev.ground = () => rayEllipsoid(pickRay(x, y)); } router.dispatch(ev);