فهرست منبع

Finish all the doc for classes started by the letter A

sebastien 7 سال پیش
والد
کامیت
55b106cadb
3فایلهای تغییر یافته به همراه238 افزوده شده و 146 حذف شده
  1. 67 8
      src/Audio/babylon.audioEngine.ts
  2. 146 129
      src/Behaviors/Cameras/babylon.autoRotationBehavior.ts
  3. 25 9
      src/Tools/babylon.tools.ts

+ 67 - 8
src/Audio/babylon.audioEngine.ts

@@ -39,20 +39,53 @@
     // Sets the default audio engine to Babylon JS.
     Engine.AudioEngineFactory = () => { return new AudioEngine(); };
 
+    /**
+     * This represents the default audio engine used in babylon.
+     * It is responsible to play, synchronize and analyse sounds throughout the  application.
+     * @see http://doc.babylonjs.com/how_to/playing_sounds_and_music
+     */
     export class AudioEngine implements IAudioEngine{
-        private _audioContext: Nullable<AudioContext> = null;
-        private _audioContextInitialized = false;
+        /**
+         * Gets whether the current host supports Web Audio and thus could create AudioContexts.
+         */
         public canUseWebAudio: boolean = false;
+
+        /**
+         * The master gain node defines the global audio volume of your audio engine.
+         */
         public masterGain: GainNode;
 
-        private _connectedAnalyser: Nullable<Analyser>;
+        /**
+         * Defines if Babylon should emit a warning if WebAudio is not supported.
+         * @ignoreNaming
+         */
         public WarnedWebAudioUnsupported: boolean = false;
-        public unlocked: boolean = false;
-        public onAudioUnlocked: () => any;
 
+        /**
+         * Gets whether or not mp3 are supported by your browser.
+         */
         public isMP3supported: boolean = false;
+
+        /**
+         * Gets whether or not ogg are supported by your browser.
+         */
         public isOGGsupported: boolean = false;
 
+        /**
+         * Gets whether audio has been unlocked on the device.
+         * Some Browsers have strong restrictions about Audio and won t autoplay unless
+         * a user interaction has happened.
+         */
+        public unlocked: boolean = false;
+
+        /**
+         * Event raised when audio has been unlocked on the browser.
+         */
+        public onAudioUnlocked: () => any;
+
+        /**
+         * Gets the current AudioContext if available.
+         */
         public get audioContext(): Nullable<AudioContext> {
             if (!this._audioContextInitialized) {
                 this._initializeAudioContext();
@@ -60,6 +93,16 @@
             return this._audioContext;
         }
 
+        private _audioContext: Nullable<AudioContext> = null;
+        private _audioContextInitialized = false;
+        private _connectedAnalyser: Nullable<Analyser>;
+        
+        /**
+         * Instantiates a new audio engine.
+         * 
+         * There should be only one per page as some browsers restrict the number
+         * of audio contexts you can create.
+         */
         constructor() {
             if (typeof window.AudioContext !== 'undefined' || typeof window.webkitAudioContext !== 'undefined') {
                 window.AudioContext = window.AudioContext || window.webkitAudioContext;
@@ -136,7 +179,10 @@
             }
         }
 
-        public dispose() {
+        /**
+         * Destroy and release the resources associated with the audio ccontext.
+         */
+        public dispose(): void {
             if (this.canUseWebAudio && this._audioContextInitialized) {
                 if (this._connectedAnalyser && this._audioContext) {
                     this._connectedAnalyser.stopDebugCanvas();
@@ -150,6 +196,10 @@
             this.WarnedWebAudioUnsupported = false;
         }
 
+        /**
+         * Gets the global volume sets on the master gain.
+         * @returns the global volume if set or -1 otherwise
+         */
         public getGlobalVolume(): number {
             if (this.canUseWebAudio && this._audioContextInitialized) {
                 return this.masterGain.gain.value;
@@ -159,13 +209,22 @@
             }
         }
 
-        public setGlobalVolume(newVolume: number) {
+        /**
+         * Sets the global volume of your experience (sets on the master gain).
+         */
+        public setGlobalVolume(newVolume: number): void {
             if (this.canUseWebAudio && this._audioContextInitialized) {
                 this.masterGain.gain.value = newVolume;
             }
         }
 
-        public connectToAnalyser(analyser: Analyser) {
+        /**
+         * Connect the audio engine to an audio analyser allowing some amazing 
+         * synchornization between the sounds/music and your visualization (VuMeter for instance).
+         * @see http://doc.babylonjs.com/how_to/playing_sounds_and_music#using-the-analyser
+         * @param analyser The analyser to connect to the engine
+         */
+        public connectToAnalyser(analyser: Analyser): void {
             if (this._connectedAnalyser) {
                 this._connectedAnalyser.stopDebugCanvas();
             }

+ 146 - 129
src/Behaviors/Cameras/babylon.autoRotationBehavior.ts

@@ -1,76 +1,83 @@
 module BABYLON {
+    /**
+     * The autoRotation behavior (BABYLON.AutoRotationBehavior) is designed to create a smooth rotation of an ArcRotateCamera when there is no user interaction.
+     * @see http://doc.babylonjs.com/how_to/camera_behaviors#autorotation-behavior
+     */
     export class AutoRotationBehavior implements Behavior<ArcRotateCamera> {
+        /**
+         * Gets the name of the behavior.
+         */
         public get name(): string {
             return "AutoRotation";
         }
 
         private _zoomStopsAnimation = false;
-		private _idleRotationSpeed = 0.05;
-		private _idleRotationWaitTime = 2000;
+        private _idleRotationSpeed = 0.05;
+        private _idleRotationWaitTime = 2000;
         private _idleRotationSpinupTime = 2000;  
        
-		/**
-		* Sets the flag that indicates if user zooming should stop animation.
-		*/
-		public set zoomStopsAnimation(flag: boolean) {
-			this._zoomStopsAnimation = flag;
-		}
-
-		/**
-		* Gets the flag that indicates if user zooming should stop animation.
-		*/
-		public get zoomStopsAnimation(): boolean {
-			return this._zoomStopsAnimation;
+        /**
+        * Sets the flag that indicates if user zooming should stop animation.
+        */
+        public set zoomStopsAnimation(flag: boolean) {
+            this._zoomStopsAnimation = flag;
+        }
+
+        /**
+        * Gets the flag that indicates if user zooming should stop animation.
+        */
+        public get zoomStopsAnimation(): boolean {
+            return this._zoomStopsAnimation;
         }       
         
-		/**
-		* Sets the default speed at which the camera rotates around the model.
-		*/
-		public set idleRotationSpeed(speed: number) {
-			this._idleRotationSpeed = speed;
-		}
-
-		/**
-		* Gets the default speed at which the camera rotates around the model.
-		*/
-		public get idleRotationSpeed() {
-			return this._idleRotationSpeed;
-		}
-
-		/**
-		* Sets the time (in milliseconds) to wait after user interaction before the camera starts rotating.
-		*/
-		public set idleRotationWaitTime(time: number) {
-			this._idleRotationWaitTime = time;
-		}
-
-		/**
-		* Gets the time (milliseconds) to wait after user interaction before the camera starts rotating.
-		*/
-		public get idleRotationWaitTime() {
-			return this._idleRotationWaitTime;
-		}
-
-		/**
-		* Sets the time (milliseconds) to take to spin up to the full idle rotation speed.
-		*/
-		public set idleRotationSpinupTime(time: number) {
-			this._idleRotationSpinupTime = time;
-		}
-
-		/**
-		* Gets the time (milliseconds) to take to spin up to the full idle rotation speed.
-		*/
-		public get idleRotationSpinupTime() {
-			return this._idleRotationSpinupTime;
-		}
-
-		/**
-		 * Gets a value indicating if the camera is currently rotating because of this behavior
-		 */
-		public get rotationInProgress(): boolean {
-			return Math.abs(this._cameraRotationSpeed) > 0;
-		}
+        /**
+        * Sets the default speed at which the camera rotates around the model.
+        */
+        public set idleRotationSpeed(speed: number) {
+            this._idleRotationSpeed = speed;
+        }
+
+        /**
+        * Gets the default speed at which the camera rotates around the model.
+        */
+        public get idleRotationSpeed() {
+            return this._idleRotationSpeed;
+        }
+
+        /**
+        * Sets the time (in milliseconds) to wait after user interaction before the camera starts rotating.
+        */
+        public set idleRotationWaitTime(time: number) {
+            this._idleRotationWaitTime = time;
+        }
+
+        /**
+        * Gets the time (milliseconds) to wait after user interaction before the camera starts rotating.
+        */
+        public get idleRotationWaitTime() {
+            return this._idleRotationWaitTime;
+        }
+
+        /**
+        * Sets the time (milliseconds) to take to spin up to the full idle rotation speed.
+        */
+        public set idleRotationSpinupTime(time: number) {
+            this._idleRotationSpinupTime = time;
+        }
+
+        /**
+        * Gets the time (milliseconds) to take to spin up to the full idle rotation speed.
+        */
+        public get idleRotationSpinupTime() {
+            return this._idleRotationSpinupTime;
+        }
+
+        /**
+         * Gets a value indicating if the camera is currently rotating because of this behavior
+         */
+        public get rotationInProgress(): boolean {
+            return Math.abs(this._cameraRotationSpeed) > 0;
+        }
         
         // Default behavior functions
         private _onPrePointerObservableObserver: Nullable<Observer<PointerInfoPre>>;
@@ -78,13 +85,20 @@ module BABYLON {
         private _attachedCamera: Nullable<ArcRotateCamera>;
         private _isPointerDown = false;
         private _lastFrameTime: Nullable<number> = null;
-		private _lastInteractionTime = -Infinity;
-		private _cameraRotationSpeed: number = 0;
-
-		public init(): void {
-			// Do notihng
-		}
+        private _lastInteractionTime = -Infinity;
+        private _cameraRotationSpeed: number = 0;
+
+        /**
+         * Initializes the behavior.
+         */
+        public init(): void {
+            // Do notihng
+        }
 
+        /**
+         * Attaches the behavior to its arc rotate camera.
+         * @param camera Defines the camera to attach the behavior to
+         */
         public attach(camera: ArcRotateCamera): void {
             this._attachedCamera = camera;
             let scene = this._attachedCamera.getScene();
@@ -112,78 +126,81 @@ module BABYLON {
                 this._applyUserInteraction();
     
                 let timeToRotation = now - this._lastInteractionTime - this._idleRotationWaitTime;
-				let scale = Math.max(Math.min(timeToRotation / (this._idleRotationSpinupTime), 1), 0);
+                let scale = Math.max(Math.min(timeToRotation / (this._idleRotationSpinupTime), 1), 0);
                 this._cameraRotationSpeed = this._idleRotationSpeed * scale;
     
-				// Step camera rotation by rotation speed
-				if (this._attachedCamera) {
-					this._attachedCamera.alpha -= this._cameraRotationSpeed * (dt / 1000);
-				}
+                // Step camera rotation by rotation speed
+                if (this._attachedCamera) {
+                    this._attachedCamera.alpha -= this._cameraRotationSpeed * (dt / 1000);
+                }
             });
         }
-             
+
+        /**
+         * Detaches the behavior from its current arc rotate camera.
+         */
         public detach(): void {
-			if (!this._attachedCamera) {
-				return;
-			}
+            if (!this._attachedCamera) {
+                return;
+            }
             let scene = this._attachedCamera.getScene();
-			
-			if (this._onPrePointerObservableObserver) {
-				scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);
-			}
-			
-			this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
-			this._attachedCamera = null;
-		}
-
-		/**
-		 * Returns true if user is scrolling. 
-		 * @return true if user is scrolling.
-		 */
-		private _userIsZooming(): boolean {
-			if (!this._attachedCamera) {
-				return false;
-			}			
-			return this._attachedCamera.inertialRadiusOffset !== 0;
-		}   		
-		
-		private _lastFrameRadius = 0;
-		private _shouldAnimationStopForInteraction(): boolean {
-			if (!this._attachedCamera) {
-				return false;
-			}	
-
-			var zoomHasHitLimit = false;
-			if (this._lastFrameRadius === this._attachedCamera.radius && this._attachedCamera.inertialRadiusOffset !== 0) {
-				zoomHasHitLimit = true;
-			}
-
-			// Update the record of previous radius - works as an approx. indicator of hitting radius limits
-			this._lastFrameRadius = this._attachedCamera.radius;
-			return this._zoomStopsAnimation ? zoomHasHitLimit : this._userIsZooming();
-		}   		
-
-		/**
-		 *  Applies any current user interaction to the camera. Takes into account maximum alpha rotation.
-		 */          
+            
+            if (this._onPrePointerObservableObserver) {
+                scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);
+            }
+            
+            this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
+            this._attachedCamera = null;
+        }
+
+        /**
+         * Returns true if user is scrolling. 
+         * @return true if user is scrolling.
+         */
+        private _userIsZooming(): boolean {
+            if (!this._attachedCamera) {
+                return false;
+            }			
+            return this._attachedCamera.inertialRadiusOffset !== 0;
+        }   		
+        
+        private _lastFrameRadius = 0;
+        private _shouldAnimationStopForInteraction(): boolean {
+            if (!this._attachedCamera) {
+                return false;
+            }	
+
+            var zoomHasHitLimit = false;
+            if (this._lastFrameRadius === this._attachedCamera.radius && this._attachedCamera.inertialRadiusOffset !== 0) {
+                zoomHasHitLimit = true;
+            }
+
+            // Update the record of previous radius - works as an approx. indicator of hitting radius limits
+            this._lastFrameRadius = this._attachedCamera.radius;
+            return this._zoomStopsAnimation ? zoomHasHitLimit : this._userIsZooming();
+        }   		
+
+        /**
+         *  Applies any current user interaction to the camera. Takes into account maximum alpha rotation.
+         */          
         private _applyUserInteraction(): void {
-			if (this._userIsMoving() && !this._shouldAnimationStopForInteraction()) {
+            if (this._userIsMoving() && !this._shouldAnimationStopForInteraction()) {
                 this._lastInteractionTime = Tools.Now;
-			}
+            }
         }                
    
         // Tools
         private _userIsMoving(): boolean {
-			if (!this._attachedCamera) {
-				return false;
-			}	
-			
-			return this._attachedCamera.inertialAlphaOffset !== 0 ||
-				this._attachedCamera.inertialBetaOffset !== 0 ||
-				this._attachedCamera.inertialRadiusOffset !== 0 ||
-				this._attachedCamera.inertialPanningX !== 0 ||
-				this._attachedCamera.inertialPanningY !== 0 ||
-				this._isPointerDown;
-		}
+            if (!this._attachedCamera) {
+                return false;
+            }	
+            
+            return this._attachedCamera.inertialAlphaOffset !== 0 ||
+                this._attachedCamera.inertialBetaOffset !== 0 ||
+                this._attachedCamera.inertialRadiusOffset !== 0 ||
+                this._attachedCamera.inertialPanningX !== 0 ||
+                this._attachedCamera.inertialPanningY !== 0 ||
+                this._isPointerDown;
+        }
     }
 }

+ 25 - 9
src/Tools/babylon.tools.ts

@@ -1944,20 +1944,32 @@
     }
 
     /**
-    * An implementation of a loop for asynchronous functions.
-    */
+     * An implementation of a loop for asynchronous functions.
+     */
     export class AsyncLoop {
+        /**
+         * Defines the current index of the loop.
+         */
         public index: number;
+
         private _done: boolean;
 
         /**
-         * Constroctor.
+         * Constructor.
          * @param iterations the number of iterations.
          * @param _fn the function to run each iteration
          * @param _successCallback the callback that will be called upon succesful execution
          * @param offset starting offset.
          */
-        constructor(public iterations: number, private _fn: (asyncLoop: AsyncLoop) => void, private _successCallback: () => void, offset: number = 0) {
+        constructor(
+            /**
+             * Defines the number of iterations for the loop
+             */
+            public iterations: number, 
+            private _fn: (asyncLoop: AsyncLoop) => void, 
+            private _successCallback: () => void, 
+            offset: number = 0) {
+
             this.index = offset - 1;
             this._done = false;
         }
@@ -1985,7 +1997,12 @@
         }
 
         /**
-         * Helper function
+         * Create and run an async loop.
+         * @param iterations the number of iterations.
+         * @param _fn the function to run each iteration
+         * @param _successCallback the callback that will be called upon succesful execution
+         * @param offset starting offset.
+         * @returns the created async loop object
          */
         public static Run(iterations: number, _fn: (asyncLoop: AsyncLoop) => void, _successCallback: () => void, offset: number = 0): AsyncLoop {
             var loop = new AsyncLoop(iterations, _fn, _successCallback, offset);
@@ -1995,7 +2012,6 @@
             return loop;
         }
 
-
         /**
          * A for-loop that will run a given number of iterations synchronous and the rest async.
          * @param iterations total number of iterations
@@ -2004,10 +2020,10 @@
          * @param callback a success call back that will be called when iterating stops.
          * @param breakFunction a break condition (optional)
          * @param timeout timeout settings for the setTimeout function. default - 0.
-         * @constructor
+         * @returns the created async loop object
          */
-        public static SyncAsyncForLoop(iterations: number, syncedIterations: number, fn: (iteration: number) => void, callback: () => void, breakFunction?: () => boolean, timeout: number = 0) {
-            AsyncLoop.Run(Math.ceil(iterations / syncedIterations), (loop: AsyncLoop) => {
+        public static SyncAsyncForLoop(iterations: number, syncedIterations: number, fn: (iteration: number) => void, callback: () => void, breakFunction?: () => boolean, timeout: number = 0): AsyncLoop {
+            return AsyncLoop.Run(Math.ceil(iterations / syncedIterations), (loop: AsyncLoop) => {
                 if (breakFunction && breakFunction()) loop.breakLoop();
                 else {
                     setTimeout(() => {