@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.
Files changed (80) hide show
  1. package/README.md +2 -2
  2. package/dist/lib-cjs/api/classes/dottedPath.js +2 -5
  3. package/dist/lib-cjs/api/classes/dottedPath.js.map +1 -1
  4. package/dist/lib-cjs/api/classes/element.js +89 -66
  5. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  6. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  7. package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +1 -1
  8. package/dist/lib-cjs/api/classes/parameter.js +3 -2
  9. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  10. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  11. package/dist/lib-cjs/api/classes/parameterizable.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/placementAnimation.js +2 -2
  13. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  14. package/dist/lib-cjs/api/classes/variant.js +26 -19
  15. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  16. package/dist/lib-cjs/api/classes/variantInstance.js +19 -19
  17. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  18. package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/viewer.d.ts +5 -0
  20. package/dist/lib-cjs/api/classes/viewer.js +32 -17
  21. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  22. package/dist/lib-cjs/api/classes/viewerLight.js +24 -24
  23. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  24. package/dist/lib-cjs/api/internal/debugViewer.js +1 -2
  25. package/dist/lib-cjs/api/internal/debugViewer.js.map +1 -1
  26. package/dist/lib-cjs/api/internal/lensRendering.js.map +1 -1
  27. package/dist/lib-cjs/api/internal/sceneSetup.js +25 -22
  28. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  29. package/dist/lib-cjs/api/manager/animationManager.js +24 -15
  30. package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
  31. package/dist/lib-cjs/api/manager/sceneManager.js +3 -3
  32. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  33. package/dist/lib-cjs/api/manager/variantInstanceManager.js +10 -7
  34. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
  35. package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
  36. package/dist/lib-cjs/api/util/babylonHelper.d.ts +1 -1
  37. package/dist/lib-cjs/api/util/babylonHelper.js +12 -15
  38. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  39. package/dist/lib-cjs/api/util/globalTypes.d.ts +25 -24
  40. package/dist/lib-cjs/api/util/resourceHelper.js +3 -1
  41. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  42. package/dist/lib-cjs/api/util/stringHelper.d.ts +1 -1
  43. package/dist/lib-cjs/api/util/stringHelper.js +2 -2
  44. package/dist/lib-cjs/api/util/stringHelper.js.map +1 -1
  45. package/dist/lib-cjs/index.js.map +1 -1
  46. package/package.json +7 -3
  47. package/src/api/classes/animationInterface.ts +4 -6
  48. package/src/api/classes/dottedPath.ts +179 -187
  49. package/src/api/classes/element.ts +644 -621
  50. package/src/api/classes/event.ts +310 -313
  51. package/src/api/classes/eventBroadcaster.ts +47 -49
  52. package/src/api/classes/parameter.ts +394 -397
  53. package/src/api/classes/parameterObservable.ts +84 -83
  54. package/src/api/classes/parameterizable.ts +71 -73
  55. package/src/api/classes/placementAnimation.ts +130 -130
  56. package/src/api/classes/variant.ts +806 -778
  57. package/src/api/classes/variantInstance.ts +60 -52
  58. package/src/api/classes/variantParameterizable.ts +72 -67
  59. package/src/api/classes/viewer.ts +531 -489
  60. package/src/api/classes/viewerLight.ts +300 -300
  61. package/src/api/internal/debugViewer.ts +61 -53
  62. package/src/api/internal/lensRendering.ts +2 -3
  63. package/src/api/internal/sceneSetup.ts +144 -137
  64. package/src/api/manager/animationManager.ts +122 -97
  65. package/src/api/manager/sceneManager.ts +83 -86
  66. package/src/api/manager/variantInstanceManager.ts +234 -224
  67. package/src/api/store/specStorage.ts +48 -51
  68. package/src/api/util/babylonHelper.ts +329 -325
  69. package/src/api/util/globalTypes.ts +244 -245
  70. package/src/api/util/resourceHelper.ts +97 -109
  71. package/src/api/util/stringHelper.ts +13 -16
  72. package/src/buildinfo.json +2 -2
  73. package/src/commonjs.tsconfig.json +8 -11
  74. package/src/declaration.tsconfig.json +6 -8
  75. package/src/dev.ts +28 -28
  76. package/src/es6.tsconfig.json +8 -11
  77. package/src/index.ts +39 -39
  78. package/src/tsconfig.json +30 -41
  79. package/src/tsconfig.types.json +8 -9
  80. package/src/types.d.ts +0 -1
