@combeenation/3d-viewer 12.4.1 → 12.4.3

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