@combeenation/3d-viewer 4.0.0-beta4 → 4.0.0-beta5

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 (106) hide show
  1. package/README.md +114 -112
  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 +190 -190
  6. package/dist/lib-cjs/api/classes/element.d.ts +130 -125
  7. package/dist/lib-cjs/api/classes/element.js +743 -682
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  11. package/dist/lib-cjs/api/classes/event.d.ts +326 -312
  12. package/dist/lib-cjs/api/classes/event.js +371 -357
  13. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  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 +259 -165
  17. package/dist/lib-cjs/api/classes/parameter.js +387 -267
  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 -126
  21. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  22. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  23. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  24. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  25. package/dist/lib-cjs/api/classes/placementAnimation.js +149 -138
  26. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  27. package/dist/lib-cjs/api/classes/variant.d.ts +234 -190
  28. package/dist/lib-cjs/api/classes/variant.js +1147 -873
  29. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  30. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -41
  31. package/dist/lib-cjs/api/classes/variantInstance.js +108 -98
  32. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  33. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  34. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  35. package/dist/lib-cjs/api/classes/viewer.d.ts +131 -128
  36. package/dist/lib-cjs/api/classes/viewer.js +560 -486
  37. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  38. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -65
  39. package/dist/lib-cjs/api/classes/viewerLight.js +389 -322
  40. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  41. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  42. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  43. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  44. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  45. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +10 -6
  46. package/dist/lib-cjs/api/internal/sceneSetup.js +231 -227
  47. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  49. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  50. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  51. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  53. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  54. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  55. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  56. package/dist/lib-cjs/api/util/babylonHelper.d.ts +175 -125
  57. package/dist/lib-cjs/api/util/babylonHelper.js +520 -368
  58. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  59. package/dist/lib-cjs/api/util/globalTypes.d.ts +333 -279
  60. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  61. package/dist/lib-cjs/api/util/resourceHelper.d.ts +53 -51
  62. package/dist/lib-cjs/api/util/resourceHelper.js +240 -243
  63. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  64. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  65. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  66. package/dist/lib-cjs/buildinfo.json +3 -3
  67. package/dist/lib-cjs/index.d.ts +48 -46
  68. package/dist/lib-cjs/index.js +86 -82
  69. package/dist/lib-cjs/index.js.map +1 -1
  70. package/package.json +83 -83
  71. package/src/api/classes/animationInterface.ts +11 -11
  72. package/src/api/classes/dottedPath.ts +189 -189
  73. package/src/api/classes/element.ts +644 -617
  74. package/src/api/classes/event.ts +370 -355
  75. package/src/api/classes/eventBroadcaster.ts +54 -54
  76. package/src/api/classes/parameter.ts +408 -277
  77. package/src/api/classes/parameterObservable.ts +99 -121
  78. package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +89 -78
  79. package/src/api/classes/placementAnimation.ts +143 -133
  80. package/src/api/classes/variant.ts +817 -670
  81. package/src/api/classes/variantInstance.ts +88 -81
  82. package/src/api/classes/variantParameterizable.ts +73 -0
  83. package/src/api/classes/viewer.ts +478 -421
  84. package/src/api/classes/viewerLight.ts +330 -0
  85. package/src/api/internal/debugViewer.ts +81 -81
  86. package/src/api/internal/lensRendering.ts +10 -10
  87. package/src/api/internal/sceneSetup.ts +194 -204
  88. package/src/api/manager/animationManager.ts +116 -116
  89. package/src/api/manager/sceneManager.ts +105 -105
  90. package/src/api/manager/variantInstanceManager.ts +236 -236
  91. package/src/api/store/specStorage.ts +53 -53
  92. package/src/api/util/babylonHelper.ts +553 -392
  93. package/src/api/util/globalTypes.ts +380 -319
  94. package/src/api/util/resourceHelper.ts +184 -187
  95. package/src/api/util/stringHelper.ts +26 -0
  96. package/src/buildinfo.json +2 -2
  97. package/src/commonjs.tsconfig.json +13 -13
  98. package/src/declaration.tsconfig.json +10 -10
  99. package/src/dev.ts +42 -46
  100. package/src/es6.tsconfig.json +13 -13
  101. package/src/index.ts +91 -87
  102. package/src/pagesconfig.json +61 -57
  103. package/src/tsconfig.json +43 -43
  104. package/src/tsconfig.types.json +9 -9
  105. package/src/types.d.ts +4 -4
  106. package/dist/webpack-stats.json +0 -0
