Forráskód Böngészése

Merge pull request #1405 from sebavan/HighlightLayerExcludeList

Highlight layer exclude list
David Catuhe 8 éve
szülő
commit
070bd71d5e
1 módosított fájl, 41 hozzáadás és 31 törlés
  1. 41 31
      src/Layer/babylon.highlightlayer.ts

+ 41 - 31
src/Layer/babylon.highlightlayer.ts

@@ -87,7 +87,7 @@
          * The neutral color used during the preparation of the glow effect.
          * The neutral color used during the preparation of the glow effect.
          * This is black by default as the blend operation is a blend operation. 
          * This is black by default as the blend operation is a blend operation. 
          */
          */
-        public static neutralColor:Color4 = new Color4(0, 0, 0, 0);
+        public static neutralColor: Color4 = new Color4(0, 0, 0, 0);
 
 
         /**
         /**
          * Stencil value used for glowing meshes.
          * Stencil value used for glowing meshes.
@@ -109,12 +109,12 @@
         private _verticalBlurPostprocess: GlowBlurPostProcess;
         private _verticalBlurPostprocess: GlowBlurPostProcess;
         private _cachedDefines: string;
         private _cachedDefines: string;
         private _glowMapGenerationEffect: Effect;
         private _glowMapGenerationEffect: Effect;
-        private _glowMapMergeEffect: Effect;      
+        private _glowMapMergeEffect: Effect;
         private _blurTexture: RenderTargetTexture;
         private _blurTexture: RenderTargetTexture;
         private _mainTexture: RenderTargetTexture;
         private _mainTexture: RenderTargetTexture;
-        private _mainTextureDesiredSize: ISize = { width:0, height:0 };
-        private _meshes: {[id: string]: IHighlightLayerMesh} = {};
-        private _maxSize:number = 0;
+        private _mainTextureDesiredSize: ISize = { width: 0, height: 0 };
+        private _meshes: { [id: string]: IHighlightLayerMesh } = {};
+        private _maxSize: number = 0;
         private _shouldRender = false;
         private _shouldRender = false;
         private _instanceGlowingMeshStencilReference = HighlightLayer.glowingMeshStencilReference++;
         private _instanceGlowingMeshStencilReference = HighlightLayer.glowingMeshStencilReference++;
 
 
@@ -122,13 +122,18 @@
          * Specifies whether or not the inner glow is ACTIVE in the layer.
          * Specifies whether or not the inner glow is ACTIVE in the layer.
          */
          */
         public innerGlow: boolean = true;
         public innerGlow: boolean = true;
