InstancedMeshBVH
Defined in: core/InstancedMeshBVH.ts:47
Class to manage BVH (Bounding Volume Hierarchy) for InstancedMesh2
.
Provides methods for managing bounding volumes, frustum culling, raycasting, and bounding box computation.
Constructors
new InstancedMeshBVH()
new InstancedMeshBVH(
target
,margin
,getBBoxFromBSphere
,accurateCulling
):InstancedMeshBVH
Defined in: core/InstancedMeshBVH.ts:84
Parameters
target
The target InstancedMesh2
.
margin
number
= 0
The margin applied for bounding box calculations (default is 0).
getBBoxFromBSphere
boolean
= false
Flag to determine if instance bounding boxes should be computed from the geometry bounding sphere. Faster but less precise (default is false).
accurateCulling
boolean
= true
Flag to enable accurate frustum culling without considering margin (default is true).
Returns
Properties
accurateCulling
accurateCulling:
boolean
Defined in: core/InstancedMeshBVH.ts:67
Enables accurate frustum culling by checking intersections without applying margin to the bounding box.
bvh
bvh:
BVH
<{},number
>
Defined in: core/InstancedMeshBVH.ts:59
The BVH instance used to organize bounding volumes.
geoBoundingBox
geoBoundingBox:
Box3
Defined in: core/InstancedMeshBVH.ts:55
The geometry bounding box of the target.
nodesMap
nodesMap:
Map
<number
,BVHNode
<{},number
>>
Defined in: core/InstancedMeshBVH.ts:63
A map that stores the BVH nodes for each instance.
target
target:
InstancedMesh2
Defined in: core/InstancedMeshBVH.ts:51
The target InstancedMesh2
object that the BVH is managing.
Methods
clear()
clear():
void
Defined in: core/InstancedMeshBVH.ts:190
Clears the BVH.
Returns
void
create()
create():
void
Defined in: core/InstancedMeshBVH.ts:118
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.
Returns
void
delete()
delete(
id
):void
Defined in: core/InstancedMeshBVH.ts:180
Deletes an instance from the BVH.
Parameters
id
number
The id of the instance to delete.
Returns
void
frustumCulling()
frustumCulling(
projScreenMatrix
,onFrustumIntersection
):void
Defined in: core/InstancedMeshBVH.ts:200
Performs frustum culling to determine which instances are visible based on the provided projection matrix.
Parameters
projScreenMatrix
Matrix4
The projection screen matrix for frustum culling.
onFrustumIntersection
onFrustumIntersectionCallback
<{}, number
>
Callback function invoked when an instance intersects the frustum.
Returns
void
frustumCullingLOD()
frustumCullingLOD(
projScreenMatrix
,cameraPosition
,levels
,onFrustumIntersection
):void
Defined in: core/InstancedMeshBVH.ts:219
Performs frustum culling with Level of Detail (LOD) consideration.
Parameters
projScreenMatrix
Matrix4
The projection screen matrix for frustum culling.
cameraPosition
Vector3
The camera’s position used for LOD calculations.
levels
LODLevel
<{}>[]
An array of LOD levels.
onFrustumIntersection
onFrustumIntersectionLODCallback
<{}, number
>
Callback function invoked when an instance intersects the frustum.
Returns
void
insert()
insert(
id
):void
Defined in: core/InstancedMeshBVH.ts:143
Inserts an instance into the BVH.
Parameters
id
number
The id of the instance to insert.
Returns
void
insertRange()
insertRange(
ids
):void
Defined in: core/InstancedMeshBVH.ts:152
Inserts a range of instances into the BVH.
Parameters
ids
number
[]
An array of ids to insert.
Returns
void
intersectBox()
intersectBox(
target
,onIntersection
):boolean
Defined in: core/InstancedMeshBVH.ts:268
Checks if a given box intersects with any instance bounding box.
Parameters
target
Box3
The target bounding box.
onIntersection
onIntersectionCallback
<number
>
Callback function invoked when an intersection occurs.
Returns
boolean
True
if there is an intersection, otherwise false
.
move()
move(
id
):void
Defined in: core/InstancedMeshBVH.ts:169
Moves an instance within the BVH.
Parameters
id
number
The id of the instance to move.
Returns
void
raycast()
raycast(
raycaster
,onIntersection
):void
Defined in: core/InstancedMeshBVH.ts:250
Performs raycasting to check if a ray intersects any instances.
Parameters
raycaster
Raycaster
The raycaster used for raycasting.
onIntersection
onIntersectionRayCallback
<number
>
Callback function invoked when a ray intersects an instance.
Returns
void