@shapediver/viewer.rendering-engine.camera-engine 2.12.8 → 3.0.0
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 +5 -7
- package/dist/implementation/CameraEngine.d.ts.map +1 -1
- package/dist/implementation/CameraEngine.js +68 -27
- package/dist/implementation/CameraEngine.js.map +1 -1
- package/dist/implementation/camera/AbstractCamera.d.ts +7 -5
- package/dist/implementation/camera/AbstractCamera.d.ts.map +1 -1
- package/dist/implementation/camera/AbstractCamera.js +15 -8
- package/dist/implementation/camera/AbstractCamera.js.map +1 -1
- package/dist/implementation/camera/OrthographicCamera.d.ts +10 -13
- package/dist/implementation/camera/OrthographicCamera.d.ts.map +1 -1
- package/dist/implementation/camera/OrthographicCamera.js +53 -52
- package/dist/implementation/camera/OrthographicCamera.js.map +1 -1
- package/dist/implementation/camera/PerspectiveCamera.d.ts +9 -12
- package/dist/implementation/camera/PerspectiveCamera.d.ts.map +1 -1
- package/dist/implementation/camera/PerspectiveCamera.js +33 -38
- package/dist/implementation/camera/PerspectiveCamera.js.map +1 -1
- package/dist/implementation/controls/AbstractCameraControls.d.ts +156 -5
- package/dist/implementation/controls/AbstractCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/AbstractCameraControls.js +260 -6
- package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
- package/dist/implementation/controls/CameraControlsEventDistribution.d.ts +38 -0
- package/dist/implementation/controls/CameraControlsEventDistribution.d.ts.map +1 -0
- package/dist/implementation/controls/{perspective/CameraControlsEventDistribution.js → CameraControlsEventDistribution.js} +71 -71
- package/dist/implementation/controls/CameraControlsEventDistribution.js.map +1 -0
- package/dist/implementation/controls/{perspective/CameraControlsLogic.d.ts → CameraControlsLogic.d.ts} +5 -5
- package/dist/implementation/controls/CameraControlsLogic.d.ts.map +1 -0
- package/dist/implementation/controls/{perspective/CameraControlsLogic.js → CameraControlsLogic.js} +74 -44
- package/dist/implementation/controls/CameraControlsLogic.js.map +1 -0
- package/dist/implementation/controls/OrthographicCameraControls.d.ts +4 -67
- package/dist/implementation/controls/OrthographicCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/OrthographicCameraControls.js +22 -90
- package/dist/implementation/controls/OrthographicCameraControls.js.map +1 -1
- package/dist/implementation/controls/PerspectiveCameraControls.d.ts +4 -151
- package/dist/implementation/controls/PerspectiveCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/PerspectiveCameraControls.js +21 -247
- package/dist/implementation/controls/PerspectiveCameraControls.js.map +1 -1
- package/dist/implementation/interpolation/CameraInterpolationManager.d.ts +3 -3
- package/dist/implementation/interpolation/CameraInterpolationManager.d.ts.map +1 -1
- package/dist/implementation/interpolation/CameraInterpolationManager.js +5 -5
- package/dist/implementation/interpolation/CameraInterpolationManager.js.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.d.ts +3 -3
- package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.d.ts.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.js +11 -11
- package/dist/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.js.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.d.ts +3 -3
- package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.d.ts.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.js +6 -6
- package/dist/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.js.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.d.ts +4 -4
- package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.d.ts.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js +6 -6
- package/dist/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.js.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.d.ts +3 -3
- package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.d.ts.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.js +6 -6
- package/dist/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.js.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.d.ts +3 -3
- package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.d.ts.map +1 -1
- package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.js +9 -9
- package/dist/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.js.map +1 -1
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ICameraEngine.d.ts +7 -7
- package/dist/interfaces/ICameraEngine.d.ts.map +1 -1
- package/dist/interfaces/ICameraEngine.js +3 -0
- package/dist/interfaces/ICameraEngine.js.map +1 -1
- package/dist/interfaces/camera/ICamera.d.ts +23 -22
- package/dist/interfaces/camera/ICamera.d.ts.map +1 -1
- package/dist/interfaces/camera/ICamera.js +1 -0
- package/dist/interfaces/camera/ICamera.js.map +1 -1
- package/dist/interfaces/camera/IOrthographicCamera.d.ts +8 -7
- package/dist/interfaces/camera/IOrthographicCamera.d.ts.map +1 -1
- package/dist/interfaces/camera/IOrthographicCamera.js +4 -0
- package/dist/interfaces/camera/IOrthographicCamera.js.map +1 -1
- package/dist/interfaces/camera/IPerspectiveCamera.d.ts +2 -2
- package/dist/interfaces/camera/IPerspectiveCamera.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControls.d.ts +73 -2
- package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControls.js +1 -0
- package/dist/interfaces/controls/ICameraControls.js.map +1 -1
- package/dist/interfaces/controls/ICameraControlsEventDistribution.d.ts +1 -1
- package/dist/interfaces/controls/ICameraControlsEventDistribution.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControlsLogic.d.ts +4 -1
- package/dist/interfaces/controls/ICameraControlsLogic.d.ts.map +1 -1
- package/dist/interfaces/interpolation/ICameraInterpolation.d.ts +2 -2
- package/dist/interfaces/interpolation/ICameraInterpolation.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/implementation/CameraEngine.ts +111 -70
- package/src/implementation/camera/AbstractCamera.ts +24 -16
- package/src/implementation/camera/OrthographicCamera.ts +84 -85
- package/src/implementation/camera/PerspectiveCamera.ts +64 -69
- package/src/implementation/controls/AbstractCameraControls.ts +303 -14
- package/src/implementation/controls/{perspective/CameraControlsEventDistribution.ts → CameraControlsEventDistribution.ts} +96 -75
- package/src/implementation/controls/{perspective/CameraControlsLogic.ts → CameraControlsLogic.ts} +90 -53
- package/src/implementation/controls/OrthographicCameraControls.ts +27 -121
- package/src/implementation/controls/PerspectiveCameraControls.ts +28 -294
- package/src/implementation/interpolation/CameraInterpolationManager.ts +40 -45
- package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts +19 -22
- package/src/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.ts +15 -16
- package/src/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.ts +17 -19
- package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts +12 -14
- package/src/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.ts +18 -20
- package/src/index.ts +18 -21
- package/src/interfaces/ICameraEngine.ts +24 -11
- package/src/interfaces/camera/ICamera.ts +45 -41
- package/src/interfaces/camera/IOrthographicCamera.ts +27 -9
- package/src/interfaces/camera/IPerspectiveCamera.ts +13 -5
- package/src/interfaces/controls/ICameraControls.ts +49 -6
- package/src/interfaces/controls/ICameraControlsEventDistribution.ts +5 -2
- package/src/interfaces/controls/ICameraControlsLogic.ts +6 -3
- package/src/interfaces/interpolation/ICameraInterpolation.ts +6 -2
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts +0 -32
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.d.ts.map +0 -1
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js +0 -230
- package/dist/implementation/controls/orthographic/CameraControlsEventDistribution.js.map +0 -1
- package/dist/implementation/controls/orthographic/CameraControlsLogic.d.ts +0 -28
- package/dist/implementation/controls/orthographic/CameraControlsLogic.d.ts.map +0 -1
- package/dist/implementation/controls/orthographic/CameraControlsLogic.js +0 -243
- package/dist/implementation/controls/orthographic/CameraControlsLogic.js.map +0 -1
- package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts +0 -32
- package/dist/implementation/controls/perspective/CameraControlsEventDistribution.d.ts.map +0 -1
- package/dist/implementation/controls/perspective/CameraControlsEventDistribution.js.map +0 -1
- package/dist/implementation/controls/perspective/CameraControlsLogic.d.ts.map +0 -1
- package/dist/implementation/controls/perspective/CameraControlsLogic.js.map +0 -1
- package/dist/interfaces/controls/ICameraControlsUsage.d.ts +0 -22
- package/dist/interfaces/controls/ICameraControlsUsage.d.ts.map +0 -1
- package/dist/interfaces/controls/ICameraControlsUsage.js +0 -3
- package/dist/interfaces/controls/ICameraControlsUsage.js.map +0 -1
- package/dist/interfaces/controls/IOrthographicCameraControls.d.ts +0 -30
- package/dist/interfaces/controls/IOrthographicCameraControls.d.ts.map +0 -1
- package/dist/interfaces/controls/IOrthographicCameraControls.js +0 -3
- package/dist/interfaces/controls/IOrthographicCameraControls.js.map +0 -1
- package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts +0 -65
- package/dist/interfaces/controls/IPerspectiveCameraControls.d.ts.map +0 -1
- package/dist/interfaces/controls/IPerspectiveCameraControls.js +0 -3
- package/dist/interfaces/controls/IPerspectiveCameraControls.js.map +0 -1
- package/src/implementation/controls/orthographic/CameraControlsEventDistribution.ts +0 -234
- package/src/implementation/controls/orthographic/CameraControlsLogic.ts +0 -271
- package/src/interfaces/controls/ICameraControlsUsage.ts +0 -30
- package/src/interfaces/controls/IOrthographicCameraControls.ts +0 -13
- package/src/interfaces/controls/IPerspectiveCameraControls.ts +0 -33
|
@@ -1,43 +1,39 @@
|
|
|
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';
|
|
1
11
|
import {
|
|
2
12
|
Converter,
|
|
3
13
|
DomEventEngine,
|
|
4
14
|
Logger,
|
|
5
15
|
SettingsEngine,
|
|
6
16
|
ShapeDiverViewerCameraError,
|
|
7
|
-
|
|
8
|
-
} from '@shapediver/viewer.shared.services'
|
|
9
|
-
import { mat4, vec2, vec3 } from 'gl-matrix'
|
|
10
|
-
import { Box, IBox } from '@shapediver/viewer.shared.math'
|
|
11
|
-
import { IOrthographicCameraSettingsV3 } from '@shapediver/viewer.settings'
|
|
12
|
-
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine'
|
|
13
|
-
import { ITree, Tree } from '@shapediver/viewer.shared.node-tree'
|
|
14
|
-
|
|
15
|
-
import { CAMERA_TYPE } from '../../interfaces/ICameraEngine'
|
|
16
|
-
import { AbstractCamera } from './AbstractCamera'
|
|
17
|
-
import { OrthographicCameraControls } from '../controls/OrthographicCameraControls'
|
|
18
|
-
import { IOrthographicCamera, ORTHOGRAPHIC_CAMERA_DIRECTION } from '../../interfaces/camera/IOrthographicCamera'
|
|
19
|
-
import { IOrthographicCameraControls } from '../../interfaces/controls/IOrthographicCameraControls'
|
|
17
|
+
} from '@shapediver/viewer.shared.services';
|
|
20
18
|
|
|
21
19
|
export class OrthographicCamera extends AbstractCamera implements IOrthographicCamera {
|
|
22
|
-
// #region Properties (
|
|
20
|
+
// #region Properties (11)
|
|
23
21
|
|
|
24
22
|
readonly #converter: Converter = Converter.instance;
|
|
25
23
|
readonly #logger: Logger = Logger.instance;
|
|
26
24
|
readonly #tree: ITree = Tree.instance;
|
|
27
25
|
|
|
28
|
-
#domEventListenerToken?: string;
|
|
29
|
-
#domEventEngine?: DomEventEngine;
|
|
30
|
-
|
|
31
26
|
#bottom: number = -100;
|
|
32
|
-
#direction: ORTHOGRAPHIC_CAMERA_DIRECTION = ORTHOGRAPHIC_CAMERA_DIRECTION.
|
|
27
|
+
#direction: ORTHOGRAPHIC_CAMERA_DIRECTION = ORTHOGRAPHIC_CAMERA_DIRECTION.CUSTOM;
|
|
28
|
+
#domEventEngine?: DomEventEngine;
|
|
33
29
|
#left: number = -100;
|
|
34
30
|
#right: number = 100;
|
|
35
31
|
#top: number = 100;
|
|
36
|
-
#
|
|
37
|
-
#up: vec3 = vec3.fromValues(0, 1, 0);
|
|
38
|
-
protected _controls: IOrthographicCameraControls;
|
|
32
|
+
#up: vec3 = vec3.fromValues(0, 0, 1);
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
protected _controls: ICameraControls;
|
|
35
|
+
|
|
36
|
+
// #endregion Properties (11)
|
|
41
37
|
|
|
42
38
|
// #region Constructors (1)
|
|
43
39
|
|
|
@@ -48,7 +44,7 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
48
44
|
|
|
49
45
|
// #endregion Constructors (1)
|
|
50
46
|
|
|
51
|
-
// #region Public
|
|
47
|
+
// #region Public Getters And Setters (14)
|
|
52
48
|
|
|
53
49
|
public get bottom(): number {
|
|
54
50
|
return this.#bottom;
|
|
@@ -58,11 +54,11 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
58
54
|
this.#bottom = value;
|
|
59
55
|
}
|
|
60
56
|
|
|
61
|
-
public get controls():
|
|
57
|
+
public get controls(): ICameraControls {
|
|
62
58
|
return this._controls;
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
public set controls(value:
|
|
61
|
+
public set controls(value: ICameraControls) {
|
|
66
62
|
this._controls = value;
|
|
67
63
|
}
|
|
68
64
|
|
|
@@ -80,26 +76,22 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
80
76
|
this.up = vec3.fromValues(0, 1, 0);
|
|
81
77
|
break;
|
|
82
78
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.RIGHT:
|
|
83
|
-
|
|
84
|
-
break;
|
|
85
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.LEFT:
|
|
79
|
+
case ORTHOGRAPHIC_CAMERA_DIRECTION.LEFT:
|
|
86
80
|
this.up = vec3.fromValues(0, 0, 1);
|
|
87
81
|
break;
|
|
88
82
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.BACK:
|
|
89
|
-
|
|
90
|
-
break;
|
|
91
|
-
case ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT:
|
|
83
|
+
case ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT:
|
|
92
84
|
this.up = vec3.fromValues(0, 0, 1);
|
|
93
85
|
break;
|
|
94
86
|
default:
|
|
95
|
-
this.up = vec3.fromValues(0,
|
|
87
|
+
this.up = vec3.fromValues(0, 0, 1);
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
if (changedDirection) {
|
|
99
91
|
const { position, target } = this.calculateZoomTo(undefined);
|
|
100
92
|
this.defaultPosition = vec3.clone(position);
|
|
101
93
|
this.defaultTarget = vec3.clone(target);
|
|
102
|
-
|
|
94
|
+
|
|
103
95
|
this.position = vec3.clone(position);
|
|
104
96
|
this.target = vec3.clone(target);
|
|
105
97
|
}
|
|
@@ -137,16 +129,12 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
137
129
|
this.#up = value;
|
|
138
130
|
}
|
|
139
131
|
|
|
140
|
-
|
|
141
|
-
return this.#threeJsObject;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// #endregion Public Accessors (12)
|
|
132
|
+
// #endregion Public Getters And Setters (14)
|
|
145
133
|
|
|
146
134
|
// #region Public Methods (6)
|
|
147
135
|
|
|
148
136
|
public applySettings(settingsEngine: SettingsEngine) {
|
|
149
|
-
const cameraSetting = <
|
|
137
|
+
const cameraSetting = <IOrthographicCameraSettings>settingsEngine.camera.cameras[this.id];
|
|
150
138
|
if (cameraSetting) {
|
|
151
139
|
this.name = cameraSetting.name;
|
|
152
140
|
this.autoAdjust = cameraSetting.autoAdjust;
|
|
@@ -154,10 +142,11 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
154
142
|
this.enableCameraControls = cameraSetting.enableCameraControls;
|
|
155
143
|
this.revertAtMouseUp = cameraSetting.revertAtMouseUp;
|
|
156
144
|
this.revertAtMouseUpDuration = cameraSetting.revertAtMouseUpDuration;
|
|
145
|
+
this.sceneRotation = vec2.fromValues(cameraSetting.sceneRotation.x, cameraSetting.sceneRotation.y);
|
|
157
146
|
this.zoomExtentsFactor = cameraSetting.zoomExtentsFactor;
|
|
158
147
|
|
|
159
|
-
|
|
160
|
-
|
|
148
|
+
const position = this.#converter.toVec3(cameraSetting.position);
|
|
149
|
+
const target = this.#converter.toVec3(cameraSetting.target);
|
|
161
150
|
this.defaultPosition = vec3.clone(position);
|
|
162
151
|
this.defaultTarget = vec3.clone(target);
|
|
163
152
|
|
|
@@ -167,40 +156,36 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
167
156
|
|
|
168
157
|
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2]) {
|
|
169
158
|
if (this._viewportId) {
|
|
170
|
-
this._stateEngine.
|
|
159
|
+
this._stateEngine.viewportEngines[this._viewportId].boundingBoxCreated
|
|
171
160
|
.then(async () => {
|
|
172
161
|
await this.zoomTo(undefined, { duration: 0 });
|
|
173
162
|
this.defaultPosition = vec3.clone(this._controls.position);
|
|
174
163
|
this.defaultTarget = vec3.clone(this._controls.target);
|
|
175
|
-
})
|
|
164
|
+
});
|
|
176
165
|
}
|
|
177
166
|
}
|
|
178
167
|
(<OrthographicCameraControls>this._controls).applySettings(settingsEngine);
|
|
179
168
|
}
|
|
180
169
|
|
|
181
170
|
public assignViewer(renderingEngine: IRenderingEngine): void {
|
|
182
|
-
if(renderingEngine.closed)
|
|
171
|
+
if (renderingEngine.closed)
|
|
183
172
|
throw new ShapeDiverViewerCameraError(`OrthographicCamera(${this.id}).assignViewer: Viewer with id ${renderingEngine.id} not found.`);
|
|
184
|
-
|
|
173
|
+
|
|
185
174
|
this.assignViewerInternal(renderingEngine.id, renderingEngine.canvas);
|
|
186
175
|
this._controls.assignViewer(renderingEngine.id, renderingEngine.canvas);
|
|
187
176
|
|
|
188
|
-
if (this
|
|
189
|
-
this.#domEventEngine.removeDomEventListener(this
|
|
177
|
+
if (this.domEventListenerToken && this.#domEventEngine)
|
|
178
|
+
this.#domEventEngine.removeDomEventListener(this.domEventListenerToken);
|
|
190
179
|
|
|
191
180
|
this.#domEventEngine = renderingEngine.domEventEngine;
|
|
192
|
-
this
|
|
181
|
+
this.domEventListenerToken = this.#domEventEngine.addDomEventListener((<OrthographicCameraControls>this._controls).cameraControlsEventDistribution);
|
|
193
182
|
|
|
194
183
|
this.boundingBox = this.#tree.root.boundingBox.clone();
|
|
195
|
-
|
|
196
|
-
this._stateEngine.
|
|
184
|
+
|
|
185
|
+
this._stateEngine.viewportEngines[renderingEngine.id].boundingBoxCreated.then(async () => {
|
|
197
186
|
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2])
|
|
198
187
|
await this.zoomTo(undefined, { duration: 0 });
|
|
199
|
-
})
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
public clone(): IOrthographicCamera {
|
|
203
|
-
return new OrthographicCamera(this.id, this.version);
|
|
188
|
+
});
|
|
204
189
|
}
|
|
205
190
|
|
|
206
191
|
public calculateZoomTo(zoomTarget?: Box, startingPosition: vec3 = this.position, startingTarget: vec3 = this.target): { position: vec3; target: vec3; } {
|
|
@@ -214,64 +199,78 @@ export class OrthographicCamera extends AbstractCamera implements IOrthographicC
|
|
|
214
199
|
// specified Box
|
|
215
200
|
box = zoomTarget.clone();
|
|
216
201
|
}
|
|
217
|
-
|
|
218
|
-
if (box.isEmpty()) return { position: vec3.create(), target: vec3.create() }
|
|
219
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
|
+
|
|
220
209
|
const factor = 2 * box.boundingSphere.radius * this.zoomExtentsFactor;
|
|
221
|
-
const center = vec3.clone(box.boundingSphere.center);
|
|
222
210
|
|
|
223
211
|
switch (this.#direction) {
|
|
224
212
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.TOP:
|
|
225
213
|
return {
|
|
226
|
-
position: vec3.fromValues(
|
|
227
|
-
target: vec3.clone(
|
|
228
|
-
}
|
|
214
|
+
position: vec3.fromValues(target[0], target[1], target[2] + factor),
|
|
215
|
+
target: vec3.clone(target)
|
|
216
|
+
};
|
|
229
217
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM:
|
|
230
218
|
return {
|
|
231
|
-
position: vec3.fromValues(
|
|
232
|
-
target: vec3.clone(
|
|
233
|
-
}
|
|
219
|
+
position: vec3.fromValues(target[0], target[1], target[2] - factor),
|
|
220
|
+
target: vec3.clone(target)
|
|
221
|
+
};
|
|
234
222
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.RIGHT:
|
|
235
223
|
return {
|
|
236
|
-
position: vec3.fromValues(
|
|
237
|
-
target: vec3.clone(
|
|
238
|
-
}
|
|
224
|
+
position: vec3.fromValues(target[0] + factor, target[1], target[2]),
|
|
225
|
+
target: vec3.clone(target)
|
|
226
|
+
};
|
|
239
227
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.LEFT:
|
|
240
228
|
return {
|
|
241
|
-
position: vec3.fromValues(
|
|
242
|
-
target: vec3.clone(
|
|
243
|
-
}
|
|
229
|
+
position: vec3.fromValues(target[0] - factor, target[1], target[2]),
|
|
230
|
+
target: vec3.clone(target)
|
|
231
|
+
};
|
|
244
232
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.BACK:
|
|
245
233
|
return {
|
|
246
|
-
position: vec3.fromValues(
|
|
247
|
-
target: vec3.clone(
|
|
248
|
-
}
|
|
234
|
+
position: vec3.fromValues(target[0], target[1] + factor, target[2]),
|
|
235
|
+
target: vec3.clone(target)
|
|
236
|
+
};
|
|
249
237
|
case ORTHOGRAPHIC_CAMERA_DIRECTION.FRONT:
|
|
250
238
|
return {
|
|
251
|
-
position: vec3.fromValues(
|
|
252
|
-
target: vec3.clone(
|
|
253
|
-
}
|
|
239
|
+
position: vec3.fromValues(target[0], target[1] - factor, target[2]),
|
|
240
|
+
target: vec3.clone(target)
|
|
241
|
+
};
|
|
254
242
|
default:
|
|
255
|
-
|
|
256
|
-
position
|
|
257
|
-
|
|
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
|
+
};
|
|
258
253
|
}
|
|
259
254
|
}
|
|
260
255
|
}
|
|
261
256
|
|
|
257
|
+
public clone(): IOrthographicCamera {
|
|
258
|
+
return new OrthographicCamera(this.id, this.version);
|
|
259
|
+
}
|
|
260
|
+
|
|
262
261
|
public project(pos: vec3): vec2 {
|
|
263
262
|
const m = mat4.targetTo(mat4.create(), this.position, this.target, this.up);
|
|
264
263
|
const p = mat4.ortho(mat4.create(), this.left, this.right, this.bottom, this.top, this.near, this.far);
|
|
265
|
-
vec3.transformMat4(pos, pos, mat4.invert(m, m))
|
|
266
|
-
vec3.transformMat4(pos, pos, p)
|
|
267
|
-
return vec2.fromValues(pos[0], pos[1])
|
|
264
|
+
vec3.transformMat4(pos, pos, mat4.invert(m, m));
|
|
265
|
+
vec3.transformMat4(pos, pos, p);
|
|
266
|
+
return vec2.fromValues(pos[0], pos[1]);
|
|
268
267
|
}
|
|
269
268
|
|
|
270
|
-
public unproject(pos: vec3
|
|
269
|
+
public unproject(pos: vec3): vec3 {
|
|
271
270
|
const m = mat4.targetTo(mat4.create(), this.position, this.target, this.up);
|
|
272
271
|
const p = mat4.ortho(mat4.create(), this.left, this.right, this.bottom, this.top, this.near, this.far);
|
|
273
|
-
vec3.transformMat4(pos, pos, mat4.invert(p, p))
|
|
274
|
-
vec3.transformMat4(pos, pos, m)
|
|
272
|
+
vec3.transformMat4(pos, pos, mat4.invert(p, p));
|
|
273
|
+
vec3.transformMat4(pos, pos, m);
|
|
275
274
|
return vec3.clone(pos);
|
|
276
275
|
}
|
|
277
276
|
|
|
@@ -1,40 +1,38 @@
|
|
|
1
|
+
import { AbstractCamera } from './AbstractCamera';
|
|
2
|
+
import { Box, IBox, Plane } from '@shapediver/viewer.shared.math';
|
|
3
|
+
import { CAMERA_TYPE } from '../../interfaces/ICameraEngine';
|
|
4
|
+
import { ICameraControls } from '../../interfaces/controls/ICameraControls';
|
|
5
|
+
import { IPerspectiveCamera } from '../../interfaces/camera/IPerspectiveCamera';
|
|
6
|
+
import { IPerspectiveCameraSettings } 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 {
|
|
10
|
+
mat4,
|
|
11
|
+
quat,
|
|
12
|
+
vec2,
|
|
13
|
+
vec3
|
|
14
|
+
} from 'gl-matrix';
|
|
15
|
+
import { PerspectiveCameraControls } from '../controls/PerspectiveCameraControls';
|
|
1
16
|
import {
|
|
2
17
|
Converter,
|
|
3
18
|
DomEventEngine,
|
|
4
|
-
Logger,
|
|
5
19
|
SettingsEngine,
|
|
6
20
|
ShapeDiverViewerCameraError,
|
|
7
|
-
|
|
8
|
-
} from '@shapediver/viewer.shared.services'
|
|
9
|
-
import { mat4, quat, vec2, vec3 } from 'gl-matrix'
|
|
10
|
-
import { Box, IBox, Plane } from '@shapediver/viewer.shared.math'
|
|
11
|
-
import { IPerspectiveCameraSettingsV3 } from '@shapediver/viewer.settings'
|
|
12
|
-
import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine'
|
|
13
|
-
import { ITree, Tree } from '@shapediver/viewer.shared.node-tree'
|
|
14
|
-
|
|
15
|
-
import { CAMERA_TYPE } from '../../interfaces/ICameraEngine'
|
|
16
|
-
import { AbstractCamera } from './AbstractCamera'
|
|
17
|
-
import { PerspectiveCameraControls } from '../controls/PerspectiveCameraControls'
|
|
18
|
-
import { IPerspectiveCamera } from '../../interfaces/camera/IPerspectiveCamera'
|
|
19
|
-
import { IPerspectiveCameraControls } from '../../interfaces/controls/IPerspectiveCameraControls'
|
|
21
|
+
} from '@shapediver/viewer.shared.services';
|
|
20
22
|
|
|
21
23
|
export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCamera {
|
|
22
|
-
// #region Properties (
|
|
24
|
+
// #region Properties (6)
|
|
23
25
|
|
|
24
26
|
readonly #converter: Converter = Converter.instance;
|
|
25
|
-
readonly #logger: Logger = Logger.instance;
|
|
26
27
|
readonly #tree: ITree = Tree.instance;
|
|
27
28
|
|
|
28
|
-
protected _controls: IPerspectiveCameraControls;
|
|
29
|
-
|
|
30
|
-
#domEventListenerToken?: string;
|
|
31
|
-
#domEventEngine?: DomEventEngine;
|
|
32
|
-
|
|
33
29
|
#aspect: number | undefined;
|
|
30
|
+
#domEventEngine?: DomEventEngine;
|
|
34
31
|
#fov: number = 60;
|
|
35
|
-
#threeJsObject: { [key: string]: THREE.PerspectiveCamera } = {};
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
protected _controls: ICameraControls;
|
|
34
|
+
|
|
35
|
+
// #endregion Properties (6)
|
|
38
36
|
|
|
39
37
|
// #region Constructors (1)
|
|
40
38
|
|
|
@@ -46,7 +44,7 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
46
44
|
|
|
47
45
|
// #endregion Constructors (1)
|
|
48
46
|
|
|
49
|
-
// #region Public
|
|
47
|
+
// #region Public Getters And Setters (6)
|
|
50
48
|
|
|
51
49
|
public get aspect(): number | undefined {
|
|
52
50
|
return this.#aspect;
|
|
@@ -56,11 +54,11 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
56
54
|
this.#aspect = value;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
public get controls():
|
|
57
|
+
public get controls(): ICameraControls {
|
|
60
58
|
return this._controls;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
public set controls(value:
|
|
61
|
+
public set controls(value: ICameraControls) {
|
|
64
62
|
this._controls = value;
|
|
65
63
|
}
|
|
66
64
|
|
|
@@ -72,16 +70,12 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
72
70
|
this.#fov = value;
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
return this.#threeJsObject;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// #endregion Public Accessors (4)
|
|
73
|
+
// #endregion Public Getters And Setters (6)
|
|
80
74
|
|
|
81
75
|
// #region Public Methods (6)
|
|
82
76
|
|
|
83
77
|
public applySettings(settingsEngine: SettingsEngine) {
|
|
84
|
-
const cameraSetting = <
|
|
78
|
+
const cameraSetting = <IPerspectiveCameraSettings>settingsEngine.camera.cameras[this.id];
|
|
85
79
|
if (cameraSetting) {
|
|
86
80
|
this.name = cameraSetting.name;
|
|
87
81
|
this.autoAdjust = cameraSetting.autoAdjust;
|
|
@@ -89,10 +83,11 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
89
83
|
this.enableCameraControls = cameraSetting.enableCameraControls;
|
|
90
84
|
this.revertAtMouseUp = cameraSetting.revertAtMouseUp;
|
|
91
85
|
this.revertAtMouseUpDuration = cameraSetting.revertAtMouseUpDuration;
|
|
86
|
+
this.sceneRotation = vec2.fromValues(cameraSetting.sceneRotation.x, cameraSetting.sceneRotation.y);
|
|
92
87
|
this.zoomExtentsFactor = cameraSetting.zoomExtentsFactor;
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
const position = this.#converter.toVec3(cameraSetting.position);
|
|
90
|
+
const target = this.#converter.toVec3(cameraSetting.target);
|
|
96
91
|
this.defaultPosition = vec3.clone(position);
|
|
97
92
|
this.defaultTarget = vec3.clone(target);
|
|
98
93
|
|
|
@@ -102,40 +97,36 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2]) {
|
|
105
|
-
if(this._viewportId) {
|
|
106
|
-
this._stateEngine.
|
|
100
|
+
if (this._viewportId) {
|
|
101
|
+
this._stateEngine.viewportEngines[this._viewportId].boundingBoxCreated.then(async () => {
|
|
107
102
|
await this.zoomTo(undefined, { duration: 0 });
|
|
108
103
|
this.defaultPosition = vec3.clone(this._controls.position);
|
|
109
104
|
this.defaultTarget = vec3.clone(this._controls.target);
|
|
110
|
-
})
|
|
105
|
+
});
|
|
111
106
|
}
|
|
112
107
|
}
|
|
113
108
|
(<PerspectiveCameraControls>this._controls).applySettings(settingsEngine);
|
|
114
109
|
}
|
|
115
110
|
|
|
116
111
|
public assignViewer(renderingEngine: IRenderingEngine): void {
|
|
117
|
-
if(renderingEngine.closed)
|
|
112
|
+
if (renderingEngine.closed)
|
|
118
113
|
throw new ShapeDiverViewerCameraError(`OrthographicCamera(${this.id}).assignViewer: Viewer with id ${renderingEngine.id} not found.`);
|
|
119
114
|
|
|
120
115
|
this.assignViewerInternal(renderingEngine.id, renderingEngine.canvas);
|
|
121
116
|
this._controls.assignViewer(renderingEngine.id, renderingEngine.canvas);
|
|
122
117
|
|
|
123
|
-
if (this
|
|
124
|
-
this.#domEventEngine.removeDomEventListener(this
|
|
118
|
+
if (this.domEventListenerToken && this.#domEventEngine)
|
|
119
|
+
this.#domEventEngine.removeDomEventListener(this.domEventListenerToken);
|
|
125
120
|
|
|
126
121
|
this.#domEventEngine = renderingEngine.domEventEngine;
|
|
127
|
-
this
|
|
122
|
+
this.domEventListenerToken = this.#domEventEngine.addDomEventListener((<PerspectiveCameraControls>this._controls).cameraControlsEventDistribution);
|
|
128
123
|
|
|
129
124
|
this.boundingBox = this.#tree.root.boundingBox.clone();
|
|
130
125
|
|
|
131
|
-
this._stateEngine.
|
|
126
|
+
this._stateEngine.viewportEngines[renderingEngine.id].boundingBoxCreated.then(async () => {
|
|
132
127
|
if (this.position[0] === this.target[0] && this.position[1] === this.target[1] && this.position[2] === this.target[2])
|
|
133
128
|
await this.zoomTo(undefined, { duration: 0 });
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public clone(): IPerspectiveCamera {
|
|
138
|
-
return new PerspectiveCamera(this.id, this.version, this.aspect);
|
|
129
|
+
});
|
|
139
130
|
}
|
|
140
131
|
|
|
141
132
|
public calculateZoomTo(zoomTarget?: Box, startingPosition: vec3 = this.position, startingTarget: vec3 = this.target): { position: vec3, target: vec3 } {
|
|
@@ -150,28 +141,28 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
150
141
|
box = zoomTarget.clone();
|
|
151
142
|
}
|
|
152
143
|
|
|
153
|
-
if (box.isEmpty()) return { position: vec3.create(), target: vec3.create() }
|
|
144
|
+
if (box.isEmpty()) return { position: vec3.create(), target: vec3.create() };
|
|
154
145
|
|
|
155
146
|
const samePosition = startingPosition[0] === startingTarget[0] && startingPosition[1] === startingTarget[1] && startingPosition[2] === startingTarget[2];
|
|
156
|
-
|
|
147
|
+
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);
|
|
157
148
|
|
|
158
149
|
// if the camera position and the target are the same, we set a corner position
|
|
159
150
|
if (startingPosition[0] === startingTarget[0] && startingPosition[1] === startingTarget[1] && startingPosition[2] === startingTarget[2])
|
|
160
151
|
startingPosition = vec3.fromValues(target[0], target[1] - 7.5, target[2] + 5);
|
|
161
152
|
|
|
162
153
|
// extend box by the factor
|
|
163
|
-
const boxDir = vec3.subtract(vec3.create(), box.max, target)
|
|
154
|
+
const boxDir = vec3.subtract(vec3.create(), box.max, target);
|
|
164
155
|
vec3.multiply(boxDir, boxDir, samePosition ? vec3.fromValues(2, 2, 2) : vec3.fromValues(this.zoomExtentsFactor, this.zoomExtentsFactor, this.zoomExtentsFactor));
|
|
165
|
-
box = new Box(vec3.subtract(vec3.create(), target, boxDir), vec3.add(vec3.create(), target, boxDir))
|
|
156
|
+
box = new Box(vec3.subtract(vec3.create(), target, boxDir), vec3.add(vec3.create(), target, boxDir));
|
|
166
157
|
|
|
167
158
|
const direction = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), target, startingPosition));
|
|
168
159
|
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
const cross = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), vec3.fromValues(0, 0, 1), direction));
|
|
161
|
+
const up = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), cross, direction));
|
|
171
162
|
|
|
172
163
|
let position = vec3.add(vec3.create(), target, vec3.multiply(vec3.create(), direction, vec3.fromValues(-0.00000001, -0.00000001, -0.00000001)));
|
|
173
164
|
|
|
174
|
-
|
|
165
|
+
const points = [];
|
|
175
166
|
points.push(vec3.fromValues(box.min[0], box.min[1], box.min[2]));
|
|
176
167
|
points.push(vec3.fromValues(box.min[0], box.min[1], box.max[2]));
|
|
177
168
|
points.push(vec3.fromValues(box.min[0], box.max[1], box.min[2]));
|
|
@@ -181,18 +172,18 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
181
172
|
points.push(vec3.fromValues(box.max[0], box.max[1], box.min[2]));
|
|
182
173
|
points.push(vec3.fromValues(box.max[0], box.max[1], box.max[2]));
|
|
183
174
|
|
|
184
|
-
|
|
185
|
-
|
|
175
|
+
const fovDown = vec3.normalize(vec3.create(), vec3.transformQuat(vec3.create(), direction, quat.setAxisAngle(quat.create(), cross, (this.fov / 2) * (Math.PI / 180))));
|
|
176
|
+
const fovUp = vec3.normalize(vec3.create(), vec3.transformQuat(vec3.create(), direction, quat.setAxisAngle(quat.create(), cross, -(this.fov / 2) * (Math.PI / 180))));
|
|
186
177
|
|
|
187
178
|
const aspect = samePosition ? 1.5 : this.aspect || 1.5;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
179
|
+
const hFoV = 2 * Math.atan(Math.tan(this.fov * Math.PI / 180 / 2) * aspect);
|
|
180
|
+
const fovRight = vec3.normalize(vec3.create(), vec3.transformQuat(vec3.create(), direction, quat.setAxisAngle(quat.create(), up, hFoV / 2)));
|
|
181
|
+
const fovLeft = vec3.normalize(vec3.create(), vec3.transformQuat(vec3.create(), direction, quat.setAxisAngle(quat.create(), up, -hFoV / 2)));
|
|
191
182
|
|
|
192
|
-
|
|
183
|
+
const planeCross = new Plane(vec3.clone(cross), 0);
|
|
193
184
|
planeCross.setFromNormalAndCoplanarPoint(vec3.clone(cross), vec3.clone(target));
|
|
194
185
|
|
|
195
|
-
|
|
186
|
+
const planeUp = new Plane(vec3.fromValues(0, 0, 1), 0);
|
|
196
187
|
planeUp.setFromNormalAndCoplanarPoint(vec3.clone(up), vec3.clone(target));
|
|
197
188
|
|
|
198
189
|
let distanceCamera = 0.0;
|
|
@@ -202,7 +193,7 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
202
193
|
|
|
203
194
|
if (vec3.dot(direction, fovDown) > vec3.dot(direction, toP)) {
|
|
204
195
|
const currentDir = vec3.multiply(vec3.create(), vec3.dot(fovDown, toP) > vec3.dot(fovUp, toP) ? fovDown : fovUp, vec3.fromValues(-1, -1, -1));
|
|
205
|
-
const distance = planeUp.intersect(projected, currentDir)
|
|
196
|
+
const distance = planeUp.intersect(projected, currentDir);
|
|
206
197
|
if (distance) {
|
|
207
198
|
const cameraPoint = vec3.add(vec3.create(), vec3.multiply(vec3.create(), currentDir, vec3.fromValues(distance, distance, distance)), projected);
|
|
208
199
|
distanceCamera = Math.max(distanceCamera, vec3.distance(target, cameraPoint));
|
|
@@ -214,7 +205,7 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
214
205
|
|
|
215
206
|
if (vec3.dot(direction, fovRight) > vec3.dot(direction, toP)) {
|
|
216
207
|
const currentDir = vec3.multiply(vec3.create(), vec3.dot(fovRight, toP) > vec3.dot(fovLeft, toP) ? fovRight : fovLeft, vec3.fromValues(-1, -1, -1));
|
|
217
|
-
const distance = planeCross.intersect(projected, currentDir)
|
|
208
|
+
const distance = planeCross.intersect(projected, currentDir);
|
|
218
209
|
if (distance) {
|
|
219
210
|
const cameraPoint = vec3.add(vec3.create(), vec3.multiply(vec3.create(), currentDir, vec3.fromValues(distance, distance, distance)), projected);
|
|
220
211
|
distanceCamera = Math.max(distanceCamera, vec3.distance(target, cameraPoint));
|
|
@@ -226,24 +217,28 @@ export class PerspectiveCamera extends AbstractCamera implements IPerspectiveCam
|
|
|
226
217
|
|
|
227
218
|
return {
|
|
228
219
|
position, target
|
|
229
|
-
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public clone(): IPerspectiveCamera {
|
|
224
|
+
return new PerspectiveCamera(this.id, this.version, this.aspect);
|
|
230
225
|
}
|
|
231
226
|
|
|
232
227
|
public project(pos: vec3, position = this.position, target = this.target): vec2 {
|
|
233
228
|
const m = mat4.targetTo(mat4.create(), position, target, vec3.fromValues(0, 0, 1));
|
|
234
229
|
const aspect = this.aspect || 1.5;
|
|
235
230
|
const p = mat4.perspective(mat4.create(), this.fov / (180 / Math.PI), aspect, this.near, this.far);
|
|
236
|
-
vec3.transformMat4(pos, pos, mat4.invert(m, m))
|
|
237
|
-
vec3.transformMat4(pos, pos, p)
|
|
238
|
-
return vec2.fromValues(pos[0], pos[1])
|
|
231
|
+
vec3.transformMat4(pos, pos, mat4.invert(m, m));
|
|
232
|
+
vec3.transformMat4(pos, pos, p);
|
|
233
|
+
return vec2.fromValues(pos[0], pos[1]);
|
|
239
234
|
}
|
|
240
235
|
|
|
241
236
|
public unproject(pos: vec3, position = this.position, target = this.target): vec3 {
|
|
242
237
|
const m = mat4.targetTo(mat4.create(), position, target, vec3.fromValues(0, 0, 1));
|
|
243
238
|
const aspect = this.aspect || 1.5;
|
|
244
239
|
const p = mat4.perspective(mat4.create(), this.fov / (180 / Math.PI), aspect, this.near, this.far);
|
|
245
|
-
vec3.transformMat4(pos, pos, mat4.invert(p, p))
|
|
246
|
-
vec3.transformMat4(pos, pos, m)
|
|
240
|
+
vec3.transformMat4(pos, pos, mat4.invert(p, p));
|
|
241
|
+
vec3.transformMat4(pos, pos, m);
|
|
247
242
|
return vec3.clone(pos);
|
|
248
243
|
}
|
|
249
244
|
|