@shapediver/viewer.rendering-engine.camera-engine 2.3.5 → 2.4.1
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 +1 -0
- package/dist/implementation/CameraEngine.d.ts.map +1 -1
- package/dist/implementation/CameraEngine.js +5 -0
- package/dist/implementation/CameraEngine.js.map +1 -1
- package/dist/implementation/camera/AbstractCamera.d.ts +1 -15
- package/dist/implementation/camera/AbstractCamera.d.ts.map +1 -1
- package/dist/implementation/camera/AbstractCamera.js +61 -45
- package/dist/implementation/camera/AbstractCamera.js.map +1 -1
- package/dist/implementation/camera/OrthographicCamera.d.ts +4 -11
- package/dist/implementation/camera/OrthographicCamera.d.ts.map +1 -1
- package/dist/implementation/camera/OrthographicCamera.js +51 -32
- package/dist/implementation/camera/OrthographicCamera.js.map +1 -1
- package/dist/implementation/camera/PerspectiveCamera.d.ts +4 -7
- package/dist/implementation/camera/PerspectiveCamera.d.ts.map +1 -1
- package/dist/implementation/camera/PerspectiveCamera.js +36 -16
- package/dist/implementation/camera/PerspectiveCamera.js.map +1 -1
- package/package.json +7 -7
- package/src/implementation/CameraEngine.ts +6 -0
- package/src/implementation/camera/AbstractCamera.ts +50 -52
- package/src/implementation/camera/OrthographicCamera.ts +41 -36
- package/src/implementation/camera/PerspectiveCamera.ts +24 -19
|
@@ -23,19 +23,20 @@ import { IOrthographicCameraControls } from '../../interfaces/controls/IOrthogra
|
|
|
23
23
|
export class OrthographicCamera extends AbstractCamera implements IOrthographicCamera {
|
|
24
24
|
// #region Properties (7)
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
readonly #converter: Converter = <Converter>container.resolve(Converter);
|
|
27
|
+
readonly #logger: Logger = <Logger>container.resolve(Logger);
|
|
28
|
+
readonly #tree: ITree = <ITree>container.resolve(Tree);
|
|
29
|
+
|
|
30
|
+
#domEventListenerToken?: string;
|
|
31
|
+
#domEventEngine?: DomEventEngine;
|
|
32
|
+
|
|
33
|
+
#bottom: number = -100;
|
|
34
|
+
#direction: ORTHOGRAPHIC_CAMERA_DIRECTION = ORTHOGRAPHIC_CAMERA_DIRECTION.TOP;
|
|
35
|
+
#left: number = -100;
|
|
36
|
+
#right: number = 100;
|
|
37
|
+
#top: number = 100;
|
|
38
|
+
#threeJsObject: { [key: string]: THREE.OrthographicCamera } = {};
|
|
39
|
+
#up: vec3 = vec3.fromValues(0, 1, 0);
|
|
39
40
|
protected _controls: IOrthographicCameraControls;
|
|
40
41
|
|
|
41
42
|
// #endregion Properties (7)
|
|
@@ -52,11 +53,11 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
52
53
|
// #region Public Accessors (12)
|
|
53
54
|
|
|
54
55
|
public get bottom(): number {
|
|
55
|
-
return this
|
|
56
|
+
return this.#bottom;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
public set bottom(value: number) {
|
|
59
|
-
this
|
|
60
|
+
this.#bottom = value;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
public get controls(): IOrthographicCameraControls {
|
|
@@ -68,14 +69,14 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
public get direction(): ORTHOGRAPHIC_CAMERA_DIRECTION {
|
|
71
|
-
return this
|
|
72
|
+
return this.#direction;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
public set direction(value: ORTHOGRAPHIC_CAMERA_DIRECTION) {
|
|
75
|
-
const changedDirection = this
|
|
76
|
+
const changedDirection = this.#direction !== value;
|
|
76
77
|
|
|
77
|
-
this
|
|
78
|
-
switch (this
|
|
78
|
+
this.#direction = value;
|
|
79
|
+
switch (this.#direction) {
|
|
79
80
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.TOP:
|
|
80
81
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM:
|
|
81
82
|
this.up = vec3.fromValues(0, 1, 0);
|
|
@@ -107,35 +108,39 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
public get left(): number {
|
|
110
|
-
return this
|
|
111
|
+
return this.#left;
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
public set left(value: number) {
|
|
114
|
-
this
|
|
115
|
+
this.#left = value;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
public get right(): number {
|
|
118
|
-
return this
|
|
119
|
+
return this.#right;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
public set right(value: number) {
|
|
122
|
-
this
|
|
123
|
+
this.#right = value;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
public get top(): number {
|
|
126
|
-
return this
|
|
127
|
+
return this.#top;
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
public set top(value: number) {
|
|
130
|
-
this
|
|
131
|
+
this.#top = value;
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
public get up(): vec3 {
|
|
134
|
-
return this
|
|
135
|
+
return this.#up;
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
public set up(value: vec3) {
|
|
138
|
-
this
|
|
139
|
+
this.#up = value;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public get threeJsObject(): { [key: string]: THREE.OrthographicCamera } {
|
|
143
|
+
return this.#threeJsObject;
|
|
139
144
|
}
|
|
140
145
|
|
|
141
146
|
// #endregion Public Accessors (12)
|
|
@@ -153,8 +158,8 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
153
158
|
this.revertAtMouseUpDuration = cameraSetting.revertAtMouseUpDuration;
|
|
154
159
|
this.zoomExtentsFactor = cameraSetting.zoomExtentsFactor;
|
|
155
160
|
|
|
156
|
-
let position = this.
|
|
157
|
-
let target = this.
|
|
161
|
+
let position = this.#converter.toVec3(cameraSetting.position);
|
|
162
|
+
let target = this.#converter.toVec3(cameraSetting.target);
|
|
158
163
|
this.defaultPosition = vec3.clone(position);
|
|
159
164
|
this.defaultTarget = vec3.clone(target);
|
|
160
165
|
|
|
@@ -180,19 +185,19 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
180
185
|
let renderingEngine: IRenderingEngine | undefined = renderingEngines.find(r => r.id === viewportId && r.closed === false);
|
|
181
186
|
if(!renderingEngine) {
|
|
182
187
|
const error = new ShapeDiverViewerCameraError(`OrthographicCamera(${this.id}).assignViewer: Viewer with id ${viewportId} not found.`);
|
|
183
|
-
throw this.
|
|
188
|
+
throw this.#logger.handleError(LOGGING_TOPIC.CAMERA, `OrthographicCamera(${this.id}).assignViewer`, error);
|
|
184
189
|
}
|
|
185
190
|
|
|
186
191
|
this.assignViewerInternal(viewportId, renderingEngine.canvas);
|
|
187
192
|
this._controls.assignViewer(viewportId, renderingEngine.canvas);
|
|
188
193
|
|
|
189
|
-
if (this
|
|
190
|
-
this.
|
|
194
|
+
if (this.#domEventListenerToken && this.#domEventEngine)
|
|
195
|
+
this.#domEventEngine.removeDomEventListener(this.#domEventListenerToken);
|
|
191
196
|
|
|
192
|
-
this
|
|
193
|
-
this
|
|
197
|
+
this.#domEventEngine = renderingEngine.domEventEngine;
|
|
198
|
+
this.#domEventListenerToken = this.#domEventEngine.addDomEventListener((<OrthographicCameraControls>this._controls).cameraControlsEventDistribution);
|
|
194
199
|
|
|
195
|
-
this.boundingBox = this.
|
|
200
|
+
this.boundingBox = this.#tree.root.boundingBox.clone();
|
|
196
201
|
|
|
197
202
|
this._stateEngine.renderingEngines[viewportId].boundingBoxCreated.then(async () => {
|
|
198
203
|
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2])
|
|
@@ -221,7 +226,7 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
221
226
|
const factor = 2 * box.boundingSphere.radius * this.zoomExtentsFactor;
|
|
222
227
|
const center = vec3.clone(box.boundingSphere.center);
|
|
223
228
|
|
|
224
|
-
switch (this
|
|
229
|
+
switch (this.#direction) {
|
|
225
230
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.TOP:
|
|
226
231
|
return {
|
|
227
232
|
position: vec3.fromValues(center[0], center[1], center[2] + factor),
|
|
@@ -23,17 +23,18 @@ import { IPerspectiveCameraControls } from '../../interfaces/controls/IPerspecti
|
|
|
23
23
|
export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCamera {
|
|
24
24
|
// #region Properties (3)
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
readonly #converter: Converter = <Converter>container.resolve(Converter);
|
|
27
|
+
readonly #logger: Logger = <Logger>container.resolve(Logger);
|
|
28
|
+
readonly #tree: ITree = <ITree>container.resolve(Tree);
|
|
29
29
|
|
|
30
30
|
protected _controls: IPerspectiveCameraControls;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
#domEventListenerToken?: string;
|
|
33
|
+
#domEventEngine?: DomEventEngine;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
#aspect: number | undefined;
|
|
36
|
+
#fov: number = 60;
|
|
37
|
+
#threeJsObject: { [key: string]: THREE.PerspectiveCamera } = {};
|
|
37
38
|
|
|
38
39
|
// #endregion Properties (3)
|
|
39
40
|
|
|
@@ -49,11 +50,11 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
49
50
|
// #region Public Accessors (4)
|
|
50
51
|
|
|
51
52
|
public get aspect(): number | undefined {
|
|
52
|
-
return this
|
|
53
|
+
return this.#aspect;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
public set aspect(value: number | undefined) {
|
|
56
|
-
this
|
|
57
|
+
this.#aspect = value;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
public get controls(): IPerspectiveCameraControls {
|
|
@@ -65,11 +66,15 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
public get fov(): number {
|
|
68
|
-
return this
|
|
69
|
+
return this.#fov;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
public set fov(value: number) {
|
|
72
|
-
this
|
|
73
|
+
this.#fov = value;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public get threeJsObject(): { [key: string]: THREE.PerspectiveCamera } {
|
|
77
|
+
return this.#threeJsObject;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
// #endregion Public Accessors (4)
|
|
@@ -87,8 +92,8 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
87
92
|
this.revertAtMouseUpDuration = cameraSetting.revertAtMouseUpDuration;
|
|
88
93
|
this.zoomExtentsFactor = cameraSetting.zoomExtentsFactor;
|
|
89
94
|
|
|
90
|
-
let position = this.
|
|
91
|
-
let target = this.
|
|
95
|
+
let position = this.#converter.toVec3(cameraSetting.position);
|
|
96
|
+
let target = this.#converter.toVec3(cameraSetting.target);
|
|
92
97
|
this.defaultPosition = vec3.clone(position);
|
|
93
98
|
this.defaultTarget = vec3.clone(target);
|
|
94
99
|
|
|
@@ -114,19 +119,19 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
114
119
|
let renderingEngine: IRenderingEngine | undefined = renderingEngines.find(r => r.id === viewportId && r.closed === false);
|
|
115
120
|
if(!renderingEngine) {
|
|
116
121
|
const error = new ShapeDiverViewerCameraError(`OrthographicCamera(${this.id}).assignViewer: Viewer with id ${viewportId} not found.`);
|
|
117
|
-
throw this.
|
|
122
|
+
throw this.#logger.handleError(LOGGING_TOPIC.CAMERA, `OrthographicCamera(${this.id}).assignViewer`, error);
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
this.assignViewerInternal(viewportId, renderingEngine.canvas);
|
|
121
126
|
this._controls.assignViewer(viewportId, renderingEngine.canvas);
|
|
122
127
|
|
|
123
|
-
if (this
|
|
124
|
-
this.
|
|
128
|
+
if (this.#domEventListenerToken && this.#domEventEngine)
|
|
129
|
+
this.#domEventEngine.removeDomEventListener(this.#domEventListenerToken);
|
|
125
130
|
|
|
126
|
-
this
|
|
127
|
-
this
|
|
131
|
+
this.#domEventEngine = renderingEngine.domEventEngine;
|
|
132
|
+
this.#domEventListenerToken = this.#domEventEngine.addDomEventListener((<PerspectiveCameraControls>this._controls).cameraControlsEventDistribution);
|
|
128
133
|
|
|
129
|
-
this.boundingBox = this.
|
|
134
|
+
this.boundingBox = this.#tree.root.boundingBox.clone();
|
|
130
135
|
|
|
131
136
|
this._stateEngine.renderingEngines[viewportId].boundingBoxCreated.then(async () => {
|
|
132
137
|
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2])
|