cameraInputsManager.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import type { Nullable } from "../types";
  2. import { Camera } from "./camera";
  3. /**
  4. * @ignore
  5. * This is a list of all the different input types that are available in the application.
  6. * Fo instance: ArcRotateCameraGamepadInput...
  7. */
  8. export declare var CameraInputTypes: {};
  9. /**
  10. * This is the contract to implement in order to create a new input class.
  11. * Inputs are dealing with listening to user actions and moving the camera accordingly.
  12. */
  13. export interface ICameraInput<TCamera extends Camera> {
  14. /**
  15. * Defines the camera the input is attached to.
  16. */
  17. camera: Nullable<TCamera>;
  18. /**
  19. * Gets the class name of the current input.
  20. * @returns the class name
  21. */
  22. getClassName(): string;
  23. /**
  24. * Get the friendly name associated with the input class.
  25. * @returns the input friendly name
  26. */
  27. getSimpleName(): string;
  28. /**
  29. * Attach the input controls to a specific dom element to get the input from.
  30. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  31. */
  32. attachControl(noPreventDefault?: boolean): void;
  33. /**
  34. * Detach the current controls from the specified dom element.
  35. */
  36. detachControl(): void;
  37. /**
  38. * Update the current camera state depending on the inputs that have been used this frame.
  39. * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.
  40. */
  41. checkInputs?: () => void;
  42. }
  43. /**
  44. * Represents a map of input types to input instance or input index to input instance.
  45. */
  46. export interface CameraInputsMap<TCamera extends Camera> {
  47. /**
  48. * Accessor to the input by input type.
  49. */
  50. [name: string]: ICameraInput<TCamera>;
  51. /**
  52. * Accessor to the input by input index.
  53. */
  54. [idx: number]: ICameraInput<TCamera>;
  55. }
  56. /**
  57. * This represents the input manager used within a camera.
  58. * It helps dealing with all the different kind of input attached to a camera.
  59. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs
  60. */
  61. export declare class CameraInputsManager<TCamera extends Camera> {
  62. /**
  63. * Defines the list of inputs attached to the camera.
  64. */
  65. attached: CameraInputsMap<TCamera>;
  66. /**
  67. * Defines the dom element the camera is collecting inputs from.
  68. * This is null if the controls have not been attached.
  69. */
  70. attachedToElement: boolean;
  71. /**
  72. * Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  73. */
  74. noPreventDefault: boolean;
  75. /**
  76. * Defined the camera the input manager belongs to.
  77. */
  78. camera: TCamera;
  79. /**
  80. * Update the current camera state depending on the inputs that have been used this frame.
  81. * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.
  82. */
  83. checkInputs: () => void;
  84. /**
  85. * Instantiate a new Camera Input Manager.
  86. * @param camera Defines the camera the input manager belongs to
  87. */
  88. constructor(camera: TCamera);
  89. /**
  90. * Add an input method to a camera
  91. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs
  92. * @param input Camera input method
  93. */
  94. add(input: ICameraInput<TCamera>): void;
  95. /**
  96. * Remove a specific input method from a camera
  97. * example: camera.inputs.remove(camera.inputs.attached.mouse);
  98. * @param inputToRemove camera input method
  99. */
  100. remove(inputToRemove: ICameraInput<TCamera>): void;
  101. /**
  102. * Remove a specific input type from a camera
  103. * example: camera.inputs.remove("ArcRotateCameraGamepadInput");
  104. * @param inputType the type of the input to remove
  105. */
  106. removeByType(inputType: string): void;
  107. private _addCheckInputs;
  108. /**
  109. * Attach the input controls to the currently attached dom element to listen the events from.
  110. * @param input Defines the input to attach
  111. */
  112. attachInput(input: ICameraInput<TCamera>): void;
  113. /**
  114. * Attach the current manager inputs controls to a specific dom element to listen the events from.
  115. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  116. */
  117. attachElement(noPreventDefault?: boolean): void;
  118. /**
  119. * Detach the current manager inputs controls from a specific dom element.
  120. * @param disconnect Defines whether the input should be removed from the current list of attached inputs
  121. */
  122. detachElement(disconnect?: boolean): void;
  123. /**
  124. * Rebuild the dynamic inputCheck function from the current list of
  125. * defined inputs in the manager.
  126. */
  127. rebuildInputCheck(): void;
  128. /**
  129. * Remove all attached input methods from a camera
  130. */
  131. clear(): void;
  132. /**
  133. * Serialize the current input manager attached to a camera.
  134. * This ensures than once parsed,
  135. * the input associated to the camera will be identical to the current ones
  136. * @param serializedCamera Defines the camera serialization JSON the input serialization should write to
  137. */
  138. serialize(serializedCamera: any): void;
  139. /**
  140. * Parses an input manager serialized JSON to restore the previous list of inputs
  141. * and states associated to a camera.
  142. * @param parsedCamera Defines the JSON to parse
  143. */
  144. parse(parsedCamera: any): void;
  145. }