webXRGenericHandController.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { WebXRAbstractMotionController } from "./webXRAbstractMotionController.js";
  2. import { WebXRMotionControllerManager } from "./webXRMotionControllerManager.js";
  3. /**
  4. * A generic hand controller class that supports select and a secondary grasp
  5. */
  6. export class WebXRGenericHandController extends WebXRAbstractMotionController {
  7. /**
  8. * Create a new hand controller object, without loading a controller model
  9. * @param scene the scene to use to create this controller
  10. * @param gamepadObject the corresponding gamepad object
  11. * @param handedness the handedness of the controller
  12. */
  13. constructor(scene, gamepadObject, handedness) {
  14. // Don't load the controller model - for now, hands have no real model.
  15. super(scene, GenericHandSelectGraspProfile[handedness], gamepadObject, handedness, true);
  16. this.profileId = "generic-hand-select-grasp";
  17. }
  18. _getFilenameAndPath() {
  19. return {
  20. filename: "generic.babylon",
  21. path: "https://controllers.babylonjs.com/generic/",
  22. };
  23. }
  24. _getModelLoadingConstraints() {
  25. return true;
  26. }
  27. _processLoadedModel(_meshes) {
  28. // no-op
  29. }
  30. _setRootMesh(meshes) {
  31. // no-op
  32. }
  33. _updateModel() {
  34. // no-op
  35. }
  36. }
  37. // register the profiles
  38. WebXRMotionControllerManager.RegisterController("generic-hand-select-grasp", (xrInput, scene) => {
  39. return new WebXRGenericHandController(scene, xrInput.gamepad, xrInput.handedness);
  40. });
  41. // https://github.com/immersive-web/webxr-input-profiles/blob/main/packages/registry/profiles/generic/generic-hand-select-grasp.json
  42. const GenericHandSelectGraspProfile = {
  43. left: {
  44. selectComponentId: "xr-standard-trigger",
  45. components: {
  46. // eslint-disable-next-line @typescript-eslint/naming-convention
  47. "xr-standard-trigger": {
  48. type: "trigger",
  49. gamepadIndices: {
  50. button: 0,
  51. },
  52. rootNodeName: "xr-standard-trigger",
  53. visualResponses: {},
  54. },
  55. grasp: {
  56. type: "trigger",
  57. gamepadIndices: {
  58. button: 4,
  59. },
  60. rootNodeName: "grasp",
  61. visualResponses: {},
  62. },
  63. },
  64. gamepadMapping: "xr-standard",
  65. rootNodeName: "generic-hand-select-grasp-left",
  66. assetPath: "left.glb",
  67. },
  68. right: {
  69. selectComponentId: "xr-standard-trigger",
  70. components: {
  71. // eslint-disable-next-line @typescript-eslint/naming-convention
  72. "xr-standard-trigger": {
  73. type: "trigger",
  74. gamepadIndices: {
  75. button: 0,
  76. },
  77. rootNodeName: "xr-standard-trigger",
  78. visualResponses: {},
  79. },
  80. grasp: {
  81. type: "trigger",
  82. gamepadIndices: {
  83. button: 4,
  84. },
  85. rootNodeName: "grasp",
  86. visualResponses: {},
  87. },
  88. },
  89. gamepadMapping: "xr-standard",
  90. rootNodeName: "generic-hand-select-grasp-right",
  91. assetPath: "right.glb",
  92. },
  93. none: {
  94. selectComponentId: "xr-standard-trigger",
  95. components: {
  96. // eslint-disable-next-line @typescript-eslint/naming-convention
  97. "xr-standard-trigger": {
  98. type: "trigger",
  99. gamepadIndices: {
  100. button: 0,
  101. },
  102. rootNodeName: "xr-standard-trigger",
  103. visualResponses: {},
  104. },
  105. grasp: {
  106. type: "trigger",
  107. gamepadIndices: {
  108. button: 4,
  109. },
  110. rootNodeName: "grasp",
  111. visualResponses: {},
  112. },
  113. },
  114. gamepadMapping: "xr-standard",
  115. rootNodeName: "generic-hand-select-grasp-none",
  116. assetPath: "none.glb",
  117. },
  118. };
  119. //# sourceMappingURL=webXRGenericHandController.js.map