I need to find out the bounding box of a geometry after applying rotations on it.
Code to rotate - taken from sample editor of Three JS
object.rotation.x = xRadians;
object.rotation.y = yRdians;
object.rotation.z = zRadians
This rotates the object just fine.
Now I need to get the updated bounding box
Code to get the bounding Box
var minX = parseFloat(object.boundingBox.min.x);
var minY = parseFloat(object.boundingBox.min.y);
var minZ = parseFloat(object.boundingBox.min.z);
I keep getting the same values in minX-Z no matter what the rotation is. What is the right way of getting the updated bounding box?
I am using r-66.
I also tried using:
var radians = x * Math.PI / 180;
var axisX = new THREE.Vector3(1, 0, 0);
var matrix = new THREE.Matrix4().makeRotationAxis(axisX, radians);
geometry.applyMatrix(matrix);
This method performs the relative rotation and also updates the bounding box correctly but I do not want relative rotation. The first approach is what I am looking for but that does not update the bounding box of the object.
Any ideas? Thanks!
Box3.setFromObject( object )
computes the world-axis-aligned bounding box of an object (including its children), accounting for both the object's, and childrens', world transforms.
var box = new THREE.Box3().setFromObject( object );
three.js r.66
var box = new THREE.Box3().setFromObject( object );
will return the world coordinates, so you need to subtract them from it:
var bbox = new THREE.Box3().setFromObject(object);
bbox.min.sub(object.position);
bbox.max.sub(object.position);
This will give you the correct bounding box relative to the object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With