@shapediver/viewer.rendering-engine.camera-engine 3.16.8 → 3.16.10

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.
Files changed (60) hide show
  1. package/dist/implementation/CameraEngine.d.ts +42 -42
  2. package/dist/implementation/CameraEngine.js +607 -607
  3. package/dist/implementation/CameraEngine.js.map +1 -1
  4. package/dist/implementation/camera/AbstractCamera.d.ts +90 -90
  5. package/dist/implementation/camera/AbstractCamera.js +354 -354
  6. package/dist/implementation/camera/AbstractCamera.js.map +1 -1
  7. package/dist/implementation/camera/OrthographicCamera.d.ts +37 -37
  8. package/dist/implementation/camera/OrthographicCamera.js +268 -268
  9. package/dist/implementation/camera/OrthographicCamera.js.map +1 -1
  10. package/dist/implementation/camera/PerspectiveCamera.d.ts +28 -28
  11. package/dist/implementation/camera/PerspectiveCamera.js +250 -250
  12. package/dist/implementation/camera/PerspectiveCamera.js.map +1 -1
  13. package/dist/implementation/controls/AbstractCameraControls.d.ts +217 -217
  14. package/dist/implementation/controls/AbstractCameraControls.js +635 -635
  15. package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
  16. package/dist/implementation/controls/CameraControlsEventDistribution.d.ts +39 -39
  17. package/dist/implementation/controls/CameraControlsEventDistribution.d.ts.map +1 -1
  18. package/dist/implementation/controls/CameraControlsEventDistribution.js +287 -287
  19. package/dist/implementation/controls/CameraControlsEventDistribution.js.map +1 -1
  20. package/dist/implementation/controls/CameraControlsLogic.d.ts +36 -36
  21. package/dist/implementation/controls/CameraControlsLogic.js +530 -530
  22. package/dist/implementation/controls/CameraControlsLogic.js.map +1 -1
  23. package/dist/implementation/controls/OrthographicCameraControls.d.ts +7 -7
  24. package/dist/implementation/controls/OrthographicCameraControls.js +34 -34
  25. package/dist/implementation/controls/PerspectiveCameraControls.d.ts +7 -7
  26. package/dist/implementation/controls/PerspectiveCameraControls.js +34 -34
  27. package/dist/implementation/interpolation/CameraInterpolationManager.d.ts +22 -22
  28. package/dist/implementation/interpolation/CameraInterpolationManager.js +165 -155
  29. package/dist/implementation/interpolation/CameraInterpolationManager.js.map +1 -1
  30. package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.d.ts +36 -36
  31. package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.js +57 -57
  32. package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.d.ts +26 -26
  33. package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.js +31 -31
  34. package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.d.ts +35 -35
  35. package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js +45 -45
  36. package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js.map +1 -1
  37. package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.d.ts +26 -26
  38. package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.js +31 -31
  39. package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.d.ts +32 -32
  40. package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.js +42 -42
  41. package/dist/index.d.ts +16 -16
  42. package/dist/index.js +18 -18
  43. package/dist/interfaces/ICameraEngine.d.ts +12 -12
  44. package/dist/interfaces/ICameraEngine.js +3 -3
  45. package/dist/interfaces/camera/ICamera.d.ts +47 -47
  46. package/dist/interfaces/camera/ICamera.js +2 -2
  47. package/dist/interfaces/camera/IOrthographicCamera.d.ts +8 -8
  48. package/dist/interfaces/camera/IOrthographicCamera.js +3 -3
  49. package/dist/interfaces/camera/IPerspectiveCamera.d.ts +7 -7
  50. package/dist/interfaces/camera/IPerspectiveCamera.js +2 -2
  51. package/dist/interfaces/controls/ICameraControls.d.ts +105 -105
  52. package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
  53. package/dist/interfaces/controls/ICameraControls.js +3 -3
  54. package/dist/interfaces/controls/ICameraControlsEventDistribution.d.ts +6 -6
  55. package/dist/interfaces/controls/ICameraControlsEventDistribution.js +2 -2
  56. package/dist/interfaces/controls/ICameraControlsLogic.d.ts +14 -14
  57. package/dist/interfaces/controls/ICameraControlsLogic.js +2 -2
  58. package/dist/interfaces/interpolation/ICameraInterpolation.d.ts +11 -11
  59. package/dist/interfaces/interpolation/ICameraInterpolation.js +2 -2
  60. package/package.json +8 -8
