@shapediver/viewer.rendering-engine.camera-engine 2.12.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,40 +1,39 @@
|
|
|
1
|
+
import { AbstractCamera } from './camera/AbstractCamera';
|
|
2
|
+
import { Box } from '@shapediver/viewer.shared.math';
|
|
3
|
+
import { CAMERA_TYPE, ICameraEngine } from '../interfaces/ICameraEngine';
|
|
4
|
+
import { ICamera } from '../interfaces/camera/ICamera';
|
|
5
|
+
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine';
|
|
6
|
+
import { ISceneEvent } from '@shapediver/viewer.shared.types';
|
|
1
7
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import { PerspectiveCameraControls } from './controls/PerspectiveCameraControls'
|
|
24
|
-
import { ORTHOGRAPHIC_CAMERA_DIRECTION } from '../interfaces/camera/IOrthographicCamera'
|
|
25
|
-
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine'
|
|
26
|
-
import { ICamera } from '../interfaces/camera/ICamera'
|
|
8
|
+
ITree,
|
|
9
|
+
ITreeNode,
|
|
10
|
+
Tree,
|
|
11
|
+
TreeNode
|
|
12
|
+
} from '@shapediver/viewer.shared.node-tree';
|
|
13
|
+
import { ORTHOGRAPHIC_CAMERA_DIRECTION } from '../interfaces/camera/IOrthographicCamera';
|
|
14
|
+
import { OrthographicCamera } from './camera/OrthographicCamera';
|
|
15
|
+
import { OrthographicCameraControls } from './controls/OrthographicCameraControls';
|
|
16
|
+
import { PerspectiveCamera } from './camera/PerspectiveCamera';
|
|
17
|
+
import { PerspectiveCameraControls } from './controls/PerspectiveCameraControls';
|
|
18
|
+
import { vec3 } from 'gl-matrix';
|
|
19
|
+
import {
|
|
20
|
+
EventEngine,
|
|
21
|
+
EVENTTYPE,
|
|
22
|
+
IEvent,
|
|
23
|
+
Logger,
|
|
24
|
+
SettingsEngine,
|
|
25
|
+
ShapeDiverViewerCameraError,
|
|
26
|
+
StateEngine,
|
|
27
|
+
UuidGenerator,
|
|
28
|
+
} from '@shapediver/viewer.shared.services';
|
|
27
29
|
|
|
28
30
|
export class CameraEngine implements ICameraEngine {
|
|
29
|
-
// #region Properties (
|
|
31
|
+
// #region Properties (11)
|
|
30
32
|
|
|
33
|
+
private readonly _cameraNode: ITreeNode = new TreeNode('cameras');
|
|
31
34
|
private readonly _cameras: {
|
|
32
35
|
[key: string]: ICamera
|
|
33
36
|
} = {};
|
|
34
|
-
private readonly _camerasDomEventListenerToken: {
|
|
35
|
-
[key: string]: string
|
|
36
|
-
} = {};
|
|
37
|
-
private readonly _cameraNode: ITreeNode = new TreeNode('cameras');
|
|
38
37
|
private readonly _eventEngine: EventEngine = EventEngine.instance;
|
|
39
38
|
private readonly _logger: Logger = Logger.instance;
|
|
40
39
|
private readonly _stateEngine: StateEngine = StateEngine.instance;
|
|
@@ -43,25 +42,25 @@ export class CameraEngine implements ICameraEngine {
|
|
|
43
42
|
|
|
44
43
|
private _camera: ICamera | null = null;
|
|
45
44
|
private _settingsApplied: boolean = false;
|
|
45
|
+
private _update?: () => void;
|
|
46
46
|
|
|
47
47
|
protected _boundingBox: Box = new Box();
|
|
48
|
-
private _update?: () => void;
|
|
49
48
|
|
|
50
|
-
// #endregion Properties (
|
|
49
|
+
// #endregion Properties (11)
|
|
51
50
|
|
|
52
51
|
// #region Constructors (1)
|
|
53
52
|
|
|
54
|
-
constructor(private readonly _renderingEngine: IRenderingEngine
|
|
53
|
+
constructor(private readonly _renderingEngine: IRenderingEngine) {
|
|
55
54
|
this._tree.root.addChild(this._cameraNode);
|
|
56
55
|
this._cameraNode.restrictViewports = [this._renderingEngine.id];
|
|
57
|
-
|
|
56
|
+
|
|
58
57
|
this._eventEngine.addListener(EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e: IEvent) => {
|
|
59
58
|
const viewerEvent = <ISceneEvent>e;
|
|
60
59
|
if (viewerEvent.viewportId === this._renderingEngine.id) {
|
|
61
60
|
this._boundingBox = new Box(viewerEvent.boundingBox!.min, viewerEvent.boundingBox!.max);
|
|
62
61
|
|
|
63
62
|
const cameras = this.cameras;
|
|
64
|
-
for (
|
|
63
|
+
for (const c in cameras)
|
|
65
64
|
cameras[c].boundingBox = this._boundingBox.clone();
|
|
66
65
|
}
|
|
67
66
|
});
|
|
@@ -76,7 +75,7 @@ export class CameraEngine implements ICameraEngine {
|
|
|
76
75
|
|
|
77
76
|
// #endregion Constructors (1)
|
|
78
77
|
|
|
79
|
-
// #region Public
|
|
78
|
+
// #region Public Getters And Setters (4)
|
|
80
79
|
|
|
81
80
|
public get camera(): ICamera | null {
|
|
82
81
|
return this._camera;
|
|
@@ -87,7 +86,7 @@ export class CameraEngine implements ICameraEngine {
|
|
|
87
86
|
} {
|
|
88
87
|
return this._cameras;
|
|
89
88
|
}
|
|
90
|
-
|
|
89
|
+
|
|
91
90
|
public get update(): (() => void) | undefined {
|
|
92
91
|
return this._update;
|
|
93
92
|
}
|
|
@@ -96,24 +95,24 @@ export class CameraEngine implements ICameraEngine {
|
|
|
96
95
|
this._update = value;
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
// #endregion Public
|
|
98
|
+
// #endregion Public Getters And Setters (4)
|
|
100
99
|
|
|
101
|
-
// #region Public Methods (
|
|
100
|
+
// #region Public Methods (8)
|
|
102
101
|
|
|
103
102
|
public activateCameraEvents(): void {
|
|
104
103
|
const cameras = this.cameras;
|
|
105
|
-
for(
|
|
104
|
+
for (const c in cameras)
|
|
106
105
|
(<PerspectiveCameraControls | OrthographicCameraControls>cameras[c].controls).cameraControlsEventDistribution.activateCameraEvents();
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
public applySettings(settingsEngine: SettingsEngine) {
|
|
110
109
|
const cameras = this.cameras;
|
|
111
|
-
for (
|
|
110
|
+
for (const c in cameras)
|
|
112
111
|
this.removeCamera(c);
|
|
113
112
|
|
|
114
|
-
for(
|
|
113
|
+
for (const id in settingsEngine.settings.camera.cameras) {
|
|
115
114
|
const cameraSetting = settingsEngine.settings.camera.cameras[id];
|
|
116
|
-
if(cameraSetting.type === 'perspective') {
|
|
115
|
+
if (cameraSetting.type === 'perspective') {
|
|
117
116
|
this.createCamera(CAMERA_TYPE.PERSPECTIVE, id);
|
|
118
117
|
} else {
|
|
119
118
|
const camera = this.createCamera(CAMERA_TYPE.ORTHOGRAPHIC, id);
|
|
@@ -121,13 +120,13 @@ export class CameraEngine implements ICameraEngine {
|
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
for (
|
|
123
|
+
for (const c in cameras)
|
|
125
124
|
cameras[c].applySettings(settingsEngine);
|
|
126
125
|
|
|
127
126
|
const cameraKeys = Object.keys(settingsEngine.settings.camera.cameras);
|
|
128
127
|
|
|
129
|
-
if(cameraKeys.length > 0) {
|
|
130
|
-
if(!settingsEngine.settings.camera.cameraId) {
|
|
128
|
+
if (cameraKeys.length > 0) {
|
|
129
|
+
if (!settingsEngine.settings.camera.cameraId) {
|
|
131
130
|
this.assignCamera(cameraKeys[0]);
|
|
132
131
|
} else {
|
|
133
132
|
this.assignCamera(settingsEngine.settings.camera.cameraId);
|
|
@@ -138,14 +137,14 @@ export class CameraEngine implements ICameraEngine {
|
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
this._settingsApplied = true;
|
|
141
|
-
if(this._update) this._update();
|
|
140
|
+
if (this._update) this._update();
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
public assignCamera(id: string): boolean {
|
|
145
144
|
const camera = this.cameras[id];
|
|
146
145
|
if (!camera) return false;
|
|
147
146
|
|
|
148
|
-
for (
|
|
147
|
+
for (const c in this.cameras)
|
|
149
148
|
this.cameras[c].active = false;
|
|
150
149
|
|
|
151
150
|
this._camera = camera;
|
|
@@ -156,10 +155,10 @@ export class CameraEngine implements ICameraEngine {
|
|
|
156
155
|
public createCamera(type: CAMERA_TYPE, id?: string): ICamera {
|
|
157
156
|
const cameras = this.cameras;
|
|
158
157
|
const cameraId = id || this._uuidGenerator.create();
|
|
159
|
-
if (cameras[cameraId])
|
|
158
|
+
if (cameras[cameraId])
|
|
160
159
|
throw new ShapeDiverViewerCameraError(`CameraEngine.createCamera: Camera (${type}) with this id (${cameraId}) already exists.`);
|
|
161
|
-
|
|
162
|
-
const initialAspectRatio =
|
|
160
|
+
|
|
161
|
+
const initialAspectRatio = (<HTMLDivElement>this._renderingEngine.canvas.parentNode).clientWidth / (<HTMLDivElement>this._renderingEngine.canvas.parentNode).clientHeight;
|
|
163
162
|
const camera = CAMERA_TYPE.PERSPECTIVE === type ? new PerspectiveCamera(cameraId, undefined, initialAspectRatio) : new OrthographicCamera(cameraId);
|
|
164
163
|
camera.assignViewer(this._renderingEngine);
|
|
165
164
|
|
|
@@ -171,7 +170,7 @@ export class CameraEngine implements ICameraEngine {
|
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
this._cameraNode.addData(camera);
|
|
174
|
-
if(this._update) this._update();
|
|
173
|
+
if (this._update) this._update();
|
|
175
174
|
return camera;
|
|
176
175
|
}
|
|
177
176
|
|
|
@@ -188,13 +187,14 @@ export class CameraEngine implements ICameraEngine {
|
|
|
188
187
|
frontCamera.direction = ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT;
|
|
189
188
|
const backCamera = <OrthographicCamera>this.createCamera(CAMERA_TYPE.ORTHOGRAPHIC, 'back');
|
|
190
189
|
backCamera.direction = ORTHOGRAPHIC_CAMERA_DIRECTION.BACK;
|
|
190
|
+
this.createCamera(CAMERA_TYPE.ORTHOGRAPHIC, 'orthographic');
|
|
191
191
|
const camera = this.createCamera(CAMERA_TYPE.PERSPECTIVE, 'perspective');
|
|
192
192
|
this.assignCamera(camera.id);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
public deactivateCameraEvents(): void {
|
|
196
196
|
const cameras = this.cameras;
|
|
197
|
-
for (
|
|
197
|
+
for (const c in cameras)
|
|
198
198
|
(<PerspectiveCameraControls | OrthographicCameraControls>cameras[c].controls).cameraControlsEventDistribution.deactivateCameraEvents();
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -202,14 +202,13 @@ export class CameraEngine implements ICameraEngine {
|
|
|
202
202
|
const cameras = this.cameras;
|
|
203
203
|
const camera = cameras[id];
|
|
204
204
|
if (!camera) return false;
|
|
205
|
-
this._renderingEngine.domEventEngine.removeDomEventListener(
|
|
205
|
+
if (camera.domEventListenerToken) this._renderingEngine.domEventEngine.removeDomEventListener(camera.domEventListenerToken);
|
|
206
206
|
if (this._camera && this._camera.id === id)
|
|
207
207
|
this._camera = null;
|
|
208
208
|
|
|
209
209
|
delete cameras[id];
|
|
210
|
-
delete this._camerasDomEventListenerToken[id];
|
|
211
210
|
this._cameraNode.removeData(camera);
|
|
212
|
-
if(this._update) this._update();
|
|
211
|
+
if (this._update) this._update();
|
|
213
212
|
return true;
|
|
214
213
|
}
|
|
215
214
|
|
|
@@ -217,7 +216,7 @@ export class CameraEngine implements ICameraEngine {
|
|
|
217
216
|
settingsEngine.settings.camera.cameraId = this._camera ? this._camera.id : 'perspective';
|
|
218
217
|
settingsEngine.settings.camera.cameras = {};
|
|
219
218
|
|
|
220
|
-
for (
|
|
219
|
+
for (const c in this.cameras) {
|
|
221
220
|
const camera = this.cameras[c];
|
|
222
221
|
|
|
223
222
|
if (camera.type === CAMERA_TYPE.PERSPECTIVE) {
|
|
@@ -234,6 +233,7 @@ export class CameraEngine implements ICameraEngine {
|
|
|
234
233
|
target: { x: camera.defaultTarget[0], y: camera.defaultTarget[1], z: camera.defaultTarget[2] },
|
|
235
234
|
type: camera.type,
|
|
236
235
|
fov: (<PerspectiveCamera>camera).fov,
|
|
236
|
+
sceneRotation: { x: (<PerspectiveCamera>camera).sceneRotation[0], y: (<PerspectiveCamera>camera).sceneRotation[1] },
|
|
237
237
|
controls: {
|
|
238
238
|
autoRotationSpeed: controls.autoRotationSpeed,
|
|
239
239
|
damping: controls.damping,
|
|
@@ -271,14 +271,20 @@ export class CameraEngine implements ICameraEngine {
|
|
|
271
271
|
},
|
|
272
272
|
rotation: controls.rotationRestriction,
|
|
273
273
|
zoom: controls.zoomRestriction,
|
|
274
|
-
}
|
|
274
|
+
},
|
|
275
|
+
enableAzimuthRotation: controls.enableAzimuthRotation,
|
|
276
|
+
enablePolarRotation: controls.enablePolarRotation,
|
|
277
|
+
enableObjectControls: controls.enableObjectControls,
|
|
278
|
+
enableTurntableControls: controls.enableTurntableControls,
|
|
279
|
+
turntableCenter: { x: controls.turntableCenter[0], y: controls.turntableCenter[1], z: controls.turntableCenter[2] },
|
|
280
|
+
objectControlsCenter: { x: controls.objectControlsCenter[0], y: controls.objectControlsCenter[1], z: controls.objectControlsCenter[2] },
|
|
275
281
|
}
|
|
276
|
-
}
|
|
277
|
-
|
|
282
|
+
};
|
|
283
|
+
|
|
278
284
|
} else {
|
|
279
285
|
if (settingsEngine.camera.cameras[camera.id]) {
|
|
280
286
|
const previousDirection = settingsEngine.camera.cameras[camera.id].type;
|
|
281
|
-
|
|
287
|
+
|
|
282
288
|
// if the direction changed, but the default position & target did not, there is an issue
|
|
283
289
|
if (previousDirection !== camera.type && (
|
|
284
290
|
settingsEngine.camera.cameras[camera.id].position.x === camera.defaultPosition[0] &&
|
|
@@ -293,7 +299,7 @@ export class CameraEngine implements ICameraEngine {
|
|
|
293
299
|
}
|
|
294
300
|
}
|
|
295
301
|
const controls = <OrthographicCameraControls>(<OrthographicCamera>camera).controls;
|
|
296
|
-
|
|
302
|
+
|
|
297
303
|
settingsEngine.camera.cameras[camera.id] = {
|
|
298
304
|
name: camera.name,
|
|
299
305
|
autoAdjust: camera.autoAdjust,
|
|
@@ -305,40 +311,75 @@ export class CameraEngine implements ICameraEngine {
|
|
|
305
311
|
position: { x: camera.defaultPosition[0], y: camera.defaultPosition[1], z: camera.defaultPosition[2] },
|
|
306
312
|
target: { x: camera.defaultTarget[0], y: camera.defaultTarget[1], z: camera.defaultTarget[2] },
|
|
307
313
|
type: (<OrthographicCamera>camera).direction,
|
|
314
|
+
sceneRotation: { x: (<OrthographicCamera>camera).sceneRotation[0], y: (<OrthographicCamera>camera).sceneRotation[1] },
|
|
308
315
|
controls: {
|
|
316
|
+
autoRotationSpeed: controls.autoRotationSpeed,
|
|
309
317
|
damping: controls.damping,
|
|
318
|
+
enableAutoRotation: controls.enableAutoRotation,
|
|
310
319
|
enableKeyPan: controls.enableKeyPan,
|
|
311
320
|
enablePan: controls.enablePan,
|
|
321
|
+
enableRotation: controls.enableRotation,
|
|
312
322
|
enableZoom: controls.enableZoom,
|
|
313
323
|
input: controls.input,
|
|
314
324
|
keyPanSpeed: controls.keyPanSpeed,
|
|
315
325
|
movementSmoothness: controls.movementSmoothness,
|
|
326
|
+
rotationSpeed: controls.rotationSpeed,
|
|
316
327
|
panSpeed: controls.panSpeed,
|
|
317
328
|
zoomSpeed: controls.zoomSpeed,
|
|
329
|
+
restrictions: {
|
|
330
|
+
position: {
|
|
331
|
+
cube: {
|
|
332
|
+
min: { x: controls.cubePositionRestriction.min[0], y: controls.cubePositionRestriction.min[1], z: controls.cubePositionRestriction.min[2] },
|
|
333
|
+
max: { x: controls.cubePositionRestriction.max[0], y: controls.cubePositionRestriction.max[1], z: controls.cubePositionRestriction.max[2] },
|
|
334
|
+
},
|
|
335
|
+
sphere: {
|
|
336
|
+
center: { x: controls.spherePositionRestriction.center[0], y: controls.spherePositionRestriction.center[1], z: controls.spherePositionRestriction.center[2] },
|
|
337
|
+
radius: controls.spherePositionRestriction.radius,
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
target: {
|
|
341
|
+
cube: {
|
|
342
|
+
min: { x: controls.cubeTargetRestriction.min[0], y: controls.cubeTargetRestriction.min[1], z: controls.cubeTargetRestriction.min[2] },
|
|
343
|
+
max: { x: controls.cubeTargetRestriction.max[0], y: controls.cubeTargetRestriction.max[1], z: controls.cubeTargetRestriction.max[2] },
|
|
344
|
+
},
|
|
345
|
+
sphere: {
|
|
346
|
+
center: { x: controls.sphereTargetRestriction.center[0], y: controls.sphereTargetRestriction.center[1], z: controls.sphereTargetRestriction.center[2] },
|
|
347
|
+
radius: controls.sphereTargetRestriction.radius,
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
rotation: controls.rotationRestriction,
|
|
351
|
+
zoom: controls.zoomRestriction,
|
|
352
|
+
},
|
|
353
|
+
enableAzimuthRotation: controls.enableAzimuthRotation,
|
|
354
|
+
enablePolarRotation: controls.enablePolarRotation,
|
|
355
|
+
enableObjectControls: controls.enableObjectControls,
|
|
356
|
+
enableTurntableControls: controls.enableTurntableControls,
|
|
357
|
+
turntableCenter: { x: controls.turntableCenter[0], y: controls.turntableCenter[1], z: controls.turntableCenter[2] },
|
|
358
|
+
objectControlsCenter: { x: controls.objectControlsCenter[0], y: controls.objectControlsCenter[1], z: controls.objectControlsCenter[2] },
|
|
318
359
|
}
|
|
319
|
-
}
|
|
360
|
+
};
|
|
320
361
|
}
|
|
321
362
|
}
|
|
322
363
|
}
|
|
323
364
|
|
|
324
|
-
// #endregion Public Methods (
|
|
325
|
-
|
|
365
|
+
// #endregion Public Methods (8)
|
|
366
|
+
|
|
326
367
|
// #region Private Methods (1)
|
|
327
368
|
|
|
328
369
|
private searchForNewCameras() {
|
|
329
370
|
const getCameraData = (node: ITreeNode) => {
|
|
330
|
-
for(let i = 0; i < node.data.length; i++)
|
|
331
|
-
if((node.data[i] instanceof AbstractCamera) && !this._cameras[node.data[i].id]) {
|
|
371
|
+
for (let i = 0; i < node.data.length; i++)
|
|
372
|
+
if ((node.data[i] instanceof AbstractCamera) && !this._cameras[node.data[i].id]) {
|
|
332
373
|
const camera = <AbstractCamera>node.data[i];
|
|
333
|
-
if(camera.viewportId === this._renderingEngine.id)
|
|
374
|
+
if (camera.viewportId === this._renderingEngine.id)
|
|
334
375
|
this._cameras[camera.id] = camera;
|
|
335
376
|
}
|
|
336
377
|
|
|
337
|
-
for(let i = 0; i < node.children.length; i++)
|
|
378
|
+
for (let i = 0; i < node.children.length; i++)
|
|
338
379
|
getCameraData(node.children[i]);
|
|
339
380
|
};
|
|
340
381
|
getCameraData(this._tree.root);
|
|
341
|
-
if(this._update) this._update();
|
|
382
|
+
if (this._update) this._update();
|
|
342
383
|
}
|
|
343
384
|
|
|
344
385
|
// #endregion Private Methods (1)
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import * as detectIt from 'detect-it';
|
|
2
|
+
import { AbstractTreeNodeData, ITreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
3
|
+
import { Box, IBox } from '@shapediver/viewer.shared.math';
|
|
4
|
+
import { CAMERA_TYPE } from '../../interfaces/ICameraEngine';
|
|
5
|
+
import { ICamera, ICameraOptions } from '../../interfaces/camera/ICamera';
|
|
6
|
+
import { ICameraControls } from '../../interfaces/controls/ICameraControls';
|
|
7
|
+
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine';
|
|
2
8
|
import { vec2, vec3 } from 'gl-matrix';
|
|
3
9
|
import {
|
|
4
10
|
EventEngine,
|
|
@@ -6,22 +12,16 @@ import {
|
|
|
6
12
|
SettingsEngine,
|
|
7
13
|
StateEngine,
|
|
8
14
|
} from '@shapediver/viewer.shared.services';
|
|
9
|
-
import { Box, IBox } from '@shapediver/viewer.shared.math';
|
|
10
|
-
import { AbstractTreeNodeData, ITreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
11
|
-
|
|
12
|
-
import { ICameraControls } from '../../interfaces/controls/ICameraControls';
|
|
13
|
-
import { ICamera, ICameraOptions } from '../../interfaces/camera/ICamera';
|
|
14
|
-
import { CAMERA_TYPE } from '../../interfaces/ICameraEngine';
|
|
15
|
-
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine';
|
|
16
15
|
|
|
17
16
|
export abstract class AbstractCamera extends AbstractTreeNodeData implements ICamera {
|
|
18
|
-
// #region Properties (
|
|
17
|
+
// #region Properties (24)
|
|
19
18
|
|
|
20
19
|
#active: boolean = false;
|
|
21
20
|
#autoAdjust: boolean = false;
|
|
22
21
|
#cameraMovementDuration: number = 800;
|
|
23
22
|
#defaultPosition: vec3 = vec3.create();
|
|
24
23
|
#defaultTarget: vec3 = vec3.create();
|
|
24
|
+
#domEventListenerToken: string | undefined;
|
|
25
25
|
#enableCameraControls: boolean = true;
|
|
26
26
|
#far: number = 1000;
|
|
27
27
|
#name?: string;
|
|
@@ -43,7 +43,7 @@ export abstract class AbstractCamera extends AbstractTreeNodeData implements ICa
|
|
|
43
43
|
protected _target: vec3 = vec3.create();
|
|
44
44
|
protected _viewportId?: string;
|
|
45
45
|
|
|
46
|
-
// #endregion Properties (
|
|
46
|
+
// #endregion Properties (24)
|
|
47
47
|
|
|
48
48
|
// #region Constructors (1)
|
|
49
49
|
|
|
@@ -53,7 +53,7 @@ export abstract class AbstractCamera extends AbstractTreeNodeData implements ICa
|
|
|
53
53
|
|
|
54
54
|
// #endregion Constructors (1)
|
|
55
55
|
|
|
56
|
-
// #region Public
|
|
56
|
+
// #region Public Getters And Setters (43)
|
|
57
57
|
|
|
58
58
|
public get active(): boolean {
|
|
59
59
|
return this.#active;
|
|
@@ -103,6 +103,14 @@ export abstract class AbstractCamera extends AbstractTreeNodeData implements ICa
|
|
|
103
103
|
this.#defaultTarget = value;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
public get domEventListenerToken(): string | undefined {
|
|
107
|
+
return this.#domEventListenerToken;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public set domEventListenerToken(value: string | undefined) {
|
|
111
|
+
this.#domEventListenerToken = value;
|
|
112
|
+
}
|
|
113
|
+
|
|
106
114
|
public get enableCameraControls(): boolean {
|
|
107
115
|
return this.#enableCameraControls;
|
|
108
116
|
}
|
|
@@ -221,7 +229,7 @@ export abstract class AbstractCamera extends AbstractTreeNodeData implements ICa
|
|
|
221
229
|
this.#zoomExtentsFactor = value;
|
|
222
230
|
}
|
|
223
231
|
|
|
224
|
-
// #endregion Public
|
|
232
|
+
// #endregion Public Getters And Setters (43)
|
|
225
233
|
|
|
226
234
|
// #region Public Methods (5)
|
|
227
235
|
|
|
@@ -286,11 +294,11 @@ export abstract class AbstractCamera extends AbstractTreeNodeData implements ICa
|
|
|
286
294
|
|
|
287
295
|
// #region Public Abstract Methods (5)
|
|
288
296
|
|
|
289
|
-
abstract applySettings(settingsEngine?: SettingsEngine): void;
|
|
290
|
-
abstract assignViewer(renderingEngine: IRenderingEngine): void;
|
|
291
|
-
abstract calculateZoomTo(zoomTarget?: Box, startingPosition?: vec3, startingTarget?: vec3): { position: vec3; target: vec3; };
|
|
292
|
-
abstract project(p: vec3): vec2;
|
|
293
|
-
abstract unproject(p: vec3): vec3;
|
|
297
|
+
public abstract applySettings(settingsEngine?: SettingsEngine): void;
|
|
298
|
+
public abstract assignViewer(renderingEngine: IRenderingEngine): void;
|
|
299
|
+
public abstract calculateZoomTo(zoomTarget?: Box, startingPosition?: vec3, startingTarget?: vec3): { position: vec3; target: vec3; };
|
|
300
|
+
public abstract project(p: vec3): vec2;
|
|
301
|
+
public abstract unproject(p: vec3): vec3;
|
|
294
302
|
|
|
295
303
|
// #endregion Public Abstract Methods (5)
|
|
296
304
|
|