Bladeren bron

Merge pull request #6230 from TrevorDev/rigCamerasCameraUpdate

Option for isInFrustum to check rigCameras, viewMatrix updates for ri…
David Catuhe 6 jaren geleden
bovenliggende
commit
9c205c7485
2 gewijzigde bestanden met toevoegingen van 18 en 2 verwijderingen
  1. 1 0
      dist/preview release/what's new.md
  2. 17 2
      src/Cameras/camera.ts

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

@@ -264,6 +264,7 @@
 - Fix a bug causing `WebRequest.open` to crash if `WebRequest.CustomRequestHeaders` are set [#6055](https://github.com/BabylonJS/Babylon.js/issues/6055)([susares](https://github.com/susares))
 - Fix a bug causing `Mesh.clone` to crash if no physicsEngineComponent is used  ([barroij](https://github.com/barroij))
 - Fix zoom inertia making it difficult to zoom out with ArcRotateCamera ([TrevorDev](https://github.com/TrevorDev))
+- Option for isInFrustum to check rigCameras, viewMatrix updates for rigCameras will notify their parent ([TrevorDev](https://github.com/TrevorDev))
 
 ### Viewer
 

+ 17 - 2
src/Cameras/camera.ts

@@ -651,6 +651,11 @@ export class Camera extends Node {
             this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._computedViewMatrix);
         }
 
+        // Notify parent camera if rig camera is changed
+        if (this.parent && (this.parent as Camera).onViewMatrixChangedObservable) {
+            (this.parent as Camera).onViewMatrixChangedObservable.notifyObservers((this.parent as Camera));
+        }
+
         this.onViewMatrixChangedObservable.notifyObservers(this);
 
         this._computedViewMatrix.invertToRef(this._worldMatrix);
@@ -785,12 +790,22 @@ export class Camera extends Node {
      * Checks if a cullable object (mesh...) is in the camera frustum
      * This checks the bounding box center. See isCompletelyInFrustum for a full bounding check
      * @param target The object to check
+     * @param checkRigCameras If the rig cameras should be checked (eg. with webVR camera both eyes should be checked) (Default: false)
      * @returns true if the object is in frustum otherwise false
      */
-    public isInFrustum(target: ICullable): boolean {
+    public isInFrustum(target: ICullable, checkRigCameras = false): boolean {
         this._updateFrustumPlanes();
 
-        return target.isInFrustum(this._frustumPlanes);
+        if (checkRigCameras && this.rigCameras.length > 0) {
+            var result = false;
+            this.rigCameras.forEach((cam) => {
+                cam._updateFrustumPlanes();
+                result = result || target.isInFrustum(cam._frustumPlanes);
+            });
+            return result;
+        }else {
+            return target.isInFrustum(this._frustumPlanes);
+        }
     }
 
     /**