@shapediver/viewer.rendering-engine.camera-engine 2.12.8 → 3.0.0

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 (143) hide show
  1. package/dist/implementation/CameraEngine.d.ts +5 -7
  2. package/dist/implementation/CameraEngine.d.ts.map +1 -1
  3. package/dist/implementation/CameraEngine.js +68 -27
  4. package/dist/implementation/CameraEngine.js.map +1 -1
  5. package/dist/implementation/camera/AbstractCamera.d.ts +7 -5
  6. package/dist/implementation/camera/AbstractCamera.d.ts.map +1 -1
  7. package/dist/implementation/camera/AbstractCamera.js +15 -8
  8. package/dist/implementation/camera/AbstractCamera.js.map +1 -1
  9. package/dist/implementation/camera/OrthographicCamera.d.ts +10 -13
  10. package/dist/implementation/camera/OrthographicCamera.d.ts.map +1 -1
  11. package/dist/implementation/camera/OrthographicCamera.js +53 -52
  12. package/dist/implementation/camera/OrthographicCamera.js.map +1 -1
  13. package/dist/implementation/camera/PerspectiveCamera.d.ts +9 -12
  14. package/dist/implementation/camera/PerspectiveCamera.d.ts.map +1 -1
  15. package/dist/implementation/camera/PerspectiveCamera.js +33 -38
  16. package/dist/implementation/camera/PerspectiveCamera.js.map +1 -1
  17. package/dist/implementation/controls/AbstractCameraControls.d.ts +156 -5
  18. package/dist/implementation/controls/AbstractCameraControls.d.ts.map +1 -1
  19. package/dist/implementation/controls/AbstractCameraControls.js +260 -6
  20. package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
  21. package/dist/implementation/controls/CameraControlsEventDistribution.d.ts +38 -0
  22. package/dist/implementation/controls/CameraControlsEventDistribution.d.ts.map +1 -0
  23. package/dist/implementation/controls/{perspective/CameraControlsEventDistribution.js → CameraControlsEventDistribution.js} +71 -71
  24. package/dist/implementation/controls/CameraControlsEventDistribution.js.map +1 -0
  25. package/dist/implementation/controls/{perspective/CameraControlsLogic.d.ts → CameraControlsLogic.d.ts} +5 -5
  26. package/dist/implementation/controls/CameraControlsLogic.d.ts.map +1 -0
  27. package/dist/implementation/controls/{perspective/CameraControlsLogic.js → CameraControlsLogic.js} +74 -44
  28. package/dist/implementation/controls/CameraControlsLogic.js.map +1 -0
  29. package/dist/implementation/controls/OrthographicCameraControls.d.ts +4 -67
  30. package/dist/implementation/controls/OrthographicCameraControls.d.ts.map +1 -1
  31. package/dist/implementation/controls/OrthographicCameraControls.js +22 -90
  32. package/dist/implementation/controls/OrthographicCameraControls.js.map +1 -1
  33. package/dist/implementation/controls/PerspectiveCameraControls.d.ts +4 -151
  34. package/dist/implementation/controls/PerspectiveCameraControls.d.ts.map +1 -1
  35. package/dist/implementation/controls/PerspectiveCameraControls.js +21 -247
  36. package/dist/implementation/controls/PerspectiveCameraControls.js.map +1 -1
  37. package/dist/implementation/interpolation/CameraInterpolationManager.d.ts +3 -3
  38. package/dist/implementation/interpolation/CameraInterpolationManager.d.ts.map +1 -1
  39. package/dist/implementation/interpolation/CameraInterpolationManager.js +5 -5
  40. package/dist/implementation/interpolation/CameraInterpolationManager.js.map +1 -1
  41. package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.d.ts +3 -3
  42. package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.d.ts.map +1 -1
  43. package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.js +11 -11
  44. package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.js.map +1 -1
  45. package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.d.ts +3 -3
  46. package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.d.ts.map +1 -1
  47. package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.js +6 -6
  48. package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.js.map +1 -1
  49. package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.d.ts +4 -4
  50. package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.d.ts.map +1 -1
  51. package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js +6 -6
  52. package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js.map +1 -1
  53. package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.d.ts +3 -3
  54. package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.d.ts.map +1 -1
  55. package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.js +6 -6
  56. package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.js.map +1 -1
  57. package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.d.ts +3 -3
  58. package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.d.ts.map +1 -1
  59. package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.js +9 -9
  60. package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.js.map +1 -1
  61. package/dist/index.d.ts +6 -8
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +6 -6
  64. package/dist/index.js.map +1 -1
  65. package/dist/interfaces/ICameraEngine.d.ts +7 -7
  66. package/dist/interfaces/ICameraEngine.d.ts.map +1 -1
  67. package/dist/interfaces/ICameraEngine.js +3 -0
  68. package/dist/interfaces/ICameraEngine.js.map +1 -1
  69. package/dist/interfaces/camera/ICamera.d.ts +23 -22
  70. package/dist/interfaces/camera/ICamera.d.ts.map +1 -1
  71. package/dist/interfaces/camera/ICamera.js +1 -0
  72. package/dist/interfaces/camera/ICamera.js.map +1 -1
  73. package/dist/interfaces/camera/IOrthographicCamera.d.ts +8 -7
  74. package/dist/interfaces/camera/IOrthographicCamera.d.ts.map +1 -1
  75. package/dist/interfaces/camera/IOrthographicCamera.js +4 -0
  76. package/dist/interfaces/camera/IOrthographicCamera.js.map +1 -1
  77. package/dist/interfaces/camera/IPerspectiveCamera.d.ts +2 -2
  78. package/dist/interfaces/camera/IPerspectiveCamera.d.ts.map +1 -1
  79. package/dist/interfaces/controls/ICameraControls.d.ts +73 -2
  80. package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
  81. package/dist/interfaces/controls/ICameraControls.js +1 -0
  82. package/dist/interfaces/controls/ICameraControls.js.map +1 -1
  83. package/dist/interfaces/controls/ICameraControlsEventDistribution.d.ts +1 -1
  84. package/dist/interfaces/controls/ICameraControlsEventDistribution.d.ts.map +1 -1
  85. package/dist/interfaces/controls/ICameraControlsLogic.d.ts +4 -1
  86. package/dist/interfaces/controls/ICameraControlsLogic.d.ts.map +1 -1
  87. package/dist/interfaces/interpolation/ICameraInterpolation.d.ts +2 -2
  88. package/dist/interfaces/interpolation/ICameraInterpolation.d.ts.map +1 -1
  89. package/package.json +8 -8
  90. package/src/implementation/CameraEngine.ts +111 -70
  91. package/src/implementation/camera/AbstractCamera.ts +24 -16
  92. package/src/implementation/camera/OrthographicCamera.ts +84 -85
  93. package/src/implementation/camera/PerspectiveCamera.ts +64 -69
  94. package/src/implementation/controls/AbstractCameraControls.ts +303 -14
  95. package/src/implementation/controls/{perspective/CameraControlsEventDistribution.ts → CameraControlsEventDistribution.ts} +96 -75
  96. package/src/implementation/controls/{perspective/CameraControlsLogic.ts → CameraControlsLogic.ts} +90 -53
  97. package/src/implementation/controls/OrthographicCameraControls.ts +27 -121
  98. package/src/implementation/controls/PerspectiveCameraControls.ts +28 -294
  99. package/src/implementation/interpolation/CameraInterpolationManager.ts +40 -45
  100. package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts +19 -22
  101. package/src/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.ts +15 -16
  102. package/src/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.ts +17 -19
  103. package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts +12 -14
  104. package/src/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.ts +18 -20
  105. package/src/index.ts +18 -21
  106. package/src/interfaces/ICameraEngine.ts +24 -11
  107. package/src/interfaces/camera/ICamera.ts +45 -41
  108. package/src/interfaces/camera/IOrthographicCamera.ts +27 -9
  109. package/src/interfaces/camera/IPerspectiveCamera.ts +13 -5
  110. package/src/interfaces/controls/ICameraControls.ts +49 -6
  111. package/src/interfaces/controls/ICameraControlsEventDistribution.ts +5 -2
  112. package/src/interfaces/controls/ICameraControlsLogic.ts +6 -3
  113. package/src/interfaces/interpolation/ICameraInterpolation.ts +6 -2
  114. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts +0 -32
  115. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts.map +0 -1
  116. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js +0 -230
  117. package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js.map +0 -1
  118. package/dist/implementation/controls/orthographic/CameraControlsLogic.d.ts +0 -28
  119. package/dist/implementation/controls/orthographic/CameraControlsLogic.d.ts.map +0 -1
  120. package/dist/implementation/controls/orthographic/CameraControlsLogic.js +0 -243
  121. package/dist/implementation/controls/orthographic/CameraControlsLogic.js.map +0 -1
  122. package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts +0 -32
  123. package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts.map +0 -1
  124. package/dist/implementation/controls/perspective/CameraControlsEventDistribution.js.map +0 -1
  125. package/dist/implementation/controls/perspective/CameraControlsLogic.d.ts.map +0 -1
  126. package/dist/implementation/controls/perspective/CameraControlsLogic.js.map +0 -1
  127. package/dist/interfaces/controls/ICameraControlsUsage.d.ts +0 -22
  128. package/dist/interfaces/controls/ICameraControlsUsage.d.ts.map +0 -1
  129. package/dist/interfaces/controls/ICameraControlsUsage.js +0 -3
  130. package/dist/interfaces/controls/ICameraControlsUsage.js.map +0 -1
  131. package/dist/interfaces/controls/IOrthographicCameraControls.d.ts +0 -30
  132. package/dist/interfaces/controls/IOrthographicCameraControls.d.ts.map +0 -1
  133. package/dist/interfaces/controls/IOrthographicCameraControls.js +0 -3
  134. package/dist/interfaces/controls/IOrthographicCameraControls.js.map +0 -1
  135. package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts +0 -65
  136. package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts.map +0 -1
  137. package/dist/interfaces/controls/IPerspectiveCameraControls.js +0 -3
  138. package/dist/interfaces/controls/IPerspectiveCameraControls.js.map +0 -1
  139. package/src/implementation/controls/orthographic/CameraControlsEventDistribution.ts +0 -234
  140. package/src/implementation/controls/orthographic/CameraControlsLogic.ts +0 -271
  141. package/src/interfaces/controls/ICameraControlsUsage.ts +0 -30
  142. package/src/interfaces/controls/IOrthographicCameraControls.ts +0 -13
  143. package/src/interfaces/controls/IPerspectiveCameraControls.ts +0 -33