@@ -2,407 +2,404 @@ import { Color3 } from '@babylonjs/core/Maths/math.color';
2
2
  import { Vector3 } from '@babylonjs/core/Maths/math.vector';
3
3
  import { get, isEmpty, isNumber, isString } from 'lodash-es';
4
4
 
5
-
6
5
  /**
7
6
  * This `Parameter` class defines all parameters that can be consumed and committed by a {@link ParameterObservable}.
8
7
  * Use {@link ParameterObservable.addParameterObserver} or {@link ParameterObservable.commitParameters} to either add or
9
8
  * commit parameters on your observable objects.
10
9
  */
11
10
  export class Parameter {
12
-
13
- /**
14
- * Constructor.
15
- */
16
- private constructor() {}
17
-
18
- /**
19
- * Mutates the visibility. Helper methods are {@link VariantParameterizable.show} and
20
- * {@link VariantParameterizable.hide}. Getter and setter is {@link VariantParameterizable.visible}.
21
- *
22
- * Scopes:
23
- * * {@link Element}
24
- * * {@link Variant}
25
- * * {@link ViewerLight} Available for all light types
26
- *
27
- * @parser {@link parseBoolean}
28
- */
29
- public static readonly VISIBLE = 'visible';
30
-
31
- /**
32
- * Stretches or compresses some meshes. Getter and setter is {@link VariantParameterizable.scaling}.
33
- *
34
- * Scopes:
35
- * * {@link Element}
36
- * * {@link Variant}
37
- *
38
- * @parser {@link parseScaling}
39
- */
40
- public static readonly SCALING = 'scaling';
41
-
42
- /**
43
- * Mutates the material. Getter and setter is {@link VariantParameterizable.material}. The value of this parameter
44
- * represents the ID of a baked-in glTF or custom created material in the {@link Variant} tree.
45
- *
46
- * Scopes:
47
- * * {@link Element}
48
- * * {@link Variant}
49
- *
50
- * @parser string
51
- */
52
- public static readonly MATERIAL = 'material';
53
-
54
- /**
55
- * Mutates the material color.
56
- *
57
- * Scopes:
58
- * * {@link Element}
59
- * * {@link Variant}
60
- *
61
- * @parser {@link parseColor}
62
- */
63
- public static readonly MATERIAL_COLOR = 'material.color';
64
-
65
- /**
66
- * Mutates the material metallness.
67
- *
68
- * Scopes:
69
- * * {@link Element}
70
- * * {@link Variant}
71
- *
72
- * @parser {@link parseNumber}
73
- */
74
- public static readonly MATERIAL_METALLNESS = 'material.metallness';
75
-
76
- /**
77
- * Mutates the material roughness.
78
- *
79
- * Scopes:
80
- * * {@link Element}
81
- * * {@link Variant}
82
- *
83
- * @parser {@link parseNumber}
84
- */
85
- public static readonly MATERIAL_ROUGHNESS = 'material.roughness';
86
-
87
- /**
88
- * Mutates whether a highlight layer should be enabled.
89
- *
90
- * Scopes:
91
- * * {@link Element}
92
- * * {@link Variant}
93
- *
94
- * @parser {@link parseBoolean}
95
- */
96
- public static readonly HIGHLIGHT_ENABLED = 'highlight.enabled';
97
-
98
- /**
99
- * Changes the highlight color.
100
- *
101
- * Scopes:
102
- * * {@link Element}
103
- * * {@link Variant}
104
- *
105
- * @parser {@link parseColor}
106
- */
107
- public static readonly HIGHLIGHT_COLOR = 'highlight.color';
108
-
109
- /**
110
- * Mutates the highlighted state. Getter and setter is {@link VariantParameterizable.highlighted}.
111
- *
112
- * Scopes:
113
- * * {@link Element}
114
- * * {@link Variant}
115
- *
116
- * @parser {@link parseBoolean}
117
- */
118
- public static readonly HIGHLIGHTED = 'highlighted';
119
-
120
- /**
121
- * Mutates the position relative to its origin position. Getter and setter is {@link VariantParameterizable.position}.
122
- *
123
- * Scopes:
124
- * * {@link Element}
125
- * * {@link Variant}
126
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#position), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#position), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#position)
127
- *
128
- * @parser {@link parseVector}
129
- */
130
- public static readonly POSITION = 'position';
131
-
132
- /**
133
- * Mutates the rotation relative to its origin rotation. Getter and setter is {@link VariantParameterizable.rotation}.
134
- *
135
- * Scopes:
136
- * * {@link Element}
137
- * * {@link Variant}
138
- *
139
- * @parser {@link parseRotation}
140
- */
141
- public static readonly ROTATION = 'rotation';
142
-
143
- /**
144
- * Mutates whether a shadow should be casted or not.
145
- *
146
- * Scopes:
147
- * * {@link Element}
148
- * * {@link Variant}
149
- *
150
- * @parser {@link parseBoolean}
151
- */
152
- public static readonly CAST_SHADOW = 'castShadow';
153
-
154
- /**
155
- * Mutates from which lights a shadow should be casted.
156
- *
157
- * Scopes:
158
- * * {@link Element}
159
- * * {@link Variant}
160
- *
161
- * @parser {@link parseCommaSeparatedList}
162
- */
163
- public static readonly CAST_SHADOW_FROM_LIGHTS = 'castShadow.fromLights';
164
-
165
- /**
166
- * Mutates whether to receive shadows or not.
167
- *
168
- * Scopes:
169
- * * {@link Element}
170
- * * {@link Variant}
171
- *
172
- * @parser {@link parseBoolean}
173
- */
174
- public static readonly RECEIVE_SHADOWS = 'receiveShadows';
175
-
176
- /**
177
- * Mutates the intensity of Lights.
178
- *
179
- * Scopes:
180
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#intensity), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#intensity), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#intensity), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#intensity)
181
- *
182
- * @parser {@link parseNumber}
183
- */
184
- public static readonly INTENSITY = 'intensity';
185
-
186
- /**
187
- * Mutates the direction of Lights.
188
- *
189
- * Scopes:
190
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#direction), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#direction), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#direction), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#direction)
191
- *
192
- * @parser {@link parseNumber}
193
- */
194
- public static readonly DIRECTION = 'direction';
195
-
196
- /**
197
- * Mutates the angle of Lights.
198
- *
199
- * Scopes:
200
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#angle)
201
- *
202
- * @parser {@link parseNumber}
203
- */
204
- public static readonly ANGLE = 'angle';
205
-
206
- /**
207
- * Mutates the exponent of Lights.
208
- *
209
- * Scopes:
210
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#exponent)
211
- *
212
- * @parser {@link parseNumber}
213
- */
214
- public static readonly EXPONENT = 'exponent';
215
-
216
- /**
217
- * Mutates the diffuse color of Lights.
218
- *
219
- * Scopes:
220
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#diffuse), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#diffuse), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#diffuse), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#diffuse)
221
- *
222
- * @parser {@link parseNumber}
223
- */
224
- public static readonly DIFFUSE = 'diffuse';
225
-
226
- /**
227
- * Mutates the specular color of Lights.
228
- *
229
- * Scopes:
230
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#specular), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#specular), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#specular), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#specular)
231
- *
232
- * @parser {@link parseNumber}
233
- */
234
- public static readonly SPECULAR = 'specular';
235
-
236
- /**
237
- * The {@link ParameterDeclarations} for all parameters in this class.
238
- */
239
- public static get declarations(): ParameterDeclarations {
240
- const declarations: ParameterDeclarations = {};
241
- declarations[Parameter.VISIBLE] = { type: 'boolean', parser: Parameter.parseBoolean };
242
- declarations[Parameter.SCALING] = { type: 'number', parser: Parameter.parseNumber };
243
- declarations[Parameter.POSITION] = { type: 'vector', parser: Parameter.parseVector };
244
- declarations[Parameter.ROTATION] = { type: 'vector', parser: Parameter.parseVector };
245
- declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
246
- declarations[Parameter.MATERIAL] = { type: 'string' };
247
- declarations[Parameter.MATERIAL_COLOR] = { type: 'color', parser: Parameter.parseColor };
248
- declarations[Parameter.MATERIAL_METALLNESS] = { type: 'number', parser: Parameter.parseNumber };
249
- declarations[Parameter.MATERIAL_ROUGHNESS] = { type: 'number', parser: Parameter.parseNumber };
250
- declarations[Parameter.HIGHLIGHT_ENABLED] = { type: 'boolean', parser: Parameter.parseBoolean };
251
- declarations[Parameter.HIGHLIGHT_COLOR] = { type: 'color', parser: Parameter.parseColor };
252
- declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
253
- declarations[Parameter.CAST_SHADOW] = { type: 'boolean', parser: Parameter.parseBoolean };
254
- declarations[Parameter.CAST_SHADOW_FROM_LIGHTS] = { type: 'csl', parser: Parameter.parseCommaSeparatedList };
255
- declarations[Parameter.RECEIVE_SHADOWS] = { type: 'boolean', parser: Parameter.parseBoolean };
256
- declarations[Parameter.INTENSITY] = { type: 'number', parser: Parameter.parseNumber };
257
- declarations[Parameter.DIRECTION] = { type: 'vector', parser: Parameter.parseVector };
258
- declarations[Parameter.ANGLE] = { type: 'number', parser: Parameter.parseNumber };
259
- declarations[Parameter.EXPONENT] = { type: 'number', parser: Parameter.parseNumber };
260
- declarations[Parameter.DIFFUSE] = { type: 'color', parser: Parameter.parseColor };
261
- declarations[Parameter.SPECULAR] = { type: 'color', parser: Parameter.parseColor };
262
- return declarations;
263
- }
264
-
265
- /**
266
- * Gets the {@link ParameterDeclaration} for a given {@link Parameter} declared in this class.
267
- */
268
- public static getDeclaration(parameter: string): ParameterDeclaration {
269
- return Parameter.declarations[parameter];
270
- }
271
-
272
- /**
273
- * All parameters defined in this class.
274
- */
275
- public static get all() {
276
- const all: string[] = [];
277
- for( const parameter in Parameter ) {
278
- const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
279
- if( parameter.toUpperCase() === parameter && property && isString( property.value ) ) {
280
- all.push( property.value );
281
- }
282
- }
283
- return all;
284
- }
285
-
286
- /**
287
- * Parses given {@link ParameterBag} with given {@link ParameterDeclarations}.
288
- */
289
- public static parseFromDeclarations( declarations: ParameterDeclarations, parameterBag: ParameterBag ): ParsedParameterBag {
290
- const parameters: ParsedParameterBag = {};
291
- for( const parameter in parameterBag ) {
292
- const value = get( parameterBag, parameter );
293
- parameters[parameter] = value;
294
- const declaration: ParameterDeclaration = declarations[parameter];
295
- if( declaration ) {
296
- if( !isEmpty( value ) && declaration.parser ) {
297
- parameters[parameter] = declaration.parser( value );
298
- }
299
- }
300
- }
301
- return parameters;
302
- }
303
-
304
- /**
305
- * Parses a string of format `'(x,y,z)'` to a `Vector3`.
306
- */
307
- public static parseVector( value: ParameterValue ): Vector3 {
308
- if( !isString( value ) ) {
309
- throw new Error( `Unable to convert "${value}" into a Vector: not a string.` );
310
- }
311
- let cleanedValue = value.split( ' ' ).join( '' );
312
- if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
313
- cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
314
- let [x, y, z] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
315
- return new Vector3( x, y, z );
316
- } else {
317
- throw new Error( `Unable to parse "${value}" to a Vector: expected "(x,y,z)".` );
318
- }
319
- }
320
-
321
- /**
322
- * Stringifies a Vector3 to format `(x,y,z)`.
323
- */
324
- public static stringifyVector( value: Vector3 ): string {
325
- return `(${value.x},${value.y},${value.z})`;
326
- }
327
-
328
- /**
329
- * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
330
- */
331
- public static parseRotation( value: ParameterValue ): Vector3 {
332
- const rotation = Parameter.parseVector( value );
333
- const deg2rad = function( deg: number ) {
334
- return deg * Math.PI / 180;
335
- };
336
- return rotation.set(
337
- deg2rad( rotation.x ),
338
- deg2rad( rotation.y ),
339
- deg2rad( rotation.z )
340
- );
341
- }
342
-
343
- /**
344
- * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
345
- */
346
- public static parseScaling( value: ParameterValue ): Vector3 {
347
- let scaling = new Vector3();
348
- if( isString( value ) ) {
349
- const cleanedFactor = value.split( ' ' ).join( '' );
350
- if( cleanedFactor.startsWith( '(' ) && cleanedFactor.endsWith( ')' ) ) {
351
- scaling = Parameter.parseVector( cleanedFactor );
352
- } else {
353
- const _factor = parseFloat( value );
354
- scaling = new Vector3( _factor, _factor, _factor );
355
- }
356
- } else if( isNumber( value ) ) {
357
- scaling = new Vector3( value, value, value );
358
- } else {
359
- throw new Error( `Unable to convert "${value}" to a Vector: expected "(x,y,z)".` );
360
- }
361
- return scaling;
362
- }
363
-
364
- /**
365
- * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
366
- */
367
- public static parseColor( value: ParameterValue ): Color3 {
368
- let cleanedValue = value.toString().split( ' ' ).join( '' );
369
- if( cleanedValue.startsWith( '#' ) ) {
370
- return Color3.FromHexString( value.toString() );
371
- }
372
- if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
373
- cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
374
- let [r, g, b] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
375
- return Color3.FromInts( r, g, b );
376
- }
377
- throw new Error( `Unable to parse "${value}" to a Color: expected "#rrggbb" or "(r,g,b)".` );
378
- }
379
-
380
- /**
381
- * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or `undefined`.
382
- */
383
- public static parseBoolean( value: ParameterValue ): boolean {
384
- if( value.toString() === 'true' || value.toString() === '1' ) {
385
- return true;
386
- } else if( value.toString() === 'false' || value.toString() === '0' ) {
387
- return false;
388
- }
389
- throw new Error( `Unable to parse "${value}" to a boolean.` );
390
- }
391
-
392
- /**
393
- * Parses a number `string` to a `number`.
394
- */
395
- public static parseNumber( value: ParameterValue ): number {
396
- return parseFloat( value.toString() );
397
- }
398
-
399
- /**
400
- * Parses a string with comma separated values to a list of strings.
401
- */
402
- public static parseCommaSeparatedList( value: ParameterValue ): string[] {
403
- return value.toString()
404
- .split( ',' )
405
- .map( s => s.trim() );
406
- }
407
-
11
+ /**
12
+ * Constructor.
13
+ */
14
+ private constructor() {}
15
+
16
+ /**
17
+ * Mutates the visibility. Helper methods are {@link VariantParameterizable.show} and
18
+ * {@link VariantParameterizable.hide}. Getter and setter is {@link VariantParameterizable.visible}.
19
+ *
20
+ * Scopes:
21
+ * * {@link Element}
22
+ * * {@link Variant}
23
+ * * {@link ViewerLight} Available for all light types
24
+ *
25
+ * @parser {@link parseBoolean}
26
+ */
27
+ public static readonly VISIBLE = 'visible';
28
+
29
+ /**
30
+ * Stretches or compresses some meshes. Getter and setter is {@link VariantParameterizable.scaling}.
31
+ *
32
+ * Scopes:
33
+ * * {@link Element}
34
+ * * {@link Variant}
35
+ *
36
+ * @parser {@link parseScaling}
37
+ */
38
+ public static readonly SCALING = 'scaling';
39
+
40
+ /**
41
+ * Mutates the material. Getter and setter is {@link VariantParameterizable.material}. The value of this parameter
42
+ * represents the ID of a baked-in glTF or custom created material in the {@link Variant} tree.
43
+ *
44
+ * Scopes:
45
+ * * {@link Element}
46
+ * * {@link Variant}
47
+ *
48
+ * @parser string
49
+ */
50
+ public static readonly MATERIAL = 'material';
51
+
52
+ /**
53
+ * Mutates the material color.
54
+ *
55
+ * Scopes:
56
+ * * {@link Element}
57
+ * * {@link Variant}
58
+ *
59
+ * @parser {@link parseColor}
60
+ */
61
+ public static readonly MATERIAL_COLOR = 'material.color';
62
+
63
+ /**
64
+ * Mutates the material metallness.
65
+ *
66
+ * Scopes:
67
+ * * {@link Element}
68
+ * * {@link Variant}
69
+ *
70
+ * @parser {@link parseNumber}
71
+ */
72
+ public static readonly MATERIAL_METALLNESS = 'material.metallness';
73
+
74
+ /**
75
+ * Mutates the material roughness.
76
+ *
77
+ * Scopes:
78
+ * * {@link Element}
79
+ * * {@link Variant}
80
+ *
81
+ * @parser {@link parseNumber}
82
+ */
83
+ public static readonly MATERIAL_ROUGHNESS = 'material.roughness';
84
+
85
+ /**
86
+ * Mutates whether a highlight layer should be enabled.
87
+ *
88
+ * Scopes:
89
+ * * {@link Element}
90
+ * * {@link Variant}
91
+ *
92
+ * @parser {@link parseBoolean}
93
+ */
94
+ public static readonly HIGHLIGHT_ENABLED = 'highlight.enabled';
95
+
96
+ /**
97
+ * Changes the highlight color.
98
+ *
99
+ * Scopes:
100
+ * * {@link Element}
101
+ * * {@link Variant}
102
+ *
103
+ * @parser {@link parseColor}
104
+ */
105
+ public static readonly HIGHLIGHT_COLOR = 'highlight.color';
106
+
107
+ /**
108
+ * Mutates the highlighted state. Getter and setter is {@link VariantParameterizable.highlighted}.
109
+ *
110
+ * Scopes:
111
+ * * {@link Element}
112
+ * * {@link Variant}
113
+ *
114
+ * @parser {@link parseBoolean}
115
+ */
116
+ public static readonly HIGHLIGHTED = 'highlighted';
117
+
118
+ /**
119
+ * Mutates the position relative to its origin position. Getter and setter is {@link VariantParameterizable.position}.
120
+ *
121
+ * Scopes:
122
+ * * {@link Element}
123
+ * * {@link Variant}
124
+ * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#position), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#position), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#position)
125
+ *
126
+ * @parser {@link parseVector}
127
+ */
128
+ public static readonly POSITION = 'position';
129
+
130
+ /**
131
+ * Mutates the rotation relative to its origin rotation. Getter and setter is {@link VariantParameterizable.rotation}.
132
+ *
133
+ * Scopes:
134
+ * * {@link Element}
135
+ * * {@link Variant}
136
+ *
137
+ * @parser {@link parseRotation}
138
+ */
139
+ public static readonly ROTATION = 'rotation';
140
+
141
+ /**
142
+ * Mutates whether a shadow should be casted or not.
143
+ *
144
+ * Scopes:
145
+ * * {@link Element}
146
+ * * {@link Variant}
147
+ *
148
+ * @parser {@link parseBoolean}
149
+ */
150
+ public static readonly CAST_SHADOW = 'castShadow';
151
+
152
+ /**
153
+ * Mutates from which lights a shadow should be casted.
154
+ *
155
+ * Scopes:
156
+ * * {@link Element}
157
+ * * {@link Variant}
158
+ *
159
+ * @parser {@link parseCommaSeparatedList}
160
+ */
161
+ public static readonly CAST_SHADOW_FROM_LIGHTS = 'castShadow.fromLights';
162
+
163
+ /**
164
+ * Mutates whether to receive shadows or not.
165
+ *
166
+ * Scopes:
167
+ * * {@link Element}
168
+ * * {@link Variant}
169
+ *
170
+ * @parser {@link parseBoolean}
171
+ */
172
+ public static readonly RECEIVE_SHADOWS = 'receiveShadows';
173
+
174
+ /**
175
+ * Mutates the intensity of Lights.
176
+ *
177
+ * Scopes:
178
+ * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#intensity), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#intensity), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#intensity), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#intensity)
179
+ *
180
+ * @parser {@link parseNumber}
181
+ */
182
+ public static readonly INTENSITY = 'intensity';
183
+
184
+ /**
185
+ * Mutates the direction of Lights.
186
+ *
187
+ * Scopes:
188
+ * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#direction), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#direction), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#direction), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#direction)
189
+ *
190
+ * @parser {@link parseNumber}
191
+ */
192
+ public static readonly DIRECTION = 'direction';
193
+
194
+ /**
195
+ * Mutates the angle of Lights.
196
+ *
197
+ * Scopes:
198
+ * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#angle)
199
+ *
200
+ * @parser {@link parseNumber}
201
+ */
202
+ public static readonly ANGLE = 'angle';
203
+
204
+ /**
205
+ * Mutates the exponent of Lights.
206
+ *
207
+ * Scopes:
208
+ * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#exponent)
209
+ *
210
+ * @parser {@link parseNumber}
211
+ */
212
+ public static readonly EXPONENT = 'exponent';
213
+
214
+ /**
215
+ * Mutates the diffuse color of Lights.
216
+ *
217
+ * Scopes:
218
+ * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#diffuse), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#diffuse), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#diffuse), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#diffuse)
219
+ *
220
+ * @parser {@link parseNumber}
221
+ */
222
+ public static readonly DIFFUSE = 'diffuse';
223
+
224
+ /**
225
+ * Mutates the specular color of Lights.
226
+ *
227
+ * Scopes:
228
+ * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#specular), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#specular), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#specular), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#specular)
229
+ *
230
+ * @parser {@link parseNumber}
231
+ */
232
+ public static readonly SPECULAR = 'specular';
233
+
234
+ /**
235
+ * The {@link ParameterDeclarations} for all parameters in this class.
236
+ */
237
+ public static get declarations(): ParameterDeclarations {
238
+ const declarations: ParameterDeclarations = {};
239
+ declarations[Parameter.VISIBLE] = { type: 'boolean', parser: Parameter.parseBoolean };
240
+ declarations[Parameter.SCALING] = { type: 'number', parser: Parameter.parseNumber };
241
+ declarations[Parameter.POSITION] = { type: 'vector', parser: Parameter.parseVector };
242
+ declarations[Parameter.ROTATION] = { type: 'vector', parser: Parameter.parseVector };
243
+ declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
244
+ declarations[Parameter.MATERIAL] = { type: 'string' };
245
+ declarations[Parameter.MATERIAL_COLOR] = { type: 'color', parser: Parameter.parseColor };
246
+ declarations[Parameter.MATERIAL_METALLNESS] = { type: 'number', parser: Parameter.parseNumber };
247
+ declarations[Parameter.MATERIAL_ROUGHNESS] = { type: 'number', parser: Parameter.parseNumber };
248
+ declarations[Parameter.HIGHLIGHT_ENABLED] = { type: 'boolean', parser: Parameter.parseBoolean };
249
+ declarations[Parameter.HIGHLIGHT_COLOR] = { type: 'color', parser: Parameter.parseColor };
250
+ declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
251
+ declarations[Parameter.CAST_SHADOW] = { type: 'boolean', parser: Parameter.parseBoolean };
252
+ declarations[Parameter.CAST_SHADOW_FROM_LIGHTS] = { type: 'csl', parser: Parameter.parseCommaSeparatedList };
253
+ declarations[Parameter.RECEIVE_SHADOWS] = { type: 'boolean', parser: Parameter.parseBoolean };
254
+ declarations[Parameter.INTENSITY] = { type: 'number', parser: Parameter.parseNumber };
255
+ declarations[Parameter.DIRECTION] = { type: 'vector', parser: Parameter.parseVector };
256
+ declarations[Parameter.ANGLE] = { type: 'number', parser: Parameter.parseNumber };
257
+ declarations[Parameter.EXPONENT] = { type: 'number', parser: Parameter.parseNumber };
258
+ declarations[Parameter.DIFFUSE] = { type: 'color', parser: Parameter.parseColor };
259
+ declarations[Parameter.SPECULAR] = { type: 'color', parser: Parameter.parseColor };
260
+ return declarations;
261
+ }
262
+
263
+ /**
264
+ * Gets the {@link ParameterDeclaration} for a given {@link Parameter} declared in this class.
265
+ */
266
+ public static getDeclaration(parameter: string): ParameterDeclaration {
267
+ return Parameter.declarations[parameter];
268
+ }
269
+
270
+ /**
271
+ * All parameters defined in this class.
272
+ */
273
+ public static get all() {
274
+ const all: string[] = [];
275
+ for (const parameter in Parameter) {
276
+ const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
277
+ if (parameter.toUpperCase() === parameter && property && isString(property.value)) {
278
+ all.push(property.value);
279
+ }
280
+ }
281
+ return all;
282
+ }
283
+
284
+ /**
285
+ * Parses given {@link ParameterBag} with given {@link ParameterDeclarations}.
286
+ */
287
+ public static parseFromDeclarations(
288
+ declarations: ParameterDeclarations,
289
+ parameterBag: ParameterBag
290
+ ): ParsedParameterBag {
291
+ const parameters: ParsedParameterBag = {};
292
+ for (const parameter in parameterBag) {
293
+ const value = get(parameterBag, parameter);
294
+ parameters[parameter] = value;
295
+ const declaration: ParameterDeclaration = declarations[parameter];
296
+ if (declaration) {
297
+ if (!isEmpty(value) && declaration.parser) {
298
+ parameters[parameter] = declaration.parser(value);
299
+ }
300
+ }
301
+ }
302
+ return parameters;
303
+ }
304
+
305
+ /**
306
+ * Parses a string of format `'(x,y,z)'` to a `Vector3`.
307
+ */
308
+ public static parseVector(value: ParameterValue): Vector3 {
309
+ if (!isString(value)) {
310
+ throw new Error(`Unable to convert "${value}" into a Vector: not a string.`);
311
+ }
312
+ let cleanedValue = value.split(' ').join('');
313
+ if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
314
+ cleanedValue = cleanedValue.substring(1, cleanedValue.length - 1);
315
+ let [x, y, z] = cleanedValue.split(',').map(value => parseFloat(value));
316
+ return new Vector3(x, y, z);
317
+ } else {
318
+ throw new Error(`Unable to parse "${value}" to a Vector: expected "(x,y,z)".`);
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Stringifies a Vector3 to format `(x,y,z)`.
324
+ */
325
+ public static stringifyVector(value: Vector3): string {
326
+ return `(${value.x},${value.y},${value.z})`;
327
+ }
328
+
329
+ /**
330
+ * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
331
+ */
332
+ public static parseRotation(value: ParameterValue): Vector3 {
333
+ const rotation = Parameter.parseVector(value);
334
+ const deg2rad = function (deg: number) {
335
+ return (deg * Math.PI) / 180;
336
+ };
337
+ return rotation.set(deg2rad(rotation.x), deg2rad(rotation.y), deg2rad(rotation.z));
338
+ }
339
+
340
+ /**
341
+ * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
342
+ */
343
+ public static parseScaling(value: ParameterValue): Vector3 {
344
+ let scaling = new Vector3();
345
+ if (isString(value)) {
346
+ const cleanedFactor = value.split(' ').join('');
347
+ if (cleanedFactor.startsWith('(') && cleanedFactor.endsWith(')')) {
348
+ scaling = Parameter.parseVector(cleanedFactor);
349
+ } else {
350
+ const _factor = parseFloat(value);
351
+ scaling = new Vector3(_factor, _factor, _factor);
352
+ }
353
+ } else if (isNumber(value)) {
354
+ scaling = new Vector3(value, value, value);
355
+ } else {
356
+ throw new Error(`Unable to convert "${value}" to a Vector: expected "(x,y,z)".`);
357
+ }
358
+ return scaling;
359
+ }
360
+
361
+ /**
362
+ * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
363
+ */
364
+ public static parseColor(value: ParameterValue): Color3 {
365
+ let cleanedValue = value.toString().split(' ').join('');
366
+ if (cleanedValue.startsWith('#')) {
367
+ return Color3.FromHexString(value.toString());
368
+ }
369
+ if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
370
+ cleanedValue = cleanedValue.substring(1, cleanedValue.length - 1);
371
+ let [r, g, b] = cleanedValue.split(',').map(value => parseFloat(value));
372
+ return Color3.FromInts(r, g, b);
373
+ }
374
+ throw new Error(`Unable to parse "${value}" to a Color: expected "#rrggbb" or "(r,g,b)".`);
375
+ }
376
+
377
+ /**
378
+ * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or `undefined`.
379
+ */
380
+ public static parseBoolean(value: ParameterValue): boolean {
381
+ if (value.toString() === 'true' || value.toString() === '1') {
382
+ return true;
383
+ } else if (value.toString() === 'false' || value.toString() === '0') {
384
+ return false;
385
+ }
386
+ throw new Error(`Unable to parse "${value}" to a boolean.`);
387
+ }
388
+
389
+ /**
390
+ * Parses a number `string` to a `number`.
391
+ */
392
+ public static parseNumber(value: ParameterValue): number {
393
+ return parseFloat(value.toString());
394
+ }
395
+
396
+ /**
397
+ * Parses a string with comma separated values to a list of strings.
398
+ */
399
+ public static parseCommaSeparatedList(value: ParameterValue): string[] {
400
+ return value
401
+ .toString()
402
+ .split(',')
403
+ .map(s => s.trim());
404
+ }
408
405
  }