@@ -1,277 +1,408 @@
1
- import { Color3 } from '@babylonjs/core/Maths/math.color';
2
- import { Vector3 } from '@babylonjs/core/Maths/math.vector';
3
- import { isNumber, isString } from 'lodash-es';
4
-
5
-
6
- /**
7
- * This `Parameter` class defines all parameters that can be consumed and committed by a {@link ParameterObservable}.
8
- * Use {@link ParameterObservable.addParameterObserver} or {@link ParameterObservable.commitParameters} to either add or
9
- * commit parameters on your observable objects.
10
- */
11
- export class Parameter {
12
-
13
- /**
14
- * Constructor.
15
- */
16
- private constructor() {}
17
-
18
- /**
19
- * Mutates the visibility. Helper methods are {@link ElementParameterizable.show} and
20
- * {@link ElementParameterizable.hide}. Getter and setter is {@link ElementParameterizable.visible}.
21
- *
22
- * Scopes:
23
- * * {@link Element}
24
- * * {@link Variant}
25
- *
26
- * @parser {@link parseBoolean}
27
- */
28
- public static readonly VISIBLE = 'visible';
29
-
30
- /**
31
- * Stretches or compresses some meshes. Getter and setter is {@link ElementParameterizable.scaling}.
32
- *
33
- * Scopes:
34
- * * {@link Element}
35
- * * {@link Variant}
36
- *
37
- * @parser {@link parseScaling}
38
- */
39
- public static readonly SCALING = 'scaling';
40
-
41
- /**
42
- * Mutates the material. Getter and setter is {@link ElementParameterizable.material}. The value of this parameter
43
- * represents the ID of a baked-in glTF or custom created material in the {@link Variant} tree.
44
- *
45
- * Scopes:
46
- * * {@link Element}
47
- * * {@link Variant}
48
- *
49
- * @parser string
50
- */
51
- public static readonly MATERIAL = 'material';
52
-
53
- /**
54
- * Mutates the material color.
55
- *
56
- * Scopes:
57
- * * {@link Element}
58
- * * {@link Variant}
59
- *
60
- * @parser {@link parseColor}
61
- */
62
- public static readonly MATERIAL_COLOR = 'material.color';
63
-
64
- /**
65
- * Mutates the material metallness.
66
- *
67
- * Scopes:
68
- * * {@link Element}
69
- * * {@link Variant}
70
- *
71
- * @parser {@link parseNumber}
72
- */
73
- public static readonly MATERIAL_METALLNESS = 'material.metallness';
74
-
75
- /**
76
- * Mutates the material roughness.
77
- *
78
- * Scopes:
79
- * * {@link Element}
80
- * * {@link Variant}
81
- *
82
- * @parser {@link parseNumber}
83
- */
84
- public static readonly MATERIAL_ROUGHNESS = 'material.roughness';
85
-
86
- /**
87
- * Mutates whether a highlight layer should be enabled.
88
- *
89
- * Scopes:
90
- * * {@link Element}
91
- * * {@link Variant}
92
- *
93
- * @parser {@link parseBoolean}
94
- */
95
- public static readonly HIGHLIGHT_ENABLED = 'highlight.enabled';
96
-
97
- /**
98
- * Changes the highlight color.
99
- *
100
- * Scopes:
101
- * * {@link Element}
102
- * * {@link Variant}
103
- *
104
- * @parser {@link parseColor}
105
- */
106
- public static readonly HIGHLIGHT_COLOR = 'highlight.color';
107
-
108
- /**
109
- * Mutates the highlighted state. Getter and setter is {@link ElementParameterizable.highlighted}.
110
- *
111
- * Scopes:
112
- * * {@link Element}
113
- * * {@link Variant}
114
- *
115
- * @parser {@link parseBoolean}
116
- */
117
- public static readonly HIGHLIGHTED = 'highlighted';
118
-
119
- /**
120
- * Mutates the position relative to its origin position. Getter and setter is {@link ElementParameterizable.position}.
121
- *
122
- * Scopes:
123
- * * {@link Element}
124
- * * {@link Variant}
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 ElementParameterizable.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
- * The {@link ParameterDeclarations} for all parameters in this class.
143
- */
144
- public static get declarations(): ParameterDeclarations {
145
- const declaration: ParameterDeclarations = {};
146
- declaration[Parameter.VISIBLE] = { type: 'boolean' };
147
- declaration[Parameter.SCALING] = { type: 'number' };
148
- declaration[Parameter.HIGHLIGHTED] = { type: 'boolean' };
149
- declaration[Parameter.MATERIAL] = { type: 'string' };
150
- declaration[Parameter.MATERIAL_COLOR] = { type: 'color' };
151
- declaration[Parameter.MATERIAL_METALLNESS] = { type: 'number' };
152
- declaration[Parameter.MATERIAL_ROUGHNESS] = { type: 'number' };
153
- declaration[Parameter.HIGHLIGHT_ENABLED] = { type: 'boolean' };
154
- declaration[Parameter.HIGHLIGHT_COLOR] = { type: 'color' };
155
- declaration[Parameter.HIGHLIGHTED] = { type: 'boolean' };
156
- declaration[Parameter.POSITION] = { type: 'vector' };
157
- declaration[Parameter.ROTATION] = { type: 'vector' };
158
- return declaration;
159
- }
160
-
161
- /**
162
- * Gets the {@link ParameterDeclaration} for a given {@link Parameter} declared in this class.
163
- */
164
- public static getDeclaration(parameter: string): ParameterDeclaration {
165
- return Parameter.declarations[parameter];
166
- }
167
-
168
- /**
169
- * All parameters defined in this class.
170
- */
171
- public static get all() {
172
- const all: string[] = [];
173
- for( const parameter in Parameter ) {
174
- const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
175
- if( parameter.toUpperCase() === parameter && property && isString( property.value ) ) {
176
- all.push( property.value );
177
- }
178
- }
179
- return all;
180
- }
181
-
182
- /**
183
- * Parses a string of format `'(x,y,z)'` to a `Vector3`.
184
- */
185
- public static parseVector( value: ParameterValue ): Vector3 {
186
- if( !isString( value ) ) {
187
- throw new Error( `Unable to convert "${value}" into a Vector: not a string.` );
188
- }
189
- let cleanedValue = value.split( ' ' ).join( '' );
190
- if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
191
- cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
192
- let [x, y, z] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
193
- return new Vector3( x, y, z );
194
- } else {
195
- throw new Error( `Unable to parse "${value}" to a Vector: expected "(x,y,z)".` );
196
- }
197
- }
198
-
199
- /**
200
- * Stringifies a Vector3 to format `(x,y,z)`.
201
- */
202
- public static stringifyVector( value: Vector3 ): string {
203
- return `(${value.x},${value.y},${value.z})`;
204
- }
205
-
206
- /**
207
- * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
208
- */
209
- public static parseRotation( value: ParameterValue ): Vector3 {
210
- const rotation = Parameter.parseVector( value );
211
- const deg2rad = function( deg: number ) {
212
- return deg * Math.PI / 180;
213
- };
214
- return rotation.set(
215
- deg2rad( rotation.x ),
216
- deg2rad( rotation.y ),
217
- deg2rad( rotation.z )
218
- );
219
- }
220
-
221
- /**
222
- * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
223
- */
224
- public static parseScaling( value: ParameterValue ): Vector3 {
225
- let scaling = new Vector3();
226
- if( isString( value ) ) {
227
- const cleanedFactor = value.split( ' ' ).join( '' );
228
- if( cleanedFactor.startsWith( '(' ) && cleanedFactor.endsWith( ')' ) ) {
229
- scaling = Parameter.parseVector( cleanedFactor );
230
- } else {
231
- const _factor = parseFloat( value );
232
- scaling = new Vector3( _factor, _factor, _factor );
233
- }
234
- } else if( isNumber( value ) ) {
235
- scaling = new Vector3( value, value, value );
236
- } else {
237
- throw new Error( `Unable to convert "${value}" to a Vector: expected "(x,y,z)".` );
238
- }
239
- return scaling;
240
- }
241
-
242
- /**
243
- * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
244
- */
245
- public static parseColor( value: ParameterValue ): Color3 {
246
- let cleanedValue = value.toString().split( ' ' ).join( '' );
247
- if( cleanedValue.startsWith( '#' ) ) {
248
- return Color3.FromHexString( value.toString() );
249
- }
250
- if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
251
- cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
252
- let [r, g, b] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
253
- return Color3.FromInts( r, g, b );
254
- }
255
- throw new Error( `Unable to parse "${value}" to a Color: expected "#rrggbb" or "(r,g,b)".` );
256
- }
257
-
258
- /**
259
- * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or `undefined`.
260
- */
261
- public static parseBoolean( value: ParameterValue ): boolean {
262
- if( value.toString() === 'true' || value.toString() === '1' ) {
263
- return true;
264
- } else if( value.toString() === 'false' || value.toString() === '0' ) {
265
- return false;
266
- }
267
- throw new Error( `Unable to parse "${value}" to a boolean.` );
268
- }
269
-
270
- /**
271
- * Parses a number `string` to a `number`.
272
- */
273
- public static parseNumber( value: ParameterValue ): number {
274
- return parseFloat( value.toString() );
275
- }
276
-
277
- }
1
+ import { Color3 } from '@babylonjs/core/Maths/math.color';
2
+ import { Vector3 } from '@babylonjs/core/Maths/math.vector';
3
+ import { get, isEmpty, isNumber, isString } from 'lodash-es';
4
+
5
+
6
+ /**
7
+ * This `Parameter` class defines all parameters that can be consumed and committed by a {@link ParameterObservable}.
8
+ * Use {@link ParameterObservable.addParameterObserver} or {@link ParameterObservable.commitParameters} to either add or
9
+ * commit parameters on your observable objects.
10
+ */
11
+ 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.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.POSITION] = { type: 'vector', parser: Parameter.parseVector };
252
+ declarations[Parameter.ROTATION] = { type: 'vector', parser: Parameter.parseVector };
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
+
408
+ }