فهرست منبع

Merge branch 'patch-1' of https://github.com/Wilt/three.js into dev

Mr.doob 10 سال پیش
والد
کامیت
d7757f56c5
1فایلهای تغییر یافته به همراه8 افزوده شده و 17 حذف شده
  1. 8 17
      src/core/Object3D.js

+ 8 - 17
src/core/Object3D.js

@@ -377,33 +377,24 @@ THREE.Object3D.prototype = {
 
 
 	getObjectById: function ( id, recursive ) {
 	getObjectById: function ( id, recursive ) {
 
 
-		if ( this.id === id ) return this;
+		return this.getObjectByProperty('id', id, recursive);
 
 
-		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
-
-			var child = this.children[ i ];
-			var object = child.getObjectById( id, recursive );
-
-			if ( object !== undefined ) {
-
-				return object;
-
-			}
+	},
 
 
-		}
+	getObjectByName: function ( name, recursive ) {
 
 
-		return undefined;
+		return this.getObjectByProperty('name', name, recursive);
 
 
 	},
 	},
+	
+	getObjectByProperty: function ( name, value, recursive ) {
 
 
-	getObjectByName: function ( name, recursive ) {
-
-		if ( this.name === name ) return this;
+		if ( this[name] === value ) return this;
 
 
 		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
 		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
 
 
 			var child = this.children[ i ];
 			var child = this.children[ i ];
-			var object = child.getObjectByName( name, recursive );
+			var object = child.getObjectByProperty( name, value, recursive );
 
 
 			if ( object !== undefined ) {
 			if ( object !== undefined ) {