@shapediver/viewer.rendering-engine.camera-engine 2.11.0 → 2.12.1

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 (51) hide show
  1. package/dist/implementation/camera/AbstractCamera.d.ts +5 -3
  2. package/dist/implementation/camera/AbstractCamera.d.ts.map +1 -1
  3. package/dist/implementation/camera/AbstractCamera.js +26 -18
  4. package/dist/implementation/camera/AbstractCamera.js.map +1 -1
  5. package/dist/implementation/controls/AbstractCameraControls.d.ts +13 -7
  6. package/dist/implementation/controls/AbstractCameraControls.d.ts.map +1 -1
  7. package/dist/implementation/controls/AbstractCameraControls.js +71 -38
  8. package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
  9. package/dist/implementation/controls/OrthographicCameraControls.d.ts.map +1 -1
  10. package/dist/implementation/controls/OrthographicCameraControls.js +2 -2
  11. package/dist/implementation/controls/OrthographicCameraControls.js.map +1 -1
  12. package/dist/implementation/controls/PerspectiveCameraControls.d.ts +15 -3
  13. package/dist/implementation/controls/PerspectiveCameraControls.d.ts.map +1 -1
  14. package/dist/implementation/controls/PerspectiveCameraControls.js +108 -78
  15. package/dist/implementation/controls/PerspectiveCameraControls.js.map +1 -1
  16. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts +3 -3
  17. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts.map +1 -1
  18. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js +31 -23
  19. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js.map +1 -1
  20. package/dist/implementation/controls/orthographic/CameraControlsLogic.d.ts.map +1 -1
  21. package/dist/implementation/controls/orthographic/CameraControlsLogic.js +36 -38
  22. package/dist/implementation/controls/orthographic/CameraControlsLogic.js.map +1 -1
  23. package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts +4 -4
  24. package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts.map +1 -1
  25. package/dist/implementation/controls/perspective/CameraControlsEventDistribution.js +39 -32
  26. package/dist/implementation/controls/perspective/CameraControlsEventDistribution.js.map +1 -1
  27. package/dist/implementation/controls/perspective/CameraControlsLogic.d.ts +3 -2
  28. package/dist/implementation/controls/perspective/CameraControlsLogic.d.ts.map +1 -1
  29. package/dist/implementation/controls/perspective/CameraControlsLogic.js +88 -66
  30. package/dist/implementation/controls/perspective/CameraControlsLogic.js.map +1 -1
  31. package/dist/interfaces/camera/ICamera.d.ts +9 -8
  32. package/dist/interfaces/camera/ICamera.d.ts.map +1 -1
  33. package/dist/interfaces/controls/ICameraControls.d.ts +4 -3
  34. package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
  35. package/dist/interfaces/controls/ICameraControlsLogic.d.ts +3 -2
  36. package/dist/interfaces/controls/ICameraControlsLogic.d.ts.map +1 -1
  37. package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts +4 -0
  38. package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts.map +1 -1
  39. package/package.json +7 -7
  40. package/src/implementation/camera/AbstractCamera.ts +44 -37
  41. package/src/implementation/controls/AbstractCameraControls.ts +113 -70
  42. package/src/implementation/controls/OrthographicCameraControls.ts +9 -9
  43. package/src/implementation/controls/PerspectiveCameraControls.ts +114 -73
  44. package/src/implementation/controls/orthographic/CameraControlsEventDistribution.ts +61 -56
  45. package/src/implementation/controls/orthographic/CameraControlsLogic.ts +45 -53
  46. package/src/implementation/controls/perspective/CameraControlsEventDistribution.ts +83 -80
  47. package/src/implementation/controls/perspective/CameraControlsLogic.ts +100 -81
  48. package/src/interfaces/camera/ICamera.ts +31 -26
  49. package/src/interfaces/controls/ICameraControls.ts +5 -5
  50. package/src/interfaces/controls/ICameraControlsLogic.ts +6 -2
  51. package/src/interfaces/controls/IPerspectiveCameraControls.ts +10 -2
