webXRInputSource.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { Observable } from "../Misc/observable";
  2. import { AbstractMesh } from "../Meshes/abstractMesh";
  3. import type { Ray } from "../Culling/ray";
  4. import type { Scene } from "../scene";
  5. import type { WebXRAbstractMotionController } from "./motionController/webXRAbstractMotionController";
  6. import type { WebXRCamera } from "./webXRCamera";
  7. import type { WebXRSessionManager } from "./webXRSessionManager";
  8. /**
  9. * Configuration options for the WebXR controller creation
  10. */
  11. export interface IWebXRControllerOptions {
  12. /**
  13. * Should the controller mesh be animated when a user interacts with it
  14. * The pressed buttons / thumbstick and touchpad animations will be disabled
  15. */
  16. disableMotionControllerAnimation?: boolean;
  17. /**
  18. * Do not load the controller mesh, in case a different mesh needs to be loaded.
  19. */
  20. doNotLoadControllerMesh?: boolean;
  21. /**
  22. * Force a specific controller type for this controller.
  23. * This can be used when creating your own profile or when testing different controllers
  24. */
  25. forceControllerProfile?: string;
  26. /**
  27. * Defines a rendering group ID for meshes that will be loaded.
  28. * This is for the default controllers only.
  29. */
  30. renderingGroupId?: number;
  31. }
  32. /**
  33. * Represents an XR controller
  34. */
  35. export declare class WebXRInputSource {
  36. private _scene;
  37. /** The underlying input source for the controller */
  38. inputSource: XRInputSource;
  39. private _options;
  40. private _tmpVector;
  41. private _uniqueId;
  42. private _disposed;
  43. /**
  44. * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if that's the case only the pointer from the head will be available
  45. */
  46. grip?: AbstractMesh;
  47. /**
  48. * If available, this is the gamepad object related to this controller.
  49. * Using this object it is possible to get click events and trackpad changes of the
  50. * webxr controller that is currently being used.
  51. */
  52. motionController?: WebXRAbstractMotionController;
  53. /**
  54. * Event that fires when the controller is removed/disposed.
  55. * The object provided as event data is this controller, after associated assets were disposed.
  56. * uniqueId is still available.
  57. */
  58. onDisposeObservable: Observable<WebXRInputSource>;
  59. /**
  60. * Will be triggered when the mesh associated with the motion controller is done loading.
  61. * It is also possible that this will never trigger (!) if no mesh was loaded, or if the developer decides to load a different mesh
  62. * A shortened version of controller -> motion controller -> on mesh loaded.
  63. */
  64. onMeshLoadedObservable: Observable<AbstractMesh>;
  65. /**
  66. * Observers registered here will trigger when a motion controller profile was assigned to this xr controller
  67. */
  68. onMotionControllerInitObservable: Observable<WebXRAbstractMotionController>;
  69. /**
  70. * Pointer which can be used to select objects or attach a visible laser to
  71. */
  72. pointer: AbstractMesh;
  73. /**
  74. * The last XRPose the was calculated on the current XRFrame
  75. * @internal
  76. */
  77. _lastXRPose?: XRPose;
  78. /**
  79. * Creates the input source object
  80. * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRInputControllerSupport
  81. * @param _scene the scene which the controller should be associated to
  82. * @param inputSource the underlying input source for the controller
  83. * @param _options options for this controller creation
  84. */
  85. constructor(_scene: Scene,
  86. /** The underlying input source for the controller */
  87. inputSource: XRInputSource, _options?: IWebXRControllerOptions);
  88. /**
  89. * Get this controllers unique id
  90. */
  91. get uniqueId(): string;
  92. /**
  93. * Disposes of the object
  94. */
  95. dispose(): void;
  96. /**
  97. * Gets a world space ray coming from the pointer or grip
  98. * @param result the resulting ray
  99. * @param gripIfAvailable use the grip mesh instead of the pointer, if available
  100. */
  101. getWorldPointerRayToRef(result: Ray, gripIfAvailable?: boolean): void;
  102. /**
  103. * Updates the controller pose based on the given XRFrame
  104. * @param xrFrame xr frame to update the pose with
  105. * @param referenceSpace reference space to use
  106. * @param xrCamera the xr camera, used for parenting
  107. * @param xrSessionManager the session manager used to get the world reference system
  108. */
  109. updateFromXRFrame(xrFrame: XRFrame, referenceSpace: XRReferenceSpace, xrCamera: WebXRCamera, xrSessionManager: WebXRSessionManager): void;
  110. }