Browse Source

Box3: revert setFromObject()

Presumably, the previous version was correct.

FIxes #8432.
WestLangley 9 years ago
parent
commit
cb853767d3
1 changed files with 26 additions and 12 deletions
  1. 26 12
      src/math/Box3.js

+ 26 - 12
src/math/Box3.js

@@ -92,35 +92,49 @@ THREE.Box3.prototype = {
 		// Computes the world-axis-aligned bounding box of an object (including its children),
 		// Computes the world-axis-aligned bounding box of an object (including its children),
 		// accounting for both the object's, and children's, world transforms
 		// accounting for both the object's, and children's, world transforms
 
 
-		var box;
+		var v1 = new THREE.Vector3();
 
 
 		return function ( object ) {
 		return function ( object ) {
 
 
-			if ( box === undefined ) box = new THREE.Box3();
-
 			var scope = this;
 			var scope = this;
 
 
-			this.makeEmpty();
-
 			object.updateMatrixWorld( true );
 			object.updateMatrixWorld( true );
 
 
+			this.makeEmpty();
+
 			object.traverse( function ( node ) {
 			object.traverse( function ( node ) {
 
 
 				var geometry = node.geometry;
 				var geometry = node.geometry;
 
 
 				if ( geometry !== undefined ) {
 				if ( geometry !== undefined ) {
 
 
-					if ( geometry.boundingBox === null ) {
+					if ( geometry instanceof THREE.Geometry ) {
 
 
-						geometry.computeBoundingBox();
+						var vertices = geometry.vertices;
 
 
-					}
+						for ( var i = 0, il = vertices.length; i < il; i ++ ) {
+
+							v1.copy( vertices[ i ] );
+
+							v1.applyMatrix4( node.matrixWorld );
+
+							scope.expandByPoint( v1 );
+
+						}
+
+					} else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
+
+						var positions = geometry.attributes[ 'position' ].array;
+
+						for ( var i = 0, il = positions.length; i < il; i += 3 ) {
+
+							v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
+
+							v1.applyMatrix4( node.matrixWorld );
 
 
-					if ( geometry.boundingBox.isEmpty() === false ) {
+							scope.expandByPoint( v1 );
 
 
-						box.copy( geometry.boundingBox );
-						box.applyMatrix4( node.matrixWorld );
-						scope.union( box );
+						}
 
 
 					}
 					}