@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,29 +1,29 @@
1
- import { IRenderingEngine } from "@shapediver/viewer.rendering-engine.rendering-engine";
2
- import { Box, Sphere } from "@shapediver/viewer.shared.math";
3
- import { SettingsEngine } from "@shapediver/viewer.shared.services";
4
- import { mat4, vec2, vec3 } from "gl-matrix";
5
- import { IPerspectiveCamera } from "../../interfaces/camera/IPerspectiveCamera";
6
- import { ICameraControls } from "../../interfaces/controls/ICameraControls";
7
- import { AbstractCamera } from "./AbstractCamera";
8
- export declare class PerspectiveCamera extends AbstractCamera implements IPerspectiveCamera {
9
- #private;
10
- protected _controls: ICameraControls;
11
- constructor(id: string, version?: string, initialAspect?: number, isDefault?: boolean);
12
- get aspect(): number | undefined;
13
- set aspect(value: number | undefined);
14
- get controls(): ICameraControls;
15
- set controls(value: ICameraControls);
16
- get fov(): number;
17
- set fov(value: number);
18
- applySettings(settingsEngine: SettingsEngine): void;
19
- assignViewer(renderingEngine: IRenderingEngine): void;
20
- calculateZoomTo(zoomTarget?: Box, startingPosition?: vec3, startingTarget?: vec3): {
21
- position: vec3;
22
- target: vec3;
23
- };
24
- clone(): IPerspectiveCamera;
25
- project(pos: vec3, position?: vec3, target?: vec3): vec2;
26
- unproject(pos: vec3, position?: vec3, target?: vec3): vec3;
27
- protected getProjectionMatrix(sphere: Sphere): mat4 | undefined;
28
- }
1
+ import { IRenderingEngine } from "@shapediver/viewer.rendering-engine.rendering-engine";
2
+ import { Box, Sphere } from "@shapediver/viewer.shared.math";
3
+ import { SettingsEngine } from "@shapediver/viewer.shared.services";
4
+ import { mat4, vec2, vec3 } from "gl-matrix";
5
+ import { IPerspectiveCamera } from "../../interfaces/camera/IPerspectiveCamera";
6
+ import { ICameraControls } from "../../interfaces/controls/ICameraControls";
7
+ import { AbstractCamera } from "./AbstractCamera";
8
+ export declare class PerspectiveCamera extends AbstractCamera implements IPerspectiveCamera {
9
+ #private;
10
+ protected _controls: ICameraControls;
11
+ constructor(id: string, version?: string, initialAspect?: number, isDefault?: boolean);
12
+ get aspect(): number | undefined;
13
+ set aspect(value: number | undefined);
14
+ get controls(): ICameraControls;
15
+ set controls(value: ICameraControls);
16
+ get fov(): number;
17
+ set fov(value: number);
18
+ applySettings(settingsEngine: SettingsEngine): void;
19
+ assignViewer(renderingEngine: IRenderingEngine): void;
20
+ calculateZoomTo(zoomTarget?: Box, startingPosition?: vec3, startingTarget?: vec3): {
21
+ position: vec3;
22
+ target: vec3;
23
+ };
24
+ clone(): IPerspectiveCamera;
25
+ project(pos: vec3, position?: vec3, target?: vec3): vec2;
26
+ unproject(pos: vec3, position?: vec3, target?: vec3): vec3;
27
+ protected getProjectionMatrix(sphere: Sphere): mat4 | undefined;
28
+ }
29
29
  //# sourceMappingURL=PerspectiveCamera.d.ts.map
