@shapediver/viewer.rendering-engine.camera-engine 1.15.7 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/implementation/CameraEngine.d.ts +15 -12
  2. package/dist/implementation/CameraEngine.d.ts.map +1 -1
  3. package/dist/implementation/CameraEngine.js +53 -40
  4. package/dist/implementation/CameraEngine.js.map +1 -1
  5. package/dist/implementation/camera/AbstractCamera.d.ts +23 -46
  6. package/dist/implementation/camera/AbstractCamera.d.ts.map +1 -1
  7. package/dist/implementation/camera/AbstractCamera.js +11 -6
  8. package/dist/implementation/camera/AbstractCamera.js.map +1 -1
  9. package/dist/implementation/camera/OrthographicCamera.d.ts +10 -5
  10. package/dist/implementation/camera/OrthographicCamera.d.ts.map +1 -1
  11. package/dist/implementation/camera/OrthographicCamera.js +29 -15
  12. package/dist/implementation/camera/OrthographicCamera.js.map +1 -1
  13. package/dist/implementation/camera/PerspectiveCamera.d.ts +10 -4
  14. package/dist/implementation/camera/PerspectiveCamera.d.ts.map +1 -1
  15. package/dist/implementation/camera/PerspectiveCamera.js +27 -15
  16. package/dist/implementation/camera/PerspectiveCamera.js.map +1 -1
  17. package/dist/implementation/controls/AbstractCameraControls.d.ts +6 -12
  18. package/dist/implementation/controls/AbstractCameraControls.d.ts.map +1 -1
  19. package/dist/implementation/controls/AbstractCameraControls.js +5 -5
  20. package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
  21. package/dist/implementation/controls/OrthographicCameraControls.d.ts +2 -2
  22. package/dist/implementation/controls/OrthographicCameraControls.d.ts.map +1 -1
  23. package/dist/implementation/controls/OrthographicCameraControls.js +3 -4
  24. package/dist/implementation/controls/OrthographicCameraControls.js.map +1 -1
  25. package/dist/implementation/controls/PerspectiveCameraControls.d.ts +2 -2
  26. package/dist/implementation/controls/PerspectiveCameraControls.d.ts.map +1 -1
  27. package/dist/implementation/controls/PerspectiveCameraControls.js +3 -4
  28. package/dist/implementation/controls/PerspectiveCameraControls.js.map +1 -1
  29. package/dist/implementation/interpolation/CameraInterpolationManager.d.ts +2 -8
  30. package/dist/implementation/interpolation/CameraInterpolationManager.d.ts.map +1 -1
  31. package/dist/implementation/interpolation/CameraInterpolationManager.js +0 -1
  32. package/dist/implementation/interpolation/CameraInterpolationManager.js.map +1 -1
  33. package/dist/index.d.ts +3 -3
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/interfaces/ICameraEngine.d.ts +4 -3
  38. package/dist/interfaces/ICameraEngine.d.ts.map +1 -1
  39. package/dist/interfaces/ICameraEngine.js +6 -6
  40. package/dist/interfaces/ICameraEngine.js.map +1 -1
  41. package/dist/interfaces/camera/ICamera.d.ts +37 -33
  42. package/dist/interfaces/camera/ICamera.d.ts.map +1 -1
  43. package/dist/interfaces/camera/IOrthographicCamera.d.ts +1 -0
  44. package/dist/interfaces/camera/IOrthographicCamera.d.ts.map +1 -1
  45. package/dist/interfaces/camera/IPerspectiveCamera.d.ts +1 -0
  46. package/dist/interfaces/camera/IPerspectiveCamera.d.ts.map +1 -1
  47. package/dist/interfaces/controls/ICameraControls.d.ts +29 -0
  48. package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
  49. package/dist/interfaces/controls/ICameraControlsUsage.d.ts +2 -9
  50. package/dist/interfaces/controls/ICameraControlsUsage.d.ts.map +1 -1
  51. package/package.json +15 -12
  52. package/src/implementation/CameraEngine.ts +324 -0
  53. package/src/implementation/camera/AbstractCamera.ts +314 -0
  54. package/src/implementation/camera/OrthographicCamera.ts +276 -0
  55. package/src/implementation/camera/PerspectiveCamera.ts +250 -0
  56. package/src/implementation/controls/AbstractCameraControls.ts +329 -0
  57. package/src/implementation/controls/OrthographicCameraControls.ts +131 -0
  58. package/src/implementation/controls/PerspectiveCameraControls.ts +263 -0
  59. package/src/implementation/controls/orthographic/CameraControlsEventDistribution.ts +205 -0
  60. package/src/implementation/controls/orthographic/CameraControlsLogic.ts +279 -0
  61. package/src/implementation/controls/perspective/CameraControlsEventDistribution.ts +221 -0
  62. package/src/implementation/controls/perspective/CameraControlsLogic.ts +478 -0
  63. package/src/implementation/interpolation/CameraInterpolationManager.ts +154 -0
  64. package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts +86 -0
  65. package/src/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.ts +42 -0
  66. package/src/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.ts +63 -0
  67. package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts +43 -0
  68. package/src/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.ts +67 -0
  69. package/src/index.ts +31 -0
  70. package/src/interfaces/ICameraEngine.ts +19 -0
  71. package/src/interfaces/camera/ICamera.ts +77 -0
  72. package/src/interfaces/camera/IOrthographicCamera.ts +18 -0
  73. package/src/interfaces/camera/IPerspectiveCamera.ts +10 -0
  74. package/src/interfaces/controls/ICameraControls.ts +37 -0
  75. package/src/interfaces/controls/ICameraControlsEventDistribution.ts +8 -0
  76. package/src/interfaces/controls/ICameraControlsLogic.ts +8 -0
  77. package/src/interfaces/controls/ICameraControlsUsage.ts +30 -0
  78. package/src/interfaces/controls/IOrthographicCameraControls.ts +13 -0
  79. package/src/interfaces/controls/IPerspectiveCameraControls.ts +25 -0
  80. package/src/interfaces/interpolation/ICameraInterpolation.ts +5 -0
  81. package/tsconfig.json +17 -0
