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