diff --git a/docs/api/en/math/Box3.html b/docs/api/en/math/Box3.html index 40f1c1069e1037..464b30c9baad83 100644 --- a/docs/api/en/math/Box3.html +++ b/docs/api/en/math/Box3.html @@ -138,6 +138,7 @@

[method:Box3 expandByObject]( [param:Object3D object] )

Expands the boundaries of this box to include [page:Object3D object] and its children, accounting for the object's, and children's, world transforms. + The function may result in a larger box than strictly necessary.

@@ -279,6 +280,7 @@

[method:Box3 setFromObject]( [param:Object3D object] )

Computes the world-axis-aligned bounding box of an [page:Object3D] (including its children), accounting for the object's, and children's, world transforms. + The function may result in a larger box than strictly necessary.

diff --git a/src/math/Box3.js b/src/math/Box3.js index eb1aea375c5d50..a5504d29467013 100644 --- a/src/math/Box3.js +++ b/src/math/Box3.js @@ -41,6 +41,8 @@ function Box3( min, max ) { } +var _box = new Box3(); + Object.assign( Box3.prototype, { isBox3: true, @@ -251,36 +253,17 @@ Object.assign( Box3.prototype, { if ( geometry !== undefined ) { - if ( geometry.isGeometry ) { - - var vertices = geometry.vertices; - - for ( i = 0, l = vertices.length; i < l; i ++ ) { - - _vector.copy( vertices[ i ] ); - _vector.applyMatrix4( object.matrixWorld ); - - this.expandByPoint( _vector ); - - } - - } else if ( geometry.isBufferGeometry ) { + if ( geometry.boundingBox === null ) { - var attribute = geometry.attributes.position; + geometry.computeBoundingBox(); - if ( attribute !== undefined ) { - - for ( i = 0, l = attribute.count; i < l; i ++ ) { - - _vector.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld ); - - this.expandByPoint( _vector ); - - } + } - } + _box.copy( geometry.boundingBox ); + _box.applyMatrix4( object.matrixWorld ); - } + this.expandByPoint( _box.min ); + this.expandByPoint( _box.max ); }