webXRGenericMotionController.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { WebXRAbstractMotionController } from "./webXRAbstractMotionController.js";
  2. import { Mesh } from "../../Meshes/mesh.js";
  3. import { Quaternion } from "../../Maths/math.vector.js";
  4. /**
  5. * A generic trigger-only motion controller for WebXR
  6. */
  7. export class WebXRGenericTriggerMotionController extends WebXRAbstractMotionController {
  8. constructor(scene, gamepadObject, handedness) {
  9. super(scene, GenericTriggerLayout[handedness], gamepadObject, handedness);
  10. this.profileId = WebXRGenericTriggerMotionController.ProfileId;
  11. }
  12. _getFilenameAndPath() {
  13. return {
  14. filename: "generic.babylon",
  15. path: "https://controllers.babylonjs.com/generic/",
  16. };
  17. }
  18. _getModelLoadingConstraints() {
  19. return true;
  20. }
  21. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  22. _processLoadedModel(meshes) {
  23. // nothing to do
  24. }
  25. _setRootMesh(meshes) {
  26. this.rootMesh = new Mesh(this.profileId + " " + this.handedness, this.scene);
  27. meshes.forEach((mesh) => {
  28. mesh.isPickable = false;
  29. if (!mesh.parent) {
  30. mesh.setParent(this.rootMesh);
  31. }
  32. });
  33. this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);
  34. }
  35. _updateModel() {
  36. // no-op
  37. }
  38. }
  39. /**
  40. * Static version of the profile id of this controller
  41. */
  42. WebXRGenericTriggerMotionController.ProfileId = "generic-trigger";
  43. // https://github.com/immersive-web/webxr-input-profiles/blob/master/packages/registry/profiles/generic/generic-trigger-touchpad-thumbstick.json
  44. const GenericTriggerLayout = {
  45. left: {
  46. selectComponentId: "xr-standard-trigger",
  47. components: {
  48. // eslint-disable-next-line @typescript-eslint/naming-convention
  49. "xr-standard-trigger": {
  50. type: "trigger",
  51. gamepadIndices: {
  52. button: 0,
  53. },
  54. rootNodeName: "xr_standard_trigger",
  55. visualResponses: {},
  56. },
  57. },
  58. gamepadMapping: "xr-standard",
  59. rootNodeName: "generic-trigger-left",
  60. assetPath: "left.glb",
  61. },
  62. right: {
  63. selectComponentId: "xr-standard-trigger",
  64. components: {
  65. // eslint-disable-next-line @typescript-eslint/naming-convention
  66. "xr-standard-trigger": {
  67. type: "trigger",
  68. gamepadIndices: {
  69. button: 0,
  70. },
  71. rootNodeName: "xr_standard_trigger",
  72. visualResponses: {},
  73. },
  74. },
  75. gamepadMapping: "xr-standard",
  76. rootNodeName: "generic-trigger-right",
  77. assetPath: "right.glb",
  78. },
  79. none: {
  80. selectComponentId: "xr-standard-trigger",
  81. components: {
  82. // eslint-disable-next-line @typescript-eslint/naming-convention
  83. "xr-standard-trigger": {
  84. type: "trigger",
  85. gamepadIndices: {
  86. button: 0,
  87. },
  88. rootNodeName: "xr_standard_trigger",
  89. visualResponses: {},
  90. },
  91. },
  92. gamepadMapping: "xr-standard",
  93. rootNodeName: "generic-trigger-none",
  94. assetPath: "none.glb",
  95. },
  96. };
  97. //# sourceMappingURL=webXRGenericMotionController.js.map