浏览代码

add spacing to attachToBoxBehavior to make it less dense, do not clear when applying post processes to utility layer

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

+ 15 - 5
src/Behaviors/Mesh/babylon.attachToBoxBehavior.ts

@@ -26,17 +26,24 @@ module BABYLON {
         private _target:Mesh;
         private _scene:Scene;
         private _onRenderObserver:Nullable<Observer<Scene>>;
+        private _tmpMatrix = new Matrix();
+        private _tmpVector = new Vector3();
+
         /**
          * Creates the AttachToBoxBehavior, used to attach UI to the closest face of the box to a camera
          * @param ui The transform node that should be attched to the mesh
          */
-        constructor(private ui: BABYLON.TransformNode){}
-         /**
+        constructor(private ui: BABYLON.TransformNode){
+            /* Does nothing */
+        }
+
+        /**
          *  Initializes the behavior
          */
-        init(){}
-        private _tmpMatrix = new Matrix();
-        private _tmpVector = new Vector3();
+        public init(){
+            /* Does nothing */
+        }
+        
         private _closestFace(targetDirection:Vector3){
             // Go over each face and calculate the angle between the face's normal and targetDirection
             this._faceVectors.forEach((v)=>{
@@ -58,6 +65,7 @@ module BABYLON {
                 }
             }, this._faceVectors[0]);
         }
+        
         private _zeroVector = Vector3.Zero();
         private _lookAtTmpMatrix = new Matrix();
         private _lookAtToRef(pos:Vector3, up = new BABYLON.Vector3(0,1,0), ref:Quaternion){
@@ -65,6 +73,7 @@ module BABYLON {
             this._lookAtTmpMatrix.invert();
             BABYLON.Quaternion.FromRotationMatrixToRef(this._lookAtTmpMatrix, ref);
         }
+
         /**
          * Attaches the AttachToBoxBehavior to the passed in mesh
          * @param target The mesh that the specified node will be attached to
@@ -146,6 +155,7 @@ module BABYLON {
                 this.ui.position.addInPlace(this._tmpVector);
             })
         }
+
         /**
          *  Detaches the behavior from the mesh
          */

+ 1 - 1
src/PostProcess/babylon.postProcess.ts

@@ -468,7 +468,7 @@
             this.onActivateObservable.notifyObservers(camera);
 
             // Clear
-            if (this.autoClear && this.alphaMode === Engine.ALPHA_DISABLE) {
+            if (scene._allowPostProcessClear && this.autoClear && this.alphaMode === Engine.ALPHA_DISABLE) {
                 this._engine.clear(this.clearColor ? this.clearColor : scene.clearColor, true, true, true);
             }
 

+ 25 - 2
src/Rendering/babylon.utilityLayerRenderer.ts

@@ -53,7 +53,7 @@ module BABYLON {
         constructor(/** the original scene that will be rendered on top of */ public originalScene:Scene){
             // Create scene which will be rendered in the foreground and remove it from being referenced by engine to avoid interfering with existing app
             this.utilityLayerScene = new BABYLON.Scene(originalScene.getEngine());
-            this.utilityLayerScene._renderPostProcesses = false;
+            this.utilityLayerScene._allowPostProcessClear = false;
             originalScene.getEngine().scenes.pop();
 
             // Detach controls on utility scene, events will be fired by logic below to handle picking priority
@@ -172,7 +172,30 @@ module BABYLON {
          */
         public render(){
             this._updateCamera();
-            this.utilityLayerScene.render(false);
+            if(this.utilityLayerScene.activeCamera){
+                // Set the camera's scene to utility layers scene
+                var oldScene = this.utilityLayerScene.activeCamera.getScene();
+                var camera = this.utilityLayerScene.activeCamera;
+                camera._scene = this.utilityLayerScene;
+                if(camera.leftCamera){
+                    camera.leftCamera._scene = this.utilityLayerScene;
+                }
+                if(camera.rightCamera){
+                    camera.rightCamera._scene = this.utilityLayerScene;
+                }
+
+                this.utilityLayerScene.render(false);
+
+                // Reset camera's scene back to original
+                camera._scene = oldScene;
+                if(camera.leftCamera){
+                    camera.leftCamera._scene = oldScene;
+                }
+                if(camera.rightCamera){
+                    camera.rightCamera._scene = oldScene;
+                }
+            }
+            
         }
 
         /**

+ 2 - 2
src/babylon.node.ts

@@ -96,8 +96,8 @@
 
         /** @hidden */
         public _waitingParentId: Nullable<string>;
-
-        private _scene: Scene;
+        /** @hidden */
+        public _scene: Scene;
         /** @hidden */
         public _cache: any;
 

+ 3 - 3
src/babylon.scene.ts

@@ -4334,7 +4334,7 @@
             this._setAlternateTransformMatrix(alternateCamera.getViewMatrix(), alternateCamera.getProjectionMatrix());
         }
         /** @hidden */
-        public _renderPostProcesses = true;
+        public _allowPostProcessClear = true;
         private _renderForCamera(camera: Camera, rigParent?: Camera): void {
             if (camera && camera._skipRendering) {
                 return;
@@ -4413,7 +4413,7 @@
             this.onAfterRenderTargetsRenderObservable.notifyObservers(this);
 
             // Prepare Frame
-            if (this.postProcessManager && this._renderPostProcesses) {
+            if (this.postProcessManager) {
                 this.postProcessManager._prepareFrame();
             }
 
@@ -4433,7 +4433,7 @@
             }
             
             // Finalize frame
-            if (this.postProcessManager && this._renderPostProcesses) {
+            if (this.postProcessManager) {
                 this.postProcessManager._finalizeFrame(camera.isIntermediate);
             }