# AccelerationStructure
The viewer is using three-mesh-bvh (opens new window) as the backbone for it's BVH implementation. The AccelerationStructure class is a thin wrapper around the library's MeshBVH (opens new window) 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 |
---|
# Accessors
bvh | geometry |
---|
# Methods
buildBVH | getBoundingBox | getVertexAtIndex | raycast |
---|---|---|---|
raycastFirst | shapecast | transformInput | transformOutput |
# Typedefs
VectorLike |
---|
# Constructors
# constructor
constructor(bvh: MeshBVH)
Populates/constructs this acceleration structure with the backing BVH.
Parameters
- bvh: The backing BVH as a MeshBVH (opens new window)
# Accessors
# bvh
get bvh(): MeshBVH
Gets the backing BVH.
Returns: MeshBVH (opens new window)
# geometry
get geometry(): BufferGeometry
Gets the three.js geometry associated to the BVH.
TIP
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 (opens new window)
# Methods
# buildBVH
static buildBVH(
indices: number[],
position: Float32Array,
options: BVHOptions = DefaultBVHOptions,
transform?: Matrix4
): MeshBVH
2
3
4
5
6
Build a BVH using the provided geometry data.
Parameters
- indices: Geometry indices
- position: Geometry vertex positions
- options: BVHOptions
- optional transform: A Matrix4 (opens new window) that transforms the geometry data before building the BVH
Returns: MeshBVH (opens new window)
# getBoundingBox
getBoundingBox(target?: Box3): Box3
Gets the aabb of the entire BVH.
Parameters
- optional target: Box3 (opens new window)
Returns: Box3 (opens new window)
# getVertexAtIndex
getVertexAtIndex(index: number): Vector3
Gets position value of a vertex at the given index inside the BVH vertex position array.
Parameters
- index: number
Returns: Vector3 (opens new window)
# raycast
raycast(
ray: Ray,
materialOrSide: Side | Material | Material[] = FrontSide
): Intersection<Object3D<Event>>[]
2
3
4
Wrapper over three-mesh-bvh raycast function. Keeps original behavior,but makes sure input and output spaces are correct.
Parameters
- ray: Ray (opens new window) to intersect with
- materialOrSide: Side (opens new window) | Material (opens new window) | Material[] (opens new window)
Returns: Intersection (opens new window)
# raycastFirst
raycastFirst(
ray: Ray,
materialOrSide: Side | Material | Material[] = FrontSide
): Intersection<Object3D<Event>>[]
2
3
4
Identical to raycast
but stops at first intersection found.
Parameters
- ray: Ray (opens new window) to intersect with
- materialOrSide: Side (opens new window) | Material (opens new window) | Material[] (opens new window)
Returns: Intersection (opens new window)
# shapecast
shapecast(
callbacks: {
intersectsBounds: (
box: Box3,
isLeaf: boolean,
score: number | undefined,
depth: number,
nodeIndex: number
) => ShapecastIntersection | boolean
traverseBoundsOrder?: (box: Box3) => number
} & (
| {
intersectsRange: (
triangleOffset: number,
triangleCount: number,
contained: boolean,
depth: number,
nodeIndex: number,
box: Box3
) => boolean
}
| {
intersectsTriangle: (
triangle: ExtendedTriangle,
triangleIndex: number,
contained: boolean,
depth: number
) => boolean | void
}
)
): boolean
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 (opens new window)
Returns: boolean
# transformInput
transformInput<T extends Vector3 | Ray | Box3>(input: T): T
Transform input vector, ray or box from world space into the acceleration structure's space.
WARNING
All the AccelerationStructure methods that deal with querying the BVH: getBoundingBox, getVertexAtIndex, raycast, raycastFirst, shapecast already call this function implicitly.
Parameters
Returns: Vector3 (opens new window) | Ray (opens new window) | Box3 (opens new window)
# transformOutput
transformOutput<T extends Vector3 | Ray | Box3>(output: T): T
Transform input vector, ray or box from the acceleration structure's space into world space.
Parameters
- input: Vector3 (opens new window) | Ray (opens new window) | Box3 (opens new window)
WARNING
All the AccelerationStructure methods that deal with querying the BVH: getBoundingBox, getVertexAtIndex, raycast, raycastFirst, shapecast already call this function implicitly.
Returns: Vector3 (opens new window) | Ray (opens new window) | Box3 (opens new window)
# Typedefs
# VectorLike
type VectorLike = { x: number; y: number; z?: number; w?: number };
Archtype for Vector2, Vector3 and Vector4.