浏览代码

default utility layer will not autocleardepth

Trevor Baron 7 年之前
父节点
当前提交
f85a6428c2

+ 1 - 1
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -49,7 +49,7 @@ module BABYLON {
          * @param gizmoLayer The utility layer the gizmo will be added to
          * @param color The color of the gizmo
          */
-        constructor(color:Color3 = Color3.Gray(), gizmoLayer:UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer){
+        constructor(color:Color3 = Color3.Gray(), gizmoLayer:UtilityLayerRenderer = UtilityLayerRenderer.DefaultKeepDepthUtilityLayer){
             super(gizmoLayer);
 
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to

+ 1 - 6
src/Gizmos/babylon.gizmoManager.ts

@@ -12,7 +12,6 @@ module BABYLON {
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         private _attachedMesh:Nullable<AbstractMesh> = null;
         private _boundingBoxColor = BABYLON.Color3.FromHexString("#0984e3");
-        private _boundingBoxUtilLayer:Nullable<UtilityLayerRenderer> = null;
         private _dragBehavior = new BABYLON.SixDofDragBehavior();
         /**
          * Array of meshes which will have the gizmo attached when a pointer selected them. If null, all meshes are attachable. (Default: null)
@@ -138,11 +137,7 @@ module BABYLON {
          */
         public set boundingBoxGizmoEnabled(value:boolean){
             if(value){
-                if(!this._boundingBoxUtilLayer){
-                    this._boundingBoxUtilLayer = new BABYLON.UtilityLayerRenderer(this.scene);
-                    this._boundingBoxUtilLayer.utilityLayerScene.autoClearDepthAndStencil = false;
-                }
-                this.gizmos.boundingBoxGizmo = this.gizmos.boundingBoxGizmo || new BoundingBoxGizmo(this._boundingBoxColor, this._boundingBoxUtilLayer);
+                this.gizmos.boundingBoxGizmo = this.gizmos.boundingBoxGizmo || new BoundingBoxGizmo(this._boundingBoxColor);
                 this.gizmos.boundingBoxGizmo.attachedMesh = this._attachedMesh;
                 if(this._attachedMesh){
                     this._attachedMesh.removeBehavior(this._dragBehavior);

+ 18 - 1
src/Rendering/babylon.utilityLayerRenderer.ts

@@ -6,15 +6,32 @@ module BABYLON {
         private _pointerCaptures: {[pointerId:number]: boolean} = {};
         private _lastPointerEvents: {[pointerId:number]: number} = {};
         private static _DefaultUtilityLayer:Nullable<UtilityLayerRenderer> = null;
+        private static _DefaultKeepDepthUtilityLayer:Nullable<UtilityLayerRenderer> = null;
+        /** 
+         * A shared utility layer that can be used to overlay objects into a scene (Depth map of the previous scene is cleared before drawing on top of it)
+         */ 
         public static get DefaultUtilityLayer():UtilityLayerRenderer{
             if(UtilityLayerRenderer._DefaultUtilityLayer == null){
                 UtilityLayerRenderer._DefaultUtilityLayer = new UtilityLayerRenderer(BABYLON.Engine.LastCreatedScene!);
-                UtilityLayerRenderer._DefaultUtilityLayer.originalScene.onDisposeObservable.add(()=>{
+                UtilityLayerRenderer._DefaultUtilityLayer.originalScene.onDisposeObservable.addOnce(()=>{
                     UtilityLayerRenderer._DefaultUtilityLayer = null;
                 });
             }
             return UtilityLayerRenderer._DefaultUtilityLayer;
         }
+        /** 
+         * A shared utility layer that can be used to embed objects into a scene (Depth map of the previous scene is not cleared before drawing on top of it)
+         */ 
+        public static get DefaultKeepDepthUtilityLayer():UtilityLayerRenderer{
+            if(UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null){
+                UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(BABYLON.Engine.LastCreatedScene!);
+                UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
+                UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(()=>{
+                    UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;
+                });
+            }
+            return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;
+        }
 
         /** 
          * The scene that is rendered on top of the original scene