@combeenation/3d-viewer 5.0.1 → 5.0.3-beta2
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/README.md +111 -114
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +187 -187
- package/dist/lib-cjs/api/classes/element.d.ts +139 -139
- package/dist/lib-cjs/api/classes/element.js +794 -794
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js +135 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js.map +1 -0
- package/dist/lib-cjs/api/classes/event.d.ts +326 -326
- package/dist/lib-cjs/api/classes/event.js +371 -371
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
- package/dist/lib-cjs/api/classes/parameter.d.ts +316 -259
- package/dist/lib-cjs/api/classes/parameter.js +451 -388
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +101 -101
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +44 -44
- package/dist/lib-cjs/api/classes/placementAnimation.js +163 -163
- package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
- package/dist/lib-cjs/api/classes/variant.js +1154 -1154
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
- package/dist/lib-cjs/api/classes/variantInstance.js +108 -108
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +99 -99
- package/dist/lib-cjs/api/classes/viewer.d.ts +177 -175
- package/dist/lib-cjs/api/classes/viewer.js +717 -701
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +392 -392
- package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
- package/dist/lib-cjs/api/internal/debugViewer.js +86 -86
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -10
- package/dist/lib-cjs/api/internal/sceneSetup.js +238 -234
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
- package/dist/lib-cjs/api/manager/animationManager.js +130 -130
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +65 -65
- package/dist/lib-cjs/api/manager/gltfExportManager.js +223 -222
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +31 -32
- package/dist/lib-cjs/api/manager/sceneManager.js +153 -132
- package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +335 -335
- package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
- package/dist/lib-cjs/api/store/specStorage.js +51 -51
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +174 -166
- package/dist/lib-cjs/api/util/babylonHelper.js +575 -497
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +366 -356
- package/dist/lib-cjs/api/util/globalTypes.js +1 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -53
- package/dist/lib-cjs/api/util/resourceHelper.js +257 -242
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/stringHelper.js +25 -25
- package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/structureHelper.js +48 -44
- package/dist/lib-cjs/api/util/structureHelper.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/index.d.ts +49 -49
- package/dist/lib-cjs/index.js +89 -89
- package/dist/webpack-stats.json +0 -0
- package/package.json +87 -87
- package/src/api/classes/animationInterface.ts +10 -10
- package/src/api/classes/dottedPath.ts +181 -181
- package/src/api/classes/element.ts +690 -692
- package/src/api/classes/event.ts +367 -367
- package/src/api/classes/eventBroadcaster.ts +52 -52
- package/src/api/classes/parameter.ts +474 -405
- package/src/api/classes/parameterObservable.ts +100 -100
- package/src/api/classes/parameterizable.ts +87 -87
- package/src/api/classes/placementAnimation.ts +160 -160
- package/src/api/classes/variant.ts +845 -845
- package/src/api/classes/variantInstance.ts +97 -97
- package/src/api/classes/variantParameterizable.ts +85 -85
- package/src/api/classes/viewer.ts +650 -624
- package/src/api/classes/viewerLight.ts +334 -334
- package/src/api/internal/debugViewer.ts +90 -90
- package/src/api/internal/lensRendering.ts +10 -10
- package/src/api/internal/sceneSetup.ts +204 -201
- package/src/api/manager/animationManager.ts +142 -142
- package/src/api/manager/gltfExportManager.ts +191 -191
- package/src/api/manager/sceneManager.ts +128 -102
- package/src/api/manager/variantInstanceManager.ts +265 -265
- package/src/api/store/specStorage.ts +51 -51
- package/src/api/util/babylonHelper.ts +628 -538
- package/src/api/util/globalTypes.ts +413 -402
- package/src/api/util/resourceHelper.ts +189 -173
- package/src/api/util/stringHelper.ts +23 -23
- package/src/api/util/structureHelper.ts +49 -43
- package/src/buildinfo.json +3 -3
- package/src/commonjs.tsconfig.json +10 -10
- package/src/declaration.tsconfig.json +8 -8
- package/src/dev.ts +42 -42
- package/src/es6.tsconfig.json +10 -10
- package/src/index.ts +94 -94
- package/src/pagesconfig.json +77 -73
- package/src/tsconfig.json +32 -32
- package/src/tsconfig.types.json +9 -9
- package/src/types.d.ts +3 -3
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
/// <reference types="gsap" />
|
|
2
|
-
/**
|
|
3
|
-
* An {@link PlacementAnimation} handling `Tweens` of the `GSAP` API using configured {@link PlacementDefinition}s
|
|
4
|
-
* and {@link AnimationDefinition}s. It mutates the attributes in the given {@link PlacementDefinition} with the given
|
|
5
|
-
* {@link AnimationDefinition}. The latter can be anything the `GSAP` allows in its API. Please consider using the
|
|
6
|
-
* API of the {@link AnimationManager} to handle instances of this class in your consuming project.
|
|
7
|
-
*/
|
|
8
|
-
export declare class PlacementAnimation implements AnimationInterface {
|
|
9
|
-
readonly mutable: object;
|
|
10
|
-
protected _placement: PlacementDefinition | string;
|
|
11
|
-
protected _animation?: string | AnimationDefinition | undefined;
|
|
12
|
-
protected _placementDefinition: PlacementDefinition;
|
|
13
|
-
protected _animationDefinition: AnimationDefinition;
|
|
14
|
-
protected _timeline: GSAPTimeline;
|
|
15
|
-
/**
|
|
16
|
-
* Constructor.
|
|
17
|
-
*/
|
|
18
|
-
constructor(mutable: object, _placement: PlacementDefinition | string, _animation?: string | AnimationDefinition | undefined);
|
|
19
|
-
/**
|
|
20
|
-
* Plays all `Tweens` of this {@link PlacementAnimation}.
|
|
21
|
-
*/
|
|
22
|
-
play(): Promise<AnimationInterface>;
|
|
23
|
-
/**
|
|
24
|
-
* Pause all `Tweens` of this {@link PlacementAnimation}.
|
|
25
|
-
*/
|
|
26
|
-
pause(): AnimationInterface;
|
|
27
|
-
/**
|
|
28
|
-
* Kills all `Tweens` of this {@link PlacementAnimation}.
|
|
29
|
-
*/
|
|
30
|
-
kill(): AnimationInterface;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a {@link AnimationDefinition} definition if not provided in the constructor and sets some defaults.
|
|
33
|
-
* Only custom properties from {@link AnimationDefinition} are adjusted, all {@link GSAPTweenVars} remain untouched.
|
|
34
|
-
*/
|
|
35
|
-
protected prepareAnimationDefinition(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Prepares different types of {@link PlacementDefinition} and sets some defaults.
|
|
38
|
-
*/
|
|
39
|
-
protected preparePlacementDefinition(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Creates `Tweens` for the {@link PlacementDefinition} configured for this {@link PlacementAnimation}.
|
|
42
|
-
*/
|
|
43
|
-
protected createTweens(): void;
|
|
44
|
-
}
|
|
1
|
+
/// <reference types="gsap" />
|
|
2
|
+
/**
|
|
3
|
+
* An {@link PlacementAnimation} handling `Tweens` of the `GSAP` API using configured {@link PlacementDefinition}s
|
|
4
|
+
* and {@link AnimationDefinition}s. It mutates the attributes in the given {@link PlacementDefinition} with the given
|
|
5
|
+
* {@link AnimationDefinition}. The latter can be anything the `GSAP` allows in its API. Please consider using the
|
|
6
|
+
* API of the {@link AnimationManager} to handle instances of this class in your consuming project.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PlacementAnimation implements AnimationInterface {
|
|
9
|
+
readonly mutable: object;
|
|
10
|
+
protected _placement: PlacementDefinition | string;
|
|
11
|
+
protected _animation?: string | AnimationDefinition | undefined;
|
|
12
|
+
protected _placementDefinition: PlacementDefinition;
|
|
13
|
+
protected _animationDefinition: AnimationDefinition;
|
|
14
|
+
protected _timeline: GSAPTimeline;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor.
|
|
17
|
+
*/
|
|
18
|
+
constructor(mutable: object, _placement: PlacementDefinition | string, _animation?: string | AnimationDefinition | undefined);
|
|
19
|
+
/**
|
|
20
|
+
* Plays all `Tweens` of this {@link PlacementAnimation}.
|
|
21
|
+
*/
|
|
22
|
+
play(): Promise<AnimationInterface>;
|
|
23
|
+
/**
|
|
24
|
+
* Pause all `Tweens` of this {@link PlacementAnimation}.
|
|
25
|
+
*/
|
|
26
|
+
pause(): AnimationInterface;
|
|
27
|
+
/**
|
|
28
|
+
* Kills all `Tweens` of this {@link PlacementAnimation}.
|
|
29
|
+
*/
|
|
30
|
+
kill(): AnimationInterface;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a {@link AnimationDefinition} definition if not provided in the constructor and sets some defaults.
|
|
33
|
+
* Only custom properties from {@link AnimationDefinition} are adjusted, all {@link GSAPTweenVars} remain untouched.
|
|
34
|
+
*/
|
|
35
|
+
protected prepareAnimationDefinition(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Prepares different types of {@link PlacementDefinition} and sets some defaults.
|
|
38
|
+
*/
|
|
39
|
+
protected preparePlacementDefinition(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Creates `Tweens` for the {@link PlacementDefinition} configured for this {@link PlacementAnimation}.
|
|
42
|
+
*/
|
|
43
|
+
protected createTweens(): void;
|
|
44
|
+
}
|
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlacementAnimation = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
|
|
6
|
-
var math_vector_1 = require("@babylonjs/core/Maths/math.vector");
|
|
7
|
-
var gsap_1 = require("gsap");
|
|
8
|
-
var lodash_es_1 = require("lodash-es");
|
|
9
|
-
var parameter_1 = require("../classes/parameter");
|
|
10
|
-
var specStorage_1 = require("../store/specStorage");
|
|
11
|
-
/**
|
|
12
|
-
* An {@link PlacementAnimation} handling `Tweens` of the `GSAP` API using configured {@link PlacementDefinition}s
|
|
13
|
-
* and {@link AnimationDefinition}s. It mutates the attributes in the given {@link PlacementDefinition} with the given
|
|
14
|
-
* {@link AnimationDefinition}. The latter can be anything the `GSAP` allows in its API. Please consider using the
|
|
15
|
-
* API of the {@link AnimationManager} to handle instances of this class in your consuming project.
|
|
16
|
-
*/
|
|
17
|
-
var PlacementAnimation = /** @class */ (function () {
|
|
18
|
-
/**
|
|
19
|
-
* Constructor.
|
|
20
|
-
*/
|
|
21
|
-
function PlacementAnimation(mutable, _placement, _animation) {
|
|
22
|
-
var _a;
|
|
23
|
-
this.mutable = mutable;
|
|
24
|
-
this._placement = _placement;
|
|
25
|
-
this._animation = _animation;
|
|
26
|
-
if (lodash_es_1.isString(_placement)) {
|
|
27
|
-
var placementDefinitions = specStorage_1.SpecStorage.get('scene.placements');
|
|
28
|
-
if (!placementDefinitions) {
|
|
29
|
-
throw new Error("No PlacementDefinitions defined in JSON structure.");
|
|
30
|
-
}
|
|
31
|
-
var placementDefinition = placementDefinitions[_placement];
|
|
32
|
-
if (!placementDefinition) {
|
|
33
|
-
throw new Error("PlacementDefinition \"" + _placement + "\" not defined in JSON structure.");
|
|
34
|
-
}
|
|
35
|
-
this._placementDefinition = lodash_es_1.cloneDeep(placementDefinition);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
this._placementDefinition = lodash_es_1.cloneDeep(_placement);
|
|
39
|
-
}
|
|
40
|
-
if (lodash_es_1.isString(_animation)) {
|
|
41
|
-
var animationDefinition = (_a = specStorage_1.SpecStorage.get('scene.animations')) === null || _a === void 0 ? void 0 : _a[_animation];
|
|
42
|
-
if (!animationDefinition) {
|
|
43
|
-
throw new Error("AnimationDefinition \"" + _animation + "\" not defined in JSON structure.");
|
|
44
|
-
}
|
|
45
|
-
this._animationDefinition = lodash_es_1.cloneDeep(animationDefinition);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
this._animationDefinition = lodash_es_1.cloneDeep(_animation);
|
|
49
|
-
}
|
|
50
|
-
this.prepareAnimationDefinition();
|
|
51
|
-
// create (shallow) copy for GSAP which doesn't contain `shortestWay`,
|
|
52
|
-
// because that's not part of the original `TweenVars` input typing and therefore leads to warnings
|
|
53
|
-
var _b = this._animationDefinition, shortestWay = _b.shortestWay, gsapTweenVars = tslib_1.__rest(_b, ["shortestWay"]);
|
|
54
|
-
this._timeline = gsap_1.gsap.timeline({
|
|
55
|
-
defaults: gsapTweenVars,
|
|
56
|
-
paused: true,
|
|
57
|
-
});
|
|
58
|
-
this.preparePlacementDefinition();
|
|
59
|
-
this.createTweens();
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Plays all `Tweens` of this {@link PlacementAnimation}.
|
|
63
|
-
*/
|
|
64
|
-
PlacementAnimation.prototype.play = function () {
|
|
65
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
66
|
-
return tslib_1.__generator(this, function (_a) {
|
|
67
|
-
switch (_a.label) {
|
|
68
|
-
case 0: return [4 /*yield*/, this._timeline.play().then()];
|
|
69
|
-
case 1:
|
|
70
|
-
_a.sent();
|
|
71
|
-
return [2 /*return*/, this];
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Pause all `Tweens` of this {@link PlacementAnimation}.
|
|
78
|
-
*/
|
|
79
|
-
PlacementAnimation.prototype.pause = function () {
|
|
80
|
-
this._timeline.pause();
|
|
81
|
-
return this;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Kills all `Tweens` of this {@link PlacementAnimation}.
|
|
85
|
-
*/
|
|
86
|
-
PlacementAnimation.prototype.kill = function () {
|
|
87
|
-
this._timeline.kill();
|
|
88
|
-
return this;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Creates a {@link AnimationDefinition} definition if not provided in the constructor and sets some defaults.
|
|
92
|
-
* Only custom properties from {@link AnimationDefinition} are adjusted, all {@link GSAPTweenVars} remain untouched.
|
|
93
|
-
*/
|
|
94
|
-
PlacementAnimation.prototype.prepareAnimationDefinition = function () {
|
|
95
|
-
// create an animation definition if not available yet
|
|
96
|
-
this._animationDefinition = this._animationDefinition || {};
|
|
97
|
-
// parse shortest way flag or set to `true` if not configured
|
|
98
|
-
if (this._animationDefinition.shortestWay !== undefined) {
|
|
99
|
-
this._animationDefinition.shortestWay = parameter_1.Parameter.parseBoolean(this._animationDefinition.shortestWay);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
this._animationDefinition.shortestWay = true;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Prepares different types of {@link PlacementDefinition} and sets some defaults.
|
|
107
|
-
*/
|
|
108
|
-
PlacementAnimation.prototype.preparePlacementDefinition = function () {
|
|
109
|
-
var position = this._placementDefinition.position;
|
|
110
|
-
if (lodash_es_1.isString(position)) {
|
|
111
|
-
position = parameter_1.Parameter.parseVector(position);
|
|
112
|
-
this._placementDefinition.position = position;
|
|
113
|
-
}
|
|
114
|
-
if (this.mutable instanceof arcRotateCamera_1.ArcRotateCamera) {
|
|
115
|
-
// parse the target
|
|
116
|
-
if (lodash_es_1.isString(this._placementDefinition.target)) {
|
|
117
|
-
this._placementDefinition.target = parameter_1.Parameter.parseVector(this._placementDefinition.target);
|
|
118
|
-
}
|
|
119
|
-
if (position) {
|
|
120
|
-
// parse the position and calculate alpha, beta and radius with a "ghost camera"
|
|
121
|
-
// @see https://www.babylonjs-playground.com/#4IVMG#0
|
|
122
|
-
var ghostCam = this.mutable.clone('ghost');
|
|
123
|
-
ghostCam.setPosition(position);
|
|
124
|
-
lodash_es_1.merge(this._placementDefinition, {
|
|
125
|
-
alpha: ghostCam.alpha,
|
|
126
|
-
beta: ghostCam.beta,
|
|
127
|
-
radius: ghostCam.radius,
|
|
128
|
-
});
|
|
129
|
-
delete this._placementDefinition.position;
|
|
130
|
-
ghostCam.dispose();
|
|
131
|
-
}
|
|
132
|
-
else if (this._animationDefinition.shortestWay && this._placementDefinition.alpha !== undefined) {
|
|
133
|
-
// transform the target's alpha value into the same turn as the current camera position to avoid movements > 360 degrees
|
|
134
|
-
var alphaGap = this.mutable.alpha - this._placementDefinition.alpha;
|
|
135
|
-
var cntTurns = Math.round(alphaGap / (2 * Math.PI));
|
|
136
|
-
this._placementDefinition.alpha += 2 * Math.PI * cntTurns;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Creates `Tweens` for the {@link PlacementDefinition} configured for this {@link PlacementAnimation}.
|
|
142
|
-
*/
|
|
143
|
-
PlacementAnimation.prototype.createTweens = function () {
|
|
144
|
-
for (var property in this._placementDefinition) {
|
|
145
|
-
var propertyValue = lodash_es_1.get(this._placementDefinition, property);
|
|
146
|
-
var tweenVars = {};
|
|
147
|
-
var _mutable = this.mutable;
|
|
148
|
-
if (propertyValue instanceof math_vector_1.Vector3) {
|
|
149
|
-
// GSAP does not support mutation of complex objects, so we are forced
|
|
150
|
-
// to use the properties on the object as mutable directly and mutate
|
|
151
|
-
// the coordinates separately.
|
|
152
|
-
_mutable = lodash_es_1.get(this.mutable, property);
|
|
153
|
-
lodash_es_1.merge(tweenVars, { x: propertyValue.x, y: propertyValue.y, z: propertyValue.z });
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
lodash_es_1.set(tweenVars, property, propertyValue);
|
|
157
|
-
}
|
|
158
|
-
this._timeline.to(_mutable, tweenVars, 0); // Note: position 0 does the "parallel" stuff here
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
return PlacementAnimation;
|
|
162
|
-
}());
|
|
163
|
-
exports.PlacementAnimation = PlacementAnimation;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlacementAnimation = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
|
|
6
|
+
var math_vector_1 = require("@babylonjs/core/Maths/math.vector");
|
|
7
|
+
var gsap_1 = require("gsap");
|
|
8
|
+
var lodash_es_1 = require("lodash-es");
|
|
9
|
+
var parameter_1 = require("../classes/parameter");
|
|
10
|
+
var specStorage_1 = require("../store/specStorage");
|
|
11
|
+
/**
|
|
12
|
+
* An {@link PlacementAnimation} handling `Tweens` of the `GSAP` API using configured {@link PlacementDefinition}s
|
|
13
|
+
* and {@link AnimationDefinition}s. It mutates the attributes in the given {@link PlacementDefinition} with the given
|
|
14
|
+
* {@link AnimationDefinition}. The latter can be anything the `GSAP` allows in its API. Please consider using the
|
|
15
|
+
* API of the {@link AnimationManager} to handle instances of this class in your consuming project.
|
|
16
|
+
*/
|
|
17
|
+
var PlacementAnimation = /** @class */ (function () {
|
|
18
|
+
/**
|
|
19
|
+
* Constructor.
|
|
20
|
+
*/
|
|
21
|
+
function PlacementAnimation(mutable, _placement, _animation) {
|
|
22
|
+
var _a;
|
|
23
|
+
this.mutable = mutable;
|
|
24
|
+
this._placement = _placement;
|
|
25
|
+
this._animation = _animation;
|
|
26
|
+
if (lodash_es_1.isString(_placement)) {
|
|
27
|
+
var placementDefinitions = specStorage_1.SpecStorage.get('scene.placements');
|
|
28
|
+
if (!placementDefinitions) {
|
|
29
|
+
throw new Error("No PlacementDefinitions defined in JSON structure.");
|
|
30
|
+
}
|
|
31
|
+
var placementDefinition = placementDefinitions[_placement];
|
|
32
|
+
if (!placementDefinition) {
|
|
33
|
+
throw new Error("PlacementDefinition \"" + _placement + "\" not defined in JSON structure.");
|
|
34
|
+
}
|
|
35
|
+
this._placementDefinition = lodash_es_1.cloneDeep(placementDefinition);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this._placementDefinition = lodash_es_1.cloneDeep(_placement);
|
|
39
|
+
}
|
|
40
|
+
if (lodash_es_1.isString(_animation)) {
|
|
41
|
+
var animationDefinition = (_a = specStorage_1.SpecStorage.get('scene.animations')) === null || _a === void 0 ? void 0 : _a[_animation];
|
|
42
|
+
if (!animationDefinition) {
|
|
43
|
+
throw new Error("AnimationDefinition \"" + _animation + "\" not defined in JSON structure.");
|
|
44
|
+
}
|
|
45
|
+
this._animationDefinition = lodash_es_1.cloneDeep(animationDefinition);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this._animationDefinition = lodash_es_1.cloneDeep(_animation);
|
|
49
|
+
}
|
|
50
|
+
this.prepareAnimationDefinition();
|
|
51
|
+
// create (shallow) copy for GSAP which doesn't contain `shortestWay`,
|
|
52
|
+
// because that's not part of the original `TweenVars` input typing and therefore leads to warnings
|
|
53
|
+
var _b = this._animationDefinition, shortestWay = _b.shortestWay, gsapTweenVars = tslib_1.__rest(_b, ["shortestWay"]);
|
|
54
|
+
this._timeline = gsap_1.gsap.timeline({
|
|
55
|
+
defaults: gsapTweenVars,
|
|
56
|
+
paused: true,
|
|
57
|
+
});
|
|
58
|
+
this.preparePlacementDefinition();
|
|
59
|
+
this.createTweens();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Plays all `Tweens` of this {@link PlacementAnimation}.
|
|
63
|
+
*/
|
|
64
|
+
PlacementAnimation.prototype.play = function () {
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
66
|
+
return tslib_1.__generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0: return [4 /*yield*/, this._timeline.play().then()];
|
|
69
|
+
case 1:
|
|
70
|
+
_a.sent();
|
|
71
|
+
return [2 /*return*/, this];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Pause all `Tweens` of this {@link PlacementAnimation}.
|
|
78
|
+
*/
|
|
79
|
+
PlacementAnimation.prototype.pause = function () {
|
|
80
|
+
this._timeline.pause();
|
|
81
|
+
return this;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Kills all `Tweens` of this {@link PlacementAnimation}.
|
|
85
|
+
*/
|
|
86
|
+
PlacementAnimation.prototype.kill = function () {
|
|
87
|
+
this._timeline.kill();
|
|
88
|
+
return this;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Creates a {@link AnimationDefinition} definition if not provided in the constructor and sets some defaults.
|
|
92
|
+
* Only custom properties from {@link AnimationDefinition} are adjusted, all {@link GSAPTweenVars} remain untouched.
|
|
93
|
+
*/
|
|
94
|
+
PlacementAnimation.prototype.prepareAnimationDefinition = function () {
|
|
95
|
+
// create an animation definition if not available yet
|
|
96
|
+
this._animationDefinition = this._animationDefinition || {};
|
|
97
|
+
// parse shortest way flag or set to `true` if not configured
|
|
98
|
+
if (this._animationDefinition.shortestWay !== undefined) {
|
|
99
|
+
this._animationDefinition.shortestWay = parameter_1.Parameter.parseBoolean(this._animationDefinition.shortestWay);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this._animationDefinition.shortestWay = true;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Prepares different types of {@link PlacementDefinition} and sets some defaults.
|
|
107
|
+
*/
|
|
108
|
+
PlacementAnimation.prototype.preparePlacementDefinition = function () {
|
|
109
|
+
var position = this._placementDefinition.position;
|
|
110
|
+
if (lodash_es_1.isString(position)) {
|
|
111
|
+
position = parameter_1.Parameter.parseVector(position);
|
|
112
|
+
this._placementDefinition.position = position;
|
|
113
|
+
}
|
|
114
|
+
if (this.mutable instanceof arcRotateCamera_1.ArcRotateCamera) {
|
|
115
|
+
// parse the target
|
|
116
|
+
if (lodash_es_1.isString(this._placementDefinition.target)) {
|
|
117
|
+
this._placementDefinition.target = parameter_1.Parameter.parseVector(this._placementDefinition.target);
|
|
118
|
+
}
|
|
119
|
+
if (position) {
|
|
120
|
+
// parse the position and calculate alpha, beta and radius with a "ghost camera"
|
|
121
|
+
// @see https://www.babylonjs-playground.com/#4IVMG#0
|
|
122
|
+
var ghostCam = this.mutable.clone('ghost');
|
|
123
|
+
ghostCam.setPosition(position);
|
|
124
|
+
lodash_es_1.merge(this._placementDefinition, {
|
|
125
|
+
alpha: ghostCam.alpha,
|
|
126
|
+
beta: ghostCam.beta,
|
|
127
|
+
radius: ghostCam.radius,
|
|
128
|
+
});
|
|
129
|
+
delete this._placementDefinition.position;
|
|
130
|
+
ghostCam.dispose();
|
|
131
|
+
}
|
|
132
|
+
else if (this._animationDefinition.shortestWay && this._placementDefinition.alpha !== undefined) {
|
|
133
|
+
// transform the target's alpha value into the same turn as the current camera position to avoid movements > 360 degrees
|
|
134
|
+
var alphaGap = this.mutable.alpha - this._placementDefinition.alpha;
|
|
135
|
+
var cntTurns = Math.round(alphaGap / (2 * Math.PI));
|
|
136
|
+
this._placementDefinition.alpha += 2 * Math.PI * cntTurns;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Creates `Tweens` for the {@link PlacementDefinition} configured for this {@link PlacementAnimation}.
|
|
142
|
+
*/
|
|
143
|
+
PlacementAnimation.prototype.createTweens = function () {
|
|
144
|
+
for (var property in this._placementDefinition) {
|
|
145
|
+
var propertyValue = lodash_es_1.get(this._placementDefinition, property);
|
|
146
|
+
var tweenVars = {};
|
|
147
|
+
var _mutable = this.mutable;
|
|
148
|
+
if (propertyValue instanceof math_vector_1.Vector3) {
|
|
149
|
+
// GSAP does not support mutation of complex objects, so we are forced
|
|
150
|
+
// to use the properties on the object as mutable directly and mutate
|
|
151
|
+
// the coordinates separately.
|
|
152
|
+
_mutable = lodash_es_1.get(this.mutable, property);
|
|
153
|
+
lodash_es_1.merge(tweenVars, { x: propertyValue.x, y: propertyValue.y, z: propertyValue.z });
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
lodash_es_1.set(tweenVars, property, propertyValue);
|
|
157
|
+
}
|
|
158
|
+
this._timeline.to(_mutable, tweenVars, 0); // Note: position 0 does the "parallel" stuff here
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return PlacementAnimation;
|
|
162
|
+
}());
|
|
163
|
+
exports.PlacementAnimation = PlacementAnimation;
|
|
164
164
|
//# sourceMappingURL=placementAnimation.js.map
|