@combeenation/3d-viewer 4.2.0 → 4.3.0-alpha1
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 +2 -2
- package/dist/lib-cjs/api/classes/dottedPath.js +2 -5
- package/dist/lib-cjs/api/classes/dottedPath.js.map +1 -1
- package/dist/lib-cjs/api/classes/element.js +89 -66
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/event.js.map +1 -1
- package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameter.js +3 -2
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterizable.js.map +1 -1
- package/dist/lib-cjs/api/classes/placementAnimation.js +2 -2
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.js +26 -19
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.js +19 -19
- package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +5 -0
- package/dist/lib-cjs/api/classes/viewer.js +32 -17
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.js +24 -24
- package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
- package/dist/lib-cjs/api/internal/debugViewer.js +1 -2
- package/dist/lib-cjs/api/internal/debugViewer.js.map +1 -1
- package/dist/lib-cjs/api/internal/lensRendering.js.map +1 -1
- package/dist/lib-cjs/api/internal/sceneSetup.js +25 -22
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/manager/animationManager.js +24 -15
- package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.js +3 -3
- package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +10 -7
- package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
- package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.js +12 -15
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +25 -24
- package/dist/lib-cjs/api/util/resourceHelper.js +3 -1
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +1 -1
- package/dist/lib-cjs/api/util/stringHelper.js +2 -2
- package/dist/lib-cjs/api/util/stringHelper.js.map +1 -1
- package/dist/lib-cjs/index.js.map +1 -1
- package/package.json +7 -3
- package/src/api/classes/animationInterface.ts +4 -6
- package/src/api/classes/dottedPath.ts +179 -187
- package/src/api/classes/element.ts +644 -621
- package/src/api/classes/event.ts +310 -313
- package/src/api/classes/eventBroadcaster.ts +47 -49
- package/src/api/classes/parameter.ts +394 -397
- package/src/api/classes/parameterObservable.ts +84 -83
- package/src/api/classes/parameterizable.ts +71 -73
- package/src/api/classes/placementAnimation.ts +130 -130
- package/src/api/classes/variant.ts +806 -778
- package/src/api/classes/variantInstance.ts +60 -52
- package/src/api/classes/variantParameterizable.ts +72 -67
- package/src/api/classes/viewer.ts +531 -489
- package/src/api/classes/viewerLight.ts +300 -300
- package/src/api/internal/debugViewer.ts +61 -53
- package/src/api/internal/lensRendering.ts +2 -3
- package/src/api/internal/sceneSetup.ts +144 -137
- package/src/api/manager/animationManager.ts +122 -97
- package/src/api/manager/sceneManager.ts +83 -86
- package/src/api/manager/variantInstanceManager.ts +234 -224
- package/src/api/store/specStorage.ts +48 -51
- package/src/api/util/babylonHelper.ts +329 -325
- package/src/api/util/globalTypes.ts +244 -245
- package/src/api/util/resourceHelper.ts +97 -109
- package/src/api/util/stringHelper.ts +13 -16
- package/src/buildinfo.json +2 -2
- package/src/commonjs.tsconfig.json +8 -11
- package/src/declaration.tsconfig.json +6 -8
- package/src/dev.ts +28 -28
- package/src/es6.tsconfig.json +8 -11
- package/src/index.ts +39 -39
- package/src/tsconfig.json +30 -41
- package/src/tsconfig.types.json +8 -9
- package/src/types.d.ts +0 -1
|
@@ -3,97 +3,98 @@ import { uuidv4 } from '../util/stringHelper';
|
|
|
3
3
|
import { EventBroadcaster } from './eventBroadcaster';
|
|
4
4
|
|
|
5
5
|
export abstract class ParameterObservable extends EventBroadcaster {
|
|
6
|
+
public readonly uuid: string;
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
public readonly parameters: ParameterBag = {};
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
protected readonly parameterDeclaration: ParameterDeclarations = {};
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
protected parameterObservers: Map<string, ParameterObserver[]> = new Map();
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
protected constructor(parameterDeclaration: ParameterDeclarations = {}, parameters: ParameterBag = {}) {
|
|
15
|
+
super();
|
|
16
|
+
this.uuid = uuidv4();
|
|
17
|
+
this.parameterDeclaration = merge(this.parameterDeclaration, parameterDeclaration);
|
|
18
|
+
this.parameters = merge(this.parameters, parameters);
|
|
19
|
+
}
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The uuid (if not overloaded).
|
|
23
|
+
*/
|
|
24
|
+
get id(): string {
|
|
25
|
+
return this.uuid;
|
|
26
|
+
}
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Adds an observer function for parameter changes.
|
|
30
|
+
* The {@link ParameterObserver} gets 3 parameters: the {@link ParameterObservable}, the old {@link ParameterValue}
|
|
31
|
+
* and the new {@link ParameterValue}.
|
|
32
|
+
*
|
|
33
|
+
* See {@page Parameters} for an example.
|
|
34
|
+
*/
|
|
35
|
+
public addParameterObserver(parameter: string, observer: ParameterObserver): ParameterObservable {
|
|
36
|
+
if (this.parameterObservers.has(parameter)) {
|
|
37
|
+
this.parameterObservers.get(parameter)!.push(observer);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
this.parameterObservers.set(parameter, [observer]);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
public addParameterObserver( parameter: string, observer: ParameterObserver ): ParameterObservable {
|
|
37
|
-
if( this.parameterObservers.has( parameter ) ) {
|
|
38
|
-
this.parameterObservers.get( parameter )!.push( observer );
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
this.parameterObservers.set( parameter, [observer] );
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
+
/**
|
|
45
|
+
* Removes all {@link ParameterObserver}s for given parameter.
|
|
46
|
+
*/
|
|
47
|
+
public removeParameterObservers(parameter: string): ParameterObservable {
|
|
48
|
+
this.parameterObservers.delete(parameter);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Invoke parameter observers for given parameter.
|
|
54
|
+
*/
|
|
55
|
+
public async commitParameter(parameter: string, value: ParameterValue): Promise<ParameterObservable> {
|
|
56
|
+
const parameters: ParameterBag = {};
|
|
57
|
+
parameters[parameter] = value;
|
|
58
|
+
return this.commitParameters(parameters);
|
|
59
|
+
}
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const parameters: ParameterBag = {};
|
|
58
|
-
parameters[parameter] = value;
|
|
59
|
-
return this.commitParameters( parameters );
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Invoke parameter observers for given parameters.
|
|
64
|
-
*/
|
|
65
|
-
public abstract commitParameters( parameters?: ParameterBag ): Promise<ParameterObservable>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Asserts whether given parameter is declared and valid.
|
|
69
|
-
*/
|
|
70
|
-
public assertParameter( parameterDeclaration: ParameterDeclarations, parameter: string, value: ParameterValue ) {
|
|
71
|
-
if( !(parameter in parameterDeclaration) ) {
|
|
72
|
-
// This is a valid case since we are not able to check parameters that are not declared.
|
|
73
|
-
// We just ignore parameters that are not declared.
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const declaration = parameterDeclaration[parameter];
|
|
77
|
-
const genericError = `"${value}" is not a valid value for parameter "${parameter}" of type. ` +
|
|
78
|
-
`"${declaration.type}" for ${this.constructor.name} "${this.id}".`;
|
|
79
|
-
if( declaration.parser ) {
|
|
80
|
-
try {
|
|
81
|
-
declaration.parser( value );
|
|
82
|
-
} catch( e ) {
|
|
83
|
-
throw Error( genericError + e.message );
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
switch( declaration.type ) {
|
|
87
|
-
case 'select':
|
|
88
|
-
if( !declaration.options ) {
|
|
89
|
-
throw Error( `No options defined for parameter declaration "${parameter}"` +
|
|
90
|
-
`of type "${declaration.type}" for ${this.constructor.name} "${this.id}".` );
|
|
91
|
-
}
|
|
92
|
-
if( declaration.options.indexOf( value ) === -1 ) {
|
|
93
|
-
throw Error( genericError + ` Valid values are: "${declaration.options.join( '", "' )}".` );
|
|
94
|
-
}
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
61
|
+
/**
|
|
62
|
+
* Invoke parameter observers for given parameters.
|
|
63
|
+
*/
|
|
64
|
+
public abstract commitParameters(parameters?: ParameterBag): Promise<ParameterObservable>;
|
|
98
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Asserts whether given parameter is declared and valid.
|
|
68
|
+
*/
|
|
69
|
+
public assertParameter(parameterDeclaration: ParameterDeclarations, parameter: string, value: ParameterValue) {
|
|
70
|
+
if (!(parameter in parameterDeclaration)) {
|
|
71
|
+
// This is a valid case since we are not able to check parameters that are not declared.
|
|
72
|
+
// We just ignore parameters that are not declared.
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const declaration = parameterDeclaration[parameter];
|
|
76
|
+
const genericError =
|
|
77
|
+
`"${value}" is not a valid value for parameter "${parameter}" of type. ` +
|
|
78
|
+
`"${declaration.type}" for ${this.constructor.name} "${this.id}".`;
|
|
79
|
+
if (declaration.parser) {
|
|
80
|
+
try {
|
|
81
|
+
declaration.parser(value);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw Error(genericError + e.message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
switch (declaration.type) {
|
|
87
|
+
case 'select':
|
|
88
|
+
if (!declaration.options) {
|
|
89
|
+
throw Error(
|
|
90
|
+
`No options defined for parameter declaration "${parameter}"` +
|
|
91
|
+
`of type "${declaration.type}" for ${this.constructor.name} "${this.id}".`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
if (declaration.options.indexOf(value) === -1) {
|
|
95
|
+
throw Error(genericError + ` Valid values are: "${declaration.options.join('", "')}".`);
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
99
100
|
}
|
|
@@ -2,88 +2,86 @@ import { Parameter } from './parameter';
|
|
|
2
2
|
import { ParameterObservable } from './parameterObservable';
|
|
3
3
|
|
|
4
4
|
export abstract class Parameterizable extends ParameterObservable {
|
|
5
|
+
protected parameterDeclaration: ParameterDeclarations = Parameter.declarations;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
get visible(): boolean | undefined {
|
|
8
|
+
if (!(Parameter.VISIBLE in this.parameters)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
return Parameter.parseBoolean(this.parameters[Parameter.VISIBLE]);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
7
17
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
get highlighted(): boolean | undefined {
|
|
19
|
+
if (!(Parameter.HIGHLIGHTED in this.parameters)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
return Parameter.parseBoolean(this.parameters[Parameter.HIGHLIGHTED]);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
18
28
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} catch( e ) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
+
get material(): string | undefined {
|
|
30
|
+
if (!(Parameter.MATERIAL in this.parameters)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return this.parameters[Parameter.MATERIAL].toString();
|
|
34
|
+
}
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
get scaling(): string | undefined {
|
|
37
|
+
if (!(Parameter.SCALING in this.parameters)) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return this.parameters[Parameter.SCALING].toString();
|
|
41
|
+
}
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
get position(): string | undefined {
|
|
44
|
+
if (!(Parameter.POSITION in this.parameters)) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return this.parameters[Parameter.POSITION].toString();
|
|
48
|
+
}
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
get rotation(): string | undefined {
|
|
51
|
+
if (!(Parameter.ROTATION in this.parameters)) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return this.parameters[Parameter.ROTATION].toString();
|
|
55
|
+
}
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
get castShadow(): boolean | undefined {
|
|
58
|
+
if (!(Parameter.CAST_SHADOW in this.parameters)) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return Parameter.parseBoolean(this.parameters[Parameter.CAST_SHADOW]);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
return Parameter.parseBoolean( this.parameters[Parameter.CAST_SHADOW] );
|
|
64
|
-
} catch( e ) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
+
public async show(): Promise<ParameterObservable> {
|
|
69
|
+
await this.commitParameter(Parameter.VISIBLE, true);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
public async hide(): Promise<ParameterObservable> {
|
|
74
|
+
await this.commitParameter(Parameter.VISIBLE, false);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
public async toggle(): Promise<ParameterObservable> {
|
|
80
|
-
await this.commitParameter( Parameter.VISIBLE, !this.visible );
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public async toggleHighlight(): Promise<ParameterObservable> {
|
|
85
|
-
await this.commitParameter( Parameter.HIGHLIGHTED, !this.highlighted );
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
78
|
+
public async toggle(): Promise<ParameterObservable> {
|
|
79
|
+
await this.commitParameter(Parameter.VISIBLE, !this.visible);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
88
82
|
|
|
83
|
+
public async toggleHighlight(): Promise<ParameterObservable> {
|
|
84
|
+
await this.commitParameter(Parameter.HIGHLIGHTED, !this.highlighted);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
89
87
|
}
|
|
@@ -12,146 +12,146 @@ import { SpecStorage } from '../store/specStorage';
|
|
|
12
12
|
* API of the {@link AnimationManager} to handle instances of this class in your consuming project.
|
|
13
13
|
*/
|
|
14
14
|
export class PlacementAnimation implements AnimationInterface {
|
|
15
|
+
protected _placementDefinition: PlacementDefinition;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
protected _animationDefinition: AnimationDefinition;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
protected _timeline: GSAPTimeline;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*/
|
|
24
|
+
public constructor(
|
|
25
|
+
public readonly mutable: object,
|
|
26
|
+
protected _placement: PlacementDefinition | string,
|
|
27
|
+
protected _animation?: AnimationDefinition | string
|
|
28
|
+
) {
|
|
29
|
+
if (isString(_placement)) {
|
|
30
|
+
const placementDefinitions = SpecStorage.get<PlacementDefinitions>('scene.placements');
|
|
31
|
+
if (!placementDefinitions) {
|
|
32
|
+
throw new Error(`No PlacementDefinitions defined in JSON structure.`);
|
|
33
|
+
}
|
|
34
|
+
const placementDefinition = placementDefinitions[_placement];
|
|
35
|
+
if (!placementDefinition) {
|
|
36
|
+
throw new Error(`PlacementDefinition "${_placement}" not defined in JSON structure.`);
|
|
37
|
+
}
|
|
38
|
+
this._placementDefinition = cloneDeep(placementDefinition);
|
|
39
|
+
} else {
|
|
40
|
+
this._placementDefinition = cloneDeep(_placement) as PlacementDefinition;
|
|
41
|
+
}
|
|
42
|
+
if (isString(_animation)) {
|
|
43
|
+
const animationDefinition = SpecStorage.get<AnimationDefinitions>('scene.animations')?.[_animation];
|
|
44
|
+
if (!animationDefinition) {
|
|
45
|
+
throw new Error(`AnimationDefinition "${_animation}" not defined in JSON structure.`);
|
|
46
|
+
}
|
|
47
|
+
this._animationDefinition = cloneDeep(animationDefinition);
|
|
48
|
+
} else {
|
|
49
|
+
this._animationDefinition = cloneDeep(_animation) as AnimationDefinition;
|
|
50
|
+
}
|
|
21
51
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
protected _animation?: AnimationDefinition | string ) {
|
|
28
|
-
if( isString( _placement ) ) {
|
|
29
|
-
const placementDefinitions = SpecStorage.get<PlacementDefinitions>( 'scene.placements' );
|
|
30
|
-
if( !placementDefinitions ) {
|
|
31
|
-
throw new Error( `No PlacementDefinitions defined in JSON structure.` );
|
|
32
|
-
}
|
|
33
|
-
const placementDefinition = placementDefinitions[_placement];
|
|
34
|
-
if( !placementDefinition ) {
|
|
35
|
-
throw new Error( `PlacementDefinition "${_placement}" not defined in JSON structure.` );
|
|
36
|
-
}
|
|
37
|
-
this._placementDefinition = cloneDeep( placementDefinition );
|
|
38
|
-
} else {
|
|
39
|
-
this._placementDefinition = cloneDeep( _placement ) as PlacementDefinition;
|
|
40
|
-
}
|
|
41
|
-
if( isString( _animation ) ) {
|
|
42
|
-
const animationDefinition = SpecStorage.get<AnimationDefinitions>( 'scene.animations' )?.[_animation];
|
|
43
|
-
if( !animationDefinition ) {
|
|
44
|
-
throw new Error( `AnimationDefinition "${_animation}" not defined in JSON structure.` );
|
|
45
|
-
}
|
|
46
|
-
this._animationDefinition = cloneDeep( animationDefinition );
|
|
47
|
-
} else {
|
|
48
|
-
this._animationDefinition = cloneDeep( _animation ) as AnimationDefinition;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.prepareAnimationDefinition();
|
|
52
|
-
this._timeline = gsap.timeline( {
|
|
53
|
-
defaults: this._animationDefinition,
|
|
54
|
-
paused: true
|
|
55
|
-
} );
|
|
52
|
+
this.prepareAnimationDefinition();
|
|
53
|
+
this._timeline = gsap.timeline({
|
|
54
|
+
defaults: this._animationDefinition,
|
|
55
|
+
paused: true,
|
|
56
|
+
});
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
this.preparePlacementDefinition();
|
|
59
|
+
this.createTweens();
|
|
60
|
+
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Plays all `Tweens` of this {@link PlacementAnimation}.
|
|
64
|
+
*/
|
|
65
|
+
public async play(): Promise<AnimationInterface> {
|
|
66
|
+
await this._timeline.play().then();
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Pause all `Tweens` of this {@link PlacementAnimation}.
|
|
72
|
+
*/
|
|
73
|
+
public pause(): AnimationInterface {
|
|
74
|
+
this._timeline.pause();
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Kills all `Tweens` of this {@link PlacementAnimation}.
|
|
80
|
+
*/
|
|
81
|
+
public kill(): AnimationInterface {
|
|
82
|
+
this._timeline.kill();
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Creates a {@link AnimationDefinition} definition if not provided in the constructor and sets some defaults.
|
|
88
|
+
* Only custom properties from {@link AnimationDefinition} are adjusted, all {@link GSAPTweenVars} remain untouched.
|
|
89
|
+
*/
|
|
90
|
+
protected prepareAnimationDefinition() {
|
|
91
|
+
// create an animation definition if not available yet
|
|
92
|
+
this._animationDefinition = this._animationDefinition || {};
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
// parse shortest way flag or set to `true` if not configured
|
|
95
|
+
if (this._animationDefinition.shortestWay !== undefined) {
|
|
96
|
+
this._animationDefinition.shortestWay = Parameter.parseBoolean(this._animationDefinition.shortestWay);
|
|
97
|
+
} else {
|
|
98
|
+
this._animationDefinition.shortestWay = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Creates `Tweens` for the {@link PlacementDefinition} configured for this {@link PlacementAnimation}.
|
|
138
|
-
*/
|
|
139
|
-
protected createTweens() {
|
|
140
|
-
for( const property in this._placementDefinition ) {
|
|
141
|
-
const propertyValue = get( this._placementDefinition, property );
|
|
142
|
-
const tweenVars: object = {};
|
|
143
|
-
let _mutable = this.mutable;
|
|
144
|
-
if( propertyValue instanceof Vector3 ) {
|
|
145
|
-
// GSAP does not support mutation of complex objects, so we are forced
|
|
146
|
-
// to use the properties on the object as mutable directly and mutate
|
|
147
|
-
// the coordinates separately.
|
|
148
|
-
_mutable = get( this.mutable, property );
|
|
149
|
-
merge( tweenVars, { x: propertyValue.x, y: propertyValue.y, z: propertyValue.z } );
|
|
150
|
-
} else {
|
|
151
|
-
set( tweenVars, property, propertyValue );
|
|
152
|
-
}
|
|
153
|
-
this._timeline.to( _mutable, tweenVars, 0 ); // Note: position 0 does the "parallel" stuff here
|
|
154
|
-
}
|
|
155
|
-
}
|
|
102
|
+
/**
|
|
103
|
+
* Prepares different types of {@link PlacementDefinition} and sets some defaults.
|
|
104
|
+
*/
|
|
105
|
+
protected preparePlacementDefinition() {
|
|
106
|
+
let position = this._placementDefinition.position;
|
|
107
|
+
if (isString(position)) {
|
|
108
|
+
position = Parameter.parseVector(position);
|
|
109
|
+
this._placementDefinition.position = position;
|
|
110
|
+
}
|
|
111
|
+
if (this.mutable instanceof ArcRotateCamera) {
|
|
112
|
+
// parse the target
|
|
113
|
+
if (isString(this._placementDefinition.target)) {
|
|
114
|
+
this._placementDefinition.target = Parameter.parseVector(this._placementDefinition.target);
|
|
115
|
+
}
|
|
116
|
+
if (position) {
|
|
117
|
+
// parse the position and calculate alpha, beta and radius with a "ghost camera"
|
|
118
|
+
// @see https://www.babylonjs-playground.com/#4IVMG#0
|
|
119
|
+
const ghostCam = (this.mutable as ArcRotateCamera).clone('ghost') as ArcRotateCamera;
|
|
120
|
+
ghostCam.setPosition(position);
|
|
121
|
+
merge(this._placementDefinition, {
|
|
122
|
+
alpha: ghostCam.alpha,
|
|
123
|
+
beta: ghostCam.beta,
|
|
124
|
+
radius: ghostCam.radius,
|
|
125
|
+
});
|
|
126
|
+
delete this._placementDefinition.position;
|
|
127
|
+
ghostCam.dispose();
|
|
128
|
+
} else if (this._animationDefinition.shortestWay && this._placementDefinition.alpha !== undefined) {
|
|
129
|
+
// transform the target's alpha value into the same turn as the current camera position to avoid movements > 360 degrees
|
|
130
|
+
const alphaGap = this.mutable.alpha - this._placementDefinition.alpha;
|
|
131
|
+
const cntTurns = Math.round(alphaGap / (2 * Math.PI));
|
|
132
|
+
this._placementDefinition.alpha += 2 * Math.PI * cntTurns;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
156
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Creates `Tweens` for the {@link PlacementDefinition} configured for this {@link PlacementAnimation}.
|
|
139
|
+
*/
|
|
140
|
+
protected createTweens() {
|
|
141
|
+
for (const property in this._placementDefinition) {
|
|
142
|
+
const propertyValue = get(this._placementDefinition, property);
|
|
143
|
+
const tweenVars: object = {};
|
|
144
|
+
let _mutable = this.mutable;
|
|
145
|
+
if (propertyValue instanceof Vector3) {
|
|
146
|
+
// GSAP does not support mutation of complex objects, so we are forced
|
|
147
|
+
// to use the properties on the object as mutable directly and mutate
|
|
148
|
+
// the coordinates separately.
|
|
149
|
+
_mutable = get(this.mutable, property);
|
|
150
|
+
merge(tweenVars, { x: propertyValue.x, y: propertyValue.y, z: propertyValue.z });
|
|
151
|
+
} else {
|
|
152
|
+
set(tweenVars, property, propertyValue);
|
|
153
|
+
}
|
|
154
|
+
this._timeline.to(_mutable, tweenVars, 0); // Note: position 0 does the "parallel" stuff here
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
157
|
}
|