@shapediver/viewer.rendering-engine.camera-engine 3.16.8 → 3.16.9
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 +42 -42
- package/dist/implementation/CameraEngine.js +607 -607
- package/dist/implementation/CameraEngine.js.map +1 -1
- package/dist/implementation/camera/AbstractCamera.d.ts +90 -90
- package/dist/implementation/camera/AbstractCamera.js +354 -354
- package/dist/implementation/camera/AbstractCamera.js.map +1 -1
- package/dist/implementation/camera/OrthographicCamera.d.ts +37 -37
- package/dist/implementation/camera/OrthographicCamera.js +268 -268
- package/dist/implementation/camera/OrthographicCamera.js.map +1 -1
- package/dist/implementation/camera/PerspectiveCamera.d.ts +28 -28
- package/dist/implementation/camera/PerspectiveCamera.js +250 -250
- package/dist/implementation/camera/PerspectiveCamera.js.map +1 -1
- package/dist/implementation/controls/AbstractCameraControls.d.ts +217 -217
- package/dist/implementation/controls/AbstractCameraControls.js +635 -635
- package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
- package/dist/implementation/controls/CameraControlsEventDistribution.d.ts +39 -39
- package/dist/implementation/controls/CameraControlsEventDistribution.d.ts.map +1 -1
- package/dist/implementation/controls/CameraControlsEventDistribution.js +287 -287
- package/dist/implementation/controls/CameraControlsEventDistribution.js.map +1 -1
- package/dist/implementation/controls/CameraControlsLogic.d.ts +36 -36
- package/dist/implementation/controls/CameraControlsLogic.js +530 -530
- package/dist/implementation/controls/CameraControlsLogic.js.map +1 -1
- package/dist/implementation/controls/OrthographicCameraControls.d.ts +7 -7
- package/dist/implementation/controls/OrthographicCameraControls.js +34 -34
- package/dist/implementation/controls/PerspectiveCameraControls.d.ts +7 -7
- package/dist/implementation/controls/PerspectiveCameraControls.js +34 -34
- package/dist/implementation/interpolation/CameraInterpolationManager.d.ts +22 -22
- package/dist/implementation/interpolation/CameraInterpolationManager.js +165 -155
- package/dist/implementation/interpolation/CameraInterpolationManager.js.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.d.ts +36 -36
- package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.js +57 -57
- package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.d.ts +26 -26
- package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.js +31 -31
- package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.d.ts +35 -35
- package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js +45 -45
- package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.d.ts +26 -26
- package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.js +31 -31
- package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.d.ts +32 -32
- package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.js +42 -42
- package/dist/index.d.ts +16 -16
- package/dist/index.js +18 -18
- package/dist/interfaces/ICameraEngine.d.ts +12 -12
- package/dist/interfaces/ICameraEngine.js +3 -3
- package/dist/interfaces/camera/ICamera.d.ts +47 -47
- package/dist/interfaces/camera/ICamera.js +2 -2
- package/dist/interfaces/camera/IOrthographicCamera.d.ts +8 -8
- package/dist/interfaces/camera/IOrthographicCamera.js +3 -3
- package/dist/interfaces/camera/IPerspectiveCamera.d.ts +7 -7
- package/dist/interfaces/camera/IPerspectiveCamera.js +2 -2
- package/dist/interfaces/controls/ICameraControls.d.ts +105 -105
- package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControls.js +3 -3
- package/dist/interfaces/controls/ICameraControlsEventDistribution.d.ts +6 -6
- package/dist/interfaces/controls/ICameraControlsEventDistribution.js +2 -2
- package/dist/interfaces/controls/ICameraControlsLogic.d.ts +14 -14
- package/dist/interfaces/controls/ICameraControlsLogic.js +2 -2
- package/dist/interfaces/interpolation/ICameraInterpolation.d.ts +11 -11
- package/dist/interfaces/interpolation/ICameraInterpolation.js +2 -2
- package/package.json +8 -8
|
@@ -1,608 +1,608 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CameraEngine = void 0;
|
|
4
|
-
const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
|
|
5
|
-
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
6
|
-
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
7
|
-
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
8
|
-
const gl_matrix_1 = require("gl-matrix");
|
|
9
|
-
const AbstractCamera_1 = require("./camera/AbstractCamera");
|
|
10
|
-
const OrthographicCamera_1 = require("./camera/OrthographicCamera");
|
|
11
|
-
const PerspectiveCamera_1 = require("./camera/PerspectiveCamera");
|
|
12
|
-
class CameraEngine {
|
|
13
|
-
constructor(_renderingEngine) {
|
|
14
|
-
this._renderingEngine = _renderingEngine;
|
|
15
|
-
this._cameraNode = new viewer_shared_node_tree_1.TreeNode("cameras");
|
|
16
|
-
this._cameras = {};
|
|
17
|
-
this._eventEngine = viewer_shared_services_1.EventEngine.instance;
|
|
18
|
-
this._logger = viewer_shared_services_1.Logger.instance;
|
|
19
|
-
this._stateEngine = viewer_shared_services_1.StateEngine.instance;
|
|
20
|
-
this._tree = viewer_shared_node_tree_1.Tree.instance;
|
|
21
|
-
this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
|
|
22
|
-
this._defaultCameraIds = [
|
|
23
|
-
"top",
|
|
24
|
-
"bottom",
|
|
25
|
-
"left",
|
|
26
|
-
"right",
|
|
27
|
-
"front",
|
|
28
|
-
"back",
|
|
29
|
-
];
|
|
30
|
-
this._camera = null;
|
|
31
|
-
this._loadDefaultCameras = true;
|
|
32
|
-
this._settingsApplied = false;
|
|
33
|
-
this._boundingBox = new viewer_shared_math_1.Box();
|
|
34
|
-
this._tree.root.addChild(this._cameraNode);
|
|
35
|
-
this._cameraNode.restrictViewports = [this._renderingEngine.id];
|
|
36
|
-
this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
|
|
37
|
-
const viewerEvent = e;
|
|
38
|
-
if (viewerEvent.viewportId === this._renderingEngine.id) {
|
|
39
|
-
this._boundingBox = new viewer_shared_math_1.Box(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max);
|
|
40
|
-
const cameras = this.cameras;
|
|
41
|
-
for (const c in cameras)
|
|
42
|
-
cameras[c].boundingBox = this._boundingBox.clone();
|
|
43
|
-
if (!this._boundingBox.isEmpty() && this.camera) {
|
|
44
|
-
// check if the at least a part of the bounding box is visible
|
|
45
|
-
// if not zoom to the bounding box
|
|
46
|
-
if (!this.camera.boundingSphereVisible(this._boundingBox.boundingSphere)) {
|
|
47
|
-
this.camera.zoomTo(this._boundingBox, {
|
|
48
|
-
duration: 0,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.VIEWPORT.VIEWPORT_UPDATED, (e) => {
|
|
55
|
-
const viewerEvent = e;
|
|
56
|
-
if (viewerEvent.viewportId === this._renderingEngine.id) {
|
|
57
|
-
this.searchForNewCameras();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
get camera() {
|
|
62
|
-
return this._camera;
|
|
63
|
-
}
|
|
64
|
-
get cameras() {
|
|
65
|
-
return this._cameras;
|
|
66
|
-
}
|
|
67
|
-
get loadDefaultCameras() {
|
|
68
|
-
return this._loadDefaultCameras;
|
|
69
|
-
}
|
|
70
|
-
set loadDefaultCameras(value) {
|
|
71
|
-
this._loadDefaultCameras = value;
|
|
72
|
-
if (value) {
|
|
73
|
-
// if the default cameras are not yet created, we create them
|
|
74
|
-
if (!this.hasDefaultCameras()) {
|
|
75
|
-
this.createDefaultCameras(true, false);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// check if there are currently default cameras and remove them
|
|
80
|
-
if (this.hasDefaultCameras()) {
|
|
81
|
-
for (const cameraId of this._defaultCameraIds) {
|
|
82
|
-
if (this._cameras[cameraId])
|
|
83
|
-
this.removeCamera(cameraId);
|
|
84
|
-
}
|
|
85
|
-
// check if the current camera is one of the default cameras
|
|
86
|
-
if (!this._camera) {
|
|
87
|
-
// check if there are other cameras available
|
|
88
|
-
const cameraKeys = Object.keys(this._cameras);
|
|
89
|
-
if (cameraKeys.length > 0) {
|
|
90
|
-
// if so, assign the first camera
|
|
91
|
-
this.assignCamera(cameraKeys[0]);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// create the perspective camera if no cameras are available
|
|
95
|
-
this.createDefaultCameras(false, true);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// if the current camera is one of the default cameras, we need to assign a new camera
|
|
100
|
-
if (this._defaultCameraIds.includes(this._camera.id)) {
|
|
101
|
-
// if the current camera is one of the default cameras, assign the first camera
|
|
102
|
-
const cameraKeys = Object.keys(this._cameras);
|
|
103
|
-
if (cameraKeys.length > 0) {
|
|
104
|
-
this.assignCamera(cameraKeys[0]);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// create the perspective camera if no cameras are available
|
|
108
|
-
this.createDefaultCameras(false, true);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
get update() {
|
|
116
|
-
return this._update;
|
|
117
|
-
}
|
|
118
|
-
set update(value) {
|
|
119
|
-
this._update = value;
|
|
120
|
-
}
|
|
121
|
-
activateCameraEvents() {
|
|
122
|
-
const cameras = this.cameras;
|
|
123
|
-
for (const c in cameras)
|
|
124
|
-
(cameras[c].controls).cameraControlsEventDistribution.activateCameraEvents();
|
|
125
|
-
}
|
|
126
|
-
hasDefaultCameras() {
|
|
127
|
-
let defaultCamerasInSettings = true;
|
|
128
|
-
for (const cameraId of this._defaultCameraIds) {
|
|
129
|
-
if (!this._cameras[cameraId]) {
|
|
130
|
-
defaultCamerasInSettings = false;
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return defaultCamerasInSettings;
|
|
135
|
-
}
|
|
136
|
-
applySettings(settingsEngine) {
|
|
137
|
-
var _a, _b, _c, _d;
|
|
138
|
-
const cameras = this.cameras;
|
|
139
|
-
for (const c in cameras)
|
|
140
|
-
this.removeCamera(c);
|
|
141
|
-
/**
|
|
142
|
-
* Due to some inconsistency in the behavior of saving settings
|
|
143
|
-
* we save the orthographic default cameras, even if they were never changed.
|
|
144
|
-
* Now we check if the six cameras exist and were not change and if so, we never add them
|
|
145
|
-
*/
|
|
146
|
-
let defaultCamerasInSettings = true;
|
|
147
|
-
for (const cameraId of this._defaultCameraIds) {
|
|
148
|
-
if (settingsEngine.settings.camera.cameraId === cameraId) {
|
|
149
|
-
// the camera was set as the default, don't remove it
|
|
150
|
-
defaultCamerasInSettings = false;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
if (!settingsEngine.settings.camera.cameras[cameraId])
|
|
154
|
-
defaultCamerasInSettings = false;
|
|
155
|
-
}
|
|
156
|
-
for (const id in settingsEngine.settings.camera.cameras) {
|
|
157
|
-
const cameraSetting = settingsEngine.settings.camera.cameras[id];
|
|
158
|
-
if (cameraSetting.type === "perspective") {
|
|
159
|
-
this.createCamera(viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE, id);
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
const isDefault = defaultCamerasInSettings &&
|
|
163
|
-
this._defaultCameraIds.includes(id);
|
|
164
|
-
const camera = this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, id, isDefault);
|
|
165
|
-
camera.direction =
|
|
166
|
-
cameraSetting.type;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
for (const c in cameras)
|
|
170
|
-
cameras[c].applySettings(settingsEngine);
|
|
171
|
-
this._loadDefaultCameras =
|
|
172
|
-
settingsEngine.settings.camera.loadDefaultCameras;
|
|
173
|
-
const cameraKeys = Object.keys(settingsEngine.settings.camera.cameras);
|
|
174
|
-
if (cameraKeys.length > 0) {
|
|
175
|
-
if (!settingsEngine.settings.camera.cameraId) {
|
|
176
|
-
this.assignCamera(cameraKeys[0]);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.assignCamera(settingsEngine.settings.camera.cameraId);
|
|
180
|
-
}
|
|
181
|
-
// create the default orthographic cameras if there are no cameras with the default names
|
|
182
|
-
if (!defaultCamerasInSettings &&
|
|
183
|
-
cameraKeys.every((key) => !this._defaultCameraIds.includes(key)))
|
|
184
|
-
this.createDefaultCameras(this._loadDefaultCameras, false);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
this.createDefaultCameras(this._loadDefaultCameras, true);
|
|
188
|
-
this.camera.applySettings(settingsEngine);
|
|
189
|
-
}
|
|
190
|
-
this._settingsApplied = true;
|
|
191
|
-
// If the camera is set to auto adjust, we call zoomTo once when the bounding box is available
|
|
192
|
-
// this is needed as the default position and target might not make sense if the model is loaded with a different modelState
|
|
193
|
-
// or different initial parameters
|
|
194
|
-
const sessionObj = Object.values(this._stateEngine.sessionEngines).find((s) => (s === null || s === void 0 ? void 0 : s.settingsEngine) === settingsEngine);
|
|
195
|
-
const zoomTo = !!(sessionObj === null || sessionObj === void 0 ? void 0 : sessionObj.sessionCreationDefinition.initialParameterValues) ||
|
|
196
|
-
!!(sessionObj === null || sessionObj === void 0 ? void 0 : sessionObj.sessionCreationDefinition.modelStateId);
|
|
197
|
-
if ((zoomTo && ((_a = this.camera) === null || _a === void 0 ? void 0 : _a.autoAdjust)) ||
|
|
198
|
-
((_b = this.camera) === null || _b === void 0 ? void 0 : _b.initialAutoAdjust) ||
|
|
199
|
-
this._renderingEngine.viewportCreationDefinition.initialAutoAdjust) {
|
|
200
|
-
// Use boundingBoxCreated which resolves immediately if the scene
|
|
201
|
-
// is already loaded (session-first), or once it appears (viewport-first).
|
|
202
|
-
(_c = this._stateEngine.viewportEngines[this._renderingEngine.id]) === null || _c === void 0 ? void 0 : _c.boundingBoxCreated.then(() => {
|
|
203
|
-
var _a;
|
|
204
|
-
(_a = this.camera) === null || _a === void 0 ? void 0 : _a.zoomTo(undefined, { duration: 0 });
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
if ((_d = this.camera) === null || _d === void 0 ? void 0 : _d.autoAdjust) {
|
|
208
|
-
// Default: zoom only if the camera cannot see any part of the scene.
|
|
209
|
-
const token = this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
|
|
210
|
-
const viewerEvent = e;
|
|
211
|
-
if (viewerEvent.viewportId === this._renderingEngine.id) {
|
|
212
|
-
this._boundingBox = new viewer_shared_math_1.Box(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max);
|
|
213
|
-
if (this._boundingBox.isEmpty() || !this.camera)
|
|
214
|
-
return;
|
|
215
|
-
if (!this.camera.boundingSphereVisible(this._boundingBox.boundingSphere)) {
|
|
216
|
-
this.camera.zoomTo(this._boundingBox, {
|
|
217
|
-
duration: 0,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
this._eventEngine.removeListener(token);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
if (this._update)
|
|
225
|
-
this._update();
|
|
226
|
-
}
|
|
227
|
-
assignCamera(id) {
|
|
228
|
-
const camera = this.cameras[id];
|
|
229
|
-
if (!camera)
|
|
230
|
-
return false;
|
|
231
|
-
for (const c in this.cameras)
|
|
232
|
-
this.cameras[c].active = false;
|
|
233
|
-
this._camera = camera;
|
|
234
|
-
this._camera.active = true;
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
|
-
close() {
|
|
238
|
-
this._tree.root.removeChild(this._cameraNode);
|
|
239
|
-
}
|
|
240
|
-
createCamera(type, id, isDefault = false) {
|
|
241
|
-
const cameras = this.cameras;
|
|
242
|
-
const cameraId = id || this._uuidGenerator.create();
|
|
243
|
-
if (cameras[cameraId])
|
|
244
|
-
throw new viewer_shared_services_1.ShapeDiverViewerCameraError(`CameraEngine.createCamera: Camera (${type}) with this id (${cameraId}) already exists.`);
|
|
245
|
-
const initialAspectRatio = this._renderingEngine.canvas.parentNode
|
|
246
|
-
.clientWidth /
|
|
247
|
-
this._renderingEngine.canvas.parentNode
|
|
248
|
-
.clientHeight;
|
|
249
|
-
const camera = viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE === type
|
|
250
|
-
? new PerspectiveCamera_1.PerspectiveCamera(cameraId, undefined, initialAspectRatio, isDefault)
|
|
251
|
-
: new OrthographicCamera_1.OrthographicCamera(cameraId, undefined, isDefault);
|
|
252
|
-
camera.assignViewer(this._renderingEngine);
|
|
253
|
-
cameras[cameraId] = camera;
|
|
254
|
-
if (this._settingsApplied && this._renderingEngine.settingsEngine) {
|
|
255
|
-
camera.applySettings(this._renderingEngine.settingsEngine);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
camera.zoomTo(undefined, { duration: 0 });
|
|
259
|
-
}
|
|
260
|
-
this._cameraNode.addData(camera);
|
|
261
|
-
if (this._update)
|
|
262
|
-
this._update();
|
|
263
|
-
return camera;
|
|
264
|
-
}
|
|
265
|
-
createDefaultCameras(createOrthographic = true, createPerspective = true) {
|
|
266
|
-
if (createOrthographic) {
|
|
267
|
-
const topCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "top", true));
|
|
268
|
-
topCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.TOP;
|
|
269
|
-
const bottomCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "bottom", true));
|
|
270
|
-
bottomCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM;
|
|
271
|
-
const leftCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "left", true));
|
|
272
|
-
leftCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.LEFT;
|
|
273
|
-
const rightCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "right", true));
|
|
274
|
-
rightCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.RIGHT;
|
|
275
|
-
const frontCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "front", true));
|
|
276
|
-
frontCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT;
|
|
277
|
-
const backCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "back", true));
|
|
278
|
-
backCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.BACK;
|
|
279
|
-
}
|
|
280
|
-
if (createPerspective) {
|
|
281
|
-
const camera = this.createCamera(viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE, "perspective");
|
|
282
|
-
this.assignCamera(camera.id);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
deactivateCameraEvents() {
|
|
286
|
-
const cameras = this.cameras;
|
|
287
|
-
for (const c in cameras)
|
|
288
|
-
(cameras[c].controls).cameraControlsEventDistribution.deactivateCameraEvents();
|
|
289
|
-
}
|
|
290
|
-
removeCamera(id) {
|
|
291
|
-
const cameras = this.cameras;
|
|
292
|
-
const camera = cameras[id];
|
|
293
|
-
if (!camera)
|
|
294
|
-
return false;
|
|
295
|
-
camera.destroy();
|
|
296
|
-
if (camera.domEventListenerToken)
|
|
297
|
-
this._renderingEngine.domEventEngine.removeDomEventListener(camera.domEventListenerToken);
|
|
298
|
-
if (this._camera && this._camera.id === id)
|
|
299
|
-
this._camera = null;
|
|
300
|
-
delete cameras[id];
|
|
301
|
-
this._cameraNode.removeData(camera);
|
|
302
|
-
if (this._update)
|
|
303
|
-
this._update();
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
saveSettings(settingsEngine) {
|
|
307
|
-
settingsEngine.camera.loadDefaultCameras = this._loadDefaultCameras;
|
|
308
|
-
settingsEngine.settings.camera.cameraId = this._camera
|
|
309
|
-
? this._camera.id
|
|
310
|
-
: "perspective";
|
|
311
|
-
settingsEngine.settings.camera.cameras = {};
|
|
312
|
-
for (const c in this.cameras) {
|
|
313
|
-
const camera = this.cameras[c];
|
|
314
|
-
// don't save the default cameras
|
|
315
|
-
if (camera.isDefault)
|
|
316
|
-
continue;
|
|
317
|
-
if (camera.type === viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE) {
|
|
318
|
-
const controls = (camera.controls);
|
|
319
|
-
settingsEngine.camera.cameras[camera.id] = {
|
|
320
|
-
name: camera.name,
|
|
321
|
-
autoAdjust: camera.autoAdjust,
|
|
322
|
-
cameraMovementDuration: camera.cameraMovementDuration,
|
|
323
|
-
enableCameraControls: camera.enableCameraControls,
|
|
324
|
-
initialAutoAdjust: camera.initialAutoAdjust,
|
|
325
|
-
revertAtMouseUp: camera.revertAtMouseUp,
|
|
326
|
-
revertAtMouseUpDuration: camera.revertAtMouseUpDuration,
|
|
327
|
-
zoomExtentsFactor: camera.zoomExtentsFactor,
|
|
328
|
-
position: {
|
|
329
|
-
x: camera.defaultPosition[0],
|
|
330
|
-
y: camera.defaultPosition[1],
|
|
331
|
-
z: camera.defaultPosition[2],
|
|
332
|
-
},
|
|
333
|
-
target: {
|
|
334
|
-
x: camera.defaultTarget[0],
|
|
335
|
-
y: camera.defaultTarget[1],
|
|
336
|
-
z: camera.defaultTarget[2],
|
|
337
|
-
},
|
|
338
|
-
type: camera.type,
|
|
339
|
-
fov: camera.fov,
|
|
340
|
-
sceneRotation: {
|
|
341
|
-
x: camera.sceneRotation[0],
|
|
342
|
-
y: camera.sceneRotation[1],
|
|
343
|
-
},
|
|
344
|
-
controls: {
|
|
345
|
-
autoRotationSpeed: controls.autoRotationSpeed,
|
|
346
|
-
damping: controls.damping,
|
|
347
|
-
enableAutoRotation: controls.enableAutoRotation,
|
|
348
|
-
enableKeyPan: controls.enableKeyPan,
|
|
349
|
-
enablePan: controls.enablePan,
|
|
350
|
-
enableRotation: controls.enableRotation,
|
|
351
|
-
enableZoom: controls.enableZoom,
|
|
352
|
-
input: controls.input,
|
|
353
|
-
keyPanSpeed: controls.keyPanSpeed,
|
|
354
|
-
movementSmoothness: controls.movementSmoothness,
|
|
355
|
-
rotationSpeed: controls.rotationSpeed,
|
|
356
|
-
panSpeed: controls.panSpeed,
|
|
357
|
-
zoomSpeed: controls.zoomSpeed,
|
|
358
|
-
restrictions: {
|
|
359
|
-
position: {
|
|
360
|
-
cube: {
|
|
361
|
-
min: {
|
|
362
|
-
x: controls.cubePositionRestriction
|
|
363
|
-
.min[0],
|
|
364
|
-
y: controls.cubePositionRestriction
|
|
365
|
-
.min[1],
|
|
366
|
-
z: controls.cubePositionRestriction
|
|
367
|
-
.min[2],
|
|
368
|
-
},
|
|
369
|
-
max: {
|
|
370
|
-
x: controls.cubePositionRestriction
|
|
371
|
-
.max[0],
|
|
372
|
-
y: controls.cubePositionRestriction
|
|
373
|
-
.max[1],
|
|
374
|
-
z: controls.cubePositionRestriction
|
|
375
|
-
.max[2],
|
|
376
|
-
},
|
|
377
|
-
},
|
|
378
|
-
sphere: {
|
|
379
|
-
center: {
|
|
380
|
-
x: controls.spherePositionRestriction
|
|
381
|
-
.center[0],
|
|
382
|
-
y: controls.spherePositionRestriction
|
|
383
|
-
.center[1],
|
|
384
|
-
z: controls.spherePositionRestriction
|
|
385
|
-
.center[2],
|
|
386
|
-
},
|
|
387
|
-
radius: controls.spherePositionRestriction
|
|
388
|
-
.radius,
|
|
389
|
-
},
|
|
390
|
-
},
|
|
391
|
-
target: {
|
|
392
|
-
cube: {
|
|
393
|
-
min: {
|
|
394
|
-
x: controls.cubeTargetRestriction
|
|
395
|
-
.min[0],
|
|
396
|
-
y: controls.cubeTargetRestriction
|
|
397
|
-
.min[1],
|
|
398
|
-
z: controls.cubeTargetRestriction
|
|
399
|
-
.min[2],
|
|
400
|
-
},
|
|
401
|
-
max: {
|
|
402
|
-
x: controls.cubeTargetRestriction
|
|
403
|
-
.max[0],
|
|
404
|
-
y: controls.cubeTargetRestriction
|
|
405
|
-
.max[1],
|
|
406
|
-
z: controls.cubeTargetRestriction
|
|
407
|
-
.max[2],
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
sphere: {
|
|
411
|
-
center: {
|
|
412
|
-
x: controls.sphereTargetRestriction
|
|
413
|
-
.center[0],
|
|
414
|
-
y: controls.sphereTargetRestriction
|
|
415
|
-
.center[1],
|
|
416
|
-
z: controls.sphereTargetRestriction
|
|
417
|
-
.center[2],
|
|
418
|
-
},
|
|
419
|
-
radius: controls.sphereTargetRestriction
|
|
420
|
-
.radius,
|
|
421
|
-
},
|
|
422
|
-
},
|
|
423
|
-
rotation: controls.rotationRestriction,
|
|
424
|
-
zoom: controls.zoomRestriction,
|
|
425
|
-
},
|
|
426
|
-
enableAzimuthRotation: controls.enableAzimuthRotation,
|
|
427
|
-
enablePolarRotation: controls.enablePolarRotation,
|
|
428
|
-
enableObjectControls: controls.enableObjectControls,
|
|
429
|
-
enableTurntableControls: controls.enableTurntableControls,
|
|
430
|
-
turntableCenter: {
|
|
431
|
-
x: controls.turntableCenter[0],
|
|
432
|
-
y: controls.turntableCenter[1],
|
|
433
|
-
z: controls.turntableCenter[2],
|
|
434
|
-
},
|
|
435
|
-
objectControlsCenter: {
|
|
436
|
-
x: controls.objectControlsCenter[0],
|
|
437
|
-
y: controls.objectControlsCenter[1],
|
|
438
|
-
z: controls.objectControlsCenter[2],
|
|
439
|
-
},
|
|
440
|
-
},
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
if (settingsEngine.camera.cameras[camera.id]) {
|
|
445
|
-
const previousDirection = settingsEngine.camera.cameras[camera.id].type;
|
|
446
|
-
// if the direction changed, but the default position & target did not, there is an issue
|
|
447
|
-
if (previousDirection !== camera.type &&
|
|
448
|
-
settingsEngine.camera.cameras[camera.id].position.x ===
|
|
449
|
-
camera.defaultPosition[0] &&
|
|
450
|
-
settingsEngine.camera.cameras[camera.id].position.y ===
|
|
451
|
-
camera.defaultPosition[1] &&
|
|
452
|
-
settingsEngine.camera.cameras[camera.id].position.z ===
|
|
453
|
-
camera.defaultPosition[2] &&
|
|
454
|
-
settingsEngine.camera.cameras[camera.id].target.x ===
|
|
455
|
-
camera.defaultTarget[0] &&
|
|
456
|
-
settingsEngine.camera.cameras[camera.id].target.y ===
|
|
457
|
-
camera.defaultTarget[1] &&
|
|
458
|
-
settingsEngine.camera.cameras[camera.id].target.z ===
|
|
459
|
-
camera.defaultTarget[2]) {
|
|
460
|
-
camera.defaultPosition = gl_matrix_1.vec3.clone(camera.position);
|
|
461
|
-
camera.defaultTarget = gl_matrix_1.vec3.clone(camera.target);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
const controls = (camera.controls);
|
|
465
|
-
settingsEngine.camera.cameras[camera.id] = {
|
|
466
|
-
name: camera.name,
|
|
467
|
-
autoAdjust: camera.autoAdjust,
|
|
468
|
-
cameraMovementDuration: camera.cameraMovementDuration,
|
|
469
|
-
enableCameraControls: camera.enableCameraControls,
|
|
470
|
-
initialAutoAdjust: camera.initialAutoAdjust,
|
|
471
|
-
revertAtMouseUp: camera.revertAtMouseUp,
|
|
472
|
-
revertAtMouseUpDuration: camera.revertAtMouseUpDuration,
|
|
473
|
-
zoomExtentsFactor: camera.zoomExtentsFactor,
|
|
474
|
-
position: {
|
|
475
|
-
x: camera.defaultPosition[0],
|
|
476
|
-
y: camera.defaultPosition[1],
|
|
477
|
-
z: camera.defaultPosition[2],
|
|
478
|
-
},
|
|
479
|
-
target: {
|
|
480
|
-
x: camera.defaultTarget[0],
|
|
481
|
-
y: camera.defaultTarget[1],
|
|
482
|
-
z: camera.defaultTarget[2],
|
|
483
|
-
},
|
|
484
|
-
type: camera.direction,
|
|
485
|
-
sceneRotation: {
|
|
486
|
-
x: camera.sceneRotation[0],
|
|
487
|
-
y: camera.sceneRotation[1],
|
|
488
|
-
},
|
|
489
|
-
controls: {
|
|
490
|
-
autoRotationSpeed: controls.autoRotationSpeed,
|
|
491
|
-
damping: controls.damping,
|
|
492
|
-
enableAutoRotation: controls.enableAutoRotation,
|
|
493
|
-
enableKeyPan: controls.enableKeyPan,
|
|
494
|
-
enablePan: controls.enablePan,
|
|
495
|
-
enableRotation: controls.enableRotation,
|
|
496
|
-
enableZoom: controls.enableZoom,
|
|
497
|
-
input: controls.input,
|
|
498
|
-
keyPanSpeed: controls.keyPanSpeed,
|
|
499
|
-
movementSmoothness: controls.movementSmoothness,
|
|
500
|
-
rotationSpeed: controls.rotationSpeed,
|
|
501
|
-
panSpeed: controls.panSpeed,
|
|
502
|
-
zoomSpeed: controls.zoomSpeed,
|
|
503
|
-
restrictions: {
|
|
504
|
-
position: {
|
|
505
|
-
cube: {
|
|
506
|
-
min: {
|
|
507
|
-
x: controls.cubePositionRestriction
|
|
508
|
-
.min[0],
|
|
509
|
-
y: controls.cubePositionRestriction
|
|
510
|
-
.min[1],
|
|
511
|
-
z: controls.cubePositionRestriction
|
|
512
|
-
.min[2],
|
|
513
|
-
},
|
|
514
|
-
max: {
|
|
515
|
-
x: controls.cubePositionRestriction
|
|
516
|
-
.max[0],
|
|
517
|
-
y: controls.cubePositionRestriction
|
|
518
|
-
.max[1],
|
|
519
|
-
z: controls.cubePositionRestriction
|
|
520
|
-
.max[2],
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
|
-
sphere: {
|
|
524
|
-
center: {
|
|
525
|
-
x: controls.spherePositionRestriction
|
|
526
|
-
.center[0],
|
|
527
|
-
y: controls.spherePositionRestriction
|
|
528
|
-
.center[1],
|
|
529
|
-
z: controls.spherePositionRestriction
|
|
530
|
-
.center[2],
|
|
531
|
-
},
|
|
532
|
-
radius: controls.spherePositionRestriction
|
|
533
|
-
.radius,
|
|
534
|
-
},
|
|
535
|
-
},
|
|
536
|
-
target: {
|
|
537
|
-
cube: {
|
|
538
|
-
min: {
|
|
539
|
-
x: controls.cubeTargetRestriction
|
|
540
|
-
.min[0],
|
|
541
|
-
y: controls.cubeTargetRestriction
|
|
542
|
-
.min[1],
|
|
543
|
-
z: controls.cubeTargetRestriction
|
|
544
|
-
.min[2],
|
|
545
|
-
},
|
|
546
|
-
max: {
|
|
547
|
-
x: controls.cubeTargetRestriction
|
|
548
|
-
.max[0],
|
|
549
|
-
y: controls.cubeTargetRestriction
|
|
550
|
-
.max[1],
|
|
551
|
-
z: controls.cubeTargetRestriction
|
|
552
|
-
.max[2],
|
|
553
|
-
},
|
|
554
|
-
},
|
|
555
|
-
sphere: {
|
|
556
|
-
center: {
|
|
557
|
-
x: controls.sphereTargetRestriction
|
|
558
|
-
.center[0],
|
|
559
|
-
y: controls.sphereTargetRestriction
|
|
560
|
-
.center[1],
|
|
561
|
-
z: controls.sphereTargetRestriction
|
|
562
|
-
.center[2],
|
|
563
|
-
},
|
|
564
|
-
radius: controls.sphereTargetRestriction
|
|
565
|
-
.radius,
|
|
566
|
-
},
|
|
567
|
-
},
|
|
568
|
-
rotation: controls.rotationRestriction,
|
|
569
|
-
zoom: controls.zoomRestriction,
|
|
570
|
-
},
|
|
571
|
-
enableAzimuthRotation: controls.enableAzimuthRotation,
|
|
572
|
-
enablePolarRotation: controls.enablePolarRotation,
|
|
573
|
-
enableObjectControls: controls.enableObjectControls,
|
|
574
|
-
enableTurntableControls: controls.enableTurntableControls,
|
|
575
|
-
turntableCenter: {
|
|
576
|
-
x: controls.turntableCenter[0],
|
|
577
|
-
y: controls.turntableCenter[1],
|
|
578
|
-
z: controls.turntableCenter[2],
|
|
579
|
-
},
|
|
580
|
-
objectControlsCenter: {
|
|
581
|
-
x: controls.objectControlsCenter[0],
|
|
582
|
-
y: controls.objectControlsCenter[1],
|
|
583
|
-
z: controls.objectControlsCenter[2],
|
|
584
|
-
},
|
|
585
|
-
},
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
searchForNewCameras() {
|
|
591
|
-
const getCameraData = (node) => {
|
|
592
|
-
for (let i = 0; i < node.data.length; i++)
|
|
593
|
-
if (node.data[i] instanceof AbstractCamera_1.AbstractCamera &&
|
|
594
|
-
!this._cameras[node.data[i].id]) {
|
|
595
|
-
const camera = node.data[i];
|
|
596
|
-
if (camera.viewportId === this._renderingEngine.id)
|
|
597
|
-
this._cameras[camera.id] = camera;
|
|
598
|
-
}
|
|
599
|
-
for (let i = 0; i < node.children.length; i++)
|
|
600
|
-
getCameraData(node.children[i]);
|
|
601
|
-
};
|
|
602
|
-
getCameraData(this._tree.root);
|
|
603
|
-
if (this._update)
|
|
604
|
-
this._update();
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
exports.CameraEngine = CameraEngine;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CameraEngine = void 0;
|
|
4
|
+
const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
|
|
5
|
+
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
6
|
+
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
7
|
+
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
8
|
+
const gl_matrix_1 = require("gl-matrix");
|
|
9
|
+
const AbstractCamera_1 = require("./camera/AbstractCamera");
|
|
10
|
+
const OrthographicCamera_1 = require("./camera/OrthographicCamera");
|
|
11
|
+
const PerspectiveCamera_1 = require("./camera/PerspectiveCamera");
|
|
12
|
+
class CameraEngine {
|
|
13
|
+
constructor(_renderingEngine) {
|
|
14
|
+
this._renderingEngine = _renderingEngine;
|
|
15
|
+
this._cameraNode = new viewer_shared_node_tree_1.TreeNode("cameras");
|
|
16
|
+
this._cameras = {};
|
|
17
|
+
this._eventEngine = viewer_shared_services_1.EventEngine.instance;
|
|
18
|
+
this._logger = viewer_shared_services_1.Logger.instance;
|
|
19
|
+
this._stateEngine = viewer_shared_services_1.StateEngine.instance;
|
|
20
|
+
this._tree = viewer_shared_node_tree_1.Tree.instance;
|
|
21
|
+
this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
|
|
22
|
+
this._defaultCameraIds = [
|
|
23
|
+
"top",
|
|
24
|
+
"bottom",
|
|
25
|
+
"left",
|
|
26
|
+
"right",
|
|
27
|
+
"front",
|
|
28
|
+
"back",
|
|
29
|
+
];
|
|
30
|
+
this._camera = null;
|
|
31
|
+
this._loadDefaultCameras = true;
|
|
32
|
+
this._settingsApplied = false;
|
|
33
|
+
this._boundingBox = new viewer_shared_math_1.Box();
|
|
34
|
+
this._tree.root.addChild(this._cameraNode);
|
|
35
|
+
this._cameraNode.restrictViewports = [this._renderingEngine.id];
|
|
36
|
+
this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
|
|
37
|
+
const viewerEvent = e;
|
|
38
|
+
if (viewerEvent.viewportId === this._renderingEngine.id) {
|
|
39
|
+
this._boundingBox = new viewer_shared_math_1.Box(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max);
|
|
40
|
+
const cameras = this.cameras;
|
|
41
|
+
for (const c in cameras)
|
|
42
|
+
cameras[c].boundingBox = this._boundingBox.clone();
|
|
43
|
+
if (!this._boundingBox.isEmpty() && this.camera) {
|
|
44
|
+
// check if the at least a part of the bounding box is visible
|
|
45
|
+
// if not zoom to the bounding box
|
|
46
|
+
if (!this.camera.boundingSphereVisible(this._boundingBox.boundingSphere)) {
|
|
47
|
+
this.camera.zoomTo(this._boundingBox, {
|
|
48
|
+
duration: 0,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.VIEWPORT.VIEWPORT_UPDATED, (e) => {
|
|
55
|
+
const viewerEvent = e;
|
|
56
|
+
if (viewerEvent.viewportId === this._renderingEngine.id) {
|
|
57
|
+
this.searchForNewCameras();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
get camera() {
|
|
62
|
+
return this._camera;
|
|
63
|
+
}
|
|
64
|
+
get cameras() {
|
|
65
|
+
return this._cameras;
|
|
66
|
+
}
|
|
67
|
+
get loadDefaultCameras() {
|
|
68
|
+
return this._loadDefaultCameras;
|
|
69
|
+
}
|
|
70
|
+
set loadDefaultCameras(value) {
|
|
71
|
+
this._loadDefaultCameras = value;
|
|
72
|
+
if (value) {
|
|
73
|
+
// if the default cameras are not yet created, we create them
|
|
74
|
+
if (!this.hasDefaultCameras()) {
|
|
75
|
+
this.createDefaultCameras(true, false);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// check if there are currently default cameras and remove them
|
|
80
|
+
if (this.hasDefaultCameras()) {
|
|
81
|
+
for (const cameraId of this._defaultCameraIds) {
|
|
82
|
+
if (this._cameras[cameraId])
|
|
83
|
+
this.removeCamera(cameraId);
|
|
84
|
+
}
|
|
85
|
+
// check if the current camera is one of the default cameras
|
|
86
|
+
if (!this._camera) {
|
|
87
|
+
// check if there are other cameras available
|
|
88
|
+
const cameraKeys = Object.keys(this._cameras);
|
|
89
|
+
if (cameraKeys.length > 0) {
|
|
90
|
+
// if so, assign the first camera
|
|
91
|
+
this.assignCamera(cameraKeys[0]);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// create the perspective camera if no cameras are available
|
|
95
|
+
this.createDefaultCameras(false, true);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// if the current camera is one of the default cameras, we need to assign a new camera
|
|
100
|
+
if (this._defaultCameraIds.includes(this._camera.id)) {
|
|
101
|
+
// if the current camera is one of the default cameras, assign the first camera
|
|
102
|
+
const cameraKeys = Object.keys(this._cameras);
|
|
103
|
+
if (cameraKeys.length > 0) {
|
|
104
|
+
this.assignCamera(cameraKeys[0]);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// create the perspective camera if no cameras are available
|
|
108
|
+
this.createDefaultCameras(false, true);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
get update() {
|
|
116
|
+
return this._update;
|
|
117
|
+
}
|
|
118
|
+
set update(value) {
|
|
119
|
+
this._update = value;
|
|
120
|
+
}
|
|
121
|
+
activateCameraEvents() {
|
|
122
|
+
const cameras = this.cameras;
|
|
123
|
+
for (const c in cameras)
|
|
124
|
+
(cameras[c].controls).cameraControlsEventDistribution.activateCameraEvents();
|
|
125
|
+
}
|
|
126
|
+
hasDefaultCameras() {
|
|
127
|
+
let defaultCamerasInSettings = true;
|
|
128
|
+
for (const cameraId of this._defaultCameraIds) {
|
|
129
|
+
if (!this._cameras[cameraId]) {
|
|
130
|
+
defaultCamerasInSettings = false;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return defaultCamerasInSettings;
|
|
135
|
+
}
|
|
136
|
+
applySettings(settingsEngine) {
|
|
137
|
+
var _a, _b, _c, _d;
|
|
138
|
+
const cameras = this.cameras;
|
|
139
|
+
for (const c in cameras)
|
|
140
|
+
this.removeCamera(c);
|
|
141
|
+
/**
|
|
142
|
+
* Due to some inconsistency in the behavior of saving settings
|
|
143
|
+
* we save the orthographic default cameras, even if they were never changed.
|
|
144
|
+
* Now we check if the six cameras exist and were not change and if so, we never add them
|
|
145
|
+
*/
|
|
146
|
+
let defaultCamerasInSettings = true;
|
|
147
|
+
for (const cameraId of this._defaultCameraIds) {
|
|
148
|
+
if (settingsEngine.settings.camera.cameraId === cameraId) {
|
|
149
|
+
// the camera was set as the default, don't remove it
|
|
150
|
+
defaultCamerasInSettings = false;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
if (!settingsEngine.settings.camera.cameras[cameraId])
|
|
154
|
+
defaultCamerasInSettings = false;
|
|
155
|
+
}
|
|
156
|
+
for (const id in settingsEngine.settings.camera.cameras) {
|
|
157
|
+
const cameraSetting = settingsEngine.settings.camera.cameras[id];
|
|
158
|
+
if (cameraSetting.type === "perspective") {
|
|
159
|
+
this.createCamera(viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE, id);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
const isDefault = defaultCamerasInSettings &&
|
|
163
|
+
this._defaultCameraIds.includes(id);
|
|
164
|
+
const camera = this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, id, isDefault);
|
|
165
|
+
camera.direction =
|
|
166
|
+
cameraSetting.type;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (const c in cameras)
|
|
170
|
+
cameras[c].applySettings(settingsEngine);
|
|
171
|
+
this._loadDefaultCameras =
|
|
172
|
+
settingsEngine.settings.camera.loadDefaultCameras;
|
|
173
|
+
const cameraKeys = Object.keys(settingsEngine.settings.camera.cameras);
|
|
174
|
+
if (cameraKeys.length > 0) {
|
|
175
|
+
if (!settingsEngine.settings.camera.cameraId) {
|
|
176
|
+
this.assignCamera(cameraKeys[0]);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.assignCamera(settingsEngine.settings.camera.cameraId);
|
|
180
|
+
}
|
|
181
|
+
// create the default orthographic cameras if there are no cameras with the default names
|
|
182
|
+
if (!defaultCamerasInSettings &&
|
|
183
|
+
cameraKeys.every((key) => !this._defaultCameraIds.includes(key)))
|
|
184
|
+
this.createDefaultCameras(this._loadDefaultCameras, false);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.createDefaultCameras(this._loadDefaultCameras, true);
|
|
188
|
+
this.camera.applySettings(settingsEngine);
|
|
189
|
+
}
|
|
190
|
+
this._settingsApplied = true;
|
|
191
|
+
// If the camera is set to auto adjust, we call zoomTo once when the bounding box is available
|
|
192
|
+
// this is needed as the default position and target might not make sense if the model is loaded with a different modelState
|
|
193
|
+
// or different initial parameters
|
|
194
|
+
const sessionObj = Object.values(this._stateEngine.sessionEngines).find((s) => (s === null || s === void 0 ? void 0 : s.settingsEngine) === settingsEngine);
|
|
195
|
+
const zoomTo = !!(sessionObj === null || sessionObj === void 0 ? void 0 : sessionObj.sessionCreationDefinition.initialParameterValues) ||
|
|
196
|
+
!!(sessionObj === null || sessionObj === void 0 ? void 0 : sessionObj.sessionCreationDefinition.modelStateId);
|
|
197
|
+
if ((zoomTo && ((_a = this.camera) === null || _a === void 0 ? void 0 : _a.autoAdjust)) ||
|
|
198
|
+
((_b = this.camera) === null || _b === void 0 ? void 0 : _b.initialAutoAdjust) ||
|
|
199
|
+
this._renderingEngine.viewportCreationDefinition.initialAutoAdjust) {
|
|
200
|
+
// Use boundingBoxCreated which resolves immediately if the scene
|
|
201
|
+
// is already loaded (session-first), or once it appears (viewport-first).
|
|
202
|
+
(_c = this._stateEngine.viewportEngines[this._renderingEngine.id]) === null || _c === void 0 ? void 0 : _c.boundingBoxCreated.then(() => {
|
|
203
|
+
var _a;
|
|
204
|
+
(_a = this.camera) === null || _a === void 0 ? void 0 : _a.zoomTo(undefined, { duration: 0 });
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if ((_d = this.camera) === null || _d === void 0 ? void 0 : _d.autoAdjust) {
|
|
208
|
+
// Default: zoom only if the camera cannot see any part of the scene.
|
|
209
|
+
const token = this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
|
|
210
|
+
const viewerEvent = e;
|
|
211
|
+
if (viewerEvent.viewportId === this._renderingEngine.id) {
|
|
212
|
+
this._boundingBox = new viewer_shared_math_1.Box(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max);
|
|
213
|
+
if (this._boundingBox.isEmpty() || !this.camera)
|
|
214
|
+
return;
|
|
215
|
+
if (!this.camera.boundingSphereVisible(this._boundingBox.boundingSphere)) {
|
|
216
|
+
this.camera.zoomTo(this._boundingBox, {
|
|
217
|
+
duration: 0,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
this._eventEngine.removeListener(token);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (this._update)
|
|
225
|
+
this._update();
|
|
226
|
+
}
|
|
227
|
+
assignCamera(id) {
|
|
228
|
+
const camera = this.cameras[id];
|
|
229
|
+
if (!camera)
|
|
230
|
+
return false;
|
|
231
|
+
for (const c in this.cameras)
|
|
232
|
+
this.cameras[c].active = false;
|
|
233
|
+
this._camera = camera;
|
|
234
|
+
this._camera.active = true;
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
close() {
|
|
238
|
+
this._tree.root.removeChild(this._cameraNode);
|
|
239
|
+
}
|
|
240
|
+
createCamera(type, id, isDefault = false) {
|
|
241
|
+
const cameras = this.cameras;
|
|
242
|
+
const cameraId = id || this._uuidGenerator.create();
|
|
243
|
+
if (cameras[cameraId])
|
|
244
|
+
throw new viewer_shared_services_1.ShapeDiverViewerCameraError(`CameraEngine.createCamera: Camera (${type}) with this id (${cameraId}) already exists.`);
|
|
245
|
+
const initialAspectRatio = this._renderingEngine.canvas.parentNode
|
|
246
|
+
.clientWidth /
|
|
247
|
+
this._renderingEngine.canvas.parentNode
|
|
248
|
+
.clientHeight;
|
|
249
|
+
const camera = viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE === type
|
|
250
|
+
? new PerspectiveCamera_1.PerspectiveCamera(cameraId, undefined, initialAspectRatio, isDefault)
|
|
251
|
+
: new OrthographicCamera_1.OrthographicCamera(cameraId, undefined, isDefault);
|
|
252
|
+
camera.assignViewer(this._renderingEngine);
|
|
253
|
+
cameras[cameraId] = camera;
|
|
254
|
+
if (this._settingsApplied && this._renderingEngine.settingsEngine) {
|
|
255
|
+
camera.applySettings(this._renderingEngine.settingsEngine);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
camera.zoomTo(undefined, { duration: 0 });
|
|
259
|
+
}
|
|
260
|
+
this._cameraNode.addData(camera);
|
|
261
|
+
if (this._update)
|
|
262
|
+
this._update();
|
|
263
|
+
return camera;
|
|
264
|
+
}
|
|
265
|
+
createDefaultCameras(createOrthographic = true, createPerspective = true) {
|
|
266
|
+
if (createOrthographic) {
|
|
267
|
+
const topCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "top", true));
|
|
268
|
+
topCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.TOP;
|
|
269
|
+
const bottomCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "bottom", true));
|
|
270
|
+
bottomCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM;
|
|
271
|
+
const leftCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "left", true));
|
|
272
|
+
leftCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.LEFT;
|
|
273
|
+
const rightCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "right", true));
|
|
274
|
+
rightCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.RIGHT;
|
|
275
|
+
const frontCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "front", true));
|
|
276
|
+
frontCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT;
|
|
277
|
+
const backCamera = (this.createCamera(viewer_shared_types_1.CAMERA_TYPE.ORTHOGRAPHIC, "back", true));
|
|
278
|
+
backCamera.direction = viewer_shared_types_1.ORTHOGRAPHIC_CAMERA_DIRECTION.BACK;
|
|
279
|
+
}
|
|
280
|
+
if (createPerspective) {
|
|
281
|
+
const camera = this.createCamera(viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE, "perspective");
|
|
282
|
+
this.assignCamera(camera.id);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
deactivateCameraEvents() {
|
|
286
|
+
const cameras = this.cameras;
|
|
287
|
+
for (const c in cameras)
|
|
288
|
+
(cameras[c].controls).cameraControlsEventDistribution.deactivateCameraEvents();
|
|
289
|
+
}
|
|
290
|
+
removeCamera(id) {
|
|
291
|
+
const cameras = this.cameras;
|
|
292
|
+
const camera = cameras[id];
|
|
293
|
+
if (!camera)
|
|
294
|
+
return false;
|
|
295
|
+
camera.destroy();
|
|
296
|
+
if (camera.domEventListenerToken)
|
|
297
|
+
this._renderingEngine.domEventEngine.removeDomEventListener(camera.domEventListenerToken);
|
|
298
|
+
if (this._camera && this._camera.id === id)
|
|
299
|
+
this._camera = null;
|
|
300
|
+
delete cameras[id];
|
|
301
|
+
this._cameraNode.removeData(camera);
|
|
302
|
+
if (this._update)
|
|
303
|
+
this._update();
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
saveSettings(settingsEngine) {
|
|
307
|
+
settingsEngine.camera.loadDefaultCameras = this._loadDefaultCameras;
|
|
308
|
+
settingsEngine.settings.camera.cameraId = this._camera
|
|
309
|
+
? this._camera.id
|
|
310
|
+
: "perspective";
|
|
311
|
+
settingsEngine.settings.camera.cameras = {};
|
|
312
|
+
for (const c in this.cameras) {
|
|
313
|
+
const camera = this.cameras[c];
|
|
314
|
+
// don't save the default cameras
|
|
315
|
+
if (camera.isDefault)
|
|
316
|
+
continue;
|
|
317
|
+
if (camera.type === viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE) {
|
|
318
|
+
const controls = (camera.controls);
|
|
319
|
+
settingsEngine.camera.cameras[camera.id] = {
|
|
320
|
+
name: camera.name,
|
|
321
|
+
autoAdjust: camera.autoAdjust,
|
|
322
|
+
cameraMovementDuration: camera.cameraMovementDuration,
|
|
323
|
+
enableCameraControls: camera.enableCameraControls,
|
|
324
|
+
initialAutoAdjust: camera.initialAutoAdjust,
|
|
325
|
+
revertAtMouseUp: camera.revertAtMouseUp,
|
|
326
|
+
revertAtMouseUpDuration: camera.revertAtMouseUpDuration,
|
|
327
|
+
zoomExtentsFactor: camera.zoomExtentsFactor,
|
|
328
|
+
position: {
|
|
329
|
+
x: camera.defaultPosition[0],
|
|
330
|
+
y: camera.defaultPosition[1],
|
|
331
|
+
z: camera.defaultPosition[2],
|
|
332
|
+
},
|
|
333
|
+
target: {
|
|
334
|
+
x: camera.defaultTarget[0],
|
|
335
|
+
y: camera.defaultTarget[1],
|
|
336
|
+
z: camera.defaultTarget[2],
|
|
337
|
+
},
|
|
338
|
+
type: camera.type,
|
|
339
|
+
fov: camera.fov,
|
|
340
|
+
sceneRotation: {
|
|
341
|
+
x: camera.sceneRotation[0],
|
|
342
|
+
y: camera.sceneRotation[1],
|
|
343
|
+
},
|
|
344
|
+
controls: {
|
|
345
|
+
autoRotationSpeed: controls.autoRotationSpeed,
|
|
346
|
+
damping: controls.damping,
|
|
347
|
+
enableAutoRotation: controls.enableAutoRotation,
|
|
348
|
+
enableKeyPan: controls.enableKeyPan,
|
|
349
|
+
enablePan: controls.enablePan,
|
|
350
|
+
enableRotation: controls.enableRotation,
|
|
351
|
+
enableZoom: controls.enableZoom,
|
|
352
|
+
input: controls.input,
|
|
353
|
+
keyPanSpeed: controls.keyPanSpeed,
|
|
354
|
+
movementSmoothness: controls.movementSmoothness,
|
|
355
|
+
rotationSpeed: controls.rotationSpeed,
|
|
356
|
+
panSpeed: controls.panSpeed,
|
|
357
|
+
zoomSpeed: controls.zoomSpeed,
|
|
358
|
+
restrictions: {
|
|
359
|
+
position: {
|
|
360
|
+
cube: {
|
|
361
|
+
min: {
|
|
362
|
+
x: controls.cubePositionRestriction
|
|
363
|
+
.min[0],
|
|
364
|
+
y: controls.cubePositionRestriction
|
|
365
|
+
.min[1],
|
|
366
|
+
z: controls.cubePositionRestriction
|
|
367
|
+
.min[2],
|
|
368
|
+
},
|
|
369
|
+
max: {
|
|
370
|
+
x: controls.cubePositionRestriction
|
|
371
|
+
.max[0],
|
|
372
|
+
y: controls.cubePositionRestriction
|
|
373
|
+
.max[1],
|
|
374
|
+
z: controls.cubePositionRestriction
|
|
375
|
+
.max[2],
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
sphere: {
|
|
379
|
+
center: {
|
|
380
|
+
x: controls.spherePositionRestriction
|
|
381
|
+
.center[0],
|
|
382
|
+
y: controls.spherePositionRestriction
|
|
383
|
+
.center[1],
|
|
384
|
+
z: controls.spherePositionRestriction
|
|
385
|
+
.center[2],
|
|
386
|
+
},
|
|
387
|
+
radius: controls.spherePositionRestriction
|
|
388
|
+
.radius,
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
target: {
|
|
392
|
+
cube: {
|
|
393
|
+
min: {
|
|
394
|
+
x: controls.cubeTargetRestriction
|
|
395
|
+
.min[0],
|
|
396
|
+
y: controls.cubeTargetRestriction
|
|
397
|
+
.min[1],
|
|
398
|
+
z: controls.cubeTargetRestriction
|
|
399
|
+
.min[2],
|
|
400
|
+
},
|
|
401
|
+
max: {
|
|
402
|
+
x: controls.cubeTargetRestriction
|
|
403
|
+
.max[0],
|
|
404
|
+
y: controls.cubeTargetRestriction
|
|
405
|
+
.max[1],
|
|
406
|
+
z: controls.cubeTargetRestriction
|
|
407
|
+
.max[2],
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
sphere: {
|
|
411
|
+
center: {
|
|
412
|
+
x: controls.sphereTargetRestriction
|
|
413
|
+
.center[0],
|
|
414
|
+
y: controls.sphereTargetRestriction
|
|
415
|
+
.center[1],
|
|
416
|
+
z: controls.sphereTargetRestriction
|
|
417
|
+
.center[2],
|
|
418
|
+
},
|
|
419
|
+
radius: controls.sphereTargetRestriction
|
|
420
|
+
.radius,
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
rotation: controls.rotationRestriction,
|
|
424
|
+
zoom: controls.zoomRestriction,
|
|
425
|
+
},
|
|
426
|
+
enableAzimuthRotation: controls.enableAzimuthRotation,
|
|
427
|
+
enablePolarRotation: controls.enablePolarRotation,
|
|
428
|
+
enableObjectControls: controls.enableObjectControls,
|
|
429
|
+
enableTurntableControls: controls.enableTurntableControls,
|
|
430
|
+
turntableCenter: {
|
|
431
|
+
x: controls.turntableCenter[0],
|
|
432
|
+
y: controls.turntableCenter[1],
|
|
433
|
+
z: controls.turntableCenter[2],
|
|
434
|
+
},
|
|
435
|
+
objectControlsCenter: {
|
|
436
|
+
x: controls.objectControlsCenter[0],
|
|
437
|
+
y: controls.objectControlsCenter[1],
|
|
438
|
+
z: controls.objectControlsCenter[2],
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
if (settingsEngine.camera.cameras[camera.id]) {
|
|
445
|
+
const previousDirection = settingsEngine.camera.cameras[camera.id].type;
|
|
446
|
+
// if the direction changed, but the default position & target did not, there is an issue
|
|
447
|
+
if (previousDirection !== camera.type &&
|
|
448
|
+
settingsEngine.camera.cameras[camera.id].position.x ===
|
|
449
|
+
camera.defaultPosition[0] &&
|
|
450
|
+
settingsEngine.camera.cameras[camera.id].position.y ===
|
|
451
|
+
camera.defaultPosition[1] &&
|
|
452
|
+
settingsEngine.camera.cameras[camera.id].position.z ===
|
|
453
|
+
camera.defaultPosition[2] &&
|
|
454
|
+
settingsEngine.camera.cameras[camera.id].target.x ===
|
|
455
|
+
camera.defaultTarget[0] &&
|
|
456
|
+
settingsEngine.camera.cameras[camera.id].target.y ===
|
|
457
|
+
camera.defaultTarget[1] &&
|
|
458
|
+
settingsEngine.camera.cameras[camera.id].target.z ===
|
|
459
|
+
camera.defaultTarget[2]) {
|
|
460
|
+
camera.defaultPosition = gl_matrix_1.vec3.clone(camera.position);
|
|
461
|
+
camera.defaultTarget = gl_matrix_1.vec3.clone(camera.target);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const controls = (camera.controls);
|
|
465
|
+
settingsEngine.camera.cameras[camera.id] = {
|
|
466
|
+
name: camera.name,
|
|
467
|
+
autoAdjust: camera.autoAdjust,
|
|
468
|
+
cameraMovementDuration: camera.cameraMovementDuration,
|
|
469
|
+
enableCameraControls: camera.enableCameraControls,
|
|
470
|
+
initialAutoAdjust: camera.initialAutoAdjust,
|
|
471
|
+
revertAtMouseUp: camera.revertAtMouseUp,
|
|
472
|
+
revertAtMouseUpDuration: camera.revertAtMouseUpDuration,
|
|
473
|
+
zoomExtentsFactor: camera.zoomExtentsFactor,
|
|
474
|
+
position: {
|
|
475
|
+
x: camera.defaultPosition[0],
|
|
476
|
+
y: camera.defaultPosition[1],
|
|
477
|
+
z: camera.defaultPosition[2],
|
|
478
|
+
},
|
|
479
|
+
target: {
|
|
480
|
+
x: camera.defaultTarget[0],
|
|
481
|
+
y: camera.defaultTarget[1],
|
|
482
|
+
z: camera.defaultTarget[2],
|
|
483
|
+
},
|
|
484
|
+
type: camera.direction,
|
|
485
|
+
sceneRotation: {
|
|
486
|
+
x: camera.sceneRotation[0],
|
|
487
|
+
y: camera.sceneRotation[1],
|
|
488
|
+
},
|
|
489
|
+
controls: {
|
|
490
|
+
autoRotationSpeed: controls.autoRotationSpeed,
|
|
491
|
+
damping: controls.damping,
|
|
492
|
+
enableAutoRotation: controls.enableAutoRotation,
|
|
493
|
+
enableKeyPan: controls.enableKeyPan,
|
|
494
|
+
enablePan: controls.enablePan,
|
|
495
|
+
enableRotation: controls.enableRotation,
|
|
496
|
+
enableZoom: controls.enableZoom,
|
|
497
|
+
input: controls.input,
|
|
498
|
+
keyPanSpeed: controls.keyPanSpeed,
|
|
499
|
+
movementSmoothness: controls.movementSmoothness,
|
|
500
|
+
rotationSpeed: controls.rotationSpeed,
|
|
501
|
+
panSpeed: controls.panSpeed,
|
|
502
|
+
zoomSpeed: controls.zoomSpeed,
|
|
503
|
+
restrictions: {
|
|
504
|
+
position: {
|
|
505
|
+
cube: {
|
|
506
|
+
min: {
|
|
507
|
+
x: controls.cubePositionRestriction
|
|
508
|
+
.min[0],
|
|
509
|
+
y: controls.cubePositionRestriction
|
|
510
|
+
.min[1],
|
|
511
|
+
z: controls.cubePositionRestriction
|
|
512
|
+
.min[2],
|
|
513
|
+
},
|
|
514
|
+
max: {
|
|
515
|
+
x: controls.cubePositionRestriction
|
|
516
|
+
.max[0],
|
|
517
|
+
y: controls.cubePositionRestriction
|
|
518
|
+
.max[1],
|
|
519
|
+
z: controls.cubePositionRestriction
|
|
520
|
+
.max[2],
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
sphere: {
|
|
524
|
+
center: {
|
|
525
|
+
x: controls.spherePositionRestriction
|
|
526
|
+
.center[0],
|
|
527
|
+
y: controls.spherePositionRestriction
|
|
528
|
+
.center[1],
|
|
529
|
+
z: controls.spherePositionRestriction
|
|
530
|
+
.center[2],
|
|
531
|
+
},
|
|
532
|
+
radius: controls.spherePositionRestriction
|
|
533
|
+
.radius,
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
target: {
|
|
537
|
+
cube: {
|
|
538
|
+
min: {
|
|
539
|
+
x: controls.cubeTargetRestriction
|
|
540
|
+
.min[0],
|
|
541
|
+
y: controls.cubeTargetRestriction
|
|
542
|
+
.min[1],
|
|
543
|
+
z: controls.cubeTargetRestriction
|
|
544
|
+
.min[2],
|
|
545
|
+
},
|
|
546
|
+
max: {
|
|
547
|
+
x: controls.cubeTargetRestriction
|
|
548
|
+
.max[0],
|
|
549
|
+
y: controls.cubeTargetRestriction
|
|
550
|
+
.max[1],
|
|
551
|
+
z: controls.cubeTargetRestriction
|
|
552
|
+
.max[2],
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
sphere: {
|
|
556
|
+
center: {
|
|
557
|
+
x: controls.sphereTargetRestriction
|
|
558
|
+
.center[0],
|
|
559
|
+
y: controls.sphereTargetRestriction
|
|
560
|
+
.center[1],
|
|
561
|
+
z: controls.sphereTargetRestriction
|
|
562
|
+
.center[2],
|
|
563
|
+
},
|
|
564
|
+
radius: controls.sphereTargetRestriction
|
|
565
|
+
.radius,
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
rotation: controls.rotationRestriction,
|
|
569
|
+
zoom: controls.zoomRestriction,
|
|
570
|
+
},
|
|
571
|
+
enableAzimuthRotation: controls.enableAzimuthRotation,
|
|
572
|
+
enablePolarRotation: controls.enablePolarRotation,
|
|
573
|
+
enableObjectControls: controls.enableObjectControls,
|
|
574
|
+
enableTurntableControls: controls.enableTurntableControls,
|
|
575
|
+
turntableCenter: {
|
|
576
|
+
x: controls.turntableCenter[0],
|
|
577
|
+
y: controls.turntableCenter[1],
|
|
578
|
+
z: controls.turntableCenter[2],
|
|
579
|
+
},
|
|
580
|
+
objectControlsCenter: {
|
|
581
|
+
x: controls.objectControlsCenter[0],
|
|
582
|
+
y: controls.objectControlsCenter[1],
|
|
583
|
+
z: controls.objectControlsCenter[2],
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
searchForNewCameras() {
|
|
591
|
+
const getCameraData = (node) => {
|
|
592
|
+
for (let i = 0; i < node.data.length; i++)
|
|
593
|
+
if (node.data[i] instanceof AbstractCamera_1.AbstractCamera &&
|
|
594
|
+
!this._cameras[node.data[i].id]) {
|
|
595
|
+
const camera = node.data[i];
|
|
596
|
+
if (camera.viewportId === this._renderingEngine.id)
|
|
597
|
+
this._cameras[camera.id] = camera;
|
|
598
|
+
}
|
|
599
|
+
for (let i = 0; i < node.children.length; i++)
|
|
600
|
+
getCameraData(node.children[i]);
|
|
601
|
+
};
|
|
602
|
+
getCameraData(this._tree.root);
|
|
603
|
+
if (this._update)
|
|
604
|
+
this._update();
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
exports.CameraEngine = CameraEngine;
|
|
608
608
|
//# sourceMappingURL=CameraEngine.js.map
|