@@ -1,26 +1,33 @@
1
- import { CameraControlsLogic } from './CameraControlsLogic';
2
- import { ICameraControlsEventDistribution } from '../../../interfaces/controls/ICameraControlsEventDistribution';
3
- import { PerspectiveCameraControls } from '../PerspectiveCameraControls';
1
+ import { ICameraControls } from '../../interfaces/controls/ICameraControls';
2
+ import { ICameraControlsEventDistribution } from '../../interfaces/controls/ICameraControlsEventDistribution';
3
+ import { ICameraControlsLogic } from '../../interfaces/controls/ICameraControlsLogic';
4
4
 
5
5
  export class CameraControlsEventDistribution implements ICameraControlsEventDistribution {
6
- // #region Properties (2)
6
+ // #region Properties (6)
7
7
 
8
- private _active = {
8
+ protected _active = {
9
9
  rotation: false,
10
10
  zoom: false,
11
11
  pan: false
12
12
  };
13
- private _activeEvents = true;
13
+ protected _activeEvents = true;
14
+ protected _cameraLogic: ICameraControlsLogic;
15
+ protected _controls: ICameraControls;
16
+ protected _primaryPointerEvent?: PointerEvent;
17
+ protected _secondaryPointerEvent?: PointerEvent;
14
18
 
15
- // #endregion Properties (2)
19
+ // #endregion Properties (6)
16
20
 
17
21
  // #region Constructors (1)
18
22
 
19
- constructor(private readonly _controls: PerspectiveCameraControls, private readonly _cameraLogic: CameraControlsLogic) { }
23
+ constructor(controls: ICameraControls, cameraLogic: ICameraControlsLogic) {
24
+ this._controls = controls;
25
+ this._cameraLogic = cameraLogic;
26
+ }
20
27
 
21
28
  // #endregion Constructors (1)
22
29
 
23
- // #region Public Methods (20)
30
+ // #region Public Methods (16)
24
31
 
25
32
  public activateCameraEvents(): void {
26
33
  this._activeEvents = true;
@@ -31,22 +38,24 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
31
38
  this.reset();
32
39
  }
33
40
 
34
- public onDown(event: MouseEvent | TouchEvent): void {
41
+ public onDown(event: PointerEvent): void {
35
42
  if (this._controls.camera.active === false) return;
43
+
36
44
  const { x, y } = this.convertInput(event);
37
45
 
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;
46
+ const touchEvent = event.pointerType === 'touch';
47
+ const input = this.getInput(event);
48
+ const mapping = event.pointerType === 'touch' ? this._controls.input.touch : this._controls.input.mouse;
40
49
 
41
50
  if (input === mapping.rotate && this._controls.enableRotation) {
42
- this._cameraLogic.rotate(x, y, this._active.rotation, window.TouchEvent && event instanceof TouchEvent);
51
+ this._cameraLogic.rotate(x, y, this._active.rotation, touchEvent);
43
52
  this._active.rotation = true;
44
53
  } else {
45
54
  this._active.rotation = false;
46
55
  }
47
56
 
48
57
  if (input === mapping.pan && this._controls.enablePan) {
49
- this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
58
+ this._cameraLogic.pan(x, y, this._active.pan, touchEvent);
50
59
  this._active.pan = true;
51
60
  } else {
52
61
  this._active.pan = false;
@@ -54,11 +63,11 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
54
63
 
55
64
  if (input === mapping.zoom && this._controls.enableZoom) {
56
65
  let x1 = x, y1 = y;
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;
66
+ if (touchEvent && this._controls.input.touch.zoom === 2 && this._primaryPointerEvent && this._secondaryPointerEvent) {
67
+ x1 = (this._primaryPointerEvent!.pageX - this._secondaryPointerEvent!.pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
68
+ y1 = (this._primaryPointerEvent!.pageY - this._secondaryPointerEvent!.pageY) / window.innerHeight;
60
69
  }
61
- this._cameraLogic.zoom(x1, y1, this._active.zoom, window.TouchEvent && event instanceof TouchEvent);
70
+ this._cameraLogic.zoom(x1, y1, this._active.zoom, touchEvent);
62
71
  this._active.zoom = true;
63
72
  } else {
64
73
  this._active.zoom = false;
@@ -105,31 +114,7 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
105
114
  this.onKey(event);
106
115
  }
107
116
 
108
- public onMouseDown(event: MouseEvent): void {
109
- if (this._controls.camera.active === false) return;
110
- if (!this._activeEvents) return;
111
- this.onDown(event);
112
- }
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
-
120
- public onMouseMove(event: MouseEvent): void {
121
- if (this._controls.camera.active === false) return;
122
- if (!this._activeEvents) return;
123
- this.onMove(event);
124
- }
125
-
126
- public onMouseOut(event: WheelEvent): void {
127
- if (this._controls.camera.active === false) return;
128
- }
129
-
130
- public onMouseUp(event: WheelEvent): void {
131
- if (this._controls.camera.active === false) return;
132
- }
117
+ public onKeyUp(event: KeyboardEvent): void { }
133
118
 
134
119
  public onMouseWheel(event: WheelEvent): void {
135
120
  if (this._controls.camera.active === false) return;
@@ -137,53 +122,83 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
137
122
  this.onWheel(event);
138
123
  }
139
124
 
140
- public onMove(event: MouseEvent | TouchEvent): void {
125
+ public onMove(event: PointerEvent): void {
141
126
  if (this._controls.camera.active === false) return;
142
127
  const { x, y } = this.convertInput(event);
143
128
 
129
+ const touchEvent = event.pointerType === 'touch';
130
+
144
131
  if (this._controls.enableRotation && this._active.rotation)
145
- this._cameraLogic.rotate(x, y, this._active.rotation, window.TouchEvent && event instanceof TouchEvent);
132
+ this._cameraLogic.rotate(x, y, this._active.rotation, touchEvent);
146
133
 
147
134
  if (this._controls.enablePan && this._active.pan)
148
- this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
135
+ this._cameraLogic.pan(x, y, this._active.pan, touchEvent);
149
136
 
150
137
  if (this._controls.enableZoom && this._active.zoom) {
151
138
  let x1 = x, y1 = y;
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;
139
+ if (touchEvent && this._controls.input.touch.zoom === 2 && this._primaryPointerEvent && this._secondaryPointerEvent) {
140
+ x1 = (this._primaryPointerEvent!.pageX - this._secondaryPointerEvent!.pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
141
+ y1 = (this._primaryPointerEvent!.pageY - this._secondaryPointerEvent!.pageY) / window.innerHeight;
155
142
  }
156
- this._cameraLogic.zoom(x1, y1, this._active.zoom, window.TouchEvent && event instanceof TouchEvent);
143
+ this._cameraLogic.zoom(x1, y1, this._active.zoom, touchEvent);
157
144
  }
158
145
  }
159
146
 
160
- public onTouchCancel(event: TouchEvent): void {
147
+ public onPointerDown(event: PointerEvent): void {
161
148
  if (this._controls.camera.active === false) return;
149
+ if (!this._activeEvents) return;
150
+
151
+ if (event.isPrimary === true)
152
+ this._primaryPointerEvent = event;
153
+ else if (event.isPrimary === false)
154
+ this._secondaryPointerEvent = event;
155
+
156
+ this.onDown(event);
162
157
  }
163
158
 
164
- public onTouchEnd(event: TouchEvent): void {
159
+ public onPointerEnd(event: PointerEvent): void {
165
160
  if (this._controls.camera.active === false) return;
166
161
  if (!this._activeEvents) return;
162
+
163
+ if (event.isPrimary === true)
164
+ this._primaryPointerEvent = undefined;
165
+ else if (event.isPrimary === false)
166
+ this._secondaryPointerEvent = undefined;
167
+
167
168
  this.onUp(event);
168
169
  }
169
170
 
170
- public onTouchMove(event: TouchEvent): void {
171
+ public onPointerMove(event: PointerEvent): void {
171
172
  if (this._controls.camera.active === false) return;
172
173
  if (!this._activeEvents) return;
174
+
175
+ if (event.isPrimary === true)
176
+ this._primaryPointerEvent = event;
177
+ else if (event.isPrimary === false)
178
+ this._secondaryPointerEvent = event;
179
+
173
180
  this.onMove(event);
174
181
  }
175
182
 
176
- public onTouchStart(event: TouchEvent): void {
183
+ public onPointerOut(event: PointerEvent): void {
177
184
  if (this._controls.camera.active === false) return;
178
- if (!this._activeEvents) return;
179
- this.onDown(event);
185
+
186
+ if (event.isPrimary === true)
187
+ this._primaryPointerEvent = undefined;
188
+ else if (event.isPrimary === false)
189
+ this._secondaryPointerEvent = undefined;
180
190
  }
181
191
 
182
- public onTouchUp(event: TouchEvent): void {
192
+ public onPointerUp(event: PointerEvent): void {
183
193
  if (this._controls.camera.active === false) return;
194
+
195
+ if (event.isPrimary === true)
196
+ this._primaryPointerEvent = undefined;
197
+ else if (event.isPrimary === false)
198
+ this._secondaryPointerEvent = undefined;
184
199
  }
185
200
 
186
- public onUp(event: MouseEvent | TouchEvent): void {
201
+ public onUp(event: PointerEvent): void {
187
202
  if (this._controls.camera.active === false) return;
188
203
  this._active.rotation = false;
189
204
  this._active.zoom = false;
@@ -212,7 +227,7 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
212
227
  }
213
228
  }
214
229
 
215
- public reset() {
230
+ public reset(): void {
216
231
  this._active = {
217
232
  rotation: false,
218
233
  zoom: false,
@@ -220,29 +235,35 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
220
235
  };
221
236
  }
222
237
 
223
- // #endregion Public Methods (20)
238
+ // #endregion Public Methods (16)
224
239
 
225
- // #region Private Methods (1)
240
+ // #region Protected Methods (2)
226
241
 
227
- private convertInput(event: MouseEvent | TouchEvent): { x: number, y: number } {
228
- if (event instanceof MouseEvent) {
242
+ protected convertInput(event: PointerEvent): { x: number, y: number } {
243
+ if (this._primaryPointerEvent && this._secondaryPointerEvent) {
229
244
  return {
230
- x: event.clientX,
231
- y: event.clientY
245
+ x: (this._primaryPointerEvent.pageX + this._secondaryPointerEvent.pageX) / 2,
246
+ y: (this._primaryPointerEvent.pageY + this._secondaryPointerEvent.pageY) / 2
232
247
  };
233
248
  } else {
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
- };
240
249
  return {
241
- x: (event.touches[0].pageX + event.touches[1].pageX) / 2,
242
- y: (event.touches[0].pageY + event.touches[1].pageY) / 2
250
+ x: event.clientX,
251
+ y: event.clientY
243
252
  };
244
253
  }
245
254
  }
246
255
 
247
- // #endregion Private Methods (1)
248
- }
256
+ protected getInput(event: PointerEvent): number {
257
+ if (event.pointerType === 'touch') {
258
+ if (this._secondaryPointerEvent) {
259
+ return 2;
260
+ } else {
261
+ return 1;
262
+ }
263
+ } else {
264
+ return event.button;
265
+ }
266
+ }
267
+
268
+ // #endregion Protected Methods (2)
269
+ }
@@ -1,12 +1,19 @@
1
- import { mat4, quat, vec2, vec3 } from 'gl-matrix';
2
1
  import { Box, Sphere, Spherical } from '@shapediver/viewer.shared.math';
3
-
4
- import { PerspectiveCameraControls } from '../PerspectiveCameraControls';
5
- import { ICameraControlsLogic } from '../../../interfaces/controls/ICameraControlsLogic';
6
- import { PerspectiveCamera } from '../../camera/PerspectiveCamera';
2
+ import { Adjustments, ICameraControls } from '../../interfaces/controls/ICameraControls';
3
+ import { ICameraControlsLogic } from '../../interfaces/controls/ICameraControlsLogic';
4
+ import {
5
+ mat4,
6
+ quat,
7
+ vec2,
8
+ vec3
9
+ } from 'gl-matrix';
10
+ import { OrthographicCamera } from '../camera/OrthographicCamera';
11
+ import { PerspectiveCamera } from '../camera/PerspectiveCamera';
12
+ import { CAMERA_TYPE } from '../../interfaces/ICameraEngine';
13
+ import { ORTHOGRAPHIC_CAMERA_DIRECTION } from '../../interfaces/camera/IOrthographicCamera';
7
14
 
8
15
  export class CameraControlsLogic implements ICameraControlsLogic {
9
- // #region Properties (15)
16
+ // #region Properties (13)
10
17
 
11
18
  private _adjustedSettings = {
12
19
  autoRotationSpeed: () => this._controls.autoRotationSpeed * this._settingsAdjustments.autoRotationSpeed,
@@ -45,28 +52,12 @@ export class CameraControlsLogic implements ICameraControlsLogic {
45
52
  private _rotateDelta = vec2.create();
46
53
  private _rotateEnd = vec2.create();
47
54
  private _rotateStart = vec2.create();
48
- private _settingsAdjustments = {
49
- autoRotationSpeed: 2 * Math.PI / 60 / 60,
50
- damping: 1.0,
51
- movementSmoothness: 1.0,
52
- panSpeed: 1.75,
53
- rotationSpeed: Math.PI,
54
- zoomSpeed: 0.025,
55
- };
56
- private _touchAdjustments = {
57
- autoRotationSpeed: 1.0,
58
- damping: 1.0,
59
- movementSmoothness: 1.0,
60
- panSpeed: 1.0 / 1.75,
61
- rotationSpeed: 1.5,
62
- zoomSpeed: 100.0,
63
- };
64
55
 
65
- // #endregion Properties (15)
56
+ // #endregion Properties (13)
66
57
 
67
58
  // #region Constructors (1)
68
59
 
69
- constructor(private readonly _controls: PerspectiveCameraControls) {
60
+ constructor(private readonly _controls: ICameraControls, private readonly _settingsAdjustments: Adjustments, private readonly _touchAdjustments: Adjustments) {
70
61
  this._quat = quat.fromValues(-Math.sin(Math.PI / 4), 0, 0, Math.sin(Math.PI / 4));
71
62
  this._quatInverse = quat.fromValues(Math.sin(Math.PI / 4), 0, 0, Math.sin(Math.PI / 4));
72
63
  }
@@ -112,7 +103,6 @@ export class CameraControlsLogic implements ICameraControlsLogic {
112
103
  }
113
104
 
114
105
  public pan(x: number, y: number, active: boolean, touch: boolean): void {
115
-
116
106
  if (!active) {
117
107
  this._panStart = vec2.fromValues(x, y);
118
108
  } else {
@@ -226,7 +216,8 @@ export class CameraControlsLogic implements ICameraControlsLogic {
226
216
  minPolarAngle !== 0 ||
227
217
  maxPolarAngle !== 180 ||
228
218
  this._controls.enableAzimuthRotation === false ||
229
- this._controls.enablePolarRotation === false
219
+ this._controls.enablePolarRotation === false ||
220
+ this._controls.enableObjectControls === true
230
221
  ) {
231
222
  let offset = vec3.subtract(vec3.create(), position, target);
232
223
  vec3.transformQuat(offset, offset, this._quat);
@@ -238,18 +229,24 @@ export class CameraControlsLogic implements ICameraControlsLogic {
238
229
  spherical.phi < minPolarAngle ||
239
230
  spherical.phi > maxPolarAngle ||
240
231
  this._controls.enableAzimuthRotation === false ||
241
- this._controls.enablePolarRotation === false
232
+ this._controls.enablePolarRotation === false ||
233
+ this._controls.enableObjectControls === true
242
234
  ) {
243
235
  spherical.theta = Math.max(minAzimuthAngle, Math.min(maxAzimuthAngle, spherical.theta));
244
236
  spherical.phi = Math.max(minPolarAngle, Math.min(maxPolarAngle, spherical.phi));
245
237
 
246
- if (this._controls.enableAzimuthRotation === false || this._controls.enablePolarRotation === false) {
238
+ if (this._controls.enableAzimuthRotation === false || this._controls.enablePolarRotation === false || this._controls.enableObjectControls === true) {
247
239
  const defaultOffset = vec3.subtract(vec3.create(), this._controls.camera.defaultPosition, this._controls.camera.defaultTarget);
248
240
  vec3.transformQuat(defaultOffset, defaultOffset, this._quat);
249
241
 
250
242
  const defaultSpherical = new Spherical().fromVec3(defaultOffset);
251
243
  if (this._controls.enableAzimuthRotation === false) spherical.theta = defaultSpherical.theta;
252
244
  if (this._controls.enablePolarRotation === false) spherical.phi = defaultSpherical.phi;
245
+
246
+ if(this._controls.enableObjectControls) {
247
+ spherical.theta = defaultSpherical.theta;
248
+ spherical.phi = defaultSpherical.phi;
249
+ }
253
250
  }
254
251
 
255
252
  spherical.makeSafe();
@@ -258,12 +255,14 @@ export class CameraControlsLogic implements ICameraControlsLogic {
258
255
  vec3.add(position, offset, target);
259
256
  }
260
257
 
261
- if (sceneRotation[1] < minAzimuthAngle ||
258
+ if ((sceneRotation[1] < minAzimuthAngle ||
262
259
  sceneRotation[1] > maxAzimuthAngle ||
263
260
  sceneRotation[0] < minPolarAngle ||
264
261
  sceneRotation[0] > maxPolarAngle ||
265
262
  this._controls.enableAzimuthRotation === false ||
266
- this._controls.enablePolarRotation === false) {
263
+ this._controls.enablePolarRotation === false) &&
264
+ this._controls.enableObjectControls === false
265
+ ) {
267
266
  sceneRotation[1] = this._controls.enableAzimuthRotation === false ? 0 : Math.max(minAzimuthAngle, Math.min(maxAzimuthAngle, sceneRotation[1]));
268
267
  sceneRotation[0] = this._controls.enablePolarRotation === false ? 0 : Math.max(minPolarAngle, Math.min(maxPolarAngle, sceneRotation[0]));
269
268
  }
@@ -273,6 +272,7 @@ export class CameraControlsLogic implements ICameraControlsLogic {
273
272
  }
274
273
 
275
274
  public rotate(x: number, y: number, active: boolean, touch: boolean): void {
275
+ if (this._controls.camera.type === CAMERA_TYPE.ORTHOGRAPHIC && (this._controls.camera as OrthographicCamera).direction !== ORTHOGRAPHIC_CAMERA_DIRECTION.CUSTOM) return;
276
276
 
277
277
  if (!active) {
278
278
  this._rotateStart = vec2.fromValues(x, y);
@@ -297,7 +297,11 @@ export class CameraControlsLogic implements ICameraControlsLogic {
297
297
  spherical.phi += phiDelta * this._adjustedSettings.movementSmoothness();
298
298
  }
299
299
 
300
- const offset = this.rotationSphericalToOffset(this._controls.enableTurntableControls ? new Spherical(1.0, spherical.phi, 0) : spherical);
300
+ let sphericalForOffset = spherical;
301
+ if(this._controls.enableTurntableControls)
302
+ sphericalForOffset = new Spherical(1.0, spherical.phi, 0);
303
+
304
+ const offset = this.rotationSphericalToOffset(sphericalForOffset);
301
305
 
302
306
  const damping = 1 - Math.max(0.01, Math.min(1, this._adjustedSettings.damping()));
303
307
  const framesTheta = (Math.log(1 / Math.abs(spherical.theta)) - 5 * Math.log(10)) / (Math.log(damping));
@@ -312,7 +316,9 @@ export class CameraControlsLogic implements ICameraControlsLogic {
312
316
  this._damping.zoom.duration = 0;
313
317
 
314
318
  this._controls.applyPositionVector(offset, true);
319
+
315
320
  if (this._controls.enableTurntableControls) this._controls.applyRotation([0, spherical.theta], true);
321
+ if (this._controls.enableObjectControls) this._controls.applyRotation([spherical.phi, spherical.theta], true);
316
322
  }
317
323
  }
318
324
 
@@ -353,9 +359,16 @@ export class CameraControlsLogic implements ICameraControlsLogic {
353
359
  const spherical = new Spherical();
354
360
  spherical.theta = this._damping.rotation.theta * Math.pow(damping, frameSinceStart);
355
361
  spherical.phi = this._damping.rotation.phi * Math.pow(damping, frameSinceStart);
356
- const offset = this.rotationSphericalToOffset(this._controls.enableTurntableControls ? new Spherical(1.0, spherical.phi, 0) : spherical);
362
+
363
+ let sphericalForOffset = spherical;
364
+ if(this._controls.enableTurntableControls)
365
+ sphericalForOffset = new Spherical(1.0, spherical.phi, 0);
366
+
367
+ const offset = this.rotationSphericalToOffset(sphericalForOffset);
357
368
  this._controls.applyPositionVector(offset);
369
+
358
370
  if (this._controls.enableTurntableControls) this._controls.applyRotation([0, spherical.theta]);
371
+ if (this._controls.enableObjectControls) this._controls.applyRotation([spherical.phi, spherical.theta]);
359
372
  }
360
373
  } else {
361
374
  this._damping.rotation.time = 0;
@@ -379,9 +392,15 @@ export class CameraControlsLogic implements ICameraControlsLogic {
379
392
 
380
393
  if (this._controls.enableAutoRotation) {
381
394
  const spherical = new Spherical(1.0, 0.0, -this._adjustedSettings.autoRotationSpeed());
382
- const offset = this.rotationSphericalToOffset(this._controls.enableTurntableControls ? new Spherical(1.0, spherical.phi, 0) : spherical);
395
+
396
+ let sphericalForOffset = spherical;
397
+ if(this._controls.enableTurntableControls)
398
+ sphericalForOffset = new Spherical(1.0, spherical.phi, 0);
399
+ const offset = this.rotationSphericalToOffset(sphericalForOffset);
400
+
383
401
  this._controls.applyPositionVector(offset);
384
402
  if (this._controls.enableTurntableControls) this._controls.applyRotation([0, spherical.theta]);
403
+ if (this._controls.enableObjectControls) this._controls.applyRotation([spherical.phi, spherical.theta]);
385
404
  }
386
405
  }
387
406
 
@@ -426,31 +445,49 @@ export class CameraControlsLogic implements ICameraControlsLogic {
426
445
  private panDeltaToOffset(panDelta: vec2): vec3 {
427
446
  const offset = vec3.create();
428
447
  const panOffset = vec3.create();
429
-
448
+
430
449
  if (!this._controls.canvas) return offset;
431
450
  if (this._controls.canvas.clientWidth == 0 || this._controls.canvas.clientHeight == 0) return offset;
432
451
 
433
452
  // perspective
434
453
  vec3.subtract(offset, this._controls.getPositionWithManualUpdates(), this._controls.getTargetWithManualUpdates());
435
- let targetDistance = vec3.length(offset);
436
-
437
- // half of the fov is center to top of screen
438
- targetDistance *= Math.tan((((<PerspectiveCamera>this._controls.camera).fov / 2) * Math.PI) / 180.0);
439
-
440
- // we use only clientHeight here so aspect ratio does not distort speed
441
- // left
442
- const mat = mat4.targetTo(mat4.create(), this._controls.camera.position, this._controls.camera.target, vec3.fromValues(0, 0, 1));
443
-
444
- const v1 = vec3.fromValues(mat[0], mat[1], mat[2]);
445
- const scalar1 = -(2 * panDelta[0] * targetDistance / this._controls.canvas?.clientHeight);
446
- vec3.multiply(v1, v1, vec3.fromValues(scalar1, scalar1, scalar1));
447
- vec3.add(panOffset, panOffset, v1);
448
-
449
- // // up
450
- const v2 = vec3.fromValues(mat[4], mat[5], mat[6]);
451
- const scalar2 = 2 * panDelta[1] * targetDistance / this._controls.canvas?.clientHeight;
452
- vec3.multiply(v2, v2, vec3.fromValues(scalar2, scalar2, scalar2));
453
- vec3.add(panOffset, panOffset, v2);
454
+ if(this._controls.camera instanceof OrthographicCamera) {
455
+ const orthographicCamera: OrthographicCamera = <OrthographicCamera>this._controls.camera;
456
+ const mat = mat4.targetTo(mat4.create(), orthographicCamera.position, orthographicCamera.target, orthographicCamera.up);
457
+
458
+ // // we use only clientHeight here so aspect ratio does not distort speed
459
+ // // left
460
+ const v1 = vec3.fromValues(mat[0], mat[1], mat[2]);
461
+ const scalar1 = -(panDelta[0] * (orthographicCamera.right - orthographicCamera.left) * 0.5 / this._controls.canvas?.clientHeight /** orthographicCamera.zoom */);
462
+ vec3.multiply(v1, v1, vec3.fromValues(scalar1, scalar1, scalar1));
463
+ vec3.add(panOffset, panOffset, v1);
464
+
465
+ // // up
466
+ const v2 = vec3.fromValues(mat[4], mat[5], mat[6]);
467
+ const scalar2 = panDelta[1] * (orthographicCamera.right - orthographicCamera.left) * 0.5 / this._controls.canvas?.clientHeight /** orthographicCamera.zoom */;
468
+ vec3.multiply(v2, v2, vec3.fromValues(scalar2, scalar2, scalar2));
469
+ vec3.add(panOffset, panOffset, v2);
470
+ } else {
471
+ let targetDistance = vec3.length(offset);
472
+
473
+ // half of the fov is center to top of screen
474
+ targetDistance *= Math.tan((((<PerspectiveCamera>this._controls.camera).fov / 2) * Math.PI) / 180.0);
475
+
476
+ // we use only clientHeight here so aspect ratio does not distort speed
477
+ // left
478
+ const mat = mat4.targetTo(mat4.create(), this._controls.camera.position, this._controls.camera.target, vec3.fromValues(0, 0, 1));
479
+
480
+ const v1 = vec3.fromValues(mat[0], mat[1], mat[2]);
481
+ const scalar1 = -(2 * panDelta[0] * targetDistance / this._controls.canvas?.clientHeight);
482
+ vec3.multiply(v1, v1, vec3.fromValues(scalar1, scalar1, scalar1));
483
+ vec3.add(panOffset, panOffset, v1);
484
+
485
+ // // up
486
+ const v2 = vec3.fromValues(mat[4], mat[5], mat[6]);
487
+ const scalar2 = 2 * panDelta[1] * targetDistance / this._controls.canvas?.clientHeight;
488
+ vec3.multiply(v2, v2, vec3.fromValues(scalar2, scalar2, scalar2));
489
+ vec3.add(panOffset, panOffset, v2);
490
+ }
454
491
 
455
492
  return vec3.clone(panOffset);
456
493
  }