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