5

In my scene I have a simple cube:

var test = new THREE.Mesh(new THREE.CubeGeometry(10,10,10), new THREE.MeshBasicMaterial());
scene.add(test);

This cube is getting traversed/scaled through the user with THREE.TransformControls. What I need is the boundingbox of the cube after these interactions. So I'm doing

test.geometry.computeBoundingBox();
var bb = test.geometry.boundingBox;
bb.translate(test.localToWorld( new THREE.Vector3()));

But I always get a wrong boundingbox! The translation is computed correct, but not the scale. The width and heigth of the boundingbox is always 10 ...

Is this a bug or feature? How do I get the correct boundingbox of my cube?

1 Answer 1

6

You can compute the world-axis-aligned bounding box of an object (including its children) like so:

var box = new THREE.Box3();
box.setFromObject( object );

Have a look at the source code so you understand what it is doing.

three.js. r.60

Sign up to request clarification or add additional context in comments.

1 Comment

I know this function but didn't thought it would solve my problem - it's awesome! I always searched some function to scale my bbox... Many thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.