/** * Stable public entry point for the Instance Culling product block. * @module three-blocks/instance-culling */ import type { BufferAttribute, BufferGeometry, Camera, Mesh, Node, Renderer, Sphere, StorageBufferAttribute, StorageInstancedBufferAttribute, TypedArray, Vector4 } from 'three/webgpu'; /** GPU storage attributes accepted as culling inputs. */ export type ComputeInstanceCullingStorageAttribute = StorageBufferAttribute | StorageInstancedBufferAttribute; /** CPU or GPU attribute data accepted as a culling source. */ export type ComputeInstanceCullingBufferSource = BufferAttribute | ComputeInstanceCullingStorageAttribute | TypedArray; /** Local-space sphere accepted by instance-culling configuration. */ export interface ComputeInstanceCullingBoundingSphere { /** Local-space center. */ readonly center: { readonly x: number; readonly y: number; readonly z: number; }; /** Non-negative local-space radius. */ readonly radius: number; } /** Read-only CPU snapshot returned for one configured instance bound. */ export interface ComputeInstanceCullingBoundingSphereResult { /** Copied local-space center components. */ readonly center: { readonly x: number | undefined; readonly y: number | undefined; readonly z: number | undefined; }; /** Copied radius. */ readonly radius: number | undefined; } /** Configuration shared by mesh-bound and standalone cullers. */ export interface ComputeInstanceCullingCommonOptions { /** Number of source instances. */ count?: number | undefined; /** Index count written into the indirect draw command. */ indexCount?: number | undefined; /** Instance matrices or storage used as the primary culling source. */ instanceMatrixStorage?: ComputeInstanceCullingBufferSource | null | undefined; /** Positions used when complete matrices are not available. */ refPosition?: ComputeInstanceCullingBufferSource | null | undefined; /** Optional normals associated with reference positions. */ refNormal?: ComputeInstanceCullingBufferSource | null | undefined; /** Whether frustum and LOD rejection is enabled initially. */ enabled?: boolean | undefined; /** Whether translucent survivors may be depth-sorted. */ sortObjects?: boolean | undefined; /** Force sorting even when the attached material does not request it. */ forceSort?: boolean | undefined; /** Normalized horizontal and vertical frustum padding. */ frustumPadXY?: number | undefined; /** Near-plane frustum padding. */ frustumPadZNear?: number | undefined; /** Far-plane frustum padding. */ frustumPadZFar?: number | undefined; /** Shared local-space bound used for conservative visibility testing. */ boundingSphere?: ComputeInstanceCullingBoundingSphere | Sphere | null | undefined; /** Allocate and test a separate bounding sphere for every instance. */ perInstanceBoundingBox?: boolean | undefined; /** Optional caller-provided vec4 sphere storage. */ boundingSpheresStorage?: ComputeInstanceCullingBufferSource | null | undefined; } /** Optional overrides for the `(mesh, renderer, options)` constructor. */ export interface ComputeInstanceCullingMeshOptions extends ComputeInstanceCullingCommonOptions { /** Use the mesh instance-matrix attribute as the culling source. */ useInstanceMatrix?: boolean | undefined; } /** Base configuration for a standalone culler. */ export interface ComputeInstanceCullingStandaloneOptions extends ComputeInstanceCullingCommonOptions { /** WebGPU renderer that submits culling and releases associated resources. */ renderer: Renderer; } /** Standalone configuration requiring a matrix or position source. */ export type ComputeInstanceCullingOptions = ComputeInstanceCullingStandaloneOptions & ({ instanceMatrixStorage: ComputeInstanceCullingBufferSource; refPosition?: ComputeInstanceCullingBufferSource | null | undefined; } | { refPosition: ComputeInstanceCullingBufferSource; instanceMatrixStorage?: ComputeInstanceCullingBufferSource | null | undefined; }); /** CPU sphere data accepted when deriving a shared conservative bound. */ export type ComputeInstanceCullingBoundsData = TypedArray | readonly ComputeInstanceCullingBoundingSphere[]; interface InstanceCullingConstructor { /** Construct a culler bound to a caller-owned mesh and renderer. */ new (mesh: Mesh, renderer: Renderer, options?: ComputeInstanceCullingMeshOptions): ComputeInstanceCulling; /** Construct a standalone culler from explicit renderer and storage inputs. */ new (options: ComputeInstanceCullingOptions): ComputeInstanceCulling; readonly prototype: ComputeInstanceCulling; } /** * Stable GPU frustum-culling facade for a Three.js mesh or standalone instance * source. Construction requires WebGPU and at least one matrix or position * source; inconsistent counts, missing renderer support, or unusable geometry * throw before the culler is ready. The culler owns its compacted-ID, indirect, * sorting, and optional bounds buffers but never owns the source mesh, geometry, * camera, or renderer. Mesh construction installs automatic pre-render updates; * standalone use must call {@link ComputeInstanceCulling.setCameraUniforms} after * camera controls and {@link ComputeInstanceCulling.update} before rendering. * Readback methods allocate caller-owned diagnostic snapshots. Call * {@link ComputeInstanceCulling.dispose} when the culler is detached; do not use * the instance afterward. */ export interface ComputeInstanceCulling { /** Runtime type guard for the stable culling facade. */ readonly isComputeInstanceCulling: true; /** Copy camera matrices after controls update and before the culling dispatch. */ setCameraUniforms(camera: Camera): void; /** Submit culling after camera/source updates and before rendering the target geometry. */ update(): void; /** Bind the culler-owned indirect draw command to caller-owned geometry. */ attachGeometry(geometry: BufferGeometry): void; /** Retain a caller-owned mesh reference for material-aware sorting and cleanup. */ attachMesh(mesh: Mesh): void; /** Copy the five indirect draw arguments into a caller-owned diagnostic snapshot. */ readIndirectArgs(): Promise; /** Copy surviving source IDs into a caller-owned diagnostic snapshot. */ readSurvivorIndicesAsync(): Promise; /** Update one local-space bound when per-instance bounds are enabled. */ setBoundingSphereAt(instanceIndex: number, center: { readonly x: number; readonly y: number; readonly z: number; }, radius: number): void; /** Read one local-space bound without exposing the underlying storage buffer. */ getBoundingSphereAt(instanceIndex: number, target?: Vector4): ComputeInstanceCullingBoundingSphereResult | null; /** Derive one conservative shared bound from per-instance sphere data. */ setMaxBoundingSphere(boundsData: ComputeInstanceCullingBoundsData): void; /** Allocate or replace culler-owned vec4 storage for per-instance bounds. */ initBoundingSpheresStorage(data?: Float32Array): void; /** Release culler-owned GPU resources and remove installed mesh hooks. */ dispose(): void; } /** Runtime-identical constructor for the narrow stable instance-culling facade. */ export declare const ComputeInstanceCulling: InstanceCullingConstructor; export { LOD_MODE_EXP } from './Compute/LODConstants.js'; /** * Return the original source-instance ID selected by a culling facade. */ export declare const instanceCullingIndex: (culler: ComputeInstanceCulling | null | undefined) => Node<"uint">; /** * Return a source instance matrix selected through a culling facade. */ export declare const instanceCullingMatrix: (culler: ComputeInstanceCulling | null | undefined, idNode?: Node<"int"> | Node<"uint">) => Node<"mat4"> | null;