Raanan Weber 5 éve
szülő
commit
e6be02f486

+ 1 - 1
src/Cameras/XR/webXRControllerModelLoader.ts

@@ -61,7 +61,7 @@ export class WebXRControllerModelLoader {
             controllerModel.hand = c.inputSource.handedness;
             controllerModel.isXR = true;
             controllerModel.initControllerMesh(c.getScene(), (m) => {
-                controllerModel.mesh!.parent = c.grip || input.baseExperience.container;
+                controllerModel.mesh!.parent = c.grip || null;
                 controllerModel.mesh!.rotationQuaternion = rotation;
                 controllerModel.mesh!.position = position;
                 m.isPickable = false;

+ 12 - 12
src/Cameras/XR/webXRControllerTeleportation.ts

@@ -111,22 +111,23 @@ export class WebXRControllerTeleportation {
                 }
 
                 if (c.inputSource.gamepad) {
-                    if (c.inputSource.gamepad.axes[3] !== undefined) {
+                    const yIndex = c.inputSource.gamepad.axes.length - 1;
+                    const xIndex = c.inputSource.gamepad.axes.length - 2;
+                    if (c.inputSource.gamepad.axes[yIndex] !== undefined) {
                         // Forward teleportation
-                        if (c.inputSource.gamepad.axes[3] < -0.7) {
+                        if (c.inputSource.gamepad.axes[yIndex] < -0.7) {
                             forwardReadyToTeleport = true;
                         } else {
                             if (forwardReadyToTeleport) {
                                 // Teleport the users feet to where they targeted
                                 this._tmpVector.copyFrom(teleportationTarget.position);
-                                this._tmpVector.y += input.baseExperience.camera.position.y;
-                                input.baseExperience.setPositionOfCameraUsingContainer(this._tmpVector);
+                                input.baseExperience.camera.position.addInPlace(this._tmpVector);
                             }
                             forwardReadyToTeleport = false;
                         }
 
                         // Backward teleportation
-                        if (c.inputSource.gamepad.axes[3] > 0.7) {
+                        if (c.inputSource.gamepad.axes[yIndex] > 0.7) {
                             backwardReadyToTeleport = true;
                         } else {
                             if (backwardReadyToTeleport) {
@@ -148,28 +149,27 @@ export class WebXRControllerTeleportation {
                                 if (pick && pick.pickedPoint) {
                                     // Teleport the users feet to where they targeted
                                     this._tmpVector.copyFrom(pick.pickedPoint);
-                                    this._tmpVector.y += input.baseExperience.camera.position.y;
-                                    input.baseExperience.setPositionOfCameraUsingContainer(this._tmpVector);
+                                    input.baseExperience.camera.position.addInPlace(this._tmpVector);
                                 }
                             }
                             backwardReadyToTeleport = false;
                         }
                     }
 
-                    if (c.inputSource.gamepad.axes[2] !== undefined) {
-                        if (c.inputSource.gamepad.axes[2] < -0.7) {
+                    if (c.inputSource.gamepad.axes[xIndex] !== undefined) {
+                        if (c.inputSource.gamepad.axes[xIndex] < -0.7) {
                             leftReadyToTeleport = true;
                         } else {
                             if (leftReadyToTeleport) {
-                                input.baseExperience.rotateCameraByQuaternionUsingContainer(Quaternion.FromEulerAngles(0, -Math.PI / 4, 0));
+                                input.baseExperience.camera.rotationQuaternion.multiplyInPlace(Quaternion.FromEulerAngles(0, -Math.PI / 4, 0));
                             }
                             leftReadyToTeleport = false;
                         }
-                        if (c.inputSource.gamepad.axes[2] > 0.7) {
+                        if (c.inputSource.gamepad.axes[xIndex] > 0.7) {
                             rightReadyToTeleport = true;
                         } else {
                             if (rightReadyToTeleport) {
-                                input.baseExperience.rotateCameraByQuaternionUsingContainer(Quaternion.FromEulerAngles(0, Math.PI / 4, 0));
+                                input.baseExperience.camera.rotationQuaternion.multiplyInPlace(Quaternion.FromEulerAngles(0, Math.PI / 4, 0));
                             }
                             rightReadyToTeleport = false;
                         }

+ 1 - 34
src/Cameras/XR/webXRExperienceHelper.ts

@@ -1,8 +1,7 @@
 import { Nullable } from "../../types";
 import { Observable } from "../../Misc/observable";
 import { IDisposable, Scene } from "../../scene";
-import { Quaternion, Vector3 } from "../../Maths/math.vector";
-import { AbstractMesh } from "../../Meshes/abstractMesh";
+import { Quaternion } from "../../Maths/math.vector";
 import { Camera } from "../../Cameras/camera";
 import { WebXRSessionManager } from "./webXRSessionManager";
 import { WebXRCamera } from "./webXRCamera";
@@ -15,10 +14,6 @@ import { WebXRFeaturesManager } from './webXRFeaturesManager';
  */
 export class WebXRExperienceHelper implements IDisposable {
     /**
-     * Container which stores the xr camera and controllers as children. This can be used to move the camera/user as the camera's position is updated by the xr device
-     */
-    public container: AbstractMesh;
-    /**
      * Camera used to render xr content
      */
     public camera: WebXRCamera;
@@ -33,8 +28,6 @@ export class WebXRExperienceHelper implements IDisposable {
         this.onStateChangedObservable.notifyObservers(this.state);
     }
 
-    private static _TmpVector = new Vector3();
-
     /**
      * Fires when the state of the experience helper has changed
      */
@@ -83,8 +76,6 @@ export class WebXRExperienceHelper implements IDisposable {
         this.sessionManager = new WebXRSessionManager(scene);
         this.camera = new WebXRCamera("", scene, this.sessionManager);
         this.featuresManager = new WebXRFeaturesManager(this.sessionManager);
-        this.container = new AbstractMesh("WebXR Container", scene);
-        this.camera.parent = this.container;
 
         scene.onDisposeObservable.add(() => {
             this.exitXRAsync();
@@ -165,34 +156,10 @@ export class WebXRExperienceHelper implements IDisposable {
     }
 
     /**
-     * Updates the global position of the camera by moving the camera's container
-     * This should be used instead of modifying the camera's position as it will be overwritten by an xrSessions's update frame
-     * @param position The desired global position of the camera
-     */
-    public setPositionOfCameraUsingContainer(position: Vector3) {
-        this.camera.globalPosition.subtractToRef(position, WebXRExperienceHelper._TmpVector);
-        this.container.position.subtractInPlace(WebXRExperienceHelper._TmpVector);
-    }
-
-    /**
-     * Rotates the xr camera by rotating the camera's container around the camera's position
-     * This should be used instead of modifying the camera's rotation as it will be overwritten by an xrSessions's update frame
-     * @param rotation the desired quaternion rotation to apply to the camera
-     */
-    public rotateCameraByQuaternionUsingContainer(rotation: Quaternion) {
-        if (!this.container.rotationQuaternion) {
-            this.container.rotationQuaternion = Quaternion.FromEulerVector(this.container.rotation);
-        }
-        this.container.rotationQuaternion.multiplyInPlace(rotation);
-        this.container.position.rotateByQuaternionAroundPointToRef(rotation, this.camera.globalPosition, this.container.position);
-    }
-
-    /**
      * Disposes of the experience helper
      */
     public dispose() {
         this.camera.dispose();
-        this.container.dispose();
         this.onStateChangedObservable.clear();
         this.sessionManager.dispose();
     }

+ 1 - 1
src/Cameras/XR/webXRInput.ts

@@ -69,7 +69,7 @@ export class WebXRInput implements IDisposable {
         let sources = this.controllers.map((c) => {return c.inputSource; });
         for (let input of addInputs) {
             if (sources.indexOf(input) === -1) {
-                let controller = new WebXRController(this.baseExperience.camera._scene, input, this.baseExperience.container);
+                let controller = new WebXRController(this.baseExperience.camera._scene, input);
                 this.controllers.push(controller);
                 this.onControllerAddedObservable.notifyObservers(controller);
             }