/** * GPU screen-space picking for `SplatMesh`. * * Picking renders the splats once more into a 1×1 target, with a * material that writes linear view depth instead of color; the depth comes back * through an async readback and unprojects to a world point. That needs a whole * subsystem of its own - a render target, a proxy mesh, a private scene, saved * renderer state - none of which the mesh itself ever touches, so it lives here * rather than as ten more fields on an already large class. * * The picker reaches back into the mesh through {@link SplatPickHost} rather * than holding the mesh itself: the four things it needs are otherwise private, * and widening them for the picker would put them in the published .d.ts. * * Internal. Nothing here is exported from `index.ts`. */ import * as THREE from 'three/webgpu'; import type { SplatPickOptions, SplatPickResult } from './splat-mesh'; import type { FloatUniform } from './splat-mesh-material'; /** What the picker needs from the mesh it picks. */ export interface SplatPickHost { /** The mesh, for the transform/visibility the proxy mirrors and its geometry. */ readonly mesh: THREE.Mesh; isDisposed(): boolean; getActiveCount(): number; /** The mesh's live viewport uniform value, in drawing-buffer pixels. */ getViewportSize(): THREE.Vector2; /** Visibility as resolved by an owning unified renderer, when any. */ getPickVisible(): boolean; /** Whether a sorter exists. A pick never creates one - see {@link prepare}. */ hasSorter(): boolean; /** Pick from the full active list instead of the display's GPU-culled list. */ usesUnculledPickList(): boolean; updateWorldMatrix(): void; /** * Brings the GPU to the state `update()` would leave it in: flush pending * uploads, refresh the projection uniforms, and refresh an existing sorter's * draw list. Ordering matters, so the mesh owns it. */ prepare(camera: THREE.Camera, renderer: THREE.WebGPURenderer): void; /** * Writes focal / viewport / local-camera uniforms for a camera drawing into * a viewport of `width`×`height` pixels. The pick pass crops the frustum to * one source pixel and renders into a 1×1 target, so it must rewrite these * after the crop and restore the canvas-sized values before returning. */ setView(camera: THREE.Camera, width: number, height: number): void; /** Captures the live display uniforms; restoration does not recompute a stale camera. */ captureView(): () => void; /** Builds the pick-mode TSL graph onto a freshly created material. */ applyPickGraph(material: THREE.NodeMaterial): void; } /** * The mesh's active list: a storage buffer that also steps once per instance. * * Unified and compute-projection sources pick by reading this list at * `instanceIndex`. WebGL2 has no storage buffers, so three binds that read as * a plain vertex attribute and drops the element index: without an instance * divisor every pick instance read rows 0-3 by vertex, and the pass drew one * wrong quad instead of the source (a pooled tenant then never hit, or hit * everywhere). The flags only set that divisor. WebGPU binds the buffer as * storage, where they have no effect. */ export declare const createActiveIndexAttribute: (count: number) => THREE.StorageBufferAttribute; /** * Owns the pick pass and everything it allocates. Resources are created on the * first pick, so a mesh that is never picked pays nothing. */ export declare class SplatPicker { private readonly host; /** Alpha below which a splat is transparent enough to pick through. */ private readonly alphaThreshold; /** Camera planes for the pick material's depth encoding. */ private readonly near; private readonly far; private material; private proxy; private unculledGeometry; private target; /** Renderer/material pair whose validation scopes compileAsync has drained. */ private compiledRenderer; private compiledMaterialVersion; /** In-flight validation shared by render-only preparation and the first pick. */ private compilation; /** Reused sub-frustum camera; preserves the caller's concrete camera type. */ private pickCamera; private readonly scene; /** Serializes picks: they share one render target and one renderer. */ private queue; private readonly point; private readonly savedClearColor; constructor(host: SplatPickHost); /** The pick uniforms the material graph binds. */ get uniforms(): { alphaThreshold: FloatUniform; near: FloatUniform; far: FloatUniform; }; pick(ndc: THREE.Vector2, camera: THREE.Camera, renderer: THREE.WebGPURenderer, options?: SplatPickOptions): Promise; /** Runs one bounded pick pass for an ordered set of screen coordinates. */ pickMany(ndcs: readonly THREE.Vector2[], camera: THREE.Camera, renderer: THREE.WebGPURenderer, options?: SplatPickOptions): Promise; /** * Builds and validates the lazy pick bindings while CPU storage still exists. * * Three's `NodeStorageBuffer` captures `attribute.array` while compiling a * new material. Render-only meshes replace that array with a zero-length * mirror after upload, so compiling the pick material afterwards can create * an invalid WebGPU binding on strict backends such as SwiftShader. The mesh * awaits this preparation before releasing those mirrors. */ prepareForCpuRelease(camera: THREE.Camera, renderer: THREE.WebGPURenderer): Promise; /** Rebuilds the pick graph after a settings change. No-op before the first pick. */ rebuildMaterial(): void; /** Flags the pick graph for recompile (e.g. the modifier list changed). */ markNeedsUpdate(): void; dispose(): void; private runMany; private ensureResources; /** Compiles for the pick target while restoring renderer state before the first async yield. */ private compilePipeline; /** Maps a source framebuffer rectangle onto the complete pick target. */ private cropCameraToRect; }