@@ -1,11 +1,11 @@
1
- import { mat4, vec2, vec3 } from 'gl-matrix'
1
+ import { mat4, vec2, vec3 } from 'gl-matrix';
2
2
 
3
- import { OrthographicCameraControls } from '../../..'
4
- import { ICameraControlsLogic } from '../../../interfaces/controls/ICameraControlsLogic'
5
- import { OrthographicCamera } from '../../camera/OrthographicCamera'
3
+ import { OrthographicCameraControls } from '../../..';
4
+ import { ICameraControlsLogic } from '../../../interfaces/controls/ICameraControlsLogic';
5
+ import { OrthographicCamera } from '../../camera/OrthographicCamera';
6
6
 
7
7
  export class CameraControlsLogic implements ICameraControlsLogic {
8
- // #region Properties (16)
8
+ // #region Properties (10)
9
9
 
10
10
  private _adjustedSettings = {
11
11
  damping: () => this._controls.damping * this._settingsAdjustments.damping,
@@ -40,17 +40,17 @@ export class CameraControlsLogic implements ICameraControlsLogic {
40
40
  private _settingsAdjustments = {
41
41
  damping: 1.0,
42
42
  movementSmoothness: 1.0,
43
- panSpeed: 2.0,
43
+ panSpeed: 1.75,
44
44
  zoomSpeed: 0.025,
45
45
  };
46
46
  private _touchAdjustments = {
47
47
  damping: 1.0,
48
48
  movementSmoothness: 1.0,
49
- panSpeed: 2.0,
50
- zoomSpeed: 50.0,
49
+ panSpeed: 4.0 / 1.75,
50
+ zoomSpeed: 100.0,
51
51
  };
52
52
 
53
- // #endregion Properties (16)
53
+ // #endregion Properties (10)
54
54
 
55
55
  // #region Constructors (1)
56
56
 
@@ -58,18 +58,13 @@ export class CameraControlsLogic implements ICameraControlsLogic {
58
58
 
59
59
  // #endregion Constructors (1)
60
60
 
61
- // #region Public Methods (7)
61
+ // #region Public Methods (6)
62
62
 
63
63
  public isWithinRestrictions(position: vec3, target: vec3): boolean {
64
64
  return true;
65
65
  }
66
66
 
67
67
  public pan(x: number, y: number, active: boolean, touch: boolean): void {
68
- if (touch) {
69
- x = x / window.devicePixelRatio;
70
- y = y / window.devicePixelRatio;
71
- }
72
-
73
68
  if (!active) {
74
69
  this._panStart = vec2.fromValues(x, y);
75
70
  } else {
@@ -79,7 +74,7 @@ export class CameraControlsLogic implements ICameraControlsLogic {
79
74
  vec2.copy(this._panStart, this._panEnd);
80
75
 
81
76
  const adjustedPanSpeed = this._adjustedSettings.panSpeed() * (touch ? this._touchAdjustments.panSpeed : 1.0);
82
- let offset = this.panDeltaToOffset(vec2.mul(vec2.create(), this._panDelta, vec2.fromValues(adjustedPanSpeed, adjustedPanSpeed)));
77
+ const offset = this.panDeltaToOffset(vec2.mul(vec2.create(), this._panDelta, vec2.fromValues(adjustedPanSpeed, adjustedPanSpeed)));
83
78
 
84
79
  if (this._damping.pan.duration > 0) {
85
80
  if (offset[0] < 0) {
@@ -99,11 +94,11 @@ export class CameraControlsLogic implements ICameraControlsLogic {
99
94
  }
100
95
  }
101
96
 
102
- let damping = 1 - Math.max(0.01, Math.min(0.99, this._adjustedSettings.damping()));
97
+ const damping = 1 - Math.max(0.01, Math.min(0.99, this._adjustedSettings.damping()));
103
98
 
104
- let framesOffsetX = (Math.log(1 / Math.abs(offset[0])) - 5 * Math.log(10)) / (Math.log(damping));
105
- let framesOffsetY = (Math.log(1 / Math.abs(offset[1])) - 5 * Math.log(10)) / (Math.log(damping));
106
- let framesOffsetZ = (Math.log(1 / Math.abs(offset[2])) - 5 * Math.log(10)) / (Math.log(damping));
99
+ const framesOffsetX = (Math.log(1 / Math.abs(offset[0])) - 5 * Math.log(10)) / (Math.log(damping));
100
+ const framesOffsetY = (Math.log(1 / Math.abs(offset[1])) - 5 * Math.log(10)) / (Math.log(damping));
101
+ const framesOffsetZ = (Math.log(1 / Math.abs(offset[2])) - 5 * Math.log(10)) / (Math.log(damping));
107
102
  this._damping.pan.time = 0;
108
103
  this._damping.pan.duration = Math.max(framesOffsetX, Math.max(framesOffsetY, framesOffsetZ)) * 16.6666;
109
104
  this._damping.pan.offset = vec3.clone(offset);
@@ -156,8 +151,7 @@ export class CameraControlsLogic implements ICameraControlsLogic {
156
151
  this._damping.pan.duration = 0;
157
152
  }
158
153
 
159
-
160
- let damping = 1 - Math.max(0.01, Math.min(1, this._adjustedSettings.damping()));
154
+ const damping = 1 - Math.max(0.01, Math.min(1, this._adjustedSettings.damping()));
161
155
 
162
156
  if (this._damping.pan.duration > 0) {
163
157
  if (this._damping.pan.time + time > this._damping.pan.duration) {
@@ -166,9 +160,9 @@ export class CameraControlsLogic implements ICameraControlsLogic {
166
160
  } else {
167
161
  this._damping.pan.time += time;
168
162
 
169
- let frameSinceStart = this._damping.pan.time / 16.6666;
170
- let dampingFrames = Math.pow(damping, frameSinceStart);
171
- let offset = vec3.multiply(vec3.create(), this._damping.pan.offset, vec3.fromValues(dampingFrames, dampingFrames, dampingFrames));
163
+ const frameSinceStart = this._damping.pan.time / 16.6666;
164
+ const dampingFrames = Math.pow(damping, frameSinceStart);
165
+ const offset = vec3.multiply(vec3.create(), this._damping.pan.offset, vec3.fromValues(dampingFrames, dampingFrames, dampingFrames));
172
166
  this._controls.applyTargetVector(offset);
173
167
  this._controls.applyPositionVector(offset);
174
168
  }
@@ -183,20 +177,18 @@ export class CameraControlsLogic implements ICameraControlsLogic {
183
177
  } else {
184
178
  this._damping.zoom.time += time;
185
179
 
186
- let frameSinceStart = this._damping.zoom.time / 16.6666;
187
- let delta = this._damping.zoom.delta * Math.pow(damping, frameSinceStart);
180
+ const frameSinceStart = this._damping.zoom.time / 16.6666;
181
+ const delta = this._damping.zoom.delta * Math.pow(damping, frameSinceStart);
188
182
 
189
- let newDistance = vec3.distance(this._controls.getTargetWithManualUpdates(), this._controls.getPositionWithManualUpdates())
183
+ const newDistance = vec3.distance(this._controls.getTargetWithManualUpdates(), this._controls.getPositionWithManualUpdates())
190
184
  * (1 - delta);
191
185
 
192
-
193
- let dir = vec3.create(),
186
+ const dir = vec3.create(),
194
187
  offset = vec3.create();
195
188
  vec3.normalize(dir, vec3.subtract(dir, this._controls.getTargetWithManualUpdates(), this._controls.getPositionWithManualUpdates()));
196
- vec3.add(offset, this._controls.getPositionWithManualUpdates(), vec3.multiply(offset, dir, vec3.fromValues(newDistance, newDistance, newDistance)))
197
- vec3.subtract(offset, offset, this._controls.getTargetWithManualUpdates())
189
+ vec3.add(offset, this._controls.getPositionWithManualUpdates(), vec3.multiply(offset, dir, vec3.fromValues(newDistance, newDistance, newDistance)));
190
+ vec3.subtract(offset, offset, this._controls.getTargetWithManualUpdates());
198
191
  this._controls.applyTargetVector(offset, true);
199
-
200
192
  }
201
193
  } else {
202
194
  this._damping.zoom.time = 0;
@@ -204,9 +196,7 @@ export class CameraControlsLogic implements ICameraControlsLogic {
204
196
  }
205
197
 
206
198
  public zoom(x: number, y: number, active: boolean, touch: boolean): void {
207
- var distance = Math.sqrt(x * x + y * y);
208
- if (touch)
209
- distance = distance / window.devicePixelRatio;
199
+ const distance = Math.sqrt(x * x + y * y);
210
200
 
211
201
  if (!active) {
212
202
  this._dollyStart = distance;
@@ -222,39 +212,41 @@ export class CameraControlsLogic implements ICameraControlsLogic {
222
212
  this._dollyDelta = Math.max(this._dollyDelta, this._adjustedSettings.movementSmoothness() * this._damping.zoom.delta);
223
213
  }
224
214
  }
225
- let delta = this._dollyDelta * this._adjustedSettings.zoomSpeed() * (touch ? this._touchAdjustments.zoomSpeed : 1.0);
215
+ const delta = this._dollyDelta * this._adjustedSettings.zoomSpeed() * (touch ? this._touchAdjustments.zoomSpeed : 1.0);
226
216
 
227
- let damping = 1 - Math.max(0.01, Math.min(1, this._adjustedSettings.damping()));
228
- let framesDelta = (Math.log(1 / Math.abs(this._dollyDelta)) - 5 * Math.log(10)) / (Math.log(damping));
217
+ const damping = 1 - Math.max(0.01, Math.min(1, this._adjustedSettings.damping()));
218
+ const framesDelta = (Math.log(1 / Math.abs(this._dollyDelta)) - 5 * Math.log(10)) / (Math.log(damping));
229
219
  this._damping.zoom.time = 0;
230
220
  this._damping.zoom.duration = framesDelta * 16.6666;
231
221
  this._damping.zoom.delta = delta;
232
222
 
233
223
  this._damping.pan.duration = 0;
234
224
 
235
-
236
- let newDistance = vec3.distance(this._controls.getTargetWithManualUpdates(), this._controls.getPositionWithManualUpdates())
225
+ const newDistance = vec3.distance(this._controls.getTargetWithManualUpdates(), this._controls.getPositionWithManualUpdates())
237
226
  * (1 - delta);
238
227
 
239
- let dir = vec3.create(),
228
+ const dir = vec3.create(),
240
229
  offset = vec3.create();
241
230
  vec3.normalize(dir, vec3.subtract(dir, this._controls.getTargetWithManualUpdates(), this._controls.getPositionWithManualUpdates()));
242
- vec3.add(offset, this._controls.getPositionWithManualUpdates(), vec3.multiply(offset, dir, vec3.fromValues(newDistance, newDistance, newDistance)))
243
- vec3.subtract(offset, offset, this._controls.getTargetWithManualUpdates())
231
+ vec3.add(offset, this._controls.getPositionWithManualUpdates(), vec3.multiply(offset, dir, vec3.fromValues(newDistance, newDistance, newDistance)));
232
+ vec3.subtract(offset, offset, this._controls.getTargetWithManualUpdates());
244
233
  this._controls.applyTargetVector(offset, true);
245
234
  }
246
235
  }
247
236
 
248
- // #endregion Public Methods (7)
237
+ // #endregion Public Methods (6)
249
238
 
250
- // #region Private Methods (7)
239
+ // #region Private Methods (1)
251
240
 
252
241
  private panDeltaToOffset(panDelta: vec2): vec3 {
253
- let offset = vec3.create();
254
- let panOffset = vec3.create();
242
+ const offset = vec3.create();
243
+ const panOffset = vec3.create();
244
+
245
+ if (!this._controls.canvas) return offset;
246
+ if (this._controls.canvas.clientWidth == 0 || this._controls.canvas.clientHeight == 0) return offset;
255
247
 
256
248
  // perspective
257
- vec3.subtract(offset, this._controls.getPositionWithManualUpdates(), this._controls.getTargetWithManualUpdates())
249
+ vec3.subtract(offset, this._controls.getPositionWithManualUpdates(), this._controls.getTargetWithManualUpdates());
258
250
 
259
251
  const orthographicCamera: OrthographicCamera = <OrthographicCamera>this._controls.camera;
260
252
  const mat = mat4.targetTo(mat4.create(), orthographicCamera.position, orthographicCamera.target, orthographicCamera.up);
@@ -262,18 +254,18 @@ export class CameraControlsLogic implements ICameraControlsLogic {
262
254
  // // we use only clientHeight here so aspect ratio does not distort speed
263
255
  // // left
264
256
  const v1 = vec3.fromValues(mat[0], mat[1], mat[2]);
265
- const scalar1 = -(panDelta[0] * (orthographicCamera.right - orthographicCamera.left) * 0.5 / 1 /** orthographicCamera.zoom */);
257
+ const scalar1 = -(panDelta[0] * (orthographicCamera.right - orthographicCamera.left) * 0.5 / this._controls.canvas?.clientHeight /** orthographicCamera.zoom */);
266
258
  vec3.multiply(v1, v1, vec3.fromValues(scalar1, scalar1, scalar1));
267
259
  vec3.add(panOffset, panOffset, v1);
268
260
 
269
261
  // // up
270
262
  const v2 = vec3.fromValues(mat[4], mat[5], mat[6]);
271
- const scalar2 = panDelta[1] * (orthographicCamera.right - orthographicCamera.left) * 0.5 / 1 /** orthographicCamera.zoom */;
263
+ const scalar2 = panDelta[1] * (orthographicCamera.right - orthographicCamera.left) * 0.5 / this._controls.canvas?.clientHeight /** orthographicCamera.zoom */;
272
264
  vec3.multiply(v2, v2, vec3.fromValues(scalar2, scalar2, scalar2));
273
265
  vec3.add(panOffset, panOffset, v2);
274
266
 
275
267
  return vec3.clone(panOffset);
276
268
  }
277
269
 
278
- // #endregion Private Methods (7)
279
- };
270
+ // #endregion Private Methods (1)
271
+ }
@@ -1,19 +1,18 @@
1
- import { CameraControlsLogic } from './CameraControlsLogic'
2
- import { ICameraControlsEventDistribution } from '../../../interfaces/controls/ICameraControlsEventDistribution'
3
- import { PerspectiveCameraControls } from '../PerspectiveCameraControls'
1
+ import { CameraControlsLogic } from './CameraControlsLogic';
2
+ import { ICameraControlsEventDistribution } from '../../../interfaces/controls/ICameraControlsEventDistribution';
3
+ import { PerspectiveCameraControls } from '../PerspectiveCameraControls';
4
4
 
5
5
  export class CameraControlsEventDistribution implements ICameraControlsEventDistribution {
6
- // #region Properties (1)
6
+ // #region Properties (2)
7
7
 
8
8
  private _active = {
9
9
  rotation: false,
10
10
  zoom: false,
11
11
  pan: false
12
12
  };
13
-
14
13
  private _activeEvents = true;
15
14
 
16
- // #endregion Properties (1)
15
+ // #endregion Properties (2)
17
16
 
18
17
  // #region Constructors (1)
19
18
 
@@ -21,7 +20,7 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
21
20
 
22
21
  // #endregion Constructors (1)
23
22
 
24
- // #region Public Methods (16)
23
+ // #region Public Methods (20)
25
24
 
26
25
  public activateCameraEvents(): void {
27
26
  this._activeEvents = true;
@@ -29,46 +28,46 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
29
28
 
30
29
  public deactivateCameraEvents(): void {
31
30
  this._activeEvents = false;
32
- this.reset()
31
+ this.reset();
33
32
  }
34
33
 
35
- public onDown(event: MouseEvent|TouchEvent): void {
36
- if(this._controls.camera.active === false) return;
37
- let {x,y} = this.convertInput(event);
34
+ public onDown(event: MouseEvent | TouchEvent): void {
35
+ if (this._controls.camera.active === false) return;
36
+ const { x, y } = this.convertInput(event);
38
37
 
39
- let input = window.TouchEvent && event instanceof TouchEvent ? (event as TouchEvent).touches.length : (event as MouseEvent).button;
40
- let mapping = window.TouchEvent && event instanceof TouchEvent ? this._controls.input.touch : this._controls.input.mouse;
38
+ const input = window.TouchEvent && event instanceof TouchEvent ? (event as TouchEvent).touches.length : (event as MouseEvent).button;
39
+ const mapping = window.TouchEvent && event instanceof TouchEvent ? this._controls.input.touch : this._controls.input.mouse;
41
40
 
42
41
  if (input === mapping.rotate && this._controls.enableRotation) {
43
42
  this._cameraLogic.rotate(x, y, this._active.rotation, window.TouchEvent && event instanceof TouchEvent);
44
43
  this._active.rotation = true;
45
- this._active.pan = false;
46
- this._active.zoom = false;
44
+ } else {
45
+ this._active.rotation = false;
47
46
  }
48
47
 
49
48
  if (input === mapping.pan && this._controls.enablePan) {
50
49
  this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
51
- this._active.rotation = false;
52
50
  this._active.pan = true;
53
- this._active.zoom = false;
51
+ } else {
52
+ this._active.pan = false;
54
53
  }
55
54
 
56
55
  if (input === mapping.zoom && this._controls.enableZoom) {
57
56
  let x1 = x, y1 = y;
58
- if(window.TouchEvent && event instanceof TouchEvent && this._controls.input.touch.zoom === 2 && event.touches.length >= 2) {
59
- x1 = (event.touches[0].pageX - event.touches[1].pageX)/ window.innerWidth * (window.innerWidth / window.innerHeight);
60
- y1 = (event.touches[0].pageY - event.touches[1].pageY)/ window.innerHeight;
57
+ if (window.TouchEvent && event instanceof TouchEvent && this._controls.input.touch.zoom === 2 && event.touches.length >= 2) {
58
+ x1 = (event.touches[0].pageX - event.touches[1].pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
59
+ y1 = (event.touches[0].pageY - event.touches[1].pageY) / window.innerHeight;
61
60
  }
62
61
  this._cameraLogic.zoom(x1, y1, this._active.zoom, window.TouchEvent && event instanceof TouchEvent);
63
- this._active.rotation = false;
64
- this._active.pan = false;
65
62
  this._active.zoom = true;
63
+ } else {
64
+ this._active.zoom = false;
66
65
  }
67
66
  }
68
67
 
69
68
  public onKey(event: KeyboardEvent): void {
70
- if(this._controls.camera.active === false) return;
71
- if(!this._controls.enableKeyPan) return;
69
+ if (this._controls.camera.active === false) return;
70
+ if (!this._controls.enableKeyPan) return;
72
71
  switch (event.keyCode) {
73
72
  case this._controls.input.keys.up:
74
73
  this._cameraLogic.pan(0, 0, false, false);
@@ -101,46 +100,46 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
101
100
  }
102
101
 
103
102
  public onKeyDown(event: KeyboardEvent): void {
104
- if(this._controls.camera.active === false) return;
105
- if(!this._activeEvents) return;
106
- this.onKey(event)
103
+ if (this._controls.camera.active === false) return;
104
+ if (!this._activeEvents) return;
105
+ this.onKey(event);
107
106
  }
108
107
 
109
108
  public onMouseDown(event: MouseEvent): void {
110
- if(this._controls.camera.active === false) return;
111
- if(!this._activeEvents) return;
109
+ if (this._controls.camera.active === false) return;
110
+ if (!this._activeEvents) return;
112
111
  this.onDown(event);
113
112
  }
114
113
 
114
+ public onMouseEnd(event: MouseEvent): void {
115
+ if (this._controls.camera.active === false) return;
116
+ if (!this._activeEvents) return;
117
+ this.onUp(event);
118
+ }
119
+
115
120
  public onMouseMove(event: MouseEvent): void {
116
- if(this._controls.camera.active === false) return;
117
- if(!this._activeEvents) return;
121
+ if (this._controls.camera.active === false) return;
122
+ if (!this._activeEvents) return;
118
123
  this.onMove(event);
119
124
  }
120
125
 
121
- public onMouseEnd(event: MouseEvent): void {
122
- if(this._controls.camera.active === false) return;
123
- if(!this._activeEvents) return;
124
- this.onUp(event);
126
+ public onMouseOut(event: WheelEvent): void {
127
+ if (this._controls.camera.active === false) return;
125
128
  }
126
129
 
127
- public onMouseWheel(event: WheelEvent): void {
128
- if(this._controls.camera.active === false) return;
129
- if(!this._activeEvents) return;
130
- this.onWheel(event);
131
- }
132
-
133
130
  public onMouseUp(event: WheelEvent): void {
134
- if(this._controls.camera.active === false) return;
131
+ if (this._controls.camera.active === false) return;
135
132
  }
136
133
 
137
- public onMouseOut(event: WheelEvent): void {
138
- if(this._controls.camera.active === false) return;
134
+ public onMouseWheel(event: WheelEvent): void {
135
+ if (this._controls.camera.active === false) return;
136
+ if (!this._activeEvents) return;
137
+ this.onWheel(event);
139
138
  }
140
139
 
141
- public onMove(event: MouseEvent|TouchEvent): void {
142
- if(this._controls.camera.active === false) return;
143
- let {x,y} = this.convertInput(event);
140
+ public onMove(event: MouseEvent | TouchEvent): void {
141
+ if (this._controls.camera.active === false) return;
142
+ const { x, y } = this.convertInput(event);
144
143
 
145
144
  if (this._controls.enableRotation && this._active.rotation)
146
145
  this._cameraLogic.rotate(x, y, this._active.rotation, window.TouchEvent && event instanceof TouchEvent);
@@ -148,63 +147,63 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
148
147
  if (this._controls.enablePan && this._active.pan)
149
148
  this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
150
149
 
151
- if (this._controls.enableZoom && this._active.zoom){
150
+ if (this._controls.enableZoom && this._active.zoom) {
152
151
  let x1 = x, y1 = y;
153
- if(window.TouchEvent && event instanceof TouchEvent && this._controls.input.touch.zoom === 2 && event.touches.length >= 2) {
154
- x1 = (event.touches[0].pageX - event.touches[1].pageX)/ window.innerWidth * (window.innerWidth / window.innerHeight);
155
- y1 = (event.touches[0].pageY - event.touches[1].pageY)/ window.innerHeight;
152
+ if (window.TouchEvent && event instanceof TouchEvent && this._controls.input.touch.zoom === 2 && event.touches.length >= 2) {
153
+ x1 = (event.touches[0].pageX - event.touches[1].pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
154
+ y1 = (event.touches[0].pageY - event.touches[1].pageY) / window.innerHeight;
156
155
  }
157
156
  this._cameraLogic.zoom(x1, y1, this._active.zoom, window.TouchEvent && event instanceof TouchEvent);
158
157
  }
159
158
  }
160
159
 
160
+ public onTouchCancel(event: TouchEvent): void {
161
+ if (this._controls.camera.active === false) return;
162
+ }
163
+
161
164
  public onTouchEnd(event: TouchEvent): void {
162
- if(this._controls.camera.active === false) return;
163
- if(!this._activeEvents) return;
165
+ if (this._controls.camera.active === false) return;
166
+ if (!this._activeEvents) return;
164
167
  this.onUp(event);
165
168
  }
166
169
 
167
170
  public onTouchMove(event: TouchEvent): void {
168
- if(this._controls.camera.active === false) return;
169
- if(!this._activeEvents) return;
171
+ if (this._controls.camera.active === false) return;
172
+ if (!this._activeEvents) return;
170
173
  this.onMove(event);
171
174
  }
172
175
 
173
176
  public onTouchStart(event: TouchEvent): void {
174
- if(this._controls.camera.active === false) return;
175
- if(!this._activeEvents) return;
177
+ if (this._controls.camera.active === false) return;
178
+ if (!this._activeEvents) return;
176
179
  this.onDown(event);
177
180
  }
178
181
 
179
- public onTouchCancel(event: TouchEvent): void {
180
- if(this._controls.camera.active === false) return;
181
- }
182
-
183
182
  public onTouchUp(event: TouchEvent): void {
184
- if(this._controls.camera.active === false) return;
183
+ if (this._controls.camera.active === false) return;
185
184
  }
186
185
 
187
- public onUp(event: MouseEvent|TouchEvent): void {
188
- if(this._controls.camera.active === false) return;
186
+ public onUp(event: MouseEvent | TouchEvent): void {
187
+ if (this._controls.camera.active === false) return;
189
188
  this._active.rotation = false;
190
189
  this._active.zoom = false;
191
190
  this._active.pan = false;
192
191
  }
193
192
 
194
193
  public onWheel(event: WheelEvent): void {
195
- if(this._controls.camera.active === false) return;
196
- if(!this._activeEvents) return;
197
- if(!this._controls.enableZoom) return;
194
+ if (this._controls.camera.active === false) return;
195
+ if (!this._activeEvents) return;
196
+ if (!this._controls.enableZoom) return;
198
197
  let delta = 0;
199
- if (event.deltaY !== undefined) {
198
+ if (event.deltaY !== undefined) {
200
199
  // WebKit / Opera / Explorer 9
201
- delta = -event.deltaY ;
200
+ delta = -event.deltaY;
202
201
  } else if (event.detail !== undefined) {
203
202
  // Firefox
204
203
  delta = -event.detail;
205
204
  }
206
205
  // convert to 2 screen coordinates that are far enough
207
- if(Math.sign(delta) > 0) {
206
+ if (Math.sign(delta) > 0) {
208
207
  this._cameraLogic.zoom(0, 0, false, false);
209
208
  this._cameraLogic.zoom(1, 0, true, false);
210
209
  } else {
@@ -221,23 +220,27 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
221
220
  };
222
221
  }
223
222
 
224
- // #endregion Public Methods (16)
223
+ // #endregion Public Methods (20)
225
224
 
226
225
  // #region Private Methods (1)
227
226
 
228
- private convertInput(event: MouseEvent|TouchEvent): {x: number, y: number} {
229
- let aspect = window.innerWidth / window.innerHeight;
227
+ private convertInput(event: MouseEvent | TouchEvent): { x: number, y: number } {
230
228
  if (event instanceof MouseEvent) {
231
229
  return {
232
- x: event.clientX / window.innerWidth * aspect,
233
- y: event.clientY / window.innerHeight
234
- }
230
+ x: event.clientX,
231
+ y: event.clientY
232
+ };
235
233
  } else {
236
- if(event.touches.length < 1) return { x: 0, y: 0 };
234
+ if (event.touches.length < 1) return { x: 0, y: 0 };
235
+ if (event.touches.length === 1)
236
+ return {
237
+ x: event.touches[0].pageX,
238
+ y: event.touches[0].pageY
239
+ };
237
240
  return {
238
- x: event.touches[0].pageX / window.innerWidth * aspect,
239
- y: event.touches[0].pageY / window.innerHeight
240
- }
241
+ x: (event.touches[0].pageX + event.touches[1].pageX) / 2,
242
+ y: (event.touches[0].pageY + event.touches[1].pageY) / 2
243
+ };
241
244
  }
242
245
  }
243
246