Browse Source

Added getObjectById to Object3D. Renamed getChildByName to getObjectByName.
I'm undecided about this change. Not sure if getObject* is better than getChild*.

Mr.doob 12 years ago
parent
commit
aa613e4142
1 changed files with 39 additions and 2 deletions
  1. 39 2
      src/core/Object3D.js

+ 39 - 2
src/core/Object3D.js

@@ -305,7 +305,37 @@ THREE.Object3D.prototype = {
 
 	},
 
-	getChildByName: function ( name, recursive ) {
+	getObjectById: function ( id, recursive ) {
+
+		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
+
+			var child = this.children[ i ];
+
+			if ( child.id === id ) {
+
+				return child;
+
+			}
+
+			if ( recursive === true ) {
+
+				child = child.getObjectById( id, recursive );
+
+				if ( child !== undefined ) {
+
+					return child;
+
+				}
+
+			}
+
+		}
+
+		return undefined;
+
+	},
+
+	getObjectByName: function ( name, recursive ) {
 
 		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
 
@@ -319,7 +349,7 @@ THREE.Object3D.prototype = {
 
 			if ( recursive === true ) {
 
-				child = child.getChildByName( name, recursive );
+				child = child.getObjectByName( name, recursive );
 
 				if ( child !== undefined ) {
 
@@ -335,6 +365,13 @@ THREE.Object3D.prototype = {
 
 	},
 
+	getChildByName: function ( name, recursive ) {
+
+		console.warn( 'DEPRECATED: Object3D\'s .getChildByName() has been renamed to .getObjectByName().' );
+		return this.getObjectByName( name, recursive );
+
+	},
+
 	getDescendants: function ( array ) {
 
 		if ( array === undefined ) array = [];