freeCameraInputsManager.js 2.8 KB

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