Browse Source

add expandByObject

sunag 8 years ago
parent
commit
59aa8cc9ab
1 changed files with 67 additions and 63 deletions
  1. 67 63
      src/math/Box3.js

+ 67 - 63
src/math/Box3.js

@@ -92,9 +92,7 @@ Box3.prototype = {
 
 
 	},
 	},
 
 
-	setFromPoints: function ( points, makeEmpty ) {
-
-		if (makeEmpty !== false) this.makeEmpty();
+	setFromPoints: function ( points ) {
 
 
 		for ( var i = 0, il = points.length; i < il; i ++ ) {
 		for ( var i = 0, il = points.length; i < il; i ++ ) {
 
 
@@ -123,69 +121,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, makeEmpty ) {
-
-			var scope = this;
-
-			object.updateMatrixWorld( true );
-
-			if (makeEmpty !== false) 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 );
-
-								scope.expandByPoint( v1 );
+	setFromObject: function ( object ) {
 
 
-							}
-
-						}
-
-					}
-
-				}
+		this.makeEmpty();
 
 
-			} );
+		this.expandByObject( object );
 
 
-			return this;
-
-		};
-
-	}(),
+	},
 
 
 	clone: function () {
 	clone: function () {
 
 
@@ -260,6 +202,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 ) {
 	containsPoint: function ( point ) {
 
 
 		return point.x < this.min.x || point.x > this.max.x ||
 		return point.x < this.min.x || point.x > this.max.x ||