Box3

A 3D box represents by min and max.

Math Class

A 3D box represents by min and max.

Constructors

Constructor

new Box3(min?, max?): Box3

Parameters

min?

Vector3

max?

Vector3

Returns

Box3

Properties

min

min: Vector3

Vector3 representing the lower (x, y, z) boundary of the box.

Default Value

( + Infinity, + Infinity, + Infinity ).

max

max: Vector3

Vector3 representing the upper (x, y, z) boundary of the box.

Default Value

( - Infinity, - Infinity, - Infinity ).

planes

planes: Plane[]

An array of Planes represents the six faces of the box.


corners

corners: Vector3[]

The position of eight box’s vertexes.


isBox3

isBox3: boolean

Check the type whether it belongs to Box3. This value should not be changed by user.

Methods

set()

set(min, max): Box3

Sets the lower and upper (x, y, z) boundaries of this box.
Please note that this method only copies the values from the given objects.

Parameters

min

Vector3

Vector3 representing the lower (x, y, z) boundary of the box.

max

Vector3

Vector3 representing the lower upper (x, y, z) boundary of the box.

Returns

Box3


setFromArray()

setFromArray(array): Box3

Sets the upper and lower bounds of this box to include all of the data in array.

Parameters

array

ArrayLike<number>

An array of position data that the resulting box will envelop.

Returns

Box3


setFromBufferAttribute()

setFromBufferAttribute(attribute): Box3

Sets the upper and lower bounds of this box to include all of the data in attribute.

Parameters

attribute

BufferAttribute

A buffer attribute of position data that the resulting box will envelop.

Returns

Box3


setFromBufferAttributeRange()

setFromBufferAttributeRange(attribute, start, count): Box3

Sets the upper and lower bounds of this box by a part of attributes.

Parameters

attribute

BufferAttribute

A buffer attribute of position data that the resulting box will envelop.

start

number

The start attributes of range.

count

number

The count of attributes in range.

Returns

Box3


setFromIndexBufferAttributeRange()

setFromIndexBufferAttributeRange(positionAttribute, indexAttribute, start, count): Box3

Sets the upper and lower bounds of this box by a part of vertexes’ index.

Parameters

positionAttribute

BufferAttribute

A buffer of vertex data.

indexAttribute

BufferAttribute

A buffer of vertex’ index.

start

number

The start indexes of range.

count

number

The count of indexes in range.

Returns

Box3


setFromPoints()

setFromPoints(_points): Box3

Sets the upper and lower bounds of this box to include all of the points in Array| points.

Parameters

_points

Vector3[]

Returns

Box3


setFromCenterAndSize()

setFromCenterAndSize(_center, size): Box3

Centers this box on center and sets this box’s width, height and depth to the values specified in size.

Parameters

_center

Vector3

size

Vector3

Desired x, y and z dimensions of the box.

Returns

Box3


setFromObject()

setFromObject(object): Box3

Computes the world-axis-aligned bounding box of an Object3D (including its children), accounting for the object’s, and children’s, world transforms. The function may result in a larger box than strictly necessary.

Parameters

object

Object3D

Object3D to compute the bounding box of.

Returns

Box3


clone()

clone(): Box3

Returns a new Box3 with the same min and max as this clone.

Returns

Box3


copy()

copy(box): Box3

Copies the min and max from box to this box.

Parameters

box

Box3

Box3 to copy.

Returns

Box3


makeEmpty()

makeEmpty(): Box3

Makes this box empty.

Returns

Box3


isEmpty()

isEmpty(): boolean

Returns true if this box includes zero points within its bounds. Note that a box with equal lower and upper bounds still includes one point, the one both bounds share.

Returns

boolean


getCenter()

getCenter(target): Vector3

Returns the center point of the box as a Vector3.

Parameters

target

Vector3

the result will be copied into this Vector3.

Returns

Vector3


getCenterUnsafe()

getCenterUnsafe(target): void

Returns the center point of the box as a Vector3. this method returns the center whatever the values of box’ min is over than max.

Parameters

target

Vector3

the result will be copied into this Vector3.

Returns

void


getSize()

getSize(target?): Vector3

Returns the width, height and depth of this box.

Parameters

target?

Vector3

the result will be copied into this Vector3.

Returns

Vector3


getCorners()

getCorners(): Vector3[]

Return the position of eight box’s vertexes.

Returns

Vector3[]


getPlanes()

getPlanes(): Plane[]

Return an array of planes of eight box’s surface.

Returns

Plane[]


expandByPoint()

