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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +114 -112
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  6. package/dist/lib-cjs/api/classes/element.d.ts +130 -125
  7. package/dist/lib-cjs/api/classes/element.js +743 -682
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  11. package/dist/lib-cjs/api/classes/event.d.ts +326 -312
  12. package/dist/lib-cjs/api/classes/event.js +371 -357
  13. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  14. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  15. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  16. package/dist/lib-cjs/api/classes/parameter.d.ts +259 -165
  17. package/dist/lib-cjs/api/classes/parameter.js +387 -267
  18. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  20. package/dist/lib-cjs/api/classes/parameterObservable.js +101 -126
  21. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  22. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  23. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  24. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  25. package/dist/lib-cjs/api/classes/placementAnimation.js +149 -138
  26. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  27. package/dist/lib-cjs/api/classes/variant.d.ts +234 -190
  28. package/dist/lib-cjs/api/classes/variant.js +1147 -873
  29. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  30. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -41
  31. package/dist/lib-cjs/api/classes/variantInstance.js +108 -98
  32. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  33. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  34. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  35. package/dist/lib-cjs/api/classes/viewer.d.ts +131 -128
  36. package/dist/lib-cjs/api/classes/viewer.js +560 -486
  37. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  38. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -65
  39. package/dist/lib-cjs/api/classes/viewerLight.js +389 -322
  40. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  41. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  42. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  43. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  44. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  45. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +10 -6
  46. package/dist/lib-cjs/api/internal/sceneSetup.js +231 -227
  47. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  49. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  50. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  51. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  53. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  54. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  55. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  56. package/dist/lib-cjs/api/util/babylonHelper.d.ts +175 -125
  57. package/dist/lib-cjs/api/util/babylonHelper.js +520 -368
  58. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  59. package/dist/lib-cjs/api/util/globalTypes.d.ts +333 -279
  60. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  61. package/dist/lib-cjs/api/util/resourceHelper.d.ts +53 -51
  62. package/dist/lib-cjs/api/util/resourceHelper.js +240 -243
  63. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  64. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  65. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  66. package/dist/lib-cjs/buildinfo.json +3 -3
  67. package/dist/lib-cjs/index.d.ts +48 -46
  68. package/dist/lib-cjs/index.js +86 -82
  69. package/dist/lib-cjs/index.js.map +1 -1
  70. package/package.json +83 -83
  71. package/src/api/classes/animationInterface.ts +11 -11
  72. package/src/api/classes/dottedPath.ts +189 -189
  73. package/src/api/classes/element.ts +644 -617
  74. package/src/api/classes/event.ts +370 -355
  75. package/src/api/classes/eventBroadcaster.ts +54 -54
  76. package/src/api/classes/parameter.ts +408 -277
  77. package/src/api/classes/parameterObservable.ts +99 -121
  78. package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +89 -78
  79. package/src/api/classes/placementAnimation.ts +143 -133
  80. package/src/api/classes/variant.ts +817 -670
  81. package/src/api/classes/variantInstance.ts +88 -81
  82. package/src/api/classes/variantParameterizable.ts +73 -0
  83. package/src/api/classes/viewer.ts +478 -421
  84. package/src/api/classes/viewerLight.ts +330 -0
  85. package/src/api/internal/debugViewer.ts +81 -81
  86. package/src/api/internal/lensRendering.ts +10 -10
  87. package/src/api/internal/sceneSetup.ts +194 -204
  88. package/src/api/manager/animationManager.ts +116 -116
  89. package/src/api/manager/sceneManager.ts +105 -105
  90. package/src/api/manager/variantInstanceManager.ts +236 -236
  91. package/src/api/store/specStorage.ts +53 -53
  92. package/src/api/util/babylonHelper.ts +553 -392
  93. package/src/api/util/globalTypes.ts +380 -319
  94. package/src/api/util/resourceHelper.ts +184 -187
  95. package/src/api/util/stringHelper.ts +26 -0
  96. package/src/buildinfo.json +2 -2
  97. package/src/commonjs.tsconfig.json +13 -13
  98. package/src/declaration.tsconfig.json +10 -10
  99. package/src/dev.ts +42 -46
  100. package/src/es6.tsconfig.json +13 -13
  101. package/src/index.ts +91 -87
  102. package/src/pagesconfig.json +61 -57
  103. package/src/tsconfig.json +43 -43
  104. package/src/tsconfig.types.json +9 -9
  105. package/src/types.d.ts +4 -4
  106. package/dist/webpack-stats.json +0 -0
