Преглед изворни кода

Merge pull request #3266 from TrevorDev/addDefaultHeightToWebVROptions

add default height webvr option, fix teleporting position
sebavan пре 7 година
родитељ
комит
27fc30f8e1
2 измењених фајлова са 12 додато и 4 уклоњено
  1. 7 4
      src/Cameras/VR/babylon.vrExperienceHelper.ts
  2. 5 0
      src/Cameras/VR/babylon.webVRCamera.ts

+ 7 - 4
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -79,6 +79,7 @@ module BABYLON {
         private _currentHit: Nullable<PickingInfo>;
         private _pointerDownOnMeshAsked = false;
         private _isActionableMesh = false;
+        private _defaultHeight:number;
 
         public get deviceOrientationCamera(): DeviceOrientationCamera {
             return this._deviceOrientationCamera;
@@ -105,13 +106,15 @@ module BABYLON {
         constructor(scene: Scene, public webVROptions: WebVROptions = {}) {
             this._scene = scene;
 
+            this._defaultHeight = webVROptions.defaultHeight || 1.7;
+
             if (!this._scene.activeCamera || isNaN(this._scene.activeCamera.position.x)) {
-                this._position = new BABYLON.Vector3(0, 2, 0);
-                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", new BABYLON.Vector3(0, 1.7, 0), scene);
+                this._position = new BABYLON.Vector3(0, this._defaultHeight, 0);
+                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
             }
             else {
                 this._position = this._scene.activeCamera.position.clone();
-                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position, scene);
+                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
                 this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;
                 this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;
                 // Set rotation from previous camera
@@ -824,7 +827,7 @@ module BABYLON {
             // offset of the headset from the anchor. Then add the helper's position to account for user's height offset
             this.webVRCamera.leftCamera!.globalPosition.subtractToRef(this.webVRCamera.position, this._workingVector);
             this._haloCenter.subtractToRef(this._workingVector, this._workingVector);
-            this._workingVector.addInPlace(this.position);
+            this._workingVector.y += this._defaultHeight;
             
             // Create animation from the camera's position to the new location
             this.currentVRCamera.animations = [];

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

@@ -38,6 +38,7 @@ module BABYLON {
         useCustomVRButton?: boolean; // if you don't want to use the default VR button of the helper
         customVRButton?: HTMLButtonElement; //if you'd like to provide your own button to the VRHelper
         rayLength?: number; // to change the length of the ray for gaze/controllers.
+        defaultHeight?: number; // to change the default offset from the ground to account for user's height
     }
 
     export class WebVRFreeCamera extends FreeCamera implements PoseControlled {
@@ -66,6 +67,10 @@ module BABYLON {
         constructor(name: string, position: Vector3, scene: Scene, private webVROptions: WebVROptions = {}) {
             super(name, position, scene);
 
+            if(webVROptions.defaultHeight){
+                this.position.y = webVROptions.defaultHeight;
+            }
+            
             this.minZ = 0.1;
 
             //legacy support - the compensation boolean was removed.