三@0.119 正在破坏边界框的最小值和最大值的计算

问题描述

我在后端使用了 Three.js lib 来计算 AABB(轴对齐边界框)。

getAABB: function (position,scale,orientation) {
    const cube = new Mesh(new BoxGeometry(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,}
    };
  }

对于三个@0.118,结果看起来不错:

{
  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

但是一旦我更新到three@0.119,它就开始返回错误的结果:

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

在本例中,您可以看到 0.119 https://jsfiddle.net/yura_syedin/zwm3jkdL/

的错误结果

这是 0.118 https://jsfiddle.net/yura_syedin/5801pLaw/34/

的正确结果

根据发行说明,没有太多变化

enter image description here

解决方法

看起来 BoxGeometry 构造函数在 r119 中修复了一个错误。

  • r118 中,当您使用 0,0 宽度/高度/深度参数构造一个框时,构造函数认为它们没有被定义,并且默认为 1,1,1。这是the implementation for r118
  • r119 中,当您用 0,0 构造一个盒子时,它尊重这些尺寸,并为您提供一个带有 min: 2,max: 2 的盒子,因为它尊重尺寸为 0 个单位。这是the implementation for r119

只要确保您使用一些非零值初始化框,您就会在不同版本中获得相同的结果。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...