[email protected] is breaking calculation of min and max for the bounding box

279 Views Asked by At

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 [email protected] 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 [email protected] 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

1

There are 1 best solutions below

1
M - On

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.