BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Box3.containsBox()

The Box3.containsBox() method is a function of the Three.js library that is used to check if one Box3 object is completely contained within another Box3 object.

The Box3 class is used to represent a 3D bounding box defined by two Vector3 vectors representing the minimum and maximum corners of the box. It is often used to calculate collisions and clipping in 3D graphics.

Syntax

The syntax for the Box3.containsBox() method is as follows:

containsBox(box: Box3): boolean;

Here, box is the Box3 object to be tested for containment within the current Box3 object. The method returns true if the box object is completely inside the current Box3 object, and false otherwise.

Example

const box1 = new THREE.Box3(new THREE.Vector3(0, 0, 0), new THREE.Vector3(1, 1, 1));
const box2 = new THREE.Box3(new THREE.Vector3(0.2, 0.2, 0.2), new THREE.Vector3(0.8, 0.8, 0.8));

console.log(box1.containsBox(box2)); // Outputs true

In this example, we create two Box3 objects, box1 and box2. We then check if box2 is contained entirely within box1 using the containsBox() method. Since box2 is fully contained within box1, the output is true.

Notes

  • The containsBox() method only checks if one box is entirely contained within another. If the boxes partially overlap, the method will still return false.

  • If either of the Box3 objects passed to the containsBox() method is invalid (e.g. if it has a minimum corner greater than its maximum corner), the method may return unexpected results.

  • The containsBox() method is often used in conjunction with other Box3 methods such as intersectsBox() and union().