소스 검색

reapply part of the changes

sevan 8 년 전
부모
커밋
b51bc3d20b
3개의 변경된 파일35개의 추가작업 그리고 53개의 파일을 삭제
  1. 31 46
      src/Cameras/Holographic/babylon.holographicCamera.ts
  2. 0 4
      src/Cameras/babylon.camera.ts
  3. 4 3
      src/babylon.scene.ts

+ 31 - 46
src/Cameras/Holographic/babylon.holographicCamera.ts

@@ -6,26 +6,18 @@
         private _scriptProjection: Matrix;
         private _scriptViewProjection: Matrix;
 
-        private _onBeforeRenderObserver: Observer<Scene>;
+        private _holographicViewMatrix: Matrix;
 
-        private _holographicViewMatrix: Matrix;        
-        private _holographicViewMatrixChanged = false;
+        private _onBeforeRenderObserver: Observer<Scene>;
+        private _onBeforeCameraRenderObserver: Observer<Camera>;
 
         constructor(name: string, position: Vector3, scene: Scene) {            
             super(name, position, scene);
 
-            this._holographicViewMatrix = new Matrix();
-
             scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
             
-            var self = this;
-            this._onBeforeRenderObserver = scene.onBeforeRenderObservable.add(function (scene) {
-                self._holographicViewMatrix.m = (<any>window).getViewMatrix();
-                self.setViewMatrix(self._holographicViewMatrix);
-            })
-
+            this._holographicViewMatrix = new Matrix();            
             this._identityProjection = BABYLON.Matrix.Identity();
-
             this._scriptProjection = BABYLON.Matrix.Transpose(BABYLON.Matrix.PerspectiveFovLH(30, window.innerWidth / window.innerHeight, 1, 20));
             this._scriptViewProjection = BABYLON.Matrix.Identity();
 
@@ -39,6 +31,17 @@
             this.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED;
             this.cameraRigMode = BABYLON.Camera.RIG_MODE_NONE;
 
+            var self = this;
+            this._onBeforeRenderObserver = scene.onBeforeRenderObservable.add(function (scene) {
+                self._holographicViewMatrix.m = (<any>window).getViewMatrix();
+                self.setViewMatrix(self._holographicViewMatrix);
+            })
+            this._onBeforeCameraRenderObserver = scene.onBeforeCameraRenderObservable.add(function() {
+                if (scene.frustumPlanes) {
+                    self.getFrustumPlanesToRef(scene.frustumPlanes);
+                }
+            })
+
             scene.addCamera(this);
             if (!scene.activeCamera) {
                 scene.activeCamera = this;
@@ -47,25 +50,15 @@
 
         public getTypeName(): string {
             return "HolographicCamera";
-        };
-        
-        public _initCache(): void {
-        };
-
-        public _updateCache(): void {
-            // Check why ???
-            this._holographicViewMatrixChanged = false;
-        };
+        };        
 
-        public _updateFromScene(): void {
-        };
 
-        // Synchronized
-        public _isSynchronizedViewMatrix() : boolean {
-            return !this._holographicViewMatrixChanged;
+        public getProjectionMatrix(): Matrix {
+            return this._identityProjection;
         };
-        public _isSynchronizedProjectionMatrix() : boolean {
-            return true;
+        
+        public getViewMatrix(): Matrix {
+            return this._holographicViewMatrix;
         };
 
         public setViewMatrix(view: Matrix) : void {
@@ -73,26 +66,18 @@
             this.position.x = view.m[12];
             this.position.y = view.m[13];
             this.position.z = -view.m[14];
-            this._holographicViewMatrixChanged = true;
-        };
-
-        public getViewMatrix(): Matrix {
-            return this._holographicViewMatrix;
         };
+        
+        public _initCache(): void { };
+        public _updateCache(): void { };
+        public _updateFromScene(): void { };
 
-        public getProjectionMatrix(): Matrix {
-            return this._identityProjection;
+        // Synchronized
+        public _isSynchronizedViewMatrix() : boolean {
+            return true;
         };
-
-        public computeFrustumPlanes(frustumPlanes: Plane[]) : void {
-            if (frustumPlanes) {
-                this.getFrustumPlanesToRef(frustumPlanes);
-            }
-        }
-        
-        private getFrustumPlanes(): Plane[] {
-            this._holographicViewMatrix.multiplyToRef(this._scriptProjection, this._scriptViewProjection);
-            return BABYLON.Frustum.GetPlanes(this._scriptViewProjection);
+        public _isSynchronizedProjectionMatrix() : boolean {
+            return true;
         };
 
         private getFrustumPlanesToRef(result: Plane[]): Plane[] {
@@ -103,7 +88,7 @@
 
         public dispose(): void {
             this.getScene().onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
-
+            this.getScene().onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver);
             super.dispose();
         }
     }

+ 0 - 4
src/Cameras/babylon.camera.ts

@@ -808,9 +808,5 @@
 
             return camera;
         }
-
-        public computeFrustumPlanes(frustumPlanes: Plane[]) { 
-            // NOP by default.
-        }
     }
 }

+ 4 - 3
src/babylon.scene.ts

@@ -543,7 +543,11 @@
 
         private _viewMatrix: Matrix;
         private _projectionMatrix: Matrix;
+        
         private _frustumPlanes: Plane[];
+        public get frustumPlanes(): Plane[] {
+            return this._frustumPlanes;
+        }
 
         private _selectionOctree: Octree<AbstractMesh>;
 
@@ -561,7 +565,6 @@
         private _externalData: StringDictionary<Object>;
         private _uid: string;
 
-
         /**
          * @constructor
          * @param {BABYLON.Engine} engine - the engine to be used to render this scene.
@@ -1983,8 +1986,6 @@
             this._boundingBoxRenderer.reset();
             this._edgesRenderers.reset();
 
-            this.activeCamera.computeFrustumPlanes(this._frustumPlanes);
-
             // Meshes
             var meshes: AbstractMesh[];
             var len: number;