@combeenation/3d-viewer 7.1.3 → 8.0.0

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 +111 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
  6. package/dist/lib-cjs/api/classes/element.d.ts +153 -153
  7. package/dist/lib-cjs/api/classes/element.js +672 -672
  8. package/dist/lib-cjs/api/classes/event.d.ts +401 -401
  9. package/dist/lib-cjs/api/classes/event.js +424 -424
  10. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  11. package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
  12. package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +7 -7
  13. package/dist/lib-cjs/api/classes/fuzzyMap.js +21 -21
  14. package/dist/lib-cjs/api/classes/parameter.d.ts +351 -351
  15. package/dist/lib-cjs/api/classes/parameter.js +524 -524
  16. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  17. package/dist/lib-cjs/api/classes/parameterObservable.js +72 -72
  18. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  19. package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
  20. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
  21. package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
  22. package/dist/lib-cjs/api/classes/variant.d.ts +253 -253
  23. package/dist/lib-cjs/api/classes/variant.js +858 -858
  24. package/dist/lib-cjs/api/classes/variantInstance.d.ts +53 -53
  25. package/dist/lib-cjs/api/classes/variantInstance.js +125 -125
  26. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  27. package/dist/lib-cjs/api/classes/variantParameterizable.js +86 -86
  28. package/dist/lib-cjs/api/classes/viewer.d.ts +213 -213
  29. package/dist/lib-cjs/api/classes/viewer.js +716 -716
  30. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  31. package/dist/lib-cjs/api/classes/viewerError.d.ts +43 -43
  32. package/dist/lib-cjs/api/classes/viewerError.js +55 -55
  33. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  34. package/dist/lib-cjs/api/classes/viewerLight.js +348 -348
  35. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  36. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  37. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
  38. package/dist/lib-cjs/api/internal/sceneSetup.js +226 -226
  39. package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
  40. package/dist/lib-cjs/api/manager/animationManager.js +126 -126
  41. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +102 -79
  42. package/dist/lib-cjs/api/manager/gltfExportManager.js +320 -242
  43. package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
  44. package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
  45. package/dist/lib-cjs/api/manager/sceneManager.js +128 -128
  46. package/dist/lib-cjs/api/manager/tagManager.d.ts +116 -116
  47. package/dist/lib-cjs/api/manager/tagManager.js +444 -444
  48. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
  49. package/dist/lib-cjs/api/manager/textureLoadManager.js +97 -97
  50. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +106 -106
  51. package/dist/lib-cjs/api/manager/variantInstanceManager.js +292 -292
  52. package/dist/lib-cjs/api/store/specStorage.d.ts +32 -32
  53. package/dist/lib-cjs/api/store/specStorage.js +65 -65
  54. package/dist/lib-cjs/api/util/babylonHelper.d.ts +235 -235
  55. package/dist/lib-cjs/api/util/babylonHelper.js +753 -753
  56. package/dist/lib-cjs/api/util/globalTypes.d.ts +457 -455
  57. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  58. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
  59. package/dist/lib-cjs/api/util/resourceHelper.js +203 -203
  60. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +44 -44
  61. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +175 -175
  62. package/dist/lib-cjs/api/util/stringHelper.d.ts +13 -13
  63. package/dist/lib-cjs/api/util/stringHelper.js +32 -32
  64. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  65. package/dist/lib-cjs/api/util/structureHelper.js +57 -57
  66. package/dist/lib-cjs/buildinfo.json +3 -3
  67. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  68. package/dist/lib-cjs/index.d.ts +54 -54
  69. package/dist/lib-cjs/index.js +117 -117
  70. package/package.json +81 -81
  71. package/src/api/classes/animationInterface.ts +10 -10
  72. package/src/api/classes/dottedPath.ts +181 -181
  73. package/src/api/classes/element.ts +733 -733
  74. package/src/api/classes/event.ts +457 -457
  75. package/src/api/classes/eventBroadcaster.ts +52 -52
  76. package/src/api/classes/fuzzyMap.ts +21 -21
  77. package/src/api/classes/parameter.ts +561 -561
  78. package/src/api/classes/parameterObservable.ts +73 -73
  79. package/src/api/classes/parameterizable.ts +87 -87
  80. package/src/api/classes/placementAnimation.ts +162 -162
  81. package/src/api/classes/variant.ts +949 -949
  82. package/src/api/classes/variantInstance.ts +123 -123
  83. package/src/api/classes/variantParameterizable.ts +83 -83
  84. package/src/api/classes/viewer.ts +772 -772
  85. package/src/api/classes/viewerError.ts +63 -63
  86. package/src/api/classes/viewerLight.ts +339 -339
  87. package/src/api/internal/debugViewer.ts +90 -90
  88. package/src/api/internal/lensRendering.ts +9 -9
  89. package/src/api/internal/sceneSetup.ts +205 -205
  90. package/src/api/manager/animationManager.ts +143 -143
  91. package/src/api/manager/gltfExportManager.ts +297 -237
  92. package/src/api/manager/sceneManager.ts +134 -134
  93. package/src/api/manager/tagManager.ts +477 -477
  94. package/src/api/manager/textureLoadManager.ts +95 -95
  95. package/src/api/manager/variantInstanceManager.ts +309 -309
  96. package/src/api/store/specStorage.ts +68 -68
  97. package/src/api/util/babylonHelper.ts +823 -823
  98. package/src/api/util/globalTypes.ts +527 -525
  99. package/src/api/util/resourceHelper.ts +191 -191
  100. package/src/api/util/sceneLoaderHelper.ts +170 -170
  101. package/src/api/util/stringHelper.ts +30 -30
  102. package/src/api/util/structureHelper.ts +58 -58
  103. package/src/buildinfo.json +3 -3
  104. package/src/dev.ts +62 -62
  105. package/src/index.ts +103 -103
  106. package/src/types.d.ts +38 -38
