scene.inputManager.d.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import type { EventState, Observer } from "../Misc/observable";
  2. import { PointerInfo } from "../Events/pointerEvents";
  3. import type { Nullable } from "../types";
  4. import { PickingInfo } from "../Collisions/pickingInfo";
  5. import { Vector2 } from "../Maths/math.vector";
  6. import type { AbstractMesh } from "../Meshes/abstractMesh";
  7. import type { IMouseEvent, IPointerEvent } from "../Events/deviceInputEvents";
  8. import type { Scene } from "../scene";
  9. /**
  10. * Class used to manage all inputs for the scene.
  11. */
  12. export declare class InputManager {
  13. /** The distance in pixel that you have to move to prevent some events */
  14. static DragMovementThreshold: number;
  15. /** Time in milliseconds to wait to raise long press events if button is still pressed */
  16. static LongPressDelay: number;
  17. /** Time in milliseconds with two consecutive clicks will be considered as a double click */
  18. static DoubleClickDelay: number;
  19. /**
  20. * This flag will modify the behavior so that, when true, a click will happen if and only if
  21. * another click DOES NOT happen within the DoubleClickDelay time frame. If another click does
  22. * happen within that time frame, the first click will not fire an event and and a double click will occur.
  23. */
  24. static ExclusiveDoubleClickMode: boolean;
  25. /** This is a defensive check to not allow control attachment prior to an already active one. If already attached, previous control is unattached before attaching the new one. */
  26. private _alreadyAttached;
  27. private _alreadyAttachedTo;
  28. private _onPointerMove;
  29. private _onPointerDown;
  30. private _onPointerUp;
  31. private _initClickEvent;
  32. private _initActionManager;
  33. private _delayedSimpleClick;
  34. private _meshPickProceed;
  35. private _previousButtonPressed;
  36. private _currentPickResult;
  37. private _previousPickResult;
  38. private _totalPointersPressed;
  39. private _doubleClickOccured;
  40. private _isSwiping;
  41. private _swipeButtonPressed;
  42. private _skipPointerTap;
  43. private _isMultiTouchGesture;
  44. private _pointerOverMesh;
  45. private _pickedDownMesh;
  46. private _pickedUpMesh;
  47. private _pointerX;
  48. private _pointerY;
  49. private _unTranslatedPointerX;
  50. private _unTranslatedPointerY;
  51. private _startingPointerPosition;
  52. private _previousStartingPointerPosition;
  53. private _startingPointerTime;
  54. private _previousStartingPointerTime;
  55. private _pointerCaptures;
  56. private _meshUnderPointerId;
  57. private _movePointerInfo;
  58. private _cameraObserverCount;
  59. private _delayedClicks;
  60. private _onKeyDown;
  61. private _onKeyUp;
  62. private _scene;
  63. private _deviceSourceManager;
  64. /**
  65. * Creates a new InputManager
  66. * @param scene - defines the hosting scene
  67. */
  68. constructor(scene?: Scene);
  69. /**
  70. * Gets the mesh that is currently under the pointer
  71. * @returns Mesh that the pointer is pointer is hovering over
  72. */
  73. get meshUnderPointer(): Nullable<AbstractMesh>;
  74. /**
  75. * When using more than one pointer (for example in XR) you can get the mesh under the specific pointer
  76. * @param pointerId - the pointer id to use
  77. * @returns The mesh under this pointer id or null if not found
  78. */
  79. getMeshUnderPointerByPointerId(pointerId: number): Nullable<AbstractMesh>;
  80. /**
  81. * Gets the pointer coordinates in 2D without any translation (ie. straight out of the pointer event)
  82. * @returns Vector with X/Y values directly from pointer event
  83. */
  84. get unTranslatedPointer(): Vector2;
  85. /**
  86. * Gets or sets the current on-screen X position of the pointer
  87. * @returns Translated X with respect to screen
  88. */
  89. get pointerX(): number;
  90. set pointerX(value: number);
  91. /**
  92. * Gets or sets the current on-screen Y position of the pointer
  93. * @returns Translated Y with respect to screen
  94. */
  95. get pointerY(): number;
  96. set pointerY(value: number);
  97. private _updatePointerPosition;
  98. private _processPointerMove;
  99. /** @internal */
  100. _setRayOnPointerInfo(pickInfo: Nullable<PickingInfo>, event: IMouseEvent): void;
  101. /** @internal */
  102. _addCameraPointerObserver(observer: (p: PointerInfo, s: EventState) => void, mask?: number): Nullable<Observer<PointerInfo>>;
  103. /** @internal */
  104. _removeCameraPointerObserver(observer: Observer<PointerInfo>): boolean;
  105. private _checkForPicking;
  106. private _checkPrePointerObservable;
  107. /** @internal */
  108. _pickMove(evt: IPointerEvent): PickingInfo;
  109. private _setCursorAndPointerOverMesh;
  110. /**
  111. * Use this method to simulate a pointer move on a mesh
  112. * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay
  113. * @param pickResult - pickingInfo of the object wished to simulate pointer event on
  114. * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)
  115. */
  116. simulatePointerMove(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): void;
  117. /**
  118. * Use this method to simulate a pointer down on a mesh
  119. * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay
  120. * @param pickResult - pickingInfo of the object wished to simulate pointer event on
  121. * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)
  122. */
  123. simulatePointerDown(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): void;
  124. private _processPointerDown;
  125. /**
  126. * @internal
  127. * @internals Boolean if delta for pointer exceeds drag movement threshold
  128. */
  129. _isPointerSwiping(): boolean;
  130. /**
  131. * Use this method to simulate a pointer up on a mesh
  132. * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay
  133. * @param pickResult - pickingInfo of the object wished to simulate pointer event on
  134. * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)
  135. * @param doubleTap - indicates that the pointer up event should be considered as part of a double click (false by default)
  136. */
  137. simulatePointerUp(pickResult: PickingInfo, pointerEventInit?: PointerEventInit, doubleTap?: boolean): void;
  138. private _processPointerUp;
  139. /**
  140. * Gets a boolean indicating if the current pointer event is captured (meaning that the scene has already handled the pointer down)
  141. * @param pointerId - defines the pointer id to use in a multi-touch scenario (0 by default)
  142. * @returns true if the pointer was captured
  143. */
  144. isPointerCaptured(pointerId?: number): boolean;
  145. /**
  146. * Attach events to the canvas (To handle actionManagers triggers and raise onPointerMove, onPointerDown and onPointerUp
  147. * @param attachUp - defines if you want to attach events to pointerup
  148. * @param attachDown - defines if you want to attach events to pointerdown
  149. * @param attachMove - defines if you want to attach events to pointermove
  150. * @param elementToAttachTo - defines the target DOM element to attach to (will use the canvas by default)
  151. */
  152. attachControl(attachUp?: boolean, attachDown?: boolean, attachMove?: boolean, elementToAttachTo?: Nullable<HTMLElement>): void;
  153. /**
  154. * Detaches all event handlers
  155. */
  156. detachControl(): void;
  157. /**
  158. * Force the value of meshUnderPointer
  159. * @param mesh - defines the mesh to use
  160. * @param pointerId - optional pointer id when using more than one pointer. Defaults to 0
  161. * @param pickResult - optional pickingInfo data used to find mesh
  162. * @param evt - optional pointer event
  163. */
  164. setPointerOverMesh(mesh: Nullable<AbstractMesh>, pointerId?: number, pickResult?: Nullable<PickingInfo>, evt?: IPointerEvent): void;
  165. /**
  166. * Gets the mesh under the pointer
  167. * @returns a Mesh or null if no mesh is under the pointer
  168. */
  169. getPointerOverMesh(): Nullable<AbstractMesh>;
  170. /**
  171. * @param mesh - Mesh to invalidate
  172. * @internal
  173. */
  174. _invalidateMesh(mesh: AbstractMesh): void;
  175. }