/** * Safari/Firefox-compatible BVH closest point implementation for point clouds. * * Pointer-free storage traversal for PointsBVH from three-mesh-bvh. * Key differences from triangle queries: * - Index buffer stores uint (single point index) instead of uvec3 (triangle indices) * - No triangle closest point calculation - direct point-to-point distance * * The key insight is that Safari/Firefox's WebGPU implementation (naga validator) * rejects `ptr` as function parameters. This is part of the * `unrestricted_pointer_parameters` WGSL extension that only Chromium supports. * * Solution: Use TSL Fn() for the main compute entry point that accesses storage * buffers via .element(). The storage buffers become module-level bindings * and are accessed directly without passing pointers between functions. */ import type { NodeBuilder } from 'three/webgpu'; import type { TSLFloatNode, TSLFunction, TSLStorageNode, TSLVec3Node, TSLVec4Node } from '../../types/tsl.cjs'; export interface DistanceSqToBoundsParameters { point: TSLVec3Node; boundsMin: TSLVec3Node; boundsMax: TSLVec3Node; } export interface DistanceSqToBoundsWGSLFunction { (parameters: DistanceSqToBoundsParameters): TSLFloatNode; build(builder: NodeBuilder): void; } export type PointsBVHClosestPointArguments = [ point: TSLVec3Node, maxDistance: TSLFloatNode ]; export type PointsBVHClosestPointFunction = TSLFunction; /** * Computes the squared distance from a point to an AABB. */ export declare const distanceSqToBoundsWGSL: DistanceSqToBoundsWGSLFunction; /** * Creates a BVH closest point to point function for point clouds using TSL Fn(). * * This 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 distance */ export declare function createPointsBVHClosestPointFn(bvhIndexBuffer: TSLStorageNode<'uint'>, bvhPositionBuffer: TSLStorageNode<'vec3'>, bvhNodeBuffer: TSLStorageNode<'float'>): PointsBVHClosestPointFunction;