Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box3.expandFromObject doesn't work when the given Line doesn't have vertices #18740

Closed
2 tasks done
woo-cie opened this issue Feb 26, 2020 · 1 comment · Fixed by #18744
Closed
2 tasks done

Box3.expandFromObject doesn't work when the given Line doesn't have vertices #18740

woo-cie opened this issue Feb 26, 2020 · 1 comment · Fixed by #18744
Labels

Comments

@woo-cie
Copy link

woo-cie commented Feb 26, 2020

Description of the problem

When giving object3D with an empty bounding box to expandFromObject, new Box3 is not empty.
Max of new Box3 is (+Inf, +Inf, +Inf) and min of that is (-Inf, -Inf, -Inf).

const line = new Line(new Geometry());
line.geometry.computeBoundingBox();

console.log(line.geometry.boundingBox.min);
// Vector3 {x: Infinity, y: Infinity, z: Infinity, constructor: Object}
console.log(new Box3().setFromObject(line).min);
// Vector3 {x: -Infinity, y: -Infinity, z: -Infinity, constructor: Object}

console.log(line.geometry.boundingBox.max);
// Vector3 {x: -Infinity, y: -Infinity, z: -Infinity, constructor: Object}
console.log(new Box3().setFromObject(line).max);
// Vector3 {x: Infinity, y: Infinity, z: Infinity, constructor: Object}

This is because expandFromObject use expandFromPoint to set max and min.
To fix this, it should set max and min directly or ignore when max = -Inf and min = +Inf.

three.js/src/math/Box3.js

Lines 265 to 266 in c23b245

this.expandByPoint( _box.min );
this.expandByPoint( _box.max );

Three.js version

r111 and later

Browser
  • All of them
OS
  • All of them
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 26, 2020

You are right. Creating an AABB from a 3D objects like mesh, point cloud or line with an initial geometry object should be empty. Right now, this code returns false:

console.log( new THREE.Box3().setFromObject( new THREE.Mesh() ).isEmpty() ); // false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants