getObject by any custom property present in userData of Object

object3d

#1

– getObject by any custom property present in userData of Object

I want to get an Object by its custom property set un userData field … can i use Object.getObjectByProperty method for that ? if Yes then how ?

Example lets say my 3d Object has custom property called type under userData field … and using scene.getObjectByProperty method i want to get my Object …how can i do this ?


#2

No, this method does not support this kind of deep selection. The following should work:

THREE.Object3D.prototype.getObjectByUserDataProperty = function ( name, value ) {

	if ( this.userData[ name ] === value ) return this;
	
	for ( var i = 0, l = this.children.length; i < l; i ++ ) {

		var child = this.children[ i ];
		var object = child.getObjectByUserDataProperty( name, value );

		if ( object !== undefined ) {

			return object;

		}

	}
	
	return undefined;

}