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