Browse Source

Doc Layer

sebastien 7 years ago
parent
commit
35fb80140e
1 changed files with 66 additions and 5 deletions
  1. 66 5
      src/Layer/babylon.layer.ts

+ 66 - 5
src/Layer/babylon.layer.ts

@@ -1,12 +1,51 @@
 module BABYLON {
 module BABYLON {
+
+    /**
+     * This represents a full screen 2d layer.
+     * This can be usefull to display a picture in the  background of your scene for instance.
+     * @see https://www.babylonjs-playground.com/#08A2BS#1
+     */
     export class Layer {
     export class Layer {
+        /**
+         * Define the texture the layer should display.
+         */
         public texture: Nullable<Texture>;
         public texture: Nullable<Texture>;
+
+        /**
+         * Is the layer in background or foreground.
+         */
         public isBackground: boolean;
         public isBackground: boolean;
+
+        /**
+         * Define the color of the layer (instead of texture).
+         */
         public color: Color4;
         public color: Color4;
+
+        /**
+         * Define the scale of the layer in order to zoom in out of the texture.
+         */
         public scale = new Vector2(1, 1);
         public scale = new Vector2(1, 1);
+
+        /**
+         * Define an offset for the layer in order to shift the texture.
+         */
         public offset = new Vector2(0, 0);
         public offset = new Vector2(0, 0);
+        
+        /**
+         * Define the alpha blending mode used in the layer in case the texture or color has an alpha.
+         */
         public alphaBlendingMode = Engine.ALPHA_COMBINE;
         public alphaBlendingMode = Engine.ALPHA_COMBINE;
+
+        /**
+         * Define if the layer should alpha test or alpha blend with the rest of the scene.
+         * Alpha test will not mix with the background color in case of transparency.
+         * It will either use the texture color or the background depending on the alpha value of the current pixel.
+         */
         public alphaTest: boolean;
         public alphaTest: boolean;
+
+        /**
+         * Define a mask to restrict the layer to only some of the scene cameras.
+         */
         public layerMask: number = 0x0FFFFFFF;
         public layerMask: number = 0x0FFFFFFF;
         
         
         private _scene: Scene;
         private _scene: Scene;
@@ -15,15 +54,16 @@
         private _effect: Effect;
         private _effect: Effect;
         private _alphaTestEffect: Effect;
         private _alphaTestEffect: Effect;
 
 
-
-        // Events
-
         /**
         /**
-        * An event triggered when the layer is disposed.
-        */
+         * An event triggered when the layer is disposed.
+         */
         public onDisposeObservable = new Observable<Layer>();
         public onDisposeObservable = new Observable<Layer>();
 
 
         private _onDisposeObserver: Nullable<Observer<Layer>>;
         private _onDisposeObserver: Nullable<Observer<Layer>>;
+        /**
+         * Back compatibility with callback before the onDisposeObservable existed.
+         * The set callback will be triggered when the layer has been disposed.
+         */
         public set onDispose(callback: () => void) {
         public set onDispose(callback: () => void) {
             if (this._onDisposeObserver) {
             if (this._onDisposeObserver) {
                 this.onDisposeObservable.remove(this._onDisposeObserver);
                 this.onDisposeObservable.remove(this._onDisposeObserver);
@@ -37,6 +77,10 @@
         public onBeforeRenderObservable = new Observable<Layer>();
         public onBeforeRenderObservable = new Observable<Layer>();
 
 
         private _onBeforeRenderObserver: Nullable<Observer<Layer>>;
         private _onBeforeRenderObserver: Nullable<Observer<Layer>>;
+        /**
+         * Back compatibility with callback before the onBeforeRenderObservable existed.
+         * The set callback will be triggered just before rendering the layer.
+         */
         public set onBeforeRender(callback: () => void) {
         public set onBeforeRender(callback: () => void) {
             if (this._onBeforeRenderObserver) {
             if (this._onBeforeRenderObserver) {
                 this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
                 this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
@@ -57,6 +101,17 @@
             this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);
             this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);
         }
         }
 
 
+        /**
+         * Instantiates a new layer.
+         * This represents a full screen 2d layer.
+         * This can be usefull to display a picture in the  background of your scene for instance.
+         * @see https://www.babylonjs-playground.com/#08A2BS#1
+         * @param name Define the name of the layer in the scene
+         * @param imgUrl Define the url of the texture to display in the layer
+         * @param scene Define the scene the layer belongs to
+         * @param isBackground Defines whether the layer is displayed in front or behind the scene
+         * @param color Defines a color for the layer
+         */
         constructor(public name: string, imgUrl: Nullable<string>, scene: Nullable<Scene>, isBackground?: boolean, color?: Color4) {
         constructor(public name: string, imgUrl: Nullable<string>, scene: Nullable<Scene>, isBackground?: boolean, color?: Color4) {
             this.texture = imgUrl ? new Texture(imgUrl, scene, true) : null;
             this.texture = imgUrl ? new Texture(imgUrl, scene, true) : null;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.isBackground = isBackground === undefined ? true : isBackground;
@@ -123,6 +178,9 @@
             this._createIndexBuffer();
             this._createIndexBuffer();
         }
         }
 
 
+        /**
+         * Renders the layer in the scene.
+         */
         public render(): void {
         public render(): void {
             var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
             var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
 
 
@@ -165,6 +223,9 @@
             this.onAfterRenderObservable.notifyObservers(this);
             this.onAfterRenderObservable.notifyObservers(this);
         }
         }
 
 
+        /**
+         * Disposes and releases the associated ressources.
+         */
         public dispose(): void {
         public dispose(): void {
             var vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];
             var vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];
             if (vertexBuffer) {
             if (vertexBuffer) {