babylon.arcrotatecamera.input.mousewheel.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 ArcRotateCameraMouseWheelInput = (function () {
  10. function ArcRotateCameraMouseWheelInput() {
  11. this.wheelPrecision = 3.0;
  12. }
  13. ArcRotateCameraMouseWheelInput.prototype.attachControl = function (element, noPreventDefault) {
  14. var _this = this;
  15. this._wheel = function (p, s) {
  16. //sanity check - this should be a PointerWheel event.
  17. if (p.type !== BABYLON.PointerEventTypes.POINTERWHEEL)
  18. return;
  19. var event = p.event;
  20. var delta = 0;
  21. if (event.wheelDelta) {
  22. delta = event.wheelDelta / (_this.wheelPrecision * 40);
  23. }
  24. else if (event.detail) {
  25. delta = -event.detail / _this.wheelPrecision;
  26. }
  27. if (delta)
  28. _this.camera.inertialRadiusOffset += delta;
  29. if (event.preventDefault) {
  30. if (!noPreventDefault) {
  31. event.preventDefault();
  32. }
  33. }
  34. };
  35. this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, BABYLON.PointerEventTypes.POINTERWHEEL);
  36. };
  37. ArcRotateCameraMouseWheelInput.prototype.detachControl = function (element) {
  38. if (this._observer && element) {
  39. this.camera.getScene().onPointerObservable.remove(this._observer);
  40. this._observer = null;
  41. this._wheel = null;
  42. }
  43. };
  44. ArcRotateCameraMouseWheelInput.prototype.getTypeName = function () {
  45. return "ArcRotateCameraMouseWheelInput";
  46. };
  47. ArcRotateCameraMouseWheelInput.prototype.getSimpleName = function () {
  48. return "mousewheel";
  49. };
  50. __decorate([
  51. BABYLON.serialize()
  52. ], ArcRotateCameraMouseWheelInput.prototype, "wheelPrecision", void 0);
  53. return ArcRotateCameraMouseWheelInput;
  54. })();
  55. BABYLON.ArcRotateCameraMouseWheelInput = ArcRotateCameraMouseWheelInput;
  56. BABYLON.CameraInputTypes["ArcRotateCameraMouseWheelInput"] = ArcRotateCameraMouseWheelInput;
  57. })(BABYLON || (BABYLON = {}));