浏览代码

teleportation with no motion controllers

Raanan Weber 5 年之前
父节点
当前提交
84f2c9780b
共有 1 个文件被更改,包括 17 次插入15 次删除
  1. 17 15
      src/XR/features/WebXRControllerTeleportation.ts

+ 17 - 15
src/XR/features/WebXRControllerTeleportation.ts

@@ -406,7 +406,9 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
             }
         };
         const controllerData = this._controllers[xrController.uniqueId];
-        if (controllerData.xrController.inputSource.targetRayMode === 'tracked-pointer') {
+        // motion controller only available to gamepad-enabled input sources.
+        if (controllerData.xrController.inputSource.targetRayMode === 'tracked-pointer'
+            && controllerData.xrController.inputSource.gamepad) {
             // motion controller support
             xrController.onMotionControllerInitObservable.addOnce(() => {
                 if (xrController.motionController) {
@@ -520,21 +522,21 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
             this._xrSessionManager.scene.onPointerObservable.add((pointerInfo) => {
                 if (pointerInfo.type === PointerEventTypes.POINTERDOWN) {
                     controllerData.teleportationState.forward = true;
-                        this._currentTeleportationControllerId = controllerData.xrController.uniqueId;
-                        controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;
-                        controllerData.teleportationState.currentRotation = 0;
-                        const timeToSelect = this._options.timeToTeleport || 3000;
-                        let timer = 0;
-                        const observer = this._xrSessionManager.onXRFrameObservable.add(() => {
-                            timer += this._xrSessionManager.scene.getEngine().getDeltaTime();
-                            if (timer >= timeToSelect && this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {
-                                this._teleportForward(xrController.uniqueId);
-                            }
+                    this._currentTeleportationControllerId = controllerData.xrController.uniqueId;
+                    controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;
+                    controllerData.teleportationState.currentRotation = 0;
+                    const timeToSelect = this._options.timeToTeleport || 3000;
+                    let timer = 0;
+                    const observer = this._xrSessionManager.onXRFrameObservable.add(() => {
+                        timer += this._xrSessionManager.scene.getEngine().getDeltaTime();
+                        if (timer >= timeToSelect && this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {
+                            this._teleportForward(xrController.uniqueId);
+                        }
 
-                            if (timer >= timeToSelect) {
-                                this._xrSessionManager.onXRFrameObservable.remove(observer);
-                            }
-                        });
+                        if (timer >= timeToSelect) {
+                            this._xrSessionManager.onXRFrameObservable.remove(observer);
+                        }
+                    });
                 } else if (pointerInfo.type === PointerEventTypes.POINTERUP) {
                     controllerData.teleportationState.forward = false;
                     this._currentTeleportationControllerId = "";