@@ -1,683 +1,744 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Element = void 0;
4
- var tslib_1 = require("tslib");
5
- var highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
6
- var material_1 = require("@babylonjs/core/Materials/material");
7
- var standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
8
- var dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
9
- var math_axis_1 = require("@babylonjs/core/Maths/math.axis");
10
- var math_color_1 = require("@babylonjs/core/Maths/math.color");
11
- var abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
12
- var instancedMesh_1 = require("@babylonjs/core/Meshes/instancedMesh");
13
- var mesh_1 = require("@babylonjs/core/Meshes/mesh");
14
- var transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
15
- var lodash_es_1 = require("lodash-es");
16
- var babylonHelper_1 = require("../util/babylonHelper");
17
- var resourceHelper_1 = require("../util/resourceHelper");
18
- var dottedPath_1 = require("./dottedPath");
19
- var elementParameterizable_1 = require("./elementParameterizable");
20
- var event_1 = require("./event");
21
- var parameter_1 = require("./parameter");
22
- /**
23
- * An {@link Element} of a {@link Variant}. Acts as a container for diverse definitions. Lives only in the context of a
24
- * {@link Variant}.
25
- *
26
- * When used in typings, refer to via its alias {@link VariantElement} to prevent name clashes with the web APIs
27
- * [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) class
28
- */
29
- var Element = /** @class */ (function (_super) {
30
- tslib_1.__extends(Element, _super);
31
- /**
32
- * Constructor.
33
- */
34
- function Element(variant, name) {
35
- var _a;
36
- var _this = _super.call(this) || this;
37
- _this.variant = variant;
38
- _this.name = name;
39
- _this._dottedNodes = new Map();
40
- _this._parameterObservers = new Map();
41
- _this.nodes = [];
42
- if ((_a = process.env.NODE_ENV) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('dev')) {
43
- _this.assertPathDefinitions();
44
- }
45
- var nodes = _this.variant.inheritedNodes.map(function (node) { return babylonHelper_1.cloneTransformNode(node, _this.filterNode.bind(_this)); });
46
- _this.nodes = nodes.filter(function (node) { return !!node; });
47
- _this._dottedNodes = babylonHelper_1.mapToDottedNodes(_this.nodes, function (node) { return node instanceof transformNode_1.TransformNode; });
48
- _this.addParameterObservers();
49
- return _this;
50
- }
51
- Object.defineProperty(Element.prototype, "dottedPath", {
52
- /**
53
- * The {@link DottedPath} in the built tree of {@link Element}s.
54
- * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
55
- */
56
- get: function () {
57
- return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
58
- },
59
- enumerable: false,
60
- configurable: true
61
- });
62
- Object.defineProperty(Element.prototype, "id", {
63
- /**
64
- * The id representing a {@link DottedPath}.
65
- */
66
- get: function () {
67
- var dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
68
- dottedPath.shiftPart(); // remove root
69
- return dottedPath.path;
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
- Object.defineProperty(Element.prototype, "definition", {
75
- /**
76
- * The {@link ElementDefinition} of the {@link Element}.
77
- */
78
- get: function () {
79
- var definition = this.variant.structureJson.elements[this.name];
80
- if (lodash_es_1.isArray(definition)) {
81
- return {
82
- paths: {
83
- include: definition
84
- }
85
- };
86
- }
87
- return definition;
88
- },
89
- enumerable: false,
90
- configurable: true
91
- });
92
- Object.defineProperty(Element.prototype, "pathDefinitions", {
93
- /**
94
- * The {@link PathDefinitions} of the {@link Element}.
95
- */
96
- get: function () {
97
- return this.definition.paths;
98
- },
99
- enumerable: false,
100
- configurable: true
101
- });
102
- Object.defineProperty(Element.prototype, "traceableDefinitions", {
103
- /**
104
- * The {@link TraceableDefinitions} of the {@link Element}.
105
- */
106
- get: function () {
107
- return this.definition.traceables || {};
108
- },
109
- enumerable: false,
110
- configurable: true
111
- });
112
- Object.defineProperty(Element.prototype, "paintableDefinitions", {
113
- /**
114
- * The {@link PaintableDefinition} of the {@link Element}.
115
- */
116
- get: function () {
117
- return this.definition.paintables || {};
118
- },
119
- enumerable: false,
120
- configurable: true
121
- });
122
- Object.defineProperty(Element.prototype, "inheritedParameters", {
123
- /**
124
- * The inherited {@link ParameterBag}.
125
- * Merges the {@link Variant}'s parameters and those from the {@link Element}.
126
- */
127
- get: function () {
128
- return lodash_es_1.merge({}, this.variant.inheritedParameters, this.parameters);
129
- },
130
- enumerable: false,
131
- configurable: true
132
- });
133
- Object.defineProperty(Element.prototype, "highlightLayer", {
134
- get: function () {
135
- return this._highlightLayer;
136
- },
137
- /**
138
- * @protected
139
- */
140
- set: function (layer) {
141
- this._highlightLayer = layer;
142
- },
143
- enumerable: false,
144
- configurable: true
145
- });
146
- /**
147
- * Destroys this {@link Element} and dispose all nodes.
148
- */
149
- Element.prototype.destroy = function () {
150
- this.nodes.forEach(function (node) {
151
- node.dispose();
152
- });
153
- return this;
154
- };
155
- /**
156
- * Gets a node by its {@link DottedPath}.
157
- */
158
- Element.prototype.getNode = function (dottedPath) {
159
- var _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
160
- var keys = Array.from(this._dottedNodes.keys()).map(function (dp) { return dp.path; });
161
- var values = Array.from(this._dottedNodes.values());
162
- var node = values[keys.indexOf(_dottedPath.path)];
163
- if (!node) {
164
- throw new Error("Node with path \"" + _dottedPath.path + "\" does not exist for element \"" + this.id + "\".");
165
- }
166
- return node;
167
- };
168
- /**
169
- * Gets a mesh by its {@link DottedPath}.
170
- */
171
- Element.prototype.getMesh = function (dottedPath) {
172
- return tslib_1.__awaiter(this, void 0, void 0, function () {
173
- var node;
174
- return tslib_1.__generator(this, function (_a) {
175
- switch (_a.label) {
176
- case 0: return [4 /*yield*/, this.getNode(dottedPath)];
177
- case 1:
178
- node = _a.sent();
179
- if (node instanceof mesh_1.Mesh) {
180
- return [2 /*return*/, node];
181
- }
182
- return [2 /*return*/, null];
183
- }
184
- });
185
- });
186
- };
187
- /**
188
- * Gets a {@link PaintableDefinition} by its name.
189
- */
190
- Element.prototype.getPaintableDefinition = function (name) {
191
- if (!this.paintableDefinitions || !this.paintableDefinitions[name]) {
192
- throw new Error("No paintable \"" + name + "\" defined for element \"" + this.id + "\".");
193
- }
194
- return this.paintableDefinitions[name];
195
- };
196
- /**
197
- * Gets a {@link TraceableDefinition} by its name.
198
- */
199
- Element.prototype.getTraceableDefinition = function (name) {
200
- if (!this.traceableDefinitions || !this.traceableDefinitions[name]) {
201
- throw new Error("No traceable \"" + name + "\" defined to add observer in element \"" + this.id + "\".");
202
- }
203
- return this.traceableDefinitions[name];
204
- };
205
- /**
206
- * Gets the paintable Node by its name.
207
- */
208
- Element.prototype.getPaintableNode = function (name) {
209
- return this.getNode(this.getPaintableDefinition(name).path);
210
- };
211
- /**
212
- * Gets the traceable Node by its name.
213
- */
214
- Element.prototype.getTraceableNode = function (name) {
215
- return this.getNode(this.getTraceableDefinition(name).path);
216
- };
217
- /**
218
- * Places the given {@link ParameterBag} in the {@link Element}'s parameters, replaces all patterns in the
219
- * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
220
- *
221
- * @emit {@link Event.ELEMENT_PARAMETER_COMMITTED}
222
- */
223
- Element.prototype.commitParameters = function (parameters) {
224
- return tslib_1.__awaiter(this, void 0, void 0, function () {
225
- var oldParameters, observerPromises, _loop_1, this_1, parameter;
226
- var _this = this;
227
- return tslib_1.__generator(this, function (_a) {
228
- switch (_a.label) {
229
- case 0:
230
- if (!parameters) {
231
- parameters = {};
232
- }
233
- oldParameters = lodash_es_1.cloneDeep(this.parameters);
234
- lodash_es_1.merge(this.parameters, parameters);
235
- observerPromises = [];
236
- _loop_1 = function (parameter) {
237
- var oldParameterValue = oldParameters[parameter];
238
- var newParameterValue = this_1.parameters[parameter];
239
- this_1.variant.assertParameter(this_1.variant.inheritedParameterDeclaration, parameter, newParameterValue);
240
- if (oldParameterValue === newParameterValue) {
241
- return "continue";
242
- }
243
- // parameter changed
244
- var parameterObservers = resourceHelper_1.mergeMaps(this_1._parameterObservers, this_1.parameterObservers);
245
- if (parameterObservers.has(parameter)) {
246
- var observers = parameterObservers.get(parameter);
247
- observerPromises = lodash_es_1.concat(observerPromises, observers.map(function (observer) {
248
- var observerResult = observer(_this, oldParameterValue, newParameterValue);
249
- return Promise.resolve(observerResult).then(function () {
250
- _this.broadcastEvent(event_1.Event.ELEMENT_PARAMETER_COMMITTED, _this, parameter, oldParameterValue, newParameterValue);
251
- });
252
- }));
253
- }
254
- };
255
- this_1 = this;
256
- for (parameter in this.parameters) {
257
- _loop_1(parameter);
258
- }
259
- return [4 /*yield*/, Promise.all(observerPromises)];
260
- case 1:
261
- _a.sent();
262
- return [2 /*return*/, this];
263
- }
264
- });
265
- });
266
- };
267
- /**
268
- * Adds an observer function for camera matrix changes.
269
- * The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
270
- */
271
- Element.prototype.addTraceableObserver = function (traceable, observer, payload) {
272
- var _this = this;
273
- if (payload && !(payload instanceof HTMLElement)) {
274
- throw new Error("Payload for camera observer must be an instance of \"HTMLElement\" in element \"" + this.id + "\".");
275
- }
276
- if (!this.traceableDefinitions || !this.traceableDefinitions[traceable]) {
277
- throw new Error("No traceable \"" + traceable + "\" defined to add observer in element \"" + this.id + "\".");
278
- }
279
- var node = this.getTraceableNode(traceable);
280
- if (!(node instanceof abstractMesh_1.AbstractMesh)) {
281
- throw new Error("The path must be an instance of \"AbstractMesh\" for camera observer in element \"" + this.id + "\".");
282
- }
283
- this.variant.viewer.sceneManager.activeCamera.onViewMatrixChangedObservable.add(function (eventData, eventState) {
284
- var position = babylonHelper_1.getClientRectFromMesh(node, _this.variant.viewer.scene, _this.variant.viewer.canvas);
285
- if (payload) {
286
- payload.style.top = position.top + "px";
287
- payload.style.left = position.left + "px";
288
- }
289
- observer(node, position);
290
- });
291
- return this;
292
- };
293
- /**
294
- * Draws a `ImageBitmap` or `OffscreenCanvas` onto a `paintable` defined via {@link PaintableDefinition}.
295
- */
296
- Element.prototype.drawPaintable = function (paintable, imageSource) {
297
- // node and material checks and preperation
298
- var node = this.getPaintableNode(paintable);
299
- if (!(node instanceof abstractMesh_1.AbstractMesh)) {
300
- throw new Error("The path must be an instance of \"AbstractMesh\" for paintable \"" + paintable + "\" " +
301
- ("in element \"" + this.id + "\"."));
302
- }
303
- if (node.material && !lodash_es_1.get(node.metadata, 'dirty.material')) {
304
- babylonHelper_1.cloneTransformNodeMaterial(node);
305
- }
306
- if (!node.material) {
307
- node.material = new standardMaterial_1.StandardMaterial(this.id + "." + paintable + ".material", this.variant.viewer.scene);
308
- }
309
- node.material.transparencyMode = material_1.Material.MATERIAL_ALPHATESTANDBLEND;
310
- if (!lodash_es_1.get(node.metadata, 'dirty.material.texture')) {
311
- // inject initial value and mark as dirty
312
- babylonHelper_1.injectTransformNodeMetadata(node, { dirty: { material: { texture: true } } });
313
- }
314
- // consider width and height of the paintable
315
- var widthAndHeight = {
316
- width: imageSource.width,
317
- height: imageSource.height
318
- };
319
- var paintableDefinition = this.getPaintableDefinition(paintable);
320
- if (lodash_es_1.isNumber(paintableDefinition.textureOptions)) {
321
- widthAndHeight.width = paintableDefinition.textureOptions;
322
- widthAndHeight.height = paintableDefinition.textureOptions;
323
- }
324
- else if (lodash_es_1.isPlainObject(paintableDefinition.textureOptions)) {
325
- widthAndHeight.width = paintableDefinition.textureOptions.width;
326
- widthAndHeight.height = paintableDefinition.textureOptions.height;
327
- }
328
- // create dynamic texture on which the image can be drawn
329
- var texture = new dynamicTexture_1.DynamicTexture(this.id + "." + paintable + ".texture", widthAndHeight, this.variant.viewer.scene, false);
330
- // draw image on texture
331
- var ctx = texture.getContext();
332
- ctx.drawImage(imageSource, 0, 0);
333
- texture.update(false);
334
- // finally apply the texture on the desired node material
335
- babylonHelper_1.setMaterialTexture(node, texture, false);
336
- return this;
337
- };
338
- /**
339
- * Draws a SVG string onto a `paintable` defined via {@link PaintableDefinition}.
340
- */
341
- Element.prototype.drawPaintableFromSvg = function (paintable, svgSource) {
342
- return tslib_1.__awaiter(this, void 0, void 0, function () {
343
- var image;
344
- return tslib_1.__generator(this, function (_a) {
345
- switch (_a.label) {
346
- case 0: return [4 /*yield*/, resourceHelper_1.createImageFromSvg(svgSource)];
347
- case 1:
348
- image = _a.sent();
349
- return [2 /*return*/, this.drawPaintable(paintable, image)];
350
- }
351
- });
352
- });
353
- };
354
- /**
355
- * Draws an Image from source (URL/URI) onto a `paintable` defined via {@link PaintableDefinition}.
356
- */
357
- Element.prototype.drawPaintableFromImgSrc = function (paintable, imgSource) {
358
- return tslib_1.__awaiter(this, void 0, void 0, function () {
359
- var image;
360
- return tslib_1.__generator(this, function (_a) {
361
- switch (_a.label) {
362
- case 0: return [4 /*yield*/, resourceHelper_1.createImageFromImgSrc(imgSource)];
363
- case 1:
364
- image = _a.sent();
365
- return [2 /*return*/, this.drawPaintable(paintable, image)];
366
- }
367
- });
368
- });
369
- };
370
- /**
371
- * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
372
- */
373
- Element.prototype.addParameterObservers = function () {
374
- var _this = this;
375
- this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
376
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
377
- var visible;
378
- return tslib_1.__generator(this, function (_a) {
379
- try {
380
- visible = parameter_1.Parameter.parseBoolean(newValue);
381
- }
382
- catch (e) {
383
- return [2 /*return*/];
384
- }
385
- if (visible === true) {
386
- element.nodes.forEach(function (node) {
387
- babylonHelper_1.injectTransformNodeMetadata(node, { visibility: node.isEnabled() });
388
- babylonHelper_1.activateTransformNode(node);
389
- });
390
- }
391
- else if (visible === false) {
392
- element.nodes.forEach(function (node) {
393
- babylonHelper_1.injectTransformNodeMetadata(node, { visibility: node.isEnabled() });
394
- babylonHelper_1.deactivateTransformNode(node);
395
- });
396
- }
397
- return [2 /*return*/];
398
- });
399
- }); }
400
- ]);
401
- this._parameterObservers.set(parameter_1.Parameter.SCALING, [
402
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
403
- return tslib_1.__generator(this, function (_a) {
404
- // we have to deal just with root nodes here due to relative impacts in a node tree
405
- element.nodes.forEach(function (node) { return node.scaling = parameter_1.Parameter.parseScaling(newValue); });
406
- return [2 /*return*/];
407
- });
408
- }); }
409
- ]);
410
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL, [
411
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
412
- var material;
413
- return tslib_1.__generator(this, function (_a) {
414
- material = element.variant.getMaterial(newValue.toString());
415
- element.nodes.forEach(function (node) {
416
- babylonHelper_1.assertTransformNode(node, function (node) {
417
- if (node instanceof instancedMesh_1.InstancedMesh) {
418
- throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL + "\" " +
419
- "of an InstancedMesh is not supported. " +
420
- ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
421
- }
422
- });
423
- babylonHelper_1.setMaterial(node, material);
424
- });
425
- return [2 /*return*/];
426
- });
427
- }); }
428
- ]);
429
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_COLOR, [
430
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
431
- var color;
432
- return tslib_1.__generator(this, function (_a) {
433
- color = parameter_1.Parameter.parseColor(newValue);
434
- element.nodes.forEach(function (node) {
435
- babylonHelper_1.assertTransformNode(node, function (node) {
436
- if (node instanceof instancedMesh_1.InstancedMesh) {
437
- throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL_COLOR + "\" " +
438
- "of an InstancedMesh is not supported. " +
439
- ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
440
- }
441
- });
442
- if (!lodash_es_1.get(node.metadata, 'dirty.material')) {
443
- babylonHelper_1.cloneTransformNodeMaterial(node);
444
- }
445
- if (!lodash_es_1.get(node.metadata, 'dirty.material.color')) {
446
- // inject initial value and mark as dirty
447
- babylonHelper_1.injectTransformNodeMetadata(node, { dirty: { material: { color: oldValue } } });
448
- }
449
- babylonHelper_1.setMaterialColor(node, color);
450
- });
451
- return [2 /*return*/];
452
- });
453
- }); }
454
- ]);
455
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_METALLNESS, [
456
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
457
- var metallness;
458
- return tslib_1.__generator(this, function (_a) {
459
- metallness = parameter_1.Parameter.parseNumber(newValue);
460
- element.nodes.forEach(function (node) {
461
- babylonHelper_1.assertTransformNode(node, function (node) {
462
- if (node instanceof instancedMesh_1.InstancedMesh) {
463
- throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL_METALLNESS + "\" " +
464
- "of an InstancedMesh is not supported. " +
465
- ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
466
- }
467
- });
468
- if (!lodash_es_1.get(node.metadata, 'dirty.material')) {
469
- babylonHelper_1.cloneTransformNodeMaterial(node);
470
- }
471
- if (!lodash_es_1.get(node.metadata, 'dirty.material.metallness')) {
472
- // inject initial value and mark as dirty
473
- babylonHelper_1.injectTransformNodeMetadata(node, { dirty: { material: { metallness: oldValue } } });
474
- }
475
- babylonHelper_1.setMaterialMetallness(node, metallness);
476
- });
477
- return [2 /*return*/];
478
- });
479
- }); }
480
- ]);
481
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_ROUGHNESS, [
482
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
483
- var roughness;
484
- return tslib_1.__generator(this, function (_a) {
485
- roughness = parameter_1.Parameter.parseNumber(newValue);
486
- element.nodes.forEach(function (node) {
487
- babylonHelper_1.assertTransformNode(node, function (node) {
488
- if (node instanceof instancedMesh_1.InstancedMesh) {
489
- throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL_ROUGHNESS + "\" " +
490
- "of an InstancedMesh is not supported. " +
491
- ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
492
- }
493
- });
494
- if (!lodash_es_1.get(node.metadata, 'dirty.material')) {
495
- babylonHelper_1.cloneTransformNodeMaterial(node);
496
- }
497
- if (!lodash_es_1.get(node.metadata, 'dirty.material.roughness')) {
498
- // inject initial value and mark as dirty
499
- babylonHelper_1.injectTransformNodeMetadata(node, { dirty: { material: { roughness: oldValue } } });
500
- }
501
- babylonHelper_1.setMaterialRoughness(node, roughness);
502
- });
503
- return [2 /*return*/];
504
- });
505
- }); }
506
- ]);
507
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_COLOR, [
508
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
509
- var _a;
510
- return tslib_1.__generator(this, function (_b) {
511
- // trigger Parameter.HIGHLIGHTED observers
512
- (_a = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHTED)) === null || _a === void 0 ? void 0 : _a.forEach(function (observer) {
513
- observer(element, !!element.highlighted, !!element.highlighted);
514
- });
515
- return [2 /*return*/];
516
- });
517
- }); }
518
- ]);
519
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_ENABLED, [
520
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
521
- var curr;
522
- var _a;
523
- return tslib_1.__generator(this, function (_b) {
524
- try {
525
- curr = parameter_1.Parameter.parseBoolean(newValue);
526
- }
527
- catch (e) {
528
- return [2 /*return*/];
529
- }
530
- switch (curr) {
531
- case true:
532
- if (element._highlightLayer) {
533
- break;
534
- }
535
- element.highlightLayer = new highlightLayer_1.HighlightLayer(dottedPath_1.DottedPath.create(element.id).addPart('highlight').path, element.variant.viewer.scene);
536
- break;
537
- case false:
538
- (_a = element.highlightLayer) === null || _a === void 0 ? void 0 : _a.dispose();
539
- break;
540
- }
541
- return [2 /*return*/];
542
- });
543
- }); }
544
- ]);
545
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHTED, [
546
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
547
- var highlighted;
548
- var _this = this;
549
- var _a;
550
- return tslib_1.__generator(this, function (_b) {
551
- if (!element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
552
- return [2 /*return*/];
553
- }
554
- // trigger Parameter.HIGHLIGHT_ENABLED observers to ensure HighlightLayer
555
- (_a = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHT_ENABLED)) === null || _a === void 0 ? void 0 : _a.forEach(function (observer) {
556
- observer(element, _this.parameters[parameter_1.Parameter.HIGHLIGHT_ENABLED], true);
557
- });
558
- try {
559
- highlighted = parameter_1.Parameter.parseBoolean(newValue);
560
- }
561
- catch (e) {
562
- return [2 /*return*/];
563
- }
564
- // Add/Remove meshes to previously created highlight layers.
565
- if (highlighted === true) {
566
- element.nodes.forEach(function (node) {
567
- babylonHelper_1.assertTransformNode(node, function (node) {
568
- if (node instanceof instancedMesh_1.InstancedMesh) {
569
- throw new Error("Changing parameter \"" + parameter_1.Parameter.HIGHLIGHTED + "\" " +
570
- "of an InstancedMesh is not supported. " +
571
- ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
572
- }
573
- });
574
- var color = math_color_1.Color3.Green();
575
- if (element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]) {
576
- color = parameter_1.Parameter.parseColor(element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]);
577
- }
578
- if (typeof element._highlightLayer !== "undefined") {
579
- babylonHelper_1.addToHighlightLayer(element._highlightLayer, color, node);
580
- }
581
- });
582
- }
583
- else if (highlighted === false) {
584
- element.nodes.forEach(function (node) {
585
- if (typeof element._highlightLayer !== "undefined") {
586
- babylonHelper_1.removeFromHighlightLayer(element._highlightLayer, node);
587
- }
588
- });
589
- }
590
- return [2 /*return*/];
591
- });
592
- }); }
593
- ]);
594
- this._parameterObservers.set(parameter_1.Parameter.POSITION, [
595
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
596
- return tslib_1.__generator(this, function (_a) {
597
- // we have to deal just with root nodes here due to relative impacts in a node tree
598
- element.nodes.forEach(function (node) {
599
- // remember absolute position and reset it before translating
600
- if (!lodash_es_1.get(node.metadata, 'position')) {
601
- node.metadata.position = node.absolutePosition.clone();
602
- }
603
- node.setAbsolutePosition(node.metadata.position);
604
- // move
605
- var distance = parameter_1.Parameter.parseVector(newValue);
606
- node.translate(math_axis_1.Axis.X, distance.x, math_axis_1.Space.WORLD);
607
- node.translate(math_axis_1.Axis.Y, distance.y, math_axis_1.Space.WORLD);
608
- node.translate(math_axis_1.Axis.Z, distance.z, math_axis_1.Space.WORLD);
609
- });
610
- return [2 /*return*/];
611
- });
612
- }); }
613
- ]);
614
- this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
615
- function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
616
- return tslib_1.__generator(this, function (_a) {
617
- // we have to deal just with root nodes here due to relative impacts in a node tree
618
- element.nodes.forEach(function (node) {
619
- // remember absolute rotation and reset it before translating
620
- if (!lodash_es_1.get(node.metadata, 'rotation')) {
621
- node.metadata.rotation = node.rotation.clone();
622
- }
623
- node.rotation = node.metadata.rotation;
624
- // rotate
625
- var rotation = parameter_1.Parameter.parseRotation(newValue);
626
- node.rotate(math_axis_1.Axis.X, rotation.x, math_axis_1.Space.WORLD);
627
- node.rotate(math_axis_1.Axis.Y, rotation.y, math_axis_1.Space.WORLD);
628
- node.rotate(math_axis_1.Axis.Z, rotation.z, math_axis_1.Space.WORLD);
629
- });
630
- return [2 /*return*/];
631
- });
632
- }); }
633
- ]);
634
- return this;
635
- };
636
- /**
637
- * Filter for nodes that are not defined or excluded in the `pathDefinitions`.
638
- */
639
- Element.prototype.filterNode = function (node) {
640
- var _this = this;
641
- var includeTokens = [];
642
- this.pathDefinitions.include.forEach(function (dottedPath) {
643
- includeTokens = lodash_es_1.union(includeTokens, dottedPath_1.DottedPath.create(dottedPath).leafTokens);
644
- });
645
- var shallKeep = function (dp) {
646
- var isDirectlyIncluded = !!includeTokens.find(function (_dp) { return _dp === dp.path; });
647
- var isSubOfIncluded = !!_this.pathDefinitions.include.find(function (_dp) {
648
- return dp.path.startsWith("" + _dp + dottedPath_1.DottedPath.DELIMITER);
649
- });
650
- return isDirectlyIncluded || isSubOfIncluded;
651
- };
652
- var shallExclude = function (dp) {
653
- if (!_this.pathDefinitions.exclude) {
654
- return false;
655
- }
656
- return !!_this.pathDefinitions.exclude.find(function (_dp) { return dp.path === _dp; });
657
- };
658
- return shallKeep(node.metadata.dottedPath) && !shallExclude(node.metadata.dottedPath);
659
- };
660
- /**
661
- * Asserts whether all {@link pathDefinitions} link to a valid `Node` path.
662
- * @protected
663
- */
664
- Element.prototype.assertPathDefinitions = function () {
665
- var _this = this;
666
- var _a;
667
- var dottedNodes = this.variant.inheritedDottedNodes;
668
- if (dottedNodes.size === 0) {
669
- throw new Error("There are no mapped nodes for element \"" + this.id + "\".");
670
- }
671
- var include = this.pathDefinitions.include.map(function (path) { return dottedPath_1.DottedPath.create(path).path; });
672
- var exclude = (_a = this.pathDefinitions.exclude) === null || _a === void 0 ? void 0 : _a.map(function (path) { return dottedPath_1.DottedPath.create(path).path; });
673
- var keys = Array.from(dottedNodes.keys()).map(function (dottedPath) { return dottedPath.path; });
674
- lodash_es_1.union(include, exclude).forEach(function (path) {
675
- if (keys.indexOf(path) === -1) {
676
- throw new Error("Node with path \"" + path + "\" does not exist for element \"" + _this.id + "\".");
677
- }
678
- });
679
- };
680
- return Element;
681
- }(elementParameterizable_1.ElementParameterizable));
682
- exports.Element = Element;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Element = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
6
+ var material_1 = require("@babylonjs/core/Materials/material");
7
+ var standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
8
+ var dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
9
+ var math_color_1 = require("@babylonjs/core/Maths/math.color");
10
+ var abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
11
+ var instancedMesh_1 = require("@babylonjs/core/Meshes/instancedMesh");
12
+ var mesh_1 = require("@babylonjs/core/Meshes/mesh");
13
+ var transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
14
+ var lodash_es_1 = require("lodash-es");
15
+ var babylonHelper_1 = require("../util/babylonHelper");
16
+ var resourceHelper_1 = require("../util/resourceHelper");
17
+ var variantParameterizable_1 = require("./../classes/variantParameterizable");
18
+ var dottedPath_1 = require("./dottedPath");
19
+ var parameter_1 = require("./parameter");
20
+ /**
21
+ * An {@link Element} of a {@link Variant}. Acts as a container for diverse definitions. Lives only in the context of a
22
+ * {@link Variant}.
23
+ *
24
+ * When used in typings, refer to via its alias {@link VariantElement} to prevent name clashes with the web APIs
25
+ * [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) class
26
+ */
27
+ var Element = /** @class */ (function (_super) {
28
+ tslib_1.__extends(Element, _super);
29
+ /**
30
+ * Constructor.
31
+ */
32
+ function Element(variant, name) {
33
+ var _a;
34
+ var _this = _super.call(this, variant, name) || this;
35
+ _this.variant = variant;
36
+ _this.name = name;
37
+ _this.nodes = [];
38
+ _this._dottedNodes = new Map();
39
+ if ((_a = process.env.NODE_ENV) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('dev')) {
40
+ _this.assertPathDefinitions();
41
+ }
42
+ var nodes = _this.variant.inheritedNodes.map(function (node) { return babylonHelper_1.cloneTransformNode(node, _this.filterNode.bind(_this)); });
43
+ _this.nodes = nodes.filter(function (node) { return !!node; });
44
+ _this._dottedNodes = babylonHelper_1.mapToDottedNodes(_this.nodes, function (node) { return node instanceof transformNode_1.TransformNode; });
45
+ _this.addParameterObservers();
46
+ return _this;
47
+ }
48
+ /**
49
+ * Creates an {@link Element} with given name.
50
+ */
51
+ Element.create = function (variant, name) {
52
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
53
+ return tslib_1.__generator(this, function (_a) {
54
+ return [2 /*return*/, new Element(variant, name)];
55
+ });
56
+ });
57
+ };
58
+ Object.defineProperty(Element.prototype, "dottedPath", {
59
+ /**
60
+ * The {@link DottedPath} in the built tree of {@link Element}s.
61
+ * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
62
+ */
63
+ get: function () {
64
+ return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
65
+ },
66
+ enumerable: false,
67
+ configurable: true
68
+ });
69
+ Object.defineProperty(Element.prototype, "id", {
70
+ /**
71
+ * The id representing a {@link DottedPath}.
72
+ */
73
+ get: function () {
74
+ var dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
75
+ dottedPath.shiftPart(); // remove root
76
+ return dottedPath.path;
77
+ },
78
+ enumerable: false,
79
+ configurable: true
80
+ });
81
+ Object.defineProperty(Element.prototype, "definition", {
82
+ /**
83
+ * The {@link ElementDefinition} of the {@link Element}.
84
+ */
85
+ get: function () {
86
+ var definition = this.variant.structureJson.elements[this.name];
87
+ if (lodash_es_1.isArray(definition)) {
88
+ return {
89
+ paths: {
90
+ include: definition
91
+ }
92
+ };
93
+ }
94
+ return definition;
95
+ },
96
+ enumerable: false,
97
+ configurable: true
98
+ });
99
+ Object.defineProperty(Element.prototype, "pathDefinitions", {
100
+ /**
101
+ * The {@link PathDefinitions} of the {@link Element}.
102
+ */
103
+ get: function () {
104
+ return this.definition.paths;
105
+ },
106
+ enumerable: false,
107
+ configurable: true
108
+ });
109
+ Object.defineProperty(Element.prototype, "traceableDefinitions", {
110
+ /**
111
+ * The {@link TraceableDefinitions} of the {@link Element}.
112
+ */
113
+ get: function () {
114
+ return this.definition.traceables || {};
115
+ },
116
+ enumerable: false,
117
+ configurable: true
118
+ });
119
+ Object.defineProperty(Element.prototype, "paintableDefinitions", {
120
+ /**
121
+ * The {@link PaintableDefinition} of the {@link Element}.
122
+ */
123
+ get: function () {
124
+ return this.definition.paintables || {};
125
+ },
126
+ enumerable: false,
127
+ configurable: true
128
+ });
129
+ Object.defineProperty(Element.prototype, "inheritedParameters", {
130
+ /**
131
+ * The inherited {@link ParameterBag}.
132
+ * Merges the {@link Variant}'s parameters and those from the {@link Element}.
133
+ */
134
+ get: function () {
135
+ return lodash_es_1.merge({}, this.variant.inheritedParameters, this.parameters);
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ Object.defineProperty(Element.prototype, "highlightLayer", {
141
+ get: function () {
142
+ return this._highlightLayer;
143
+ },
144
+ /**
145
+ * @protected
146
+ */
147
+ set: function (layer) {
148
+ this._highlightLayer = layer;
149
+ },
150
+ enumerable: false,
151
+ configurable: true
152
+ });
153
+ /**
154
+ * Destroys this {@link Element} and dispose all nodes.
155
+ */
156
+ Element.prototype.destroy = function () {
157
+ this.nodes.forEach(function (node) {
158
+ node.dispose();
159
+ });
160
+ return this;
161
+ };
162
+ /**
163
+ * Gets a node by its {@link DottedPath}.
164
+ */
165
+ Element.prototype.getNode = function (dottedPath) {
166
+ var _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
167
+ var keys = Array.from(this._dottedNodes.keys()).map(function (dp) { return dp.path; });
168
+ var values = Array.from(this._dottedNodes.values());
169
+ var node = values[keys.indexOf(_dottedPath.path)];
170
+ if (!node) {
171
+ throw new Error("Node with path \"" + _dottedPath.path + "\" does not exist for element \"" + this.id + "\".");
172
+ }
173
+ return node;
174
+ };
175
+ /**
176
+ * Gets a mesh by its {@link DottedPath}.
177
+ */
178
+ Element.prototype.getMesh = function (dottedPath) {
179
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
180
+ var node;
181
+ return tslib_1.__generator(this, function (_a) {
182
+ switch (_a.label) {
183
+ case 0: return [4 /*yield*/, this.getNode(dottedPath)];
184
+ case 1:
185
+ node = _a.sent();
186
+ if (node instanceof mesh_1.Mesh) {
187
+ return [2 /*return*/, node];
188
+ }
189
+ return [2 /*return*/, null];
190
+ }
191
+ });
192
+ });
193
+ };
194
+ /**
195
+ * Gets a {@link PaintableDefinition} by its name.
196
+ */
197
+ Element.prototype.getPaintableDefinition = function (name) {
198
+ if (!this.paintableDefinitions || !this.paintableDefinitions[name]) {
199
+ throw new Error("No paintable \"" + name + "\" defined for element \"" + this.id + "\".");
200
+ }
201
+ return this.paintableDefinitions[name];
202
+ };
203
+ /**
204
+ * Gets a {@link TraceableDefinition} by its name.
205
+ */
206
+ Element.prototype.getTraceableDefinition = function (name) {
207
+ if (!this.traceableDefinitions || !this.traceableDefinitions[name]) {
208
+ throw new Error("No traceable \"" + name + "\" defined to add observer in element \"" + this.id + "\".");
209
+ }
210
+ return this.traceableDefinitions[name];
211
+ };
212
+ /**
213
+ * Gets the paintable Node by its name.
214
+ */
215
+ Element.prototype.getPaintableNode = function (name) {
216
+ return this.getNode(this.getPaintableDefinition(name).path);
217
+ };
218
+ /**
219
+ * Gets the traceable Node by its name.
220
+ */
221
+ Element.prototype.getTraceableNode = function (name) {
222
+ return this.getNode(this.getTraceableDefinition(name).path);
223
+ };
224
+ /**
225
+ * @see {@link VariantParameterizable.commitParameters}
226
+ * @emit {@link Event.ELEMENT_PARAMETER_COMMITTED}
227
+ */
228
+ Element.prototype.commitParameters = function (parameters) {
229
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
230
+ return tslib_1.__generator(this, function (_a) {
231
+ return [2 /*return*/, _super.prototype.commitParameters.call(this, parameters)];
232
+ });
233
+ });
234
+ };
235
+ /**
236
+ * Adds an observer function for camera matrix changes.
237
+ * The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
238
+ */
239
+ Element.prototype.addTraceableObserver = function (traceable, observer, payload) {
240
+ var _this = this;
241
+ if (payload && !(payload instanceof HTMLElement)) {
242
+ throw new Error("Payload for camera observer must be an instance of \"HTMLElement\" in element \"" + this.id + "\".");
243
+ }
244
+ if (!this.traceableDefinitions || !this.traceableDefinitions[traceable]) {
245
+ throw new Error("No traceable \"" + traceable + "\" defined to add observer in element \"" + this.id + "\".");
246
+ }
247
+ var node = this.getTraceableNode(traceable);
248
+ if (!(node instanceof abstractMesh_1.AbstractMesh)) {
249
+ throw new Error("The path must be an instance of \"AbstractMesh\" for camera observer in element \"" + this.id + "\".");
250
+ }
251
+ this.variant.viewer.sceneManager.activeCamera.onViewMatrixChangedObservable.add(function (eventData, eventState) {
252
+ var position = babylonHelper_1.getClientRectFromMesh(node, _this.variant.viewer.scene, _this.variant.viewer.canvas);
253
+ if (payload) {
254
+ payload.style.top = position.top + "px";
255
+ payload.style.left = position.left + "px";
256
+ }
257
+ observer(node, position);
258
+ });
259
+ return this;
260
+ };
261
+ /**
262
+ * Draws a `ImageBitmap` or `OffscreenCanvas` onto a `paintable` defined via {@link PaintableDefinition}.
263
+ */
264
+ Element.prototype.drawPaintable = function (paintable, imageSource) {
265
+ // node and material checks and preperation
266
+ var node = this.getPaintableNode(paintable);
267
+ if (!(node instanceof abstractMesh_1.AbstractMesh)) {
268
+ throw new Error("The path must be an instance of \"AbstractMesh\" for paintable \"" + paintable + "\" " +
269
+ ("in element \"" + this.id + "\"."));
270
+ }
271
+ if (node.material && !lodash_es_1.has(node.metadata, 'dirty.material')) {
272
+ babylonHelper_1.cloneTransformNodeMaterial(node);
273
+ }
274
+ if (!node.material) {
275
+ node.material = new standardMaterial_1.StandardMaterial(this.id + "." + paintable + ".material", this.variant.viewer.scene);
276
+ }
277
+ node.material.transparencyMode = material_1.Material.MATERIAL_ALPHATESTANDBLEND;
278
+ if (!lodash_es_1.has(node.metadata, 'dirty.material.texture')) {
279
+ // inject initial value and mark as dirty
280
+ babylonHelper_1.injectNodeMetadata(node, { dirty: { material: { texture: true } } });
281
+ }
282
+ // consider width and height of the paintable
283
+ var widthAndHeight = {
284
+ width: imageSource.width,
285
+ height: imageSource.height
286
+ };
287
+ var paintableDefinition = this.getPaintableDefinition(paintable);
288
+ if (lodash_es_1.isNumber(paintableDefinition.textureOptions)) {
289
+ widthAndHeight.width = paintableDefinition.textureOptions;
290
+ widthAndHeight.height = paintableDefinition.textureOptions;
291
+ }
292
+ else if (lodash_es_1.isPlainObject(paintableDefinition.textureOptions)) {
293
+ widthAndHeight.width = paintableDefinition.textureOptions.width;
294
+ widthAndHeight.height = paintableDefinition.textureOptions.height;
295
+ }
296
+ // create dynamic texture on which the image can be drawn
297
+ var texture = new dynamicTexture_1.DynamicTexture(this.id + "." + paintable + ".texture", widthAndHeight, this.variant.viewer.scene, false);
298
+ // draw image on texture
299
+ var ctx = texture.getContext();
300
+ ctx.drawImage(imageSource, 0, 0);
301
+ texture.update(false);
302
+ // finally apply the texture on the desired node material
303
+ babylonHelper_1.setMaterialTexture(node, texture, false);
304
+ return this;
305
+ };
306
+ /**
307
+ * Draws a SVG string onto a `paintable` defined via {@link PaintableDefinition}.
308
+ */
309
+ Element.prototype.drawPaintableFromSvg = function (paintable, svgSource) {
310
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
311
+ var image;
312
+ return tslib_1.__generator(this, function (_a) {
313
+ switch (_a.label) {
314
+ case 0: return [4 /*yield*/, resourceHelper_1.createImageFromSvg(svgSource)];
315
+ case 1:
316
+ image = _a.sent();
317
+ return [2 /*return*/, this.drawPaintable(paintable, image)];
318
+ }
319
+ });
320
+ });
321
+ };
322
+ /**
323
+ * Draws an Image from source (URL/URI) onto a `paintable` defined via {@link PaintableDefinition}.
324
+ */
325
+ Element.prototype.drawPaintableFromImgSrc = function (paintable, imgSource) {
326
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
327
+ var image;
328
+ return tslib_1.__generator(this, function (_a) {
329
+ switch (_a.label) {
330
+ case 0: return [4 /*yield*/, resourceHelper_1.createImageFromImgSrc(imgSource)];
331
+ case 1:
332
+ image = _a.sent();
333
+ return [2 /*return*/, this.drawPaintable(paintable, image)];
334
+ }
335
+ });
336
+ });
337
+ };
338
+ /**
339
+ * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
340
+ */
341
+ Element.prototype.addParameterObservers = function () {
342
+ var _this = this;
343
+ this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
344
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
345
+ var visible;
346
+ return tslib_1.__generator(this, function (_a) {
347
+ try {
348
+ visible = parameter_1.Parameter.parseBoolean(newValue);
349
+ }
350
+ catch (e) {
351
+ return [2 /*return*/];
352
+ }
353
+ if (visible === true) {
354
+ element.nodes.forEach(function (node) {
355
+ babylonHelper_1.injectNodeMetadata(node, { visibility: node.isEnabled() });
356
+ babylonHelper_1.activateTransformNode(node);
357
+ });
358
+ }
359
+ else if (visible === false) {
360
+ element.nodes.forEach(function (node) {
361
+ babylonHelper_1.injectNodeMetadata(node, { visibility: node.isEnabled() });
362
+ babylonHelper_1.deactivateTransformNode(node);
363
+ });
364
+ }
365
+ return [2 /*return*/];
366
+ });
367
+ }); }
368
+ ]);
369
+ this._parameterObservers.set(parameter_1.Parameter.SCALING, [
370
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
371
+ return tslib_1.__generator(this, function (_a) {
372
+ // we have to deal just with root nodes here due to relative impacts in a node tree
373
+ element.nodes.forEach(function (node) { return node.scaling = parameter_1.Parameter.parseScaling(newValue); });
374
+ return [2 /*return*/];
375
+ });
376
+ }); }
377
+ ]);
378
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL, [
379
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
380
+ var material;
381
+ return tslib_1.__generator(this, function (_a) {
382
+ material = element.variant.getMaterial(newValue.toString());
383
+ element.nodes.forEach(function (node) {
384
+ babylonHelper_1.assertTransformNode(node, function (node) {
385
+ if (node instanceof instancedMesh_1.InstancedMesh) {
386
+ throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL + "\" " +
387
+ "of an InstancedMesh is not supported. " +
388
+ ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
389
+ }
390
+ });
391
+ babylonHelper_1.setMaterial(node, material);
392
+ });
393
+ return [2 /*return*/];
394
+ });
395
+ }); }
396
+ ]);
397
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_COLOR, [
398
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
399
+ var color;
400
+ return tslib_1.__generator(this, function (_a) {
401
+ color = parameter_1.Parameter.parseColor(newValue);
402
+ element.nodes.forEach(function (node) {
403
+ babylonHelper_1.assertTransformNode(node, function (node) {
404
+ if (node instanceof instancedMesh_1.InstancedMesh) {
405
+ throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL_COLOR + "\" " +
406
+ "of an InstancedMesh is not supported. " +
407
+ ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
408
+ }
409
+ });
410
+ if (!lodash_es_1.has(node.metadata, 'dirty.material')) {
411
+ babylonHelper_1.cloneTransformNodeMaterial(node);
412
+ }
413
+ if (!lodash_es_1.has(node.metadata, 'dirty.material.color')) {
414
+ // inject initial value and mark as dirty
415
+ babylonHelper_1.injectNodeMetadata(node, { dirty: { material: { color: oldValue } } });
416
+ }
417
+ babylonHelper_1.setMaterialColor(node, color);
418
+ });
419
+ return [2 /*return*/];
420
+ });
421
+ }); }
422
+ ]);
423
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_METALLNESS, [
424
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
425
+ var metallness;
426
+ return tslib_1.__generator(this, function (_a) {
427
+ metallness = parameter_1.Parameter.parseNumber(newValue);
428
+ element.nodes.forEach(function (node) {
429
+ babylonHelper_1.assertTransformNode(node, function (node) {
430
+ if (node instanceof instancedMesh_1.InstancedMesh) {
431
+ throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL_METALLNESS + "\" " +
432
+ "of an InstancedMesh is not supported. " +
433
+ ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
434
+ }
435
+ });
436
+ if (!lodash_es_1.has(node.metadata, 'dirty.material')) {
437
+ babylonHelper_1.cloneTransformNodeMaterial(node);
438
+ }
439
+ if (!lodash_es_1.has(node.metadata, 'dirty.material.metallness')) {
440
+ // inject initial value and mark as dirty
441
+ babylonHelper_1.injectNodeMetadata(node, { dirty: { material: { metallness: oldValue } } });
442
+ }
443
+ babylonHelper_1.setMaterialMetallness(node, metallness);
444
+ });
445
+ return [2 /*return*/];
446
+ });
447
+ }); }
448
+ ]);
449
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_ROUGHNESS, [
450
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
451
+ var roughness;
452
+ return tslib_1.__generator(this, function (_a) {
453
+ roughness = parameter_1.Parameter.parseNumber(newValue);
454
+ element.nodes.forEach(function (node) {
455
+ babylonHelper_1.assertTransformNode(node, function (node) {
456
+ if (node instanceof instancedMesh_1.InstancedMesh) {
457
+ throw new Error("Changing parameter \"" + parameter_1.Parameter.MATERIAL_ROUGHNESS + "\" " +
458
+ "of an InstancedMesh is not supported. " +
459
+ ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
460
+ }
461
+ });
462
+ if (!lodash_es_1.has(node.metadata, 'dirty.material')) {
463
+ babylonHelper_1.cloneTransformNodeMaterial(node);
464
+ }
465
+ if (!lodash_es_1.has(node.metadata, 'dirty.material.roughness')) {
466
+ // inject initial value and mark as dirty
467
+ babylonHelper_1.injectNodeMetadata(node, { dirty: { material: { roughness: oldValue } } });
468
+ }
469
+ babylonHelper_1.setMaterialRoughness(node, roughness);
470
+ });
471
+ return [2 /*return*/];
472
+ });
473
+ }); }
474
+ ]);
475
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_COLOR, [
476
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
477
+ var _a;
478
+ return tslib_1.__generator(this, function (_b) {
479
+ // trigger Parameter.HIGHLIGHTED observers
480
+ (_a = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHTED)) === null || _a === void 0 ? void 0 : _a.forEach(function (observer) {
481
+ observer(element, !!element.highlighted, !!element.highlighted);
482
+ });
483
+ return [2 /*return*/];
484
+ });
485
+ }); }
486
+ ]);
487
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_ENABLED, [
488
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
489
+ var curr;
490
+ var _a;
491
+ return tslib_1.__generator(this, function (_b) {
492
+ try {
493
+ curr = parameter_1.Parameter.parseBoolean(newValue);
494
+ }
495
+ catch (e) {
496
+ return [2 /*return*/];
497
+ }
498
+ switch (curr) {
499
+ case true:
500
+ if (element._highlightLayer) {
501
+ break;
502
+ }
503
+ element.highlightLayer = new highlightLayer_1.HighlightLayer(dottedPath_1.DottedPath.create(element.id).addPart('highlight').path, element.variant.viewer.scene);
504
+ break;
505
+ case false:
506
+ (_a = element.highlightLayer) === null || _a === void 0 ? void 0 : _a.dispose();
507
+ break;
508
+ }
509
+ return [2 /*return*/];
510
+ });
511
+ }); }
512
+ ]);
513
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHTED, [
514
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
515
+ var highlighted;
516
+ var _this = this;
517
+ var _a;
518
+ return tslib_1.__generator(this, function (_b) {
519
+ if (!element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
520
+ return [2 /*return*/];
521
+ }
522
+ // trigger Parameter.HIGHLIGHT_ENABLED observers to ensure HighlightLayer
523
+ (_a = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHT_ENABLED)) === null || _a === void 0 ? void 0 : _a.forEach(function (observer) {
524
+ observer(element, _this.parameters[parameter_1.Parameter.HIGHLIGHT_ENABLED], true);
525
+ });
526
+ try {
527
+ highlighted = parameter_1.Parameter.parseBoolean(newValue);
528
+ }
529
+ catch (e) {
530
+ return [2 /*return*/];
531
+ }
532
+ // Add/Remove meshes to previously created highlight layers.
533
+ if (highlighted === true) {
534
+ element.nodes.forEach(function (node) {
535
+ babylonHelper_1.assertTransformNode(node, function (node) {
536
+ if (node instanceof instancedMesh_1.InstancedMesh) {
537
+ throw new Error("Changing parameter \"" + parameter_1.Parameter.HIGHLIGHTED + "\" " +
538
+ "of an InstancedMesh is not supported. " +
539
+ ("Tried to change node \"" + node.id + "\" on element \"" + element.id + "\"."));
540
+ }
541
+ });
542
+ var color = math_color_1.Color3.Green();
543
+ if (element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]) {
544
+ color = parameter_1.Parameter.parseColor(element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]);
545
+ }
546
+ if (typeof element._highlightLayer !== "undefined") {
547
+ babylonHelper_1.addToHighlightLayer(element._highlightLayer, color, node);
548
+ }
549
+ });
550
+ }
551
+ else if (highlighted === false) {
552
+ element.nodes.forEach(function (node) {
553
+ if (typeof element._highlightLayer !== "undefined") {
554
+ babylonHelper_1.removeFromHighlightLayer(element._highlightLayer, node);
555
+ }
556
+ });
557
+ }
558
+ return [2 /*return*/];
559
+ });
560
+ }); }
561
+ ]);
562
+ this._parameterObservers.set(parameter_1.Parameter.POSITION, [
563
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
564
+ return tslib_1.__generator(this, function (_a) {
565
+ // we have to deal just with root nodes here due to relative impacts in a node tree
566
+ element.nodes.forEach(function (node) { return babylonHelper_1.moveTransformNode(node, parameter_1.Parameter.parseVector(newValue)); });
567
+ return [2 /*return*/];
568
+ });
569
+ }); }
570
+ ]);
571
+ this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
572
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
573
+ return tslib_1.__generator(this, function (_a) {
574
+ switch (_a.label) {
575
+ case 0:
576
+ if (!(parameter_1.Parameter.POSITION in element.inheritedParameters)) return [3 /*break*/, 2];
577
+ return [4 /*yield*/, element.commitParameter(parameter_1.Parameter.POSITION, element.inheritedParameters[parameter_1.Parameter.POSITION])];
578
+ case 1:
579
+ _a.sent();
580
+ _a.label = 2;
581
+ case 2:
582
+ // we have to deal just with root nodes here due to relative impacts in a node tree
583
+ element.nodes.forEach(function (node) { return babylonHelper_1.rotateTransformNode(node, parameter_1.Parameter.parseRotation(newValue)); });
584
+ return [2 /*return*/];
585
+ }
586
+ });
587
+ }); }
588
+ ]);
589
+ this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW, [
590
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
591
+ var castShadow, lightCsl;
592
+ return tslib_1.__generator(this, function (_a) {
593
+ switch (_a.label) {
594
+ case 0:
595
+ try {
596
+ castShadow = parameter_1.Parameter.parseBoolean(newValue);
597
+ }
598
+ catch (e) {
599
+ return [2 /*return*/];
600
+ }
601
+ lightCsl = element.inheritedParameters[parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS];
602
+ if (!lightCsl) {
603
+ lightCsl = element.variant.inheritedViewerLights.map(function (l) { return l.name; }).join(',');
604
+ }
605
+ if (!(castShadow === true)) return [3 /*break*/, 2];
606
+ return [4 /*yield*/, this.castShadowValueHandler(lightCsl, babylonHelper_1.addToShadowGenerator)];
607
+ case 1:
608
+ _a.sent();
609
+ _a.label = 2;
610
+ case 2:
611
+ if (!(castShadow === false)) return [3 /*break*/, 4];
612
+ return [4 /*yield*/, this.castShadowValueHandler(lightCsl, babylonHelper_1.removeFromShadowGenerator)];
613
+ case 3:
614
+ _a.sent();
615
+ _a.label = 4;
616
+ case 4: return [2 /*return*/];
617
+ }
618
+ });
619
+ }); }
620
+ ]);
621
+ this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, [
622
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
623
+ var lightCsl;
624
+ return tslib_1.__generator(this, function (_a) {
625
+ switch (_a.label) {
626
+ case 0:
627
+ lightCsl = element.variant.inheritedViewerLights.map(function (l) { return l.name; }).join(',');
628
+ // cleanup all shadow generators
629
+ return [4 /*yield*/, this.castShadowValueHandler(lightCsl, babylonHelper_1.removeFromShadowGenerator)];
630
+ case 1:
631
+ // cleanup all shadow generators
632
+ _a.sent();
633
+ if (!(element.castShadow === true)) return [3 /*break*/, 3];
634
+ // if newValue is undefined or '' then set newValue to lightCsl (use all lights)
635
+ if (!newValue) {
636
+ newValue = lightCsl;
637
+ }
638
+ return [4 /*yield*/, this.castShadowValueHandler(newValue, babylonHelper_1.addToShadowGenerator)];
639
+ case 2:
640
+ _a.sent();
641
+ _a.label = 3;
642
+ case 3: return [2 /*return*/];
643
+ }
644
+ });
645
+ }); }
646
+ ]);
647
+ this._parameterObservers.set(parameter_1.Parameter.RECEIVE_SHADOWS, [
648
+ function (element, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
649
+ return tslib_1.__generator(this, function (_a) {
650
+ element.nodes.forEach(function (node) { return babylonHelper_1.setReceiveShadows(node, parameter_1.Parameter.parseBoolean(newValue)); });
651
+ return [2 /*return*/];
652
+ });
653
+ }); }
654
+ ]);
655
+ return this;
656
+ };
657
+ /**
658
+ * Filter for nodes that are not defined or excluded in the `pathDefinitions`.
659
+ */
660
+ Element.prototype.filterNode = function (node) {
661
+ var _this = this;
662
+ var includeTokens = [];
663
+ this.pathDefinitions.include.forEach(function (dottedPath) {
664
+ includeTokens = lodash_es_1.union(includeTokens, dottedPath_1.DottedPath.create(dottedPath).leafTokens);
665
+ });
666
+ var shallKeep = function (dp) {
667
+ var isDirectlyIncluded = !!includeTokens.find(function (_dp) { return _dp === dp.path; });
668
+ var isSubOfIncluded = !!_this.pathDefinitions.include.find(function (_dp) {
669
+ return dp.path.startsWith("" + _dp + dottedPath_1.DottedPath.DELIMITER);
670
+ });
671
+ return isDirectlyIncluded || isSubOfIncluded;
672
+ };
673
+ var shallExclude = function (dp) {
674
+ if (!_this.pathDefinitions.exclude) {
675
+ return false;
676
+ }
677
+ return !!_this.pathDefinitions.exclude.find(function (_dp) { return dp.path === _dp; });
678
+ };
679
+ return shallKeep(node.metadata.dottedPath) && !shallExclude(node.metadata.dottedPath);
680
+ };
681
+ /**
682
+ * Asserts whether all {@link pathDefinitions} link to a valid `Node` path.
683
+ * @protected
684
+ */
685
+ Element.prototype.assertPathDefinitions = function () {
686
+ var _this = this;
687
+ var _a;
688
+ var dottedNodes = this.variant.inheritedDottedNodes;
689
+ if (dottedNodes.size === 0) {
690
+ throw new Error("There are no mapped nodes for element \"" + this.id + "\".");
691
+ }
692
+ var include = this.pathDefinitions.include.map(function (path) { return dottedPath_1.DottedPath.create(path).path; });
693
+ var exclude = (_a = this.pathDefinitions.exclude) === null || _a === void 0 ? void 0 : _a.map(function (path) { return dottedPath_1.DottedPath.create(path).path; });
694
+ var keys = Array.from(dottedNodes.keys()).map(function (dottedPath) { return dottedPath.path; });
695
+ lodash_es_1.union(include, exclude).forEach(function (path) {
696
+ if (keys.indexOf(path) === -1) {
697
+ throw new Error("Node with path \"" + path + "\" does not exist for element \"" + _this.id + "\".");
698
+ }
699
+ });
700
+ };
701
+ /**
702
+ * Handles callback for given light parameter.
703
+ */
704
+ Element.prototype.castShadowValueHandler = function (lightCsl, mutator) {
705
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
706
+ var lights, _i, _a, lightName, viewerLight, shadowGenerators;
707
+ var _this = this;
708
+ return tslib_1.__generator(this, function (_b) {
709
+ switch (_b.label) {
710
+ case 0:
711
+ lights = [];
712
+ _i = 0, _a = parameter_1.Parameter.parseCommaSeparatedList(lightCsl);
713
+ _b.label = 1;
714
+ case 1:
715
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
716
+ lightName = _a[_i];
717
+ return [4 /*yield*/, this.variant.getViewerLight(lightName)];
718
+ case 2:
719
+ viewerLight = _b.sent();
720
+ if (viewerLight) {
721
+ lights.push(viewerLight.light);
722
+ }
723
+ _b.label = 3;
724
+ case 3:
725
+ _i++;
726
+ return [3 /*break*/, 1];
727
+ case 4:
728
+ shadowGenerators = lights
729
+ .map(function (light) { return light === null || light === void 0 ? void 0 : light.getShadowGenerator(); })
730
+ .filter(Boolean);
731
+ shadowGenerators.forEach(function (generator) {
732
+ _this.nodes.forEach(function (node) {
733
+ mutator(generator, node);
734
+ });
735
+ });
736
+ return [2 /*return*/];
737
+ }
738
+ });
739
+ });
740
+ };
741
+ return Element;
742
+ }(variantParameterizable_1.VariantParameterizable));
743
+ exports.Element = Element;
683
744
  //# sourceMappingURL=element.js.map