Przeglądaj źródła

Added new observables to camera

David Catuhe 8 lat temu
rodzic
commit
afe086881d

Plik diff jest za duży
+ 905 - 904
dist/preview release/babylon.d.ts


Plik diff jest za duży
+ 2 - 2
dist/preview release/babylon.js


+ 18 - 17
dist/preview release/babylon.max.js

@@ -14373,6 +14373,9 @@ var BABYLON;
             _this._rigCameras = new Array();
             _this._webvrViewMatrix = BABYLON.Matrix.Identity();
             _this.customRenderTargets = new Array();
+            // Observables
+            _this.onViewMatrixChangedObservable = new BABYLON.Observable();
+            _this.onProjectionMatrixChangedObservable = new BABYLON.Observable();
             // Cache
             _this._computedViewMatrix = BABYLON.Matrix.Identity();
             _this._projectionMatrix = new BABYLON.Matrix();
@@ -14677,10 +14680,11 @@ var BABYLON;
             return BABYLON.Matrix.Identity();
         };
         Camera.prototype.getViewMatrix = function (force) {
-            this._computedViewMatrix = this._computeViewMatrix(force);
             if (!force && this._isSynchronizedViewMatrix()) {
                 return this._computedViewMatrix;
             }
+            this._computedViewMatrix = this._getViewMatrix();
+            this._currentRenderId = this.getScene().getRenderId();
             this._refreshFrustumPlanes = true;
             if (!this.parent || !this.parent.getWorldMatrix) {
                 this._globalPosition.copyFrom(this.position);
@@ -14698,15 +14702,7 @@ var BABYLON;
             if (this._cameraRigParams && this._cameraRigParams.vrPreViewMatrix) {
                 this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._computedViewMatrix);
             }
-            this._currentRenderId = this.getScene().getRenderId();
-            return this._computedViewMatrix;
-        };
-        Camera.prototype._computeViewMatrix = function (force) {
-            if (!force && this._isSynchronizedViewMatrix()) {
-                return this._computedViewMatrix;
-            }
-            this._computedViewMatrix = this._getViewMatrix();
-            this._currentRenderId = this.getScene().getRenderId();
+            this.onViewMatrixChangedObservable.notifyObservers(this);
             return this._computedViewMatrix;
         };
         Camera.prototype.freezeProjectionMatrix = function (projection) {
@@ -14737,16 +14733,18 @@ var BABYLON;
                 else {
                     BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix, this.fovMode === Camera.FOVMODE_VERTICAL_FIXED);
                 }
-                return this._projectionMatrix;
-            }
-            var halfWidth = engine.getRenderWidth() / 2.0;
-            var halfHeight = engine.getRenderHeight() / 2.0;
-            if (scene.useRightHandedSystem) {
-                BABYLON.Matrix.OrthoOffCenterRHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
             }
             else {
-                BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
+                var halfWidth = engine.getRenderWidth() / 2.0;
+                var halfHeight = engine.getRenderHeight() / 2.0;
+                if (scene.useRightHandedSystem) {
+                    BABYLON.Matrix.OrthoOffCenterRHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
+                }
+                else {
+                    BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
+                }
             }
