freeCameraInputsManager.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { FreeCamera } from "./freeCamera";
  2. import { CameraInputsManager } from "./cameraInputsManager";
  3. import { FreeCameraKeyboardMoveInput } from "../Cameras/Inputs/freeCameraKeyboardMoveInput";
  4. import { FreeCameraMouseInput } from "../Cameras/Inputs/freeCameraMouseInput";
  5. import { FreeCameraMouseWheelInput } from "../Cameras/Inputs/freeCameraMouseWheelInput";
  6. import { FreeCameraTouchInput } from "../Cameras/Inputs/freeCameraTouchInput";
  7. import { Nullable } from '../types';
  8. /**
  9. * Default Inputs manager for the FreeCamera.
  10. * It groups all the default supported inputs for ease of use.
  11. * @see https://doc.babylonjs.com/how_to/customizing_camera_inputs
  12. */
  13. export class FreeCameraInputsManager extends CameraInputsManager<FreeCamera> {
  14. /**
  15. * @hidden
  16. */
  17. public _mouseInput: Nullable<FreeCameraMouseInput> = null;
  18. /**
  19. * @hidden
  20. */
  21. public _mouseWheelInput: Nullable<FreeCameraMouseWheelInput> = null;
  22. /**
  23. * Instantiates a new FreeCameraInputsManager.
  24. * @param camera Defines the camera the inputs belong to
  25. */
  26. constructor(camera: FreeCamera) {
  27. super(camera);
  28. }
  29. /**
  30. * Add keyboard input support to the input manager.
  31. * @returns the current input manager
  32. */
  33. addKeyboard(): FreeCameraInputsManager {
  34. this.add(new FreeCameraKeyboardMoveInput());
  35. return this;
  36. }
  37. /**
  38. * Add mouse input support to the input manager.
  39. * @param touchEnabled if the FreeCameraMouseInput should support touch (default: true)
  40. * @returns the current input manager
  41. */
  42. addMouse(touchEnabled = true): FreeCameraInputsManager {
  43. if (!this._mouseInput) {
  44. this._mouseInput = new FreeCameraMouseInput(touchEnabled);
  45. this.add(this._mouseInput);
  46. }
  47. return this;
  48. }
  49. /**
  50. * Removes the mouse input support from the manager
  51. * @returns the current input manager
  52. */
  53. removeMouse(): FreeCameraInputsManager {
  54. if (this._mouseInput) {
  55. this.remove(this._mouseInput);
  56. }
  57. return this;
  58. }
  59. /**
  60. * Add mouse wheel input support to the input manager.
  61. * @returns the current input manager
  62. */
  63. addMouseWheel(): FreeCameraInputsManager {
  64. if (!this._mouseWheelInput) {
  65. this._mouseWheelInput = new FreeCameraMouseWheelInput();
  66. this.add(this._mouseWheelInput);
  67. }
  68. return this;
  69. }
  70. /**
  71. * Removes the mouse wheel input support from the manager
  72. * @returns the current input manager
  73. */
  74. removeMouseWheel(): FreeCameraInputsManager {
  75. if (this._mouseWheelInput) {
  76. this.remove(this._mouseWheelInput);
  77. }
  78. return this;
  79. }
  80. /**
  81. * Add touch input support to the input manager.
  82. * @returns the current input manager
  83. */
  84. addTouch(): FreeCameraInputsManager {
  85. this.add(new FreeCameraTouchInput());
  86. return this;
  87. }
  88. /**
  89. * Remove all attached input methods from a camera
  90. */
  91. public clear(): void {
  92. super.clear();
  93. this._mouseInput = null;
  94. }
  95. }