UNPKG

@three.ez/batched-mesh-extensions

Version:
91 lines 3.79 kB
import { BVH, onFrustumIntersectionCallback, onIntersectionCallback, onIntersectionRayCallback } from 'bvh.js'; import { BatchedMesh, Box3, CoordinateSystem, Matrix4, Raycaster } from 'three'; /** * Class to manage BVH (Bounding Volume Hierarchy) for `BatchedMesh`. * Provides methods for managing bounding volumes, frustum culling, raycasting, and bounding box computation. */ export declare class BatchedMeshBVH { /** * The target `BatchedMesh` object that the BVH is managing. */ target: BatchedMesh; /** * The BVH instance used to organize bounding volumes. */ bvh: BVH<{}, number>; /** * A map that stores the BVH nodes for each instance. */ nodesMap: Map<number, { box: import("bvh.js").FloatArray; parent?: /*elided*/ any; left?: /*elided*/ any; right?: /*elided*/ any; object?: number; }>; /** * Enables accurate frustum culling by checking intersections without applying margin to the bounding box. */ accurateCulling: boolean; protected _margin: number; protected _origin: Float32Array<ArrayBuffer>; protected _dir: Float32Array<ArrayBuffer>; protected _cameraPos: Float32Array<ArrayBuffer>; protected _boxArray: Float32Array<ArrayBuffer>; /** * @param target The target `BatchedMesh`. * @param margin The margin applied for bounding box calculations (default is 0). * @param accurateCulling Flag to enable accurate frustum culling without considering margin (default is true). */ constructor(target: BatchedMesh, coordinateSystem: CoordinateSystem, margin?: number, accurateCulling?: boolean); /** * Builds the BVH from the target mesh's instances using a top-down construction method. * This approach is more efficient and accurate compared to incremental methods, which add one instance at a time. */ create(): void; /** * Inserts an instance into the BVH. * @param id The id of the instance to insert. */ insert(id: number): void; /** * Inserts a range of instances into the BVH. * @param ids An array of ids to insert. */ insertRange(ids: number[]): void; /** * Moves an instance within the BVH. * @param id The id of the instance to move. */ move(id: number): void; /** * Deletes an instance from the BVH. * @param id The id of the instance to delete. */ delete(id: number): void; /** * Clears the BVH. */ clear(): void; /** * Performs frustum culling to determine which instances are visible based on the provided projection matrix. * @param projScreenMatrix The projection screen matrix for frustum culling. * @param onFrustumIntersection Callback function invoked when an instance intersects the frustum. */ frustumCulling(projScreenMatrix: Matrix4, onFrustumIntersection: onFrustumIntersectionCallback<{}, number>): void; /** * Performs raycasting to check if a ray intersects any instances. * @param raycaster The raycaster used for raycasting. * @param onIntersection Callback function invoked when a ray intersects an instance. */ raycast(raycaster: Raycaster, onIntersection: onIntersectionRayCallback<number>): void; /** * Checks if a given box intersects with any instance bounding box. * @param target The target bounding box. * @param onIntersection Callback function invoked when an intersection occurs. * @returns `True` if there is an intersection, otherwise `false`. */ intersectBox(target: Box3, onIntersection: onIntersectionCallback<number>): boolean; protected getBox(id: number, array: Float32Array): Float32Array; } //# sourceMappingURL=BatchedMeshBVH.d.ts.map