瀏覽代碼

Merge pull request #12377 from ngokevin/box3inlinefn

remove inline fn in Box3.expandByObject to reduce GC
Mr.doob 7 年之前
父節點
當前提交
50248d1b6b
共有 1 個文件被更改,包括 29 次插入25 次删除
  1. 29 25
      src/math/Box3.js

+ 29 - 25
src/math/Box3.js

@@ -211,46 +211,40 @@ Object.assign( Box3.prototype, {
 
 		var v1 = new Vector3();
 
-		return function expandByObject( object ) {
-
-			var scope = this;
+		var scope;
 
-			object.updateMatrixWorld( true );
+		function traverse ( node ) {
 
-			object.traverse( function ( node ) {
+			var i, l;
 
-				var i, l;
+			var geometry = node.geometry;
 
-				var geometry = node.geometry;
+			if ( geometry !== undefined ) {
 
-				if ( geometry !== undefined ) {
+				if ( geometry.isGeometry ) {
 
-					if ( geometry.isGeometry ) {
+					var vertices = geometry.vertices;
 
-						var vertices = geometry.vertices;
+					for ( i = 0, l = vertices.length; i < l; i ++ ) {
 
-						for ( i = 0, l = vertices.length; i < l; i ++ ) {
+						v1.copy( vertices[ i ] );
+						v1.applyMatrix4( node.matrixWorld );
 
-							v1.copy( vertices[ i ] );
-							v1.applyMatrix4( node.matrixWorld );
-
-							scope.expandByPoint( v1 );
+						scope.expandByPoint( v1 );
 
-						}
-
-					} else if ( geometry.isBufferGeometry ) {
+					}
 
-						var attribute = geometry.attributes.position;
+				} else if ( geometry.isBufferGeometry ) {
 
-						if ( attribute !== undefined ) {
+					var attribute = geometry.attributes.position;
 
-							for ( i = 0, l = attribute.count; i < l; i ++ ) {
+					if ( attribute !== undefined ) {
 
-								v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
+						for ( i = 0, l = attribute.count; i < l; i ++ ) {
 
-								scope.expandByPoint( v1 );
+							v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
 
-							}
+							scope.expandByPoint( v1 );
 
 						}
 
@@ -258,7 +252,17 @@ Object.assign( Box3.prototype, {
 
 				}
 
-			} );
+			}
+
+		}
+
+		return function expandByObject( object ) {
+
+			scope = this;
+
+			object.updateMatrixWorld( true );
+
+			object.traverse( traverse );
 
 			return this;