admin管理员组

文章数量:1303427

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!

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!

Share Improve this question edited Mar 28, 2014 at 12:36 Tiny 27.9k112 gold badges351 silver badges607 bronze badges asked Mar 28, 2014 at 12:15 user3472487user3472487 831 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Box3.setFromObject( object ) putes 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.

本文标签: javascriptThree JSBoundingBox not being updated after performing rotationsStack Overflow