Skip to content

Commit

Permalink
Merge pull request mrdoob#10474 from sunag/84dev
Browse files Browse the repository at this point in the history
Optional makeEmpty in THREE.Box3
  • Loading branch information
mrdoob authored Jan 12, 2017
2 parents 49798d7 + 81e173a commit 59e929e
Showing 1 changed file with 70 additions and 60 deletions.
130 changes: 70 additions & 60 deletions src/math/Box3.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Box3.prototype = {
this.min.set( minX, minY, minZ );
this.max.set( maxX, maxY, maxZ );

return this;

},

setFromBufferAttribute: function ( attribute ) {
Expand Down Expand Up @@ -88,6 +90,8 @@ Box3.prototype = {
this.min.set( minX, minY, minZ );
this.max.set( maxX, maxY, maxZ );

return this;

},

setFromPoints: function ( points ) {
Expand Down Expand Up @@ -121,69 +125,13 @@ Box3.prototype = {

}(),

setFromObject: function () {

// Computes the world-axis-aligned bounding box of an object (including its children),
// accounting for both the object's, and children's, world transforms

var v1 = new Vector3();

return function setFromObject( object ) {

var scope = this;

object.updateMatrixWorld( true );

this.makeEmpty();

object.traverse( function ( node ) {

var i, l;

var geometry = node.geometry;

if ( geometry !== undefined ) {

if ( geometry.isGeometry ) {

var vertices = geometry.vertices;

for ( i = 0, l = vertices.length; i < l; i ++ ) {

v1.copy( vertices[ i ] );
v1.applyMatrix4( node.matrixWorld );

scope.expandByPoint( v1 );

}

} else if ( geometry.isBufferGeometry ) {

var attribute = geometry.attributes.position;

if ( attribute !== undefined ) {

for ( i = 0, l = attribute.count; i < l; i ++ ) {

v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
setFromObject: function ( object ) {

scope.expandByPoint( v1 );

}

}

}

}

} );

return this;
this.makeEmpty();

};
return this.expandByObject( object );

}(),
},

clone: function () {

Expand Down Expand Up @@ -258,6 +206,68 @@ Box3.prototype = {

},

expandByObject: function () {

// Computes the world-axis-aligned bounding box of an object (including its children),
// accounting for both the object's, and children's, world transforms

var v1 = new Vector3();

return function expandByObject( object ) {

var scope = this;

object.updateMatrixWorld( true );

object.traverse( function ( node ) {

var i, l;

var geometry = node.geometry;

if ( geometry !== undefined ) {

if ( geometry.isGeometry ) {

var vertices = geometry.vertices;

for ( i = 0, l = vertices.length; i < l; i ++ ) {

v1.copy( vertices[ i ] );
v1.applyMatrix4( node.matrixWorld );

scope.expandByPoint( v1 );

}

} else if ( geometry.isBufferGeometry ) {

var attribute = geometry.attributes.position;

if ( attribute !== undefined ) {

for ( i = 0, l = attribute.count; i < l; i ++ ) {

v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );

scope.expandByPoint( v1 );

}

}

}

}

} );

return this;

};

}(),

containsPoint: function ( point ) {

return point.x < this.min.x || point.x > this.max.x ||
Expand Down

0 comments on commit 59e929e

Please sign in to comment.