+            this.onProjectionMatrixChangedObservable.notifyObservers(this);
             return this._projectionMatrix;
         };
         Camera.prototype.getTranformationMatrix = function () {
@@ -14788,6 +14786,9 @@ var BABYLON;
             return new BABYLON.Ray(origin, direction, length);
         };
         Camera.prototype.dispose = function () {
+            // Observables
+            this.onViewMatrixChangedObservable.clear();
+            this.onProjectionMatrixChangedObservable.clear();
             // Animations
             this.getScene().stopAnimation(this);
             // Remove from scene

Plik diff jest za duży
+ 905 - 904
dist/preview release/babylon.module.d.ts


Plik diff jest za duży
+ 2 - 2
dist/preview release/babylon.worker.js


Plik diff jest za duży
+ 748 - 747
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Plik diff jest za duży
+ 2 - 2
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 18 - 17
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -14373,6 +14373,9 @@ var BABYLON;
             _this._rigCameras = new Array();
             _this._webvrViewMatrix = BABYLON.Matrix.Identity();
             _this.customRenderTargets = new Array();
+            // Observables
+            _this.onViewMatrixChangedObservable = new BABYLON.Observable();
+            _this.onProjectionMatrixChangedObservable = new BABYLON.Observable();
             // Cache
             _this._computedViewMatrix = BABYLON.Matrix.Identity();
             _this._projectionMatrix = new BABYLON.Matrix();
@@ -14677,10 +14680,11 @@ var BABYLON;
             return BABYLON.Matrix.Identity();
         };
         Camera.prototype.getViewMatrix = function (force) {
-            this._computedViewMatrix = this._computeViewMatrix(force);
             if (!force && this._isSynchronizedViewMatrix()) {
                 return this._computedViewMatrix;
             }
+            this._computedViewMatrix = this._getViewMatrix();
+            this._currentRenderId = this.getScene().getRenderId();
             this._refreshFrustumPlanes = true;
             if (!this.parent || !this.parent.getWorldMatrix) {
                 this._globalPosition.copyFrom(this.position);
@@ -14698,15 +14702,7 @@ var BABYLON;
             if (this._cameraRigParams && this._cameraRigParams.vrPreViewMatrix) {
                 this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._computedViewMatrix);
             }
-            this._currentRenderId = this.getScene().getRenderId();
-            return this._computedViewMatrix;
-        };
-        Camera.prototype._computeViewMatrix = function (force) {
-            if (!force && this._isSynchronizedViewMatrix()) {
-                return this._computedViewMatrix;
-            }
-            this._computedViewMatrix = this._getViewMatrix();
-            this._currentRenderId = this.getScene().getRenderId();
+            this.onViewMatrixChangedObservable.notifyObservers(this);
             return this._computedViewMatrix;
         };
         Camera.prototype.freezeProjectionMatrix = function (projection) {
@@ -14737,16 +14733,18 @@ var BABYLON;
                 else {
                     BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix, this.fovMode === Camera.FOVMODE_VERTICAL_FIXED);
                 }
-                return this._projectionMatrix;
-            }
-            var halfWidth = engine.getRenderWidth() / 2.0;
-            var halfHeight = engine.getRenderHeight() / 2.0;
-            if (scene.useRightHandedSystem) {
-                BABYLON.Matrix.OrthoOffCenterRHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
             }
             else {
-                BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
+                var halfWidth = engine.getRenderWidth() / 2.0;
+                var halfHeight = engine.getRenderHeight() / 2.0;
+                if (scene.useRightHandedSystem) {
+                    BABYLON.Matrix.OrthoOffCenterRHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
+                }
+                else {
+                    BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
+                }
             }
