@combeenation/3d-viewer 9.3.0 → 10.0.0-alpha3

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 (111) hide show
  1. package/README.md +9 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
  6. package/dist/lib-cjs/api/classes/element.d.ts +153 -153
  7. package/dist/lib-cjs/api/classes/element.js +666 -667
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/event.d.ts +401 -401
  10. package/dist/lib-cjs/api/classes/event.js +424 -424
  11. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  12. package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
  13. package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +7 -7
  14. package/dist/lib-cjs/api/classes/fuzzyMap.js +21 -21
  15. package/dist/lib-cjs/api/classes/parameter.d.ts +410 -410
  16. package/dist/lib-cjs/api/classes/parameter.js +642 -642
  17. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  18. package/dist/lib-cjs/api/classes/parameterObservable.js +72 -72
  19. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  20. package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
  21. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
  22. package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
  23. package/dist/lib-cjs/api/classes/variant.d.ts +261 -261
  24. package/dist/lib-cjs/api/classes/variant.js +871 -871
  25. package/dist/lib-cjs/api/classes/variantInstance.d.ts +53 -53
  26. package/dist/lib-cjs/api/classes/variantInstance.js +125 -125
  27. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  28. package/dist/lib-cjs/api/classes/variantParameterizable.js +86 -86
  29. package/dist/lib-cjs/api/classes/viewer.d.ts +211 -213
  30. package/dist/lib-cjs/api/classes/viewer.js +736 -717
  31. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  32. package/dist/lib-cjs/api/classes/viewerError.d.ts +43 -43
  33. package/dist/lib-cjs/api/classes/viewerError.js +55 -55
  34. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  35. package/dist/lib-cjs/api/classes/viewerLight.js +344 -348
  36. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  37. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  38. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  39. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
  40. package/dist/lib-cjs/api/internal/sceneSetup.js +224 -226
  41. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  42. package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
  43. package/dist/lib-cjs/api/manager/animationManager.js +126 -126
  44. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +102 -102
  45. package/dist/lib-cjs/api/manager/gltfExportManager.js +322 -322
  46. package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
  47. package/dist/lib-cjs/api/manager/sceneManager.js +128 -128
  48. package/dist/lib-cjs/api/manager/tagManager.d.ts +118 -118
  49. package/dist/lib-cjs/api/manager/tagManager.js +535 -535
  50. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
  51. package/dist/lib-cjs/api/manager/textureLoadManager.js +98 -98
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +106 -106
  53. package/dist/lib-cjs/api/manager/variantInstanceManager.js +290 -290
  54. package/dist/lib-cjs/api/store/specStorage.d.ts +32 -32
  55. package/dist/lib-cjs/api/store/specStorage.js +65 -65
  56. package/dist/lib-cjs/api/util/babylonHelper.d.ts +238 -238
  57. package/dist/lib-cjs/api/util/babylonHelper.js +826 -826
  58. package/dist/lib-cjs/api/util/geometryHelper.d.ts +7 -7
  59. package/dist/lib-cjs/api/util/geometryHelper.js +115 -115
  60. package/dist/lib-cjs/api/util/globalTypes.d.ts +484 -484
  61. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  62. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
  63. package/dist/lib-cjs/api/util/resourceHelper.js +214 -214
  64. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +44 -44
  65. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +175 -175
  66. package/dist/lib-cjs/api/util/stringHelper.d.ts +13 -13
  67. package/dist/lib-cjs/api/util/stringHelper.js +32 -32
  68. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  69. package/dist/lib-cjs/api/util/structureHelper.js +64 -64
  70. package/dist/lib-cjs/buildinfo.json +3 -3
  71. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  72. package/dist/lib-cjs/index.d.ts +54 -54
  73. package/dist/lib-cjs/index.js +117 -117
  74. package/package.json +84 -82
  75. package/src/api/classes/animationInterface.ts +10 -10
  76. package/src/api/classes/dottedPath.ts +181 -181
  77. package/src/api/classes/element.ts +723 -723
  78. package/src/api/classes/event.ts +457 -457
  79. package/src/api/classes/eventBroadcaster.ts +52 -52
  80. package/src/api/classes/fuzzyMap.ts +21 -21
  81. package/src/api/classes/parameter.ts +686 -686
  82. package/src/api/classes/parameterObservable.ts +73 -73
  83. package/src/api/classes/parameterizable.ts +87 -87
  84. package/src/api/classes/placementAnimation.ts +162 -162
  85. package/src/api/classes/variant.ts +964 -964
  86. package/src/api/classes/variantInstance.ts +123 -123
  87. package/src/api/classes/variantParameterizable.ts +83 -83
  88. package/src/api/classes/viewer.ts +786 -770
  89. package/src/api/classes/viewerError.ts +63 -63
  90. package/src/api/classes/viewerLight.ts +335 -339
  91. package/src/api/internal/debugViewer.ts +90 -90
  92. package/src/api/internal/lensRendering.ts +9 -9
  93. package/src/api/internal/sceneSetup.ts +203 -205
  94. package/src/api/manager/animationManager.ts +143 -143
  95. package/src/api/manager/gltfExportManager.ts +312 -312
  96. package/src/api/manager/sceneManager.ts +134 -134
  97. package/src/api/manager/tagManager.ts +576 -576
  98. package/src/api/manager/textureLoadManager.ts +96 -96
  99. package/src/api/manager/variantInstanceManager.ts +306 -306
  100. package/src/api/store/specStorage.ts +68 -68
  101. package/src/api/util/babylonHelper.ts +915 -915
  102. package/src/api/util/geometryHelper.ts +140 -140
  103. package/src/api/util/globalTypes.ts +560 -560
  104. package/src/api/util/resourceHelper.ts +201 -201
  105. package/src/api/util/sceneLoaderHelper.ts +170 -170
  106. package/src/api/util/stringHelper.ts +30 -30
  107. package/src/api/util/structureHelper.ts +63 -63
  108. package/src/buildinfo.json +3 -3
  109. package/src/dev.ts +70 -62
  110. package/src/index.ts +103 -103
  111. package/src/types.d.ts +49 -38