@@ -1,673 +1,673 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Element = void 0;
13
- const babylonHelper_1 = require("../util/babylonHelper");
14
- const resourceHelper_1 = require("../util/resourceHelper");
15
- const sceneLoaderHelper_1 = require("../util/sceneLoaderHelper");
16
- const variantParameterizable_1 = require("./../classes/variantParameterizable");
17
- const dottedPath_1 = require("./dottedPath");
18
- const event_1 = require("./event");
19
- const parameter_1 = require("./parameter");
20
- const highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
21
- const pbrMaterial_1 = require("@babylonjs/core/Materials/PBR/pbrMaterial");
22
- const dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
23
- const material_1 = require("@babylonjs/core/Materials/material");
24
- const math_color_1 = require("@babylonjs/core/Maths/math.color");
25
- const abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
26
- const mesh_1 = require("@babylonjs/core/Meshes/mesh");
27
- const transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
28
- const lodash_es_1 = require("lodash-es");
29
- /**
30
- * An {@link Element} of a {@link Variant}. Acts as a container for diverse definitions. Lives only in the context of a
31
- * {@link Variant}.
32
- *
33
- * When used in typings, refer to via its alias {@link VariantElement} to prevent name clashes with the web APIs
34
- * [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) class
35
- */
36
- class Element extends variantParameterizable_1.VariantParameterizable {
37
- /**
38
- * Constructor.
39
- */
40
- constructor(variant, name) {
41
- var _a;
42
- super(variant, name);
43
- this.variant = variant;
44
- this.name = name;
45
- this.nodes = [];
46
- this._dottedNodes = new Map();
47
- if ((_a = process.env.NODE_ENV) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('dev')) {
48
- this.assertPathDefinitions();
49
- }
50
- const nodes = this.variant.inheritedNodes.map(node => {
51
- const nodeNamingStrategy = {
52
- handler: variant.viewer.nodeNamingStrategyHandler,
53
- payload: {
54
- variantInstance: variant.variantInstance,
55
- variant: variant,
56
- variantParameterizable: this,
57
- },
58
- };
59
- return (0, babylonHelper_1.cloneTransformNode)(node, nodeNamingStrategy, this.filterNode.bind(this), true);
60
- });
61
- this.nodes = nodes.filter(node => !!node);
62
- this._dottedNodes = (0, babylonHelper_1.mapToDottedNodes)(this.nodes, node => node instanceof transformNode_1.TransformNode);
63
- variant.broadcastEvent(event_1.Event.ELEMENT_NODES_CLONED, this);
64
- this.addMissingMaterialObservers();
65
- this.addParameterObservers();
66
- }
67
- /**
68
- * Creates an {@link Element} with given name.
69
- */
70
- static create(variant, name) {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- const element = new Element(variant, name);
73
- variant.broadcastEvent(event_1.Event.ELEMENT_CREATED, element);
74
- return element;
75
- });
76
- }
77
- /**
78
- * The {@link DottedPath} in the built tree of {@link Element}s.
79
- * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
80
- */
81
- get dottedPath() {
82
- return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
83
- }
84
- /**
85
- * The id representing a {@link DottedPath}.
86
- */
87
- get id() {
88
- const dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
89
- dottedPath.shiftPart(); // remove root
90
- return dottedPath.path;
91
- }
92
- /**
93
- * The {@link ElementDefinition} of the {@link Element}.
94
- */
95
- get definition() {
96
- const definition = this.variant.structureJson.elements[this.name];
97
- if ((0, lodash_es_1.isArray)(definition)) {
98
- return {
99
- paths: {
100
- include: definition,
101
- },
102
- };
103
- }
104
- return definition;
105
- }
106
- /**
107
- * The {@link PathDefinitions} of the {@link Element}.
108
- */
109
- get pathDefinitions() {
110
- return this.definition.paths;
111
- }
112
- /**
113
- * The {@link TraceableDefinitions} of the {@link Element}.
114
- */
115
- get traceableDefinitions() {
116
- return this.definition.traceables || {};
117
- }
118
- /**
119
- * The {@link PaintableDefinition} of the {@link Element}.
120
- */
121
- get paintableDefinitions() {
122
- return this.definition.paintables || {};
123
- }
124
- /**
125
- * The inherited {@link ParameterBag}.
126
- * Merges the {@link Variant}'s parameters and those from the {@link Element}.
127
- */
128
- get inheritedParameters() {
129
- return (0, lodash_es_1.merge)({}, this.variant.inheritedParameters, this.parameters);
130
- }
131
- /**
132
- * The actual {@link TransformNode}s that make up this {@link Element}.
133
- */
134
- get nodesFlat() {
135
- return this.nodes.reduce((acc, cur) => [...acc, ...cur.getChildren(n => n instanceof transformNode_1.TransformNode, false)], this.nodes);
136
- }
137
- /**
138
- * The actual {@link Mesh}es that make up this {@link Element}.
139
- * Handy for e.g. creating a bounding box around an entire element.
140
- */
141
- get meshesFlat() {
142
- return this.nodes.reduce((acc, cur) => [...acc, ...cur.getChildren(n => n instanceof mesh_1.Mesh, false)], this.nodes.filter(n => n instanceof mesh_1.Mesh));
143
- }
144
- /**
145
- * The actual {@link AbstractMesh}es that make up this {@link Element}.
146
- * I.e. (real) Meshes as well as InstancedMeshes.
147
- */
148
- get abstractMeshesFlat() {
149
- return this.nodes.reduce((acc, cur) => [...acc, ...cur.getChildren(n => n instanceof abstractMesh_1.AbstractMesh, false)], this.nodes.filter(n => n instanceof abstractMesh_1.AbstractMesh));
150
- }
151
- /**
152
- * The meshes of this {@link Element}.
153
- */
154
- get meshes() {
155
- return this.nodes.filter(node => node instanceof mesh_1.Mesh);
156
- }
157
- /**
158
- * @protected
159
- */
160
- set highlightLayer(layer) {
161
- this._highlightLayer = layer;
162
- }
163
- get highlightLayer() {
164
- return this._highlightLayer;
165
- }
166
- /**
167
- * Destroys this {@link Element} and dispose all nodes.
168
- */
169
- destroy() {
170
- this.nodes.forEach(node => {
171
- node.dispose();
172
- });
173
- return this;
174
- }
175
- /**
176
- * Gets a node by its {@link DottedPath}.
177
- */
178
- getNode(dottedPath) {
179
- const _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
180
- const keys = Array.from(this._dottedNodes.keys()).map(dp => dp.path);
181
- const values = Array.from(this._dottedNodes.values());
182
- const node = values[keys.indexOf(_dottedPath.path)];
183
- if (!node) {
184
- throw new Error(`Node with path "${_dottedPath.path}" does not exist for element "${this.id}".`);
185
- }
186
- return node;
187
- }
188
- /**
189
- * Gets a mesh by its {@link DottedPath}.
190
- */
191
- getMesh(dottedPath) {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- const node = yield this.getNode(dottedPath);
194
- if (node instanceof mesh_1.Mesh) {
195
- return node;
196
- }
197
- return null;
198
- });
199
- }
200
- /**
201
- * Gets a {@link PaintableDefinition} by its name.
202
- */
203
- getPaintableDefinition(name) {
204
- if (!this.paintableDefinitions || !this.paintableDefinitions[name]) {
205
- throw new Error(`No paintable "${name}" defined for element "${this.id}".`);
206
- }
207
- return this.paintableDefinitions[name];
208
- }
209
- /**
210
- * Gets a {@link TraceableDefinition} by its name.
211
- */
212
- getTraceableDefinition(name) {
213
- if (!this.traceableDefinitions || !this.traceableDefinitions[name]) {
214
- throw new Error(`No traceable "${name}" defined to add observer in element "${this.id}".`);
215
- }
216
- return this.traceableDefinitions[name];
217
- }
218
- /**
219
- * Gets the paintable Node by its name.
220
- */
221
- getPaintableNode(name) {
222
- return this.getNode(this.getPaintableDefinition(name).path);
223
- }
224
- /**
225
- * Gets the traceable Node by its name.
226
- */
227
- getTraceableNode(name) {
228
- return this.getNode(this.getTraceableDefinition(name).path);
229
- }
230
- /**
231
- * @see {@link VariantParameterizable.commitParameters}
232
- * @emit {@link Event.ELEMENT_PARAMETER_COMMITTED}
233
- */
234
- commitParameters(parameters) {
235
- const _super = Object.create(null, {
236
- commitParameters: { get: () => super.commitParameters }
237
- });
238
- return __awaiter(this, void 0, void 0, function* () {
239
- return _super.commitParameters.call(this, parameters);
240
- });
241
- }
242
- /**
243
- * Adds an observer function for camera matrix changes.
244
- * The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
245
- */
246
- addTraceableObserver(traceable, observer, payload) {
247
- if (payload && !(payload instanceof HTMLElement)) {
248
- throw new Error(`Payload for camera observer must be an instance of "HTMLElement" in element "${this.id}".`);
249
- }
250
- if (!this.traceableDefinitions || !this.traceableDefinitions[traceable]) {
251
- throw new Error(`No traceable "${traceable}" defined to add observer in element "${this.id}".`);
252
- }
253
- const node = this.getTraceableNode(traceable);
254
- if (!(node instanceof abstractMesh_1.AbstractMesh)) {
255
- throw new Error(`The path must be an instance of "AbstractMesh" for camera observer in element "${this.id}".`);
256
- }
257
- this.variant.viewer.sceneManager.activeCamera.onViewMatrixChangedObservable.add((eventData, eventState) => {
258
- const position = (0, babylonHelper_1.getClientRectFromMesh)(node, this.variant.viewer.scene, this.variant.viewer.canvas);
259
- if (payload) {
260
- payload.style.top = `${position.top}px`;
261
- payload.style.left = `${position.left}px`;
262
- }
263
- observer(node, position);
264
- });
265
- return this;
266
- }
267
- /**
268
- * Draws a `ImageBitmap` or `OffscreenCanvas` onto a `paintable` defined via {@link PaintableDefinition}.
269
- */
270
- drawPaintable(paintable, imageSource) {
271
- // node and material checks and preperation
272
- const node = this.getPaintableNode(paintable);
273
- if (!(node instanceof abstractMesh_1.AbstractMesh)) {
274
- throw new Error(`The path must be an instance of "AbstractMesh" for paintable "${paintable}" ` + `in element "${this.id}".`);
275
- }
276
- if (node.material && this.variant.viewer.cloneMaterialsOnMutation) {
277
- if (node.material && !(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
278
- (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
279
- }
280
- if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.texture')) {
281
- // inject initial value and mark as dirty
282
- (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { texture: true } } });
283
- }
284
- }
285
- else if (!node.material) {
286
- // paintables should also work if no material is assigned to the node per default
287
- // in this case a certain fallback material with fitting default values is defined
288
- const pbrMat = new pbrMaterial_1.PBRMaterial(`${this.id}.${paintable}.material`, this.variant.viewer.scene);
289
- pbrMat.roughness = 1.0;
290
- pbrMat.metallic = 1.0;
291
- node.material = pbrMat;
292
- }
293
- // TODO: Not sure if this really should be overwritten every time the paintable is redrawn.
294
- // Maybe the 3D artist had something in mind when setting a certain transparency mode, which would get overwritten
295
- // in this case.
296
- // Applying it as a default if no material is set is fine though (see roughness/metallic some lines above).
297
- // Removing this line will most likely break existing configurators, so be cautios!
298
- node.material.transparencyMode = material_1.Material.MATERIAL_ALPHATESTANDBLEND;
299
- // consider width and height of the paintable
300
- const widthAndHeight = {
301
- width: imageSource.width,
302
- height: imageSource.height,
303
- };
304
- const paintableDefinition = this.getPaintableDefinition(paintable);
305
- if ((0, lodash_es_1.isNumber)(paintableDefinition.textureOptions)) {
306
- widthAndHeight.width = paintableDefinition.textureOptions;
307
- widthAndHeight.height = paintableDefinition.textureOptions;
308
- }
309
- else if ((0, lodash_es_1.isPlainObject)(paintableDefinition.textureOptions)) {
310
- widthAndHeight.width = paintableDefinition.textureOptions.width;
311
- widthAndHeight.height = paintableDefinition.textureOptions.height;
312
- }
313
- // create dynamic texture on which the image can be drawn
314
- const texture = new dynamicTexture_1.DynamicTexture(`${this.id}.${paintable}.texture`, widthAndHeight, this.variant.viewer.scene, false);
315
- // draw image on texture
316
- const ctx = texture.getContext();
317
- ctx.drawImage(imageSource, 0, 0);
318
- texture.update(false);
319
- // finally apply the texture on the desired node material
320
- (0, babylonHelper_1.setMaterialTexture)(node, texture, false);
321
- return this;
322
- }
323
- /**
324
- * Draws a SVG string onto a `paintable` defined via {@link PaintableDefinition}.
325
- */
326
- drawPaintableFromSvg(paintable, svgSource) {
327
- return __awaiter(this, void 0, void 0, function* () {
328
- const image = yield (0, resourceHelper_1.createImageFromSvg)(svgSource);
329
- return this.drawPaintable(paintable, image);
330
- });
331
- }
332
- /**
333
- * Draws an Image from source (URL/URI) onto a `paintable` defined via {@link PaintableDefinition}.
334
- */
335
- drawPaintableFromImgSrc(paintable, imgSource) {
336
- return __awaiter(this, void 0, void 0, function* () {
337
- const image = yield (0, resourceHelper_1.createImageFromImgSrc)(imgSource);
338
- return this.drawPaintable(paintable, image);
339
- });
340
- }
341
- /**
342
- * Adds observers for loading missing materials where needed
343
- */
344
- addMissingMaterialObservers() {
345
- for (const abstractMesh of this.abstractMeshesFlat) {
346
- (0, sceneLoaderHelper_1.addMissingMaterialObserver)(abstractMesh);
347
- }
348
- }
349
- /**
350
- * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
351
- */
352
- addParameterObservers() {
353
- this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
354
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
355
- let visible;
356
- try {
357
- visible = parameter_1.Parameter.parseBoolean(newValue);
358
- }
359
- catch (e) {
360
- return;
361
- }
362
- if (visible === true) {
363
- // Override visible state and materials if tag manager is in use to support texture lazy loading
364
- if (element.variant.viewer.tagManager.parameters.size > 0) {
365
- const hiddenNodeNames = [];
366
- element.variant.viewer.tagManager.parameters.forEach((parameterBag, subject) => {
367
- const nodes = element.variant.viewer.tagManager.getNodesBySubject(subject);
368
- const visibleParamValue = parameterBag[parameter_1.Parameter.VISIBLE];
369
- const isVisible = undefined === visibleParamValue || parameter_1.Parameter.parseBoolean(visibleParamValue);
370
- if (!isVisible) {
371
- hiddenNodeNames.push(...nodes.map(node => node.name));
372
- }
373
- // overwrite materials immediatly, so that original material of node doesn't get loaded, since it could
374
- // be exchanged by the tag manager
375
- if (parameterBag[parameter_1.Parameter.MATERIAL]) {
376
- nodes.forEach(node => (0, babylonHelper_1.setMaterial)(node, parameterBag[parameter_1.Parameter.MATERIAL], false));
377
- }
378
- });
379
- // enable all nodes that are not explicitely hidden by the tag manager
380
- element.nodesFlat.map(node => {
381
- if (!hiddenNodeNames.includes(node.name)) {
382
- node.setEnabled(true);
383
- }
384
- });
385
- return;
386
- }
387
- // The default behaviour.
388
- element.nodes.forEach(node => {
389
- (0, babylonHelper_1.injectNodeMetadata)(node, { visibility: node.isEnabled() });
390
- (0, babylonHelper_1.activateTransformNode)(node);
391
- });
392
- }
393
- else if (visible === false) {
394
- element.nodes.forEach(node => {
395
- (0, babylonHelper_1.injectNodeMetadata)(node, { visibility: node.isEnabled() });
396
- (0, babylonHelper_1.deactivateTransformNode)(node);
397
- });
398
- }
399
- }),
400
- ]);
401
- this._parameterObservers.set(parameter_1.Parameter.SCALING, [
402
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
403
- // we have to deal just with root nodes here due to relative impacts in a node tree
404
- element.nodes.forEach(node => (0, babylonHelper_1.transformTransformNode)(node, {
405
- scaling: parameter_1.Parameter.parseVector(newValue),
406
- position: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.POSITION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.POSITION)),
407
- rotation: parameter_1.Parameter.parseRotation(element.inheritedParameters[parameter_1.Parameter.ROTATION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.ROTATION)),
408
- }));
409
- }),
410
- ]);
411
- this._parameterObservers.set(parameter_1.Parameter.POSITION, [
412
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
413
- // we have to deal just with root nodes here due to relative impacts in a node tree
414
- element.nodes.forEach(node => (0, babylonHelper_1.transformTransformNode)(node, {
415
- scaling: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.SCALING] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.SCALING)),
416
- position: parameter_1.Parameter.parseVector(newValue),
417
- rotation: parameter_1.Parameter.parseRotation(element.inheritedParameters[parameter_1.Parameter.ROTATION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.ROTATION)),
418
- }));
419
- }),
420
- ]);
421
- this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
422
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
423
- // we have to deal just with root nodes here due to relative impacts in a node tree
424
- element.nodes.forEach(node => (0, babylonHelper_1.transformTransformNode)(node, {
425
- scaling: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.SCALING] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.SCALING)),
426
- position: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.POSITION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.POSITION)),
427
- rotation: parameter_1.Parameter.parseRotation(newValue),
428
- }));
429
- }),
430
- ]);
431
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL, [
432
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
433
- const materialName = newValue.toString();
434
- for (const node of element.nodes) {
435
- (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL));
436
- (0, babylonHelper_1.setMaterial)(node, materialName, true, element.variant);
437
- }
438
- }),
439
- ]);
440
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_COLOR, [
441
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
442
- const color = parameter_1.Parameter.parseColor(newValue);
443
- element.nodes.forEach(node => {
444
- (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL_COLOR));
445
- if (this.variant.viewer.cloneMaterialsOnMutation) {
446
- if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
447
- (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
448
- }
449
- if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.color')) {
450
- // inject initial value and mark as dirty
451
- (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { color: oldValue } } });
452
- }
453
- }
454
- (0, babylonHelper_1.setMaterialColor)(node, color);
455
- });
456
- }),
457
- ]);
458
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_METALLNESS, [
459
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
460
- const metallness = parameter_1.Parameter.parseNumber(newValue);
461
- element.nodes.forEach(node => {
462
- (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL_METALLNESS));
463
- if (this.variant.viewer.cloneMaterialsOnMutation) {
464
- if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
465
- (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
466
- }
467
- if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.metallness')) {
468
- // inject initial value and mark as dirty
469
- (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { metallness: oldValue } } });
470
- }
471
- }
472
- (0, babylonHelper_1.setMaterialMetallness)(node, metallness);
473
- });
474
- }),
475
- ]);
476
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_ROUGHNESS, [
477
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
478
- const roughness = parameter_1.Parameter.parseNumber(newValue);
479
- element.nodes.forEach(node => {
480
- (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL_ROUGHNESS));
481
- if (this.variant.viewer.cloneMaterialsOnMutation) {
482
- if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
483
- (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
484
- }
485
- if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.roughness')) {
486
- // inject initial value and mark as dirty
487
- (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { roughness: oldValue } } });
488
- }
489
- }
490
- (0, babylonHelper_1.setMaterialRoughness)(node, roughness);
491
- });
492
- }),
493
- ]);
494
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_COLOR, [
495
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
496
- var _a;
497
- // trigger Parameter.HIGHLIGHTED observers
498
- (_a = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHTED)) === null || _a === void 0 ? void 0 : _a.forEach(observer => {
499
- observer(element, !!element.highlighted, !!element.highlighted);
500
- });
501
- }),
502
- ]);
503
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_ENABLED, [
504
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
505
- var _b;
506
- let curr;
507
- try {
508
- curr = parameter_1.Parameter.parseBoolean(newValue);
509
- }
510
- catch (e) {
511
- return;
512
- }
513
- switch (curr) {
514
- case true:
515
- if (element._highlightLayer) {
516
- break;
517
- }
518
- element.highlightLayer = new highlightLayer_1.HighlightLayer(dottedPath_1.DottedPath.create(element.id).addPart('highlight').path, element.variant.viewer.scene);
519
- break;
520
- case false:
521
- (_b = element.highlightLayer) === null || _b === void 0 ? void 0 : _b.dispose();
522
- break;
523
- }
524
- }),
525
- ]);
526
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHTED, [
527
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
528
- var _c;
529
- if (!element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
530
- return;
531
- }
532
- // trigger Parameter.HIGHLIGHT_ENABLED observers to ensure HighlightLayer
533
- (_c = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHT_ENABLED)) === null || _c === void 0 ? void 0 : _c.forEach(observer => {
534
- observer(element, this.parameters[parameter_1.Parameter.HIGHLIGHT_ENABLED], true);
535
- });
536
- let highlighted;
537
- try {
538
- highlighted = parameter_1.Parameter.parseBoolean(newValue);
539
- }
540
- catch (e) {
541
- return;
542
- }
543
- // Add/Remove meshes to previously created highlight layers.
544
- if (highlighted === true) {
545
- element.nodes.forEach(node => {
546
- (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.HIGHLIGHTED));
547
- let color = math_color_1.Color3.Green();
548
- if (element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]) {
549
- color = parameter_1.Parameter.parseColor(element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]);
550
- }
551
- if (typeof element._highlightLayer !== 'undefined') {
552
- (0, babylonHelper_1.addToHighlightLayer)(element._highlightLayer, color, node);
553
- }
554
- });
555
- }
556
- else if (highlighted === false) {
557
- element.nodes.forEach(node => {
558
- if (typeof element._highlightLayer !== 'undefined') {
559
- (0, babylonHelper_1.removeFromHighlightLayer)(element._highlightLayer, node);
560
- }
561
- });
562
- }
563
- }),
564
- ]);
565
- this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW, [
566
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
567
- let castShadow;
568
- try {
569
- castShadow = parameter_1.Parameter.parseBoolean(newValue);
570
- }
571
- catch (e) {
572
- return;
573
- }
574
- let lightCsl = element.inheritedParameters[parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS];
575
- if (!lightCsl) {
576
- lightCsl = element.variant.inheritedViewerLights.map(l => l.name).join(',');
577
- }
578
- if (castShadow === true) {
579
- yield this.castShadowValueHandler(lightCsl, babylonHelper_1.addToShadowGenerator);
580
- }
581
- if (castShadow === false) {
582
- yield this.castShadowValueHandler(lightCsl, babylonHelper_1.removeFromShadowGenerator);
583
- }
584
- }),
585
- ]);
586
- this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, [
587
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
588
- // TODO: Possible performance issue in combination with CAST_SHADOW, since both observers are initially called
589
- // when CAST_SHADOW and CAST_SHADOW_FROM_LIGHTS are defined in the spec.
590
- const lightCsl = element.variant.inheritedViewerLights.map(l => l.name).join(',');
591
- // cleanup all shadow generators
592
- yield this.castShadowValueHandler(lightCsl, babylonHelper_1.removeFromShadowGenerator);
593
- if (element.castShadow === true) {
594
- // if newValue is undefined or '' then set newValue to lightCsl (use all lights)
595
- if (!newValue) {
596
- newValue = lightCsl;
597
- }
598
- yield this.castShadowValueHandler(newValue, babylonHelper_1.addToShadowGenerator);
599
- }
600
- }),
601
- ]);
602
- this._parameterObservers.set(parameter_1.Parameter.RECEIVE_SHADOWS, [
603
- (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
604
- element.nodes.forEach(node => (0, babylonHelper_1.setReceiveShadows)(node, parameter_1.Parameter.parseBoolean(newValue)));
605
- }),
606
- ]);
607
- return this;
608
- }
609
- /**
610
- * Filter for nodes that are not defined or excluded in the `pathDefinitions`.
611
- */
612
- filterNode(node) {
613
- let includeTokens = [];
614
- this.pathDefinitions.include.forEach(dottedPath => {
615
- includeTokens = (0, lodash_es_1.union)(includeTokens, dottedPath_1.DottedPath.create(dottedPath).leafTokens);
616
- });
617
- const shallKeep = (dp) => {
618
- const isDirectlyIncluded = !!includeTokens.find(_dp => _dp === dp.path);
619
- const isSubOfIncluded = !!this.pathDefinitions.include.find(_dp => {
620
- return dp.path.startsWith(`${_dp}${dottedPath_1.DottedPath.DELIMITER}`);
621
- });
622
- return isDirectlyIncluded || isSubOfIncluded;
623
- };
624
- const shallExclude = (dp) => {
625
- if (!this.pathDefinitions.exclude) {
626
- return false;
627
- }
628
- return !!this.pathDefinitions.exclude.find(_dp => dp.path === _dp);
629
- };
630
- return shallKeep(node.metadata.dottedPath) && !shallExclude(node.metadata.dottedPath);
631
- }
632
- /**
633
- * Asserts whether all {@link pathDefinitions} link to a valid `Node` path.
634
- * @protected
635
- */
636
- assertPathDefinitions() {
637
- var _a;
638
- const dottedNodes = this.variant.inheritedDottedNodes;
639
- if (dottedNodes.size === 0) {
640
- throw new Error(`There are no mapped nodes for element "${this.id}".`);
641
- }
642
- const include = this.pathDefinitions.include.map(path => dottedPath_1.DottedPath.create(path).path);
643
- const exclude = (_a = this.pathDefinitions.exclude) === null || _a === void 0 ? void 0 : _a.map(path => dottedPath_1.DottedPath.create(path).path);
644
- const keys = Array.from(dottedNodes.keys()).map(dottedPath => dottedPath.path);
645
- (0, lodash_es_1.union)(include, exclude).forEach(path => {
646
- if (keys.indexOf(path) === -1) {
647
- throw new Error(`Node with path "${path}" does not exist for element "${this.id}".`);
648
- }
649
- });
650
- }
651
- /**
652
- * Handles callback for given light parameter.
653
- */
654
- castShadowValueHandler(lightCsl, mutator) {
655
- return __awaiter(this, void 0, void 0, function* () {
656
- const lights = [];
657
- for (const lightName of parameter_1.Parameter.parseCommaSeparatedList(lightCsl)) {
658
- const viewerLight = yield this.variant.getViewerLight(lightName);
659
- if (viewerLight) {
660
- lights.push(viewerLight.light);
661
- }
662
- }
663
- const shadowGenerators = lights.map(light => light === null || light === void 0 ? void 0 : light.getShadowGenerator()).filter(Boolean);
664
- shadowGenerators.forEach(generator => {
665
- this.nodes.forEach(node => {
666
- mutator(generator, node);
667
- });
668
- });
669
- });
670
- }
671
- }
672
- exports.Element = Element;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Element = void 0;
13
+ const babylonHelper_1 = require("../util/babylonHelper");
14
+ const resourceHelper_1 = require("../util/resourceHelper");
15
+ const sceneLoaderHelper_1 = require("../util/sceneLoaderHelper");
16
+ const variantParameterizable_1 = require("./../classes/variantParameterizable");
17
+ const dottedPath_1 = require("./dottedPath");
18
+ const event_1 = require("./event");
19
+ const parameter_1 = require("./parameter");
20
+ const highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
21
+ const pbrMaterial_1 = require("@babylonjs/core/Materials/PBR/pbrMaterial");
22
+ const dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
23
+ const material_1 = require("@babylonjs/core/Materials/material");
24
+ const math_color_1 = require("@babylonjs/core/Maths/math.color");
25
+ const abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
26
+ const mesh_1 = require("@babylonjs/core/Meshes/mesh");
27
+ const transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
28
+ const lodash_es_1 = require("lodash-es");
29
+ /**
30
+ * An {@link Element} of a {@link Variant}. Acts as a container for diverse definitions. Lives only in the context of a
31
+ * {@link Variant}.
32
+ *
33
+ * When used in typings, refer to via its alias {@link VariantElement} to prevent name clashes with the web APIs
34
+ * [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) class
35
+ */
36
+ class Element extends variantParameterizable_1.VariantParameterizable {
37
+ /**
38
+ * Constructor.
39
+ */
40
+ constructor(variant, name) {
41
+ var _a;
42
+ super(variant, name);
43
+ this.variant = variant;
44
+ this.name = name;
45
+ this.nodes = [];
46
+ this._dottedNodes = new Map();
47
+ if ((_a = process.env.NODE_ENV) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('dev')) {
48
+ this.assertPathDefinitions();
49
+ }
50
+ const nodes = this.variant.inheritedNodes.map(node => {
51
+ const nodeNamingStrategy = {
52
+ handler: variant.viewer.nodeNamingStrategyHandler,
53
+ payload: {
54
+ variantInstance: variant.variantInstance,
55
+ variant: variant,
56
+ variantParameterizable: this,
57
+ },
58
+ };
59
+ return (0, babylonHelper_1.cloneTransformNode)(node, nodeNamingStrategy, this.filterNode.bind(this), true);
60
+ });
61
+ this.nodes = nodes.filter(node => !!node);
62
+ this._dottedNodes = (0, babylonHelper_1.mapToDottedNodes)(this.nodes, node => node instanceof transformNode_1.TransformNode);
63
+ variant.broadcastEvent(event_1.Event.ELEMENT_NODES_CLONED, this);
64
+ this.addMissingMaterialObservers();
65
+ this.addParameterObservers();
66
+ }
67
+ /**
68
+ * Creates an {@link Element} with given name.
69
+ */
70
+ static create(variant, name) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const element = new Element(variant, name);
73
+ variant.broadcastEvent(event_1.Event.ELEMENT_CREATED, element);
74
+ return element;
75
+ });
76
+ }
77
+ /**
78
+ * The {@link DottedPath} in the built tree of {@link Element}s.
79
+ * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
80
+ */
81
+ get dottedPath() {
82
+ return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
83
+ }
84
+ /**
85
+ * The id representing a {@link DottedPath}.
86
+ */
87
+ get id() {
88
+ const dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
89
+ dottedPath.shiftPart(); // remove root
90
+ return dottedPath.path;
91
+ }
92
+ /**
93
+ * The {@link ElementDefinition} of the {@link Element}.
94
+ */
95
+ get definition() {
96
+ const definition = this.variant.structureJson.elements[this.name];
97
+ if ((0, lodash_es_1.isArray)(definition)) {
98
+ return {
99
+ paths: {
100
+ include: definition,
101
+ },
102
+ };
103
+ }
104
+ return definition;
105
+ }
106
+ /**
107
+ * The {@link PathDefinitions} of the {@link Element}.
108
+ */
109
+ get pathDefinitions() {
110
+ return this.definition.paths;
111
+ }
112
+ /**
113
+ * The {@link TraceableDefinitions} of the {@link Element}.
114
+ */
115
+ get traceableDefinitions() {
116
+ return this.definition.traceables || {};
117
+ }
118
+ /**
119
+ * The {@link PaintableDefinition} of the {@link Element}.
120
+ */
121
+ get paintableDefinitions() {
122
+ return this.definition.paintables || {};
123
+ }
124
+ /**
125
+ * The inherited {@link ParameterBag}.
126
+ * Merges the {@link Variant}'s parameters and those from the {@link Element}.
127
+ */
128
+ get inheritedParameters() {
129
+ return (0, lodash_es_1.merge)({}, this.variant.inheritedParameters, this.parameters);
130
+ }
131
+ /**
132
+ * The actual {@link TransformNode}s that make up this {@link Element}.
133
+ */
134
+ get nodesFlat() {
135
+ return this.nodes.reduce((acc, cur) => [...acc, ...cur.getChildren(n => n instanceof transformNode_1.TransformNode, false)], this.nodes);
136
+ }
137
+ /**
138
+ * The actual {@link Mesh}es that make up this {@link Element}.
139
+ * Handy for e.g. creating a bounding box around an entire element.
140
+ */
141
+ get meshesFlat() {
142
+ return this.nodes.reduce((acc, cur) => [...acc, ...cur.getChildren(n => n instanceof mesh_1.Mesh, false)], this.nodes.filter(n => n instanceof mesh_1.Mesh));
143
+ }
144
+ /**
145
+ * The actual {@link AbstractMesh}es that make up this {@link Element}.
146
+ * I.e. (real) Meshes as well as InstancedMeshes.
147
+ */
148
+ get abstractMeshesFlat() {
149
+ return this.nodes.reduce((acc, cur) => [...acc, ...cur.getChildren(n => n instanceof abstractMesh_1.AbstractMesh, false)], this.nodes.filter(n => n instanceof abstractMesh_1.AbstractMesh));
150
+ }
151
+ /**
152
+ * The meshes of this {@link Element}.
153
+ */
154
+ get meshes() {
155
+ return this.nodes.filter(node => node instanceof mesh_1.Mesh);
156
+ }
157
+ /**
158
+ * @protected
159
+ */
160
+ set highlightLayer(layer) {
161
+ this._highlightLayer = layer;
162
+ }
163
+ get highlightLayer() {
164
+ return this._highlightLayer;
165
+ }
166
+ /**
167
+ * Destroys this {@link Element} and dispose all nodes.
168
+ */
169
+ destroy() {
170
+ this.nodes.forEach(node => {
171
+ node.dispose();
172
+ });
173
+ return this;
174
+ }
175
+ /**
176
+ * Gets a node by its {@link DottedPath}.
177
+ */
178
+ getNode(dottedPath) {
179
+ const _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
180
+ const keys = Array.from(this._dottedNodes.keys()).map(dp => dp.path);
181
+ const values = Array.from(this._dottedNodes.values());
182
+ const node = values[keys.indexOf(_dottedPath.path)];
183
+ if (!node) {
184
+ throw new Error(`Node with path "${_dottedPath.path}" does not exist for element "${this.id}".`);
185
+ }
186
+ return node;
187
+ }
188
+ /**
189
+ * Gets a mesh by its {@link DottedPath}.
190
+ */
191
+ getMesh(dottedPath) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ const node = yield this.getNode(dottedPath);
194
+ if (node instanceof mesh_1.Mesh) {
195
+ return node;
196
+ }
197
+ return null;
198
+ });
199
+ }
200
+ /**
201
+ * Gets a {@link PaintableDefinition} by its name.
202
+ */
203
+ getPaintableDefinition(name) {
204
+ if (!this.paintableDefinitions || !this.paintableDefinitions[name]) {
205
+ throw new Error(`No paintable "${name}" defined for element "${this.id}".`);
206
+ }
207
+ return this.paintableDefinitions[name];
208
+ }
209
+ /**
210
+ * Gets a {@link TraceableDefinition} by its name.
211
+ */
212
+ getTraceableDefinition(name) {
213
+ if (!this.traceableDefinitions || !this.traceableDefinitions[name]) {
214
+ throw new Error(`No traceable "${name}" defined to add observer in element "${this.id}".`);
215
+ }
216
+ return this.traceableDefinitions[name];
217
+ }
218
+ /**
219
+ * Gets the paintable Node by its name.
220
+ */
221
+ getPaintableNode(name) {
222
+ return this.getNode(this.getPaintableDefinition(name).path);
223
+ }
224
+ /**
225
+ * Gets the traceable Node by its name.
226
+ */
227
+ getTraceableNode(name) {
228
+ return this.getNode(this.getTraceableDefinition(name).path);
229
+ }
230
+ /**
231
+ * @see {@link VariantParameterizable.commitParameters}
232
+ * @emit {@link Event.ELEMENT_PARAMETER_COMMITTED}
233
+ */
234
+ commitParameters(parameters) {
235
+ const _super = Object.create(null, {
236
+ commitParameters: { get: () => super.commitParameters }
237
+ });
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ return _super.commitParameters.call(this, parameters);
240
+ });
241
+ }
242
+ /**
243
+ * Adds an observer function for camera matrix changes.
244
+ * The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
245
+ */
246
+ addTraceableObserver(traceable, observer, payload) {
247
+ if (payload && !(payload instanceof HTMLElement)) {
248
+ throw new Error(`Payload for camera observer must be an instance of "HTMLElement" in element "${this.id}".`);
249
+ }
250
+ if (!this.traceableDefinitions || !this.traceableDefinitions[traceable]) {
251
+ throw new Error(`No traceable "${traceable}" defined to add observer in element "${this.id}".`);
252
+ }
253
+ const node = this.getTraceableNode(traceable);
254
+ if (!(node instanceof abstractMesh_1.AbstractMesh)) {
255
+ throw new Error(`The path must be an instance of "AbstractMesh" for camera observer in element "${this.id}".`);
256
+ }
257
+ this.variant.viewer.sceneManager.activeCamera.onViewMatrixChangedObservable.add((eventData, eventState) => {
258
+ const position = (0, babylonHelper_1.getClientRectFromMesh)(node, this.variant.viewer.scene, this.variant.viewer.canvas);
259
+ if (payload) {
260
+ payload.style.top = `${position.top}px`;
261
+ payload.style.left = `${position.left}px`;
262
+ }
263
+ observer(node, position);
264
+ });
265
+ return this;
266
+ }
267
+ /**
268
+ * Draws a `ImageBitmap` or `OffscreenCanvas` onto a `paintable` defined via {@link PaintableDefinition}.
269
+ */
270
+ drawPaintable(paintable, imageSource) {
271
+ // node and material checks and preperation
272
+ const node = this.getPaintableNode(paintable);
273
+ if (!(node instanceof abstractMesh_1.AbstractMesh)) {
274
+ throw new Error(`The path must be an instance of "AbstractMesh" for paintable "${paintable}" ` + `in element "${this.id}".`);
275
+ }
276
+ if (node.material && this.variant.viewer.cloneMaterialsOnMutation) {
277
+ if (node.material && !(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
278
+ (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
279
+ }
280
+ if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.texture')) {
281
+ // inject initial value and mark as dirty
282
+ (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { texture: true } } });
283
+ }
284
+ }
285
+ else if (!node.material) {
286
+ // paintables should also work if no material is assigned to the node per default
287
+ // in this case a certain fallback material with fitting default values is defined
288
+ const pbrMat = new pbrMaterial_1.PBRMaterial(`${this.id}.${paintable}.material`, this.variant.viewer.scene);
289
+ pbrMat.roughness = 1.0;
290
+ pbrMat.metallic = 1.0;
291
+ node.material = pbrMat;
292
+ }
293
+ // TODO: Not sure if this really should be overwritten every time the paintable is redrawn.
294
+ // Maybe the 3D artist had something in mind when setting a certain transparency mode, which would get overwritten
295
+ // in this case.
296
+ // Applying it as a default if no material is set is fine though (see roughness/metallic some lines above).
297
+ // Removing this line will most likely break existing configurators, so be cautios!
298
+ node.material.transparencyMode = material_1.Material.MATERIAL_ALPHATESTANDBLEND;
299
+ // consider width and height of the paintable
300
+ const widthAndHeight = {
301
+ width: imageSource.width,
302
+ height: imageSource.height,
303
+ };
304
+ const paintableDefinition = this.getPaintableDefinition(paintable);
305
+ if ((0, lodash_es_1.isNumber)(paintableDefinition.textureOptions)) {
306
+ widthAndHeight.width = paintableDefinition.textureOptions;
307
+ widthAndHeight.height = paintableDefinition.textureOptions;
308
+ }
309
+ else if ((0, lodash_es_1.isPlainObject)(paintableDefinition.textureOptions)) {
310
+ widthAndHeight.width = paintableDefinition.textureOptions.width;
311
+ widthAndHeight.height = paintableDefinition.textureOptions.height;
312
+ }
313
+ // create dynamic texture on which the image can be drawn
314
+ const texture = new dynamicTexture_1.DynamicTexture(`${this.id}.${paintable}.texture`, widthAndHeight, this.variant.viewer.scene, false);
315
+ // draw image on texture
316
+ const ctx = texture.getContext();
317
+ ctx.drawImage(imageSource, 0, 0);
318
+ texture.update(false);
319
+ // finally apply the texture on the desired node material
320
+ (0, babylonHelper_1.setMaterialTexture)(node, texture, false);
321
+ return this;
322
+ }
323
+ /**
324
+ * Draws a SVG string onto a `paintable` defined via {@link PaintableDefinition}.
325
+ */
326
+ drawPaintableFromSvg(paintable, svgSource) {
327
+ return __awaiter(this, void 0, void 0, function* () {
328
+ const image = yield (0, resourceHelper_1.createImageFromSvg)(svgSource);
329
+ return this.drawPaintable(paintable, image);
330
+ });
331
+ }
332
+ /**
333
+ * Draws an Image from source (URL/URI) onto a `paintable` defined via {@link PaintableDefinition}.
334
+ */
335
+ drawPaintableFromImgSrc(paintable, imgSource) {
336
+ return __awaiter(this, void 0, void 0, function* () {
337
+ const image = yield (0, resourceHelper_1.createImageFromImgSrc)(imgSource);
338
+ return this.drawPaintable(paintable, image);
339
+ });
340
+ }
341
+ /**
342
+ * Adds observers for loading missing materials where needed
343
+ */
344
+ addMissingMaterialObservers() {
345
+ for (const abstractMesh of this.abstractMeshesFlat) {
346
+ (0, sceneLoaderHelper_1.addMissingMaterialObserver)(abstractMesh);
347
+ }
348
+ }
349
+ /**
350
+ * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
351
+ */
352
+ addParameterObservers() {
353
+ this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
354
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
355
+ let visible;
356
+ try {
357
+ visible = parameter_1.Parameter.parseBoolean(newValue);
358
+ }
359
+ catch (e) {
360
+ return;
361
+ }
362
+ if (visible === true) {
363
+ // Override visible state and materials if tag manager is in use to support texture lazy loading
364
+ if (element.variant.viewer.tagManager.parameters.size > 0) {
365
+ const hiddenNodeNames = [];
366
+ element.variant.viewer.tagManager.parameters.forEach((parameterBag, subject) => {
367
+ const nodes = element.variant.viewer.tagManager.getNodesBySubject(subject);
368
+ const visibleParamValue = parameterBag[parameter_1.Parameter.VISIBLE];
369
+ const isVisible = undefined === visibleParamValue || parameter_1.Parameter.parseBoolean(visibleParamValue);
370
+ if (!isVisible) {
371
+ hiddenNodeNames.push(...nodes.map(node => node.name));
372
+ }
373
+ // overwrite materials immediatly, so that original material of node doesn't get loaded, since it could
374
+ // be exchanged by the tag manager
375
+ if (parameterBag[parameter_1.Parameter.MATERIAL]) {
376
+ nodes.forEach(node => (0, babylonHelper_1.setMaterial)(node, parameterBag[parameter_1.Parameter.MATERIAL], false));
377
+ }
378
+ });
379
+ // enable all nodes that are not explicitely hidden by the tag manager
380
+ element.nodesFlat.map(node => {
381
+ if (!hiddenNodeNames.includes(node.name)) {
382
+ node.setEnabled(true);
383
+ }
384
+ });
385
+ return;
386
+ }
387
+ // The default behaviour.
388
+ element.nodes.forEach(node => {
389
+ (0, babylonHelper_1.injectNodeMetadata)(node, { visibility: node.isEnabled() });
390
+ (0, babylonHelper_1.activateTransformNode)(node);
391
+ });
392
+ }
393
+ else if (visible === false) {
394
+ element.nodes.forEach(node => {
395
+ (0, babylonHelper_1.injectNodeMetadata)(node, { visibility: node.isEnabled() });
396
+ (0, babylonHelper_1.deactivateTransformNode)(node);
397
+ });
398
+ }
399
+ }),
400
+ ]);
401
+ this._parameterObservers.set(parameter_1.Parameter.SCALING, [
402
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
403
+ // we have to deal just with root nodes here due to relative impacts in a node tree
404
+ element.nodes.forEach(node => (0, babylonHelper_1.transformTransformNode)(node, {
405
+ scaling: parameter_1.Parameter.parseVector(newValue),
406
+ position: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.POSITION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.POSITION)),
407
+ rotation: parameter_1.Parameter.parseRotation(element.inheritedParameters[parameter_1.Parameter.ROTATION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.ROTATION)),
408
+ }));
409
+ }),
410
+ ]);
411
+ this._parameterObservers.set(parameter_1.Parameter.POSITION, [
412
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
413
+ // we have to deal just with root nodes here due to relative impacts in a node tree
414
+ element.nodes.forEach(node => (0, babylonHelper_1.transformTransformNode)(node, {
415
+ scaling: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.SCALING] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.SCALING)),
416
+ position: parameter_1.Parameter.parseVector(newValue),
417
+ rotation: parameter_1.Parameter.parseRotation(element.inheritedParameters[parameter_1.Parameter.ROTATION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.ROTATION)),
418
+ }));
419
+ }),
420
+ ]);
421
+ this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
422
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
423
+ // we have to deal just with root nodes here due to relative impacts in a node tree
424
+ element.nodes.forEach(node => (0, babylonHelper_1.transformTransformNode)(node, {
425
+ scaling: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.SCALING] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.SCALING)),
426
+ position: parameter_1.Parameter.parseVector(element.inheritedParameters[parameter_1.Parameter.POSITION] || parameter_1.Parameter.getDefaultValue(parameter_1.Parameter.POSITION)),
427
+ rotation: parameter_1.Parameter.parseRotation(newValue),
428
+ }));
429
+ }),
430
+ ]);
431
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL, [
432
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
433
+ const materialName = newValue.toString();
434
+ for (const node of element.nodes) {
435
+ (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL));
436
+ (0, babylonHelper_1.setMaterial)(node, materialName, true, element.variant);
437
+ }
438
+ }),
439
+ ]);
440
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_COLOR, [
441
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
442
+ const color = parameter_1.Parameter.parseColor(newValue);
443
+ element.nodes.forEach(node => {
444
+ (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL_COLOR));
445
+ if (this.variant.viewer.cloneMaterialsOnMutation) {
446
+ if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
447
+ (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
448
+ }
449
+ if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.color')) {
450
+ // inject initial value and mark as dirty
451
+ (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { color: oldValue } } });
452
+ }
453
+ }
454
+ (0, babylonHelper_1.setMaterialColor)(node, color);
455
+ });
456
+ }),
457
+ ]);
458
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_METALLNESS, [
459
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
460
+ const metallness = parameter_1.Parameter.parseNumber(newValue);
461
+ element.nodes.forEach(node => {
462
+ (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL_METALLNESS));
463
+ if (this.variant.viewer.cloneMaterialsOnMutation) {
464
+ if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
465
+ (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
466
+ }
467
+ if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.metallness')) {
468
+ // inject initial value and mark as dirty
469
+ (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { metallness: oldValue } } });
470
+ }
471
+ }
472
+ (0, babylonHelper_1.setMaterialMetallness)(node, metallness);
473
+ });
474
+ }),
475
+ ]);
476
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_ROUGHNESS, [
477
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
478
+ const roughness = parameter_1.Parameter.parseNumber(newValue);
479
+ element.nodes.forEach(node => {
480
+ (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.MATERIAL_ROUGHNESS));
481
+ if (this.variant.viewer.cloneMaterialsOnMutation) {
482
+ if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material')) {
483
+ (0, babylonHelper_1.cloneTransformNodeMaterial)(node);
484
+ }
485
+ if (!(0, lodash_es_1.has)(node.metadata, 'dirty.material.roughness')) {
486
+ // inject initial value and mark as dirty
487
+ (0, babylonHelper_1.injectNodeMetadata)(node, { dirty: { material: { roughness: oldValue } } });
488
+ }
489
+ }
490
+ (0, babylonHelper_1.setMaterialRoughness)(node, roughness);
491
+ });
492
+ }),
493
+ ]);
494
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_COLOR, [
495
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
496
+ var _a;
497
+ // trigger Parameter.HIGHLIGHTED observers
498
+ (_a = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHTED)) === null || _a === void 0 ? void 0 : _a.forEach(observer => {
499
+ observer(element, !!element.highlighted, !!element.highlighted);
500
+ });
501
+ }),
502
+ ]);
503
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_ENABLED, [
504
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
505
+ var _b;
506
+ let curr;
507
+ try {
508
+ curr = parameter_1.Parameter.parseBoolean(newValue);
509
+ }
510
+ catch (e) {
511
+ return;
512
+ }
513
+ switch (curr) {
514
+ case true:
515
+ if (element._highlightLayer) {
516
+ break;
517
+ }
518
+ element.highlightLayer = new highlightLayer_1.HighlightLayer(dottedPath_1.DottedPath.create(element.id).addPart('highlight').path, element.variant.viewer.scene);
519
+ break;
520
+ case false:
521
+ (_b = element.highlightLayer) === null || _b === void 0 ? void 0 : _b.dispose();
522
+ break;
523
+ }
524
+ }),
525
+ ]);
526
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHTED, [
527
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
528
+ var _c;
529
+ if (!element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
530
+ return;
531
+ }
532
+ // trigger Parameter.HIGHLIGHT_ENABLED observers to ensure HighlightLayer
533
+ (_c = this._parameterObservers.get(parameter_1.Parameter.HIGHLIGHT_ENABLED)) === null || _c === void 0 ? void 0 : _c.forEach(observer => {
534
+ observer(element, this.parameters[parameter_1.Parameter.HIGHLIGHT_ENABLED], true);
535
+ });
536
+ let highlighted;
537
+ try {
538
+ highlighted = parameter_1.Parameter.parseBoolean(newValue);
539
+ }
540
+ catch (e) {
541
+ return;
542
+ }
543
+ // Add/Remove meshes to previously created highlight layers.
544
+ if (highlighted === true) {
545
+ element.nodes.forEach(node => {
546
+ (0, babylonHelper_1.assertTransformNode)(node, node => (0, babylonHelper_1.assertMeshCapability)(node, parameter_1.Parameter.HIGHLIGHTED));
547
+ let color = math_color_1.Color3.Green();
548
+ if (element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]) {
549
+ color = parameter_1.Parameter.parseColor(element.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_COLOR]);
550
+ }
551
+ if (typeof element._highlightLayer !== 'undefined') {
552
+ (0, babylonHelper_1.addToHighlightLayer)(element._highlightLayer, color, node);
553
+ }
554
+ });
555
+ }
556
+ else if (highlighted === false) {
557
+ element.nodes.forEach(node => {
558
+ if (typeof element._highlightLayer !== 'undefined') {
559
+ (0, babylonHelper_1.removeFromHighlightLayer)(element._highlightLayer, node);
560
+ }
561
+ });
562
+ }
563
+ }),
564
+ ]);
565
+ this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW, [
566
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
567
+ let castShadow;
568
+ try {
569
+ castShadow = parameter_1.Parameter.parseBoolean(newValue);
570
+ }
571
+ catch (e) {
572
+ return;
573
+ }
574
+ let lightCsl = element.inheritedParameters[parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS];
575
+ if (!lightCsl) {
576
+ lightCsl = element.variant.inheritedViewerLights.map(l => l.name).join(',');
577
+ }
578
+ if (castShadow === true) {
579
+ yield this.castShadowValueHandler(lightCsl, babylonHelper_1.addToShadowGenerator);
580
+ }
581
+ if (castShadow === false) {
582
+ yield this.castShadowValueHandler(lightCsl, babylonHelper_1.removeFromShadowGenerator);
583
+ }
584
+ }),
585
+ ]);
586
+ this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, [
587
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
588
+ // TODO: Possible performance issue in combination with CAST_SHADOW, since both observers are initially called
589
+ // when CAST_SHADOW and CAST_SHADOW_FROM_LIGHTS are defined in the spec.
590
+ const lightCsl = element.variant.inheritedViewerLights.map(l => l.name).join(',');
591
+ // cleanup all shadow generators
592
+ yield this.castShadowValueHandler(lightCsl, babylonHelper_1.removeFromShadowGenerator);
593
+ if (element.castShadow === true) {
594
+ // if newValue is undefined or '' then set newValue to lightCsl (use all lights)
595
+ if (!newValue) {
596
+ newValue = lightCsl;
597
+ }
598
+ yield this.castShadowValueHandler(newValue, babylonHelper_1.addToShadowGenerator);
599
+ }
600
+ }),
601
+ ]);
602
+ this._parameterObservers.set(parameter_1.Parameter.RECEIVE_SHADOWS, [
603
+ (element, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
604
+ element.nodes.forEach(node => (0, babylonHelper_1.setReceiveShadows)(node, parameter_1.Parameter.parseBoolean(newValue)));
605
+ }),
606
+ ]);
607
+ return this;
608
+ }
609
+ /**
610
+ * Filter for nodes that are not defined or excluded in the `pathDefinitions`.
611
+ */
612
+ filterNode(node) {
613
+ let includeTokens = [];
614
+ this.pathDefinitions.include.forEach(dottedPath => {
615
+ includeTokens = (0, lodash_es_1.union)(includeTokens, dottedPath_1.DottedPath.create(dottedPath).leafTokens);
616
+ });
617
+ const shallKeep = (dp) => {
618
+ const isDirectlyIncluded = !!includeTokens.find(_dp => _dp === dp.path);
619
+ const isSubOfIncluded = !!this.pathDefinitions.include.find(_dp => {
620
+ return dp.path.startsWith(`${_dp}${dottedPath_1.DottedPath.DELIMITER}`);
621
+ });
622
+ return isDirectlyIncluded || isSubOfIncluded;
623
+ };
624
+ const shallExclude = (dp) => {
625
+ if (!this.pathDefinitions.exclude) {
626
+ return false;
627
+ }
628
+ return !!this.pathDefinitions.exclude.find(_dp => dp.path === _dp);
629
+ };
630
+ return shallKeep(node.metadata.dottedPath) && !shallExclude(node.metadata.dottedPath);
631
+ }
632
+ /**
633
+ * Asserts whether all {@link pathDefinitions} link to a valid `Node` path.
634
+ * @protected
635
+ */
636
+ assertPathDefinitions() {
637
+ var _a;
638
+ const dottedNodes = this.variant.inheritedDottedNodes;
639
+ if (dottedNodes.size === 0) {
640
+ throw new Error(`There are no mapped nodes for element "${this.id}".`);
641
+ }
642
+ const include = this.pathDefinitions.include.map(path => dottedPath_1.DottedPath.create(path).path);
643
+ const exclude = (_a = this.pathDefinitions.exclude) === null || _a === void 0 ? void 0 : _a.map(path => dottedPath_1.DottedPath.create(path).path);
644
+ const keys = Array.from(dottedNodes.keys()).map(dottedPath => dottedPath.path);
645
+ (0, lodash_es_1.union)(include, exclude).forEach(path => {
646
+ if (keys.indexOf(path) === -1) {
647
+ throw new Error(`Node with path "${path}" does not exist for element "${this.id}".`);
648
+ }
649
+ });
650
+ }
651
+ /**
652
+ * Handles callback for given light parameter.
653
+ */
654
+ castShadowValueHandler(lightCsl, mutator) {
655
+ return __awaiter(this, void 0, void 0, function* () {
656
+ const lights = [];
657
+ for (const lightName of parameter_1.Parameter.parseCommaSeparatedList(lightCsl)) {
658
+ const viewerLight = yield this.variant.getViewerLight(lightName);
659
+ if (viewerLight) {
660
+ lights.push(viewerLight.light);
661
+ }
662
+ }
663
+ const shadowGenerators = lights.map(light => light === null || light === void 0 ? void 0 : light.getShadowGenerator()).filter(Boolean);
664
+ shadowGenerators.forEach(generator => {
665
+ this.nodes.forEach(node => {
666
+ mutator(generator, node);
667
+ });
668
+ });
669
+ });
670
+ }
671
+ }
672
+ exports.Element = Element;
673
673
  //# sourceMappingURL=element.js.map