@@ -1,355 +1,355 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
- };
16
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
17
- if (kind === "m") throw new TypeError("Private method is not writable");
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
19
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
20
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
21
- };
22
- var _AbstractCamera_active, _AbstractCamera_autoAdjust, _AbstractCamera_cameraMovementDuration, _AbstractCamera_defaultPosition, _AbstractCamera_defaultTarget, _AbstractCamera_domEventListenerToken, _AbstractCamera_enableCameraControls, _AbstractCamera_eventListenerSceneCreatedToken, _AbstractCamera_eventListenerViewportUpdatedToken, _AbstractCamera_far, _AbstractCamera_initialAutoAdjust, _AbstractCamera_name, _AbstractCamera_near, _AbstractCamera_node, _AbstractCamera_order, _AbstractCamera_revertAtMouseUp, _AbstractCamera_revertAtMouseUpDuration, _AbstractCamera_sceneRotation, _AbstractCamera_useNodeData, _AbstractCamera_zoomExtentsFactor;
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.AbstractCamera = void 0;
25
- const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
26
- const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
27
- const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
28
- const gl_matrix_1 = require("gl-matrix");
29
- class AbstractCamera extends viewer_shared_node_tree_1.AbstractTreeNodeData {
30
- constructor(_id, _type, version, _isDefault = false) {
31
- super(_id, version);
32
- this._id = _id;
33
- this._type = _type;
34
- this._isDefault = _isDefault;
35
- _AbstractCamera_active.set(this, false);
36
- _AbstractCamera_autoAdjust.set(this, true);
37
- _AbstractCamera_cameraMovementDuration.set(this, 800);
38
- _AbstractCamera_defaultPosition.set(this, gl_matrix_1.vec3.create());
39
- _AbstractCamera_defaultTarget.set(this, gl_matrix_1.vec3.create());
40
- _AbstractCamera_domEventListenerToken.set(this, void 0);
41
- _AbstractCamera_enableCameraControls.set(this, true);
42
- _AbstractCamera_eventListenerSceneCreatedToken.set(this, void 0);
43
- _AbstractCamera_eventListenerViewportUpdatedToken.set(this, void 0);
44
- _AbstractCamera_far.set(this, 1000);
45
- _AbstractCamera_initialAutoAdjust.set(this, false);
46
- _AbstractCamera_name.set(this, void 0);
47
- _AbstractCamera_near.set(this, 1);
48
- _AbstractCamera_node.set(this, void 0);
49
- _AbstractCamera_order.set(this, void 0);
50
- _AbstractCamera_revertAtMouseUp.set(this, false);
51
- _AbstractCamera_revertAtMouseUpDuration.set(this, 800);
52
- _AbstractCamera_sceneRotation.set(this, gl_matrix_1.vec2.create());
53
- _AbstractCamera_useNodeData.set(this, false);
54
- _AbstractCamera_zoomExtentsFactor.set(this, 1);
55
- this._eventEngine = viewer_shared_services_1.EventEngine.instance;
56
- this._stateEngine = viewer_shared_services_1.StateEngine.instance;
57
- this._boundingBox = new viewer_shared_math_1.Box();
58
- this._position = gl_matrix_1.vec3.create();
59
- this._target = gl_matrix_1.vec3.create();
60
- }
61
- get active() {
62
- return __classPrivateFieldGet(this, _AbstractCamera_active, "f");
63
- }
64
- set active(value) {
65
- __classPrivateFieldSet(this, _AbstractCamera_active, value, "f");
66
- }
67
- get autoAdjust() {
68
- return __classPrivateFieldGet(this, _AbstractCamera_autoAdjust, "f");
69
- }
70
- set autoAdjust(value) {
71
- __classPrivateFieldSet(this, _AbstractCamera_autoAdjust, value, "f");
72
- }
73
- set boundingBox(value) {
74
- this._boundingBox = value;
75
- }
76
- get cameraMovementDuration() {
77
- return __classPrivateFieldGet(this, _AbstractCamera_cameraMovementDuration, "f");
78
- }
79
- set cameraMovementDuration(value) {
80
- __classPrivateFieldSet(this, _AbstractCamera_cameraMovementDuration, value, "f");
81
- }
82
- get controls() {
83
- return this._controls;
84
- }
85
- get defaultPosition() {
86
- return __classPrivateFieldGet(this, _AbstractCamera_defaultPosition, "f");
87
- }
88
- set defaultPosition(value) {
89
- __classPrivateFieldSet(this, _AbstractCamera_defaultPosition, value, "f");
90
- }
91
- get defaultTarget() {
92
- return __classPrivateFieldGet(this, _AbstractCamera_defaultTarget, "f");
93
- }
94
- set defaultTarget(value) {
95
- __classPrivateFieldSet(this, _AbstractCamera_defaultTarget, value, "f");
96
- }
97
- get domEventListenerToken() {
98
- return __classPrivateFieldGet(this, _AbstractCamera_domEventListenerToken, "f");
99
- }
100
- set domEventListenerToken(value) {
101
- __classPrivateFieldSet(this, _AbstractCamera_domEventListenerToken, value, "f");
102
- }
103
- get enableCameraControls() {
104
- return __classPrivateFieldGet(this, _AbstractCamera_enableCameraControls, "f");
105
- }
106
- set enableCameraControls(value) {
107
- __classPrivateFieldSet(this, _AbstractCamera_enableCameraControls, value, "f");
108
- }
109
- get far() {
110
- return __classPrivateFieldGet(this, _AbstractCamera_far, "f");
111
- }
112
- set far(value) {
113
- __classPrivateFieldSet(this, _AbstractCamera_far, value, "f");
114
- }
115
- get id() {
116
- return this._id;
117
- }
118
- get initialAutoAdjust() {
119
- return __classPrivateFieldGet(this, _AbstractCamera_initialAutoAdjust, "f");
120
- }
121
- set initialAutoAdjust(value) {
122
- __classPrivateFieldSet(this, _AbstractCamera_initialAutoAdjust, value, "f");
123
- }
124
- get isDefault() {
125
- return this._isDefault;
126
- }
127
- get name() {
128
- return __classPrivateFieldGet(this, _AbstractCamera_name, "f");
129
- }
130
- set name(value) {
131
- __classPrivateFieldSet(this, _AbstractCamera_name, value, "f");
132
- }
133
- get near() {
134
- return __classPrivateFieldGet(this, _AbstractCamera_near, "f");
135
- }
136
- set near(value) {
137
- __classPrivateFieldSet(this, _AbstractCamera_near, value, "f");
138
- }
139
- get node() {
140
- return __classPrivateFieldGet(this, _AbstractCamera_node, "f");
141
- }
142
- set node(value) {
143
- __classPrivateFieldSet(this, _AbstractCamera_node, value, "f");
144
- }
145
- get order() {
146
- return __classPrivateFieldGet(this, _AbstractCamera_order, "f");
147
- }
148
- set order(value) {
149
- __classPrivateFieldSet(this, _AbstractCamera_order, value, "f");
150
- }
151
- get position() {
152
- return this._position;
153
- }
154
- set position(value) {
155
- this._position = value;
156
- this._controls.position = value;
157
- }
158
- get revertAtMouseUp() {
159
- return __classPrivateFieldGet(this, _AbstractCamera_revertAtMouseUp, "f");
160
- }
161
- set revertAtMouseUp(value) {
162
- __classPrivateFieldSet(this, _AbstractCamera_revertAtMouseUp, value, "f");
163
- }
164
- get revertAtMouseUpDuration() {
165
- return __classPrivateFieldGet(this, _AbstractCamera_revertAtMouseUpDuration, "f");
166
- }
167
- set revertAtMouseUpDuration(value) {
168
- __classPrivateFieldSet(this, _AbstractCamera_revertAtMouseUpDuration, value, "f");
169
- }
170
- get sceneRotation() {
171
- return __classPrivateFieldGet(this, _AbstractCamera_sceneRotation, "f");
172
- }
173
- set sceneRotation(value) {
174
- __classPrivateFieldSet(this, _AbstractCamera_sceneRotation, value, "f");
175
- }
176
- get target() {
177
- return this._target;
178
- }
179
- set target(value) {
180
- this._target = value;
181
- this._controls.target = value;
182
- }
183
- get type() {
184
- return this._type;
185
- }
186
- get useNodeData() {
187
- return __classPrivateFieldGet(this, _AbstractCamera_useNodeData, "f");
188
- }
189
- set useNodeData(value) {
190
- __classPrivateFieldSet(this, _AbstractCamera_useNodeData, value, "f");
191
- }
192
- get viewportId() {
193
- return this._viewportId;
194
- }
195
- get zoomExtentsFactor() {
196
- return __classPrivateFieldGet(this, _AbstractCamera_zoomExtentsFactor, "f");
197
- }
198
- set zoomExtentsFactor(value) {
199
- __classPrivateFieldSet(this, _AbstractCamera_zoomExtentsFactor, value, "f");
200
- }
201
- animate(path, options) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- if (path.length === 0)
204
- return Promise.resolve(false);
205
- if (!options)
206
- options = {};
207
- options.duration =
208
- options.duration >= 0
209
- ? options.duration
210
- : this.cameraMovementDuration;
211
- const res = yield this._controls.animate(path, options);
212
- if (res) {
213
- this._position = this._controls.position;
214
- this._target = this._controls.target;
215
- }
216
- return res;
217
- });
218
- }
219
- boundingSphereVisible(sphere) {
220
- const projectionMatrix = this.getProjectionMatrix(sphere);
221
- // if we cannot calculate the projection matrix, we assume the sphere is visible
222
- if (!projectionMatrix)
223
- return true;
224
- // Calculate view matrix from camera position and target
225
- const viewMatrix = this.getViewMatrix();
226
- // Combine view and projection matrices to get view-projection matrix
227
- const viewProjectionMatrix = gl_matrix_1.mat4.create();
228
- gl_matrix_1.mat4.multiply(viewProjectionMatrix, projectionMatrix, viewMatrix);
229
- const planes = this.getFrustumPlanes(viewProjectionMatrix);
230
- for (let i = 0; i < 6; i++) {
231
- const plane = planes[i];
232
- const distance = gl_matrix_1.vec3.dot([plane[0], plane[1], plane[2]], sphere.center) +
233
- plane[3];
234
- if (distance < -sphere.radius) {
235
- return false;
236
- }
237
- }
238
- return true;
239
- }
240
- destroy() {
241
- if (__classPrivateFieldGet(this, _AbstractCamera_eventListenerSceneCreatedToken, "f"))
242
- this._eventEngine.removeListener(__classPrivateFieldGet(this, _AbstractCamera_eventListenerSceneCreatedToken, "f"));
243
- __classPrivateFieldSet(this, _AbstractCamera_eventListenerSceneCreatedToken, undefined, "f");
244
- if (__classPrivateFieldGet(this, _AbstractCamera_eventListenerViewportUpdatedToken, "f"))
245
- this._eventEngine.removeListener(__classPrivateFieldGet(this, _AbstractCamera_eventListenerViewportUpdatedToken, "f"));
246
- __classPrivateFieldSet(this, _AbstractCamera_eventListenerViewportUpdatedToken, undefined, "f");
247
- }
248
- reset(options) {
249
- if (this.defaultPosition[0] === 0 &&
250
- this.defaultPosition[1] === 0 &&
251
- this.defaultPosition[2] === 0 &&
252
- this.defaultTarget[0] === 0 &&
253
- this.defaultTarget[1] === 0 &&
254
- this.defaultTarget[2] === 0) {
255
- return this.zoomTo(undefined, options);
256
- }
257
- else {
258
- return this.set(gl_matrix_1.vec3.clone(this.defaultPosition), gl_matrix_1.vec3.clone(this.defaultTarget), options);
259
- }
260
- }
261
- set(position, target, options) {
262
- return __awaiter(this, void 0, void 0, function* () {
263
- if (!options)
264
- options = {};
265
- options.duration =
266
- options.duration >= 0
267
- ? options.duration
268
- : this.cameraMovementDuration;
269
- const res = yield this._controls.animate([
270
- {
271
- position: gl_matrix_1.vec3.clone(this.position),
272
- target: gl_matrix_1.vec3.clone(this.target),
273
- },
274
- { position, target },
275
- ], options);
276
- if (res) {
277
- this._position = this._controls.position;
278
- this._target = this._controls.target;
279
- }
280
- return res;
281
- });
282
- }
283
- update(time) {
284
- if (this.useNodeData && this.node && this._viewportId) {
285
- return true;
286
- }
287
- else {
288
- const { position, target, sceneRotation } = this._controls.update(time);
289
- let changed = true;
290
- if (gl_matrix_1.vec3.equals(position, this.position) &&
291
- gl_matrix_1.vec3.equals(target, this.target))
292
- changed = false;
293
- this.position = gl_matrix_1.vec3.clone(position);
294
- this.target = gl_matrix_1.vec3.clone(target);
295
- this.sceneRotation = gl_matrix_1.vec2.clone(sceneRotation);
296
- return changed;
297
- }
298
- }
299
- zoomTo(zoomTarget, options) {
300
- const { position, target } = this.calculateZoomTo(zoomTarget);
301
- return this.set(position, target, options);
302
- }
303
- assignViewerInternal(viewportId) {
304
- this._viewportId = viewportId;
305
- this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, () => __awaiter(this, void 0, void 0, function* () {
306
- if (__classPrivateFieldGet(this, _AbstractCamera_autoAdjust, "f") === true) {
307
- const innerListenerToken = this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.VIEWPORT.VIEWPORT_UPDATED, () => __awaiter(this, void 0, void 0, function* () {
308
- this.zoomTo();
309
- this._eventEngine.removeListener(innerListenerToken);
310
- }));
311
- }
312
- }));
313
- }
314
- getFrustumPlanes(projectionMatrix) {
315
- const planes = [];
316
- for (let i = 0; i < 6; i++) {
317
- const plane = gl_matrix_1.vec4.create();
318
- switch (i) {
319
- case 0:
320
- gl_matrix_1.vec4.set(plane, projectionMatrix[3] - projectionMatrix[0], projectionMatrix[7] - projectionMatrix[4], projectionMatrix[11] - projectionMatrix[8], projectionMatrix[15] - projectionMatrix[12]);
321
- break; // Left
322
- case 1:
323
- gl_matrix_1.vec4.set(plane, projectionMatrix[3] + projectionMatrix[0], projectionMatrix[7] + projectionMatrix[4], projectionMatrix[11] + projectionMatrix[8], projectionMatrix[15] + projectionMatrix[12]);
324
- break; // Right
325
- case 2:
326
- gl_matrix_1.vec4.set(plane, projectionMatrix[3] + projectionMatrix[1], projectionMatrix[7] + projectionMatrix[5], projectionMatrix[11] + projectionMatrix[9], projectionMatrix[15] + projectionMatrix[13]);
327
- break; // Top
328
- case 3:
329
- gl_matrix_1.vec4.set(plane, projectionMatrix[3] - projectionMatrix[1], projectionMatrix[7] - projectionMatrix[5], projectionMatrix[11] - projectionMatrix[9], projectionMatrix[15] - projectionMatrix[13]);
330
- break; // Bottom
331
- case 4:
332
- gl_matrix_1.vec4.set(plane, projectionMatrix[3] - projectionMatrix[2], projectionMatrix[7] - projectionMatrix[6], projectionMatrix[11] - projectionMatrix[10], projectionMatrix[15] - projectionMatrix[14]);
333
- break; // Near
334
- case 5:
335
- gl_matrix_1.vec4.set(plane, projectionMatrix[3] + projectionMatrix[2], projectionMatrix[7] + projectionMatrix[6], projectionMatrix[11] + projectionMatrix[10], projectionMatrix[15] + projectionMatrix[14]);
336
- break; // Far
337
- }
338
- const length = Math.sqrt(Math.pow(plane[0], 2) + Math.pow(plane[1], 2) + Math.pow(plane[2], 2));
339
- if (length !== 0) {
340
- gl_matrix_1.vec4.scale(plane, plane, 1 / length);
341
- }
342
- planes.push(plane);
343
- }
344
- return planes;
345
- }
346
- getViewMatrix() {
347
- const viewMatrix = gl_matrix_1.mat4.create();
348
- const up = gl_matrix_1.vec3.fromValues(0, 0, 1);
349
- gl_matrix_1.mat4.lookAt(viewMatrix, this._position, this._target, up);
350
- return viewMatrix;
351
- }
352
- }
353
- exports.AbstractCamera = AbstractCamera;
354
- _AbstractCamera_active = new WeakMap(), _AbstractCamera_autoAdjust = new WeakMap(), _AbstractCamera_cameraMovementDuration = new WeakMap(), _AbstractCamera_defaultPosition = new WeakMap(), _AbstractCamera_defaultTarget = new WeakMap(), _AbstractCamera_domEventListenerToken = new WeakMap(), _AbstractCamera_enableCameraControls = new WeakMap(), _AbstractCamera_eventListenerSceneCreatedToken = new WeakMap(), _AbstractCamera_eventListenerViewportUpdatedToken = new WeakMap(), _AbstractCamera_far = new WeakMap(), _AbstractCamera_initialAutoAdjust = new WeakMap(), _AbstractCamera_name = new WeakMap(), _AbstractCamera_near = new WeakMap(), _AbstractCamera_node = new WeakMap(), _AbstractCamera_order = new WeakMap(), _AbstractCamera_revertAtMouseUp = new WeakMap(), _AbstractCamera_revertAtMouseUpDuration = new WeakMap(), _AbstractCamera_sceneRotation = new WeakMap(), _AbstractCamera_useNodeData = new WeakMap(), _AbstractCamera_zoomExtentsFactor = new WeakMap();
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
17
+ if (kind === "m") throw new TypeError("Private method is not writable");
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
20
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
21
+ };
22
+ var _AbstractCamera_active, _AbstractCamera_autoAdjust, _AbstractCamera_cameraMovementDuration, _AbstractCamera_defaultPosition, _AbstractCamera_defaultTarget, _AbstractCamera_domEventListenerToken, _AbstractCamera_enableCameraControls, _AbstractCamera_eventListenerSceneCreatedToken, _AbstractCamera_eventListenerViewportUpdatedToken, _AbstractCamera_far, _AbstractCamera_initialAutoAdjust, _AbstractCamera_name, _AbstractCamera_near, _AbstractCamera_node, _AbstractCamera_order, _AbstractCamera_revertAtMouseUp, _AbstractCamera_revertAtMouseUpDuration, _AbstractCamera_sceneRotation, _AbstractCamera_useNodeData, _AbstractCamera_zoomExtentsFactor;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.AbstractCamera = void 0;
25
+ const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
26
+ const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
27
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
28
+ const gl_matrix_1 = require("gl-matrix");
29
+ class AbstractCamera extends viewer_shared_node_tree_1.AbstractTreeNodeData {
30
+ constructor(_id, _type, version, _isDefault = false) {
31
+ super(_id, version);
32
+ this._id = _id;
33
+ this._type = _type;
34
+ this._isDefault = _isDefault;
35
+ _AbstractCamera_active.set(this, false);
36
+ _AbstractCamera_autoAdjust.set(this, true);
37
+ _AbstractCamera_cameraMovementDuration.set(this, 800);
38
+ _AbstractCamera_defaultPosition.set(this, gl_matrix_1.vec3.create());
39
+ _AbstractCamera_defaultTarget.set(this, gl_matrix_1.vec3.create());
40
+ _AbstractCamera_domEventListenerToken.set(this, void 0);
41
+ _AbstractCamera_enableCameraControls.set(this, true);
42
+ _AbstractCamera_eventListenerSceneCreatedToken.set(this, void 0);
43
+ _AbstractCamera_eventListenerViewportUpdatedToken.set(this, void 0);
44
+ _AbstractCamera_far.set(this, 1000);
45
+ _AbstractCamera_initialAutoAdjust.set(this, false);
46
+ _AbstractCamera_name.set(this, void 0);
47
+ _AbstractCamera_near.set(this, 1);
48
+ _AbstractCamera_node.set(this, void 0);
49
+ _AbstractCamera_order.set(this, void 0);
50
+ _AbstractCamera_revertAtMouseUp.set(this, false);
51
+ _AbstractCamera_revertAtMouseUpDuration.set(this, 800);
52
+ _AbstractCamera_sceneRotation.set(this, gl_matrix_1.vec2.create());
53
+ _AbstractCamera_useNodeData.set(this, false);
54
+ _AbstractCamera_zoomExtentsFactor.set(this, 1);
55
+ this._eventEngine = viewer_shared_services_1.EventEngine.instance;
56
+ this._stateEngine = viewer_shared_services_1.StateEngine.instance;
57
+ this._boundingBox = new viewer_shared_math_1.Box();
58
+ this._position = gl_matrix_1.vec3.create();
59
+ this._target = gl_matrix_1.vec3.create();
60
+ }
61
+ get active() {
62
+ return __classPrivateFieldGet(this, _AbstractCamera_active, "f");
63
+ }
64
+ set active(value) {
65
+ __classPrivateFieldSet(this, _AbstractCamera_active, value, "f");
66
+ }
67
+ get autoAdjust() {
68
+ return __classPrivateFieldGet(this, _AbstractCamera_autoAdjust, "f");
69
+ }
70
+ set autoAdjust(value) {
71
+ __classPrivateFieldSet(this, _AbstractCamera_autoAdjust, value, "f");
72
+ }
73
+ set boundingBox(value) {
74
+ this._boundingBox = value;
75
+ }
76
+ get cameraMovementDuration() {
77
+ return __classPrivateFieldGet(this, _AbstractCamera_cameraMovementDuration, "f");
78
+ }
79
+ set cameraMovementDuration(value) {
80
+ __classPrivateFieldSet(this, _AbstractCamera_cameraMovementDuration, value, "f");
81
+ }
82
+ get controls() {
83
+ return this._controls;
84
+ }
85
+ get defaultPosition() {
86
+ return __classPrivateFieldGet(this, _AbstractCamera_defaultPosition, "f");
87
+ }
88
+ set defaultPosition(value) {
89
+ __classPrivateFieldSet(this, _AbstractCamera_defaultPosition, value, "f");
90
+ }
91
+ get defaultTarget() {
92
+ return __classPrivateFieldGet(this, _AbstractCamera_defaultTarget, "f");
93
+ }
94
+ set defaultTarget(value) {
95
+ __classPrivateFieldSet(this, _AbstractCamera_defaultTarget, value, "f");
96
+ }
97
+ get domEventListenerToken() {
98
+ return __classPrivateFieldGet(this, _AbstractCamera_domEventListenerToken, "f");
99
+ }
100
+ set domEventListenerToken(value) {
101
+ __classPrivateFieldSet(this, _AbstractCamera_domEventListenerToken, value, "f");
102
+ }
103
+ get enableCameraControls() {
104
+ return __classPrivateFieldGet(this, _AbstractCamera_enableCameraControls, "f");
105
+ }
106
+ set enableCameraControls(value) {
107
+ __classPrivateFieldSet(this, _AbstractCamera_enableCameraControls, value, "f");
108
+ }
109
+ get far() {
110
+ return __classPrivateFieldGet(this, _AbstractCamera_far, "f");
111
+ }
112
+ set far(value) {
113
+ __classPrivateFieldSet(this, _AbstractCamera_far, value, "f");
114
+ }
115
+ get id() {
116
+ return this._id;
117
+ }
118
+ get initialAutoAdjust() {
119
+ return __classPrivateFieldGet(this, _AbstractCamera_initialAutoAdjust, "f");
120
+ }
121
+ set initialAutoAdjust(value) {
122
+ __classPrivateFieldSet(this, _AbstractCamera_initialAutoAdjust, value, "f");
123
+ }
124
+ get isDefault() {
125
+ return this._isDefault;
126
+ }
127
+ get name() {
128
+ return __classPrivateFieldGet(this, _AbstractCamera_name, "f");
129
+ }
130
+ set name(value) {
131
+ __classPrivateFieldSet(this, _AbstractCamera_name, value, "f");
132
+ }
133
+ get near() {
134
+ return __classPrivateFieldGet(this, _AbstractCamera_near, "f");
135
+ }
136
+ set near(value) {
137
+ __classPrivateFieldSet(this, _AbstractCamera_near, value, "f");
138
+ }
139
+ get node() {
140
+ return __classPrivateFieldGet(this, _AbstractCamera_node, "f");
141
+ }
142
+ set node(value) {
143
+ __classPrivateFieldSet(this, _AbstractCamera_node, value, "f");
144
+ }
145
+ get order() {
146
+ return __classPrivateFieldGet(this, _AbstractCamera_order, "f");
147
+ }
148
+ set order(value) {
149
+ __classPrivateFieldSet(this, _AbstractCamera_order, value, "f");
150
+ }
151
+ get position() {
152
+ return this._position;
153
+ }
154
+ set position(value) {
155
+ this._position = value;
156
+ this._controls.position = value;
157
+ }
158
+ get revertAtMouseUp() {
159
+ return __classPrivateFieldGet(this, _AbstractCamera_revertAtMouseUp, "f");
160
+ }
161
+ set revertAtMouseUp(value) {
162
+ __classPrivateFieldSet(this, _AbstractCamera_revertAtMouseUp, value, "f");
163
+ }
164
+ get revertAtMouseUpDuration() {
165
+ return __classPrivateFieldGet(this, _AbstractCamera_revertAtMouseUpDuration, "f");
166
+ }
167
+ set revertAtMouseUpDuration(value) {
168
+ __classPrivateFieldSet(this, _AbstractCamera_revertAtMouseUpDuration, value, "f");
169
+ }
170
+ get sceneRotation() {
171
+ return __classPrivateFieldGet(this, _AbstractCamera_sceneRotation, "f");
172
+ }
173
+ set sceneRotation(value) {
174
+ __classPrivateFieldSet(this, _AbstractCamera_sceneRotation, value, "f");
175
+ }
176
+ get target() {
177
+ return this._target;
178
+ }
179
+ set target(value) {
180
+ this._target = value;
181
+ this._controls.target = value;
182
+ }
183
+ get type() {
184
+ return this._type;
185
+ }
186
+ get useNodeData() {
187
+ return __classPrivateFieldGet(this, _AbstractCamera_useNodeData, "f");
188
+ }
189
+ set useNodeData(value) {
190
+ __classPrivateFieldSet(this, _AbstractCamera_useNodeData, value, "f");
191
+ }
192
+ get viewportId() {
193
+ return this._viewportId;
194
+ }
195
+ get zoomExtentsFactor() {
196
+ return __classPrivateFieldGet(this, _AbstractCamera_zoomExtentsFactor, "f");
197
+ }
198
+ set zoomExtentsFactor(value) {
199
+ __classPrivateFieldSet(this, _AbstractCamera_zoomExtentsFactor, value, "f");
200
+ }
201
+ animate(path, options) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ if (path.length === 0)
204
+ return Promise.resolve(false);
205
+ if (!options)
206
+ options = {};
207
+ options.duration =
208
+ options.duration >= 0
209
+ ? options.duration
210
+ : this.cameraMovementDuration;
211
+ const res = yield this._controls.animate(path, options);
212
+ if (res) {
213
+ this._position = this._controls.position;
214
+ this._target = this._controls.target;
215
+ }
216
+ return res;
217
+ });
218
+ }
219
+ boundingSphereVisible(sphere) {
220
+ const projectionMatrix = this.getProjectionMatrix(sphere);
221
+ // if we cannot calculate the projection matrix, we assume the sphere is visible
222
+ if (!projectionMatrix)
223
+ return true;
224
+ // Calculate view matrix from camera position and target
225
+ const viewMatrix = this.getViewMatrix();
226
+ // Combine view and projection matrices to get view-projection matrix
227
+ const viewProjectionMatrix = gl_matrix_1.mat4.create();
228
+ gl_matrix_1.mat4.multiply(viewProjectionMatrix, projectionMatrix, viewMatrix);
229
+ const planes = this.getFrustumPlanes(viewProjectionMatrix);
230
+ for (let i = 0; i < 6; i++) {
231
+ const plane = planes[i];
232
+ const distance = gl_matrix_1.vec3.dot([plane[0], plane[1], plane[2]], sphere.center) +
233
+ plane[3];
234
+ if (distance < -sphere.radius) {
235
+ return false;
236
+ }
237
+ }
238
+ return true;
239
+ }
240
+ destroy() {
241
+ if (__classPrivateFieldGet(this, _AbstractCamera_eventListenerSceneCreatedToken, "f"))
242
+ this._eventEngine.removeListener(__classPrivateFieldGet(this, _AbstractCamera_eventListenerSceneCreatedToken, "f"));
243
+ __classPrivateFieldSet(this, _AbstractCamera_eventListenerSceneCreatedToken, undefined, "f");
244
+ if (__classPrivateFieldGet(this, _AbstractCamera_eventListenerViewportUpdatedToken, "f"))
245
+ this._eventEngine.removeListener(__classPrivateFieldGet(this, _AbstractCamera_eventListenerViewportUpdatedToken, "f"));
246
+ __classPrivateFieldSet(this, _AbstractCamera_eventListenerViewportUpdatedToken, undefined, "f");
247
+ }
248
+ reset(options) {
249
+ if (this.defaultPosition[0] === 0 &&
250
+ this.defaultPosition[1] === 0 &&
251
+ this.defaultPosition[2] === 0 &&
252
+ this.defaultTarget[0] === 0 &&
253
+ this.defaultTarget[1] === 0 &&
254
+ this.defaultTarget[2] === 0) {
255
+ return this.zoomTo(undefined, options);
256
+ }
257
+ else {
258
+ return this.set(gl_matrix_1.vec3.clone(this.defaultPosition), gl_matrix_1.vec3.clone(this.defaultTarget), options);
259
+ }
260
+ }
261
+ set(position, target, options) {
262
+ return __awaiter(this, void 0, void 0, function* () {
263
+ if (!options)
264
+ options = {};
265
+ options.duration =
266
+ options.duration >= 0
267
+ ? options.duration
268
+ : this.cameraMovementDuration;
269
+ const res = yield this._controls.animate([
270
+ {
271
+ position: gl_matrix_1.vec3.clone(this.position),
272
+ target: gl_matrix_1.vec3.clone(this.target),
273
+ },
274
+ { position, target },
275
+ ], options);
276
+ if (res) {
277
+ this._position = this._controls.position;
278
+ this._target = this._controls.target;
279
+ }
280
+ return res;
281
+ });
282
+ }
283
+ update(time) {
284
+ if (this.useNodeData && this.node && this._viewportId) {
285
+ return true;
286
+ }
287
+ else {
288
+ const { position, target, sceneRotation } = this._controls.update(time);
289
+ let changed = true;
290
+ if (gl_matrix_1.vec3.equals(position, this.position) &&
291
+ gl_matrix_1.vec3.equals(target, this.target))
292
+ changed = false;
293
+ this.position = gl_matrix_1.vec3.clone(position);
294
+ this.target = gl_matrix_1.vec3.clone(target);
295
+ this.sceneRotation = gl_matrix_1.vec2.clone(sceneRotation);
296
+ return changed;
297
+ }
298
+ }
299
+ zoomTo(zoomTarget, options) {
300
+ const { position, target } = this.calculateZoomTo(zoomTarget);
301
+ return this.set(position, target, options);
302
+ }
303
+ assignViewerInternal(viewportId) {
304
+ this._viewportId = viewportId;
305
+ this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, () => __awaiter(this, void 0, void 0, function* () {
306
+ if (__classPrivateFieldGet(this, _AbstractCamera_autoAdjust, "f") === true) {
307
+ const innerListenerToken = this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.VIEWPORT.VIEWPORT_UPDATED, () => __awaiter(this, void 0, void 0, function* () {
308
+ this.zoomTo();
309
+ this._eventEngine.removeListener(innerListenerToken);
310
+ }));
311
+ }
312
+ }));
313
+ }
314
+ getFrustumPlanes(projectionMatrix) {
315
+ const planes = [];
316
+ for (let i = 0; i < 6; i++) {
317
+ const plane = gl_matrix_1.vec4.create();
318
+ switch (i) {
319
+ case 0:
320
+ gl_matrix_1.vec4.set(plane, projectionMatrix[3] - projectionMatrix[0], projectionMatrix[7] - projectionMatrix[4], projectionMatrix[11] - projectionMatrix[8], projectionMatrix[15] - projectionMatrix[12]);
321
+ break; // Left
322
+ case 1:
323
+ gl_matrix_1.vec4.set(plane, projectionMatrix[3] + projectionMatrix[0], projectionMatrix[7] + projectionMatrix[4], projectionMatrix[11] + projectionMatrix[8], projectionMatrix[15] + projectionMatrix[12]);
324
+ break; // Right
325
+ case 2:
326
+ gl_matrix_1.vec4.set(plane, projectionMatrix[3] + projectionMatrix[1], projectionMatrix[7] + projectionMatrix[5], projectionMatrix[11] + projectionMatrix[9], projectionMatrix[15] + projectionMatrix[13]);
327
+ break; // Top
328
+ case 3:
329
+ gl_matrix_1.vec4.set(plane, projectionMatrix[3] - projectionMatrix[1], projectionMatrix[7] - projectionMatrix[5], projectionMatrix[11] - projectionMatrix[9], projectionMatrix[15] - projectionMatrix[13]);
330
+ break; // Bottom
331
+ case 4:
332
+ gl_matrix_1.vec4.set(plane, projectionMatrix[3] - projectionMatrix[2], projectionMatrix[7] - projectionMatrix[6], projectionMatrix[11] - projectionMatrix[10], projectionMatrix[15] - projectionMatrix[14]);
333
+ break; // Near
334
+ case 5:
335
+ gl_matrix_1.vec4.set(plane, projectionMatrix[3] + projectionMatrix[2], projectionMatrix[7] + projectionMatrix[6], projectionMatrix[11] + projectionMatrix[10], projectionMatrix[15] + projectionMatrix[14]);
336
+ break; // Far
337
+ }
338
+ const length = Math.sqrt(Math.pow(plane[0], 2) + Math.pow(plane[1], 2) + Math.pow(plane[2], 2));
339
+ if (length !== 0) {
340
+ gl_matrix_1.vec4.scale(plane, plane, 1 / length);
341
+ }
342
+ planes.push(plane);
343
+ }
344
+ return planes;
345
+ }
346
+ getViewMatrix() {
347
+ const viewMatrix = gl_matrix_1.mat4.create();
348
+ const up = gl_matrix_1.vec3.fromValues(0, 0, 1);
349
+ gl_matrix_1.mat4.lookAt(viewMatrix, this._position, this._target, up);
350
+ return viewMatrix;
351
+ }
352
+ }
353
+ exports.AbstractCamera = AbstractCamera;
354
+ _AbstractCamera_active = new WeakMap(), _AbstractCamera_autoAdjust = new WeakMap(), _AbstractCamera_cameraMovementDuration = new WeakMap(), _AbstractCamera_defaultPosition = new WeakMap(), _AbstractCamera_defaultTarget = new WeakMap(), _AbstractCamera_domEventListenerToken = new WeakMap(), _AbstractCamera_enableCameraControls = new WeakMap(), _AbstractCamera_eventListenerSceneCreatedToken = new WeakMap(), _AbstractCamera_eventListenerViewportUpdatedToken = new WeakMap(), _AbstractCamera_far = new WeakMap(), _AbstractCamera_initialAutoAdjust = new WeakMap(), _AbstractCamera_name = new WeakMap(), _AbstractCamera_near = new WeakMap(), _AbstractCamera_node = new WeakMap(), _AbstractCamera_order = new WeakMap(), _AbstractCamera_revertAtMouseUp = new WeakMap(), _AbstractCamera_revertAtMouseUpDuration = new WeakMap(), _AbstractCamera_sceneRotation = new WeakMap(), _AbstractCamera_useNodeData = new WeakMap(), _AbstractCamera_zoomExtentsFactor = new WeakMap();
355
355
  //# sourceMappingURL=AbstractCamera.js.map