+            this.onProjectionMatrixChangedObservable.notifyObservers(this);
             return this._projectionMatrix;
         };
         Camera.prototype.getTranformationMatrix = function () {
@@ -14788,6 +14786,9 @@ var BABYLON;
             return new BABYLON.Ray(origin, direction, length);
         };
         Camera.prototype.dispose = function () {
+            // Observables
+            this.onViewMatrixChangedObservable.clear();
+            this.onProjectionMatrixChangedObservable.clear();
             // Animations
             this.getScene().stopAnimation(this);
             // Remove from scene

Plik diff jest za duży
+ 748 - 747
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 1 - 0
dist/preview release/what's new.md

@@ -5,6 +5,7 @@
 - Engine can now be initialized with an existing webgl context ([deltakosh](https://github.com/deltakosh))
 
 ## Updates
+- Added `camera.onViewMatrixChangedObservable` and `camera.onProjectionMatrixChangedObservable` ([deltakosh](https://github.com/deltakosh))
 - Added support for folders when drag'n'dropping into the sandbox ([deltakosh](https://github.com/deltakosh))
 - Better serialization support ([deltakosh](https://github.com/deltakosh))
 - Introduced `performanceMonitor` class to get better FPS analysis ([deltakosh](https://github.com/deltakosh))

+ 35 - 34
src/Cameras/babylon.camera.ts

@@ -121,7 +121,11 @@
         public _rigPostProcess: PostProcess;
         protected _webvrViewMatrix = Matrix.Identity();
 
-        public customRenderTargets = new Array<RenderTargetTexture>();        
+        public customRenderTargets = new Array<RenderTargetTexture>();    
+        
+        // Observables
+        public onViewMatrixChangedObservable = new Observable<Camera>();
+        public onProjectionMatrixChangedObservable = new Observable<Camera>();
 
         // Cache
         private _computedViewMatrix = Matrix.Identity();
@@ -388,12 +392,13 @@
         }
 
         public getViewMatrix(force?: boolean): Matrix {
-            this._computedViewMatrix = this._computeViewMatrix(force);
-
             if (!force && this._isSynchronizedViewMatrix()) {
                 return this._computedViewMatrix;
             }
 
+            this._computedViewMatrix = this._getViewMatrix();
+            this._currentRenderId = this.getScene().getRenderId();
+            
             this._refreshFrustumPlanes = true;
 
             if (!this.parent || !this.parent.getWorldMatrix) {
@@ -417,21 +422,11 @@
                 this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._computedViewMatrix);
             }
 
-            this._currentRenderId = this.getScene().getRenderId();
+            this.onViewMatrixChangedObservable.notifyObservers(this);
 
             return this._computedViewMatrix;
         }
 
-        public _computeViewMatrix(force?: boolean): Matrix {
-            if (!force && this._isSynchronizedViewMatrix()) {
-                return this._computedViewMatrix;
-            }
-
-            this._computedViewMatrix = this._getViewMatrix();
-            this._currentRenderId = this.getScene().getRenderId();
-
-            return this._computedViewMatrix;
-        }
 
         public freezeProjectionMatrix(projection?: Matrix): void {
             this._doNotComputeProjectionMatrix = true;
@@ -473,28 +468,30 @@
                         this._projectionMatrix,
                         this.fovMode === Camera.FOVMODE_VERTICAL_FIXED);
                 }
-                return this._projectionMatrix;
-            }
-
-            var halfWidth = engine.getRenderWidth() / 2.0;
-            var halfHeight = engine.getRenderHeight() / 2.0;
-            if (scene.useRightHandedSystem) {
-                Matrix.OrthoOffCenterRHToRef(this.orthoLeft || -halfWidth,
-                    this.orthoRight || halfWidth,
-                    this.orthoBottom || -halfHeight,
-                    this.orthoTop || halfHeight,
-                    this.minZ,
-                    this.maxZ,
-                    this._projectionMatrix);
             } else {
-                Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth,
-                    this.orthoRight || halfWidth,
-                    this.orthoBottom || -halfHeight,
-                    this.orthoTop || halfHeight,
-                    this.minZ,
-                    this.maxZ,
-                    this._projectionMatrix);
+                var halfWidth = engine.getRenderWidth() / 2.0;
+                var halfHeight = engine.getRenderHeight() / 2.0;
+                if (scene.useRightHandedSystem) {
+                    Matrix.OrthoOffCenterRHToRef(this.orthoLeft || -halfWidth,
+                        this.orthoRight || halfWidth,
+                        this.orthoBottom || -halfHeight,
+                        this.orthoTop || halfHeight,
+                        this.minZ,
+                        this.maxZ,
+                        this._projectionMatrix);
+                } else {
+                    Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth,
+                        this.orthoRight || halfWidth,
+                        this.orthoBottom || -halfHeight,
+                        this.orthoTop || halfHeight,
+                        this.minZ,
+                        this.maxZ,
+                        this._projectionMatrix);
+                }
             }
+
+            this.onProjectionMatrixChangedObservable.notifyObservers(this);
+
             return this._projectionMatrix;
         }
 
@@ -548,6 +545,10 @@
         } 
 
         public dispose(): void {
+            // Observables
+            this.onViewMatrixChangedObservable.clear();
+            this.onProjectionMatrixChangedObservable.clear();
+
             // Animations
             this.getScene().stopAnimation(this);