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

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