
Mirror Engine API / BoundingBox
Class: BoundingBox
Axis-Aligned Bounding Box.
Constructors
new BoundingBox()
new BoundingBox(center?: Vec3, halfExtents?: Vec3): BoundingBox
Create a new BoundingBox instance. The bounding box is axis-aligned.
Parameters
center?
Center of box. The constructor takes a reference of this parameter. Defaults to (0, 0, 0).
halfExtents?
Half the distance across the box in each axis. The constructor takes a reference of this parameter. Defaults to (0.5, 0.5, 0.5).
Returns
Properties
center
readonly center: Vec3;
Center of box.
halfExtents
readonly halfExtents: Vec3;
Half the distance across the box in each axis.
Methods
add()
add(other: BoundingBox): void
Combines two bounding boxes into one, enclosing both.
Parameters
other
Bounding box to add.
Returns
void
clone()
clone(): BoundingBox
Returns a clone of the AABB.
Returns
A duplicate AABB.
compute()
compute(vertices:
| number[]
| Float32Array<ArrayBufferLike>, numVerts?: number): void
Compute the size of the AABB to encapsulate all specified vertices.
Parameters
vertices
The vertices used to compute the new size for the AABB.
number
[] | Float32Array
<ArrayBufferLike
>
numVerts?
number
Number of vertices to use from the beginning of vertices array. All vertices are used if not specified.
Returns
void
containsPoint()
containsPoint(point: Vec3): boolean
Test if a point is inside a AABB.
Parameters
point
Point to test.
Returns
boolean
True if the point is inside the AABB and false otherwise.
copy()
copy(src: BoundingBox): void
Copies the contents of a source AABB.
Parameters
src
The AABB to copy from.
Returns
void
getMax()
getMax(): Vec3
Return the maximum corner of the AABB.
Returns
Maximum corner.
getMin()
getMin(): Vec3
Return the minimum corner of the AABB.
Returns
Minimum corner.
intersects()
intersects(other: BoundingBox): boolean
Test whether two axis-aligned bounding boxes intersect.
Parameters
other
Bounding box to test against.
Returns
boolean
True if there is an intersection.
intersectsBoundingSphere()
intersectsBoundingSphere(sphere: BoundingSphere): boolean
Test if a Bounding Sphere is overlapping, enveloping, or inside this AABB.
Parameters
sphere
Bounding Sphere to test.
Returns
boolean
True if the Bounding Sphere is overlapping, enveloping, or inside the AABB and false otherwise.
intersectsRay()
intersectsRay(ray: Ray, point?: Vec3): boolean
Test if a ray intersects with the AABB.
Parameters
ray
Ray to test against (direction must be normalized).
point?
If there is an intersection, the intersection point will be copied into here.
Returns
boolean
True if there is an intersection.
setFromTransformedAabb()
setFromTransformedAabb(
aabb: BoundingBox,
m: Mat4,
ignoreScale: boolean): void
Set an AABB to enclose the specified AABB if it were to be transformed by the specified 4x4 matrix.
Parameters
aabb
Box to transform and enclose.
m
Transformation matrix to apply to source AABB.
ignoreScale
boolean
= false
If true is specified, a scale from the matrix is ignored. Defaults to false.
Returns
void
setMinMax()
setMinMax(min: Vec3, max: Vec3): void
Sets the minimum and maximum corner of the AABB. Using this function is faster than assigning min and max separately.
Parameters
min
The minimum corner of the AABB.
max
The maximum corner of the AABB.
Returns
void
computeMinMax()
static computeMinMax(
vertices:
| number[]
| Float32Array<ArrayBufferLike>,
min: Vec3,
max: Vec3,
numVerts?: number): void
Compute the min and max bounding values to encapsulate all specified vertices.
Parameters
vertices
The vertices used to compute the new size for the AABB.
number
[] | Float32Array
<ArrayBufferLike
>
min
Stored computed min value.
max
Stored computed max value.
numVerts?
number
= ...
Number of vertices to use from the beginning of vertices array. All vertices are used if not specified.
Returns
void