@shapediver/viewer.rendering-engine.camera-engine 2.11.0 → 2.12.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.
- package/dist/implementation/camera/AbstractCamera.d.ts +5 -3
- package/dist/implementation/camera/AbstractCamera.d.ts.map +1 -1
- package/dist/implementation/camera/AbstractCamera.js +26 -18
- package/dist/implementation/camera/AbstractCamera.js.map +1 -1
- package/dist/implementation/controls/AbstractCameraControls.d.ts +13 -7
- package/dist/implementation/controls/AbstractCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/AbstractCameraControls.js +71 -38
- package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
- package/dist/implementation/controls/OrthographicCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/OrthographicCameraControls.js +2 -2
- package/dist/implementation/controls/OrthographicCameraControls.js.map +1 -1
- package/dist/implementation/controls/PerspectiveCameraControls.d.ts +15 -3
- package/dist/implementation/controls/PerspectiveCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/PerspectiveCameraControls.js +108 -78
- package/dist/implementation/controls/PerspectiveCameraControls.js.map +1 -1
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts +3 -3
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts.map +1 -1
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js +31 -23
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js.map +1 -1
- package/dist/implementation/controls/orthographic/CameraControlsLogic.d.ts.map +1 -1
- package/dist/implementation/controls/orthographic/CameraControlsLogic.js +36 -38
- package/dist/implementation/controls/orthographic/CameraControlsLogic.js.map +1 -1
- package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts +4 -4
- package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts.map +1 -1
- package/dist/implementation/controls/perspective/CameraControlsEventDistribution.js +39 -32
- package/dist/implementation/controls/perspective/CameraControlsEventDistribution.js.map +1 -1
- package/dist/implementation/controls/perspective/CameraControlsLogic.d.ts +3 -2
- package/dist/implementation/controls/perspective/CameraControlsLogic.d.ts.map +1 -1
- package/dist/implementation/controls/perspective/CameraControlsLogic.js +88 -66
- package/dist/implementation/controls/perspective/CameraControlsLogic.js.map +1 -1
- package/dist/interfaces/camera/ICamera.d.ts +9 -8
- package/dist/interfaces/camera/ICamera.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControls.d.ts +4 -3
- package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControlsLogic.d.ts +3 -2
- package/dist/interfaces/controls/ICameraControlsLogic.d.ts.map +1 -1
- package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts +4 -0
- package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/implementation/camera/AbstractCamera.ts +44 -37
- package/src/implementation/controls/AbstractCameraControls.ts +113 -70
- package/src/implementation/controls/OrthographicCameraControls.ts +9 -9
- package/src/implementation/controls/PerspectiveCameraControls.ts +114 -73
- package/src/implementation/controls/orthographic/CameraControlsEventDistribution.ts +61 -56
- package/src/implementation/controls/orthographic/CameraControlsLogic.ts +45 -53
- package/src/implementation/controls/perspective/CameraControlsEventDistribution.ts +83 -80
- package/src/implementation/controls/perspective/CameraControlsLogic.ts +100 -81
- package/src/interfaces/camera/ICamera.ts +31 -26
- package/src/interfaces/controls/ICameraControls.ts +5 -5
- package/src/interfaces/controls/ICameraControlsLogic.ts +6 -2
- package/src/interfaces/controls/IPerspectiveCameraControls.ts +10 -2
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import { IOrbitControlsSettingsV3 } from '@shapediver/viewer.settings'
|
|
2
|
-
import { SettingsEngine, StateEngine, Converter } from '@shapediver/viewer.shared.services'
|
|
3
|
-
import { vec3 } from 'gl-matrix'
|
|
1
|
+
import { IOrbitControlsSettingsV3 } from '@shapediver/viewer.settings';
|
|
2
|
+
import { SettingsEngine, StateEngine, Converter } from '@shapediver/viewer.shared.services';
|
|
3
|
+
import { vec3 } from 'gl-matrix';
|
|
4
4
|
|
|
5
|
-
import { CAMERA_TYPE, ICamera } from '../..'
|
|
6
|
-
import { IPerspectiveCameraControls } from '../../interfaces/controls/IPerspectiveCameraControls'
|
|
7
|
-
import { AbstractCameraControls } from './AbstractCameraControls'
|
|
5
|
+
import { CAMERA_TYPE, ICamera } from '../..';
|
|
6
|
+
import { IPerspectiveCameraControls } from '../../interfaces/controls/IPerspectiveCameraControls';
|
|
7
|
+
import { AbstractCameraControls } from './AbstractCameraControls';
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
} from './perspective/CameraControlsEventDistribution'
|
|
11
|
-
import { CameraControlsLogic as OrbitCameraControlsLogic } from './perspective/CameraControlsLogic'
|
|
9
|
+
CameraControlsEventDistribution as OrbitCameraControlsEventDistribution,
|
|
10
|
+
} from './perspective/CameraControlsEventDistribution';
|
|
11
|
+
import { CameraControlsLogic as OrbitCameraControlsLogic } from './perspective/CameraControlsLogic';
|
|
12
12
|
|
|
13
13
|
export class PerspectiveCameraControls extends AbstractCameraControls implements IPerspectiveCameraControls {
|
|
14
|
-
// #region Properties (
|
|
14
|
+
// #region Properties (25)
|
|
15
|
+
|
|
16
|
+
private readonly _converter: Converter = Converter.instance;
|
|
17
|
+
private readonly _stateEngine: StateEngine = StateEngine.instance;
|
|
15
18
|
|
|
16
19
|
private _autoRotationSpeed: number = 0;
|
|
17
20
|
private _cubePositionRestriction: { min: vec3, max: vec3 } = { min: vec3.fromValues(-Infinity, -Infinity, -Infinity), max: vec3.fromValues(Infinity, Infinity, Infinity) };
|
|
18
21
|
private _cubeTargetRestriction: { min: vec3, max: vec3 } = { min: vec3.fromValues(-Infinity, -Infinity, -Infinity), max: vec3.fromValues(Infinity, Infinity, Infinity) };
|
|
19
22
|
private _damping: number = 0.1;
|
|
20
23
|
private _enableAutoRotation: boolean = false;
|
|
24
|
+
private _enableAzimuthRotation: boolean = true;
|
|
21
25
|
private _enableKeyPan: boolean = false;
|
|
22
26
|
private _enablePan: boolean = true;
|
|
27
|
+
private _enablePolarRotation: boolean = true;
|
|
23
28
|
private _enableRotation: boolean = true;
|
|
29
|
+
private _enableTurntableControls: boolean = false;
|
|
24
30
|
private _enableZoom: boolean = true;
|
|
25
|
-
private _input: { keys: { up: number, down: number, left: number, right: number }, mouse: { rotate: number, zoom: number, pan: number }, touch: { rotate: number, zoom: number, pan: number } } = { keys: { up: 38, down: 40, left: 37, right: 39 }, mouse: { rotate: 0, zoom: 1, pan: 2 }, touch: { rotate: 1, zoom: 2, pan:
|
|
31
|
+
private _input: { keys: { up: number, down: number, left: number, right: number }, mouse: { rotate: number, zoom: number, pan: number }, touch: { rotate: number, zoom: number, pan: number } } = { keys: { up: 38, down: 40, left: 37, right: 39 }, mouse: { rotate: 0, zoom: 1, pan: 2 }, touch: { rotate: 1, zoom: 2, pan: 2 }, };
|
|
26
32
|
private _keyPanSpeed: number = 0.5;
|
|
27
33
|
private _movementSmoothness: number = 0.5;
|
|
28
34
|
private _panSpeed: number = 0.5;
|
|
@@ -30,12 +36,11 @@ export class PerspectiveCameraControls extends AbstractCameraControls implements
|
|
|
30
36
|
private _rotationSpeed: number = 0.5;
|
|
31
37
|
private _spherePositionRestriction: { center: vec3, radius: number } = { center: vec3.create(), radius: Infinity };
|
|
32
38
|
private _sphereTargetRestriction: { center: vec3, radius: number } = { center: vec3.create(), radius: Infinity };
|
|
39
|
+
private _turntableCenter: vec3 = vec3.create();
|
|
33
40
|
private _zoomRestriction: { minDistance: number, maxDistance: number } = { minDistance: 0, maxDistance: Infinity };
|
|
34
41
|
private _zoomSpeed: number = 0.5;
|
|
35
|
-
private readonly _converter: Converter = Converter.instance;
|
|
36
|
-
private readonly _stateEngine: StateEngine = StateEngine.instance;
|
|
37
42
|
|
|
38
|
-
// #endregion Properties (
|
|
43
|
+
// #endregion Properties (25)
|
|
39
44
|
|
|
40
45
|
// #region Constructors (1)
|
|
41
46
|
|
|
@@ -45,66 +50,9 @@ export class PerspectiveCameraControls extends AbstractCameraControls implements
|
|
|
45
50
|
this._cameraControlsEventDistribution = new OrbitCameraControlsEventDistribution(this, <OrbitCameraControlsLogic>this._cameraLogic);
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
public applySettings(settingsEngine: SettingsEngine) {
|
|
49
|
-
const cameraSetting = settingsEngine.camera.cameras[this.camera.id];
|
|
50
|
-
if(!cameraSetting) return;
|
|
51
|
-
this.reset();
|
|
52
|
-
const controlsSettings = <IOrbitControlsSettingsV3>cameraSetting.controls;
|
|
53
|
-
this.autoRotationSpeed = controlsSettings.autoRotationSpeed;
|
|
54
|
-
this.damping = controlsSettings.damping;
|
|
55
|
-
this.enableAutoRotation = controlsSettings.enableAutoRotation;
|
|
56
|
-
this.enableKeyPan = controlsSettings.enableKeyPan;
|
|
57
|
-
this.enablePan = controlsSettings.enablePan;
|
|
58
|
-
this.enableRotation = controlsSettings.enableRotation;
|
|
59
|
-
this.enableZoom = controlsSettings.enableZoom;
|
|
60
|
-
this.input = controlsSettings.input;
|
|
61
|
-
this.keyPanSpeed = controlsSettings.keyPanSpeed;
|
|
62
|
-
this.movementSmoothness = controlsSettings.movementSmoothness;
|
|
63
|
-
this.rotationSpeed = controlsSettings.rotationSpeed;
|
|
64
|
-
this.panSpeed = controlsSettings.panSpeed;
|
|
65
|
-
this.zoomSpeed = controlsSettings.zoomSpeed;
|
|
66
|
-
|
|
67
|
-
if(controlsSettings.restrictions.position.cube.min.x === null) controlsSettings.restrictions.position.cube.min.x = -Infinity;
|
|
68
|
-
if(controlsSettings.restrictions.position.cube.min.y === null) controlsSettings.restrictions.position.cube.min.y = -Infinity;
|
|
69
|
-
if(controlsSettings.restrictions.position.cube.min.z === null) controlsSettings.restrictions.position.cube.min.z = -Infinity;
|
|
70
|
-
if(controlsSettings.restrictions.position.cube.max.x === null) controlsSettings.restrictions.position.cube.max.x = Infinity;
|
|
71
|
-
if(controlsSettings.restrictions.position.cube.max.y === null) controlsSettings.restrictions.position.cube.max.y = Infinity;
|
|
72
|
-
if(controlsSettings.restrictions.position.cube.max.z === null) controlsSettings.restrictions.position.cube.max.z = Infinity;
|
|
73
|
-
if(controlsSettings.restrictions.position.sphere.radius === null) controlsSettings.restrictions.position.sphere.radius = Infinity;
|
|
74
|
-
if(controlsSettings.restrictions.target.cube.min.x === null) controlsSettings.restrictions.target.cube.min.x = -Infinity;
|
|
75
|
-
if(controlsSettings.restrictions.target.cube.min.y === null) controlsSettings.restrictions.target.cube.min.y = -Infinity;
|
|
76
|
-
if(controlsSettings.restrictions.target.cube.min.z === null) controlsSettings.restrictions.target.cube.min.z = -Infinity;
|
|
77
|
-
if(controlsSettings.restrictions.target.cube.max.x === null) controlsSettings.restrictions.target.cube.max.x = Infinity;
|
|
78
|
-
if(controlsSettings.restrictions.target.cube.max.y === null) controlsSettings.restrictions.target.cube.max.y = Infinity;
|
|
79
|
-
if(controlsSettings.restrictions.target.cube.max.z === null) controlsSettings.restrictions.target.cube.max.z = Infinity;
|
|
80
|
-
if(controlsSettings.restrictions.target.sphere.radius === null) controlsSettings.restrictions.target.sphere.radius = Infinity;
|
|
81
|
-
if(controlsSettings.restrictions.rotation.minAzimuthAngle === null) controlsSettings.restrictions.rotation.minAzimuthAngle = -Infinity;
|
|
82
|
-
if(controlsSettings.restrictions.rotation.maxAzimuthAngle === null) controlsSettings.restrictions.rotation.maxAzimuthAngle = Infinity;
|
|
83
|
-
if(controlsSettings.restrictions.zoom.maxDistance === null) controlsSettings.restrictions.zoom.maxDistance = Infinity;
|
|
84
|
-
|
|
85
|
-
this.cubePositionRestriction = {
|
|
86
|
-
min: this._converter.toVec3(controlsSettings.restrictions.position.cube.min),
|
|
87
|
-
max: this._converter.toVec3(controlsSettings.restrictions.position.cube.max)
|
|
88
|
-
};
|
|
89
|
-
this.spherePositionRestriction = {
|
|
90
|
-
center: this._converter.toVec3(controlsSettings.restrictions.position.sphere.center),
|
|
91
|
-
radius: controlsSettings.restrictions.position.sphere.radius
|
|
92
|
-
};
|
|
93
|
-
this.cubeTargetRestriction = {
|
|
94
|
-
min: this._converter.toVec3(controlsSettings.restrictions.target.cube.min),
|
|
95
|
-
max: this._converter.toVec3(controlsSettings.restrictions.target.cube.max)
|
|
96
|
-
};
|
|
97
|
-
this.sphereTargetRestriction = {
|
|
98
|
-
center: this._converter.toVec3(controlsSettings.restrictions.target.sphere.center),
|
|
99
|
-
radius: controlsSettings.restrictions.target.sphere.radius
|
|
100
|
-
};
|
|
101
|
-
this.rotationRestriction = controlsSettings.restrictions.rotation;
|
|
102
|
-
this.zoomRestriction = controlsSettings.restrictions.zoom;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
53
|
// #endregion Constructors (1)
|
|
106
54
|
|
|
107
|
-
// #region Public Accessors (
|
|
55
|
+
// #region Public Accessors (46)
|
|
108
56
|
|
|
109
57
|
public get autoRotationSpeed(): number {
|
|
110
58
|
return this._autoRotationSpeed;
|
|
@@ -146,6 +94,14 @@ export class PerspectiveCameraControls extends AbstractCameraControls implements
|
|
|
146
94
|
this._enableAutoRotation = value;
|
|
147
95
|
}
|
|
148
96
|
|
|
97
|
+
public get enableAzimuthRotation(): boolean {
|
|
98
|
+
return this._enableAzimuthRotation;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public set enableAzimuthRotation(value: boolean) {
|
|
102
|
+
this._enableAzimuthRotation = value;
|
|
103
|
+
}
|
|
104
|
+
|
|
149
105
|
public get enableKeyPan(): boolean {
|
|
150
106
|
return this._enableKeyPan;
|
|
151
107
|
}
|
|
@@ -162,6 +118,14 @@ export class PerspectiveCameraControls extends AbstractCameraControls implements
|
|
|
162
118
|
this._enablePan = value;
|
|
163
119
|
}
|
|
164
120
|
|
|
121
|
+
public get enablePolarRotation(): boolean {
|
|
122
|
+
return this._enablePolarRotation;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public set enablePolarRotation(value: boolean) {
|
|
126
|
+
this._enablePolarRotation = value;
|
|
127
|
+
}
|
|
128
|
+
|
|
165
129
|
public get enableRotation(): boolean {
|
|
166
130
|
return this._enableRotation;
|
|
167
131
|
}
|
|
@@ -170,6 +134,14 @@ export class PerspectiveCameraControls extends AbstractCameraControls implements
|
|
|
170
134
|
this._enableRotation = value;
|
|
171
135
|
}
|
|
172
136
|
|
|
137
|
+
public get enableTurntableControls(): boolean {
|
|
138
|
+
return this._enableTurntableControls;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public set enableTurntableControls(value: boolean) {
|
|
142
|
+
this._enableTurntableControls = value;
|
|
143
|
+
}
|
|
144
|
+
|
|
173
145
|
public get enableZoom(): boolean {
|
|
174
146
|
return this._enableZoom;
|
|
175
147
|
}
|
|
@@ -242,6 +214,14 @@ export class PerspectiveCameraControls extends AbstractCameraControls implements
|
|
|
242
214
|
this._sphereTargetRestriction = value;
|
|
243
215
|
}
|
|
244
216
|
|
|
217
|
+
public get turntableCenter(): vec3 {
|
|
218
|
+
return this._turntableCenter;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public set turntableCenter(value: vec3) {
|
|
222
|
+
this._turntableCenter = value;
|
|
223
|
+
}
|
|
224
|
+
|
|
245
225
|
public get zoomRestriction(): { minDistance: number, maxDistance: number } {
|
|
246
226
|
return this._zoomRestriction;
|
|
247
227
|
}
|
|
@@ -258,5 +238,66 @@ export class PerspectiveCameraControls extends AbstractCameraControls implements
|
|
|
258
238
|
this._zoomSpeed = value;
|
|
259
239
|
}
|
|
260
240
|
|
|
261
|
-
// #endregion Public Accessors (
|
|
241
|
+
// #endregion Public Accessors (46)
|
|
242
|
+
|
|
243
|
+
// #region Public Methods (1)
|
|
244
|
+
|
|
245
|
+
public applySettings(settingsEngine: SettingsEngine) {
|
|
246
|
+
const cameraSetting = settingsEngine.camera.cameras[this.camera.id];
|
|
247
|
+
if (!cameraSetting) return;
|
|
248
|
+
this.reset();
|
|
249
|
+
const controlsSettings = <IOrbitControlsSettingsV3>cameraSetting.controls;
|
|
250
|
+
this.autoRotationSpeed = controlsSettings.autoRotationSpeed;
|
|
251
|
+
this.damping = controlsSettings.damping;
|
|
252
|
+
this.enableAutoRotation = controlsSettings.enableAutoRotation;
|
|
253
|
+
this.enableKeyPan = controlsSettings.enableKeyPan;
|
|
254
|
+
this.enablePan = controlsSettings.enablePan;
|
|
255
|
+
this.enableRotation = controlsSettings.enableRotation;
|
|
256
|
+
this.enableZoom = controlsSettings.enableZoom;
|
|
257
|
+
// this.input = controlsSettings.input;
|
|
258
|
+
this.keyPanSpeed = controlsSettings.keyPanSpeed;
|
|
259
|
+
this.movementSmoothness = controlsSettings.movementSmoothness;
|
|
260
|
+
this.rotationSpeed = controlsSettings.rotationSpeed;
|
|
261
|
+
this.panSpeed = controlsSettings.panSpeed;
|
|
262
|
+
this.zoomSpeed = controlsSettings.zoomSpeed;
|
|
263
|
+
|
|
264
|
+
if (controlsSettings.restrictions.position.cube.min.x === null) controlsSettings.restrictions.position.cube.min.x = -Infinity;
|
|
265
|
+
if (controlsSettings.restrictions.position.cube.min.y === null) controlsSettings.restrictions.position.cube.min.y = -Infinity;
|
|
266
|
+
if (controlsSettings.restrictions.position.cube.min.z === null) controlsSettings.restrictions.position.cube.min.z = -Infinity;
|
|
267
|
+
if (controlsSettings.restrictions.position.cube.max.x === null) controlsSettings.restrictions.position.cube.max.x = Infinity;
|
|
268
|
+
if (controlsSettings.restrictions.position.cube.max.y === null) controlsSettings.restrictions.position.cube.max.y = Infinity;
|
|
269
|
+
if (controlsSettings.restrictions.position.cube.max.z === null) controlsSettings.restrictions.position.cube.max.z = Infinity;
|
|
270
|
+
if (controlsSettings.restrictions.position.sphere.radius === null) controlsSettings.restrictions.position.sphere.radius = Infinity;
|
|
271
|
+
if (controlsSettings.restrictions.target.cube.min.x === null) controlsSettings.restrictions.target.cube.min.x = -Infinity;
|
|
272
|
+
if (controlsSettings.restrictions.target.cube.min.y === null) controlsSettings.restrictions.target.cube.min.y = -Infinity;
|
|
273
|
+
if (controlsSettings.restrictions.target.cube.min.z === null) controlsSettings.restrictions.target.cube.min.z = -Infinity;
|
|
274
|
+
if (controlsSettings.restrictions.target.cube.max.x === null) controlsSettings.restrictions.target.cube.max.x = Infinity;
|
|
275
|
+
if (controlsSettings.restrictions.target.cube.max.y === null) controlsSettings.restrictions.target.cube.max.y = Infinity;
|
|
276
|
+
if (controlsSettings.restrictions.target.cube.max.z === null) controlsSettings.restrictions.target.cube.max.z = Infinity;
|
|
277
|
+
if (controlsSettings.restrictions.target.sphere.radius === null) controlsSettings.restrictions.target.sphere.radius = Infinity;
|
|
278
|
+
if (controlsSettings.restrictions.rotation.minAzimuthAngle === null) controlsSettings.restrictions.rotation.minAzimuthAngle = -Infinity;
|
|
279
|
+
if (controlsSettings.restrictions.rotation.maxAzimuthAngle === null) controlsSettings.restrictions.rotation.maxAzimuthAngle = Infinity;
|
|
280
|
+
if (controlsSettings.restrictions.zoom.maxDistance === null) controlsSettings.restrictions.zoom.maxDistance = Infinity;
|
|
281
|
+
|
|
282
|
+
this.cubePositionRestriction = {
|
|
283
|
+
min: this._converter.toVec3(controlsSettings.restrictions.position.cube.min),
|
|
284
|
+
max: this._converter.toVec3(controlsSettings.restrictions.position.cube.max)
|
|
285
|
+
};
|
|
286
|
+
this.spherePositionRestriction = {
|
|
287
|
+
center: this._converter.toVec3(controlsSettings.restrictions.position.sphere.center),
|
|
288
|
+
radius: controlsSettings.restrictions.position.sphere.radius
|
|
289
|
+
};
|
|
290
|
+
this.cubeTargetRestriction = {
|
|
291
|
+
min: this._converter.toVec3(controlsSettings.restrictions.target.cube.min),
|
|
292
|
+
max: this._converter.toVec3(controlsSettings.restrictions.target.cube.max)
|
|
293
|
+
};
|
|
294
|
+
this.sphereTargetRestriction = {
|
|
295
|
+
center: this._converter.toVec3(controlsSettings.restrictions.target.sphere.center),
|
|
296
|
+
radius: controlsSettings.restrictions.target.sphere.radius
|
|
297
|
+
};
|
|
298
|
+
this.rotationRestriction = controlsSettings.restrictions.rotation;
|
|
299
|
+
this.zoomRestriction = controlsSettings.restrictions.zoom;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// #endregion Public Methods (1)
|
|
262
303
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CameraControlsLogic } from './CameraControlsLogic'
|
|
2
|
-
import { ICameraControlsEventDistribution } from '../../../interfaces/controls/ICameraControlsEventDistribution'
|
|
3
|
-
import { OrthographicCameraControls } from '../OrthographicCameraControls'
|
|
1
|
+
import { CameraControlsLogic } from './CameraControlsLogic';
|
|
2
|
+
import { ICameraControlsEventDistribution } from '../../../interfaces/controls/ICameraControlsEventDistribution';
|
|
3
|
+
import { OrthographicCameraControls } from '../OrthographicCameraControls';
|
|
4
4
|
|
|
5
5
|
export class CameraControlsEventDistribution implements ICameraControlsEventDistribution {
|
|
6
6
|
// #region Properties (2)
|
|
@@ -9,7 +9,6 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
|
|
|
9
9
|
zoom: false,
|
|
10
10
|
pan: false
|
|
11
11
|
};
|
|
12
|
-
|
|
13
12
|
private _activeEvents = true;
|
|
14
13
|
|
|
15
14
|
// #endregion Properties (2)
|
|
@@ -20,8 +19,8 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
|
|
|
20
19
|
|
|
21
20
|
// #endregion Constructors (1)
|
|
22
21
|
|
|
23
|
-
// #region Public Methods (
|
|
24
|
-
|
|
22
|
+
// #region Public Methods (20)
|
|
23
|
+
|
|
25
24
|
public activateCameraEvents(): void {
|
|
26
25
|
this._activeEvents = true;
|
|
27
26
|
}
|
|
@@ -31,16 +30,17 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
public onDown(event: MouseEvent | TouchEvent): void {
|
|
34
|
-
if(this._controls.camera.active === false) return;
|
|
35
|
-
|
|
33
|
+
if (this._controls.camera.active === false) return;
|
|
34
|
+
const { x, y } = this.convertInput(event);
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
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;
|
|
39
38
|
|
|
40
39
|
if (input === mapping.pan && this._controls.enablePan) {
|
|
41
40
|
this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
|
|
42
41
|
this._active.pan = true;
|
|
43
|
-
|
|
42
|
+
} else {
|
|
43
|
+
this._active.pan = false;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (input === mapping.zoom && this._controls.enableZoom) {
|
|
@@ -50,13 +50,14 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
|
|
|
50
50
|
y1 = (event.touches[0].pageY - event.touches[1].pageY) / window.innerHeight;
|
|
51
51
|
}
|
|
52
52
|
this._cameraLogic.zoom(x1, y1, this._active.zoom, window.TouchEvent && event instanceof TouchEvent);
|
|
53
|
-
this._active.pan = false;
|
|
54
53
|
this._active.zoom = true;
|
|
54
|
+
} else {
|
|
55
|
+
this._active.zoom = false;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
public onKey(event: KeyboardEvent): void {
|
|
59
|
-
if(this._controls.camera.active === false) return;
|
|
60
|
+
if (this._controls.camera.active === false) return;
|
|
60
61
|
if (this._controls.enableKeyPan) {
|
|
61
62
|
switch (event.keyCode) {
|
|
62
63
|
case this._controls.input.keys.up:
|
|
@@ -91,46 +92,46 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
public onKeyDown(event: KeyboardEvent): void {
|
|
94
|
-
if(this._controls.camera.active === false) return;
|
|
95
|
-
if(!this._activeEvents) return;
|
|
96
|
-
this.onKey(event)
|
|
95
|
+
if (this._controls.camera.active === false) return;
|
|
96
|
+
if (!this._activeEvents) return;
|
|
97
|
+
this.onKey(event);
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
public onMouseDown(event: MouseEvent): void {
|
|
100
|
-
if(this._controls.camera.active === false) return;
|
|
101
|
-
if(!this._activeEvents) return;
|
|
101
|
+
if (this._controls.camera.active === false) return;
|
|
102
|
+
if (!this._activeEvents) return;
|
|
102
103
|
this.onDown(event);
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
public onMouseMove(event: MouseEvent): void {
|
|
106
|
-
if(this._controls.camera.active === false) return;
|
|
107
|
-
if(!this._activeEvents) return;
|
|
108
|
-
this.onMove(event);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
106
|
public onMouseEnd(event: MouseEvent): void {
|
|
112
|
-
if(this._controls.camera.active === false) return;
|
|
113
|
-
if(!this._activeEvents) return;
|
|
107
|
+
if (this._controls.camera.active === false) return;
|
|
108
|
+
if (!this._activeEvents) return;
|
|
114
109
|
this.onUp(event);
|
|
115
110
|
}
|
|
116
|
-
|
|
117
|
-
public
|
|
118
|
-
if(this._controls.camera.active === false) return;
|
|
111
|
+
|
|
112
|
+
public onMouseMove(event: MouseEvent): void {
|
|
113
|
+
if (this._controls.camera.active === false) return;
|
|
114
|
+
if (!this._activeEvents) return;
|
|
115
|
+
this.onMove(event);
|
|
119
116
|
}
|
|
120
117
|
|
|
121
118
|
public onMouseOut(event: WheelEvent): void {
|
|
122
|
-
if(this._controls.camera.active === false) return;
|
|
119
|
+
if (this._controls.camera.active === false) return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public onMouseUp(event: WheelEvent): void {
|
|
123
|
+
if (this._controls.camera.active === false) return;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
public onMouseWheel(event: WheelEvent): void {
|
|
126
|
-
if(this._controls.camera.active === false) return;
|
|
127
|
-
if(!this._activeEvents) return;
|
|
127
|
+
if (this._controls.camera.active === false) return;
|
|
128
|
+
if (!this._activeEvents) return;
|
|
128
129
|
this.onWheel(event);
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
public onMove(event: MouseEvent | TouchEvent): void {
|
|
132
|
-
if(this._controls.camera.active === false) return;
|
|
133
|
-
|
|
133
|
+
if (this._controls.camera.active === false) return;
|
|
134
|
+
const { x, y } = this.convertInput(event);
|
|
134
135
|
|
|
135
136
|
if (this._controls.enablePan && this._active.pan)
|
|
136
137
|
this._cameraLogic.pan(x, y, this._active.pan, window.TouchEvent && event instanceof TouchEvent);
|
|
@@ -145,40 +146,40 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
|
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
public onTouchCancel(event: TouchEvent): void {
|
|
150
|
+
if (this._controls.camera.active === false) return;
|
|
151
|
+
}
|
|
152
|
+
|
|
148
153
|
public onTouchEnd(event: TouchEvent): void {
|
|
149
|
-
if(this._controls.camera.active === false) return;
|
|
150
|
-
if(!this._activeEvents) return;
|
|
154
|
+
if (this._controls.camera.active === false) return;
|
|
155
|
+
if (!this._activeEvents) return;
|
|
151
156
|
this.onUp(event);
|
|
152
157
|
}
|
|
153
158
|
|
|
154
159
|
public onTouchMove(event: TouchEvent): void {
|
|
155
|
-
if(this._controls.camera.active === false) return;
|
|
156
|
-
if(!this._activeEvents) return;
|
|
160
|
+
if (this._controls.camera.active === false) return;
|
|
161
|
+
if (!this._activeEvents) return;
|
|
157
162
|
this.onMove(event);
|
|
158
163
|
}
|
|
159
164
|
|
|
160
165
|
public onTouchStart(event: TouchEvent): void {
|
|
161
|
-
if(this._controls.camera.active === false) return;
|
|
162
|
-
if(!this._activeEvents) return;
|
|
166
|
+
if (this._controls.camera.active === false) return;
|
|
167
|
+
if (!this._activeEvents) return;
|
|
163
168
|
this.onDown(event);
|
|
164
169
|
}
|
|
165
170
|
|
|
166
|
-
public onTouchCancel(event: TouchEvent): void {
|
|
167
|
-
if(this._controls.camera.active === false) return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
171
|
public onTouchUp(event: TouchEvent): void {
|
|
171
|
-
if(this._controls.camera.active === false) return;
|
|
172
|
+
if (this._controls.camera.active === false) return;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
public onUp(event: MouseEvent | TouchEvent): void {
|
|
175
|
-
if(this._controls.camera.active === false) return;
|
|
176
|
+
if (this._controls.camera.active === false) return;
|
|
176
177
|
this._active.zoom = false;
|
|
177
178
|
this._active.pan = false;
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
public onWheel(event: WheelEvent): void {
|
|
181
|
-
if(this._controls.camera.active === false) return;
|
|
182
|
+
if (this._controls.camera.active === false) return;
|
|
182
183
|
if (!this._controls.enableZoom) return;
|
|
183
184
|
let delta = 0;
|
|
184
185
|
if (event.deltaY !== undefined) {
|
|
@@ -205,23 +206,27 @@ export class CameraControlsEventDistribution implements ICameraControlsEventDist
|
|
|
205
206
|
};
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
// #endregion Public Methods (
|
|
209
|
+
// #endregion Public Methods (20)
|
|
209
210
|
|
|
210
211
|
// #region Private Methods (1)
|
|
211
212
|
|
|
212
213
|
private convertInput(event: MouseEvent | TouchEvent): { x: number, y: number } {
|
|
213
|
-
let aspect = window.innerWidth / window.innerHeight;
|
|
214
214
|
if (event instanceof MouseEvent) {
|
|
215
215
|
return {
|
|
216
|
-
x: event.clientX
|
|
217
|
-
y: event.clientY
|
|
218
|
-
}
|
|
216
|
+
x: event.clientX,
|
|
217
|
+
y: event.clientY
|
|
218
|
+
};
|
|
219
219
|
} else {
|
|
220
|
-
if(event.touches.length < 1) return { x: 0, y: 0 };
|
|
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
|
+
};
|
|
221
226
|
return {
|
|
222
|
-
x: event.touches[0].pageX
|
|
223
|
-
y: event.touches[0].pageY /
|
|
224
|
-
}
|
|
227
|
+
x: (event.touches[0].pageX + event.touches[1].pageX) / 2,
|
|
228
|
+
y: (event.touches[0].pageY + event.touches[1].pageY) / 2
|
|
229
|
+
};
|
|
225
230
|
}
|
|
226
231
|
}
|
|
227
232
|
|