@shapediver/viewer.rendering-engine.camera-engine 1.15.7 → 2.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 +15 -12
- package/dist/implementation/CameraEngine.d.ts.map +1 -1
- package/dist/implementation/CameraEngine.js +53 -40
- package/dist/implementation/CameraEngine.js.map +1 -1
- package/dist/implementation/camera/AbstractCamera.d.ts +23 -46
- package/dist/implementation/camera/AbstractCamera.d.ts.map +1 -1
- package/dist/implementation/camera/AbstractCamera.js +11 -6
- package/dist/implementation/camera/AbstractCamera.js.map +1 -1
- package/dist/implementation/camera/OrthographicCamera.d.ts +10 -5
- package/dist/implementation/camera/OrthographicCamera.d.ts.map +1 -1
- package/dist/implementation/camera/OrthographicCamera.js +29 -15
- package/dist/implementation/camera/OrthographicCamera.js.map +1 -1
- package/dist/implementation/camera/PerspectiveCamera.d.ts +10 -4
- package/dist/implementation/camera/PerspectiveCamera.d.ts.map +1 -1
- package/dist/implementation/camera/PerspectiveCamera.js +27 -15
- package/dist/implementation/camera/PerspectiveCamera.js.map +1 -1
- package/dist/implementation/controls/AbstractCameraControls.d.ts +6 -12
- package/dist/implementation/controls/AbstractCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/AbstractCameraControls.js +5 -5
- package/dist/implementation/controls/AbstractCameraControls.js.map +1 -1
- package/dist/implementation/controls/OrthographicCameraControls.d.ts +2 -2
- package/dist/implementation/controls/OrthographicCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/OrthographicCameraControls.js +3 -4
- package/dist/implementation/controls/OrthographicCameraControls.js.map +1 -1
- package/dist/implementation/controls/PerspectiveCameraControls.d.ts +2 -2
- package/dist/implementation/controls/PerspectiveCameraControls.d.ts.map +1 -1
- package/dist/implementation/controls/PerspectiveCameraControls.js +3 -4
- package/dist/implementation/controls/PerspectiveCameraControls.js.map +1 -1
- package/dist/implementation/interpolation/CameraInterpolationManager.d.ts +2 -8
- package/dist/implementation/interpolation/CameraInterpolationManager.d.ts.map +1 -1
- package/dist/implementation/interpolation/CameraInterpolationManager.js +0 -1
- package/dist/implementation/interpolation/CameraInterpolationManager.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ICameraEngine.d.ts +4 -3
- package/dist/interfaces/ICameraEngine.d.ts.map +1 -1
- package/dist/interfaces/ICameraEngine.js +6 -6
- package/dist/interfaces/ICameraEngine.js.map +1 -1
- package/dist/interfaces/camera/ICamera.d.ts +37 -33
- package/dist/interfaces/camera/ICamera.d.ts.map +1 -1
- package/dist/interfaces/camera/IOrthographicCamera.d.ts +1 -0
- package/dist/interfaces/camera/IOrthographicCamera.d.ts.map +1 -1
- package/dist/interfaces/camera/IPerspectiveCamera.d.ts +1 -0
- package/dist/interfaces/camera/IPerspectiveCamera.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControls.d.ts +29 -0
- package/dist/interfaces/controls/ICameraControls.d.ts.map +1 -1
- package/dist/interfaces/controls/ICameraControlsUsage.d.ts +2 -9
- package/dist/interfaces/controls/ICameraControlsUsage.d.ts.map +1 -1
- package/package.json +15 -12
- package/src/implementation/CameraEngine.ts +324 -0
- package/src/implementation/camera/AbstractCamera.ts +314 -0
- package/src/implementation/camera/OrthographicCamera.ts +276 -0
- package/src/implementation/camera/PerspectiveCamera.ts +250 -0
- package/src/implementation/controls/AbstractCameraControls.ts +329 -0
- package/src/implementation/controls/OrthographicCameraControls.ts +131 -0
- package/src/implementation/controls/PerspectiveCameraControls.ts +263 -0
- package/src/implementation/controls/orthographic/CameraControlsEventDistribution.ts +205 -0
- package/src/implementation/controls/orthographic/CameraControlsLogic.ts +279 -0
- package/src/implementation/controls/perspective/CameraControlsEventDistribution.ts +221 -0
- package/src/implementation/controls/perspective/CameraControlsLogic.ts +478 -0
- package/src/implementation/interpolation/CameraInterpolationManager.ts +154 -0
- package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts +86 -0
- package/src/implementation/interpolation/interpolationMethods/CameraLinearInterpolation.ts +42 -0
- package/src/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.ts +63 -0
- package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts +43 -0
- package/src/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.ts +67 -0
- package/src/index.ts +31 -0
- package/src/interfaces/ICameraEngine.ts +19 -0
- package/src/interfaces/camera/ICamera.ts +77 -0
- package/src/interfaces/camera/IOrthographicCamera.ts +18 -0
- package/src/interfaces/camera/IPerspectiveCamera.ts +10 -0
- package/src/interfaces/controls/ICameraControls.ts +37 -0
- package/src/interfaces/controls/ICameraControlsEventDistribution.ts +8 -0
- package/src/interfaces/controls/ICameraControlsLogic.ts +8 -0
- package/src/interfaces/controls/ICameraControlsUsage.ts +30 -0
- package/src/interfaces/controls/IOrthographicCameraControls.ts +13 -0
- package/src/interfaces/controls/IPerspectiveCameraControls.ts +25 -0
- package/src/interfaces/interpolation/ICameraInterpolation.ts +5 -0
- package/tsconfig.json +17 -0
package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { mat4, quat, vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
import { ICamera } from '../../../interfaces/camera/ICamera'
|
|
4
|
+
import { ICameraControlsUsage } from '../../../interfaces/controls/ICameraControlsUsage'
|
|
5
|
+
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation'
|
|
6
|
+
|
|
7
|
+
export class CameraCylindricalInterpolation implements ICameraInterpolation {
|
|
8
|
+
// #region Properties (10)
|
|
9
|
+
|
|
10
|
+
private _dir_from: vec3;
|
|
11
|
+
private _dir_to: vec3;
|
|
12
|
+
private _from_position_heightAdjusted: vec3;
|
|
13
|
+
private _h_from: number;
|
|
14
|
+
private _h_to: number;
|
|
15
|
+
private _lorr: vec3;
|
|
16
|
+
private _r_from: number;
|
|
17
|
+
private _r_to: number;
|
|
18
|
+
private _shortest_angle: number;
|
|
19
|
+
private _to_position_heightAdjusted: vec3;
|
|
20
|
+
|
|
21
|
+
// #endregion Properties (10)
|
|
22
|
+
|
|
23
|
+
// #region Constructors (1)
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private readonly _camera: ICamera,
|
|
27
|
+
private readonly _cameraControls: ICameraControlsUsage,
|
|
28
|
+
private readonly _from: { position: vec3, target: vec3 },
|
|
29
|
+
private readonly _to: { position: vec3, target: vec3 })
|
|
30
|
+
{
|
|
31
|
+
this._h_from = this._from.position[2] - this._from.target[2];
|
|
32
|
+
this._from_position_heightAdjusted = vec3.fromValues(this._from.position[0], this._from.position[1], this._from.target[2]);
|
|
33
|
+
this._r_from = vec3.distance(this._from_position_heightAdjusted, this._from.target);
|
|
34
|
+
this._dir_from = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._from_position_heightAdjusted, this._from.target));
|
|
35
|
+
|
|
36
|
+
this._h_to = this._to.position[2] - this._to.target[2];
|
|
37
|
+
this._to_position_heightAdjusted = vec3.fromValues(this._to.position[0], this._to.position[1], this._to.target[2]);
|
|
38
|
+
this._r_to = vec3.distance(this._to_position_heightAdjusted, this._to.target);
|
|
39
|
+
this._dir_to = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._to_position_heightAdjusted, this._to.target));
|
|
40
|
+
|
|
41
|
+
if (this._dir_from[0] === 0 && this._dir_from[1] === 0 && this._dir_from[2] === 0)
|
|
42
|
+
this._dir_from = vec3.fromValues(1,0,0);
|
|
43
|
+
|
|
44
|
+
if (this._dir_to[0] === 0 && this._dir_to[1] === 0 && this._dir_to[2] === 0)
|
|
45
|
+
this._dir_to = vec3.fromValues(1,0,0);
|
|
46
|
+
|
|
47
|
+
this._lorr = vec3.cross(vec3.create(), this._dir_to, this._dir_from);
|
|
48
|
+
// This is why people hate JavaScript. The dot product of two normalized vector is larger than 1 on occasion due to precision errors...
|
|
49
|
+
let dot1 = Math.min(1, Math.max(-1, vec3.dot(this._dir_to, this._dir_from)));
|
|
50
|
+
let dot2 = Math.min(1, Math.max(-1, vec3.dot(this._lorr, vec3.fromValues(0, 0, 1))));
|
|
51
|
+
this._shortest_angle = dot2 > 0 ? -Math.acos(dot1) : Math.acos(dot1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// #endregion Constructors (1)
|
|
55
|
+
|
|
56
|
+
// #region Public Methods (3)
|
|
57
|
+
|
|
58
|
+
public onComplete(value: { delta: number }): void {
|
|
59
|
+
let positionOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.position[0], this._to.position[1], this._to.position[2]), this._cameraControls.getPositionWithUpdates());
|
|
60
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
61
|
+
let targetOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.target[0], this._to.target[1], this._to.target[2]), this._cameraControls.getTargetWithUpdates());
|
|
62
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public onStop(value: { delta: number }): void {
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public onUpdate(value: { delta: number }): void {
|
|
69
|
+
let t = vec3.add(vec3.create(), vec3.multiply(vec3.create(), this._from.target, vec3.fromValues(1 - value.delta, 1 - value.delta, 1 - value.delta)), vec3.multiply(vec3.create(), this._to.target, vec3.fromValues(value.delta, value.delta, value.delta)));
|
|
70
|
+
let targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
71
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
72
|
+
|
|
73
|
+
let angle = this._shortest_angle * value.delta;
|
|
74
|
+
let dir = vec3.transformQuat(vec3.create(), this._dir_from, quat.setAxisAngle(quat.create(), vec3.fromValues(0, 0, 1), angle));
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
let scalar = this._r_from * (1 - value.delta) + this._r_to * value.delta;
|
|
78
|
+
let p = vec3.add(vec3.create(), t, vec3.multiply(vec3.create(), dir, vec3.fromValues(scalar, scalar, scalar)));
|
|
79
|
+
vec3.add(p, p, vec3.fromValues(0, 0, (this._h_from * (1 - value.delta) + this._h_to * value.delta)));
|
|
80
|
+
|
|
81
|
+
let positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
82
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// #endregion Public Methods (3)
|
|
86
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { mat4, vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
import { ICamera } from '../../../interfaces/camera/ICamera'
|
|
4
|
+
import { ICameraControlsUsage } from '../../../interfaces/controls/ICameraControlsUsage'
|
|
5
|
+
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation'
|
|
6
|
+
|
|
7
|
+
export class CameraLinearInterpolation implements ICameraInterpolation {
|
|
8
|
+
// #region Constructors (1)
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly _camera: ICamera,
|
|
12
|
+
private readonly _cameraControls: ICameraControlsUsage,
|
|
13
|
+
private readonly _from: { position: vec3, target: vec3 },
|
|
14
|
+
private readonly _to: { position: vec3, target: vec3 })
|
|
15
|
+
{
|
|
16
|
+
}
|
|
17
|
+
// #endregion Constructors (1)
|
|
18
|
+
|
|
19
|
+
// #region Public Methods (3)
|
|
20
|
+
|
|
21
|
+
public onComplete(value: { delta: number }): void {
|
|
22
|
+
let positionOffset = vec3.subtract(vec3.create(), this._to.position, this._cameraControls.getPositionWithUpdates());
|
|
23
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
24
|
+
let targetOffset = vec3.subtract(vec3.create(), this._to.target, this._cameraControls.getTargetWithUpdates());
|
|
25
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public onStop(value: { delta: number }): void {
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public onUpdate(value: { delta: number }): void {
|
|
32
|
+
let p = vec3.add(vec3.create(), vec3.multiply(vec3.create(), this._from.position, vec3.fromValues(1 - value.delta, 1 - value.delta, 1 - value.delta)), vec3.multiply(vec3.create(), this._to.position, vec3.fromValues(value.delta, value.delta, value.delta)));
|
|
33
|
+
let positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
34
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
35
|
+
|
|
36
|
+
let t = vec3.add(vec3.create(), vec3.multiply(vec3.create(), this._from.target, vec3.fromValues(1 - value.delta, 1 - value.delta, 1 - value.delta)), vec3.multiply(vec3.create(), this._to.target, vec3.fromValues(value.delta, value.delta, value.delta)));
|
|
37
|
+
let targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
38
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// #endregion Public Methods (3)
|
|
42
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { mat4, vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
import { ICamera } from '../../../interfaces/camera/ICamera'
|
|
4
|
+
import { ICameraControlsUsage } from '../../../interfaces/controls/ICameraControlsUsage'
|
|
5
|
+
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation'
|
|
6
|
+
|
|
7
|
+
export class CameraMultipleInterpolation implements ICameraInterpolation {
|
|
8
|
+
// #region Properties (1)
|
|
9
|
+
|
|
10
|
+
public end: {
|
|
11
|
+
position: { x: number[], y: number[], z: number[] },
|
|
12
|
+
target: { x: number[], y: number[], z: number[] }
|
|
13
|
+
} = {
|
|
14
|
+
position: { x: [], y: [], z: [] },
|
|
15
|
+
target: { x: [], y: [], z: [] }
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// #endregion Properties (1)
|
|
19
|
+
|
|
20
|
+
// #region Constructors (1)
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly _camera: ICamera,
|
|
24
|
+
private readonly _cameraControls: ICameraControlsUsage,
|
|
25
|
+
private readonly _path: { position: vec3, target: vec3 }[],
|
|
26
|
+
private readonly _interpolationFunction: Function)
|
|
27
|
+
{
|
|
28
|
+
for(let i = 0; i < this._path.length; i++) {
|
|
29
|
+
this.end.position.x.push(this._path[i].position[0]);
|
|
30
|
+
this.end.position.y.push(this._path[i].position[1]);
|
|
31
|
+
this.end.position.z.push(this._path[i].position[2]);
|
|
32
|
+
this.end.target.x.push(this._path[i].target[0]);
|
|
33
|
+
this.end.target.y.push(this._path[i].target[1]);
|
|
34
|
+
this.end.target.z.push(this._path[i].target[2]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// #endregion Constructors (1)
|
|
39
|
+
|
|
40
|
+
// #region Public Methods (3)
|
|
41
|
+
|
|
42
|
+
public onComplete(value: { delta: number }): void {
|
|
43
|
+
let positionOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._path[this._path.length-1].position[0], this._path[this._path.length-1].position[1], this._path[this._path.length-1].position[2]), this._cameraControls.getPositionWithUpdates());
|
|
44
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
45
|
+
let targetOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._path[this._path.length-1].target[0], this._path[this._path.length-1].target[1], this._path[this._path.length-1].target[2]), this._cameraControls.getTargetWithUpdates());
|
|
46
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public onStop(value: { delta: number }): void {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public onUpdate(value: { delta: number }): void {
|
|
53
|
+
let p: vec3 = vec3.fromValues(this._interpolationFunction(this.end.position.x, value.delta), this._interpolationFunction(this.end.position.y, value.delta), this._interpolationFunction(this.end.position.z, value.delta));
|
|
54
|
+
let positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
55
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
56
|
+
|
|
57
|
+
let t: vec3 = vec3.fromValues(this._interpolationFunction(this.end.target.x, value.delta), this._interpolationFunction(this.end.target.y, value.delta), this._interpolationFunction(this.end.target.z, value.delta));
|
|
58
|
+
let targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
59
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// #endregion Public Methods (3)
|
|
63
|
+
}
|
package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { mat4, vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
import { ICamera } from '../../../interfaces/camera/ICamera'
|
|
4
|
+
import { ICameraControlsUsage } from '../../../interfaces/controls/ICameraControlsUsage'
|
|
5
|
+
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation'
|
|
6
|
+
|
|
7
|
+
export class CameraOrthographicInterpolation implements ICameraInterpolation {
|
|
8
|
+
// #region Constructors (1)
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly _camera: ICamera,
|
|
12
|
+
private readonly _cameraControls: ICameraControlsUsage,
|
|
13
|
+
private readonly _from: { position: vec3, target: vec3 },
|
|
14
|
+
private readonly _to: { position: vec3, target: vec3 })
|
|
15
|
+
{
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// #endregion Constructors (1)
|
|
19
|
+
|
|
20
|
+
// #region Public Methods (3)
|
|
21
|
+
|
|
22
|
+
public onComplete(value: { delta: number }): void {
|
|
23
|
+
let positionOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.position[0], this._to.position[1], this._to.position[2]), this._cameraControls.getPositionWithUpdates());
|
|
24
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
25
|
+
let targetOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.target[0], this._to.target[1], this._to.target[2]), this._cameraControls.getTargetWithUpdates());
|
|
26
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public onStop(value: { delta: number }): void {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public onUpdate(value: { delta: number }): void {
|
|
33
|
+
let t: vec3 = vec3.add(vec3.create(), vec3.multiply(vec3.create(), this._from.target, vec3.fromValues(1 - value.delta, 1 - value.delta, 1 - value.delta)), vec3.multiply(vec3.create(), this._to.target, vec3.fromValues(value.delta, value.delta, value.delta)));
|
|
34
|
+
let targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
35
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
36
|
+
|
|
37
|
+
let p: vec3 = vec3.add(vec3.create(), vec3.multiply(vec3.create(), this._from.position, vec3.fromValues(1 - value.delta, 1 - value.delta, 1 - value.delta)), vec3.multiply(vec3.create(), this._to.position, vec3.fromValues(value.delta, value.delta, value.delta)));
|
|
38
|
+
let positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
39
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// #endregion Public Methods (3)
|
|
43
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mat4, quat, vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
import { ICamera } from '../../../interfaces/camera/ICamera'
|
|
4
|
+
import { ICameraControlsUsage } from '../../../interfaces/controls/ICameraControlsUsage'
|
|
5
|
+
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation'
|
|
6
|
+
|
|
7
|
+
export class CameraSphericalInterpolation implements ICameraInterpolation {
|
|
8
|
+
// #region Properties (6)
|
|
9
|
+
|
|
10
|
+
private _axis: vec3;
|
|
11
|
+
private _c_angle: number;
|
|
12
|
+
private _direction_from: vec3;
|
|
13
|
+
private _direction_to: vec3;
|
|
14
|
+
private _radius_from: number;
|
|
15
|
+
private _radius_to: number;
|
|
16
|
+
|
|
17
|
+
// #endregion Properties (6)
|
|
18
|
+
|
|
19
|
+
// #region Constructors (1)
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private readonly _camera: ICamera,
|
|
23
|
+
private readonly _cameraControls: ICameraControlsUsage,
|
|
24
|
+
private readonly _from: { position: vec3, target: vec3 },
|
|
25
|
+
private readonly _to: { position: vec3, target: vec3 })
|
|
26
|
+
{
|
|
27
|
+
this._radius_from = vec3.distance(this._from.position, this._from.target);
|
|
28
|
+
this._direction_from = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._from.position, this._from.target));
|
|
29
|
+
|
|
30
|
+
this._radius_to = vec3.distance(this._to.position, this._to.target);
|
|
31
|
+
this._direction_to = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._to.position, this._to.target));
|
|
32
|
+
|
|
33
|
+
this._axis = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), this._direction_to, this._direction_from));
|
|
34
|
+
this._c_angle = -Math.acos(Math.min(1, Math.max(-1, vec3.dot(this._direction_to, this._direction_from))));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// #endregion Constructors (1)
|
|
38
|
+
|
|
39
|
+
// #region Public Methods (3)
|
|
40
|
+
|
|
41
|
+
public onComplete(value: { delta: number }): void {
|
|
42
|
+
let positionOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.position[0], this._to.position[1], this._to.position[2]), this._cameraControls.getPositionWithUpdates());
|
|
43
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
44
|
+
|
|
45
|
+
let targetOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.target[0], this._to.target[1], this._to.target[2]), this._cameraControls.getTargetWithUpdates());
|
|
46
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public onStop(value: { delta: number }): void {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public onUpdate(value: { delta: number }): void {
|
|
53
|
+
let t: vec3 = vec3.add(vec3.create(), vec3.multiply(vec3.create(), this._from.target, vec3.fromValues(1 - value.delta, 1 - value.delta, 1 - value.delta)), vec3.multiply(vec3.create(), this._to.target, vec3.fromValues(value.delta, value.delta, value.delta)));
|
|
54
|
+
let targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
55
|
+
this._cameraControls.applyTargetVector(targetOffset);
|
|
56
|
+
|
|
57
|
+
let angle = this._c_angle * value.delta;
|
|
58
|
+
let dir = vec3.normalize(vec3.create(), vec3.transformQuat(vec3.create(), this._direction_from, quat.setAxisAngle(quat.create(), this._axis, angle)));
|
|
59
|
+
|
|
60
|
+
let scalar = (this._radius_from * (1 - value.delta) + this._radius_to * value.delta);
|
|
61
|
+
let p: vec3 = vec3.add(vec3.create(), t, vec3.multiply(vec3.create(), dir, vec3.fromValues(scalar, scalar, scalar)));
|
|
62
|
+
let positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
63
|
+
this._cameraControls.applyPositionVector(positionOffset);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// #endregion Public Methods (3)
|
|
67
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ICameraControls } from './interfaces/controls/ICameraControls'
|
|
2
|
+
import { AbstractCamera } from './implementation/camera/AbstractCamera'
|
|
3
|
+
import { CameraEngine } from './implementation/CameraEngine'
|
|
4
|
+
import { ICamera, ICameraOptions } from './interfaces/camera/ICamera'
|
|
5
|
+
import { CAMERA_TYPE, ICameraEngine } from './interfaces/ICameraEngine'
|
|
6
|
+
import { OrthographicCamera } from './implementation/camera/OrthographicCamera'
|
|
7
|
+
import { PerspectiveCamera } from './implementation/camera/PerspectiveCamera'
|
|
8
|
+
import { OrthographicCameraControls } from './implementation/controls/OrthographicCameraControls'
|
|
9
|
+
import { PerspectiveCameraControls } from './implementation/controls/PerspectiveCameraControls'
|
|
10
|
+
import { IPerspectiveCameraControls } from './interfaces/controls/IPerspectiveCameraControls'
|
|
11
|
+
import { IOrthographicCameraControls } from './interfaces/controls/IOrthographicCameraControls'
|
|
12
|
+
import { IOrthographicCamera, ORTHOGRAPHIC_CAMERA_DIRECTION } from './interfaces/camera/IOrthographicCamera'
|
|
13
|
+
import { IPerspectiveCamera } from './interfaces/camera/IPerspectiveCamera'
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
ICameraEngine, ICamera, ICameraControls
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
CameraEngine, AbstractCamera, CAMERA_TYPE, ORTHOGRAPHIC_CAMERA_DIRECTION, ICameraOptions
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
PerspectiveCamera, OrthographicCamera,
|
|
25
|
+
IPerspectiveCamera, IOrthographicCamera
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
PerspectiveCameraControls, OrthographicCameraControls,
|
|
30
|
+
IPerspectiveCameraControls, IOrthographicCameraControls
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
import { ICamera } from './camera/ICamera'
|
|
4
|
+
|
|
5
|
+
export enum CAMERA_TYPE {
|
|
6
|
+
PERSPECTIVE = 'perspective',
|
|
7
|
+
ORTHOGRAPHIC = 'orthographic'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ICameraEngine {
|
|
11
|
+
update?: () => void;
|
|
12
|
+
|
|
13
|
+
assignCamera(id: string): boolean;
|
|
14
|
+
createCamera(type: CAMERA_TYPE, id?: string): ICamera;
|
|
15
|
+
removeCamera(id: string): boolean;
|
|
16
|
+
|
|
17
|
+
activateCameraEvents(): void;
|
|
18
|
+
deactivateCameraEvents(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { mat4, vec2, vec3 } from 'gl-matrix'
|
|
2
|
+
import { ITreeNode, ITreeNodeData } from '@shapediver/viewer.shared.node-tree'
|
|
3
|
+
|
|
4
|
+
import { ICameraControls } from '../controls/ICameraControls'
|
|
5
|
+
import { CAMERA_TYPE } from '../ICameraEngine'
|
|
6
|
+
import { IBox } from '@shapediver/viewer.shared.math'
|
|
7
|
+
import { SettingsEngine } from '@shapediver/viewer.shared.services'
|
|
8
|
+
|
|
9
|
+
export interface ICameraOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The easing type of the camera interpolation. (default: 'Quadratic.InOut')
|
|
12
|
+
*/
|
|
13
|
+
easing?: 'Linear.None' |
|
|
14
|
+
'Quadratic.In' | 'Quadratic.Out' | 'Quadratic.InOut' |
|
|
15
|
+
'Cubic.In' | 'Cubic.Out' | 'Cubic.InOut' |
|
|
16
|
+
'Quartic.In' | 'Quartic.Out' | 'Quartic.InOut' |
|
|
17
|
+
'Quintic.In' | 'Quintic.Out' | 'Quintic.InOut' |
|
|
18
|
+
'Sinusoidal.In' | 'Sinusoidal.Out' | 'Sinusoidal.InOut' |
|
|
19
|
+
'Exponential.In' | 'Exponential.Out' | 'Exponential.InOut' |
|
|
20
|
+
'Circular.In' | 'Circular.Out' | 'Circular.InOut' |
|
|
21
|
+
'Elastic.In' | 'Elastic.Out' | 'Elastic.InOut' |
|
|
22
|
+
'Back.In' | 'Back.Out' | 'Back.InOut' |
|
|
23
|
+
'Bounce.In' | 'Bounce.Out' | 'Bounce.InOut' |
|
|
24
|
+
Function;
|
|
25
|
+
/**
|
|
26
|
+
* The duration of the camera movement. (default: cameraMovementDuration set in the settings)
|
|
27
|
+
* When set to 0, the camera is immediately updated to the specified position and target.
|
|
28
|
+
*/
|
|
29
|
+
duration?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The coordinate type of the camera interpolation. (default: 'cylindrical')
|
|
32
|
+
*/
|
|
33
|
+
coordinates?: 'spherical' | 'linear' | 'cylindrical';
|
|
34
|
+
/**
|
|
35
|
+
* The interpolation type of the camera interpolation. (default: 'CatmullRom')
|
|
36
|
+
*/
|
|
37
|
+
interpolation?: 'Linear' | 'Bezier' | 'CatmullRom' | Function
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ICamera extends ITreeNodeData {
|
|
41
|
+
// #region Properties (13)
|
|
42
|
+
|
|
43
|
+
readonly controls: ICameraControls;
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly type: CAMERA_TYPE;
|
|
46
|
+
|
|
47
|
+
autoAdjust: boolean;
|
|
48
|
+
boundingBox: IBox;
|
|
49
|
+
cameraMovementDuration: number;
|
|
50
|
+
defaultPosition: vec3;
|
|
51
|
+
defaultTarget: vec3;
|
|
52
|
+
enableCameraControls: boolean;
|
|
53
|
+
position: vec3;
|
|
54
|
+
name?: string;
|
|
55
|
+
node?: ITreeNode;
|
|
56
|
+
order?: number;
|
|
57
|
+
revertAtMouseUp: boolean;
|
|
58
|
+
revertAtMouseUpDuration: number;
|
|
59
|
+
target: vec3;
|
|
60
|
+
useNodeData: boolean;
|
|
61
|
+
zoomExtentsFactor: number;
|
|
62
|
+
|
|
63
|
+
// #endregion Properties (13)
|
|
64
|
+
|
|
65
|
+
// #region Public Methods (6)
|
|
66
|
+
|
|
67
|
+
animate(path: { position: vec3, target: vec3 }[], options?: ICameraOptions): Promise<boolean>;
|
|
68
|
+
applySettings(settingsEngine: SettingsEngine): void;
|
|
69
|
+
reset(options?: ICameraOptions): Promise<boolean>;
|
|
70
|
+
set(position: vec3, target: vec3, options?: ICameraOptions): Promise<boolean>;
|
|
71
|
+
zoomTo(zoomTarget?: IBox, options?: ICameraOptions): Promise<boolean>;
|
|
72
|
+
calculateZoomTo(zoomTarget?: IBox, startingPosition?: vec3, startingTarget?: vec3): { position: vec3; target: vec3; };
|
|
73
|
+
project(p: vec3): vec2;
|
|
74
|
+
unproject(p: vec3): vec3;
|
|
75
|
+
|
|
76
|
+
// #endregion Public Methods (6)
|
|
77
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IOrthographicCameraControls } from '../controls/IOrthographicCameraControls';
|
|
2
|
+
import { ICamera } from './ICamera'
|
|
3
|
+
|
|
4
|
+
export enum ORTHOGRAPHIC_CAMERA_DIRECTION {
|
|
5
|
+
TOP = 'top',
|
|
6
|
+
BOTTOM = 'bottom',
|
|
7
|
+
LEFT = 'left',
|
|
8
|
+
RIGHT = 'right',
|
|
9
|
+
FRONT = 'front',
|
|
10
|
+
BACK = 'back',
|
|
11
|
+
}
|
|
12
|
+
export interface IOrthographicCamera extends ICamera {
|
|
13
|
+
readonly controls: IOrthographicCameraControls;
|
|
14
|
+
|
|
15
|
+
direction: ORTHOGRAPHIC_CAMERA_DIRECTION;
|
|
16
|
+
|
|
17
|
+
clone(): IOrthographicCamera;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IPerspectiveCameraControls } from '../controls/IPerspectiveCameraControls';
|
|
2
|
+
import { ICamera } from './ICamera'
|
|
3
|
+
|
|
4
|
+
export interface IPerspectiveCamera extends ICamera {
|
|
5
|
+
readonly controls: IPerspectiveCameraControls;
|
|
6
|
+
|
|
7
|
+
fov: number;
|
|
8
|
+
|
|
9
|
+
clone(): IPerspectiveCamera;
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { mat4, vec3 } from "gl-matrix";
|
|
2
|
+
import { ICamera, ICameraOptions } from "../camera/ICamera";
|
|
3
|
+
import { ICameraControlsEventDistribution } from "./ICameraControlsEventDistribution";
|
|
4
|
+
|
|
5
|
+
export interface ICameraControls {
|
|
6
|
+
// #region Properties (6)
|
|
7
|
+
|
|
8
|
+
readonly cameraControlsEventDistribution: ICameraControlsEventDistribution;
|
|
9
|
+
|
|
10
|
+
camera: ICamera;
|
|
11
|
+
canvas?: HTMLCanvasElement;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
position: vec3;
|
|
14
|
+
target: vec3;
|
|
15
|
+
|
|
16
|
+
// #endregion Properties (6)
|
|
17
|
+
|
|
18
|
+
// #region Public Methods (15)
|
|
19
|
+
|
|
20
|
+
animate(path: { position: vec3, target: vec3 }[], options: ICameraOptions): Promise<boolean>;
|
|
21
|
+
applyPositionMatrix(matrix: mat4, manualInteraction?: boolean | undefined): void;
|
|
22
|
+
applyPositionVector(vector: vec3, manualInteraction?: boolean | undefined): void;
|
|
23
|
+
applyTargetMatrix(matrix: mat4, manualInteraction?: boolean | undefined): void;
|
|
24
|
+
applyTargetVector(vector: vec3, manualInteraction?: boolean | undefined): void;
|
|
25
|
+
applyUpMatrix(matrix: mat4, manualInteraction?: boolean | undefined): void;
|
|
26
|
+
assignViewer(viewportId: string, canvas: HTMLCanvasElement):void;
|
|
27
|
+
getPositionWithManualUpdates(): vec3;
|
|
28
|
+
getPositionWithUpdates(): vec3;
|
|
29
|
+
getTargetWithManualUpdates(): vec3;
|
|
30
|
+
getTargetWithUpdates(): vec3;
|
|
31
|
+
isMoving(): boolean;
|
|
32
|
+
isWithinRestrictions(position: vec3, target: vec3): boolean;
|
|
33
|
+
reset(): void;
|
|
34
|
+
update(time: number): { position: vec3, target: vec3 };
|
|
35
|
+
|
|
36
|
+
// #endregion Public Methods (15)
|
|
37
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
export interface ICameraControlsLogic {
|
|
4
|
+
isWithinRestrictions(position: any, target: any): boolean;
|
|
5
|
+
reset(): void;
|
|
6
|
+
restrict(p: vec3, t: vec3): { position: vec3, target: vec3 };
|
|
7
|
+
update(time: number, manualInteraction: boolean): void
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IDomEventListener } from '@shapediver/viewer.shared.services'
|
|
2
|
+
import { mat4, vec3 } from 'gl-matrix'
|
|
3
|
+
import { ICameraOptions } from '../camera/ICamera'
|
|
4
|
+
|
|
5
|
+
import { ICameraControls } from './ICameraControls'
|
|
6
|
+
|
|
7
|
+
export interface ICameraControlsUsage extends ICameraControls {
|
|
8
|
+
// #region Properties (4)
|
|
9
|
+
|
|
10
|
+
readonly canvas?: HTMLCanvasElement;
|
|
11
|
+
|
|
12
|
+
// #endregion Properties (4)
|
|
13
|
+
|
|
14
|
+
// #region Public Methods (12)
|
|
15
|
+
|
|
16
|
+
animate(path: { position: vec3, target: vec3 }[], options: ICameraOptions) : Promise<boolean>
|
|
17
|
+
applyPositionMatrix(matrix: mat4, manualInteraction?: boolean): void;
|
|
18
|
+
applyTargetMatrix(matrix: mat4, manualInteraction?: boolean): void;
|
|
19
|
+
applyPositionVector(vector: vec3, manualInteraction?: boolean): void;
|
|
20
|
+
applyTargetVector(vector: vec3, manualInteraction?: boolean): void;
|
|
21
|
+
applyUpMatrix(matrix: mat4, manualInteraction?: boolean): void;
|
|
22
|
+
getPositionWithManualUpdates(): vec3;
|
|
23
|
+
getTargetWithManualUpdates(): vec3;
|
|
24
|
+
getPositionWithUpdates(): vec3;
|
|
25
|
+
getTargetWithUpdates(): vec3;
|
|
26
|
+
isMoving(): boolean;
|
|
27
|
+
isWithinRestrictions(position: vec3, target: vec3): boolean;
|
|
28
|
+
|
|
29
|
+
// #endregion Public Methods (12)
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ICameraControls } from './ICameraControls'
|
|
2
|
+
|
|
3
|
+
export interface IOrthographicCameraControls extends ICameraControls {
|
|
4
|
+
damping: number;
|
|
5
|
+
enableKeyPan: boolean;
|
|
6
|
+
enablePan: boolean;
|
|
7
|
+
enableZoom: boolean;
|
|
8
|
+
input: { keys: { up: number, down: number, left: number, right: number }, mouse: { rotate: number, zoom: number, pan: number }, touch: { rotate: number, zoom: number, pan: number } };
|
|
9
|
+
keyPanSpeed: number;
|
|
10
|
+
movementSmoothness: number;
|
|
11
|
+
panSpeed: number;
|
|
12
|
+
zoomSpeed: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix'
|
|
2
|
+
|
|
3
|
+
import { ICameraControls } from './ICameraControls'
|
|
4
|
+
|
|
5
|
+
export interface IPerspectiveCameraControls extends ICameraControls {
|
|
6
|
+
autoRotationSpeed: number;
|
|
7
|
+
cubePositionRestriction: { min: vec3, max: vec3 };
|
|
8
|
+
cubeTargetRestriction: { min: vec3, max: vec3 };
|
|
9
|
+
damping: number;
|
|
10
|
+
enableAutoRotation: boolean;
|
|
11
|
+
enableKeyPan: boolean;
|
|
12
|
+
enablePan: boolean;
|
|
13
|
+
enableRotation: boolean;
|
|
14
|
+
enableZoom: boolean;
|
|
15
|
+
input: { keys: { up: number, down: number, left: number, right: number }, mouse: { rotate: number, zoom: number, pan: number }, touch: { rotate: number, zoom: number, pan: number } };
|
|
16
|
+
keyPanSpeed: number;
|
|
17
|
+
movementSmoothness: number;
|
|
18
|
+
panSpeed: number;
|
|
19
|
+
rotationRestriction: { minPolarAngle: number, maxPolarAngle: number, minAzimuthAngle: number, maxAzimuthAngle: number };
|
|
20
|
+
rotationSpeed: number;
|
|
21
|
+
spherePositionRestriction: { center: vec3, radius: number };
|
|
22
|
+
sphereTargetRestriction: { center: vec3, radius: number };
|
|
23
|
+
zoomRestriction: { minDistance: number, maxDistance: number };
|
|
24
|
+
zoomSpeed: number;
|
|
25
|
+
}
|
package/tsconfig.json
ADDED