@shapediver/viewer.rendering-engine.camera-engine 3.3.4 → 3.3.7
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.
- package/package.json +9 -10
- package/src/implementation/CameraEngine.ts +0 -386
- package/src/implementation/camera/AbstractCamera.ts +0 -324
- package/src/implementation/camera/OrthographicCamera.ts +0 -282
- package/src/implementation/camera/PerspectiveCamera.ts +0 -250
- package/src/implementation/controls/AbstractCameraControls.ts +0 -660
- package/src/implementation/controls/CameraControlsEventDistribution.ts +0 -289
- package/src/implementation/controls/CameraControlsLogic.ts +0 -534
- package/src/implementation/controls/OrthographicCameraControls.ts +0 -36
- package/src/implementation/controls/PerspectiveCameraControls.ts +0 -37
- package/src/implementation/interpolation/CameraInterpolationManager.ts +0 -149
- package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts +0 -83
- package/src/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.ts +0 -41
- package/src/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.ts +0 -61
- package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts +0 -41
- package/src/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.ts +0 -65
- package/src/index.ts +0 -28
- package/src/interfaces/ICameraEngine.ts +0 -33
- package/src/interfaces/camera/ICamera.ts +0 -88
- package/src/interfaces/camera/IOrthographicCamera.ts +0 -36
- package/src/interfaces/camera/IPerspectiveCamera.ts +0 -18
- package/src/interfaces/controls/ICameraControls.ts +0 -80
- package/src/interfaces/controls/ICameraControlsEventDistribution.ts +0 -11
- package/src/interfaces/controls/ICameraControlsLogic.ts +0 -15
- package/src/interfaces/interpolation/ICameraInterpolation.ts +0 -9
- package/tsconfig.json +0 -17
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { ICameraControls } from '../../interfaces/controls/ICameraControls';
|
|
2
|
-
import { ICameraControlsEventDistribution } from '../../interfaces/controls/ICameraControlsEventDistribution';
|
|
3
|
-
import { ICameraControlsLogic } from '../../interfaces/controls/ICameraControlsLogic';
|
|
4
|
-
|
|
5
|
-
export class CameraControlsEventDistribution implements ICameraControlsEventDistribution {
|
|
6
|
-
// #region Properties (7)
|
|
7
|
-
|
|
8
|
-
private _zoomResizeTimeout: NodeJS.Timeout | undefined;
|
|
9
|
-
|
|
10
|
-
protected _active = {
|
|
11
|
-
rotation: false,
|
|
12
|
-
zoom: false,
|
|
13
|
-
pan: false
|
|
14
|
-
};
|
|
15
|
-
protected _activeEvents = true;
|
|
16
|
-
protected _cameraLogic: ICameraControlsLogic;
|
|
17
|
-
protected _controls: ICameraControls;
|
|
18
|
-
protected _primaryPointerEvent?: PointerEvent;
|
|
19
|
-
protected _secondaryPointerEvent?: PointerEvent;
|
|
20
|
-
|
|
21
|
-
// #endregion Properties (7)
|
|
22
|
-
|
|
23
|
-
// #region Constructors (1)
|
|
24
|
-
|
|
25
|
-
constructor(controls: ICameraControls, cameraLogic: ICameraControlsLogic) {
|
|
26
|
-
this._controls = controls;
|
|
27
|
-
this._cameraLogic = cameraLogic;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// #endregion Constructors (1)
|
|
31
|
-
|
|
32
|
-
// #region Public Methods (16)
|
|
33
|
-
|
|
34
|
-
public activateCameraEvents(): void {
|
|
35
|
-
this._activeEvents = true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public deactivateCameraEvents(): void {
|
|
39
|
-
this._activeEvents = false;
|
|
40
|
-
this.reset();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public onDown(event: PointerEvent): void {
|
|
44
|
-
if (this._controls.camera.active === false) return;
|
|
45
|
-
|
|
46
|
-
const { x, y } = this.convertInput(event);
|
|
47
|
-
|
|
48
|
-
const touchEvent = event.pointerType === 'touch';
|
|
49
|
-
const input = this.getInput(event);
|
|
50
|
-
const mapping = event.pointerType === 'touch' ? this._controls.input.touch : this._controls.input.mouse;
|
|
51
|
-
|
|
52
|
-
if (input === mapping.rotate && this._controls.enableRotation) {
|
|
53
|
-
this._cameraLogic.rotate(x, y, this._active.rotation, touchEvent);
|
|
54
|
-
this._active.rotation = true;
|
|
55
|
-
} else {
|
|
56
|
-
this._active.rotation = false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (input === mapping.pan && this._controls.enablePan) {
|
|
60
|
-
this._cameraLogic.pan(x, y, this._active.pan, touchEvent);
|
|
61
|
-
this._active.pan = true;
|
|
62
|
-
} else {
|
|
63
|
-
this._active.pan = false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (input === mapping.zoom && this._controls.enableZoom) {
|
|
67
|
-
let x1 = x, y1 = y;
|
|
68
|
-
if (touchEvent && this._controls.input.touch.zoom === 2 && this._primaryPointerEvent && this._secondaryPointerEvent) {
|
|
69
|
-
x1 = (this._primaryPointerEvent!.pageX - this._secondaryPointerEvent!.pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
|
|
70
|
-
y1 = (this._primaryPointerEvent!.pageY - this._secondaryPointerEvent!.pageY) / window.innerHeight;
|
|
71
|
-
}
|
|
72
|
-
this._cameraLogic.zoom(x1, y1, this._active.zoom, touchEvent);
|
|
73
|
-
this._active.zoom = true;
|
|
74
|
-
} else {
|
|
75
|
-
this._active.zoom = false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public onKey(event: KeyboardEvent): void {
|
|
80
|
-
if (this._controls.camera.active === false) return;
|
|
81
|
-
if (!this._controls.enableKeyPan) return;
|
|
82
|
-
switch (event.keyCode) {
|
|
83
|
-
case this._controls.input.keys.up:
|
|
84
|
-
this._cameraLogic.pan(0, 0, false, false);
|
|
85
|
-
this._cameraLogic.pan(0, this._controls.keyPanSpeed * 0.05, true, false);
|
|
86
|
-
event.preventDefault();
|
|
87
|
-
event.stopPropagation();
|
|
88
|
-
break;
|
|
89
|
-
|
|
90
|
-
case this._controls.input.keys.down:
|
|
91
|
-
this._cameraLogic.pan(0, 0, false, false);
|
|
92
|
-
this._cameraLogic.pan(0, -this._controls.keyPanSpeed * 0.05, true, false);
|
|
93
|
-
event.preventDefault();
|
|
94
|
-
event.stopPropagation();
|
|
95
|
-
break;
|
|
96
|
-
|
|
97
|
-
case this._controls.input.keys.left:
|
|
98
|
-
this._cameraLogic.pan(0, 0, false, false);
|
|
99
|
-
this._cameraLogic.pan(this._controls.keyPanSpeed * 0.05, 0, true, false);
|
|
100
|
-
event.preventDefault();
|
|
101
|
-
event.stopPropagation();
|
|
102
|
-
break;
|
|
103
|
-
|
|
104
|
-
case this._controls.input.keys.right:
|
|
105
|
-
this._cameraLogic.pan(0, 0, false, false);
|
|
106
|
-
this._cameraLogic.pan(-this._controls.keyPanSpeed * 0.05, 0, true, false);
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
event.stopPropagation();
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
public onKeyDown(event: KeyboardEvent): void {
|
|
114
|
-
if (this._controls.camera.active === false) return;
|
|
115
|
-
if (!this._activeEvents) return;
|
|
116
|
-
this.onKey(event);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public onKeyUp(event: KeyboardEvent): void { }
|
|
120
|
-
|
|
121
|
-
public onMouseWheel(event: WheelEvent): void {
|
|
122
|
-
if (this._controls.camera.active === false) return;
|
|
123
|
-
if (!this._activeEvents) return;
|
|
124
|
-
this.onWheel(event);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public onMove(event: PointerEvent): void {
|
|
128
|
-
if (this._controls.camera.active === false) return;
|
|
129
|
-
const { x, y } = this.convertInput(event);
|
|
130
|
-
|
|
131
|
-
const touchEvent = event.pointerType === 'touch';
|
|
132
|
-
|
|
133
|
-
if (this._controls.enableRotation && this._active.rotation)
|
|
134
|
-
this._cameraLogic.rotate(x, y, this._active.rotation, touchEvent);
|
|
135
|
-
|
|
136
|
-
if (this._controls.enablePan && this._active.pan)
|
|
137
|
-
this._cameraLogic.pan(x, y, this._active.pan, touchEvent);
|
|
138
|
-
|
|
139
|
-
if (this._controls.enableZoom && this._active.zoom) {
|
|
140
|
-
let x1 = x, y1 = y;
|
|
141
|
-
if (touchEvent && this._controls.input.touch.zoom === 2 && this._primaryPointerEvent && this._secondaryPointerEvent) {
|
|
142
|
-
x1 = (this._primaryPointerEvent!.pageX - this._secondaryPointerEvent!.pageX) / window.innerWidth * (window.innerWidth / window.innerHeight);
|
|
143
|
-
y1 = (this._primaryPointerEvent!.pageY - this._secondaryPointerEvent!.pageY) / window.innerHeight;
|
|
144
|
-
}
|
|
145
|
-
this._cameraLogic.zoom(x1, y1, this._active.zoom, touchEvent);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public onPointerDown(event: PointerEvent): void {
|
|
150
|
-
if (this._controls.camera.active === false) return;
|
|
151
|
-
if (!this._activeEvents) return;
|
|
152
|
-
|
|
153
|
-
if (event.isPrimary === true)
|
|
154
|
-
this._primaryPointerEvent = event;
|
|
155
|
-
else if (event.isPrimary === false)
|
|
156
|
-
this._secondaryPointerEvent = event;
|
|
157
|
-
|
|
158
|
-
this.onDown(event);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public onPointerEnd(event: PointerEvent): void {
|
|
162
|
-
if (this._controls.camera.active === false) return;
|
|
163
|
-
if (!this._activeEvents) return;
|
|
164
|
-
|
|
165
|
-
if (event.isPrimary === true)
|
|
166
|
-
this._primaryPointerEvent = undefined;
|
|
167
|
-
else if (event.isPrimary === false)
|
|
168
|
-
this._secondaryPointerEvent = undefined;
|
|
169
|
-
|
|
170
|
-
this.onUp(event);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
public onPointerMove(event: PointerEvent): void {
|
|
174
|
-
if (this._controls.camera.active === false) return;
|
|
175
|
-
if (!this._activeEvents) return;
|
|
176
|
-
|
|
177
|
-
if (event.isPrimary === true)
|
|
178
|
-
this._primaryPointerEvent = event;
|
|
179
|
-
else if (event.isPrimary === false)
|
|
180
|
-
this._secondaryPointerEvent = event;
|
|
181
|
-
|
|
182
|
-
this.onMove(event);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
public onPointerOut(event: PointerEvent): void {
|
|
186
|
-
if (this._controls.camera.active === false) return;
|
|
187
|
-
this.revert();
|
|
188
|
-
|
|
189
|
-
if (event.isPrimary === true)
|
|
190
|
-
this._primaryPointerEvent = undefined;
|
|
191
|
-
else if (event.isPrimary === false)
|
|
192
|
-
this._secondaryPointerEvent = undefined;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
public onPointerUp(event: PointerEvent): void {
|
|
196
|
-
if (this._controls.camera.active === false) return;
|
|
197
|
-
|
|
198
|
-
if (event.isPrimary === true)
|
|
199
|
-
this._primaryPointerEvent = undefined;
|
|
200
|
-
else if (event.isPrimary === false)
|
|
201
|
-
this._secondaryPointerEvent = undefined;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public onUp(event: PointerEvent): void {
|
|
205
|
-
if (this._controls.camera.active === false) return;
|
|
206
|
-
this.revert();
|
|
207
|
-
this._active.rotation = false;
|
|
208
|
-
this._active.zoom = false;
|
|
209
|
-
this._active.pan = false;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
public onWheel(event: WheelEvent): void {
|
|
213
|
-
if (this._controls.camera.active === false) return;
|
|
214
|
-
if (!this._activeEvents) return;
|
|
215
|
-
if (!this._controls.enableZoom) return;
|
|
216
|
-
|
|
217
|
-
if(this._controls.camera.revertAtMouseUp === true) {
|
|
218
|
-
clearTimeout(this._zoomResizeTimeout);
|
|
219
|
-
this._zoomResizeTimeout = setTimeout(this.revert.bind(this), 300);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
let delta = 0;
|
|
223
|
-
if (event.deltaY !== undefined) {
|
|
224
|
-
// WebKit / Opera / Explorer 9
|
|
225
|
-
delta = -event.deltaY;
|
|
226
|
-
} else if (event.detail !== undefined) {
|
|
227
|
-
// Firefox
|
|
228
|
-
delta = -event.detail;
|
|
229
|
-
}
|
|
230
|
-
// convert to 2 screen coordinates that are far enough
|
|
231
|
-
if (Math.sign(delta) > 0) {
|
|
232
|
-
this._cameraLogic.zoom(0, 0, false, false);
|
|
233
|
-
this._cameraLogic.zoom(1, 0, true, false);
|
|
234
|
-
} else {
|
|
235
|
-
this._cameraLogic.zoom(1, 0, false, false);
|
|
236
|
-
this._cameraLogic.zoom(0, 0, true, false);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
public reset(): void {
|
|
241
|
-
this._active = {
|
|
242
|
-
rotation: false,
|
|
243
|
-
zoom: false,
|
|
244
|
-
pan: false
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// #endregion Public Methods (16)
|
|
249
|
-
|
|
250
|
-
// #region Protected Methods (2)
|
|
251
|
-
|
|
252
|
-
protected convertInput(event: PointerEvent): { x: number, y: number } {
|
|
253
|
-
if (this._primaryPointerEvent && this._secondaryPointerEvent) {
|
|
254
|
-
return {
|
|
255
|
-
x: (this._primaryPointerEvent.pageX + this._secondaryPointerEvent.pageX) / 2,
|
|
256
|
-
y: (this._primaryPointerEvent.pageY + this._secondaryPointerEvent.pageY) / 2
|
|
257
|
-
};
|
|
258
|
-
} else {
|
|
259
|
-
return {
|
|
260
|
-
x: event.clientX,
|
|
261
|
-
y: event.clientY
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
protected getInput(event: PointerEvent): number {
|
|
267
|
-
if (event.pointerType === 'touch') {
|
|
268
|
-
if (this._secondaryPointerEvent) {
|
|
269
|
-
return 2;
|
|
270
|
-
} else {
|
|
271
|
-
return 1;
|
|
272
|
-
}
|
|
273
|
-
} else {
|
|
274
|
-
return event.button;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// #endregion Protected Methods (2)
|
|
279
|
-
|
|
280
|
-
// #region Private Methods (1)
|
|
281
|
-
|
|
282
|
-
private revert() {
|
|
283
|
-
if(this._controls.camera.revertAtMouseUp === true) {
|
|
284
|
-
this._controls.camera.reset({ duration: this._controls.camera.revertAtMouseUpDuration });
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// #endregion Private Methods (1)
|
|
289
|
-
}
|