Ver código fonte

support quest controller

Trevor Baron 6 anos atrás
pai
commit
509d6f787f

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 0
Playground/scenes/left.babylon


Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 0
Playground/scenes/right.babylon


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

@@ -20,6 +20,7 @@
 - Move normalizeToUnitCube to transformNode instead of abstract mesh and add predicate to exclude sub objects when scaling ([TrevorDev](https://github.com/TrevorDev))
 - Method to check if device orientation is available ([TrevorDev](https://github.com/TrevorDev))
 - Added support for sound sprites [Doc](https://doc.babylonjs.com/how_to/playing_sounds_and_music#playing-a-sound-sprite) ([Deltakosh](https://github.com/deltakosh/))
+- Display Oculus Quest controller when using a Quest in WebVR ([TrevorDev](https://github.com/TrevorDev))
 
 ### Engine
 - Morph targets now can morph UV channel as well ([Deltakosh](https://github.com/deltakosh/))

+ 21 - 5
src/Gamepads/Controllers/oculusTouchController.ts

@@ -8,6 +8,7 @@ import { _DepthCullingState, _StencilState, _AlphaState } from "../../States/ind
 import { WebVRController } from "./webVRController";
 import { PoseEnabledControllerType, ExtendedGamepadButton, PoseEnabledControllerHelper } from "./poseEnabledController";
 import { GamepadButtonChanges } from "../../Gamepads/gamepad";
+import { Engine } from '../../Engines/engine';
 /**
  * Oculus Touch Controller
  */
@@ -26,6 +27,17 @@ export class OculusTouchController extends WebVRController {
     public static MODEL_RIGHT_FILENAME: string = 'right.babylon';
 
     /**
+     * Base Url for the Quest controller model.
+     */
+    public static QUEST_MODEL_BASE_URL: string = 'https://controllers.babylonjs.com/oculusQuest/';
+
+    /**
+     * @hidden
+     * If the controllers are running on a device that needs the updated Quest controller models
+     */
+    public static _IsQuest = false;
+
+    /**
      * Fired when the secondary trigger on this controller is modified
      */
     public onSecondaryTriggerStateChangedObservable = new Observable<ExtendedGamepadButton>();
@@ -60,7 +72,7 @@ export class OculusTouchController extends WebVRController {
             meshName = OculusTouchController.MODEL_RIGHT_FILENAME;
         }
 
-        SceneLoader.ImportMesh("", OculusTouchController.MODEL_BASE_URL, meshName, scene, (newMeshes) => {
+        SceneLoader.ImportMesh("",  OculusTouchController._IsQuest ? OculusTouchController.QUEST_MODEL_BASE_URL : OculusTouchController.MODEL_BASE_URL, meshName, scene, (newMeshes) => {
             /*
             Parent Mesh name: oculus_touch_left
             - body
@@ -144,7 +156,7 @@ export class OculusTouchController extends WebVRController {
                 this.onPadStateChangedObservable.notifyObservers(notifyObject);
                 return;
             case 1: // index trigger
-                if (this._defaultModel) {
+                if (!OculusTouchController._IsQuest && this._defaultModel) {
                     (<AbstractMesh>(this._defaultModel.getChildren()[3])).rotation.x = -notifyObject.value * 0.20;
                     (<AbstractMesh>(this._defaultModel.getChildren()[3])).position.y = -notifyObject.value * 0.005;
                     (<AbstractMesh>(this._defaultModel.getChildren()[3])).position.z = -notifyObject.value * 0.005;
@@ -152,13 +164,13 @@ export class OculusTouchController extends WebVRController {
                 this.onTriggerStateChangedObservable.notifyObservers(notifyObject);
                 return;
             case 2:  // secondary trigger
-                if (this._defaultModel) {
+                if (!OculusTouchController._IsQuest && this._defaultModel) {
                     (<AbstractMesh>(this._defaultModel.getChildren()[4])).position.x = triggerDirection * notifyObject.value * 0.0035;
                 }
                 this.onSecondaryTriggerStateChangedObservable.notifyObservers(notifyObject);
                 return;
             case 3:
-                if (this._defaultModel) {
+                if (!OculusTouchController._IsQuest && this._defaultModel) {
                     if (notifyObject.pressed) {
                         (<AbstractMesh>(this._defaultModel.getChildren()[1])).position.y = -0.001;
                     }
@@ -169,7 +181,7 @@ export class OculusTouchController extends WebVRController {
                 this.onMainButtonStateChangedObservable.notifyObservers(notifyObject);
                 return;
             case 4:
-                if (this._defaultModel) {
+                if (!OculusTouchController._IsQuest && this._defaultModel) {
                     if (notifyObject.pressed) {
                         (<AbstractMesh>(this._defaultModel.getChildren()[2])).position.y = -0.001;
                     }
@@ -188,6 +200,10 @@ export class OculusTouchController extends WebVRController {
 
 PoseEnabledControllerHelper._ControllerFactories.push({
     canCreate: (gamepadInfo) => {
+        // If the headset reports being an Oculus Quest, use the Quest controller models
+        if (Engine.LastCreatedEngine && Engine.LastCreatedEngine._vrDisplay && Engine.LastCreatedEngine._vrDisplay.displayName === "Oculus Quest") {
+            OculusTouchController._IsQuest = true;
+        }
         return gamepadInfo.id.indexOf('Oculus Touch') !== -1;
     },
     create: (gamepadInfo) => {