@@ -1,686 +1,686 @@
1
- import { ViewerError, ViewerErrorIds } from './viewerError';
2
- import { Color3 } from '@babylonjs/core/Maths/math.color';
3
- import { Vector3 } from '@babylonjs/core/Maths/math.vector';
4
- import { capitalize, get, isEmpty, isNumber, isString } from 'lodash-es';
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
- * Constructor.
14
- */
15
- private constructor() {}
16
-
17
- /**
18
- * Mutates the visibility. Helper methods are {@link VariantParameterizable.show} and
19
- * {@link VariantParameterizable.hide}. Getter and setter is {@link VariantParameterizable.visible}.
20
- *
21
- * Scopes:
22
- * * {@link Element}
23
- * * {@link Variant}
24
- * * {@link ViewerLight} Available for all light types
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 VariantParameterizable.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 VariantParameterizable.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 VariantParameterizable.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 VariantParameterizable.position}.
121
- *
122
- * Scopes:
123
- * * {@link Element}
124
- * * {@link Variant}
125
- * * {@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)
126
- *
127
- * @parser {@link parseVector}
128
- */
129
- public static readonly POSITION = 'position';
130
-
131
- /**
132
- * Mutates the rotation relative to its origin rotation. Getter and setter is {@link VariantParameterizable.rotation}.
133
- *
134
- * Scopes:
135
- * * {@link Element}
136
- * * {@link Variant}
137
- *
138
- * @parser {@link parseRotation}
139
- */
140
- public static readonly ROTATION = 'rotation';
141
-
142
- /**
143
- * Mutates the color.
144
- *
145
- * Scopes:
146
- * * {@link Material} via {@link TagManager}
147
- *
148
- * @parser {@link parseColor}
149
- */
150
- public static readonly COLOR = 'color';
151
-
152
- /**
153
- * Mutates the metallic.
154
- *
155
- * Scopes:
156
- * * {@link Material} via {@link TagManager}
157
- *
158
- * @parser {@link parseNumber}
159
- */
160
- public static readonly METALLIC = 'metallic';
161
-
162
- /**
163
- * Paintables can be used to let the client/browser draw graphics on a 3d model by mutating the texture of a
164
- * material.\
165
- * For detailed information have a look at the [paintables](./../pages/documentation/Paintables.html) page.
166
- *
167
- * Also see {@link parsePaintable} for detailed information on which values you can pass to the `paintable`
168
- * parameter.
169
- *
170
- * Scopes:
171
- * * {@link Material} via {@link TagManager}
172
- *
173
- * @parser {@link parsePaintable}
174
- *
175
- */
176
- public static readonly PAINTABLE = 'paintable';
177
-
178
- /**
179
- * Mutates the roughness.
180
- *
181
- * Scopes:
182
- * * {@link Material} via {@link TagManager}
183
- *
184
- * @parser {@link parseNumber}
185
- */
186
- public static readonly ROUGHNESS = 'roughness';
187
-
188
- /**
189
- * Mutates whether a shadow should be casted or not.
190
- *
191
- * Scopes:
192
- * * {@link Element}
193
- * * {@link Variant}
194
- *
195
- * @parser {@link parseBoolean}
196
- */
197
- public static readonly CAST_SHADOW = 'castShadow';
198
-
199
- /**
200
- * Mutates from which lights a shadow should be casted.
201
- *
202
- * Scopes:
203
- * * {@link Element}
204
- * * {@link Variant}
205
- *
206
- * @parser {@link parseCommaSeparatedList}
207
- */
208
- public static readonly CAST_SHADOW_FROM_LIGHTS = 'castShadow.fromLights';
209
-
210
- /**
211
- * Mutates whether to receive shadows or not.
212
- *
213
- * Scopes:
214
- * * {@link Element}
215
- * * {@link Variant}
216
- *
217
- * @parser {@link parseBoolean}
218
- */
219
- public static readonly RECEIVE_SHADOWS = 'receiveShadows';
220
-
221
- /**
222
- * Mutates the intensity of Lights.
223
- *
224
- * Scopes:
225
- * * {@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)
226
- *
227
- * @parser {@link parseNumber}
228
- */
229
- public static readonly INTENSITY = 'intensity';
230
-
231
- /**
232
- * Mutates the direction of Lights.
233
- *
234
- * Scopes:
235
- * * {@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)
236
- *
237
- * @parser {@link parseNumber}
238
- */
239
- public static readonly DIRECTION = 'direction';
240
-
241
- /**
242
- * Mutates the angle of Lights.
243
- *
244
- * Scopes:
245
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#angle)
246
- *
247
- * @parser {@link parseNumber}
248
- */
249
- public static readonly ANGLE = 'angle';
250
-
251
- /**
252
- * Mutates the exponent of Lights.
253
- *
254
- * Scopes:
255
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#exponent)
256
- *
257
- * @parser {@link parseNumber}
258
- */
259
- public static readonly EXPONENT = 'exponent';
260
-
261
- /**
262
- * Mutates the diffuse color of Lights.
263
- *
264
- * Scopes:
265
- * * {@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)
266
- *
267
- * @parser {@link parseNumber}
268
- */
269
- public static readonly DIFFUSE = 'diffuse';
270
-
271
- /**
272
- * Mutates the specular color of Lights.
273
- *
274
- * Scopes:
275
- * * {@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)
276
- *
277
- * @parser {@link parseNumber}
278
- */
279
- public static readonly SPECULAR = 'specular';
280
-
281
- /**
282
- * Sets the environment. See [BABYLON.Scene.environmentTexture](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#environmentTexture).
283
- *
284
- * Usually the URL to an `*.env` file.
285
- *
286
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
287
- *
288
- * Scopes:
289
- * * {@link SceneManager}
290
- *
291
- * @parser string
292
- */
293
- public static readonly ENVIRONMENT = 'environment';
294
-
295
- /**
296
- * Sets [BABYLON.Scene.clearColor](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#clearColor)
297
- *
298
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
299
- *
300
- * Scopes:
301
- * * {@link SceneManager}
302
- *
303
- * @parser {@link parseColor}
304
- */
305
- public static readonly ENVIRONMENT_COLOR = 'environment.color';
306
-
307
- /**
308
- * Rotates connected textures, i.e. IBL, reflection, background, ...
309
- * Rotation angle in degree.
310
- *
311
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
312
- *
313
- * Scopes:
314
- * * {@link SceneManager}
315
- *
316
- * @parser {@link parseNumber}
317
- */
318
- public static readonly ENVIRONMENT_ROTATION = 'environment.rotation';
319
-
320
- /**
321
- * Intensity of IBL. Defaults to 1, usually between 0 & 2.
322
- *
323
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
324
- *
325
- * Scopes:
326
- * * {@link SceneManager}
327
- *
328
- * @parser {@link parseNumber}
329
- */
330
- public static readonly ENVIRONMENT_INTENSITY = 'environment.intensity';
331
-
332
- /**
333
- * Background texture on a [PhotoDome](https://doc.babylonjs.com/divingDeeper/environment/360PhotoDome).
334
- * Just background, no IBL or reflection.
335
- *
336
- * Recommended format is `*.jpg`. HDR files are not supported as background but can be converted to `*.jpg` using
337
- * tools like Photoshop, Gimp or various free online converters.
338
- *
339
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
340
- *
341
- * Scopes:
342
- * * {@link SceneManager}
343
- *
344
- * @parser string
345
- */
346
- public static readonly ENVIRONMENT_BACKGROUND = 'environment.background';
347
-
348
- /**
349
- * If `true`, sets a `scene.environmentTexture` and creates a *BackgroundHelper* Node (via
350
- * [scene.createDefaultEnvironment](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#createDefaultEnvironment))
351
- * with two subnodes/meshes:
352
- * - BackgroundPlane
353
- * - BackgroundSkybox
354
- *
355
- * The value of this parameter is ignored if {@link ENVIRONMENT_BACKGROUND} is also set.
356
- *
357
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
358
- *
359
- * Scopes:
360
- * * {@link SceneManager}
361
- *
362
- * @parser {@link parseBoolean}
363
- */
364
- public static readonly ENVIRONMENT_USEDEFAULT = 'environment.usedefault';
365
-
366
- /**
367
- * The {@link ParameterDeclarations} for all parameters in this class.
368
- */
369
- public static get declarations(): ParameterDeclarations {
370
- return {
371
- [Parameter.VISIBLE]: { type: 'boolean', parser: Parameter.parseBoolean },
372
- [Parameter.SCALING]: { type: 'number', parser: Parameter.parseNumber },
373
- [Parameter.POSITION]: { type: 'vector', parser: Parameter.parseVector },
374
- [Parameter.ROTATION]: { type: 'vector', parser: Parameter.parseVector },
375
- [Parameter.HIGHLIGHTED]: { type: 'boolean', parser: Parameter.parseBoolean },
376
- [Parameter.MATERIAL]: { type: 'string' },
377
- [Parameter.MATERIAL_COLOR]: { type: 'color', parser: Parameter.parseColor },
378
- [Parameter.MATERIAL_METALLNESS]: { type: 'number', parser: Parameter.parseNumber },
379
- [Parameter.MATERIAL_ROUGHNESS]: { type: 'number', parser: Parameter.parseNumber },
380
- [Parameter.HIGHLIGHT_ENABLED]: { type: 'boolean', parser: Parameter.parseBoolean },
381
- [Parameter.HIGHLIGHT_COLOR]: { type: 'color', parser: Parameter.parseColor },
382
- [Parameter.COLOR]: { type: 'color', parser: Parameter.parseColor },
383
- [Parameter.METALLIC]: { type: 'number', parser: Parameter.parseNumber },
384
- [Parameter.ROUGHNESS]: { type: 'number', parser: Parameter.parseNumber },
385
- [Parameter.PAINTABLE]: { type: 'paintable', parser: Parameter.parsePaintable },
386
- [Parameter.HIGHLIGHTED]: { type: 'boolean', parser: Parameter.parseBoolean },
387
- [Parameter.CAST_SHADOW]: { type: 'boolean', parser: Parameter.parseBoolean },
388
- [Parameter.CAST_SHADOW_FROM_LIGHTS]: { type: 'csl', parser: Parameter.parseCommaSeparatedList },
389
- [Parameter.RECEIVE_SHADOWS]: { type: 'boolean', parser: Parameter.parseBoolean },
390
- [Parameter.INTENSITY]: { type: 'number', parser: Parameter.parseNumber },
391
- [Parameter.DIRECTION]: { type: 'vector', parser: Parameter.parseVector },
392
- [Parameter.ANGLE]: { type: 'number', parser: Parameter.parseNumber },
393
- [Parameter.EXPONENT]: { type: 'number', parser: Parameter.parseNumber },
394
- [Parameter.DIFFUSE]: { type: 'color', parser: Parameter.parseColor },
395
- [Parameter.SPECULAR]: { type: 'color', parser: Parameter.parseColor },
396
- [Parameter.ENVIRONMENT]: { type: 'string' },
397
- [Parameter.ENVIRONMENT_COLOR]: { type: 'color', parser: Parameter.parseColor },
398
- [Parameter.ENVIRONMENT_ROTATION]: { type: 'number', parser: Parameter.parseNumber },
399
- [Parameter.ENVIRONMENT_INTENSITY]: { type: 'number', parser: Parameter.parseNumber },
400
- [Parameter.ENVIRONMENT_BACKGROUND]: { type: 'string' },
401
- [Parameter.ENVIRONMENT_USEDEFAULT]: { type: 'boolean', parser: Parameter.parseBoolean },
402
- };
403
- }
404
-
405
- /**
406
- * The default {@link ParameterValue}s returned as {@link ParameterBag} for a set of parameters in this class.
407
- */
408
- public static get defaultValues(): ParameterBag {
409
- return {
410
- [Parameter.SCALING]: '(1, 1, 1)',
411
- [Parameter.POSITION]: '(0, 0, 0)',
412
- [Parameter.ROTATION]: '(0, 0, 0)',
413
- };
414
- }
415
-
416
- /**
417
- * Gets the default {@link ParameterValue} for a given {@link Parameter} declared in this class.
418
- */
419
- public static getDefaultValue(parameter: string): ParameterValue {
420
- return Parameter.defaultValues[parameter];
421
- }
422
-
423
- /**
424
- * All parameters defined in this class.
425
- */
426
- public static get all() {
427
- const all: string[] = [];
428
- for (const parameter in Parameter) {
429
- const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
430
- if (parameter.toUpperCase() === parameter && property && isString(property.value)) {
431
- all.push(property.value);
432
- }
433
- }
434
- return all;
435
- }
436
-
437
- /**
438
- * Asserts whether given parameter is declared and valid.
439
- */
440
- public static assertParameter(parameterDeclaration: ParameterDeclarations, parameter: string, value: ParameterValue) {
441
- if (!(parameter in parameterDeclaration)) {
442
- // This is a valid case since we are not able to check parameters that are not declared.
443
- // We just ignore parameters that are not declared.
444
- return;
445
- }
446
- const declaration = parameterDeclaration[parameter];
447
- const errorPrefix = `Invalid value for parameter "${parameter}" of type "${declaration.type}" given:`;
448
- if (declaration.parser) {
449
- try {
450
- declaration.parser(value);
451
- } catch (e: any) {
452
- throw new ViewerError({
453
- id: ViewerErrorIds.InvalidParameterValue,
454
- message: `${errorPrefix}\n${e.message}.\nGiven value: ${value}`,
455
- });
456
- }
457
- }
458
- switch (declaration.type) {
459
- case 'select':
460
- if (!declaration.options) {
461
- throw new ViewerError({
462
- id: ViewerErrorIds.UnknownParameterOption,
463
- message: `No options defined for parameter declaration "${parameter}" of type "${declaration.type}".`,
464
- });
465
- }
466
- if (declaration.options.indexOf(value) === -1) {
467
- throw Error(
468
- `${errorPrefix}\nValid values are: "${declaration.options.join('", "')}".\nGiven value: ${value}`
469
- );
470
- }
471
- break;
472
- }
473
- }
474
-
475
- /**
476
- * Parses given {@link ParameterBag} with given {@link ParameterDeclarations}.
477
- */
478
- public static parseFromDeclarations(
479
- declarations: ParameterDeclarations,
480
- parameterBag: ParameterBag
481
- ): ParsedParameterBag {
482
- const parameters: ParsedParameterBag = {};
483
- for (const parameter in parameterBag) {
484
- const value = get(parameterBag, parameter);
485
- parameters[parameter] = value;
486
- const declaration: ParameterDeclaration = declarations[parameter];
487
- if (declaration) {
488
- if (!isEmpty(value) && declaration.parser) {
489
- parameters[parameter] = declaration.parser(value);
490
- }
491
- }
492
- }
493
- return parameters;
494
- }
495
-
496
- /**
497
- * Parses a string of format `'(x,y,z)'` to a `Vector3`.
498
- */
499
- public static parseVector(value: ParameterValue): Vector3 {
500
- if (!isString(value)) {
501
- throw new Error(`Unable to convert "${value}" into a Vector: not a string.`);
502
- }
503
- let cleanedValue = value.split(' ').join('');
504
- if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
505
- cleanedValue = cleanedValue.substring(1, cleanedValue.length - 1);
506
- const [x, y, z] = cleanedValue.split(',').map(value => parseFloat(value));
507
- return new Vector3(x, y, z);
508
- } else {
509
- throw new Error(`Unable to parse "${value}" to a Vector: expected "(x,y,z)".`);
510
- }
511
- }
512
-
513
- /**
514
- * Stringifies a Vector3 to format `(x,y,z)`.
515
- */
516
- public static stringifyVector(value: Vector3): string {
517
- return `(${value.x},${value.y},${value.z})`;
518
- }
519
-
520
- /**
521
- * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
522
- */
523
- public static parseRotation(value: ParameterValue): Vector3 {
524
- const rotation = Parameter.parseVector(value);
525
- const deg2rad = function (deg: number) {
526
- return (deg * Math.PI) / 180;
527
- };
528
- return rotation.set(deg2rad(rotation.x), deg2rad(rotation.y), deg2rad(rotation.z));
529
- }
530
-
531
- /**
532
- * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
533
- */
534
- public static parseScaling(value: ParameterValue): Vector3 {
535
- let scaling = new Vector3();
536
- if (isString(value)) {
537
- const cleanedFactor = value.split(' ').join('');
538
- if (cleanedFactor.startsWith('(') && cleanedFactor.endsWith(')')) {
539
- scaling = Parameter.parseVector(cleanedFactor);
540
- } else {
541
- const _factor = parseFloat(value);
542
- scaling = new Vector3(_factor, _factor, _factor);
543
- }
544
- } else if (isNumber(value)) {
545
- scaling = new Vector3(value, value, value);
546
- } else {
547
- throw new Error(`Unable to convert "${value}" to a Vector: expected "(x,y,z)".`);
548
- }
549
- return scaling;
550
- }
551
-
552
- /**
553
- * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
554
- */
555
- public static parseColor(value: ParameterValue): Color3 {
556
- const cleanedValue = value.toString().split(' ').join('');
557
- if (cleanedValue.startsWith('#')) {
558
- return Color3.FromHexString(value.toString());
559
- }
560
- if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
561
- const rgb = cleanedValue.substring(1, cleanedValue.length - 1);
562
- const [r, g, b] = rgb.split(',').map(value => parseFloat(value));
563
- return Color3.FromInts(r, g, b);
564
- }
565
- const humanReadable = capitalize(cleanedValue);
566
- // disable lint for this rule as there is no smoother option for checking static class functions (eg Color.Red())
567
- // eslint-disable-next-line no-prototype-builtins
568
- if (Color3.hasOwnProperty(humanReadable)) {
569
- // @ts-ignore same as above
570
- return Color3[humanReadable]();
571
- }
572
- throw new Error(
573
- `Unable to parse "${value}" to a Color: expected "#rrggbb", "(r,g,b)" or any human readable property implemented in Color3.`
574
- );
575
- }
576
-
577
- /**
578
- * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or
579
- * `undefined`.
580
- */
581
- public static parseBoolean(value: ParameterValue): boolean {
582
- if (value.toString() === 'true' || value.toString() === '1') {
583
- return true;
584
- } else if (value.toString() === 'false' || value.toString() === '0') {
585
- return false;
586
- }
587
- throw new Error(`Unable to parse "${value}" to a boolean.`);
588
- }
589
-
590
- /**
591
- * Parses a number `string` to a `number`.
592
- */
593
- public static parseNumber(value: ParameterValue): number {
594
- return parseFloat(value.toString());
595
- }
596
-
597
- /**
598
- * Parses string defintion of a paintable into a paintable object.\
599
- * Here are some examples:
600
- * ```ts
601
- * // Default definition as JSON object:
602
- * '{ "src": "https://path.to/image.jpg", "uScale": 0.5 }'
603
- *
604
- * // Short hand definition, only contains source string:
605
- * 'https://path.to/image.jpg'
606
- *
607
- * // Full content, paintable texture is flipped in both directions
608
- * '{ "src": "https://path.to/image.jpg", "uScale": -1, "vScale": -1, "uOffset": 0, "vOffset": 0 }'
609
- *
610
- * // SVG content can be used directly:
611
- * '<svg>...</svg>'
612
- *
613
- * // SVG in src property works as well:
614
- * '{ "src": "<svg>...</svg>", "uScale": 0.5 }'
615
- * ```
616
- */
617
- public static parsePaintable(value: ParameterValue): PaintableValue {
618
- if (!isString(value)) {
619
- throw new Error(`Not a string.`);
620
- }
621
-
622
- const paintableValue: PaintableValue = { src: '' };
623
- let valObj: { [key: string]: any } | null = null;
624
-
625
- try {
626
- valObj = JSON.parse(value);
627
- } catch {
628
- // use string directly
629
- paintableValue.src = value;
630
-
631
- if (value.startsWith('{')) {
632
- // seems like the user tried to use a JSON string, as the input starts with {
633
- throw new Error(`Not a valid JSON string.`);
634
- }
635
- }
636
-
637
- if (valObj) {
638
- // input string is JSON, src attribute is required
639
- if (!valObj.src) {
640
- throw new Error(`Property "src" is missing.`);
641
- }
642
-
643
- if (!isString(valObj.src)) {
644
- throw new Error(`Property "src" is not a string.`);
645
- }
646
-
647
- // split src and options
648
- const { src, ...options } = valObj;
649
- paintableValue.src = src;
650
-
651
- // only forward valid paintable options
652
- const validOptionKeys = ['uScale', 'vScale', 'uOffset', 'vOffset'];
653
- const { validOptions, invalidKeys } = Object.entries(options).reduce(
654
- (accRes, [curKey, curValue]) => {
655
- const isValidKey = validOptionKeys.includes(curKey);
656
- if (isValidKey) {
657
- accRes.validOptions[curKey] = curValue;
658
- } else {
659
- accRes.invalidKeys.push(curKey);
660
- }
661
-
662
- return accRes;
663
- },
664
- { validOptions: {} as { [key: string]: any }, invalidKeys: [] as string[] }
665
- );
666
-
667
- if (invalidKeys.length) {
668
- console.warn('parsePaintable: invalid paintable options provided: ' + invalidKeys.toString());
669
- }
670
-
671
- paintableValue.options = validOptions;
672
- }
673
-
674
- return paintableValue;
675
- }
676
-
677
- /**
678
- * Parses a string with comma separated values to a list of strings.
679
- */
680
- public static parseCommaSeparatedList(value: ParameterValue): string[] {
681
- return value
682
- .toString()
683
- .split(',')
684
- .map(s => s.trim());
685
- }
686
- }
1
+ import { ViewerError, ViewerErrorIds } from './viewerError';
2
+ import { Color3 } from '@babylonjs/core/Maths/math.color';
3
+ import { Vector3 } from '@babylonjs/core/Maths/math.vector';
4
+ import { capitalize, get, isEmpty, isNumber, isString } from 'lodash-es';
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
+ * Constructor.
14
+ */
15
+ private constructor() {}
16
+
17
+ /**
18
+ * Mutates the visibility. Helper methods are {@link VariantParameterizable.show} and
19
+ * {@link VariantParameterizable.hide}. Getter and setter is {@link VariantParameterizable.visible}.
20
+ *
21
+ * Scopes:
22
+ * * {@link Element}
23
+ * * {@link Variant}
24
+ * * {@link ViewerLight} Available for all light types
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 VariantParameterizable.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 VariantParameterizable.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 VariantParameterizable.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 VariantParameterizable.position}.
121
+ *
122
+ * Scopes:
123
+ * * {@link Element}
124
+ * * {@link Variant}
125
+ * * {@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)
126
+ *
127
+ * @parser {@link parseVector}
128
+ */
129
+ public static readonly POSITION = 'position';
130
+
131
+ /**
132
+ * Mutates the rotation relative to its origin rotation. Getter and setter is {@link VariantParameterizable.rotation}.
133
+ *
134
+ * Scopes:
135
+ * * {@link Element}
136
+ * * {@link Variant}
137
+ *
138
+ * @parser {@link parseRotation}
139
+ */
140
+ public static readonly ROTATION = 'rotation';
141
+
142
+ /**
143
+ * Mutates the color.
144
+ *
145
+ * Scopes:
146
+ * * {@link Material} via {@link TagManager}
147
+ *
148
+ * @parser {@link parseColor}
149
+ */
150
+ public static readonly COLOR = 'color';
151
+
152
+ /**
153
+ * Mutates the metallic.
154
+ *
155
+ * Scopes:
156
+ * * {@link Material} via {@link TagManager}
157
+ *
158
+ * @parser {@link parseNumber}
159
+ */
160
+ public static readonly METALLIC = 'metallic';
161
+
162
+ /**
163
+ * Paintables can be used to let the client/browser draw graphics on a 3d model by mutating the texture of a
164
+ * material.\
165
+ * For detailed information have a look at the [paintables](./../pages/documentation/Paintables.html) page.
166
+ *
167
+ * Also see {@link parsePaintable} for detailed information on which values you can pass to the `paintable`
168
+ * parameter.
169
+ *
170
+ * Scopes:
171
+ * * {@link Material} via {@link TagManager}
172
+ *
173
+ * @parser {@link parsePaintable}
174
+ *
175
+ */
176
+ public static readonly PAINTABLE = 'paintable';
177
+
178
+ /**
179
+ * Mutates the roughness.
180
+ *
181
+ * Scopes:
182
+ * * {@link Material} via {@link TagManager}
183
+ *
184
+ * @parser {@link parseNumber}
185
+ */
186
+ public static readonly ROUGHNESS = 'roughness';
187
+
188
+ /**
189
+ * Mutates whether a shadow should be casted or not.
190
+ *
191
+ * Scopes:
192
+ * * {@link Element}
193
+ * * {@link Variant}
194
+ *
195
+ * @parser {@link parseBoolean}
196
+ */
197
+ public static readonly CAST_SHADOW = 'castShadow';
198
+
199
+ /**
200
+ * Mutates from which lights a shadow should be casted.
201
+ *
202
+ * Scopes:
203
+ * * {@link Element}
204
+ * * {@link Variant}
205
+ *
206
+ * @parser {@link parseCommaSeparatedList}
207
+ */
208
+ public static readonly CAST_SHADOW_FROM_LIGHTS = 'castShadow.fromLights';
209
+
210
+ /**
211
+ * Mutates whether to receive shadows or not.
212
+ *
213
+ * Scopes:
214
+ * * {@link Element}
215
+ * * {@link Variant}
216
+ *
217
+ * @parser {@link parseBoolean}
218
+ */
219
+ public static readonly RECEIVE_SHADOWS = 'receiveShadows';
220
+
221
+ /**
222
+ * Mutates the intensity of Lights.
223
+ *
224
+ * Scopes:
225
+ * * {@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)
226
+ *
227
+ * @parser {@link parseNumber}
228
+ */
229
+ public static readonly INTENSITY = 'intensity';
230
+
231
+ /**
232
+ * Mutates the direction of Lights.
233
+ *
234
+ * Scopes:
235
+ * * {@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)
236
+ *
237
+ * @parser {@link parseNumber}
238
+ */
239
+ public static readonly DIRECTION = 'direction';
240
+
241
+ /**
242
+ * Mutates the angle of Lights.
243
+ *
244
+ * Scopes:
245
+ * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#angle)
246
+ *
247
+ * @parser {@link parseNumber}
248
+ */
249
+ public static readonly ANGLE = 'angle';
250
+
251
+ /**
252
+ * Mutates the exponent of Lights.
253
+ *
254
+ * Scopes:
255
+ * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#exponent)
256
+ *
257
+ * @parser {@link parseNumber}
258
+ */
259
+ public static readonly EXPONENT = 'exponent';
260
+
261
+ /**
262
+ * Mutates the diffuse color of Lights.
263
+ *
264
+ * Scopes:
265
+ * * {@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)
266
+ *
267
+ * @parser {@link parseNumber}
268
+ */
269
+ public static readonly DIFFUSE = 'diffuse';
270
+
271
+ /**
272
+ * Mutates the specular color of Lights.
273
+ *
274
+ * Scopes:
275
+ * * {@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)
276
+ *
277
+ * @parser {@link parseNumber}
278
+ */
279
+ public static readonly SPECULAR = 'specular';
280
+
281
+ /**
282
+ * Sets the environment. See [BABYLON.Scene.environmentTexture](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#environmentTexture).
283
+ *
284
+ * Usually the URL to an `*.env` file.
285
+ *
286
+ * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
287
+ *
288
+ * Scopes:
289
+ * * {@link SceneManager}
290
+ *
291
+ * @parser string
292
+ */
293
+ public static readonly ENVIRONMENT = 'environment';
294
+
295
+ /**
296
+ * Sets [BABYLON.Scene.clearColor](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#clearColor)
297
+ *
298
+ * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
299
+ *
300
+ * Scopes:
301
+ * * {@link SceneManager}
302
+ *
303
+ * @parser {@link parseColor}
304
+ */
305
+ public static readonly ENVIRONMENT_COLOR = 'environment.color';
306
+
307
+ /**
308
+ * Rotates connected textures, i.e. IBL, reflection, background, ...
309
+ * Rotation angle in degree.
310
+ *
311
+ * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
312
+ *
313
+ * Scopes:
314
+ * * {@link SceneManager}
315
+ *
316
+ * @parser {@link parseNumber}
317
+ */
318
+ public static readonly ENVIRONMENT_ROTATION = 'environment.rotation';
319
+
320
+ /**
321
+ * Intensity of IBL. Defaults to 1, usually between 0 & 2.
322
+ *
323
+ * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
324
+ *
325
+ * Scopes:
326
+ * * {@link SceneManager}
327
+ *
328
+ * @parser {@link parseNumber}
329
+ */
330
+ public static readonly ENVIRONMENT_INTENSITY = 'environment.intensity';
331
+
332
+ /**
333
+ * Background texture on a [PhotoDome](https://doc.babylonjs.com/divingDeeper/environment/360PhotoDome).
334
+ * Just background, no IBL or reflection.
335
+ *
336
+ * Recommended format is `*.jpg`. HDR files are not supported as background but can be converted to `*.jpg` using
337
+ * tools like Photoshop, Gimp or various free online converters.
338
+ *
339
+ * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
340
+ *
341
+ * Scopes:
342
+ * * {@link SceneManager}
343
+ *
344
+ * @parser string
345
+ */
346
+ public static readonly ENVIRONMENT_BACKGROUND = 'environment.background';
347
+
348
+ /**
349
+ * If `true`, sets a `scene.environmentTexture` and creates a *BackgroundHelper* Node (via
350
+ * [scene.createDefaultEnvironment](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#createDefaultEnvironment))
351
+ * with two subnodes/meshes:
352
+ * - BackgroundPlane
353
+ * - BackgroundSkybox
354
+ *
355
+ * The value of this parameter is ignored if {@link ENVIRONMENT_BACKGROUND} is also set.
356
+ *
357
+ * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
358
+ *
359
+ * Scopes:
360
+ * * {@link SceneManager}
361
+ *
362
+ * @parser {@link parseBoolean}
363
+ */
364
+ public static readonly ENVIRONMENT_USEDEFAULT = 'environment.usedefault';
365
+
366
+ /**
367
+ * The {@link ParameterDeclarations} for all parameters in this class.
368
+ */
369
+ public static get declarations(): ParameterDeclarations {
370
+ return {
371
+ [Parameter.VISIBLE]: { type: 'boolean', parser: Parameter.parseBoolean },
372
+ [Parameter.SCALING]: { type: 'number', parser: Parameter.parseNumber },
373
+ [Parameter.POSITION]: { type: 'vector', parser: Parameter.parseVector },
374
+ [Parameter.ROTATION]: { type: 'vector', parser: Parameter.parseVector },
375
+ [Parameter.HIGHLIGHTED]: { type: 'boolean', parser: Parameter.parseBoolean },
376
+ [Parameter.MATERIAL]: { type: 'string' },
377
+ [Parameter.MATERIAL_COLOR]: { type: 'color', parser: Parameter.parseColor },
378
+ [Parameter.MATERIAL_METALLNESS]: { type: 'number', parser: Parameter.parseNumber },
379
+ [Parameter.MATERIAL_ROUGHNESS]: { type: 'number', parser: Parameter.parseNumber },
380
+ [Parameter.HIGHLIGHT_ENABLED]: { type: 'boolean', parser: Parameter.parseBoolean },
381
+ [Parameter.HIGHLIGHT_COLOR]: { type: 'color', parser: Parameter.parseColor },
382
+ [Parameter.COLOR]: { type: 'color', parser: Parameter.parseColor },
383
+ [Parameter.METALLIC]: { type: 'number', parser: Parameter.parseNumber },
384
+ [Parameter.ROUGHNESS]: { type: 'number', parser: Parameter.parseNumber },
385
+ [Parameter.PAINTABLE]: { type: 'paintable', parser: Parameter.parsePaintable },
386
+ [Parameter.HIGHLIGHTED]: { type: 'boolean', parser: Parameter.parseBoolean },
387
+ [Parameter.CAST_SHADOW]: { type: 'boolean', parser: Parameter.parseBoolean },
388
+ [Parameter.CAST_SHADOW_FROM_LIGHTS]: { type: 'csl', parser: Parameter.parseCommaSeparatedList },
389
+ [Parameter.RECEIVE_SHADOWS]: { type: 'boolean', parser: Parameter.parseBoolean },
390
+ [Parameter.INTENSITY]: { type: 'number', parser: Parameter.parseNumber },
391
+ [Parameter.DIRECTION]: { type: 'vector', parser: Parameter.parseVector },
392
+ [Parameter.ANGLE]: { type: 'number', parser: Parameter.parseNumber },
393
+ [Parameter.EXPONENT]: { type: 'number', parser: Parameter.parseNumber },
394
+ [Parameter.DIFFUSE]: { type: 'color', parser: Parameter.parseColor },
395
+ [Parameter.SPECULAR]: { type: 'color', parser: Parameter.parseColor },
396
+ [Parameter.ENVIRONMENT]: { type: 'string' },
397
+ [Parameter.ENVIRONMENT_COLOR]: { type: 'color', parser: Parameter.parseColor },
398
+ [Parameter.ENVIRONMENT_ROTATION]: { type: 'number', parser: Parameter.parseNumber },
399
+ [Parameter.ENVIRONMENT_INTENSITY]: { type: 'number', parser: Parameter.parseNumber },
400
+ [Parameter.ENVIRONMENT_BACKGROUND]: { type: 'string' },
401
+ [Parameter.ENVIRONMENT_USEDEFAULT]: { type: 'boolean', parser: Parameter.parseBoolean },
402
+ };
403
+ }
404
+
405
+ /**
406
+ * The default {@link ParameterValue}s returned as {@link ParameterBag} for a set of parameters in this class.
407
+ */
408
+ public static get defaultValues(): ParameterBag {
409
+ return {
410
+ [Parameter.SCALING]: '(1, 1, 1)',
411
+ [Parameter.POSITION]: '(0, 0, 0)',
412
+ [Parameter.ROTATION]: '(0, 0, 0)',
413
+ };
414
+ }
415
+
416
+ /**
417
+ * Gets the default {@link ParameterValue} for a given {@link Parameter} declared in this class.
418
+ */
419
+ public static getDefaultValue(parameter: string): ParameterValue {
420
+ return Parameter.defaultValues[parameter];
421
+ }
422
+
423
+ /**
424
+ * All parameters defined in this class.
425
+ */
426
+ public static get all() {
427
+ const all: string[] = [];
428
+ for (const parameter in Parameter) {
429
+ const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
430
+ if (parameter.toUpperCase() === parameter && property && isString(property.value)) {
431
+ all.push(property.value);
432
+ }
433
+ }
434
+ return all;
435
+ }
436
+
437
+ /**
438
+ * Asserts whether given parameter is declared and valid.
439
+ */
440
+ public static assertParameter(parameterDeclaration: ParameterDeclarations, parameter: string, value: ParameterValue) {
441
+ if (!(parameter in parameterDeclaration)) {
442
+ // This is a valid case since we are not able to check parameters that are not declared.
443
+ // We just ignore parameters that are not declared.
444
+ return;
445
+ }
446
+ const declaration = parameterDeclaration[parameter];
447
+ const errorPrefix = `Invalid value for parameter "${parameter}" of type "${declaration.type}" given:`;
448
+ if (declaration.parser) {
449
+ try {
450
+ declaration.parser(value);
451
+ } catch (e: any) {
452
+ throw new ViewerError({
453
+ id: ViewerErrorIds.InvalidParameterValue,
454
+ message: `${errorPrefix}\n${e.message}.\nGiven value: ${value}`,
455
+ });
456
+ }
457
+ }
458
+ switch (declaration.type) {
459
+ case 'select':
460
+ if (!declaration.options) {
461
+ throw new ViewerError({
462
+ id: ViewerErrorIds.UnknownParameterOption,
463
+ message: `No options defined for parameter declaration "${parameter}" of type "${declaration.type}".`,
464
+ });
465
+ }
466
+ if (declaration.options.indexOf(value) === -1) {
467
+ throw Error(
468
+ `${errorPrefix}\nValid values are: "${declaration.options.join('", "')}".\nGiven value: ${value}`
469
+ );
470
+ }
471
+ break;
472
+ }
473
+ }
474
+
475
+ /**
476
+ * Parses given {@link ParameterBag} with given {@link ParameterDeclarations}.
477
+ */
478
+ public static parseFromDeclarations(
479
+ declarations: ParameterDeclarations,
480
+ parameterBag: ParameterBag
481
+ ): ParsedParameterBag {
482
+ const parameters: ParsedParameterBag = {};
483
+ for (const parameter in parameterBag) {
484
+ const value = get(parameterBag, parameter);
485
+ parameters[parameter] = value;
486
+ const declaration: ParameterDeclaration = declarations[parameter];
487
+ if (declaration) {
488
+ if (!isEmpty(value) && declaration.parser) {
489
+ parameters[parameter] = declaration.parser(value);
490
+ }
491
+ }
492
+ }
493
+ return parameters;
494
+ }
495
+
496
+ /**
497
+ * Parses a string of format `'(x,y,z)'` to a `Vector3`.
498
+ */
499
+ public static parseVector(value: ParameterValue): Vector3 {
500
+ if (!isString(value)) {
501
+ throw new Error(`Unable to convert "${value}" into a Vector: not a string.`);
502
+ }
503
+ let cleanedValue = value.split(' ').join('');
504
+ if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
505
+ cleanedValue = cleanedValue.substring(1, cleanedValue.length - 1);
506
+ const [x, y, z] = cleanedValue.split(',').map(value => parseFloat(value));
507
+ return new Vector3(x, y, z);
508
+ } else {
509
+ throw new Error(`Unable to parse "${value}" to a Vector: expected "(x,y,z)".`);
510
+ }
511
+ }
512
+
513
+ /**
514
+ * Stringifies a Vector3 to format `(x,y,z)`.
515
+ */
516
+ public static stringifyVector(value: Vector3): string {
517
+ return `(${value.x},${value.y},${value.z})`;
518
+ }
519
+
520
+ /**
521
+ * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
522
+ */
523
+ public static parseRotation(value: ParameterValue): Vector3 {
524
+ const rotation = Parameter.parseVector(value);
525
+ const deg2rad = function (deg: number) {
526
+ return (deg * Math.PI) / 180;
527
+ };
528
+ return rotation.set(deg2rad(rotation.x), deg2rad(rotation.y), deg2rad(rotation.z));
529
+ }
530
+
531
+ /**
532
+ * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
533
+ */
534
+ public static parseScaling(value: ParameterValue): Vector3 {
535
+ let scaling = new Vector3();
536
+ if (isString(value)) {
537
+ const cleanedFactor = value.split(' ').join('');
538
+ if (cleanedFactor.startsWith('(') && cleanedFactor.endsWith(')')) {
539
+ scaling = Parameter.parseVector(cleanedFactor);
540
+ } else {
541
+ const _factor = parseFloat(value);
542
+ scaling = new Vector3(_factor, _factor, _factor);
543
+ }
544
+ } else if (isNumber(value)) {
545
+ scaling = new Vector3(value, value, value);
546
+ } else {
547
+ throw new Error(`Unable to convert "${value}" to a Vector: expected "(x,y,z)".`);
548
+ }
549
+ return scaling;
550
+ }
551
+
552
+ /**
553
+ * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
554
+ */
555
+ public static parseColor(value: ParameterValue): Color3 {
556
+ const cleanedValue = value.toString().split(' ').join('');
557
+ if (cleanedValue.startsWith('#')) {
558
+ return Color3.FromHexString(value.toString());
559
+ }
560
+ if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
561
+ const rgb = cleanedValue.substring(1, cleanedValue.length - 1);
562
+ const [r, g, b] = rgb.split(',').map(value => parseFloat(value));
563
+ return Color3.FromInts(r, g, b);
564
+ }
565
+ const humanReadable = capitalize(cleanedValue);
566
+ // disable lint for this rule as there is no smoother option for checking static class functions (eg Color.Red())
567
+ // eslint-disable-next-line no-prototype-builtins
568
+ if (Color3.hasOwnProperty(humanReadable)) {
569
+ // @ts-ignore same as above
570
+ return Color3[humanReadable]();
571
+ }
572
+ throw new Error(
573
+ `Unable to parse "${value}" to a Color: expected "#rrggbb", "(r,g,b)" or any human readable property implemented in Color3.`
574
+ );
575
+ }
576
+
577
+ /**
578
+ * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or
579
+ * `undefined`.
580
+ */
581
+ public static parseBoolean(value: ParameterValue): boolean {
582
+ if (value.toString() === 'true' || value.toString() === '1') {
583
+ return true;
584
+ } else if (value.toString() === 'false' || value.toString() === '0') {
585
+ return false;
586
+ }
587
+ throw new Error(`Unable to parse "${value}" to a boolean.`);
588
+ }
589
+
590
+ /**
591
+ * Parses a number `string` to a `number`.
592
+ */
593
+ public static parseNumber(value: ParameterValue): number {
594
+ return parseFloat(value.toString());
595
+ }
596
+
597
+ /**
598
+ * Parses string defintion of a paintable into a paintable object.\
599
+ * Here are some examples:
600
+ * ```ts
601
+ * // Default definition as JSON object:
602
+ * '{ "src": "https://path.to/image.jpg", "uScale": 0.5 }'
603
+ *
604
+ * // Short hand definition, only contains source string:
605
+ * 'https://path.to/image.jpg'
606
+ *
607
+ * // Full content, paintable texture is flipped in both directions
608
+ * '{ "src": "https://path.to/image.jpg", "uScale": -1, "vScale": -1, "uOffset": 0, "vOffset": 0 }'
609
+ *
610
+ * // SVG content can be used directly:
611
+ * '<svg>...</svg>'
612
+ *
613
+ * // SVG in src property works as well:
614
+ * '{ "src": "<svg>...</svg>", "uScale": 0.5 }'
615
+ * ```
616
+ */
617
+ public static parsePaintable(value: ParameterValue): PaintableValue {
618
+ if (!isString(value)) {
619
+ throw new Error(`Not a string.`);
620
+ }
621
+
622
+ const paintableValue: PaintableValue = { src: '' };
623
+ let valObj: { [key: string]: any } | null = null;
624
+
625
+ try {
626
+ valObj = JSON.parse(value);
627
+ } catch {
628
+ // use string directly
629
+ paintableValue.src = value;
630
+
631
+ if (value.startsWith('{')) {
632
+ // seems like the user tried to use a JSON string, as the input starts with {
633
+ throw new Error(`Not a valid JSON string.`);
634
+ }
635
+ }
636
+
637
+ if (valObj) {
638
+ // input string is JSON, src attribute is required
639
+ if (!valObj.src) {
640
+ throw new Error(`Property "src" is missing.`);
641
+ }
642
+
643
+ if (!isString(valObj.src)) {
644
+ throw new Error(`Property "src" is not a string.`);
645
+ }
646
+
647
+ // split src and options
648
+ const { src, ...options } = valObj;
649
+ paintableValue.src = src;
650
+
651
+ // only forward valid paintable options
652
+ const validOptionKeys = ['uScale', 'vScale', 'uOffset', 'vOffset'];
653
+ const { validOptions, invalidKeys } = Object.entries(options).reduce(
654
+ (accRes, [curKey, curValue]) => {
655
+ const isValidKey = validOptionKeys.includes(curKey);
656
+ if (isValidKey) {
657
+ accRes.validOptions[curKey] = curValue;
658
+ } else {
659
+ accRes.invalidKeys.push(curKey);
660
+ }
661
+
662
+ return accRes;
663
+ },
664
+ { validOptions: {} as { [key: string]: any }, invalidKeys: [] as string[] }
665
+ );
666
+
667
+ if (invalidKeys.length) {
668
+ console.warn('parsePaintable: invalid paintable options provided: ' + invalidKeys.toString());
669
+ }
670
+
671
+ paintableValue.options = validOptions;
672
+ }
673
+
674
+ return paintableValue;
675
+ }
676
+
677
+ /**
678
+ * Parses a string with comma separated values to a list of strings.
679
+ */
680
+ public static parseCommaSeparatedList(value: ParameterValue): string[] {
681
+ return value
682
+ .toString()
683
+ .split(',')
684
+ .map(s => s.trim());
685
+ }
686
+ }