/** * Safari/Firefox-compatible BVH range query for point clouds with weighted normal accumulation. * * Unlike bvhClosestPointToPointsWithDirection.js which finds the single closest point, * this function finds ALL points within a given radius and accumulates weighted normals * for smooth collision response (matching the JS pointsCollide.js behavior). * * Returns vec4(maxPenetration, normalX, normalY, normalZ) where: * - maxPenetration: deepest penetration depth among all colliding points * - normal: weighted average of all collision normals (weight = depth²) * * @module three-blocks/Compute/bvh/bvhPointsRangeQuery */ import type { NodeBuilder } from 'three/webgpu'; import type { TSLFloatNode, TSLFunction, TSLStorageNode, TSLVec3Node, TSLVec4Node } from '../../types/tsl.js'; export interface RangeDistanceSqToBoundsParameters { point: TSLVec3Node; boundsMin: TSLVec3Node; boundsMax: TSLVec3Node; } export interface RangeDistanceSqToBoundsWGSLFunction { (parameters: RangeDistanceSqToBoundsParameters): TSLFloatNode; build(builder: NodeBuilder): void; } export type PointsBVHRangeQueryArguments = [ point: TSLVec3Node, queryRadius: TSLFloatNode ]; export type PointsBVHRangeQueryFunction = TSLFunction; /** * Computes the squared distance from a point to an AABB. */ export declare const distanceSqToBoundsWGSL: RangeDistanceSqToBoundsWGSLFunction; /** * Creates a PointsBVH range query function that returns accumulated weighted normals. * * This function is designed for constraint systems where particles collide with * multiple nearby points. Instead of responding to a single closest point (which * causes jittery behavior), it accumulates normals from ALL penetrating points * with quadratic weighting by penetration depth. * * Uses the TSL Fn() pattern which: * 1. Accesses storage buffers via .element() - generates NodeBuffer_XXX.value[i] syntax * 2. Avoids ptr in function signatures * 3. Works on Safari/Firefox WebGPU * * @param {StorageBufferNode} bvhIndexBuffer - Storage buffer for point indices (uint) * @param {StorageBufferNode} bvhPositionBuffer - Storage buffer for point positions (vec3f) * @param {StorageBufferNode} bvhNodeBuffer - Storage buffer for BVH nodes (flat f32 array) * @returns {Function} A TSL function that computes range query with weighted normals */ export declare function createPointsBVHRangeQueryFn(bvhIndexBuffer: TSLStorageNode<'uint'>, bvhPositionBuffer: TSLStorageNode<'vec3'>, bvhNodeBuffer: TSLStorageNode<'float'>): PointsBVHRangeQueryFunction;