Преглед изворни кода

Adding Scene.onRenderingGroupObservable

Also removed the /// <reference tags in some files
nockawa пре 8 година
родитељ
комит
99f1fbc5b6

+ 1 - 3
postProcessLibrary/postProcesses/asciiArt/babylon.asciiArtPostProcess.ts

@@ -1,6 +1,4 @@
- /// <reference path="../../../dist/preview release/babylon.d.ts"/>
- 
-module BABYLON {
+module BABYLON {
 
     /**
      * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.

+ 1 - 3
postProcessLibrary/postProcesses/digitalRain/babylon.digitalRainPostProcess.ts

@@ -1,6 +1,4 @@
- /// <reference path="../../../dist/preview release/babylon.d.ts"/>
- 
-module BABYLON {
+module BABYLON {
 
     /**
      * DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.

+ 42 - 0
src/Rendering/babylon.renderingManager.ts

@@ -23,6 +23,7 @@
         private _customOpaqueSortCompareFn: { [id:number]: (a: SubMesh, b: SubMesh) => number } = {};
         private _customAlphaTestSortCompareFn: { [id:number]: (a: SubMesh, b: SubMesh) => number } = {};
         private _customTransparentSortCompareFn: { [id:number]: (a: SubMesh, b: SubMesh) => number } = {};
+        private _renderinGroupInfo: RenderingGroupInfo = null;
 
         constructor(scene: Scene) {
             this._scene = scene;
@@ -101,6 +102,18 @@
         public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>) => void,
             activeMeshes: AbstractMesh[], renderParticles: boolean, renderSprites: boolean): void {
 
+            // Check if there's at least on observer on the onRenderingGroupObservable and initialize things to fire it
+            let observable = this._scene.onRenderingGroupObservable.hasObservers() ? this._scene.onRenderingGroupObservable : null;
+            let info: RenderingGroupInfo = null;
+            if (observable) {
+                if (!this._renderinGroupInfo) {
+                    this._renderinGroupInfo = new RenderingGroupInfo();
+                }
+                info = this._renderinGroupInfo;
+                info.scene = this._scene;
+                info.camera = this._scene.activeCamera;
+            }
+
             this._currentActiveMeshes = activeMeshes;
             this._currentRenderParticles = renderParticles;
             this._currentRenderSprites = renderSprites;
@@ -113,19 +126,48 @@
                 this._currentIndex = index;
 
                 if (renderingGroup) {
+                    let renderingGroupMask = 0;
+
+                    // Fire PRECLEAR stage
+                    if (observable) {
+                        renderingGroupMask = Math.pow(2, index);
+                        info.renderStage = RenderingGroupInfo.STAGE_PRECLEAR;
+                        info.renderingGroupId = index;
+                        observable.notifyObservers(info, renderingGroupMask);
+                    }
+
+                    // Clear depth/stencil if needed
                     if (this._autoClearDepthStencil[index]) {
                         this._clearDepthStencilBuffer();
                     }
 
+                    // Fire PREOPAQUE stage
+                    if (observable) {
+                        info.renderStage = RenderingGroupInfo.STAGE_PREOPAQUE;
+                        observable.notifyObservers(info, renderingGroupMask);
+                    }
+
                     if (!renderingGroup.onBeforeTransparentRendering) {
                         renderingGroup.onBeforeTransparentRendering = this._renderSpritesAndParticles.bind(this);
                     }
 
+                    // Fire PRETRANSPARENT stage
+                    if (observable) {
+                        info.renderStage = RenderingGroupInfo.STAGE_PRETRANSPARENT;
+                        observable.notifyObservers(info, renderingGroupMask);
+                    }
+
                     if (!renderingGroup.render(customRenderFunction)) {
                         this._renderingGroups.splice(index, 1);
                         needToStepBack = true;
                         this._renderSpritesAndParticles();
                     }
+
+                    // Fire POSTTRANSPARENT stage
+                    if (observable) {
+                        info.renderStage = RenderingGroupInfo.STAGE_POSTTRANSPARENT;
+                        observable.notifyObservers(info, renderingGroupMask);
+                    }
                 } else {
                     this._renderSpritesAndParticles();
                 }

+ 52 - 0
src/babylon.scene.ts

@@ -63,6 +63,51 @@
     }
 
     /**
+     * This class is used by the onRenderingGroupObservable
+     */
+    export class RenderingGroupInfo {
+        /**
+         * The Scene that being rendered
+         */
+        scene: Scene;
+
+        /**
+         * The camera currently used for the rendering pass
+         */
+        camera: Camera;
+
+        /**
+         * The ID of the renderingGroup being processed
+         */
+        renderingGroupId: number;
+
+        /**
+         * The rendering stage, can be either STAGE_PRECLEAR, STAGE_PREOPAQUE, STAGE_PRETRANSPARENT, STAGE_POSTTRANSPARENT
+         */
+        renderStage: number;
+
+        /**
+         * Stage corresponding to the very first hook in the renderingGroup phase: before the render buffer may be cleared
+         */
+        static STAGE_PRECLEAR = 1;
+
+        /**
+         * Called before opaque object are rendered
+         */
+        static STAGE_PREOPAQUE = 2;
+
+        /**
+         * Called after the opaque objects are rendered and before the transparent ones
+         */
+        static STAGE_PRETRANSPARENT = 3;
+
+        /**
+         * Called after the transparent object are rendered, last hook of the renderingGroup phase
+         */
+        static STAGE_POSTTRANSPARENT = 4;
+    }
+
+    /**
      * Represents a scene to be rendered by the engine.
      * @see http://doc.babylonjs.com/page.php?p=21911
      */
@@ -234,6 +279,13 @@
         */
         public onMeshRemovedObservable = new Observable<AbstractMesh>();
 
+        /**
+         * This Observable will be triggered for each stage of each renderingGroup of each rendered camera.
+         * The RenderinGroupInfo class contains all the information about the context in which the observable is called
+         * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)
+         */
+        public onRenderingGroupObservable = new Observable<RenderingGroupInfo>();
+
         // Animations
         public animations: Animation[] = [];