The Box3.applyMatrix4()
method in Three.js applies a Matrix4
transformation to the bounding box.
box.applyMatrix4(matrix);
matrix
- The Matrix4
transformation to apply to the box.To transform a box, create a Matrix4
representing the transformation and call applyMatrix4(matrix)
on the box.
var box = new THREE.Box3(
new THREE.Vector3(-1, -1, -1),
new THREE.Vector3(1, 1, 1)
);
var matrix = new THREE.Matrix4();
matrix.makeTranslation(1, 0, 0);
box.applyMatrix4(matrix);
In the example above, a new Box3
object is created with two corner vectors, representing a cube centered around the origin. A Matrix4
is created and translated one unit along the X-axis. Finally, the box is transformed by the matrix.
Note that this method does not modify the original bounding box, but returns a new bounding box with the transformed corners.