Prechádzať zdrojové kódy

Merge pull request #4698 from TrevorDev/webVRCameraPoseUpdatedEvent

webVR camera poseUpdated event
David Catuhe 7 rokov pred
rodič
commit
70e344f9fd

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

@@ -67,6 +67,7 @@
 - Added effect layer per rendering group addressing [Issue 4463](https://github.com/BabylonJS/Babylon.js/issues/4463) ([sebavan](http://www.github.com/sebavan))
 - Added predicate function `targetMask` argument to `scene.beginWeightedAnimation`, `scene.beginAnimation`, `scene.stopAnimation`, and `animatable.stop` to allow for selective application of animations.  ([fmmoret](http://github.com/fmmoret))
 - Oculus GO and GearVR 3dof controllers will now rotate with the user if they turn around in their room ([TrevorDev](https://github.com/TrevorDev))
+- Added onPoseUpdatedFromDeviceObservable to webVRCamera to detect when the camera's pose has been updated ([TrevorDev](https://github.com/TrevorDev))
 
 ### glTF Loader
 

+ 9 - 0
src/Cameras/VR/babylon.webVRCamera.ts

@@ -183,6 +183,11 @@ module BABYLON {
          */
         public onControllerMeshLoadedObservable = new Observable<WebVRController>();
         /**
+         * Emits an event when the HMD's pose has been updated.
+         */
+        public onPoseUpdatedFromDeviceObservable = new Observable<any>();
+        private _poseSet = false;
+        /**
          * If the rig cameras be used as parent instead of this camera.
          */
         public rigParenting: boolean = true;
@@ -431,6 +436,7 @@ module BABYLON {
                         this._deviceRoomPosition.z *= -1;
                     }
                 }
+                this._poseSet = true;
             }
         }
 
@@ -559,6 +565,9 @@ module BABYLON {
             this._workingMatrix.multiplyToRef(this._deviceToWorld, this._workingMatrix)
             Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);
 
+            if(this._poseSet){
+                this.onPoseUpdatedFromDeviceObservable.notifyObservers(null);
+            }
             super.update();
         }