import * as THREE from 'three/webgpu'; import type { ComputeNode, Renderer, StorageBufferNode, UniformNode } from 'three/webgpu'; import type { GeometryBVH } from 'three-mesh-bvh' with { "resolution-mode": "import" }; import type { BVHComputeData } from 'three-mesh-bvh/webgpu' with { "resolution-mode": "import" }; /** Supported direct-query BVH constraint modes. */ export type BVHVolumeConstraintMode = 'triangles' | 'points'; type BVHParticleStorageType = 'float' | 'vec3'; /** Particle buffer attributes or existing TSL storage nodes. */ export type BVHParticleStorageInput = THREE.BufferAttribute | StorageBufferNode; /** Runtime BVH data accepted explicitly or through `geometry.boundsTree`. */ export type BVHVolumeData = GeometryBVH; /** Common fluid calibration used by triangle and point-cloud density support. */ export interface BVHBoundaryDensityOptionsBase { particleCount: number; mass: number; poly6: number; h2: number; particleRadius: number; particleSpacing: number; is3D?: boolean; boundsMatrix?: THREE.Matrix4; inverseBoundsMatrix?: THREE.Matrix4; } /** Triangle-BVH mirrored density-support controls. */ export interface BVHBoundaryDensityPassOptions extends BVHBoundaryDensityOptionsBase { threshold?: number; maxSearchDistance?: number; containment?: boolean; } /** Point-cloud BVH mirrored density-support controls. */ export interface PointsBVHBoundaryDensityPassOptions extends BVHBoundaryDensityOptionsBase { h: number; pointRadius?: number; } /** Common uniforms attached to BVH mirrored density-support passes. */ export interface BVHBoundaryDensityUniformsBase { boundsMatrix: UniformNode<'mat4', THREE.Matrix4>; inverseBoundsMatrix: UniformNode<'mat4', THREE.Matrix4>; mass: UniformNode<'float', number>; poly6: UniformNode<'float', number>; h2: UniformNode<'float', number>; particleRadius: UniformNode<'float', number>; particleSpacing: UniformNode<'float', number>; } /** Triangle-BVH density-support uniforms. */ export interface BVHBoundaryDensityUniforms extends BVHBoundaryDensityUniformsBase { threshold: UniformNode<'float', number>; maxSearchDistance: UniformNode<'float', number>; containment: UniformNode<'uint', number>; } /** Point-cloud BVH density-support uniforms. */ export interface PointsBVHBoundaryDensityUniforms extends BVHBoundaryDensityUniformsBase { h: UniformNode<'float', number>; pointRadius: UniformNode<'float', number>; } /** Triangle-BVH density-support compute pass. */ export interface BVHBoundaryDensityPass extends ComputeNode { uniforms: BVHBoundaryDensityUniforms; } /** Point-cloud BVH density-support compute pass. */ export interface PointsBVHBoundaryDensityPass extends ComputeNode { uniforms: PointsBVHBoundaryDensityUniforms; } /** Common particle boundary response controls. */ export interface BVHBoundaryPassOptionsBase { particleCount: number; stiffness?: number; damping?: number; maxSearchDistance?: number; boundsMatrix?: THREE.Matrix4; inverseBoundsMatrix?: THREE.Matrix4; positionCorrection?: boolean; velocityResponse?: boolean; hardProjection?: boolean; } /** Triangle-BVH particle boundary controls. */ export interface BVHBoundaryPassOptions extends BVHBoundaryPassOptionsBase { threshold?: number; containment?: boolean; } /** Point-cloud BVH particle boundary controls. */ export interface PointsBVHBoundaryPassOptions extends BVHBoundaryPassOptionsBase { pointRadius?: number; } /** Common uniforms attached to BVH particle boundary passes. */ export interface BVHBoundaryUniformsBase { boundsMatrix: UniformNode<'mat4', THREE.Matrix4>; inverseBoundsMatrix: UniformNode<'mat4', THREE.Matrix4>; stiffness: UniformNode<'float', number>; damping: UniformNode<'float', number>; maxSearchDistance: UniformNode<'float', number>; positionCorrection: UniformNode<'uint', number>; velocityResponse: UniformNode<'uint', number>; hardProjection: UniformNode<'uint', number>; } /** Triangle-BVH particle boundary uniforms. */ export interface BVHBoundaryUniforms extends BVHBoundaryUniformsBase { threshold: UniformNode<'float', number>; containment: UniformNode<'float', number>; } /** Point-cloud BVH particle boundary uniforms. */ export interface PointsBVHBoundaryUniforms extends BVHBoundaryUniformsBase { pointRadius: UniformNode<'float', number>; } /** Triangle-BVH particle boundary compute pass. */ export interface BVHBoundaryPass extends ComputeNode { uniforms: BVHBoundaryUniforms; } /** Point-cloud BVH particle boundary compute pass. */ export interface PointsBVHBoundaryPass extends ComputeNode { uniforms: PointsBVHBoundaryUniforms; } /** Construction controls for {@link BVHVolumeConstraint}. */ export interface BVHVolumeConstraintOptions { geometry: THREE.BufferGeometry; bvh?: BVHVolumeData | null; mode?: BVHVolumeConstraintMode; stiffness?: number; damping?: number; threshold?: number; pointRadius?: number; maxSearchDistance?: number; containment?: boolean; worldMatrix?: THREE.Matrix4 | null; } /** Per-dispatch scheduling controls shared by triangle and point modes. */ export interface BVHBoundaryApplyOptions { particleRadius?: number; positionOnly?: boolean; velocityOnly?: boolean; hardProjection?: boolean; } /** Numeric fluid calibration value consumed by BVH density support. */ export interface BVHScalarControl { value: number; } /** Fluid calibration surface used by mirrored BVH density support. */ export interface BVHDensityFluid { buffers: { positions: BVHParticleStorageInput<'vec3'>; densities: BVHParticleStorageInput<'float'>; }; particleCount: number; ubos: { mass: BVHScalarControl; poly6Kernel: BVHScalarControl; h: BVHScalarControl; h2: BVHScalarControl; }; particleRadius: number; _particleSpacing: number; is3D: boolean; } /** Create mirrored ghost-particle density support for a triangle-BVH boundary. */ export declare function createBVHBoundaryDensityPass(positionsBuffer: BVHParticleStorageInput<'vec3'>, densitiesBuffer: BVHParticleStorageInput<'float'>, bvhData: BVHComputeData, options: BVHBoundaryDensityPassOptions): BVHBoundaryDensityPass; /** @deprecated Pass an initialized `BVHComputeData` instance instead of separate packed buffers. */ export declare function createBVHBoundaryDensityPass(positionsBuffer: BVHParticleStorageInput<'vec3'>, densitiesBuffer: BVHParticleStorageInput<'float'>, bvhIndexBuffer: THREE.BufferAttribute, bvhPositionBuffer: THREE.BufferAttribute, bvhNodeBuffer: THREE.BufferAttribute, options?: Partial): BVHBoundaryDensityPass; /** Create locally mirrored density support around a point-cloud BVH virtual surface. */ export declare function createPointsBVHBoundaryDensityPass(positionsBuffer: BVHParticleStorageInput<'vec3'>, densitiesBuffer: BVHParticleStorageInput<'float'>, bvhIndexBuffer: THREE.BufferAttribute, bvhPositionBuffer: THREE.BufferAttribute, bvhNodeBuffer: THREE.BufferAttribute, options: PointsBVHBoundaryDensityPassOptions): PointsBVHBoundaryDensityPass; /** * Creates a compute pass that enforces BVH volume boundary constraints for particle simulations. * * Uses direct BVH queries (no SDF precomputation) for real-time particle-mesh containment. * Applies penalty forces to particles that penetrate or escape the BVH boundary. * * **Use Cases:** * - PBF/SPH simulations contained within arbitrary meshes * - Boids flocking inside/outside mesh volumes * - Particle systems with dynamic mesh boundaries * * This implementation-level API is intentionally internal and has no public package import. */ export declare function createBVHBoundaryPass(positionsBuffer: BVHParticleStorageInput<'vec3'>, velocitiesBuffer: BVHParticleStorageInput<'vec3'>, bvhData: BVHComputeData, options: BVHBoundaryPassOptions): BVHBoundaryPass; /** @deprecated Pass an initialized `BVHComputeData` instance instead of separate packed buffers. */ export declare function createBVHBoundaryPass(positionsBuffer: BVHParticleStorageInput<'vec3'>, velocitiesBuffer: BVHParticleStorageInput<'vec3'>, bvhIndexBuffer: THREE.BufferAttribute, bvhPositionBuffer: THREE.BufferAttribute, bvhNodeBuffer: THREE.BufferAttribute, options?: Partial): BVHBoundaryPass; /** * Creates a compute pass for point cloud BVH boundary constraints. * Used for collision with point clouds (like Gaussian Splat centers). * * @function createPointsBVHBoundaryPass * @param {THREE.StorageBufferAttribute} positionsBuffer - Particle positions (vec3) * @param {THREE.StorageBufferAttribute} velocitiesBuffer - Particle velocities (vec3) * @param {THREE.StorageBufferAttribute} bvhIndexBuffer - BVH point indices (uint) * @param {THREE.StorageBufferAttribute} bvhPositionBuffer - BVH point positions (vec3) * @param {THREE.StorageBufferAttribute} bvhNodeBuffer - BVH node data (flat f32 array) * @param {Object} options - Configuration options * @param {number} options.particleCount - Number of particles * @param {number} [options.stiffness=1000.0] - Boundary stiffness coefficient * @param {number} [options.damping=0.5] - Velocity damping on collision * @param {number} [options.pointRadius=0.5] - Shell radius around each point * @param {number} [options.maxSearchDistance=10.0] - Maximum BVH search distance * @param {THREE.Matrix4} [options.boundsMatrix] - Local-to-world transform matrix * @param {THREE.Matrix4} [options.inverseBoundsMatrix] - World-to-local transform matrix * @returns {PointsBVHBoundaryPass} TSL compute node */ export declare function createPointsBVHBoundaryPass(positionsBuffer: BVHParticleStorageInput<'vec3'>, velocitiesBuffer: BVHParticleStorageInput<'vec3'>, bvhIndexBuffer: THREE.BufferAttribute, bvhPositionBuffer: THREE.BufferAttribute, bvhNodeBuffer: THREE.BufferAttribute, options: PointsBVHBoundaryPassOptions): PointsBVHBoundaryPass; /** * BVHVolumeConstraint - Direct BVH boundary constraint for particle simulations. * * Unlike SDFVolumeConstraint which requires SDF precomputation, this class queries * the BVH directly each frame. Best for dynamic meshes or when SDF resolution * would be prohibitively high. * * Supports two modes: * - `'triangles'` (default): For triangle meshes, uses signed distance for inside/outside detection * - `'points'`: For point clouds (like Gaussian Splat centers), uses pointRadius shell around each point * * @example * import { BVHVolumeConstraint } from 'three-blocks/sdf-raymarching'; * import { computeBoundsTree } from 'three-mesh-bvh'; * * // Triangle mesh constraint (containment) * geometry.computeBoundsTree(); * const containerConstraint = new BVHVolumeConstraint({ * geometry, * mode: 'triangles', * stiffness: 1000, * containment: true // Keep particles inside * }); * * // Point cloud constraint (collision with Gaussian Splats) * pointsGeometry.computeBoundsTree(); * const splatsConstraint = new BVHVolumeConstraint({ * geometry: pointsGeometry, * mode: 'points', * pointRadius: 0.5, // Shell thickness around each point * stiffness: 1000, * }); * * // In simulation loop * await containerConstraint.apply(renderer, positionsBuffer, velocitiesBuffer, particleCount); * await splatsConstraint.apply(renderer, positionsBuffer, velocitiesBuffer, particleCount); * * @class BVHVolumeConstraint * @short Direct BVH boundary constraint without SDF precomputation. * @category Simulation * @tags WebGPU, Physics, BVH */ export declare class BVHVolumeConstraint { geometry: THREE.BufferGeometry; bvh: BVHVolumeData; mode: BVHVolumeConstraintMode; stiffness: number; damping: number; threshold: number; pointRadius: number; maxSearchDistance: number; containment: boolean; boundsMatrix: THREE.Matrix4; inverseBoundsMatrix: THREE.Matrix4; private _computeNode; private _cachedParticleCount; private _cachedPositionsBuffer; private _cachedVelocitiesBuffer; private _indexBuffer; private _positionBuffer; private _nodeBuffer; private _bvhData; private _densityComputeNode; private _cachedDensityParticleCount; private _cachedDensityPositionsBuffer; private _cachedDensityBuffer; /** * Create a new BVH volume constraint. * * @param {BVHVolumeConstraintOptions} options - Configuration options * @param {THREE.BufferGeometry} options.geometry - Source geometry with BVH * @param {BVHVolumeData} [options.bvh] - BVH from three-mesh-bvh (auto-retrieved from geometry.boundsTree if not provided) * @param {BVHVolumeConstraintMode} [options.mode='triangles'] - Mode: 'triangles' for meshes, 'points' for point clouds * @param {number} [options.stiffness=1000.0] - Boundary stiffness * @param {number} [options.damping=0.5] - Velocity damping * @param {number} [options.threshold=0.0] - Distance threshold for triangles mode (positive = offset from surface) * @param {number} [options.pointRadius=0.5] - Shell radius for points mode * @param {number} [options.maxSearchDistance=10.0] - Maximum BVH search distance * @param {boolean} [options.containment=false] - For triangles mode: if true, keep particles INSIDE; if false, push OUT * @param {THREE.Matrix4} [options.worldMatrix] - World transformation matrix for the mesh */ constructor(options: BVHVolumeConstraintOptions); /** Add mirrored ghost density samples near triangle or point-cloud BVH surfaces. */ contributeDensity(renderer: Renderer, fluid: BVHDensityFluid): Promise; /** * Builds GPU storage buffers from BVH data. * @private */ private _buildBuffers; /** * Gets the index array from geometry. * @private * @param {THREE.BufferGeometry} geometry * @returns {Uint32Array} */ private _getIndexArray; /** * Gets the position array from geometry. * @private * @param {THREE.BufferGeometry} geometry * @returns {Float32Array} */ private _getPositionArray; /** * Sets the world transformation matrix for the BVH mesh. * * @param {THREE.Matrix4} matrix - World transformation matrix */ setWorldMatrix(matrix: THREE.Matrix4): void; /** * Applies the BVH boundary constraint to particle buffers. * * @param {THREE.WebGPURenderer} renderer - WebGPU renderer * @param {THREE.StorageBufferAttribute} positionsBuffer - Particle positions * @param {THREE.StorageBufferAttribute} velocitiesBuffer - Particle velocities * @param {number} particleCount - Number of particles * @param {Object} [options] - Scheduling options. * @param {number} [options.particleRadius=0] - Center offset from triangle surfaces or added point-shell radius. * @param {boolean} [options.positionOnly=false] - Apply position projection without velocity response. * @param {boolean} [options.velocityOnly=false] - Apply velocity response without position projection. * @param {boolean} [options.hardProjection=false] - Fully resolve penetration in one dispatch. * @returns {Promise} */ apply(renderer: Renderer, positionsBuffer: BVHParticleStorageInput<'vec3'>, velocitiesBuffer: BVHParticleStorageInput<'vec3'>, particleCount: number, options?: BVHBoundaryApplyOptions): Promise; /** * Updates the BVH data (for dynamic meshes). * * @param {THREE.BufferGeometry} geometry - Updated geometry * @param {BVHVolumeData} [bvh] - Updated BVH (auto-retrieved from geometry.boundsTree if not provided) */ updateBVH(geometry: THREE.BufferGeometry, bvh?: BVHVolumeData | null): void; /** * Disposes GPU resources. */ dispose(): void; } export {};