Browse Source

Simplified Object3D's .getDescendants() code.

Mr.doob 13 years ago
parent
commit
3d64085ee3
2 changed files with 14 additions and 15 deletions
  1. 3 3
      docs/api/core/Object3D.html
  2. 11 12
      src/core/Object3D.js

+ 3 - 3
docs/api/core/Object3D.html

@@ -171,12 +171,12 @@
 		Gets first child with name matching the argument. Searches whole subgraph recursively if *recursive* is true.
 		Gets first child with name matching the argument. Searches whole subgraph recursively if *recursive* is true.
 		</div>
 		</div>
 		
 		
-		<h3>.getDescendants( [page:Array returnValue] )</h3>
+		<h3>.getDescendants( [page:Array array] )</h3>
 		<div>
 		<div>
-		returnValue - optional argument that returns the the array with descendants.<br />
+		array - optional argument that returns the the array with descendants.<br />
 		</div>
 		</div>
 		<div>
 		<div>
-		Searches whole subgraph recursively to add all objects in the returnValue.
+		Searches whole subgraph recursively to add all objects in the array.
 		</div>
 		</div>
 
 
 		<h3>.updateMatrix()</h3>
 		<h3>.updateMatrix()</h3>

+ 11 - 12
src/core/Object3D.js

@@ -207,20 +207,19 @@ THREE.Object3D.prototype = {
 
 
 	},
 	},
 	
 	
-	getDescendants: function (returnValue) {
-		var children = this.children,l = children.length,child;
-		
-		if (returnValue === undefined){
-			returnValue = [];	
-		}
-		
-		for (var i = 0; i < l ; i++){
-			child = children[i];
-			returnValue.push(child);
-			child.getDescendants(returnValue);
+	getDescendants: function ( array ) {
+
+		if ( array === undefined ) array = [];
+
+		Array.prototype.push.apply( array, this.children );
+
+		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
+
+			this.children[ i ].getDescendants( array );
+
 		};
 		};
 		
 		
-		return returnValue;
+		return array;
 		
 		
 	},
 	},