Browse Source

Merge remote-tracking branch 'WestLangley/dev-bb' into dev

Mr.doob 12 years ago
parent
commit
bb5278e958
3 changed files with 45 additions and 58 deletions
  1. 0 55
      src/core/Object3D.js
  2. 3 3
      src/extras/helpers/BoundingBoxHelper.js
  3. 42 0
      src/math/Box3.js

+ 0 - 55
src/core/Object3D.js

@@ -41,8 +41,6 @@ THREE.Object3D = function () {
 
 	this.frustumCulled = true;
 
-	this.boundingBox = null;
-
 	this.userData = {};
 
 };
@@ -444,53 +442,6 @@ THREE.Object3D.prototype = {
 
 	},
 
-	computeBoundingBox: function() {
-
-		// computes the world-axis-aligned bounding box of object (including its children),
-		// accounting for both the object's and childrens' world transforms
-
-		var v1 = new THREE.Vector3();
-
-		return function() {
-
-			if ( this.boundingBox === null ) {
-
-				this.boundingBox = new THREE.Box3();
-
-			}
-
-			this.boundingBox.makeEmpty();
-
-			var scope = this.boundingBox;
-
-			this.updateMatrixWorld( true );
-
-			this.traverse( function ( node ) {
-
-				if ( node.geometry !== undefined && node.geometry.vertices !== undefined ) {
-
-					var vertices = node.geometry.vertices;
-
-					for ( var i = 0, il = vertices.length; i < il; i++ ) {
-
-						v1.copy( vertices[ i ] );
-
-						v1.applyMatrix4( node.matrixWorld );
-
-						scope.expandByPoint( v1 );
-
-					}
-
-				}
-
-			} );
-
-			return this.boundingBox;
-
-		};
-
-	}(),
-
 	clone: function ( object, recursive ) {
 
 		if ( object === undefined ) object = new THREE.Object3D();
@@ -525,12 +476,6 @@ THREE.Object3D.prototype = {
 
 		object.frustumCulled = this.frustumCulled;
 
-		if ( this.boundingBox instanceof THREE.Box3 ) {
-
-			object.boundingBox = this.boundingBox.clone();
-
-		}
-
 		object.userData = JSON.parse( JSON.stringify( this.userData ) );
 
 		if ( recursive === true ) {

+ 3 - 3
src/extras/helpers/BoundingBoxHelper.js

@@ -20,10 +20,10 @@ THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
 
 THREE.BoundingBoxHelper.prototype.update = function () {
 
-	this.object.computeBoundingBox();
+	this.box.setFromObject( this.object );
 
-	this.object.boundingBox.size( this.scale );
+	this.box.size( this.scale );
 
-	this.object.boundingBox.center( this.position );
+	this.box.center( this.position );
 
 };

+ 42 - 0
src/math/Box3.js

@@ -1,5 +1,6 @@
 /**
  * @author bhouston / http://exocortex.com
+ * @author WestLangley / http://github.com/WestLangley
  */
 
 THREE.Box3 = function ( min, max ) {
@@ -94,6 +95,47 @@ THREE.Box3.prototype = {
 
 	}(),
 
+	setFromObject: function() {
+
+		// Computes the world-axis-aligned bounding box of an object (including its children),
+		// accounting for both the object's, and childrens', world transforms
+
+		var v1 = new THREE.Vector3();
+
+		return function( object ) {
+
+			var scope = this;
+
+			object.updateMatrixWorld( true );
+
+			this.makeEmpty();
+
+			object.traverse( function ( node ) {
+
+				if ( node.geometry !== undefined && node.geometry.vertices !== undefined ) {
+
+					var vertices = node.geometry.vertices;
+
+					for ( var i = 0, il = vertices.length; i < il; i++ ) {
+
+						v1.copy( vertices[ i ] );
+
+						v1.applyMatrix4( node.matrixWorld );
+
+						scope.expandByPoint( v1 );
+
+					}
+
+				}
+
+			} );
+
+			return this;
+
+		};
+
+	}(),
+
 	copy: function ( box ) {
 
 		this.min.copy( box.min );