AccelerationStructure
Thin wrapper around the three-mesh-bvh library’s MeshBVH class with some additional specific functionality.
The viewer is using three-mesh-bvh as the backbone for it’s BVH implementation. The AccelerationStructure class is a thin wrapper around the library’s MeshBVH class with some additional specific functionality.
The speckle viewer uses a dual level BVH for optimal acceleration. The
AccelerationStructure
is the functional element of the bottom-level acceleration
structure. Each individual object will have it’s own BVH, encapsulated by an
AccelerationStructure
object.
Constructors
constructor
Populates/constructs this acceleration structure with the backing BVH.
Parameters
- bvh: The backing BVH as a MeshBVH
Accessors
bvh
Gets the backing BVH.
Returns: MeshBVH
geometry
Gets the three.js geometry associated to the BVH.
When building a BVH, three-mesh-bvh library needs a three.js geometry as input. This is that geometry. We don’t use it for rendering.
Returns: BufferGeometry
Methods
buildBVH
Build a BVH using the provided geometry data.
Parameters
- indices: Geometry indices
- position: Geometry vertex positions
- options: BVHOptions
- optional transform: A Matrix4 that transforms the geometry data before building the BVH
Returns: MeshBVH
getBoundingBox
Gets the aabb of the entire BVH.
Parameters
- optional target: Box3
Returns: Box3
getVertexAtIndex
Gets position value of a vertex at the given index inside the BVH vertex position array.
Parameters
- index: number
Returns: Vector3
raycast
Wrapper over three-mesh-bvh raycast function. Keeps original behavior,but makes sure input and output spaces are correct.
Parameters
- ray: Ray to intersect with
- materialOrSide: Side | Material | Material[]
Returns: Intersection
raycastFirst
Identical to raycast
but stops at first intersection found.
Parameters
- ray: Ray to intersect with
- materialOrSide: Side | Material | Material[]
Returns: Intersection
shapecast
Generic mechanism to intersect the BVH with various shapes/objects. The callbacks provide granular access to several stages of the BVH intersection process.
Parameters
- callbacks: More details here
Returns: boolean
transformInput
Transform input vector, ray or box from world space into the acceleration structure’s space.
All the AccelerationStructure methods that deal with querying the BVH: getBoundingBox, getVertexAtIndex, raycast, raycastFirst, shapecast already call this function implicitly.
Parameters
transformOutput
Transform input vector, ray or box from the acceleration structure’s space into world space.
Parameters
- input: Vector3 | Ray | Box3
All the AccelerationStructure methods that deal with querying the BVH: getBoundingBox, getVertexAtIndex, raycast, raycastFirst, shapecast already call this function implicitly.
Typedefs
VectorLike
Archtype for Vector2, Vector3 and Vector4.
BVHOptions
Based off the original options defined in three-mesh-bvh