1 
  2 /**
  3  * follow a object3D
  4 */
  5 WebAudio.Sound.fn.follow	= function(object3d, world){
  6 	console.assert( this.isFollowing() === false );
  7 	// handle parameter
  8 	if( object3d instanceof tQuery.Object3D ){
  9 		console.assert(object3d.length === 1)
 10 		object3d	= object3d.get(0);
 11 	}
 12 	// sanity check on parameters
 13 	console.assert( object3d instanceof THREE.Object3D );
 14 
 15 	// hook the world loop
 16 	this._followCb		= function(deltaTime){
 17 		this.updateWithObject3d(object3d, deltaTime);
 18 	}.bind(this);
 19 	world.loop().hook(this._followCb);
 20 	// for chained API
 21 	return this;
 22 }
 23 
 24 /**
 25  * unfollow the object3D if any
 26 */
 27 WebAudio.Sound.fn.unfollow	= function(world){
 28 	this._world.loop().unhook(this._followCb);
 29 	this._followCb		= null;
 30 	// for chained API
 31 	return this;
 32 }
 33 
 34 /**
 35  * @returns {Boolean} true if this sound is following a object3d, false overwise
 36 */
 37 WebAudio.Sound.prototype.isFollowing	= function(){
 38 	return this._followCb ? true : false;
 39 	// for chained API
 40 	return this;
 41 }
 42