@@ -0,0 +1,263 @@
1
+ import { IOrbitControlsSettingsV3 } from '@shapediver/viewer.settings'
2
+ import { SettingsEngine, StateEngine, Converter } from '@shapediver/viewer.shared.services'
3
+ import { vec3 } from 'gl-matrix'
4
+ import { container } from 'tsyringe'
5
+
6
+ import { CAMERA_TYPE, ICamera } from '../..'
7
+ import { IPerspectiveCameraControls } from '../../interfaces/controls/IPerspectiveCameraControls'
8
+ import { AbstractCameraControls } from './AbstractCameraControls'
9
+ import {
10
+ CameraControlsEventDistribution as OrbitCameraControlsEventDistribution,
11
+ } from './perspective/CameraControlsEventDistribution'
12
+ import { CameraControlsLogic as OrbitCameraControlsLogic } from './perspective/CameraControlsLogic'
13
+
14
+ export class PerspectiveCameraControls extends AbstractCameraControls implements IPerspectiveCameraControls {
15
+ // #region Properties (19)
16
+
17
+ private _autoRotationSpeed: number = 0;
18
+ private _cubePositionRestriction: { min: vec3, max: vec3 } = { min: vec3.fromValues(-Infinity, -Infinity, -Infinity), max: vec3.fromValues(Infinity, Infinity, Infinity) };
19
+ private _cubeTargetRestriction: { min: vec3, max: vec3 } = { min: vec3.fromValues(-Infinity, -Infinity, -Infinity), max: vec3.fromValues(Infinity, Infinity, Infinity) };
20
+ private _damping: number = 0.1;
21
+ private _enableAutoRotation: boolean = false;
22
+ private _enableKeyPan: boolean = false;
23
+ private _enablePan: boolean = true;
24
+ private _enableRotation: boolean = true;
25
+ private _enableZoom: boolean = true;
26
+ private _input: { keys: { up: number, down: number, left: number, right: number }, mouse: { rotate: number, zoom: number, pan: number }, touch: { rotate: number, zoom: number, pan: number } } = { keys: { up: 38, down: 40, left: 37, right: 39 }, mouse: { rotate: 0, zoom: 1, pan: 2 }, touch: { rotate: 1, zoom: 2, pan: 3 }, };
27
+ private _keyPanSpeed: number = 0.5;
28
+ private _movementSmoothness: number = 0.5;
29
+ private _panSpeed: number = 0.5;
30
+ private _rotationRestriction: { minPolarAngle: number, maxPolarAngle: number, minAzimuthAngle: number, maxAzimuthAngle: number } = { minPolarAngle: 0, maxPolarAngle: 180, minAzimuthAngle: -Infinity, maxAzimuthAngle: Infinity };
31
+ private _rotationSpeed: number = 0.5;
32
+ private _spherePositionRestriction: { center: vec3, radius: number } = { center: vec3.create(), radius: Infinity };
33
+ private _sphereTargetRestriction: { center: vec3, radius: number } = { center: vec3.create(), radius: Infinity };
34
+ private _zoomRestriction: { minDistance: number, maxDistance: number } = { minDistance: 0, maxDistance: Infinity };
35
+ private _zoomSpeed: number = 0.5;
36
+ private readonly _converter: Converter = <Converter>container.resolve(Converter);
37
+ private readonly _stateEngine: StateEngine = <StateEngine>container.resolve(StateEngine);
38
+
39
+ // #endregion Properties (19)
40
+
41
+ // #region Constructors (1)
42
+
43
+ constructor(camera: ICamera, enabled: boolean) {
44
+ super(camera, enabled, CAMERA_TYPE.PERSPECTIVE);
45
+ this._cameraLogic = new OrbitCameraControlsLogic(this);
46
+ this._cameraControlsEventDistribution = new OrbitCameraControlsEventDistribution(this, <OrbitCameraControlsLogic>this._cameraLogic);
47
+ }
48
+
49
+ public applySettings(settingsEngine: SettingsEngine) {
50
+ const cameraSetting = settingsEngine.camera.cameras[this.camera.id];
51
+ if(!cameraSetting) return;
52
+ this.reset();
53
+ const controlsSettings = <IOrbitControlsSettingsV3>cameraSetting.controls;
54
+ this.autoRotationSpeed = controlsSettings.autoRotationSpeed;
55
+ this.damping = controlsSettings.damping;
56
+ this.enableAutoRotation = controlsSettings.enableAutoRotation;
57
+ this.enableKeyPan = controlsSettings.enableKeyPan;
58
+ this.enablePan = controlsSettings.enablePan;
59
+ this.enableRotation = controlsSettings.enableRotation;
60
+ this.enableZoom = controlsSettings.enableZoom;
61
+ this.input = controlsSettings.input;
62
+ this.keyPanSpeed = controlsSettings.keyPanSpeed;
63
+ this.movementSmoothness = controlsSettings.movementSmoothness;
64
+ this.rotationSpeed = controlsSettings.rotationSpeed;
65
+ this.panSpeed = controlsSettings.panSpeed;
66
+ this.zoomSpeed = controlsSettings.zoomSpeed;
67
+
68
+ if(controlsSettings.restrictions.position.cube.min.x === null) controlsSettings.restrictions.position.cube.min.x = -Infinity;
69
+ if(controlsSettings.restrictions.position.cube.min.y === null) controlsSettings.restrictions.position.cube.min.y = -Infinity;
70
+ if(controlsSettings.restrictions.position.cube.min.z === null) controlsSettings.restrictions.position.cube.min.z = -Infinity;
71
+ if(controlsSettings.restrictions.position.cube.max.x === null) controlsSettings.restrictions.position.cube.max.x = Infinity;
72
+ if(controlsSettings.restrictions.position.cube.max.y === null) controlsSettings.restrictions.position.cube.max.y = Infinity;
73
+ if(controlsSettings.restrictions.position.cube.max.z === null) controlsSettings.restrictions.position.cube.max.z = Infinity;
74
+ if(controlsSettings.restrictions.position.sphere.radius === null) controlsSettings.restrictions.position.sphere.radius = Infinity;
75
+ if(controlsSettings.restrictions.target.cube.min.x === null) controlsSettings.restrictions.target.cube.min.x = -Infinity;
76
+ if(controlsSettings.restrictions.target.cube.min.y === null) controlsSettings.restrictions.target.cube.min.y = -Infinity;
77
+ if(controlsSettings.restrictions.target.cube.min.z === null) controlsSettings.restrictions.target.cube.min.z = -Infinity;
78
+ if(controlsSettings.restrictions.target.cube.max.x === null) controlsSettings.restrictions.target.cube.max.x = Infinity;
79
+ if(controlsSettings.restrictions.target.cube.max.y === null) controlsSettings.restrictions.target.cube.max.y = Infinity;
80
+ if(controlsSettings.restrictions.target.cube.max.z === null) controlsSettings.restrictions.target.cube.max.z = Infinity;
81
+ if(controlsSettings.restrictions.target.sphere.radius === null) controlsSettings.restrictions.target.sphere.radius = Infinity;
82
+ if(controlsSettings.restrictions.rotation.minAzimuthAngle === null) controlsSettings.restrictions.rotation.minAzimuthAngle = -Infinity;
83
+ if(controlsSettings.restrictions.rotation.maxAzimuthAngle === null) controlsSettings.restrictions.rotation.maxAzimuthAngle = Infinity;
84
+ if(controlsSettings.restrictions.zoom.maxDistance === null) controlsSettings.restrictions.zoom.maxDistance = Infinity;
85
+
86
+ this.cubePositionRestriction = {
87
+ min: this._converter.toVec3(controlsSettings.restrictions.position.cube.min),
88
+ max: this._converter.toVec3(controlsSettings.restrictions.position.cube.max)
89
+ };
90
+ this.spherePositionRestriction = {
91
+ center: this._converter.toVec3(controlsSettings.restrictions.position.sphere.center),
92
+ radius: controlsSettings.restrictions.position.sphere.radius
93
+ };
94
+ this.cubeTargetRestriction = {
95
+ min: this._converter.toVec3(controlsSettings.restrictions.target.cube.min),
96
+ max: this._converter.toVec3(controlsSettings.restrictions.target.cube.max)
97
+ };
98
+ this.sphereTargetRestriction = {
99
+ center: this._converter.toVec3(controlsSettings.restrictions.target.sphere.center),
100
+ radius: controlsSettings.restrictions.target.sphere.radius
101
+ };
102
+ this.rotationRestriction = controlsSettings.restrictions.rotation;
103
+ this.zoomRestriction = controlsSettings.restrictions.zoom;
104
+ }
105
+
106
+ // #endregion Constructors (1)
107
+
108
+ // #region Public Accessors (38)
109
+
110
+ public get autoRotationSpeed(): number {
111
+ return this._autoRotationSpeed;
112
+ }
113
+
114
+ public set autoRotationSpeed(value: number) {
115
+ this._autoRotationSpeed = value;
116
+ }
117
+
118
+ public get cubePositionRestriction(): { min: vec3, max: vec3 } {
119
+ return this._cubePositionRestriction;
120
+ }
121
+
122
+ public set cubePositionRestriction(value: { min: vec3, max: vec3 }) {
123
+ this._cubePositionRestriction = value;
124
+ }
125
+
126
+ public get cubeTargetRestriction(): { min: vec3, max: vec3 } {
127
+ return this._cubeTargetRestriction;
128
+ }
129
+
130
+ public set cubeTargetRestriction(value: { min: vec3, max: vec3 }) {
131
+ this._cubeTargetRestriction = value;
132
+ }
133
+
134
+ public get damping(): number {
135
+ return this._damping;
136
+ }
137
+
138
+ public set damping(value: number) {
139
+ this._damping = value;
140
+ }
141
+
142
+ public get enableAutoRotation(): boolean {
143
+ return this._enableAutoRotation;
144
+ }
145
+
146
+ public set enableAutoRotation(value: boolean) {
147
+ this._enableAutoRotation = value;
148
+ }
149
+
150
+ public get enableKeyPan(): boolean {
151
+ return this._enableKeyPan;
152
+ }
153
+
154
+ public set enableKeyPan(value: boolean) {
155
+ this._enableKeyPan = value;
156
+ }
157
+
158
+ public get enablePan(): boolean {
159
+ return this._enablePan;
160
+ }
161
+
162
+ public set enablePan(value: boolean) {
163
+ this._enablePan = value;
164
+ }
165
+
166
+ public get enableRotation(): boolean {
167
+ return this._enableRotation;
168
+ }
169
+
170
+ public set enableRotation(value: boolean) {
171
+ this._enableRotation = value;
172
+ }
173
+
174
+ public get enableZoom(): boolean {
175
+ return this._enableZoom;
176
+ }
177
+
178
+ public set enableZoom(value: boolean) {
179
+ this._enableZoom = value;
180
+ }
181
+
182
+ public get input(): { keys: { up: number, down: number, left: number, right: number }, mouse: { rotate: number, zoom: number, pan: number }, touch: { rotate: number, zoom: number, pan: number } } {
183
+ return this._input;
184
+ }
185
+
186
+ public set input(value: { keys: { up: number, down: number, left: number, right: number }, mouse: { rotate: number, zoom: number, pan: number }, touch: { rotate: number, zoom: number, pan: number } }) {
187
+ this._input = value;
188
+ }
189
+
190
+ public get keyPanSpeed(): number {
191
+ return this._keyPanSpeed;
192
+ }
193
+
194
+ public set keyPanSpeed(value: number) {
195
+ this._keyPanSpeed = value;
196
+ }
197
+
198
+ public get movementSmoothness(): number {
199
+ return this._movementSmoothness;
200
+ }
201
+
202
+ public set movementSmoothness(value: number) {
203
+ this._movementSmoothness = value;
204
+ }
205
+
206
+ public get panSpeed(): number {
207
+ return this._panSpeed;
208
+ }
209
+
210
+ public set panSpeed(value: number) {
211
+ this._panSpeed = value;
212
+ }
213
+
214
+ public get rotationRestriction(): { minPolarAngle: number, maxPolarAngle: number, minAzimuthAngle: number, maxAzimuthAngle: number } {
215
+ return this._rotationRestriction;
216
+ }
217
+
218
+ public set rotationRestriction(value: { minPolarAngle: number, maxPolarAngle: number, minAzimuthAngle: number, maxAzimuthAngle: number }) {
219
+ this._rotationRestriction = value;
220
+ }
221
+
222
+ public get rotationSpeed(): number {
223
+ return this._rotationSpeed;
224
+ }
225
+
226
+ public set rotationSpeed(value: number) {
227
+ this._rotationSpeed = value;
228
+ }
229
+
230
+ public get spherePositionRestriction(): { center: vec3, radius: number } {
231
+ return this._spherePositionRestriction;
232
+ }
233
+
234
+ public set spherePositionRestriction(value: { center: vec3, radius: number }) {
235
+ this._spherePositionRestriction = value;
236
+ }
237
+
238
+ public get sphereTargetRestriction(): { center: vec3, radius: number } {
239
+ return this._sphereTargetRestriction;
240
+ }
241
+
242
+ public set sphereTargetRestriction(value: { center: vec3, radius: number }) {
243
+ this._sphereTargetRestriction = value;
244
+ }
245
+
246
+ public get zoomRestriction(): { minDistance: number, maxDistance: number } {
247
+ return this._zoomRestriction;
248
+ }
249
+
250
+ public set zoomRestriction(value: { minDistance: number, maxDistance: number }) {
251
+ this._zoomRestriction = value;
252
+ }
253
+
254
+ public get zoomSpeed(): number {
255
+ return this._zoomSpeed;
256
+ }
257
+
258
+ public set zoomSpeed(value: number) {
259
+ this._zoomSpeed = value;
260
+ }
261
+
262
+ // #endregion Public Accessors (38)
263
+ }
@@ -0,0 +1,205 @@
1
+ import { CameraControlsLogic } from './CameraControlsLogic'
2
+ import { ICameraControlsEventDistribution } from '../../../interfaces/controls/ICameraControlsEventDistribution'
3
+ import { OrthographicCameraControls } from '../OrthographicCameraControls'
4
+
5
+ export class CameraControlsEventDistribution implements ICameraControlsEventDistribution {
6
+ // #region Properties (2)
7
+
8
+ private _active = {
9
+ zoom: false,
10
+ pan: false
11
+ };
12
+
13
+ private _activeEvents = true;
14
+
15
+ // #endregion Properties (2)
16
+
17
+ // #region Constructors (1)
18
+
19
+ constructor(private readonly _controls: OrthographicCameraControls, private readonly _cameraLogic: CameraControlsLogic) { }
20
+
21
+ // #endregion Constructors (1)
22
+
23
+ // #region Public Methods (14)
24
+
25
+ public activateCameraEvents(): void {
26
+ this._activeEvents = true;
27
+ }
28
+
29
+ public deactivateCameraEvents(): void {
30
+ this._activeEvents = false;
31
+ }
32
+
33
+ public onDown(event: MouseEvent | TouchEvent): void {
34
+ let { x, y } = this.convertInput(event);
35
+
36
+ let input = window.TouchEvent && event instanceof TouchEvent ? (event as TouchEvent).touches.length : (event as MouseEvent).button;
37
+ let mapping = window.TouchEvent && event instanceof TouchEvent ? this._controls.input.touch : this._controls.input.mouse;
38
+
39
+ if (input === mapping.pan && this._controls.enablePan) {
40
+ this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
41
+ this._active.pan = true;
42
+ this._active.zoom = false;
43
+ }
44
+
45
+ if (input === mapping.zoom && this._controls.enableZoom) {
46
+ let x1 = x, y1 = y;
47
+ if (window.TouchEvent && event instanceof TouchEvent && this._controls.input.touch.zoom === 2) {
48
+ x1 = (event.touches[0].pageX - event.touches[1].pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
49
+ y1 = (event.touches[0].pageY - event.touches[1].pageY) / window.innerHeight;
50
+ }
51
+ this._cameraLogic.zoom(x1, y1, this._active.zoom, window.TouchEvent && event instanceof TouchEvent);
52
+ this._active.pan = false;
53
+ this._active.zoom = true;
54
+ }
55
+ }
56
+
57
+ public onKey(event: KeyboardEvent): void {
58
+ if (this._controls.enableKeyPan) {
59
+ switch (event.keyCode) {
60
+ case this._controls.input.keys.up:
61
+ this._cameraLogic.pan(0, 0, false, false);
62
+ this._cameraLogic.pan(0, this._controls.keyPanSpeed * 0.05, true, false);
63
+ event.preventDefault();
64
+ event.stopPropagation();
65
+ break;
66
+
67
+ case this._controls.input.keys.down:
68
+ this._cameraLogic.pan(0, 0, false, false);
69
+ this._cameraLogic.pan(0, -this._controls.keyPanSpeed * 0.05, true, false);
70
+ event.preventDefault();
71
+ event.stopPropagation();
72
+ break;
73
+
74
+ case this._controls.input.keys.left:
75
+ this._cameraLogic.pan(0, 0, false, false);
76
+ this._cameraLogic.pan(this._controls.keyPanSpeed * 0.05, 0, true, false);
77
+ event.preventDefault();
78
+ event.stopPropagation();
79
+ break;
80
+
81
+ case this._controls.input.keys.right:
82
+ this._cameraLogic.pan(0, 0, false, false);
83
+ this._cameraLogic.pan(-this._controls.keyPanSpeed * 0.05, 0, true, false);
84
+ event.preventDefault();
85
+ event.stopPropagation();
86
+ break;
87
+ }
88
+ }
89
+ }
90
+
91
+ public onKeyDown(event: KeyboardEvent): void {
92
+ if(!this._activeEvents) return;
93
+ this.onKey(event)
94
+ }
95
+
96
+ public onMouseDown(event: MouseEvent): void {
97
+ if(!this._activeEvents) return;
98
+ this.onDown(event);
99
+ }
100
+
101
+ public onMouseMove(event: MouseEvent): void {
102
+ if(!this._activeEvents) return;
103
+ this.onMove(event);
104
+ }
105
+
106
+ public onMouseEnd(event: MouseEvent): void {
107
+ if(!this._activeEvents) return;
108
+ this.onUp(event);
109
+ }
110
+
111
+ public onMouseUp(event: WheelEvent): void {}
112
+ public onMouseOut(event: WheelEvent): void {}
113
+
114
+ public onMouseWheel(event: WheelEvent): void {
115
+ if(!this._activeEvents) return;
116
+ this.onWheel(event);
117
+ }
118
+
119
+ public onMove(event: MouseEvent | TouchEvent): void {
120
+ let { x, y } = this.convertInput(event);
121
+
122
+ if (this._controls.enablePan && this._active.pan)
123
+ this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
124
+
125
+ if (this._controls.enableZoom && this._active.zoom) {
126
+ let x1 = x, y1 = y;
127
+ if (window.TouchEvent && event instanceof TouchEvent && this._controls.input.touch.zoom === 2) {
128
+ x1 = (event.touches[0].pageX - event.touches[1].pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
129
+ y1 = (event.touches[0].pageY - event.touches[1].pageY) / window.innerHeight;
130
+ }
131
+ this._cameraLogic.zoom(x1, y1, this._active.zoom, window.TouchEvent && event instanceof TouchEvent);
132
+ }
133
+ }
134
+
135
+ public onTouchEnd(event: TouchEvent): void {
136
+ if(!this._activeEvents) return;
137
+ this.onUp(event);
138
+ }
139
+
140
+ public onTouchMove(event: TouchEvent): void {
141
+ if(!this._activeEvents) return;
142
+ this.onMove(event);
143
+ }
144
+
145
+ public onTouchStart(event: TouchEvent): void {
146
+ if(!this._activeEvents) return;
147
+ this.onDown(event);
148
+ }
149
+
150
+ public onTouchCancel(event: TouchEvent): void {}
151
+ public onTouchUp(event: TouchEvent): void {}
152
+
153
+ public onUp(event: MouseEvent | TouchEvent): void {
154
+ this._active.zoom = false;
155
+ this._active.pan = false;
156
+ }
157
+
158
+ public onWheel(event: WheelEvent): void {
159
+ if (!this._controls.enableZoom) return;
160
+ let delta = 0;
161
+ if (event.deltaY !== undefined) {
162
+ // WebKit / Opera / Explorer 9
163
+ delta = -event.deltaY;
164
+ } else if (event.detail !== undefined) {
165
+ // Firefox
166
+ delta = -event.detail;
167
+ }
168
+
169
+ if (Math.sign(delta) > 0) {
170
+ this._cameraLogic.zoom(0, 0, false, false);
171
+ this._cameraLogic.zoom(1.0, 0, true, false);
172
+ } else {
173
+ this._cameraLogic.zoom(1.0, 0, false, false);
174
+ this._cameraLogic.zoom(0, 0, true, false);
175
+ }
176
+ }
177
+
178
+ public reset() {
179
+ this._active = {
180
+ zoom: false,
181
+ pan: false
182
+ };
183
+ }
184
+
185
+ // #endregion Public Methods (14)
186
+
187
+ // #region Private Methods (1)
188
+
189
+ private convertInput(event: MouseEvent | TouchEvent): { x: number, y: number } {
190
+ let aspect = window.innerWidth / window.innerHeight;
191
+ if (event instanceof MouseEvent) {
192
+ return {
193
+ x: event.clientX / window.innerWidth * aspect,
194
+ y: event.clientY / window.innerHeight
195
+ }
196
+ } else {
197
+ return {
198
+ x: event.touches[0].pageX / window.innerWidth * aspect,
199
+ y: event.touches[0].pageY / window.innerHeight
200
+ }
201
+ }
202
+ }
203
+
204
+ // #endregion Private Methods (1)
205
+ }