-        
+
         /**
         /**
          * Specifies whether or not the outer glow is ACTIVE in the layer.
          * Specifies whether or not the outer glow is ACTIVE in the layer.
          */
          */
         public outerGlow: boolean = true;
         public outerGlow: boolean = true;
 
 
         /**
         /**
+         * Specifies the listof mesh excluded during the generation of the highlight layer.
+         */
+        public excludedMeshes: Mesh[] = [];
+
+        /**
          * Specifies the horizontal size of the blur.
          * Specifies the horizontal size of the blur.
          */
          */
         public set blurHorizontalSize(value: number) {
         public set blurHorizontalSize(value: number) {
@@ -173,7 +178,7 @@
          * @type {BABYLON.Observable}
          * @type {BABYLON.Observable}
          */
          */
         public onBeforeBlurObservable = new Observable<HighlightLayer>();
         public onBeforeBlurObservable = new Observable<HighlightLayer>();
-        
+
         /**
         /**
          * An event triggered when the highlight layer has been blurred.
          * An event triggered when the highlight layer has been blurred.
          * @type {BABYLON.Observable}
          * @type {BABYLON.Observable}
@@ -224,7 +229,7 @@
                 blurVerticalSize: 1,
                 blurVerticalSize: 1,
                 alphaBlendingMode: Engine.ALPHA_COMBINE
                 alphaBlendingMode: Engine.ALPHA_COMBINE
             };
             };
-            this._options.mainTextureRatio = this._options.mainTextureRatio || 0.25; 
+            this._options.mainTextureRatio = this._options.mainTextureRatio || 0.25;
             this._options.blurTextureSizeRatio = this._options.blurTextureSizeRatio || 0.5;
             this._options.blurTextureSizeRatio = this._options.blurTextureSizeRatio || 0.5;
             this._options.blurHorizontalSize = this._options.blurHorizontalSize || 1;
             this._options.blurHorizontalSize = this._options.blurHorizontalSize || 1;
             this._options.blurVerticalSize = this._options.blurVerticalSize || 1;
             this._options.blurVerticalSize = this._options.blurVerticalSize || 1;
@@ -250,13 +255,13 @@
             indices.push(3);
             indices.push(3);
 
 
             this._indexBuffer = engine.createIndexBuffer(indices);
             this._indexBuffer = engine.createIndexBuffer(indices);
-            
+
             // Effect
             // Effect
             this._glowMapMergeEffect = engine.createEffect("glowMapMerge",
             this._glowMapMergeEffect = engine.createEffect("glowMapMerge",
                 [VertexBuffer.PositionKind],
                 [VertexBuffer.PositionKind],
                 ["offset"],
                 ["offset"],
                 ["textureSampler"], "");
                 ["textureSampler"], "");
-            
+
             // Render target
             // Render target
             this.setMainTextureSize();
             this.setMainTextureSize();
 
 
@@ -273,13 +278,13 @@
             blurTextureWidth = Tools.GetExponentOfTwo(blurTextureWidth, this._maxSize);
             blurTextureWidth = Tools.GetExponentOfTwo(blurTextureWidth, this._maxSize);
             blurTextureHeight = Tools.GetExponentOfTwo(blurTextureHeight, this._maxSize);
             blurTextureHeight = Tools.GetExponentOfTwo(blurTextureHeight, this._maxSize);
 
 
-            this._mainTexture = new RenderTargetTexture("HighlightLayerMainRTT", 
+            this._mainTexture = new RenderTargetTexture("HighlightLayerMainRTT",
                 {
                 {
                     width: this._mainTextureDesiredSize.width,
                     width: this._mainTextureDesiredSize.width,
                     height: this._mainTextureDesiredSize.height
                     height: this._mainTextureDesiredSize.height
-                }, 
-                this._scene, 
-                false, 
+                },
+                this._scene,
+                false,
                 true,
                 true,
                 Engine.TEXTURETYPE_UNSIGNED_INT);
                 Engine.TEXTURETYPE_UNSIGNED_INT);
             this._mainTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
             this._mainTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
@@ -293,9 +298,9 @@
                 {
                 {
                     width: blurTextureWidth,
                     width: blurTextureWidth,
                     height: blurTextureHeight
                     height: blurTextureHeight
-                }, 
-                this._scene, 
-                false, 
+                },
+                this._scene,
+                false,
                 true,
                 true,
                 Engine.TEXTURETYPE_UNSIGNED_INT);
                 Engine.TEXTURETYPE_UNSIGNED_INT);
             this._blurTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
             this._blurTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
@@ -304,19 +309,19 @@
             this._blurTexture.updateSamplingMode(Texture.TRILINEAR_SAMPLINGMODE);
             this._blurTexture.updateSamplingMode(Texture.TRILINEAR_SAMPLINGMODE);
             this._blurTexture.renderParticles = false;
             this._blurTexture.renderParticles = false;
 
 
-            this._downSamplePostprocess = new PassPostProcess("HighlightLayerPPP", this._options.blurTextureSizeRatio, 
+            this._downSamplePostprocess = new PassPostProcess("HighlightLayerPPP", this._options.blurTextureSizeRatio,
                 null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
                 null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
             this._downSamplePostprocess.onApplyObservable.add(effect => {
             this._downSamplePostprocess.onApplyObservable.add(effect => {
                 effect.setTexture("textureSampler", this._mainTexture);
                 effect.setTexture("textureSampler", this._mainTexture);
             });
             });
 
 
-            this._horizontalBlurPostprocess = new GlowBlurPostProcess("HighlightLayerHBP", new BABYLON.Vector2(1.0, 0), this._options.blurHorizontalSize, 1, 
+            this._horizontalBlurPostprocess = new GlowBlurPostProcess("HighlightLayerHBP", new BABYLON.Vector2(1.0, 0), this._options.blurHorizontalSize, 1,
                 null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
                 null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
             this._horizontalBlurPostprocess.onApplyObservable.add(effect => {
             this._horizontalBlurPostprocess.onApplyObservable.add(effect => {
                 effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
                 effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
             });
             });
 
 
-            this._verticalBlurPostprocess = new GlowBlurPostProcess("HighlightLayerVBP", new BABYLON.Vector2(0, 1.0), this._options.blurVerticalSize, 1, 
+            this._verticalBlurPostprocess = new GlowBlurPostProcess("HighlightLayerVBP", new BABYLON.Vector2(0, 1.0), this._options.blurVerticalSize, 1,
                 null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
                 null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
             this._verticalBlurPostprocess.onApplyObservable.add(effect => {
             this._verticalBlurPostprocess.onApplyObservable.add(effect => {
                 effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
                 effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
@@ -326,9 +331,9 @@
                 this.onBeforeBlurObservable.notifyObservers(this);
                 this.onBeforeBlurObservable.notifyObservers(this);
 
 
                 this._scene.postProcessManager.directRender(
                 this._scene.postProcessManager.directRender(
-                    [this._downSamplePostprocess, this._horizontalBlurPostprocess, this._verticalBlurPostprocess], 
+                    [this._downSamplePostprocess, this._horizontalBlurPostprocess, this._verticalBlurPostprocess],
                     this._blurTexture.getInternalTexture());
                     this._blurTexture.getInternalTexture());
-                
+
                 this.onAfterBlurObservable.notifyObservers(this);
                 this.onAfterBlurObservable.notifyObservers(this);
             });
             });
 
 
@@ -347,6 +352,11 @@
                     return;
                     return;
                 }
                 }
 
 
+                // Excluded Mesh
+                if (this.excludedMeshes.indexOf(mesh) > -1) {
+                    return;
+                };
+
                 var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null) && (batch.visibleInstances[subMesh._id] !== undefined);
                 var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null) && (batch.visibleInstances[subMesh._id] !== undefined);
 
 
                 var highlightLayerMesh = this._meshes[mesh.id];
                 var highlightLayerMesh = this._meshes[mesh.id];
@@ -362,14 +372,14 @@
 
 
                     this._glowMapGenerationEffect.setMatrix("viewProjection", scene.getTransformMatrix());
                     this._glowMapGenerationEffect.setMatrix("viewProjection", scene.getTransformMatrix());
                     if (highlightLayerMesh) {
                     if (highlightLayerMesh) {
-                        this._glowMapGenerationEffect.setFloat4("color", 
+                        this._glowMapGenerationEffect.setFloat4("color",
                             highlightLayerMesh.color.r,
                             highlightLayerMesh.color.r,
                             highlightLayerMesh.color.g,
                             highlightLayerMesh.color.g,
                             highlightLayerMesh.color.b,
                             highlightLayerMesh.color.b,
                             1.0);
                             1.0);
                     }
                     }
                     else {
                     else {
-                        this._glowMapGenerationEffect.setFloat4("color", 
+                        this._glowMapGenerationEffect.setFloat4("color",
                             HighlightLayer.neutralColor.r,
                             HighlightLayer.neutralColor.r,
                             HighlightLayer.neutralColor.g,
                             HighlightLayer.neutralColor.g,
                             HighlightLayer.neutralColor.b,
                             HighlightLayer.neutralColor.b,
@@ -453,7 +463,7 @@
                 if (alphaTexture) {
                 if (alphaTexture) {
                     defines.push("#define ALPHATEST");
                     defines.push("#define ALPHATEST");
                     if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) &&
                     if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) &&
-                        alphaTexture.coordinatesIndex === 1) {                    
+                        alphaTexture.coordinatesIndex === 1) {
                         defines.push("#define DIFFUSEUV2");
                         defines.push("#define DIFFUSEUV2");
                         uv2 = true;
                         uv2 = true;
                     }
                     }
@@ -468,7 +478,7 @@
             if (emissiveTexture) {
             if (emissiveTexture) {
                 defines.push("#define EMISSIVE");
                 defines.push("#define EMISSIVE");
                 if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) &&
                 if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) &&
-                    emissiveTexture.coordinatesIndex === 1) {                    
+                    emissiveTexture.coordinatesIndex === 1) {
                     defines.push("#define EMISSIVEUV2");
                     defines.push("#define EMISSIVEUV2");
                     uv2 = true;
                     uv2 = true;
                 }
                 }
@@ -605,7 +615,7 @@
                     mesh: mesh,
                     mesh: mesh,
                     color: color,
                     color: color,
                     // Lambda required for capture due to Observable this context
                     // Lambda required for capture due to Observable this context
-                    observerHighlight: mesh.onBeforeRenderObservable.add((mesh: Mesh) => { 
+                    observerHighlight: mesh.onBeforeRenderObservable.add((mesh: Mesh) => {
                         mesh.getScene().getEngine().setStencilFunctionReference(this._instanceGlowingMeshStencilReference);
                         mesh.getScene().getEngine().setStencilFunctionReference(this._instanceGlowingMeshStencilReference);
                     }),
                     }),
                     observerDefault: mesh.onAfterRenderObservable.add(this.defaultStencilReference),
                     observerDefault: mesh.onAfterRenderObservable.add(this.defaultStencilReference),
@@ -624,7 +634,7 @@
             var meshHighlight = this._meshes[mesh.id];
             var meshHighlight = this._meshes[mesh.id];
             if (meshHighlight) {
             if (meshHighlight) {
                 mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
                 mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault); 
+                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
             }
             }
 
 
             this._meshes[mesh.id] = undefined;
             this._meshes[mesh.id] = undefined;
@@ -649,7 +659,7 @@
          * Sets the main texture desired size which is the closest power of two
          * Sets the main texture desired size which is the closest power of two
          * of the engine canvas size.
          * of the engine canvas size.
          */
          */
-        private setMainTextureSize() : void {
+        private setMainTextureSize(): void {
             this._mainTextureDesiredSize.width = this._engine.getRenderingCanvas().width * this._options.mainTextureRatio;
             this._mainTextureDesiredSize.width = this._engine.getRenderingCanvas().width * this._options.mainTextureRatio;
             this._mainTextureDesiredSize.height = this._engine.getRenderingCanvas().height * this._options.mainTextureRatio;
             this._mainTextureDesiredSize.height = this._engine.getRenderingCanvas().height * this._options.mainTextureRatio;
 
 
@@ -670,7 +680,7 @@
         private disposeTextureAndPostProcesses(): void {
         private disposeTextureAndPostProcesses(): void {
             this._blurTexture.dispose();
             this._blurTexture.dispose();
             this._mainTexture.dispose();
             this._mainTexture.dispose();
-            
+
             this._downSamplePostprocess.dispose();
             this._downSamplePostprocess.dispose();
             this._horizontalBlurPostprocess.dispose();
             this._horizontalBlurPostprocess.dispose();
             this._verticalBlurPostprocess.dispose();
             this._verticalBlurPostprocess.dispose();
@@ -700,7 +710,7 @@
                 if (meshHighlight && meshHighlight.mesh) {
                 if (meshHighlight && meshHighlight.mesh) {
                     meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
                     meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
                     meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
                     meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
-                } 
+                }
             }
             }
             this._meshes = null;
             this._meshes = null;