WebXRNearInteraction.d.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import type { WebXRControllerPointerSelection } from "./WebXRControllerPointerSelection";
  2. import type { WebXRSessionManager } from "../webXRSessionManager";
  3. import type { AbstractMesh } from "../../Meshes/abstractMesh";
  4. import type { WebXRInput } from "../webXRInput";
  5. import type { WebXRInputSource } from "../webXRInputSource";
  6. import type { Scene } from "../../scene";
  7. import type { Nullable } from "../../types";
  8. import { PickingInfo } from "../../Collisions/pickingInfo";
  9. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  10. import { BoundingSphere } from "../../Culling/boundingSphere";
  11. import { Color3 } from "../../Maths/math.color";
  12. import type { Material } from "../../Materials/material";
  13. import "../../Meshes/subMesh.project";
  14. /**
  15. * Where should the near interaction mesh be attached to when using a motion controller for near interaction
  16. */
  17. export declare enum WebXRNearControllerMode {
  18. /**
  19. * Motion controllers will not support near interaction
  20. */
  21. DISABLED = 0,
  22. /**
  23. * The interaction point for motion controllers will be inside of them
  24. */
  25. CENTERED_ON_CONTROLLER = 1,
  26. /**
  27. * The interaction point for motion controllers will be in front of the controller
  28. */
  29. CENTERED_IN_FRONT = 2
  30. }
  31. /**
  32. * Options interface for the near interaction module
  33. */
  34. export interface IWebXRNearInteractionOptions {
  35. /**
  36. * If provided, this scene will be used to render meshes.
  37. */
  38. customUtilityLayerScene?: Scene;
  39. /**
  40. * Should meshes created here be added to a utility layer or the main scene
  41. */
  42. useUtilityLayer?: boolean;
  43. /**
  44. * The xr input to use with this near interaction
  45. */
  46. xrInput: WebXRInput;
  47. /**
  48. * Enable near interaction on all controllers instead of switching between them
  49. */
  50. enableNearInteractionOnAllControllers?: boolean;
  51. /**
  52. * The preferred hand to give the near interaction to. This will be prioritized when the controller initialize.
  53. * If switch is enabled, it will still allow the user to switch between the different controllers
  54. */
  55. preferredHandedness?: XRHandedness;
  56. /**
  57. * Disable switching the near interaction from one controller to the other.
  58. * 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
  59. */
  60. disableSwitchOnClick?: boolean;
  61. /**
  62. * Far interaction feature to toggle when near interaction takes precedence
  63. */
  64. farInteractionFeature?: WebXRControllerPointerSelection;
  65. /**
  66. * Near interaction mode for motion controllers
  67. */
  68. nearInteractionControllerMode?: WebXRNearControllerMode;
  69. /**
  70. * Optional material for the motion controller orb, if enabled
  71. */
  72. motionControllerOrbMaterial?: Material;
  73. }
  74. /**
  75. * A module that will enable near interaction near interaction for hands and motion controllers of XR Input Sources
  76. */
  77. export declare class WebXRNearInteraction extends WebXRAbstractFeature {
  78. private readonly _options;
  79. private static _IdCounter;
  80. private _tmpRay;
  81. private _attachController;
  82. private _controllers;
  83. private _scene;
  84. private _attachedController;
  85. private _farInteractionFeature;
  86. /**
  87. * The module's name
  88. */
  89. static readonly Name = "xr-near-interaction";
  90. /**
  91. * The (Babylon) version of this module.
  92. * This is an integer representing the implementation version.
  93. * This number does not correspond to the WebXR specs version
  94. */
  95. static readonly Version = 1;
  96. /**
  97. * default color of the selection ring
  98. */
  99. selectionMeshDefaultColor: Color3;
  100. /**
  101. * This color will be applied to the selection ring when selection is triggered
  102. */
  103. selectionMeshPickedColor: Color3;
  104. /**
  105. * constructs a new background remover module
  106. * @param _xrSessionManager the session manager for this module
  107. * @param _options read-only options to be used in this module
  108. */
  109. constructor(_xrSessionManager: WebXRSessionManager, _options: IWebXRNearInteractionOptions);
  110. /**
  111. * Attach this feature
  112. * Will usually be called by the features manager
  113. *
  114. * @returns true if successful.
  115. */
  116. attach(): boolean;
  117. /**
  118. * Detach this feature.
  119. * Will usually be called by the features manager
  120. *
  121. * @returns true if successful.
  122. */
  123. detach(): boolean;
  124. /**
  125. * Will get the mesh under a specific pointer.
  126. * `scene.meshUnderPointer` will only return one mesh - either left or right.
  127. * @param controllerId the controllerId to check
  128. * @returns The mesh under pointer or null if no mesh is under the pointer
  129. */
  130. getMeshUnderPointer(controllerId: string): Nullable<AbstractMesh>;
  131. /**
  132. * Get the xr controller that correlates to the pointer id in the pointer event
  133. *
  134. * @param id the pointer id to search for
  135. * @returns the controller that correlates to this id or null if not found
  136. */
  137. getXRControllerByPointerId(id: number): Nullable<WebXRInputSource>;
  138. /**
  139. * This function sets webXRControllerPointerSelection feature that will be disabled when
  140. * the hover range is reached for a mesh and will be reattached when not in hover range.
  141. * This is used to remove the selection rays when moving.
  142. * @param farInteractionFeature the feature to disable when finger is in hover range for a mesh
  143. */
  144. setFarInteractionFeature(farInteractionFeature: Nullable<WebXRControllerPointerSelection>): void;
  145. /**
  146. * Filter used for near interaction pick and hover
  147. * @param mesh the mesh candidate to be pick-filtered
  148. * @returns if the mesh should be included in the list of candidate meshes for near interaction
  149. */
  150. private _nearPickPredicate;
  151. /**
  152. * Filter used for near interaction grab
  153. * @param mesh the mesh candidate to be pick-filtered
  154. * @returns if the mesh should be included in the list of candidate meshes for near interaction
  155. */
  156. private _nearGrabPredicate;
  157. /**
  158. * Filter used for any near interaction
  159. * @param mesh the mesh candidate to be pick-filtered
  160. * @returns if the mesh should be included in the list of candidate meshes for near interaction
  161. */
  162. private _nearInteractionPredicate;
  163. private _controllerAvailablePredicate;
  164. private _handleTransitionAnimation;
  165. private readonly _hoverRadius;
  166. private readonly _pickRadius;
  167. private readonly _controllerPickRadius;
  168. private readonly _nearGrabLengthScale;
  169. private _processTouchPoint;
  170. protected _onXRFrame(_xrFrame: XRFrame): void;
  171. private get _utilityLayerScene();
  172. private _generateVisualCue;
  173. private _isControllerReadyForNearInteraction;
  174. private _attachNearInteractionMode;
  175. private _detachController;
  176. private _generateNewTouchPointMesh;
  177. private _pickWithSphere;
  178. /**
  179. * Picks a mesh with a sphere
  180. * @param mesh the mesh to pick
  181. * @param sphere picking sphere in world coordinates
  182. * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check
  183. * @returns the picking info
  184. */
  185. static PickMeshWithSphere(mesh: AbstractMesh, sphere: BoundingSphere, skipBoundingInfo?: boolean): PickingInfo;
  186. }