浏览代码

Merge pull request #7999 from RaananW/smallTeleportFix

[XR] make teleportation and physics work automatically for non-gamepad-enabled controllers
David Catuhe 5 年之前
父节点
当前提交
2a6ef24ee7

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

@@ -82,7 +82,7 @@
 - AR reference space type recommendation changed to 'unbounded' ([#7959](https://github.com/BabylonJS/Babylon.js/issues/7959)) ([RaananW](https://github.com/RaananW))
 - Teleportation plugin doesn't use the touched to finish teleportation ([#7916](https://github.com/BabylonJS/Babylon.js/issues/7916)) ([RaananW](https://github.com/RaananW))
 - Support for pointer selection and teleportation in right handed systems ([#7967](https://github.com/BabylonJS/Babylon.js/issues/7967)) ([RaananW](https://github.com/RaananW))
-- Pointer Selection feature now uses `selectstart` and `selectend` events when gamepad is not present ([#7989](https://github.com/BabylonJS/Babylon.js/issues/7989)) ([RaananW](https://github.com/RaananW))
+- Pointer Selection feature now uses `selectstart` and `selectend` events when gamepad and motion controller are not present ([#7989](https://github.com/BabylonJS/Babylon.js/issues/7989)) ([RaananW](https://github.com/RaananW))
 
 ### Collisions
 

+ 2 - 1
src/XR/features/WebXRControllerPhysics.ts

@@ -85,7 +85,8 @@ export class WebXRControllerPhysics extends WebXRAbstractFeature {
         if (!this._xrSessionManager.scene.isPhysicsEnabled()) {
             Logger.Warn("physics engine not enabled, skipped. Please add this controller manually.");
         }
-        if (this._options.physicsProperties!.useControllerMesh) {
+        // if no motion controller available, create impostors!
+        if (this._options.physicsProperties!.useControllerMesh && xrController.inputSource.gamepad) {
             xrController.onMotionControllerInitObservable.addOnce((motionController) => {
                 motionController.onModelLoadedObservable.addOnce(() => {
                     const impostor = new PhysicsImpostor(motionController.rootMesh!, PhysicsImpostor.MeshImpostor, {

+ 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 = "";