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

Optimize Box3.expandByObject #17940

Merged
merged 4 commits into from
Nov 20, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions src/math/Box3.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function Box3( min, max ) {

}

var _box = new Box3();

Object.assign( Box3.prototype, {

isBox3: true,
Expand Down Expand Up @@ -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 );

}

Expand Down