@shapediver/viewer.rendering-engine.camera-engine 3.3.4 → 3.3.7
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/package.json +9 -10
- package/src/implementation/CameraEngine.ts +0 -386
- package/src/implementation/camera/AbstractCamera.ts +0 -324
- package/src/implementation/camera/OrthographicCamera.ts +0 -282
- package/src/implementation/camera/PerspectiveCamera.ts +0 -250
- package/src/implementation/controls/AbstractCameraControls.ts +0 -660
- package/src/implementation/controls/CameraControlsEventDistribution.ts +0 -289
- package/src/implementation/controls/CameraControlsLogic.ts +0 -534
- package/src/implementation/controls/OrthographicCameraControls.ts +0 -36
- package/src/implementation/controls/PerspectiveCameraControls.ts +0 -37
- package/src/implementation/interpolation/CameraInterpolationManager.ts +0 -149
- package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts +0 -83
- package/src/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.ts +0 -41
- package/src/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.ts +0 -61
- package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts +0 -41
- package/src/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.ts +0 -65
- package/src/index.ts +0 -28
- package/src/interfaces/ICameraEngine.ts +0 -33
- package/src/interfaces/camera/ICamera.ts +0 -88
- package/src/interfaces/camera/IOrthographicCamera.ts +0 -36
- package/src/interfaces/camera/IPerspectiveCamera.ts +0 -18
- package/src/interfaces/controls/ICameraControls.ts +0 -80
- package/src/interfaces/controls/ICameraControlsEventDistribution.ts +0 -11
- package/src/interfaces/controls/ICameraControlsLogic.ts +0 -15
- package/src/interfaces/interpolation/ICameraInterpolation.ts +0 -9
- package/tsconfig.json +0 -17
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import * as detectIt from 'detect-it';
|
|
2
|
-
import { AbstractTreeNodeData, ITreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
3
|
-
import { Box, IBox } from '@shapediver/viewer.shared.math';
|
|
4
|
-
import { CAMERA_TYPE } from '../../interfaces/ICameraEngine';
|
|
5
|
-
import { ICamera, ICameraOptions } from '../../interfaces/camera/ICamera';
|
|
6
|
-
import { ICameraControls } from '../../interfaces/controls/ICameraControls';
|
|
7
|
-
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine';
|
|
8
|
-
import { vec2, vec3 } from 'gl-matrix';
|
|
9
|
-
import {
|
|
10
|
-
EventEngine,
|
|
11
|
-
EVENTTYPE,
|
|
12
|
-
SettingsEngine,
|
|
13
|
-
StateEngine,
|
|
14
|
-
} from '@shapediver/viewer.shared.services';
|
|
15
|
-
|
|
16
|
-
export abstract class AbstractCamera extends AbstractTreeNodeData implements ICamera {
|
|
17
|
-
// #region Properties (24)
|
|
18
|
-
|
|
19
|
-
#active: boolean = false;
|
|
20
|
-
#autoAdjust: boolean = true;
|
|
21
|
-
#cameraMovementDuration: number = 800;
|
|
22
|
-
#defaultPosition: vec3 = vec3.create();
|
|
23
|
-
#defaultTarget: vec3 = vec3.create();
|
|
24
|
-
#domEventListenerToken: string | undefined;
|
|
25
|
-
#enableCameraControls: boolean = true;
|
|
26
|
-
#far: number = 1000;
|
|
27
|
-
#name?: string;
|
|
28
|
-
#near: number = 1;
|
|
29
|
-
#node?: ITreeNode;
|
|
30
|
-
#order?: number;
|
|
31
|
-
#revertAtMouseUp: boolean = false;
|
|
32
|
-
#revertAtMouseUpDuration: number = 800;
|
|
33
|
-
#sceneRotation: vec2 = vec2.create();
|
|
34
|
-
#useNodeData: boolean = false;
|
|
35
|
-
#zoomExtentsFactor: number = 1;
|
|
36
|
-
|
|
37
|
-
protected readonly _eventEngine: EventEngine = EventEngine.instance;
|
|
38
|
-
protected readonly _stateEngine: StateEngine = StateEngine.instance;
|
|
39
|
-
|
|
40
|
-
protected _boundingBox: IBox = new Box();
|
|
41
|
-
protected abstract _controls: ICameraControls;
|
|
42
|
-
protected _position: vec3 = vec3.create();
|
|
43
|
-
protected _target: vec3 = vec3.create();
|
|
44
|
-
protected _viewportId?: string;
|
|
45
|
-
|
|
46
|
-
// #endregion Properties (24)
|
|
47
|
-
|
|
48
|
-
// #region Constructors (1)
|
|
49
|
-
|
|
50
|
-
constructor(private readonly _id: string, private readonly _type: CAMERA_TYPE, version?: string, private readonly _isDefault: boolean = false) {
|
|
51
|
-
super(_id, version);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// #endregion Constructors (1)
|
|
55
|
-
|
|
56
|
-
// #region Public Getters And Setters (43)
|
|
57
|
-
|
|
58
|
-
public get active(): boolean {
|
|
59
|
-
return this.#active;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public set active(value: boolean) {
|
|
63
|
-
this.#active = value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public get autoAdjust(): boolean {
|
|
67
|
-
return this.#autoAdjust;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public set autoAdjust(value: boolean) {
|
|
71
|
-
this.#autoAdjust = value;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public set boundingBox(value: IBox) {
|
|
75
|
-
this._boundingBox = value;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public get cameraMovementDuration(): number {
|
|
79
|
-
return this.#cameraMovementDuration;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public set cameraMovementDuration(value: number) {
|
|
83
|
-
this.#cameraMovementDuration = value;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public get controls(): ICameraControls {
|
|
87
|
-
return this._controls;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public get defaultPosition(): vec3 {
|
|
91
|
-
return this.#defaultPosition;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public set defaultPosition(value: vec3) {
|
|
95
|
-
this.#defaultPosition = value;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public get defaultTarget(): vec3 {
|
|
99
|
-
return this.#defaultTarget;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public set defaultTarget(value: vec3) {
|
|
103
|
-
this.#defaultTarget = value;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public get domEventListenerToken(): string | undefined {
|
|
107
|
-
return this.#domEventListenerToken;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public set domEventListenerToken(value: string | undefined) {
|
|
111
|
-
this.#domEventListenerToken = value;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public get enableCameraControls(): boolean {
|
|
115
|
-
return this.#enableCameraControls;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public set enableCameraControls(value: boolean) {
|
|
119
|
-
this.#enableCameraControls = value;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public get far(): number {
|
|
123
|
-
return this.#far;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public set far(value: number) {
|
|
127
|
-
this.#far = value;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public get id(): string {
|
|
131
|
-
return this._id;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public get isDefault(): boolean {
|
|
135
|
-
return this._isDefault;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public get name(): string | undefined {
|
|
139
|
-
return this.#name;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public set name(value: string | undefined) {
|
|
143
|
-
this.#name = value;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public get near(): number {
|
|
147
|
-
return this.#near;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public set near(value: number) {
|
|
151
|
-
this.#near = value;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public get node(): ITreeNode | undefined {
|
|
155
|
-
return this.#node;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public set node(value: ITreeNode | undefined) {
|
|
159
|
-
this.#node = value;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public get order(): number | undefined {
|
|
163
|
-
return this.#order;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
public set order(value: number | undefined) {
|
|
167
|
-
this.#order = value;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public get position(): vec3 {
|
|
171
|
-
return this._position;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
public set position(value: vec3) {
|
|
175
|
-
this._position = value;
|
|
176
|
-
this._controls.position = value;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public get revertAtMouseUp(): boolean {
|
|
180
|
-
return this.#revertAtMouseUp;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public set revertAtMouseUp(value: boolean) {
|
|
184
|
-
this.#revertAtMouseUp = value;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
public get revertAtMouseUpDuration(): number {
|
|
188
|
-
return this.#revertAtMouseUpDuration;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
public set revertAtMouseUpDuration(value: number) {
|
|
192
|
-
this.#revertAtMouseUpDuration = value;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
public get sceneRotation(): vec2 {
|
|
196
|
-
return this.#sceneRotation;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
public set sceneRotation(value: vec2) {
|
|
200
|
-
this.#sceneRotation = value;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
public get target(): vec3 {
|
|
204
|
-
return this._target;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
public set target(value: vec3) {
|
|
208
|
-
this._target = value;
|
|
209
|
-
this._controls.target = value;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
public get type(): CAMERA_TYPE {
|
|
213
|
-
return this._type;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
public get useNodeData(): boolean {
|
|
217
|
-
return this.#useNodeData;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
public set useNodeData(value: boolean) {
|
|
221
|
-
this.#useNodeData = value;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
public get viewportId(): string | undefined {
|
|
225
|
-
return this._viewportId;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
public get zoomExtentsFactor(): number {
|
|
229
|
-
return this.#zoomExtentsFactor;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
public set zoomExtentsFactor(value: number) {
|
|
233
|
-
this.#zoomExtentsFactor = value;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// #endregion Public Getters And Setters (43)
|
|
237
|
-
|
|
238
|
-
// #region Public Methods (5)
|
|
239
|
-
|
|
240
|
-
public async animate(path: { position: vec3; target: vec3; }[], options?: ICameraOptions): Promise<boolean> {
|
|
241
|
-
if (path.length === 0) return Promise.resolve(false);
|
|
242
|
-
|
|
243
|
-
if (!options) options = {};
|
|
244
|
-
options.duration = options.duration! >= 0 ? options.duration : this.cameraMovementDuration;
|
|
245
|
-
|
|
246
|
-
const res = await this._controls.animate(path, options);
|
|
247
|
-
if (res) {
|
|
248
|
-
this._position = this._controls.position;
|
|
249
|
-
this._target = this._controls.target;
|
|
250
|
-
}
|
|
251
|
-
return res;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
public reset(options?: ICameraOptions): Promise<boolean> {
|
|
255
|
-
if ((this.defaultPosition[0] === 0 && this.defaultPosition[1] === 0 && this.defaultPosition[2] === 0) && (this.defaultTarget[0] === 0 && this.defaultTarget[1] === 0 && this.defaultTarget[2] === 0)) {
|
|
256
|
-
return this.zoomTo(undefined, options);
|
|
257
|
-
} else {
|
|
258
|
-
return this.set(vec3.clone(this.defaultPosition), vec3.clone(this.defaultTarget), options);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
public async set(position: vec3, target: vec3, options?: ICameraOptions): Promise<boolean> {
|
|
263
|
-
if (!options) options = {};
|
|
264
|
-
options.duration = options.duration! >= 0 ? options.duration : this.cameraMovementDuration;
|
|
265
|
-
|
|
266
|
-
const res = await this._controls.animate([
|
|
267
|
-
{ position: vec3.clone(this.position), target: vec3.clone(this.target) },
|
|
268
|
-
{ position, target }], options);
|
|
269
|
-
if (res) {
|
|
270
|
-
this._position = this._controls.position;
|
|
271
|
-
this._target = this._controls.target;
|
|
272
|
-
}
|
|
273
|
-
return res;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
public update(time: number): boolean {
|
|
277
|
-
if (this.useNodeData && this.node && this._viewportId) {
|
|
278
|
-
return true;
|
|
279
|
-
} else {
|
|
280
|
-
const { position, target, sceneRotation } = this._controls.update(time);
|
|
281
|
-
let changed = true;
|
|
282
|
-
if (vec3.equals(position, this.position) && vec3.equals(target, this.target))
|
|
283
|
-
changed = false;
|
|
284
|
-
|
|
285
|
-
this.position = vec3.clone(position);
|
|
286
|
-
this.target = vec3.clone(target);
|
|
287
|
-
this.sceneRotation = vec2.clone(sceneRotation);
|
|
288
|
-
return changed;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
public zoomTo(zoomTarget?: Box, options?: ICameraOptions): Promise<boolean> {
|
|
293
|
-
const { position, target } = this.calculateZoomTo(zoomTarget);
|
|
294
|
-
return this.set(position, target, options);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// #endregion Public Methods (5)
|
|
298
|
-
|
|
299
|
-
// #region Public Abstract Methods (5)
|
|
300
|
-
|
|
301
|
-
public abstract applySettings(settingsEngine?: SettingsEngine): void;
|
|
302
|
-
public abstract assignViewer(renderingEngine: IRenderingEngine): void;
|
|
303
|
-
public abstract calculateZoomTo(zoomTarget?: Box, startingPosition?: vec3, startingTarget?: vec3): { position: vec3; target: vec3; };
|
|
304
|
-
public abstract project(p: vec3): vec2;
|
|
305
|
-
public abstract unproject(p: vec3): vec3;
|
|
306
|
-
|
|
307
|
-
// #endregion Public Abstract Methods (5)
|
|
308
|
-
|
|
309
|
-
// #region Protected Methods (1)
|
|
310
|
-
|
|
311
|
-
protected assignViewerInternal(viewportId: string) {
|
|
312
|
-
this._viewportId = viewportId;
|
|
313
|
-
this._eventEngine.addListener(EVENTTYPE.SESSION.SESSION_CUSTOMIZED, async () => {
|
|
314
|
-
if (this.#autoAdjust === true) {
|
|
315
|
-
const innerListenerToken = this._eventEngine.addListener(EVENTTYPE.VIEWPORT.VIEWPORT_UPDATED, async () => {
|
|
316
|
-
this.zoomTo();
|
|
317
|
-
this._eventEngine.removeListener(innerListenerToken);
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// #endregion Protected Methods (1)
|
|
324
|
-
}
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { AbstractCamera } from './AbstractCamera';
|
|
2
|
-
import { Box, IBox } from '@shapediver/viewer.shared.math';
|
|
3
|
-
import { CAMERA_TYPE } from '../../interfaces/ICameraEngine';
|
|
4
|
-
import { ICameraControls } from '../../interfaces/controls/ICameraControls';
|
|
5
|
-
import { IOrthographicCamera, ORTHOGRAPHIC_CAMERA_DIRECTION } from '../../interfaces/camera/IOrthographicCamera';
|
|
6
|
-
import { IOrthographicCameraSettings } from '@shapediver/viewer.settings';
|
|
7
|
-
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine';
|
|
8
|
-
import { ITree, Tree } from '@shapediver/viewer.shared.node-tree';
|
|
9
|
-
import { mat4, vec2, vec3 } from 'gl-matrix';
|
|
10
|
-
import { OrthographicCameraControls } from '../controls/OrthographicCameraControls';
|
|
11
|
-
import {
|
|
12
|
-
Converter,
|
|
13
|
-
DomEventEngine,
|
|
14
|
-
Logger,
|
|
15
|
-
SettingsEngine,
|
|
16
|
-
ShapeDiverViewerCameraError,
|
|
17
|
-
} from '@shapediver/viewer.shared.services';
|
|
18
|
-
|
|
19
|
-
export class OrthographicCamera extends AbstractCamera implements IOrthographicCamera {
|
|
20
|
-
// #region Properties (11)
|
|
21
|
-
|
|
22
|
-
readonly #converter: Converter = Converter.instance;
|
|
23
|
-
readonly #logger: Logger = Logger.instance;
|
|
24
|
-
readonly #tree: ITree = Tree.instance;
|
|
25
|
-
|
|
26
|
-
#bottom: number = -100;
|
|
27
|
-
#direction: ORTHOGRAPHIC_CAMERA_DIRECTION = ORTHOGRAPHIC_CAMERA_DIRECTION.CUSTOM;
|
|
28
|
-
#domEventEngine?: DomEventEngine;
|
|
29
|
-
#left: number = -100;
|
|
30
|
-
#right: number = 100;
|
|
31
|
-
#top: number = 100;
|
|
32
|
-
#up: vec3 = vec3.fromValues(0, 0, 1);
|
|
33
|
-
|
|
34
|
-
protected _controls: ICameraControls;
|
|
35
|
-
|
|
36
|
-
// #endregion Properties (11)
|
|
37
|
-
|
|
38
|
-
// #region Constructors (1)
|
|
39
|
-
|
|
40
|
-
constructor(id: string, version?: string, isDefault: boolean = false) {
|
|
41
|
-
super(id, CAMERA_TYPE.ORTHOGRAPHIC, version, isDefault);
|
|
42
|
-
this._controls = new OrthographicCameraControls(this, true);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// #endregion Constructors (1)
|
|
46
|
-
|
|
47
|
-
// #region Public Getters And Setters (14)
|
|
48
|
-
|
|
49
|
-
public get bottom(): number {
|
|
50
|
-
return this.#bottom;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public set bottom(value: number) {
|
|
54
|
-
this.#bottom = value;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public get controls(): ICameraControls {
|
|
58
|
-
return this._controls;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public set controls(value: ICameraControls) {
|
|
62
|
-
this._controls = value;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public get direction(): ORTHOGRAPHIC_CAMERA_DIRECTION {
|
|
66
|
-
return this.#direction;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public set direction(value: ORTHOGRAPHIC_CAMERA_DIRECTION) {
|
|
70
|
-
const changedDirection = this.#direction !== value;
|
|
71
|
-
|
|
72
|
-
this.#direction = value;
|
|
73
|
-
switch (this.#direction) {
|
|
74
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.TOP:
|
|
75
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM:
|
|
76
|
-
this.up = vec3.fromValues(0, 1, 0);
|
|
77
|
-
break;
|
|
78
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.RIGHT:
|
|
79
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.LEFT:
|
|
80
|
-
this.up = vec3.fromValues(0, 0, 1);
|
|
81
|
-
break;
|
|
82
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.BACK:
|
|
83
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT:
|
|
84
|
-
this.up = vec3.fromValues(0, 0, 1);
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
this.up = vec3.fromValues(0, 0, 1);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (changedDirection) {
|
|
91
|
-
const { position, target } = this.calculateZoomTo(undefined);
|
|
92
|
-
this.defaultPosition = vec3.clone(position);
|
|
93
|
-
this.defaultTarget = vec3.clone(target);
|
|
94
|
-
|
|
95
|
-
this.position = vec3.clone(position);
|
|
96
|
-
this.target = vec3.clone(target);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public get left(): number {
|
|
101
|
-
return this.#left;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public set left(value: number) {
|
|
105
|
-
this.#left = value;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public get right(): number {
|
|
109
|
-
return this.#right;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public set right(value: number) {
|
|
113
|
-
this.#right = value;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public get top(): number {
|
|
117
|
-
return this.#top;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public set top(value: number) {
|
|
121
|
-
this.#top = value;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public get up(): vec3 {
|
|
125
|
-
return this.#up;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public set up(value: vec3) {
|
|
129
|
-
this.#up = value;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// #endregion Public Getters And Setters (14)
|
|
133
|
-
|
|
134
|
-
// #region Public Methods (6)
|
|
135
|
-
|
|
136
|
-
public applySettings(settingsEngine: SettingsEngine) {
|
|
137
|
-
const cameraSetting = <IOrthographicCameraSettings>settingsEngine.camera.cameras[this.id];
|
|
138
|
-
if (cameraSetting) {
|
|
139
|
-
this.name = cameraSetting.name;
|
|
140
|
-
this.autoAdjust = cameraSetting.autoAdjust;
|
|
141
|
-
this.cameraMovementDuration = cameraSetting.cameraMovementDuration;
|
|
142
|
-
this.enableCameraControls = cameraSetting.enableCameraControls;
|
|
143
|
-
this.revertAtMouseUp = cameraSetting.revertAtMouseUp;
|
|
144
|
-
this.revertAtMouseUpDuration = cameraSetting.revertAtMouseUpDuration;
|
|
145
|
-
this.sceneRotation = vec2.fromValues(cameraSetting.sceneRotation.x, cameraSetting.sceneRotation.y);
|
|
146
|
-
this.zoomExtentsFactor = cameraSetting.zoomExtentsFactor;
|
|
147
|
-
|
|
148
|
-
const position = this.#converter.toVec3(cameraSetting.position);
|
|
149
|
-
const target = this.#converter.toVec3(cameraSetting.target);
|
|
150
|
-
this.defaultPosition = vec3.clone(position);
|
|
151
|
-
this.defaultTarget = vec3.clone(target);
|
|
152
|
-
|
|
153
|
-
this.position = position;
|
|
154
|
-
this.target = target;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2]) {
|
|
158
|
-
if (this._viewportId) {
|
|
159
|
-
this._stateEngine.viewportEngines[this._viewportId]?.boundingBoxCreated
|
|
160
|
-
.then(async () => {
|
|
161
|
-
await this.zoomTo(undefined, { duration: 0 });
|
|
162
|
-
this.defaultPosition = vec3.clone(this._controls.position);
|
|
163
|
-
this.defaultTarget = vec3.clone(this._controls.target);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
(<OrthographicCameraControls>this._controls).applySettings(settingsEngine);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public assignViewer(renderingEngine: IRenderingEngine): void {
|
|
171
|
-
if (renderingEngine.closed)
|
|
172
|
-
throw new ShapeDiverViewerCameraError(`OrthographicCamera(${this.id}).assignViewer: Viewer with id ${renderingEngine.id} not found.`);
|
|
173
|
-
|
|
174
|
-
this.assignViewerInternal(renderingEngine.id);
|
|
175
|
-
this._controls.assignViewer(renderingEngine.id, renderingEngine.canvas);
|
|
176
|
-
|
|
177
|
-
if (this.domEventListenerToken && this.#domEventEngine)
|
|
178
|
-
this.#domEventEngine.removeDomEventListener(this.domEventListenerToken);
|
|
179
|
-
|
|
180
|
-
this.#domEventEngine = renderingEngine.domEventEngine;
|
|
181
|
-
this.domEventListenerToken = this.#domEventEngine.addDomEventListener((<OrthographicCameraControls>this._controls).cameraControlsEventDistribution);
|
|
182
|
-
|
|
183
|
-
this.boundingBox = this.#tree.root.boundingBox.clone();
|
|
184
|
-
|
|
185
|
-
this._stateEngine.viewportEngines[renderingEngine.id]?.boundingBoxCreated.then(async () => {
|
|
186
|
-
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2])
|
|
187
|
-
await this.zoomTo(undefined, { duration: 0 });
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
public calculateZoomTo(zoomTarget?: Box, startingPosition: vec3 = this.position, startingTarget: vec3 = this.target): { position: vec3; target: vec3; } {
|
|
192
|
-
let box: IBox;
|
|
193
|
-
|
|
194
|
-
// Part 1 - calculate the bounding box that we should zoom to
|
|
195
|
-
if (!zoomTarget) {
|
|
196
|
-
// complete scene
|
|
197
|
-
box = this._boundingBox.clone();
|
|
198
|
-
} else {
|
|
199
|
-
// specified Box
|
|
200
|
-
box = zoomTarget.clone();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (box.isEmpty()) return { position: vec3.create(), target: vec3.create() };
|
|
204
|
-
|
|
205
|
-
const target = vec3.fromValues((box.max[0] + box.min[0]) / 2, (box.max[1] + box.min[1]) / 2, (box.max[2] + box.min[2]) / 2);
|
|
206
|
-
if (startingPosition[0] === startingTarget[0] && startingPosition[1] === startingTarget[1] && startingPosition[2] === startingTarget[2])
|
|
207
|
-
startingPosition = vec3.fromValues(target[0], target[1] - 7.5, target[2] + 5);
|
|
208
|
-
|
|
209
|
-
const factor = 2 * box.boundingSphere.radius * this.zoomExtentsFactor;
|
|
210
|
-
|
|
211
|
-
switch (this.#direction) {
|
|
212
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.TOP:
|
|
213
|
-
return {
|
|
214
|
-
position: vec3.fromValues(target[0], target[1], target[2] + factor),
|
|
215
|
-
target: vec3.clone(target)
|
|
216
|
-
};
|
|
217
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM:
|
|
218
|
-
return {
|
|
219
|
-
position: vec3.fromValues(target[0], target[1], target[2] - factor),
|
|
220
|
-
target: vec3.clone(target)
|
|
221
|
-
};
|
|
222
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.RIGHT:
|
|
223
|
-
return {
|
|
224
|
-
position: vec3.fromValues(target[0] + factor, target[1], target[2]),
|
|
225
|
-
target: vec3.clone(target)
|
|
226
|
-
};
|
|
227
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.LEFT:
|
|
228
|
-
return {
|
|
229
|
-
position: vec3.fromValues(target[0] - factor, target[1], target[2]),
|
|
230
|
-
target: vec3.clone(target)
|
|
231
|
-
};
|
|
232
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.BACK:
|
|
233
|
-
return {
|
|
234
|
-
position: vec3.fromValues(target[0], target[1] + factor, target[2]),
|
|
235
|
-
target: vec3.clone(target)
|
|
236
|
-
};
|
|
237
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT:
|
|
238
|
-
return {
|
|
239
|
-
position: vec3.fromValues(target[0], target[1] - factor, target[2]),
|
|
240
|
-
target: vec3.clone(target)
|
|
241
|
-
};
|
|
242
|
-
default:
|
|
243
|
-
{
|
|
244
|
-
// get the direction from the starting position to the starting target
|
|
245
|
-
const direction = vec3.subtract(vec3.create(), startingPosition, target);
|
|
246
|
-
// normalize the direction
|
|
247
|
-
vec3.normalize(direction, direction);
|
|
248
|
-
// get the new position
|
|
249
|
-
return {
|
|
250
|
-
position: vec3.add(vec3.create(), target, vec3.scale(vec3.create(), direction, factor)),
|
|
251
|
-
target: vec3.clone(target)
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
public clone(): IOrthographicCamera {
|
|
258
|
-
return new OrthographicCamera(this.id, this.version);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
public project(pos: vec3): vec2 {
|
|
262
|
-
const m = mat4.targetTo(mat4.create(), this.position, this.target, this.up);
|
|
263
|
-
const p = mat4.ortho(mat4.create(), this.left, this.right, this.bottom, this.top, this.near, this.far);
|
|
264
|
-
let inverse = mat4.invert(mat4.create(), m);
|
|
265
|
-
if (!inverse) inverse = mat4.create();
|
|
266
|
-
vec3.transformMat4(pos, pos, inverse);
|
|
267
|
-
vec3.transformMat4(pos, pos, p);
|
|
268
|
-
return vec2.fromValues(pos[0], pos[1]);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
public unproject(pos: vec3): vec3 {
|
|
272
|
-
const m = mat4.targetTo(mat4.create(), this.position, this.target, this.up);
|
|
273
|
-
const p = mat4.ortho(mat4.create(), this.left, this.right, this.bottom, this.top, this.near, this.far);
|
|
274
|
-
let inverse = mat4.invert(mat4.create(), p);
|
|
275
|
-
if (!inverse) inverse = mat4.create();
|
|
276
|
-
vec3.transformMat4(pos, pos, inverse);
|
|
277
|
-
vec3.transformMat4(pos, pos, m);
|
|
278
|
-
return vec3.clone(pos);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// #endregion Public Methods (6)
|
|
282
|
-
}
|