expandByPoint(point): Box3

Expands the boundaries of this box to include point.

Parameters

point

Vector3

Vector3 that should be included in the box.

Returns

Box3


expandByVector()

expandByVector(vector): Box3

Expands this box equilaterally by vector. The width of this box will be expanded by the x component of vector in both directions. The height of this box will be expanded by the y component of vector in both directions. The depth of this box will be expanded by the z component of vector in both directions.

Parameters

vector

Vector3

Vector3 to expand the box by.

Returns

Box3


expandByScalar()

expandByScalar(scalar): Box3

Expands each dimension of the box by scalar. If negative, the dimensions of the box will be contracted.

Parameters

scalar

number

Distance to expand the box by.

Returns

Box3


expandByObject()

expandByObject(object): Box3

Expands the boundaries of this box to include object and its children, accounting for the object’s, and children’s, world transforms. The function may result in a larger box than strictly necessary.

Parameters

object

Object3D

Object3D to expand the box by.

Returns

Box3


intersectsTriangle()

intersectsTriangle(triangle): boolean

Parameters

triangle

Triangle

Triangle| Triangle to check for intersection against. Determines whether or not this box intersects Triangle| triangle.

Returns

boolean


containsPoint()

containsPoint(point): boolean

Return true if the specified point lies within or on the boundaries of this box.

Parameters

point

Vector3

Vector3 to check for inclusion.

Returns

boolean


containsBox()

containsBox(box): boolean

Return true if this box includes the entirety of box. If this and box are identical, this function also returns true.

Parameters

box

Box3

Box3 to test for inclusion.

Returns

boolean


getParameter()

getParameter(point, target): Vector3

Return a point as a proportion of this box’s width and height.

Parameters

point

Vector3

Vector3.

target

Vector3

the result will be copied into this Vector3.

Returns

Vector3


intersectsBox()

intersectsBox(box): boolean

box Box to check for intersection against. Determines whether or not this box intersects box.

Parameters

box

Box3

Returns

boolean


intersectsSphere()

intersectsSphere(sphere): boolean

Determines whether or not this box intersects sphere.

Parameters

sphere

Sphere

Sphere to check for intersection against.

Returns

boolean


intersectsPlane()

intersectsPlane(plane): boolean

Determines whether or not this box intersects plane.

Parameters

plane

Plane

Plane to check for intersection against.

Returns

boolean


clampPoint()

clampPoint(point, target): Vector3

Clamps the point within the bounds of this box.

Parameters

point

Vector3

Vector3 to clamp.

target

Vector3

the result will be copied into this Vector3.

Returns

Vector3


distanceToPoint()

distanceToPoint(point): number

If the point lies inside of this box, the distance will be 0.

Parameters

point

Vector3

Vector3 to measure distance to.

Returns

number

the distance from any edge of this box to the specified point.


getBoundingSphere()

getBoundingSphere(target): Sphere

Gets a Sphere that bounds the box.

Parameters

target

Sphere

the result will be copied into this Sphere.

Returns

Sphere


intersect()

intersect(box): Box3

Computes the intersection of this and box, setting the upper bound of this box to the lesser of the two boxes’ upper bounds and the lower bound of this box to the greater of the two boxes’ lower bounds. If there’s no overlap, makes this box empty.

Parameters

box

Box3

Returns

Box3


union()

union(box): Box3

Computes the union of this box and box, setting the upper bound of this box to the greater of the two boxes’ upper bounds and the lower bound of this box to the lesser of the two boxes’ lower bounds.

Parameters

box

Box3

Box that will be unioned with this box.

Returns

Box3


hasNan()

hasNan(): boolean

If NaN exists in three values of min and max, return true.

Returns

boolean


unionSafe()

unionSafe(box): Box3

Check the given box is valid and let this box can contain it.

Parameters

box

Box3

Returns

Box3


applyMatrix4()

applyMatrix4(matrix): Box3

Transforms this Box3 with the supplied matrix.

Parameters

matrix

Matrix4

The Matrix4 to apply.

Returns

Box3


translate()

translate(offset): Box3

Adds offset to both the upper and lower bounds of this box, effectively moving this box offset units in 3D space.

Parameters

offset

Vector3

Direction and distance of offset.

Returns

Box3


equals()

equals(box): boolean

Return true if this box and box share the same lower and upper bounds.

Parameters

box

Box3

Box to compare with this one.

Returns

boolean


toBox2()

toBox2(box2?): Box2

Return the Bounding on plane XY.

Parameters

box2?

Box2

Returns

Box2