WebXRControllerPointerSelection.d.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import type { WebXRSessionManager } from "../webXRSessionManager";
  2. import type { AbstractMesh } from "../../Meshes/abstractMesh";
  3. import type { WebXRInput } from "../webXRInput";
  4. import type { WebXRInputSource } from "../webXRInputSource";
  5. import type { Scene } from "../../scene";
  6. import type { Nullable } from "../../types";
  7. import { Color3 } from "../../Maths/math.color";
  8. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  9. import type { WebXRCamera } from "../webXRCamera";
  10. import type { Mesh } from "../../Meshes/mesh";
  11. /**
  12. * Options interface for the pointer selection module
  13. */
  14. export interface IWebXRControllerPointerSelectionOptions {
  15. /**
  16. * if provided, this scene will be used to render meshes.
  17. */
  18. customUtilityLayerScene?: Scene;
  19. /**
  20. * Disable the pointer up event when the xr controller in screen and gaze mode is disposed (meaning - when the user removed the finger from the screen)
  21. * If not disabled, the last picked point will be used to execute a pointer up event
  22. * If disabled, pointer up event will be triggered right after the pointer down event.
  23. * Used in screen and gaze target ray mode only
  24. */
  25. disablePointerUpOnTouchOut: boolean;
  26. /**
  27. * For gaze mode for tracked-pointer / controllers (time to select instead of button press)
  28. */
  29. forceGazeMode: boolean;
  30. /**
  31. * Factor to be applied to the pointer-moved function in the gaze mode. How sensitive should the gaze mode be when checking if the pointer moved
  32. * to start a new countdown to the pointer down event.
  33. * Defaults to 1.
  34. */
  35. gazeModePointerMovedFactor?: number;
  36. /**
  37. * Different button type to use instead of the main component
  38. */
  39. overrideButtonId?: string;
  40. /**
  41. * use this rendering group id for the meshes (optional)
  42. */
  43. renderingGroupId?: number;
  44. /**
  45. * The amount of time in milliseconds it takes between pick found something to a pointer down event.
  46. * Used in gaze modes. Tracked pointer uses the trigger, screen uses touch events
  47. * 3000 means 3 seconds between pointing at something and selecting it
  48. */
  49. timeToSelect?: number;
  50. /**
  51. * Should meshes created here be added to a utility layer or the main scene
  52. */
  53. useUtilityLayer?: boolean;
  54. /**
  55. * Optional WebXR camera to be used for gaze selection
  56. */
  57. gazeCamera?: WebXRCamera;
  58. /**
  59. * the xr input to use with this pointer selection
  60. */
  61. xrInput: WebXRInput;
  62. /**
  63. * Should the scene pointerX and pointerY update be disabled
  64. * This is required for fullscreen AR GUI, but might slow down other experiences.
  65. * Disable in VR, if not needed.
  66. * The first rig camera (left eye) will be used to calculate the projection
  67. */
  68. disableScenePointerVectorUpdate: boolean;
  69. /**
  70. * Enable pointer selection on all controllers instead of switching between them
  71. */
  72. enablePointerSelectionOnAllControllers?: boolean;
  73. /**
  74. * The preferred hand to give the pointer selection to. This will be prioritized when the controller initialize.
  75. * If switch is enabled, it will still allow the user to switch between the different controllers
  76. */
  77. preferredHandedness?: XRHandedness;
  78. /**
  79. * Disable switching the pointer selection from one controller to the other.
  80. * If the preferred hand is set it will be fixed on this hand, and if not it will be fixed on the first controller added to the scene
  81. */
  82. disableSwitchOnClick?: boolean;
  83. /**
  84. * The maximum distance of the pointer selection feature. Defaults to 100.
  85. */
  86. maxPointerDistance?: number;
  87. /**
  88. * A function that will be called when a new selection mesh is generated.
  89. * This function should return a mesh that will be used as the selection mesh.
  90. * The default is a torus with a 0.01 diameter and 0.0075 thickness .
  91. */
  92. customSelectionMeshGenerator?: () => Mesh;
  93. /**
  94. * A function that will be called when a new laser pointer mesh is generated.
  95. * This function should return a mesh that will be used as the laser pointer mesh.
  96. * The height (y) of the mesh must be 1.
  97. */
  98. customLasterPointerMeshGenerator?: () => AbstractMesh;
  99. /**
  100. * Use the grip space instead of the pointer space for selection, if available.
  101. */
  102. forceGripIfAvailable?: boolean;
  103. /**
  104. * If set to true, the hand rays will be disabled and the user will be able to look and pick objects.
  105. * This requires system support (like in the vision OS) and will not work in all systems.
  106. * @experimental - this is an experimental feature and might change int he future
  107. */
  108. lookAndPickMode?: boolean;
  109. }
  110. /**
  111. * A module that will enable pointer selection for motion controllers of XR Input Sources
  112. */
  113. export declare class WebXRControllerPointerSelection extends WebXRAbstractFeature {
  114. private readonly _options;
  115. private static _IdCounter;
  116. private _attachController;
  117. private _controllers;
  118. private _scene;
  119. private _tmpVectorForPickCompare;
  120. private _attachedController;
  121. /**
  122. * The module's name
  123. */
  124. static readonly Name = "xr-controller-pointer-selection";
  125. /**
  126. * The (Babylon) version of this module.
  127. * This is an integer representing the implementation version.
  128. * This number does not correspond to the WebXR specs version
  129. */
  130. static readonly Version = 1;
  131. /**
  132. * Disable lighting on the laser pointer (so it will always be visible)
  133. */
  134. disablePointerLighting: boolean;
  135. /**
  136. * Disable lighting on the selection mesh (so it will always be visible)
  137. */
  138. disableSelectionMeshLighting: boolean;
  139. /**
  140. * Should the laser pointer be displayed
  141. */
  142. displayLaserPointer: boolean;
  143. /**
  144. * Should the selection mesh be displayed (The ring at the end of the laser pointer)
  145. */
  146. displaySelectionMesh: boolean;
  147. /**
  148. * This color will be set to the laser pointer when selection is triggered
  149. */
  150. laserPointerPickedColor: Color3;
  151. /**
  152. * Default color of the laser pointer
  153. */
  154. laserPointerDefaultColor: Color3;
  155. /**
  156. * default color of the selection ring
  157. */
  158. selectionMeshDefaultColor: Color3;
  159. /**
  160. * This color will be applied to the selection ring when selection is triggered
  161. */
  162. selectionMeshPickedColor: Color3;
  163. /**
  164. * Optional filter to be used for ray selection. This predicate shares behavior with
  165. * scene.pointerMovePredicate which takes priority if it is also assigned.
  166. */
  167. raySelectionPredicate: (mesh: AbstractMesh) => boolean;
  168. /**
  169. * constructs a new background remover module
  170. * @param _xrSessionManager the session manager for this module
  171. * @param _options read-only options to be used in this module
  172. */
  173. constructor(_xrSessionManager: WebXRSessionManager, _options: IWebXRControllerPointerSelectionOptions);
  174. /**
  175. * attach this feature
  176. * Will usually be called by the features manager
  177. *
  178. * @returns true if successful.
  179. */
  180. attach(): boolean;
  181. /**
  182. * detach this feature.
  183. * Will usually be called by the features manager
  184. *
  185. * @returns true if successful.
  186. */
  187. detach(): boolean;
  188. /**
  189. * Will get the mesh under a specific pointer.
  190. * `scene.meshUnderPointer` will only return one mesh - either left or right.
  191. * @param controllerId the controllerId to check
  192. * @returns The mesh under pointer or null if no mesh is under the pointer
  193. */
  194. getMeshUnderPointer(controllerId: string): Nullable<AbstractMesh>;
  195. /**
  196. * Get the xr controller that correlates to the pointer id in the pointer event
  197. *
  198. * @param id the pointer id to search for
  199. * @returns the controller that correlates to this id or null if not found
  200. */
  201. getXRControllerByPointerId(id: number): Nullable<WebXRInputSource>;
  202. /**
  203. * @internal
  204. */
  205. _getPointerSelectionDisabledByPointerId(id: number): boolean;
  206. /**
  207. * @internal
  208. */
  209. _setPointerSelectionDisabledByPointerId(id: number, state: boolean): void;
  210. private _identityMatrix;
  211. private _screenCoordinatesRef;
  212. private _viewportRef;
  213. protected _onXRFrame(_xrFrame: XRFrame): void;
  214. private get _utilityLayerScene();
  215. private _attachGazeMode;
  216. private _attachScreenRayMode;
  217. private _attachTrackedPointerRayMode;
  218. private _convertNormalToDirectionOfRay;
  219. private _detachController;
  220. private _generateNewMeshPair;
  221. private _pickingMoved;
  222. private _updatePointerDistance;
  223. private _augmentPointerInit;
  224. /** @internal */
  225. get lasterPointerDefaultColor(): Color3;
  226. }