babylon.arcrotatecamera.input.keyboard.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var ArcRotateCameraKeyboardMoveInput = (function () {
  10. function ArcRotateCameraKeyboardMoveInput() {
  11. this._keys = [];
  12. this.keysUp = [38];
  13. this.keysDown = [40];
  14. this.keysLeft = [37];
  15. this.keysRight = [39];
  16. }
  17. ArcRotateCameraKeyboardMoveInput.prototype.attachControl = function (element, noPreventDefault) {
  18. var _this = this;
  19. this._onKeyDown = function (evt) {
  20. if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
  21. _this.keysDown.indexOf(evt.keyCode) !== -1 ||
  22. _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
  23. _this.keysRight.indexOf(evt.keyCode) !== -1) {
  24. var index = _this._keys.indexOf(evt.keyCode);
  25. if (index === -1) {
  26. _this._keys.push(evt.keyCode);
  27. }
  28. if (evt.preventDefault) {
  29. if (!noPreventDefault) {
  30. evt.preventDefault();
  31. }
  32. }
  33. }
  34. };
  35. this._onKeyUp = function (evt) {
  36. if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
  37. _this.keysDown.indexOf(evt.keyCode) !== -1 ||
  38. _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
  39. _this.keysRight.indexOf(evt.keyCode) !== -1) {
  40. var index = _this._keys.indexOf(evt.keyCode);
  41. if (index >= 0) {
  42. _this._keys.splice(index, 1);
  43. }
  44. if (evt.preventDefault) {
  45. if (!noPreventDefault) {
  46. evt.preventDefault();
  47. }
  48. }
  49. }
  50. };
  51. this._onLostFocus = function () {
  52. _this._keys = [];
  53. };
  54. BABYLON.Tools.RegisterTopRootEvents([
  55. { name: "keydown", handler: this._onKeyDown },
  56. { name: "keyup", handler: this._onKeyUp },
  57. { name: "blur", handler: this._onLostFocus }
  58. ]);
  59. };
  60. ArcRotateCameraKeyboardMoveInput.prototype.detachControl = function (element) {
  61. BABYLON.Tools.UnregisterTopRootEvents([
  62. { name: "keydown", handler: this._onKeyDown },
  63. { name: "keyup", handler: this._onKeyUp },
  64. { name: "blur", handler: this._onLostFocus }
  65. ]);
  66. };
  67. ArcRotateCameraKeyboardMoveInput.prototype.checkInputs = function () {
  68. var camera = this.camera;
  69. for (var index = 0; index < this._keys.length; index++) {
  70. var keyCode = this._keys[index];
  71. if (this.keysLeft.indexOf(keyCode) !== -1) {
  72. camera.inertialAlphaOffset -= 0.01;
  73. }
  74. else if (this.keysUp.indexOf(keyCode) !== -1) {
  75. camera.inertialBetaOffset -= 0.01;
  76. }
  77. else if (this.keysRight.indexOf(keyCode) !== -1) {
  78. camera.inertialAlphaOffset += 0.01;
  79. }
  80. else if (this.keysDown.indexOf(keyCode) !== -1) {
  81. camera.inertialBetaOffset += 0.01;
  82. }
  83. }
  84. };
  85. ArcRotateCameraKeyboardMoveInput.prototype.getTypeName = function () {
  86. return "ArcRotateCameraKeyboardMoveInput";
  87. };
  88. ArcRotateCameraKeyboardMoveInput.prototype.getSimpleName = function () {
  89. return "keyboard";
  90. };
  91. __decorate([
  92. BABYLON.serialize()
  93. ], ArcRotateCameraKeyboardMoveInput.prototype, "keysUp", void 0);
  94. __decorate([
  95. BABYLON.serialize()
  96. ], ArcRotateCameraKeyboardMoveInput.prototype, "keysDown", void 0);
  97. __decorate([
  98. BABYLON.serialize()
  99. ], ArcRotateCameraKeyboardMoveInput.prototype, "keysLeft", void 0);
  100. __decorate([
  101. BABYLON.serialize()
  102. ], ArcRotateCameraKeyboardMoveInput.prototype, "keysRight", void 0);
  103. return ArcRotateCameraKeyboardMoveInput;
  104. })();
  105. BABYLON.ArcRotateCameraKeyboardMoveInput = ArcRotateCameraKeyboardMoveInput;
  106. BABYLON.CameraInputTypes["ArcRotateCameraKeyboardMoveInput"] = ArcRotateCameraKeyboardMoveInput;
  107. })(BABYLON || (BABYLON = {}));