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

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