@@ -1,251 +1,251 @@
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
- if (kind === "m") throw new TypeError("Private method is not writable");
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
- 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");
15
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
- };
17
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
- 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");
20
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
- };
22
- var _PerspectiveCamera_converter, _PerspectiveCamera_tree, _PerspectiveCamera_aspect, _PerspectiveCamera_domEventEngine, _PerspectiveCamera_fov;
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.PerspectiveCamera = 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 viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
29
- const gl_matrix_1 = require("gl-matrix");
30
- const PerspectiveCameraControls_1 = require("../controls/PerspectiveCameraControls");
31
- const AbstractCamera_1 = require("./AbstractCamera");
32
- class PerspectiveCamera extends AbstractCamera_1.AbstractCamera {
33
- // #endregion Properties (6)
34
- // #region Constructors (1)
35
- constructor(id, version, initialAspect, isDefault = false) {
36
- super(id, viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE, version, isDefault);
37
- // #region Properties (6)
38
- _PerspectiveCamera_converter.set(this, viewer_shared_services_1.Converter.instance);
39
- _PerspectiveCamera_tree.set(this, viewer_shared_node_tree_1.Tree.instance);
40
- _PerspectiveCamera_aspect.set(this, void 0);
41
- _PerspectiveCamera_domEventEngine.set(this, void 0);
42
- _PerspectiveCamera_fov.set(this, 60);
43
- __classPrivateFieldSet(this, _PerspectiveCamera_aspect, initialAspect, "f");
44
- this._controls = new PerspectiveCameraControls_1.PerspectiveCameraControls(this, true);
45
- }
46
- // #endregion Constructors (1)
47
- // #region Public Getters And Setters (6)
48
- get aspect() {
49
- return __classPrivateFieldGet(this, _PerspectiveCamera_aspect, "f");
50
- }
51
- set aspect(value) {
52
- __classPrivateFieldSet(this, _PerspectiveCamera_aspect, value, "f");
53
- }
54
- get controls() {
55
- return this._controls;
56
- }
57
- set controls(value) {
58
- this._controls = value;
59
- }
60
- get fov() {
61
- return __classPrivateFieldGet(this, _PerspectiveCamera_fov, "f");
62
- }
63
- set fov(value) {
64
- __classPrivateFieldSet(this, _PerspectiveCamera_fov, value, "f");
65
- }
66
- // #endregion Public Getters And Setters (6)
67
- // #region Public Methods (6)
68
- applySettings(settingsEngine) {
69
- var _a;
70
- const cameraSetting = (settingsEngine.camera.cameras[this.id]);
71
- if (cameraSetting) {
72
- this.name = cameraSetting.name;
73
- this.autoAdjust = cameraSetting.autoAdjust;
74
- this.cameraMovementDuration = cameraSetting.cameraMovementDuration;
75
- this.enableCameraControls = cameraSetting.enableCameraControls;
76
- this.initialAutoAdjust = cameraSetting.initialAutoAdjust;
77
- this.revertAtMouseUp = cameraSetting.revertAtMouseUp;
78
- this.revertAtMouseUpDuration =
79
- cameraSetting.revertAtMouseUpDuration;
80
- this.sceneRotation = gl_matrix_1.vec2.fromValues(cameraSetting.sceneRotation.x, cameraSetting.sceneRotation.y);
81
- this.zoomExtentsFactor = cameraSetting.zoomExtentsFactor;
82
- const position = __classPrivateFieldGet(this, _PerspectiveCamera_converter, "f").toVec3(cameraSetting.position);
83
- const target = __classPrivateFieldGet(this, _PerspectiveCamera_converter, "f").toVec3(cameraSetting.target);
84
- this.defaultPosition = gl_matrix_1.vec3.clone(position);
85
- this.defaultTarget = gl_matrix_1.vec3.clone(target);
86
- this.position = position;
87
- this.target = target;
88
- this.fov = cameraSetting.fov;
89
- }
90
- if (this.position[0] === this.target[0] &&
91
- this.position[1] === this.target[1] &&
92
- this.position[2] === this.target[2]) {
93
- if (this._viewportId) {
94
- (_a = this._stateEngine.viewportEngines[this._viewportId]) === null || _a === void 0 ? void 0 : _a.boundingBoxCreated.then(() => __awaiter(this, void 0, void 0, function* () {
95
- yield this.zoomTo(undefined, { duration: 0 });
96
- this.defaultPosition = gl_matrix_1.vec3.clone(this._controls.position);
97
- this.defaultTarget = gl_matrix_1.vec3.clone(this._controls.target);
98
- }));
99
- }
100
- }
101
- this._controls.applySettings(settingsEngine);
102
- }
103
- assignViewer(renderingEngine) {
104
- var _a;
105
- if (renderingEngine.closed)
106
- throw new viewer_shared_services_1.ShapeDiverViewerCameraError(`OrthographicCamera(${this.id}).assignViewer: Viewer with id ${renderingEngine.id} not found.`);
107
- this.assignViewerInternal(renderingEngine.id);
108
- this._controls.assignViewer(renderingEngine.id, renderingEngine.canvas);
109
- if (this.domEventListenerToken && __classPrivateFieldGet(this, _PerspectiveCamera_domEventEngine, "f"))
110
- __classPrivateFieldGet(this, _PerspectiveCamera_domEventEngine, "f").removeDomEventListener(this.domEventListenerToken);
111
- __classPrivateFieldSet(this, _PerspectiveCamera_domEventEngine, renderingEngine.domEventEngine, "f");
112
- this.domEventListenerToken = __classPrivateFieldGet(this, _PerspectiveCamera_domEventEngine, "f").addDomEventListener(this._controls
113
- .cameraControlsEventDistribution);
114
- this.boundingBox = __classPrivateFieldGet(this, _PerspectiveCamera_tree, "f").root.boundingBox.clone();
115
- (_a = this._stateEngine.viewportEngines[renderingEngine.id]) === null || _a === void 0 ? void 0 : _a.boundingBoxCreated.then(() => __awaiter(this, void 0, void 0, function* () {
116
- if (this.position[0] === this.target[0] &&
117
- this.position[1] === this.target[1] &&
118
- this.position[2] === this.target[2])
119
- yield this.zoomTo(undefined, { duration: 0 });
120
- }));
121
- }
122
- calculateZoomTo(zoomTarget, startingPosition = this.position, startingTarget = this.target) {
123
- let box;
124
- // Part 1 - calculate the bounding box that we should zoom to
125
- if (!zoomTarget) {
126
- // complete scene
127
- box = this._boundingBox.clone();
128
- }
129
- else {
130
- // specified Box
131
- box = zoomTarget.clone();
132
- }
133
- if (box.isEmpty())
134
- return { position: startingPosition, target: startingTarget };
135
- const invalidInput = startingPosition[0] === startingTarget[0] &&
136
- startingPosition[1] === startingTarget[1] &&
137
- startingPosition[2] === startingTarget[2];
138
- const target = gl_matrix_1.vec3.fromValues((box.max[0] + box.min[0]) / 2, (box.max[1] + box.min[1]) / 2, (box.max[2] + box.min[2]) / 2);
139
- // if the camera position and the target are the same, we set a corner position
140
- if (invalidInput)
141
- startingPosition = gl_matrix_1.vec3.fromValues(target[0], target[1] - 7.5, target[2] + 5);
142
- // extend box by the factor
143
- const boxDir = gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), box.max, target);
144
- gl_matrix_1.vec3.multiply(boxDir, boxDir, invalidInput
145
- ? gl_matrix_1.vec3.fromValues(2, 2, 2)
146
- : gl_matrix_1.vec3.fromValues(this.zoomExtentsFactor, this.zoomExtentsFactor, this.zoomExtentsFactor));
147
- box = new viewer_shared_math_1.Box(gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), target, boxDir), gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), target, boxDir));
148
- let direction = gl_matrix_1.vec3.create();
149
- if (invalidInput) {
150
- direction = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), target, startingPosition));
151
- }
152
- else {
153
- direction = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), startingTarget, startingPosition));
154
- }
155
- const cross = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(0, 0, 1), direction));
156
- const up = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), cross, direction));
157
- let position = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), target, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), direction, gl_matrix_1.vec3.fromValues(-0.00000001, -0.00000001, -0.00000001)));
158
- const points = [];
159
- points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.min[1], box.min[2]));
160
- points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.min[1], box.max[2]));
161
- points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.max[1], box.min[2]));
162
- points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.max[1], box.max[2]));
163
- points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.min[1], box.min[2]));
164
- points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.min[1], box.max[2]));
165
- points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.max[1], box.min[2]));
166
- points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.max[1], box.max[2]));
167
- const fovDown = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), cross, (this.fov / 2) * (Math.PI / 180))));
168
- const fovUp = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), cross, -(this.fov / 2) * (Math.PI / 180))));
169
- const aspect = invalidInput ? 1.5 : this.aspect || 1.5;
170
- const hFoV = 2 * Math.atan(Math.tan((this.fov * Math.PI) / 180 / 2) * aspect);
171
- const fovRight = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), up, hFoV / 2)));
172
- const fovLeft = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), up, -hFoV / 2)));
173
- const planeCross = new viewer_shared_math_1.Plane();
174
- planeCross.setFromNormalAndCoplanarPoint(gl_matrix_1.vec3.clone(cross), gl_matrix_1.vec3.clone(target));
175
- const planeUp = new viewer_shared_math_1.Plane();
176
- planeUp.setFromNormalAndCoplanarPoint(gl_matrix_1.vec3.clone(up), gl_matrix_1.vec3.clone(target));
177
- let distanceCamera = 0.0;
178
- for (let i = 0; i < points.length; i++) {
179
- let projected = planeCross.clampPoint(points[i]);
180
- let toP = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), projected, position));
181
- if (gl_matrix_1.vec3.dot(direction, fovDown) > gl_matrix_1.vec3.dot(direction, toP)) {
182
- const currentDir = gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.dot(fovDown, toP) > gl_matrix_1.vec3.dot(fovUp, toP)
183
- ? fovDown
184
- : fovUp, gl_matrix_1.vec3.fromValues(-1, -1, -1));
185
- const distance = planeUp.intersect(projected, currentDir);
186
- if (distance) {
187
- const cameraPoint = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), currentDir, gl_matrix_1.vec3.fromValues(distance, distance, distance)), projected);
188
- distanceCamera = Math.max(distanceCamera, gl_matrix_1.vec3.distance(target, cameraPoint));
189
- }
190
- }
191
- projected = planeUp.clampPoint(points[i]);
192
- toP = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), projected, position));
193
- if (gl_matrix_1.vec3.dot(direction, fovRight) > gl_matrix_1.vec3.dot(direction, toP)) {
194
- const currentDir = gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.dot(fovRight, toP) > gl_matrix_1.vec3.dot(fovLeft, toP)
195
- ? fovRight
196
- : fovLeft, gl_matrix_1.vec3.fromValues(-1, -1, -1));
197
- const distance = planeCross.intersect(projected, currentDir);
198
- if (distance) {
199
- const cameraPoint = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), currentDir, gl_matrix_1.vec3.fromValues(distance, distance, distance)), projected);
200
- distanceCamera = Math.max(distanceCamera, gl_matrix_1.vec3.distance(target, cameraPoint));
201
- }
202
- }
203
- }
204
- position = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), target, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), direction, gl_matrix_1.vec3.fromValues(-distanceCamera, -distanceCamera, -distanceCamera)));
205
- return {
206
- position,
207
- target,
208
- };
209
- }
210
- clone() {
211
- return new PerspectiveCamera(this.id, this.version, this.aspect);
212
- }
213
- project(pos, position = this.position, target = this.target) {
214
- const m = gl_matrix_1.mat4.targetTo(gl_matrix_1.mat4.create(), position, target, gl_matrix_1.vec3.fromValues(0, 0, 1));
215
- const aspect = this.aspect || 1.5;
216
- const p = gl_matrix_1.mat4.perspective(gl_matrix_1.mat4.create(), this.fov / (180 / Math.PI), aspect, this.near, this.far);
217
- let inverse = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), m);
218
- if (!inverse)
219
- inverse = gl_matrix_1.mat4.create();
220
- gl_matrix_1.vec3.transformMat4(pos, pos, inverse);
221
- gl_matrix_1.vec3.transformMat4(pos, pos, p);
222
- return gl_matrix_1.vec2.fromValues(pos[0], pos[1]);
223
- }
224
- unproject(pos, position = this.position, target = this.target) {
225
- const m = gl_matrix_1.mat4.targetTo(gl_matrix_1.mat4.create(), position, target, gl_matrix_1.vec3.fromValues(0, 0, 1));
226
- const aspect = this.aspect || 1.5;
227
- const p = gl_matrix_1.mat4.perspective(gl_matrix_1.mat4.create(), this.fov / (180 / Math.PI), aspect, this.near, this.far);
228
- let inverse = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), p);
229
- if (!inverse)
230
- inverse = gl_matrix_1.mat4.create();
231
- gl_matrix_1.vec3.transformMat4(pos, pos, inverse);
232
- gl_matrix_1.vec3.transformMat4(pos, pos, m);
233
- return gl_matrix_1.vec3.clone(pos);
234
- }
235
- // #endregion Public Methods (6)
236
- // #region Protected Methods (1)
237
- getProjectionMatrix(sphere) {
238
- if (!this.aspect || sphere.radius === 0)
239
- return;
240
- const far = this.fov < 10
241
- ? this.fov * 100.0 * 100 * sphere.radius
242
- : 100 * sphere.radius;
243
- const near = this.fov < 10
244
- ? this.fov * 100.0 * 0.01 * sphere.radius
245
- : 0.01 * sphere.radius;
246
- return gl_matrix_1.mat4.perspective(gl_matrix_1.mat4.create(), this.fov / (180 / Math.PI), this.aspect, near, far);
247
- }
248
- }
249
- exports.PerspectiveCamera = PerspectiveCamera;
250
- _PerspectiveCamera_converter = new WeakMap(), _PerspectiveCamera_tree = new WeakMap(), _PerspectiveCamera_aspect = new WeakMap(), _PerspectiveCamera_domEventEngine = new WeakMap(), _PerspectiveCamera_fov = 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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _PerspectiveCamera_converter, _PerspectiveCamera_tree, _PerspectiveCamera_aspect, _PerspectiveCamera_domEventEngine, _PerspectiveCamera_fov;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.PerspectiveCamera = 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 viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
29
+ const gl_matrix_1 = require("gl-matrix");
30
+ const PerspectiveCameraControls_1 = require("../controls/PerspectiveCameraControls");
31
+ const AbstractCamera_1 = require("./AbstractCamera");
32
+ class PerspectiveCamera extends AbstractCamera_1.AbstractCamera {
33
+ // #endregion Properties (6)
34
+ // #region Constructors (1)
35
+ constructor(id, version, initialAspect, isDefault = false) {
36
+ super(id, viewer_shared_types_1.CAMERA_TYPE.PERSPECTIVE, version, isDefault);
37
+ // #region Properties (6)
38
+ _PerspectiveCamera_converter.set(this, viewer_shared_services_1.Converter.instance);
39
+ _PerspectiveCamera_tree.set(this, viewer_shared_node_tree_1.Tree.instance);
40
+ _PerspectiveCamera_aspect.set(this, void 0);
41
+ _PerspectiveCamera_domEventEngine.set(this, void 0);
42
+ _PerspectiveCamera_fov.set(this, 60);
43
+ __classPrivateFieldSet(this, _PerspectiveCamera_aspect, initialAspect, "f");
44
+ this._controls = new PerspectiveCameraControls_1.PerspectiveCameraControls(this, true);
45
+ }
46
+ // #endregion Constructors (1)
47
+ // #region Public Getters And Setters (6)
48
+ get aspect() {
49
+ return __classPrivateFieldGet(this, _PerspectiveCamera_aspect, "f");
50
+ }
51
+ set aspect(value) {
52
+ __classPrivateFieldSet(this, _PerspectiveCamera_aspect, value, "f");
53
+ }
54
+ get controls() {
55
+ return this._controls;
56
+ }
57
+ set controls(value) {
58
+ this._controls = value;
59
+ }
60
+ get fov() {
61
+ return __classPrivateFieldGet(this, _PerspectiveCamera_fov, "f");
62
+ }
63
+ set fov(value) {
64
+ __classPrivateFieldSet(this, _PerspectiveCamera_fov, value, "f");
65
+ }
66
+ // #endregion Public Getters And Setters (6)
67
+ // #region Public Methods (6)
68
+ applySettings(settingsEngine) {
69
+ var _a;
70
+ const cameraSetting = (settingsEngine.camera.cameras[this.id]);
71
+ if (cameraSetting) {
72
+ this.name = cameraSetting.name;
73
+ this.autoAdjust = cameraSetting.autoAdjust;
74
+ this.cameraMovementDuration = cameraSetting.cameraMovementDuration;
75
+ this.enableCameraControls = cameraSetting.enableCameraControls;
76
+ this.initialAutoAdjust = cameraSetting.initialAutoAdjust;
77
+ this.revertAtMouseUp = cameraSetting.revertAtMouseUp;
78
+ this.revertAtMouseUpDuration =
79
+ cameraSetting.revertAtMouseUpDuration;
80
+ this.sceneRotation = gl_matrix_1.vec2.fromValues(cameraSetting.sceneRotation.x, cameraSetting.sceneRotation.y);
81
+ this.zoomExtentsFactor = cameraSetting.zoomExtentsFactor;
82
+ const position = __classPrivateFieldGet(this, _PerspectiveCamera_converter, "f").toVec3(cameraSetting.position);
83
+ const target = __classPrivateFieldGet(this, _PerspectiveCamera_converter, "f").toVec3(cameraSetting.target);
84
+ this.defaultPosition = gl_matrix_1.vec3.clone(position);
85
+ this.defaultTarget = gl_matrix_1.vec3.clone(target);
86
+ this.position = position;
87
+ this.target = target;
88
+ this.fov = cameraSetting.fov;
89
+ }
90
+ if (this.position[0] === this.target[0] &&
91
+ this.position[1] === this.target[1] &&
92
+ this.position[2] === this.target[2]) {
93
+ if (this._viewportId) {
94
+ (_a = this._stateEngine.viewportEngines[this._viewportId]) === null || _a === void 0 ? void 0 : _a.boundingBoxCreated.then(() => __awaiter(this, void 0, void 0, function* () {
95
+ yield this.zoomTo(undefined, { duration: 0 });
96
+ this.defaultPosition = gl_matrix_1.vec3.clone(this._controls.position);
97
+ this.defaultTarget = gl_matrix_1.vec3.clone(this._controls.target);
98
+ }));
99
+ }
100
+ }
101
+ this._controls.applySettings(settingsEngine);
102
+ }
103
+ assignViewer(renderingEngine) {
104
+ var _a;
105
+ if (renderingEngine.closed)
106
+ throw new viewer_shared_services_1.ShapeDiverViewerCameraError(`OrthographicCamera(${this.id}).assignViewer: Viewer with id ${renderingEngine.id} not found.`);
107
+ this.assignViewerInternal(renderingEngine.id);
108
+ this._controls.assignViewer(renderingEngine.id, renderingEngine.canvas);
109
+ if (this.domEventListenerToken && __classPrivateFieldGet(this, _PerspectiveCamera_domEventEngine, "f"))
110
+ __classPrivateFieldGet(this, _PerspectiveCamera_domEventEngine, "f").removeDomEventListener(this.domEventListenerToken);
111
+ __classPrivateFieldSet(this, _PerspectiveCamera_domEventEngine, renderingEngine.domEventEngine, "f");
112
+ this.domEventListenerToken = __classPrivateFieldGet(this, _PerspectiveCamera_domEventEngine, "f").addDomEventListener(this._controls
113
+ .cameraControlsEventDistribution);
114
+ this.boundingBox = __classPrivateFieldGet(this, _PerspectiveCamera_tree, "f").root.boundingBox.clone();
115
+ (_a = this._stateEngine.viewportEngines[renderingEngine.id]) === null || _a === void 0 ? void 0 : _a.boundingBoxCreated.then(() => __awaiter(this, void 0, void 0, function* () {
116
+ if (this.position[0] === this.target[0] &&
117
+ this.position[1] === this.target[1] &&
118
+ this.position[2] === this.target[2])
119
+ yield this.zoomTo(undefined, { duration: 0 });
120
+ }));
121
+ }
122
+ calculateZoomTo(zoomTarget, startingPosition = this.position, startingTarget = this.target) {
123
+ let box;
124
+ // Part 1 - calculate the bounding box that we should zoom to
125
+ if (!zoomTarget) {
126
+ // complete scene
127
+ box = this._boundingBox.clone();
128
+ }
129
+ else {
130
+ // specified Box
131
+ box = zoomTarget.clone();
132
+ }
133
+ if (box.isEmpty())
134
+ return { position: startingPosition, target: startingTarget };
135
+ const invalidInput = startingPosition[0] === startingTarget[0] &&
136
+ startingPosition[1] === startingTarget[1] &&
137
+ startingPosition[2] === startingTarget[2];
138
+ const target = gl_matrix_1.vec3.fromValues((box.max[0] + box.min[0]) / 2, (box.max[1] + box.min[1]) / 2, (box.max[2] + box.min[2]) / 2);
139
+ // if the camera position and the target are the same, we set a corner position
140
+ if (invalidInput)
141
+ startingPosition = gl_matrix_1.vec3.fromValues(target[0], target[1] - 7.5, target[2] + 5);
142
+ // extend box by the factor
143
+ const boxDir = gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), box.max, target);
144
+ gl_matrix_1.vec3.multiply(boxDir, boxDir, invalidInput
145
+ ? gl_matrix_1.vec3.fromValues(2, 2, 2)
146
+ : gl_matrix_1.vec3.fromValues(this.zoomExtentsFactor, this.zoomExtentsFactor, this.zoomExtentsFactor));
147
+ box = new viewer_shared_math_1.Box(gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), target, boxDir), gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), target, boxDir));
148
+ let direction = gl_matrix_1.vec3.create();
149
+ if (invalidInput) {
150
+ direction = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), target, startingPosition));
151
+ }
152
+ else {
153
+ direction = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), startingTarget, startingPosition));
154
+ }
155
+ const cross = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(0, 0, 1), direction));
156
+ const up = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), cross, direction));
157
+ let position = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), target, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), direction, gl_matrix_1.vec3.fromValues(-0.00000001, -0.00000001, -0.00000001)));
158
+ const points = [];
159
+ points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.min[1], box.min[2]));
160
+ points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.min[1], box.max[2]));
161
+ points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.max[1], box.min[2]));
162
+ points.push(gl_matrix_1.vec3.fromValues(box.min[0], box.max[1], box.max[2]));
163
+ points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.min[1], box.min[2]));
164
+ points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.min[1], box.max[2]));
165
+ points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.max[1], box.min[2]));
166
+ points.push(gl_matrix_1.vec3.fromValues(box.max[0], box.max[1], box.max[2]));
167
+ const fovDown = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), cross, (this.fov / 2) * (Math.PI / 180))));
168
+ const fovUp = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), cross, -(this.fov / 2) * (Math.PI / 180))));
169
+ const aspect = invalidInput ? 1.5 : this.aspect || 1.5;
170
+ const hFoV = 2 * Math.atan(Math.tan((this.fov * Math.PI) / 180 / 2) * aspect);
171
+ const fovRight = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), up, hFoV / 2)));
172
+ const fovLeft = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformQuat(gl_matrix_1.vec3.create(), direction, gl_matrix_1.quat.setAxisAngle(gl_matrix_1.quat.create(), up, -hFoV / 2)));
173
+ const planeCross = new viewer_shared_math_1.Plane();
174
+ planeCross.setFromNormalAndCoplanarPoint(gl_matrix_1.vec3.clone(cross), gl_matrix_1.vec3.clone(target));
175
+ const planeUp = new viewer_shared_math_1.Plane();
176
+ planeUp.setFromNormalAndCoplanarPoint(gl_matrix_1.vec3.clone(up), gl_matrix_1.vec3.clone(target));
177
+ let distanceCamera = 0.0;
178
+ for (let i = 0; i < points.length; i++) {
179
+ let projected = planeCross.clampPoint(points[i]);
180
+ let toP = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), projected, position));
181
+ if (gl_matrix_1.vec3.dot(direction, fovDown) > gl_matrix_1.vec3.dot(direction, toP)) {
182
+ const currentDir = gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.dot(fovDown, toP) > gl_matrix_1.vec3.dot(fovUp, toP)
183
+ ? fovDown
184
+ : fovUp, gl_matrix_1.vec3.fromValues(-1, -1, -1));
185
+ const distance = planeUp.intersect(projected, currentDir);
186
+ if (distance) {
187
+ const cameraPoint = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), currentDir, gl_matrix_1.vec3.fromValues(distance, distance, distance)), projected);
188
+ distanceCamera = Math.max(distanceCamera, gl_matrix_1.vec3.distance(target, cameraPoint));
189
+ }
190
+ }
191
+ projected = planeUp.clampPoint(points[i]);
192
+ toP = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.subtract(gl_matrix_1.vec3.create(), projected, position));
193
+ if (gl_matrix_1.vec3.dot(direction, fovRight) > gl_matrix_1.vec3.dot(direction, toP)) {
194
+ const currentDir = gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.dot(fovRight, toP) > gl_matrix_1.vec3.dot(fovLeft, toP)
195
+ ? fovRight
196
+ : fovLeft, gl_matrix_1.vec3.fromValues(-1, -1, -1));
197
+ const distance = planeCross.intersect(projected, currentDir);
198
+ if (distance) {
199
+ const cameraPoint = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), currentDir, gl_matrix_1.vec3.fromValues(distance, distance, distance)), projected);
200
+ distanceCamera = Math.max(distanceCamera, gl_matrix_1.vec3.distance(target, cameraPoint));
201
+ }
202
+ }
203
+ }
204
+ position = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), target, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), direction, gl_matrix_1.vec3.fromValues(-distanceCamera, -distanceCamera, -distanceCamera)));
205
+ return {
206
+ position,
207
+ target,
208
+ };
209
+ }
210
+ clone() {
211
+ return new PerspectiveCamera(this.id, this.version, this.aspect);
212
+ }
213
+ project(pos, position = this.position, target = this.target) {
214
+ const m = gl_matrix_1.mat4.targetTo(gl_matrix_1.mat4.create(), position, target, gl_matrix_1.vec3.fromValues(0, 0, 1));
215
+ const aspect = this.aspect || 1.5;
216
+ const p = gl_matrix_1.mat4.perspective(gl_matrix_1.mat4.create(), this.fov / (180 / Math.PI), aspect, this.near, this.far);
217
+ let inverse = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), m);
218
+ if (!inverse)
219
+ inverse = gl_matrix_1.mat4.create();
220
+ gl_matrix_1.vec3.transformMat4(pos, pos, inverse);
221
+ gl_matrix_1.vec3.transformMat4(pos, pos, p);
222
+ return gl_matrix_1.vec2.fromValues(pos[0], pos[1]);
223
+ }
224
+ unproject(pos, position = this.position, target = this.target) {
225
+ const m = gl_matrix_1.mat4.targetTo(gl_matrix_1.mat4.create(), position, target, gl_matrix_1.vec3.fromValues(0, 0, 1));
226
+ const aspect = this.aspect || 1.5;
227
+ const p = gl_matrix_1.mat4.perspective(gl_matrix_1.mat4.create(), this.fov / (180 / Math.PI), aspect, this.near, this.far);
228
+ let inverse = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), p);
229
+ if (!inverse)
230
+ inverse = gl_matrix_1.mat4.create();
231
+ gl_matrix_1.vec3.transformMat4(pos, pos, inverse);
232
+ gl_matrix_1.vec3.transformMat4(pos, pos, m);
233
+ return gl_matrix_1.vec3.clone(pos);
234
+ }
235
+ // #endregion Public Methods (6)
236
+ // #region Protected Methods (1)
237
+ getProjectionMatrix(sphere) {
238
+ if (!this.aspect || sphere.radius === 0)
239
+ return;
240
+ const far = this.fov < 10
241
+ ? this.fov * 100.0 * 100 * sphere.radius
242
+ : 100 * sphere.radius;
243
+ const near = this.fov < 10
244
+ ? this.fov * 100.0 * 0.01 * sphere.radius
245
+ : 0.01 * sphere.radius;
246
+ return gl_matrix_1.mat4.perspective(gl_matrix_1.mat4.create(), this.fov / (180 / Math.PI), this.aspect, near, far);
247
+ }
248
+ }
249
+ exports.PerspectiveCamera = PerspectiveCamera;
250
+ _PerspectiveCamera_converter = new WeakMap(), _PerspectiveCamera_tree = new WeakMap(), _PerspectiveCamera_aspect = new WeakMap(), _PerspectiveCamera_domEventEngine = new WeakMap(), _PerspectiveCamera_fov = new WeakMap();
251
251
  //# sourceMappingURL=PerspectiveCamera.js.map