freeCameraInputsManager.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 { FreeCameraTouchInput } from "../Cameras/Inputs/freeCameraTouchInput";
  6. import { Nullable } from '../types';
  7. /**
  8. * Default Inputs manager for the FreeCamera.
  9. * It groups all the default supported inputs for ease of use.
  10. * @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
  11. */
  12. export class FreeCameraInputsManager extends CameraInputsManager<FreeCamera> {
  13. /**
  14. * @hidden
  15. */
  16. public _mouseInput: Nullable<FreeCameraMouseInput> = null;
  17. /**
  18. * Instantiates a new FreeCameraInputsManager.
  19. * @param camera Defines the camera the inputs belong to
  20. */
  21. constructor(camera: FreeCamera) {
  22. super(camera);
  23. }
  24. /**
  25. * Add keyboard input support to the input manager.
  26. * @returns the current input manager
  27. */
  28. addKeyboard(): FreeCameraInputsManager {
  29. this.add(new FreeCameraKeyboardMoveInput());
  30. return this;
  31. }
  32. /**
  33. * Add mouse input support to the input manager.
  34. * @param touchEnabled if the FreeCameraMouseInput should support touch (default: true)
  35. * @returns the current input manager
  36. */
  37. addMouse(touchEnabled = true): FreeCameraInputsManager {
  38. if (!this._mouseInput) {
  39. this._mouseInput = new FreeCameraMouseInput(touchEnabled);
  40. this.add(this._mouseInput);
  41. }
  42. return this;
  43. }
  44. /**
  45. * Removes the mouse input support from the manager
  46. * @returns the current input manager
  47. */
  48. removeMouse(): FreeCameraInputsManager {
  49. if (this._mouseInput) {
  50. this.remove(this._mouseInput);
  51. }
  52. return this;
  53. }
  54. /**
  55. * Add touch input support to the input manager.
  56. * @returns the current input manager
  57. */
  58. addTouch(): FreeCameraInputsManager {
  59. this.add(new FreeCameraTouchInput());
  60. return this;
  61. }
  62. /**
  63. * Remove all attached input methods from a camera
  64. */
  65. public clear(): void {
  66. super.clear();
  67. this._mouseInput = null;
  68. }
  69. }