Browse Source

Merge remote-tracking branch 'gero3/getDescendants' into dev

Mr.doob 13 years ago
parent
commit
2a75e58ae9
2 changed files with 25 additions and 0 deletions
  1. 8 0
      docs/api/core/Object3D.html
  2. 17 0
      src/core/Object3D.js

+ 8 - 0
docs/api/core/Object3D.html

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

+ 17 - 0
src/core/Object3D.js

@@ -206,6 +206,23 @@ THREE.Object3D.prototype = {
 		return undefined;
 
 	},
+	
+	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);
+		};
+		
+		return returnValue;
+		
+	},
 
 	updateMatrix: function () {