@combeenation/3d-viewer 3.0.0-rc2 → 4.0.0-alpha6

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