@shapediver/viewer.rendering-engine.camera-engine 3.3.3 → 3.3.6
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,149 +0,0 @@
|
|
|
1
|
-
import * as TWEEN from '@tweenjs/tween.js';
|
|
2
|
-
import { CameraCylindricalInterpolation } from './interpolationMethods/CameraCylindricalInterpolation';
|
|
3
|
-
import { CameraLinearInterpolation } from './interpolationMethods/CameraLinearInterpolation';
|
|
4
|
-
import { CameraMultipleInterpolation } from './interpolationMethods/CameraMultipleInterpolation';
|
|
5
|
-
import { CameraSphericalInterpolation } from './interpolationMethods/CameraSphericalInterpolation';
|
|
6
|
-
import { ICamera, ICameraOptions } from '../../interfaces/camera/ICamera';
|
|
7
|
-
import { ICameraControls } from '../../interfaces/controls/ICameraControls';
|
|
8
|
-
import { ICameraInterpolation } from '../../interfaces/interpolation/ICameraInterpolation';
|
|
9
|
-
import { vec3 } from 'gl-matrix';
|
|
10
|
-
|
|
11
|
-
export class CameraInterpolationManager {
|
|
12
|
-
// #region Properties (2)
|
|
13
|
-
|
|
14
|
-
private TweenWrapper = class {
|
|
15
|
-
private _properties: { delta: 0 } = { delta: 0 };
|
|
16
|
-
private _tween!: TWEEN.Tween<{ delta: number }>;
|
|
17
|
-
private _resolve!: (value: boolean | PromiseLike<boolean>) => void;
|
|
18
|
-
|
|
19
|
-
constructor(options: { duration: number, easing: (amount: number) => number, coordinates: string, interpolation: (v: number[], k: number) => number }, cb: ICameraInterpolation, onComplete: () => void) {
|
|
20
|
-
this._tween = new TWEEN.Tween(this._properties);
|
|
21
|
-
this._tween.easing(options.easing);
|
|
22
|
-
this._tween.to({ delta: 1.0 }, options.duration);
|
|
23
|
-
|
|
24
|
-
this._tween.onUpdate((v) => {
|
|
25
|
-
cb.onUpdate(v);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
this._tween.onStop((v) => {
|
|
29
|
-
if (cb.onStop) cb.onStop(v);
|
|
30
|
-
this._resolve(true);
|
|
31
|
-
});
|
|
32
|
-
this._tween.onComplete((v) => {
|
|
33
|
-
if (cb.onComplete) cb.onComplete(v);
|
|
34
|
-
onComplete();
|
|
35
|
-
this._resolve(true);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public start(): Promise<boolean> {
|
|
40
|
-
return new Promise((resolve) => {
|
|
41
|
-
this._resolve = resolve;
|
|
42
|
-
this._tween.start();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public stop(): void {
|
|
47
|
-
this._tween.stop();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
private _tween: any;
|
|
51
|
-
|
|
52
|
-
// #endregion Properties (2)
|
|
53
|
-
|
|
54
|
-
// #region Constructors (1)
|
|
55
|
-
|
|
56
|
-
constructor(
|
|
57
|
-
private readonly _camera: ICamera,
|
|
58
|
-
private readonly _cameraControls: ICameraControls
|
|
59
|
-
) {
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// #endregion Constructors (1)
|
|
63
|
-
|
|
64
|
-
// #region Public Methods (3)
|
|
65
|
-
|
|
66
|
-
public active(): boolean {
|
|
67
|
-
return this._tween ? true : false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* cameraTween
|
|
72
|
-
*/
|
|
73
|
-
public interpolate(path: { position: vec3, target: vec3 }[], options: ICameraOptions = {}): Promise<boolean> {
|
|
74
|
-
const newPath: { position: vec3, target: vec3 }[] = [];
|
|
75
|
-
for (let i = 0; i < path.length; i++)
|
|
76
|
-
newPath.push({
|
|
77
|
-
position: path[i].position,
|
|
78
|
-
target: path[i].target,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (this._tween) {
|
|
82
|
-
this._tween.stop();
|
|
83
|
-
this._tween = null;
|
|
84
|
-
}
|
|
85
|
-
const parsedOptions = this.optionsParser(options);
|
|
86
|
-
|
|
87
|
-
this._tween = new this.TweenWrapper(
|
|
88
|
-
parsedOptions,
|
|
89
|
-
newPath.length === 2 ?
|
|
90
|
-
this.getCameraInterpolation(newPath[0], newPath[1], parsedOptions.coordinates) :
|
|
91
|
-
new CameraMultipleInterpolation(this._camera, this._cameraControls, newPath, parsedOptions.interpolation),
|
|
92
|
-
() => { this._tween = null; }
|
|
93
|
-
);
|
|
94
|
-
return this._tween.start();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public stop(): void {
|
|
98
|
-
if (this._tween) this._tween.stop();
|
|
99
|
-
this._tween = null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// #endregion Public Methods (3)
|
|
103
|
-
|
|
104
|
-
// #region Private Methods (2)
|
|
105
|
-
|
|
106
|
-
private getCameraInterpolation(from: { position: vec3, target: vec3 }, to: { position: vec3, target: vec3 }, type: string) {
|
|
107
|
-
switch (type) {
|
|
108
|
-
case 'linear':
|
|
109
|
-
return new CameraLinearInterpolation(this._camera, this._cameraControls, from, to);
|
|
110
|
-
case 'spherical':
|
|
111
|
-
return new CameraSphericalInterpolation(this._camera, this._cameraControls, from, to);
|
|
112
|
-
case 'cylindrical':
|
|
113
|
-
return new CameraCylindricalInterpolation(this._camera, this._cameraControls, from, to);
|
|
114
|
-
default:
|
|
115
|
-
return new CameraMultipleInterpolation(this._camera, this._cameraControls, [from, to], TWEEN.Interpolation.CatmullRom);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private optionsParser(options: ICameraOptions): { duration: number, easing: (amount: number) => number, coordinates: string, interpolation: (v: number[], k: number) => number } {
|
|
120
|
-
let easing = TWEEN.Easing.Quartic.InOut;
|
|
121
|
-
if (typeof options.easing === 'string') {
|
|
122
|
-
const keys = options.easing.split('.');
|
|
123
|
-
const easingFamily = TWEEN.Easing[<keyof typeof TWEEN.Easing>keys[0]];
|
|
124
|
-
if (easingFamily) {
|
|
125
|
-
const easingFunction = easingFamily[<keyof typeof easingFamily>keys[1]];
|
|
126
|
-
if (easingFunction) easing = easingFunction;
|
|
127
|
-
}
|
|
128
|
-
} else if (typeof options.easing === 'function') {
|
|
129
|
-
easing = <(amount: number) => number>options.easing;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
let interpolation = TWEEN.Interpolation.CatmullRom;
|
|
133
|
-
if (typeof options.interpolation === 'string') {
|
|
134
|
-
const interpolationFunction = TWEEN.Interpolation[<keyof typeof TWEEN.Interpolation>options.interpolation];
|
|
135
|
-
if (interpolationFunction && interpolationFunction !== TWEEN.Interpolation.Utils) interpolation = <(v: number[], k: number) => number>interpolationFunction;
|
|
136
|
-
} else if (typeof options.interpolation === 'function') {
|
|
137
|
-
interpolation = <(v: number[], k: number) => number>options.interpolation;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
duration: options.duration && options.duration >= 0 ? options.duration : 0,
|
|
142
|
-
easing,
|
|
143
|
-
coordinates: options.coordinates !== 'spherical' && options.coordinates !== 'linear' && options.coordinates !== 'cylindrical' ? 'cylindrical' : options.coordinates,
|
|
144
|
-
interpolation
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// #endregion Private Methods (2)
|
|
149
|
-
}
|
package/src/implementation/interpolation/interpolationMethods/CameraCylindricalInterpolation.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { ICamera } from '../../../interfaces/camera/ICamera';
|
|
2
|
-
import { ICameraControls } from '../../../interfaces/controls/ICameraControls';
|
|
3
|
-
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation';
|
|
4
|
-
import { quat, vec3 } from 'gl-matrix';
|
|
5
|
-
|
|
6
|
-
export class CameraCylindricalInterpolation implements ICameraInterpolation {
|
|
7
|
-
// #region Properties (10)
|
|
8
|
-
|
|
9
|
-
private _dir_from: vec3;
|
|
10
|
-
private _dir_to: vec3;
|
|
11
|
-
private _from_position_heightAdjusted: vec3;
|
|
12
|
-
private _h_from: number;
|
|
13
|
-
private _h_to: number;
|
|
14
|
-
private _lorr: vec3;
|
|
15
|
-
private _r_from: number;
|
|
16
|
-
private _r_to: number;
|
|
17
|
-
private _shortest_angle: number;
|
|
18
|
-
private _to_position_heightAdjusted: vec3;
|
|
19
|
-
|
|
20
|
-
// #endregion Properties (10)
|
|
21
|
-
|
|
22
|
-
// #region Constructors (1)
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
private readonly _camera: ICamera,
|
|
26
|
-
private readonly _cameraControls: ICameraControls,
|
|
27
|
-
private readonly _from: { position: vec3, target: vec3 },
|
|
28
|
-
private readonly _to: { position: vec3, target: vec3 }) {
|
|
29
|
-
this._h_from = this._from.position[2] - this._from.target[2];
|
|
30
|
-
this._from_position_heightAdjusted = vec3.fromValues(this._from.position[0], this._from.position[1], this._from.target[2]);
|
|
31
|
-
this._r_from = vec3.distance(this._from_position_heightAdjusted, this._from.target);
|
|
32
|
-
this._dir_from = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._from_position_heightAdjusted, this._from.target));
|
|
33
|
-
|
|
34
|
-
this._h_to = this._to.position[2] - this._to.target[2];
|
|
35
|
-
this._to_position_heightAdjusted = vec3.fromValues(this._to.position[0], this._to.position[1], this._to.target[2]);
|
|
36
|
-
this._r_to = vec3.distance(this._to_position_heightAdjusted, this._to.target);
|
|
37
|
-
this._dir_to = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._to_position_heightAdjusted, this._to.target));
|
|
38
|
-
|
|
39
|
-
if (this._dir_from[0] === 0 && this._dir_from[1] === 0 && this._dir_from[2] === 0)
|
|
40
|
-
this._dir_from = vec3.fromValues(1, 0, 0);
|
|
41
|
-
|
|
42
|
-
if (this._dir_to[0] === 0 && this._dir_to[1] === 0 && this._dir_to[2] === 0)
|
|
43
|
-
this._dir_to = vec3.fromValues(1, 0, 0);
|
|
44
|
-
|
|
45
|
-
this._lorr = vec3.cross(vec3.create(), this._dir_to, this._dir_from);
|
|
46
|
-
// This is why people hate JavaScript. The dot product of two normalized vector is larger than 1 on occasion due to precision errors...
|
|
47
|
-
const dot1 = Math.min(1, Math.max(-1, vec3.dot(this._dir_to, this._dir_from)));
|
|
48
|
-
const dot2 = Math.min(1, Math.max(-1, vec3.dot(this._lorr, vec3.fromValues(0, 0, 1))));
|
|
49
|
-
this._shortest_angle = dot2 > 0 ? -Math.acos(dot1) : Math.acos(dot1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// #endregion Constructors (1)
|
|
53
|
-
|
|
54
|
-
// #region Public Methods (3)
|
|
55
|
-
|
|
56
|
-
public onComplete(value: { delta: number }): void {
|
|
57
|
-
const positionOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.position[0], this._to.position[1], this._to.position[2]), this._cameraControls.getPositionWithUpdates());
|
|
58
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
59
|
-
const targetOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.target[0], this._to.target[1], this._to.target[2]), this._cameraControls.getTargetWithUpdates());
|
|
60
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public onStop(value: { delta: number }): void {
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public onUpdate(value: { delta: number }): void {
|
|
67
|
-
const 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)));
|
|
68
|
-
const targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
69
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
70
|
-
|
|
71
|
-
const angle = this._shortest_angle * value.delta;
|
|
72
|
-
const dir = vec3.transformQuat(vec3.create(), this._dir_from, quat.setAxisAngle(quat.create(), vec3.fromValues(0, 0, 1), angle));
|
|
73
|
-
|
|
74
|
-
const scalar = this._r_from * (1 - value.delta) + this._r_to * value.delta;
|
|
75
|
-
const p = vec3.add(vec3.create(), t, vec3.multiply(vec3.create(), dir, vec3.fromValues(scalar, scalar, scalar)));
|
|
76
|
-
vec3.add(p, p, vec3.fromValues(0, 0, (this._h_from * (1 - value.delta) + this._h_to * value.delta)));
|
|
77
|
-
|
|
78
|
-
const positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
79
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// #endregion Public Methods (3)
|
|
83
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ICamera } from '../../../interfaces/camera/ICamera';
|
|
2
|
-
import { ICameraControls } from '../../../interfaces/controls/ICameraControls';
|
|
3
|
-
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation';
|
|
4
|
-
import { vec3 } from 'gl-matrix';
|
|
5
|
-
|
|
6
|
-
export class CameraLinearInterpolation implements ICameraInterpolation {
|
|
7
|
-
// #region Constructors (1)
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
private readonly _camera: ICamera,
|
|
11
|
-
private readonly _cameraControls: ICameraControls,
|
|
12
|
-
private readonly _from: { position: vec3, target: vec3 },
|
|
13
|
-
private readonly _to: { position: vec3, target: vec3 }) {
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// #endregion Constructors (1)
|
|
17
|
-
|
|
18
|
-
// #region Public Methods (3)
|
|
19
|
-
|
|
20
|
-
public onComplete(value: { delta: number }): void {
|
|
21
|
-
const positionOffset = vec3.subtract(vec3.create(), this._to.position, this._cameraControls.getPositionWithUpdates());
|
|
22
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
23
|
-
const targetOffset = vec3.subtract(vec3.create(), this._to.target, this._cameraControls.getTargetWithUpdates());
|
|
24
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public onStop(value: { delta: number }): void {
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public onUpdate(value: { delta: number }): void {
|
|
31
|
-
const 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)));
|
|
32
|
-
const positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
33
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
34
|
-
|
|
35
|
-
const 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)));
|
|
36
|
-
const targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
37
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// #endregion Public Methods (3)
|
|
41
|
-
}
|
package/src/implementation/interpolation/interpolationMethods/CameraMultipleInterpolation.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { ICamera } from '../../../interfaces/camera/ICamera';
|
|
2
|
-
import { ICameraControls } from '../../../interfaces/controls/ICameraControls';
|
|
3
|
-
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation';
|
|
4
|
-
import { vec3 } from 'gl-matrix';
|
|
5
|
-
|
|
6
|
-
export class CameraMultipleInterpolation implements ICameraInterpolation {
|
|
7
|
-
// #region Properties (1)
|
|
8
|
-
|
|
9
|
-
public end: {
|
|
10
|
-
position: { x: number[], y: number[], z: number[] },
|
|
11
|
-
target: { x: number[], y: number[], z: number[] }
|
|
12
|
-
} = {
|
|
13
|
-
position: { x: [], y: [], z: [] },
|
|
14
|
-
target: { x: [], y: [], z: [] }
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// #endregion Properties (1)
|
|
18
|
-
|
|
19
|
-
// #region Constructors (1)
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
private readonly _camera: ICamera,
|
|
23
|
-
private readonly _cameraControls: ICameraControls,
|
|
24
|
-
private readonly _path: { position: vec3, target: vec3 }[],
|
|
25
|
-
private readonly _interpolationFunction: (v: number[], k: number) => number) {
|
|
26
|
-
for (let i = 0; i < this._path.length; i++) {
|
|
27
|
-
this.end.position.x.push(this._path[i].position[0]);
|
|
28
|
-
this.end.position.y.push(this._path[i].position[1]);
|
|
29
|
-
this.end.position.z.push(this._path[i].position[2]);
|
|
30
|
-
this.end.target.x.push(this._path[i].target[0]);
|
|
31
|
-
this.end.target.y.push(this._path[i].target[1]);
|
|
32
|
-
this.end.target.z.push(this._path[i].target[2]);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// #endregion Constructors (1)
|
|
37
|
-
|
|
38
|
-
// #region Public Methods (3)
|
|
39
|
-
|
|
40
|
-
public onComplete(value: { delta: number }): void {
|
|
41
|
-
const 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());
|
|
42
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
43
|
-
const 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());
|
|
44
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public onStop(value: { delta: number }): void {
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public onUpdate(value: { delta: number }): void {
|
|
51
|
-
const 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));
|
|
52
|
-
const positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
53
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
54
|
-
|
|
55
|
-
const 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));
|
|
56
|
-
const targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
57
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// #endregion Public Methods (3)
|
|
61
|
-
}
|
package/src/implementation/interpolation/interpolationMethods/CameraOrthographicInterpolation.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ICamera } from '../../../interfaces/camera/ICamera';
|
|
2
|
-
import { ICameraControls } from '../../../interfaces/controls/ICameraControls';
|
|
3
|
-
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation';
|
|
4
|
-
import { vec3 } from 'gl-matrix';
|
|
5
|
-
|
|
6
|
-
export class CameraOrthographicInterpolation implements ICameraInterpolation {
|
|
7
|
-
// #region Constructors (1)
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
private readonly _camera: ICamera,
|
|
11
|
-
private readonly _cameraControls: ICameraControls,
|
|
12
|
-
private readonly _from: { position: vec3, target: vec3 },
|
|
13
|
-
private readonly _to: { position: vec3, target: vec3 }) {
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// #endregion Constructors (1)
|
|
17
|
-
|
|
18
|
-
// #region Public Methods (3)
|
|
19
|
-
|
|
20
|
-
public onComplete(value: { delta: number }): void {
|
|
21
|
-
const positionOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.position[0], this._to.position[1], this._to.position[2]), this._cameraControls.getPositionWithUpdates());
|
|
22
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
23
|
-
const targetOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.target[0], this._to.target[1], this._to.target[2]), this._cameraControls.getTargetWithUpdates());
|
|
24
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public onStop(value: { delta: number }): void {
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public onUpdate(value: { delta: number }): void {
|
|
31
|
-
const 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)));
|
|
32
|
-
const targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
33
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
34
|
-
|
|
35
|
-
const 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)));
|
|
36
|
-
const positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
37
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// #endregion Public Methods (3)
|
|
41
|
-
}
|
package/src/implementation/interpolation/interpolationMethods/CameraSphericalInterpolation.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { ICamera } from '../../../interfaces/camera/ICamera';
|
|
2
|
-
import { ICameraControls } from '../../../interfaces/controls/ICameraControls';
|
|
3
|
-
import { ICameraInterpolation } from '../../../interfaces/interpolation/ICameraInterpolation';
|
|
4
|
-
import { quat, vec3 } from 'gl-matrix';
|
|
5
|
-
|
|
6
|
-
export class CameraSphericalInterpolation implements ICameraInterpolation {
|
|
7
|
-
// #region Properties (6)
|
|
8
|
-
|
|
9
|
-
private _axis: vec3;
|
|
10
|
-
private _c_angle: number;
|
|
11
|
-
private _direction_from: vec3;
|
|
12
|
-
private _direction_to: vec3;
|
|
13
|
-
private _radius_from: number;
|
|
14
|
-
private _radius_to: number;
|
|
15
|
-
|
|
16
|
-
// #endregion Properties (6)
|
|
17
|
-
|
|
18
|
-
// #region Constructors (1)
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
private readonly _camera: ICamera,
|
|
22
|
-
private readonly _cameraControls: ICameraControls,
|
|
23
|
-
private readonly _from: { position: vec3, target: vec3 },
|
|
24
|
-
private readonly _to: { position: vec3, target: vec3 }) {
|
|
25
|
-
this._radius_from = vec3.distance(this._from.position, this._from.target);
|
|
26
|
-
this._direction_from = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._from.position, this._from.target));
|
|
27
|
-
|
|
28
|
-
this._radius_to = vec3.distance(this._to.position, this._to.target);
|
|
29
|
-
this._direction_to = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), this._to.position, this._to.target));
|
|
30
|
-
|
|
31
|
-
this._axis = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), this._direction_to, this._direction_from));
|
|
32
|
-
this._c_angle = -Math.acos(Math.min(1, Math.max(-1, vec3.dot(this._direction_to, this._direction_from))));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// #endregion Constructors (1)
|
|
36
|
-
|
|
37
|
-
// #region Public Methods (3)
|
|
38
|
-
|
|
39
|
-
public onComplete(value: { delta: number }): void {
|
|
40
|
-
const positionOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.position[0], this._to.position[1], this._to.position[2]), this._cameraControls.getPositionWithUpdates());
|
|
41
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
42
|
-
|
|
43
|
-
const targetOffset = vec3.subtract(vec3.create(), vec3.fromValues(this._to.target[0], this._to.target[1], this._to.target[2]), this._cameraControls.getTargetWithUpdates());
|
|
44
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public onStop(value: { delta: number }): void {
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public onUpdate(value: { delta: number }): void {
|
|
51
|
-
const 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)));
|
|
52
|
-
const targetOffset = vec3.subtract(vec3.create(), t, this._cameraControls.getTargetWithUpdates());
|
|
53
|
-
this._cameraControls.applyTargetVector(targetOffset);
|
|
54
|
-
|
|
55
|
-
const angle = this._c_angle * value.delta;
|
|
56
|
-
const dir = vec3.normalize(vec3.create(), vec3.transformQuat(vec3.create(), this._direction_from, quat.setAxisAngle(quat.create(), this._axis, angle)));
|
|
57
|
-
|
|
58
|
-
const scalar = (this._radius_from * (1 - value.delta) + this._radius_to * value.delta);
|
|
59
|
-
const p: vec3 = vec3.add(vec3.create(), t, vec3.multiply(vec3.create(), dir, vec3.fromValues(scalar, scalar, scalar)));
|
|
60
|
-
const positionOffset = vec3.subtract(vec3.create(), p, this._cameraControls.getPositionWithUpdates());
|
|
61
|
-
this._cameraControls.applyPositionVector(positionOffset);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// #endregion Public Methods (3)
|
|
65
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AbstractCamera } from './implementation/camera/AbstractCamera';
|
|
2
|
-
import { CAMERA_TYPE, ICameraEngine } from './interfaces/ICameraEngine';
|
|
3
|
-
import { CameraEngine } from './implementation/CameraEngine';
|
|
4
|
-
import { ICamera, ICameraOptions } from './interfaces/camera/ICamera';
|
|
5
|
-
import { ICameraControls } from './interfaces/controls/ICameraControls';
|
|
6
|
-
import { IOrthographicCamera, ORTHOGRAPHIC_CAMERA_DIRECTION } from './interfaces/camera/IOrthographicCamera';
|
|
7
|
-
import { IPerspectiveCamera } from './interfaces/camera/IPerspectiveCamera';
|
|
8
|
-
import { OrthographicCamera } from './implementation/camera/OrthographicCamera';
|
|
9
|
-
import { OrthographicCameraControls } from './implementation/controls/OrthographicCameraControls';
|
|
10
|
-
import { PerspectiveCamera } from './implementation/camera/PerspectiveCamera';
|
|
11
|
-
import { PerspectiveCameraControls } from './implementation/controls/PerspectiveCameraControls';
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
ICameraEngine, ICamera, ICameraControls
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
CameraEngine, AbstractCamera, CAMERA_TYPE, ORTHOGRAPHIC_CAMERA_DIRECTION, ICameraOptions
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
PerspectiveCamera, OrthographicCamera,
|
|
23
|
-
IPerspectiveCamera, IOrthographicCamera
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export {
|
|
27
|
-
PerspectiveCameraControls, OrthographicCameraControls
|
|
28
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ICamera } from './camera/ICamera';
|
|
2
|
-
|
|
3
|
-
// #region Interfaces (1)
|
|
4
|
-
|
|
5
|
-
export interface ICameraEngine {
|
|
6
|
-
// #region Properties (1)
|
|
7
|
-
|
|
8
|
-
update?: () => void;
|
|
9
|
-
|
|
10
|
-
// #endregion Properties (1)
|
|
11
|
-
|
|
12
|
-
// #region Public Methods (6)
|
|
13
|
-
|
|
14
|
-
activateCameraEvents(): void;
|
|
15
|
-
assignCamera(id: string): boolean;
|
|
16
|
-
createCamera(type: CAMERA_TYPE, id?: string): ICamera;
|
|
17
|
-
createDefaultCameras(): void;
|
|
18
|
-
deactivateCameraEvents(): void;
|
|
19
|
-
removeCamera(id: string): boolean;
|
|
20
|
-
|
|
21
|
-
// #endregion Public Methods (6)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// #endregion Interfaces (1)
|
|
25
|
-
|
|
26
|
-
// #region Enums (1)
|
|
27
|
-
|
|
28
|
-
export enum CAMERA_TYPE {
|
|
29
|
-
PERSPECTIVE = 'perspective',
|
|
30
|
-
ORTHOGRAPHIC = 'orthographic'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// #endregion Enums (1)
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { CAMERA_TYPE } from '../ICameraEngine';
|
|
2
|
-
import { IBox } from '@shapediver/viewer.shared.math';
|
|
3
|
-
import { ICameraControls } from '../controls/ICameraControls';
|
|
4
|
-
import { ITreeNode, ITreeNodeData } from '@shapediver/viewer.shared.node-tree';
|
|
5
|
-
import { SettingsEngine } from '@shapediver/viewer.shared.services';
|
|
6
|
-
import { vec2, vec3 } from 'gl-matrix';
|
|
7
|
-
|
|
8
|
-
// #region Interfaces (2)
|
|
9
|
-
|
|
10
|
-
export interface ICamera extends ITreeNodeData {
|
|
11
|
-
// #region Properties (21)
|
|
12
|
-
|
|
13
|
-
readonly controls: ICameraControls;
|
|
14
|
-
readonly id: string;
|
|
15
|
-
readonly type: CAMERA_TYPE;
|
|
16
|
-
readonly isDefault: boolean;
|
|
17
|
-
|
|
18
|
-
active: boolean;
|
|
19
|
-
autoAdjust: boolean;
|
|
20
|
-
boundingBox: IBox;
|
|
21
|
-
cameraMovementDuration: number;
|
|
22
|
-
defaultPosition: vec3;
|
|
23
|
-
defaultTarget: vec3;
|
|
24
|
-
domEventListenerToken?: string;
|
|
25
|
-
enableCameraControls: boolean;
|
|
26
|
-
name?: string;
|
|
27
|
-
node?: ITreeNode;
|
|
28
|
-
order?: number;
|
|
29
|
-
position: vec3;
|
|
30
|
-
revertAtMouseUp: boolean;
|
|
31
|
-
revertAtMouseUpDuration: number;
|
|
32
|
-
sceneRotation: vec2;
|
|
33
|
-
target: vec3;
|
|
34
|
-
useNodeData: boolean;
|
|
35
|
-
zoomExtentsFactor: number;
|
|
36
|
-
|
|
37
|
-
// #endregion Properties (21)
|
|
38
|
-
|
|
39
|
-
// #region Public Methods (8)
|
|
40
|
-
|
|
41
|
-
animate(path: { position: vec3, target: vec3 }[], options?: ICameraOptions): Promise<boolean>;
|
|
42
|
-
applySettings(settingsEngine: SettingsEngine): void;
|
|
43
|
-
calculateZoomTo(zoomTarget?: IBox, startingPosition?: vec3, startingTarget?: vec3): { position: vec3; target: vec3; };
|
|
44
|
-
project(p: vec3): vec2;
|
|
45
|
-
reset(options?: ICameraOptions): Promise<boolean>;
|
|
46
|
-
set(position: vec3, target: vec3, options?: ICameraOptions): Promise<boolean>;
|
|
47
|
-
unproject(p: vec3): vec3;
|
|
48
|
-
zoomTo(zoomTarget?: IBox, options?: ICameraOptions): Promise<boolean>;
|
|
49
|
-
|
|
50
|
-
// #endregion Public Methods (8)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
54
|
-
export interface ICameraOptions {
|
|
55
|
-
// #region Properties (4)
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* The coordinate type of the camera interpolation. (default: 'cylindrical')
|
|
59
|
-
*/
|
|
60
|
-
coordinates?: 'spherical' | 'linear' | 'cylindrical';
|
|
61
|
-
/**
|
|
62
|
-
* The duration of the camera movement. (default: cameraMovementDuration set in the settings)
|
|
63
|
-
* When set to 0, the camera is immediately updated to the specified position and target.
|
|
64
|
-
*/
|
|
65
|
-
duration?: number;
|
|
66
|
-
/**
|
|
67
|
-
* The easing type of the camera interpolation. (default: 'Quadratic.InOut')
|
|
68
|
-
*/
|
|
69
|
-
easing?: 'Linear.None' |
|
|
70
|
-
'Quadratic.In' | 'Quadratic.Out' | 'Quadratic.InOut' |
|
|
71
|
-
'Cubic.In' | 'Cubic.Out' | 'Cubic.InOut' |
|
|
72
|
-
'Quartic.In' | 'Quartic.Out' | 'Quartic.InOut' |
|
|
73
|
-
'Quintic.In' | 'Quintic.Out' | 'Quintic.InOut' |
|
|
74
|
-
'Sinusoidal.In' | 'Sinusoidal.Out' | 'Sinusoidal.InOut' |
|
|
75
|
-
'Exponential.In' | 'Exponential.Out' | 'Exponential.InOut' |
|
|
76
|
-
'Circular.In' | 'Circular.Out' | 'Circular.InOut' |
|
|
77
|
-
'Elastic.In' | 'Elastic.Out' | 'Elastic.InOut' |
|
|
78
|
-
'Back.In' | 'Back.Out' | 'Back.InOut' |
|
|
79
|
-
'Bounce.In' | 'Bounce.Out' | 'Bounce.InOut' | Function;
|
|
80
|
-
/**
|
|
81
|
-
* The interpolation type of the camera interpolation. (default: 'CatmullRom')
|
|
82
|
-
*/
|
|
83
|
-
interpolation?: 'Linear' | 'Bezier' | 'CatmullRom' | Function
|
|
84
|
-
|
|
85
|
-
// #endregion Properties (4)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// #endregion Interfaces (2)
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ICamera } from './ICamera';
|
|
2
|
-
import { ICameraControls } from '../controls/ICameraControls';
|
|
3
|
-
|
|
4
|
-
// #region Interfaces (1)
|
|
5
|
-
|
|
6
|
-
export interface IOrthographicCamera extends ICamera {
|
|
7
|
-
// #region Properties (2)
|
|
8
|
-
|
|
9
|
-
readonly controls: ICameraControls;
|
|
10
|
-
|
|
11
|
-
direction: ORTHOGRAPHIC_CAMERA_DIRECTION;
|
|
12
|
-
|
|
13
|
-
// #endregion Properties (2)
|
|
14
|
-
|
|
15
|
-
// #region Public Methods (1)
|
|
16
|
-
|
|
17
|
-
clone(): IOrthographicCamera;
|
|
18
|
-
|
|
19
|
-
// #endregion Public Methods (1)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// #endregion Interfaces (1)
|
|
23
|
-
|
|
24
|
-
// #region Enums (1)
|
|
25
|
-
|
|
26
|
-
export enum ORTHOGRAPHIC_CAMERA_DIRECTION {
|
|
27
|
-
TOP = 'top',
|
|
28
|
-
BOTTOM = 'bottom',
|
|
29
|
-
LEFT = 'left',
|
|
30
|
-
RIGHT = 'right',
|
|
31
|
-
FRONT = 'front',
|
|
32
|
-
BACK = 'back',
|
|
33
|
-
CUSTOM = 'custom'
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// #endregion Enums (1)
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ICamera } from './ICamera';
|
|
2
|
-
import { ICameraControls } from '../controls/ICameraControls';
|
|
3
|
-
|
|
4
|
-
export interface IPerspectiveCamera extends ICamera {
|
|
5
|
-
// #region Properties (2)
|
|
6
|
-
|
|
7
|
-
readonly controls: ICameraControls;
|
|
8
|
-
|
|
9
|
-
fov: number;
|
|
10
|
-
|
|
11
|
-
// #endregion Properties (2)
|
|
12
|
-
|
|
13
|
-
// #region Public Methods (1)
|
|
14
|
-
|
|
15
|
-
clone(): IPerspectiveCamera;
|
|
16
|
-
|
|
17
|
-
// #endregion Public Methods (1)
|
|
18
|
-
}
|