/** * Safari/Firefox-compatible BVH closest point implementation for point clouds with direction output. * * Extended version of bvhClosestPointToPoints.js that returns both distance * and direction to the closest point for use in constraint systems. * * Returns vec4(distance, directionX, directionY, directionZ) where direction * points FROM the closest surface point TOWARD the query point (outward normal). */ import type { NodeBuilder } from 'three/webgpu'; import type { TSLFloatNode, TSLFunction, TSLStorageNode, TSLVec3Node, TSLVec4Node } from '../../types/tsl.js'; export interface DirectionDistanceSqToBoundsParameters { point: TSLVec3Node; boundsMin: TSLVec3Node; boundsMax: TSLVec3Node; } export interface DirectionDistanceSqToBoundsWGSLFunction { (parameters: DirectionDistanceSqToBoundsParameters): TSLFloatNode; build(builder: NodeBuilder): void; } export type PointsBVHClosestPointWithDirectionArguments = [ point: TSLVec3Node, maxDistance: TSLFloatNode ]; export type PointsBVHClosestPointWithDirectionFunction = TSLFunction; /** * Computes the squared distance from a point to an AABB. */ export declare const distanceSqToBoundsWGSL: DirectionDistanceSqToBoundsWGSLFunction; /** * Creates a PointsBVH closest point function that returns distance AND direction. * * This extended version is designed for constraint systems where you need * both the penetration depth and the push direction. * * For point clouds, the "normal" is computed as the direction from the * closest point to the query point (normalized). * * 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 closest point with direction */ export declare function createPointsBVHClosestPointWithDirectionFn(bvhIndexBuffer: TSLStorageNode<'uint'>, bvhPositionBuffer: TSLStorageNode<'vec3'>, bvhNodeBuffer: TSLStorageNode<'float'>): PointsBVHClosestPointWithDirectionFunction;