1

I am using three.js lib on my backend to calculate AABB (axis aligned bounding box).

getAABB: function (position, scale, orientation) {
    const cube = new Mesh(new BoxGeometry(0, 0, 0));
    cube.position.set(...position);
    cube.scale.set(...scale);
    cube.rotation.set(...orientation);

    const bb = new Box3().setFromObject(cube);
    const { min, max } = bb;

    return {
      x: {
        min: min.x,
        max: max.x,
      },
      y: {
        min: min.y,
        max: max.y,
      },
      z: {
        min: min.z,
        max: max.z,
      }
    };
  }

For three@0.118 the results are looking good:

{
  x: { min: 0.5391231359521602, max: 3.46087686404784 },
  y: { min: 0.32046946879189564, max: 3.6795305312081044 },
  z: { min: 0.4349899537033477, max: 3.5650100462966523 },
}

enter image description here But once I do update to three@0.119 it is starting to return wrong results:

{
  x: { min: 2, max: 2 },
  y: { min: 2, max: 2 },
  z: { min: 2, max: 2 },
}

In this example you can see the wrong results for 0.119 https://jsfiddle.net/yura_syedin/zwm3jkdL/

Here is the correct result for 0.118 https://jsfiddle.net/yura_syedin/5801pLaw/34/

According to release notes there are not too many changes enter image description here

1nstinct
  • 1,745
  • 1
  • 26
  • 30

1 Answers1

2

It looks like the BoxGeometry constructor had a bug fixed in r119.

  • In r118 when you constructed a box with 0, 0, 0 width/height/depth parameters, the constructor thought they weren't being defined, and it would default to 1, 1, 1. Here's the implementation for r118.
  • In r119 when you construct a box with 0, 0, 0, it respects those dimensions, and gives you a box with min: 2, max: 2, since it's respecting that the dimensions are 0 units. Here's the implementation for r119.

Just make sure you're initializing the box with some non-zero value, and you'll get equal results across versions.

M -
  • 26,908
  • 11
  • 49
  • 81
  • I think you are right. It returns correct results if I define with ones ```new THREE.BoxGeometry(1, 1, 1)``` – 1nstinct Jan 07 '21 at 21:48