Geometry Bounding Box is too large

Hello,

I am working on a program that utilizes the bounding box of a three.js shape. As a result, I need to create a custom bounding box. You can find this demo here:

The program uses the bounding box of the three.js geometry. Here is a snippet from the code that finds out the min and max of the object (within the generateBoundingBox method).

  var box = new Box3();
  currentMesh.geometry.computeBoundingBox();
  box.setFromObject(currentMesh);
  const min = box.min.clone();
  const max = box.max.clone();

From here, it constructs 12 lines (11 edges, 1 diagonal), and puts that into 1 group every frame.

The diagonal line goes from the min to the max of the internal bounding box. However, you can see from the image below, that the min and max are too large for the spinning torus.

Why is the bounding box inaccurate for this shape?

Add a second parameter to setFromObject in BoundingBoxViewer.tsx line 48:

box.setFromObject(currentMesh,true);
2 Likes

Would it be more efficient if I were to use the BoxHelper built with Three.js? Can it have precise updates with lower computation time than my method of generating lines on each frame?

Here is a demo with THREE.Box3Helper.

The THREE.Box3 is used to get the precise bounding box and THREE.Box3Helper is used to create the image of the box (so you do not have to create all the lines by yourself). As far as I remember, Box3 should still be used, because of the precision parameter. The helper does not have such parameter.

https://codepen.io/boytchev/pen/eYLxqjM

1 Like