@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,771 +1,1127 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Variant = void 0;
4
- var tslib_1 = require("tslib");
5
- var assetContainer_1 = require("@babylonjs/core/assetContainer");
6
- require("@babylonjs/core/Loading/Plugins/babylonFileLoader");
7
- var sceneLoader_1 = require("@babylonjs/core/Loading/sceneLoader");
8
- var transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
9
- require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression");
10
- require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_transform");
11
- require("@babylonjs/loaders/glTF/2.0/glTFLoader");
12
- var lodash_es_1 = require("lodash-es");
13
- var babylonHelper_1 = require("../util/babylonHelper");
14
- var resourceHelper_1 = require("../util/resourceHelper");
15
- var dottedPath_1 = require("./dottedPath");
16
- var element_1 = require("./element");
17
- var elementParameterizable_1 = require("./elementParameterizable");
18
- var event_1 = require("./event");
19
- var parameter_1 = require("./parameter");
20
- /**
21
- * A concrete "Variant". Most of these are handled by either the {@link Viewer} or {@link VariantInstance}.
22
- */
23
- var Variant = /** @class */ (function (_super) {
24
- tslib_1.__extends(Variant, _super);
25
- /**
26
- * Constructor.
27
- */
28
- function Variant(name, _structureJson, viewer, parent) {
29
- var _this = _super.call(this, lodash_es_1.cloneDeep(_structureJson.parameterDeclaration), lodash_es_1.cloneDeep(_structureJson.parameters)) || this;
30
- _this.name = name;
31
- _this._structureJson = _structureJson;
32
- _this.viewer = viewer;
33
- _this.parent = parent;
34
- _this.elements = [];
35
- _this._children = new Map();
36
- _this._parameterObservers = new Map();
37
- /**
38
- * @internal
39
- */
40
- _this.parametersInitialized = false;
41
- for (var parameter in _structureJson.parameterDeclaration) {
42
- if (!(parameter in (_structureJson.parameters || []))) {
43
- throw new Error("No default value for parameter \"" + parameter + "\" defined.");
44
- }
45
- }
46
- _this.assetContainer = new assetContainer_1.AssetContainer(viewer.scene);
47
- _this.structureJson = lodash_es_1.cloneDeep(_structureJson);
48
- return _this;
49
- }
50
- /**
51
- * Creates a {@link Variant} based on given parameters.
52
- *
53
- * @throws Error if "gltf" property is provided without a filename
54
- */
55
- Variant.create = function (name, structureJson, viewer, parent) {
56
- return tslib_1.__awaiter(this, void 0, void 0, function () {
57
- var variant;
58
- return tslib_1.__generator(this, function (_a) {
59
- switch (_a.label) {
60
- case 0:
61
- variant = new Variant(name, structureJson, viewer, parent);
62
- return [4 /*yield*/, variant.loadAssets()];
63
- case 1:
64
- _a.sent();
65
- return [2 /*return*/, variant];
66
- }
67
- });
68
- });
69
- };
70
- Object.defineProperty(Variant.prototype, "ancestors", {
71
- /**
72
- * The ancestor {@link Variant}s ordered from top to bottom in the built tree.
73
- */
74
- get: function () {
75
- var ancestors = [];
76
- var variant = this;
77
- while (variant.parent) {
78
- ancestors.unshift(variant.parent);
79
- variant = variant.parent;
80
- }
81
- return ancestors;
82
- },
83
- enumerable: false,
84
- configurable: true
85
- });
86
- Object.defineProperty(Variant.prototype, "root", {
87
- /**
88
- * The root {@link Variant}.
89
- */
90
- get: function () {
91
- var _a;
92
- return (_a = this.ancestors[0]) !== null && _a !== void 0 ? _a : this;
93
- },
94
- enumerable: false,
95
- configurable: true
96
- });
97
- Object.defineProperty(Variant.prototype, "dottedPath", {
98
- /**
99
- * The {@link DottedPath} in the built tree of {@link Variant}s.
100
- * E.g. "_.top-1.sub-2.sub-sub-3"
101
- */
102
- get: function () {
103
- var parentIds = this.ancestors.map(function (ancestor) {
104
- return ancestor.name;
105
- });
106
- return dottedPath_1.DottedPath.createFromParts(parentIds).addPart(this.name);
107
- },
108
- enumerable: false,
109
- configurable: true
110
- });
111
- Object.defineProperty(Variant.prototype, "id", {
112
- /**
113
- * The id representing a {@link DottedPath}.
114
- */
115
- get: function () {
116
- var dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
117
- dottedPath.shiftPart(); // remove root
118
- return dottedPath.path || '_';
119
- },
120
- enumerable: false,
121
- configurable: true
122
- });
123
- Object.defineProperty(Variant.prototype, "glTF", {
124
- /**
125
- * The defined glTF Asset.
126
- */
127
- get: function () {
128
- if (this.structureJson.glTF) {
129
- if (lodash_es_1.isString(this.structureJson.glTF)) {
130
- return {
131
- rootUrl: this.structureJson.glTF,
132
- fileName: undefined
133
- };
134
- }
135
- if (lodash_es_1.isEmpty(this.structureJson.glTF.rootUrl)) {
136
- throw new Error("No \"rootUrl\" defined in \"glTF\" definition for variant \"" + this.id + "\".");
137
- }
138
- return this.structureJson.glTF;
139
- }
140
- },
141
- enumerable: false,
142
- configurable: true
143
- });
144
- Object.defineProperty(Variant.prototype, "glTFUri", {
145
- /**
146
- * The defined glTF URI.
147
- */
148
- get: function () {
149
- if (this.glTF) {
150
- return [this.glTF.rootUrl, this.glTF.fileName].join('');
151
- }
152
- },
153
- enumerable: false,
154
- configurable: true
155
- });
156
- Object.defineProperty(Variant.prototype, "inheritedGlTFUri", {
157
- /**
158
- * The inherited defined glTF URI.
159
- */
160
- get: function () {
161
- if (!this.glTFUri && this.parent) {
162
- return this.parent.inheritedGlTFUri;
163
- }
164
- return this.glTFUri;
165
- },
166
- enumerable: false,
167
- configurable: true
168
- });
169
- Object.defineProperty(Variant.prototype, "nodes", {
170
- /**
171
- * The TransformNodes of the {@link Variant}.
172
- */
173
- get: function () {
174
- var rootNodes = this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode && !n.parent; });
175
- return rootNodes;
176
- },
177
- enumerable: false,
178
- configurable: true
179
- });
180
- Object.defineProperty(Variant.prototype, "dottedNodes", {
181
- /**
182
- * All TransformNodes of the {@link Variant} mapped flat with a {@link DottedPath}.
183
- */
184
- get: function () {
185
- if (!this._dottedNodes) {
186
- var nodes = this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode; });
187
- var dottedNodes_1 = new Map();
188
- nodes.forEach(function (node) {
189
- dottedNodes_1.set(node.metadata.dottedPath, node);
190
- });
191
- this._dottedNodes = dottedNodes_1;
192
- }
193
- return this._dottedNodes;
194
- },
195
- enumerable: false,
196
- configurable: true
197
- });
198
- Object.defineProperty(Variant.prototype, "materials", {
199
- /**
200
- * The Materials of the {@link Variant}.
201
- */
202
- get: function () {
203
- return this.assetContainer.materials;
204
- },
205
- enumerable: false,
206
- configurable: true
207
- });
208
- Object.defineProperty(Variant.prototype, "inheritedElements", {
209
- /**
210
- * All {@link Element}s from this {@link Variant}'s parents.
211
- */
212
- get: function () {
213
- var elements = [];
214
- this.ancestors.forEach(function (ancestor) {
215
- elements = lodash_es_1.concat(elements, ancestor.elements);
216
- });
217
- return lodash_es_1.concat(elements, this.elements);
218
- },
219
- enumerable: false,
220
- configurable: true
221
- });
222
- Object.defineProperty(Variant.prototype, "inheritedNodes", {
223
- /**
224
- * All TransformNodes inherited from this {@link Variant}'s parents.
225
- */
226
- get: function () {
227
- var nodes = [];
228
- this.ancestors.forEach(function (ancestor) {
229
- nodes = lodash_es_1.concat(nodes, ancestor.nodes);
230
- });
231
- return lodash_es_1.concat(nodes, this.nodes);
232
- },
233
- enumerable: false,
234
- configurable: true
235
- });
236
- Object.defineProperty(Variant.prototype, "inheritedDottedNodes", {
237
- /**
238
- * All TransformNodes inherited from this {@link Variant}'s parents mapped flat with a {@link DottedPath}.
239
- */
240
- get: function () {
241
- var dottedNodes = this.dottedNodes;
242
- this.ancestors.forEach(function (ancestor) {
243
- dottedNodes = resourceHelper_1.mergeMaps(dottedNodes, ancestor.dottedNodes);
244
- });
245
- return dottedNodes;
246
- },
247
- enumerable: false,
248
- configurable: true
249
- });
250
- Object.defineProperty(Variant.prototype, "inheritedParameterDeclaration", {
251
- /**
252
- * The {@link ParameterDeclarations} inherited from this {@link Variant}'s parents.
253
- */
254
- get: function () {
255
- var declaration = {};
256
- this.ancestors.forEach(function (ancestor) {
257
- lodash_es_1.merge(declaration, ancestor.parameterDeclaration);
258
- });
259
- return lodash_es_1.merge(declaration, this.parameterDeclaration);
260
- },
261
- enumerable: false,
262
- configurable: true
263
- });
264
- Object.defineProperty(Variant.prototype, "inheritedParameters", {
265
- /**
266
- * The {@link ParameterBag} inherited from this {@link Variant}'s parents.
267
- */
268
- get: function () {
269
- var parameters = {};
270
- this.ancestors.forEach(function (ancestor) {
271
- lodash_es_1.merge(parameters, ancestor.parameters);
272
- });
273
- return lodash_es_1.merge(parameters, this.parameters);
274
- },
275
- enumerable: false,
276
- configurable: true
277
- });
278
- Object.defineProperty(Variant.prototype, "inheritedMaterials", {
279
- /**
280
- * All Materials from this {@link Variant}'s parents.
281
- */
282
- get: function () {
283
- var materials = [];
284
- this.ancestors.forEach(function (ancestor) {
285
- materials = lodash_es_1.concat(materials, ancestor.materials);
286
- });
287
- return lodash_es_1.concat(materials, this.materials);
288
- },
289
- enumerable: false,
290
- configurable: true
291
- });
292
- /**
293
- * Gets the direct children of the current {@link Variant}.
294
- */
295
- Variant.prototype.getChildren = function () {
296
- return tslib_1.__awaiter(this, void 0, void 0, function () {
297
- var children, _a, _b, _i, name_1, _c, _d;
298
- return tslib_1.__generator(this, function (_e) {
299
- switch (_e.label) {
300
- case 0:
301
- children = [];
302
- _a = [];
303
- for (_b in this.structureJson.variants)
304
- _a.push(_b);
305
- _i = 0;
306
- _e.label = 1;
307
- case 1:
308
- if (!(_i < _a.length)) return [3 /*break*/, 4];
309
- name_1 = _a[_i];
310
- _d = (_c = children).push;
311
- return [4 /*yield*/, this.getDescendant(name_1)];
312
- case 2:
313
- _d.apply(_c, [_e.sent()]);
314
- _e.label = 3;
315
- case 3:
316
- _i++;
317
- return [3 /*break*/, 1];
318
- case 4: return [2 /*return*/, children];
319
- }
320
- });
321
- });
322
- };
323
- /**
324
- * Gets a descendant {@link Variant} of the current {@link Variant} relative to its {@link DottedPath}.
325
- * If you have the dotted path `_.product_x.variant_blue.with_yellow_highlight` in a tree and you operate on the
326
- * `product_x`, you can call `this.getDescendant('variant_blue.with_yellow_highlight')` to get the lowermost
327
- * {@link Variant}.
328
- */
329
- Variant.prototype.getDescendant = function (dottedPath) {
330
- return tslib_1.__awaiter(this, void 0, void 0, function () {
331
- var _dottedPath, _a, name, descendantParts, variant, file, _b, _c, _d;
332
- return tslib_1.__generator(this, function (_e) {
333
- switch (_e.label) {
334
- case 0:
335
- _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
336
- _a = _dottedPath.parts, name = _a[0], descendantParts = _a.slice(1);
337
- if (!this._children.has(name)) return [3 /*break*/, 1];
338
- variant = this._children.get(name);
339
- return [3 /*break*/, 7];
340
- case 1:
341
- if (!this.structureJson.variants) {
342
- throw new Error("Missing key \"variants\" in JSON structure for variant \"" + this.id + "\".");
343
- }
344
- if (!this.structureJson.variants[name]) {
345
- throw new Error("Variant \"" + _dottedPath.path + "\" not defined in JSON structure for variant \"" + this.id + "\".");
346
- }
347
- if (!this.structureJson.variants[name].file) return [3 /*break*/, 4];
348
- file = this.structureJson.variants[name].file;
349
- _c = (_b = Variant).create;
350
- _d = [name];
351
- return [4 /*yield*/, resourceHelper_1.loadJson(file)];
352
- case 2: return [4 /*yield*/, _c.apply(_b, _d.concat([_e.sent(), this.viewer, this]))];
353
- case 3:
354
- variant = _e.sent();
355
- return [3 /*break*/, 6];
356
- case 4: return [4 /*yield*/, Variant.create(name, this.structureJson.variants[name], this.viewer, this)];
357
- case 5:
358
- variant = _e.sent();
359
- _e.label = 6;
360
- case 6:
361
- this._children.set(name, variant);
362
- _e.label = 7;
363
- case 7:
364
- if (!variant) {
365
- throw new Error("Variant \"" + _dottedPath.path + "\" was not created.");
366
- }
367
- if (!(descendantParts.length > 0)) return [3 /*break*/, 9];
368
- return [4 /*yield*/, variant.getDescendant(dottedPath_1.DottedPath.createFromParts(descendantParts))];
369
- case 8: return [2 /*return*/, _e.sent()];
370
- case 9: return [2 /*return*/, variant];
371
- }
372
- });
373
- });
374
- };
375
- /**
376
- * Gets the desired {@link Element} of the current {@link Variant} relative to its {@link DottedPath}.
377
- * Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
378
- */
379
- Variant.prototype.getElement = function (dottedPath) {
380
- return tslib_1.__awaiter(this, void 0, void 0, function () {
381
- var _dottedPath, elementName, variant, element;
382
- return tslib_1.__generator(this, function (_a) {
383
- switch (_a.label) {
384
- case 0:
385
- _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
386
- elementName = _dottedPath.popPart();
387
- variant = this;
388
- if (!(_dottedPath.parts.length > 0)) return [3 /*break*/, 2];
389
- return [4 /*yield*/, this.getDescendant(_dottedPath)];
390
- case 1:
391
- variant = _a.sent();
392
- _a.label = 2;
393
- case 2:
394
- if (variant.inheritedElements.length === 0) {
395
- throw new Error("No elements for variant \"" + variant.id + "\" found. " +
396
- "Either none are defined or they are not initialized (are you operating on the appropriate living?).");
397
- }
398
- variant.inheritedElements.forEach(function (_element) {
399
- if (_element.name === elementName) {
400
- element = _element;
401
- }
402
- });
403
- if (!element) {
404
- throw new Error("Element with name \"" + elementName + "\" does not exist for variant \"" + variant.id + "\".");
405
- }
406
- return [2 /*return*/, element];
407
- }
408
- });
409
- });
410
- };
411
- /**
412
- * A proxy for directly getting a Node from an {@link Element} by its {@link DottedPath}s.
413
- */
414
- Variant.prototype.getNode = function (elementDottedPath, nodeDottedPath) {
415
- return tslib_1.__awaiter(this, void 0, void 0, function () {
416
- var element;
417
- return tslib_1.__generator(this, function (_a) {
418
- switch (_a.label) {
419
- case 0: return [4 /*yield*/, this.getElement(elementDottedPath)];
420
- case 1:
421
- element = _a.sent();
422
- return [2 /*return*/, element.getNode(nodeDottedPath)];
423
- }
424
- });
425
- });
426
- };
427
- /**
428
- * A proxy for directly getting a Mesh from an {@link Element} by its {@link DottedPath}s.
429
- */
430
- Variant.prototype.getMesh = function (elementDottedPath, meshDottedPath) {
431
- return tslib_1.__awaiter(this, void 0, void 0, function () {
432
- var element;
433
- return tslib_1.__generator(this, function (_a) {
434
- switch (_a.label) {
435
- case 0: return [4 /*yield*/, this.getElement(elementDottedPath)];
436
- case 1:
437
- element = _a.sent();
438
- return [2 /*return*/, element.getMesh(meshDottedPath)];
439
- }
440
- });
441
- });
442
- };
443
- /**
444
- * Gets the Material defined in one of the variants glTFs by its id.
445
- */
446
- Variant.prototype.getMaterial = function (id) {
447
- for (var _i = 0, _a = this.inheritedMaterials; _i < _a.length; _i++) {
448
- var material = _a[_i];
449
- if (material.id === id) {
450
- return material;
451
- }
452
- }
453
- // fallback to dynamically created materials on scene
454
- for (var _b = 0, _c = this.viewer.scene.materials; _b < _c.length; _b++) {
455
- var material = _c[_b];
456
- if (material.id === id) {
457
- return material;
458
- }
459
- }
460
- throw new Error("Material with id \"" + id + "\" does not exist for variant \"" + this.id + "\".");
461
- };
462
- /**
463
- * Creates a living clone of this {@link Variant}. Will clone all parent {@link Variant}s in tree.
464
- *
465
- * @emit {@link Event.VARIANT_CREATED}
466
- * @ignore
467
- */
468
- Variant.prototype.createLiving = function (parameters) {
469
- var _a;
470
- return tslib_1.__awaiter(this, void 0, void 0, function () {
471
- var parent, variant;
472
- return tslib_1.__generator(this, function (_b) {
473
- switch (_b.label) {
474
- case 0: return [4 /*yield*/, ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.createLiving())];
475
- case 1:
476
- parent = _b.sent();
477
- variant = new Variant(this.name, this._structureJson, this.viewer, parent);
478
- parent === null || parent === void 0 ? void 0 : parent._children.set(variant.name, variant);
479
- variant.assetContainer = this.assetContainer;
480
- variant.parameterObservers = lodash_es_1.cloneDeep(this.parameterObservers);
481
- variant.createElements();
482
- variant.addParameterObservers();
483
- return [4 /*yield*/, variant.bootstrapParameters(parameters)];
484
- case 2:
485
- _b.sent();
486
- this.broadcastEvent(event_1.Event.VARIANT_CREATED, variant);
487
- return [2 /*return*/, variant];
488
- }
489
- });
490
- });
491
- };
492
- /**
493
- * Destroys this {@link Variant}, all parents and destroy the {@link Element}s.
494
- */
495
- Variant.prototype.destroy = function () {
496
- this.elements.forEach(function (element) { return element.destroy(); });
497
- if (this.parent) {
498
- this.parent.destroy();
499
- }
500
- this.broadcastEvent(event_1.Event.VARIANT_DESTROYED, this);
501
- return this;
502
- };
503
- /**
504
- * Places the given {@link ParameterBag} in the {@link Variant}'s parameters, replaces all patterns in the
505
- * {@link StructureJson}, broadcasts all {@link ParameterObserver}s and delegates them to its {@link Element}s.
506
- *
507
- * @emit {@link Event.VARIANT_PARAMETER_COMMITTED}
508
- */
509
- Variant.prototype.commitParameters = function (parameters) {
510
- return tslib_1.__awaiter(this, void 0, void 0, function () {
511
- var oldParameters, _parameters, parameter, value, search, mergedParameters, structureParameters, _structureParameters, parameter, value, search, replacedStructureParameters, differentStructureParameters, parameter, newParameters, structure, parameter, value, search, observerPromises, _loop_1, this_1, parameter, elementPromises;
512
- var _this = this;
513
- return tslib_1.__generator(this, function (_a) {
514
- switch (_a.label) {
515
- case 0:
516
- parameters = lodash_es_1.merge({}, parameters);
517
- oldParameters = lodash_es_1.cloneDeep(this.inheritedParameters);
518
- _parameters = JSON.stringify(parameters);
519
- for (parameter in this.inheritedParameters) {
520
- value = this.inheritedParameters[parameter];
521
- search = new RegExp("\\$\\{" + parameter + "\\}", 'g');
522
- _parameters = _parameters.replace(search, value.toString());
523
- }
524
- lodash_es_1.merge(parameters, JSON.parse(_parameters));
525
- mergedParameters = lodash_es_1.merge({}, this.inheritedParameters, parameters);
526
- structureParameters = this._structureJson.parameters || {};
527
- _structureParameters = JSON.stringify(structureParameters);
528
- for (parameter in mergedParameters) {
529
- value = mergedParameters[parameter];
530
- search = new RegExp("\\$\\{" + parameter + "\\}", 'g');
531
- _structureParameters = _structureParameters.replace(search, value.toString());
532
- }
533
- replacedStructureParameters = JSON.parse(_structureParameters);
534
- differentStructureParameters = {};
535
- for (parameter in replacedStructureParameters) {
536
- if (!lodash_es_1.isEqual(structureParameters[parameter], replacedStructureParameters[parameter])) {
537
- differentStructureParameters[parameter] = replacedStructureParameters[parameter];
538
- }
539
- }
540
- // merge replaced structure parameters and given inherited parameters to structure parameters
541
- lodash_es_1.merge(this.parameters, mergedParameters, differentStructureParameters);
542
- newParameters = this.inheritedParameters;
543
- structure = JSON.stringify(this._structureJson);
544
- for (parameter in newParameters) {
545
- value = newParameters[parameter];
546
- search = new RegExp("\\$\\{" + parameter + "\\}", 'g');
547
- structure = structure.replace(search, value.toString());
548
- }
549
- this.structureJson = JSON.parse(structure);
550
- observerPromises = [];
551
- _loop_1 = function (parameter) {
552
- var oldParameterValue = oldParameters[parameter];
553
- var newParameterValue = newParameters[parameter];
554
- this_1.assertParameter(this_1.inheritedParameterDeclaration, parameter, newParameterValue);
555
- if (oldParameterValue === newParameterValue && this_1.parametersInitialized) {
556
- return "continue";
557
- }
558
- // parameter changed
559
- var parameterObservers = resourceHelper_1.mergeMaps(this_1._parameterObservers, this_1.parameterObservers);
560
- if (parameterObservers.has(parameter)) {
561
- var observers = parameterObservers.get(parameter);
562
- observerPromises = lodash_es_1.concat(observerPromises, observers.map(function (observer) {
563
- var observerResult = observer(_this, oldParameterValue, newParameterValue);
564
- return Promise.resolve(observerResult).then(function () {
565
- if (_this.parametersInitialized) {
566
- _this.broadcastEvent(event_1.Event.VARIANT_PARAMETER_COMMITTED, _this, parameter, oldParameterValue, newParameterValue);
567
- }
568
- });
569
- }));
570
- }
571
- };
572
- this_1 = this;
573
- for (parameter in newParameters) {
574
- _loop_1(parameter);
575
- }
576
- return [4 /*yield*/, Promise.all(observerPromises)];
577
- case 1:
578
- _a.sent();
579
- // broadcast that bag has been committed
580
- this.broadcastEvent(event_1.Event.VARIANT_PARAMETER_BAG_COMMITTED, this, oldParameters, newParameters);
581
- elementPromises = this.elements.map(function (element) {
582
- var _elementDefinition = JSON.stringify(_this._structureJson.elements[element.name]);
583
- var elementParameters = {};
584
- for (var parameter in newParameters) {
585
- if (dottedPath_1.DottedPath.create(parameter).firstPart !== element.name) {
586
- continue;
587
- }
588
- // we got an element parameter
589
- var newParameterValue = newParameters[parameter];
590
- var elementParameter = parameter.replace(element.name + ".", '');
591
- // If the variant is explicitly hidden, we must not override the visibility with element parameters. We need
592
- // an exception for visibility to avoid overloading already applied element parameters with element parameters
593
- // defined in the variant spec ("dotted parameters").
594
- // @see https://github.com/Combeenation/3d-viewer/issues/44
595
- if (elementParameter === parameter_1.Parameter.VISIBLE && newParameters[parameter_1.Parameter.VISIBLE] === false) {
596
- newParameterValue = false;
597
- }
598
- elementParameters[elementParameter] = newParameterValue;
599
- var search = new RegExp("\\$\\{" + elementParameter + "\\}", 'g');
600
- _elementDefinition = _elementDefinition.replace(search, newParameterValue.toString());
601
- }
602
- _this.structureJson.elements[_this.name] = JSON.parse(_elementDefinition);
603
- return element.commitParameters(elementParameters);
604
- });
605
- return [4 /*yield*/, Promise.all(elementPromises)];
606
- case 2:
607
- _a.sent();
608
- if (!this.parent) return [3 /*break*/, 4];
609
- return [4 /*yield*/, this.parent.commitParameters(this.parameters)];
610
- case 3:
611
- _a.sent();
612
- _a.label = 4;
613
- case 4: return [2 /*return*/, this];
614
- }
615
- });
616
- });
617
- };
618
- /**
619
- * Adds an observer function for camera matrix changes for given `dottedPath` representing the {@link Element}
620
- * and the `traceable`. The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
621
- */
622
- Variant.prototype.addTraceableObserver = function (dottedPath, observer, payload) {
623
- return tslib_1.__awaiter(this, void 0, void 0, function () {
624
- var _dottedPath, traceableName, element;
625
- return tslib_1.__generator(this, function (_a) {
626
- switch (_a.label) {
627
- case 0:
628
- _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
629
- traceableName = _dottedPath.popPart();
630
- if (!traceableName) {
631
- throw new Error("The dottedPath must consist of the element and the name of the defined corresponding " +
632
- ("traceable (\"" + _dottedPath.path + "\" given)."));
633
- }
634
- return [4 /*yield*/, this.getElement(_dottedPath)];
635
- case 1:
636
- element = _a.sent();
637
- return [2 /*return*/, element.addTraceableObserver(traceableName, observer, payload)];
638
- }
639
- });
640
- });
641
- };
642
- /**
643
- * Loads {@link glTFUri} with assets, adds them to the {@link Variant}'s `assetContainer` and deactivates the meshes.
644
- * (for further processing).
645
- * @emits {@link Event.ASSET_LOADING_START}
646
- * @emits {@link Event.ASSET_LOADING_END}
647
- */
648
- Variant.prototype.loadAssets = function () {
649
- return tslib_1.__awaiter(this, void 0, void 0, function () {
650
- var _this = this;
651
- return tslib_1.__generator(this, function (_a) {
652
- this.broadcastEvent(event_1.Event.ASSET_LOADING_START, this);
653
- return [2 /*return*/, new Promise(function (resolve) {
654
- if (!_this.structureJson) {
655
- _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
656
- return resolve(_this);
657
- }
658
- if (!_this.glTF) {
659
- _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
660
- return resolve(_this);
661
- }
662
- sceneLoader_1.SceneLoader.LoadAssetContainerAsync(_this.glTF.rootUrl, _this.glTF.fileName, _this.viewer.scene).then(function (container) {
663
- _this.assetContainer = container;
664
- var nodes = _this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode; });
665
- nodes.forEach(function (node) {
666
- babylonHelper_1.deactivateTransformNode(node, false);
667
- babylonHelper_1.injectTransformNodeMetadata(node, { dottedPath: babylonHelper_1.getDottedPathForTransformNode(node) }, false);
668
- });
669
- _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
670
- resolve(_this);
671
- }).catch(function (reason) {
672
- _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
673
- throw new Error("Error loading assets for variant \"" + _this.id + "\": " + reason + ".");
674
- });
675
- })];
676
- });
677
- });
678
- };
679
- /**
680
- * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
681
- */
682
- Variant.prototype.addParameterObservers = function () {
683
- this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
684
- function (variant, oldValue, newValue) {
685
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.VISIBLE, newValue); });
686
- }
687
- ]);
688
- this._parameterObservers.set(parameter_1.Parameter.SCALING, [
689
- function (variant, oldValue, newValue) {
690
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.SCALING, newValue); });
691
- }
692
- ]);
693
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL, [
694
- function (variant, oldValue, newValue) {
695
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.MATERIAL, newValue); });
696
- }
697
- ]);
698
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_COLOR, [
699
- function (variant, oldValue, newValue) {
700
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.MATERIAL_COLOR, newValue); });
701
- }
702
- ]);
703
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_METALLNESS, [
704
- function (variant, oldValue, newValue) {
705
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.MATERIAL_METALLNESS, newValue); });
706
- }
707
- ]);
708
- this._parameterObservers.set(parameter_1.Parameter.MATERIAL_ROUGHNESS, [
709
- function (variant, oldValue, newValue) {
710
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.MATERIAL_ROUGHNESS, newValue); });
711
- }
712
- ]);
713
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_COLOR, [
714
- function (variant, oldValue, newValue) {
715
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.HIGHLIGHT_COLOR, newValue); });
716
- }
717
- ]);
718
- this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHTED, [
719
- function (variant, oldValue, newValue) {
720
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.HIGHLIGHTED, newValue); });
721
- }
722
- ]);
723
- this._parameterObservers.set(parameter_1.Parameter.POSITION, [
724
- function (variant, oldValue, newValue) {
725
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.POSITION, newValue); });
726
- }
727
- ]);
728
- this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
729
- function (variant, oldValue, newValue) {
730
- variant.elements.forEach(function (element) { return element.commitParameter(parameter_1.Parameter.ROTATION, newValue); });
731
- }
732
- ]);
733
- return this;
734
- };
735
- /**
736
- * Creates {@link Element}s and clones nodes into them.
737
- */
738
- Variant.prototype.createElements = function () {
739
- var _this = this;
740
- for (var elementName in this.structureJson.elements || {}) {
741
- this.elements.push(new element_1.Element(this, elementName));
742
- }
743
- // inject node meta to all inherited elements
744
- // we do this to inject the deepest and most concrete variant information to all cloned nodes in the tree
745
- this.inheritedElements.forEach(function (element) {
746
- element.nodes.forEach(function (node) {
747
- babylonHelper_1.injectTransformNodeMetadata(node, { variant: _this, element: element });
748
- });
749
- });
750
- return this;
751
- };
752
- /**
753
- * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
754
- */
755
- Variant.prototype.bootstrapParameters = function (parameters) {
756
- return tslib_1.__awaiter(this, void 0, void 0, function () {
757
- return tslib_1.__generator(this, function (_a) {
758
- switch (_a.label) {
759
- case 0: return [4 /*yield*/, this.commitParameters(lodash_es_1.merge(lodash_es_1.cloneDeep(this.parameters), parameters))];
760
- case 1:
761
- _a.sent();
762
- lodash_es_1.concat(this.ancestors, this).forEach(function (ancestor) { return ancestor.parametersInitialized = true; });
763
- return [2 /*return*/, this];
764
- }
765
- });
766
- });
767
- };
768
- return Variant;
769
- }(elementParameterizable_1.ElementParameterizable));
770
- exports.Variant = Variant;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Variant = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var assetContainer_1 = require("@babylonjs/core/assetContainer");
6
+ require("@babylonjs/core/Loading/Plugins/babylonFileLoader");
7
+ var sceneLoader_1 = require("@babylonjs/core/Loading/sceneLoader");
8
+ var transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
9
+ require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression");
10
+ require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_transform");
11
+ require("@babylonjs/loaders/glTF/2.0/glTFLoader");
12
+ var lodash_es_1 = require("lodash-es");
13
+ var babylonHelper_1 = require("../util/babylonHelper");
14
+ var resourceHelper_1 = require("../util/resourceHelper");
15
+ var dottedPath_1 = require("./dottedPath");
16
+ var element_1 = require("./element");
17
+ var event_1 = require("./event");
18
+ var parameter_1 = require("./parameter");
19
+ var parameterizable_1 = require("./parameterizable");
20
+ var viewerLight_1 = require("./viewerLight");
21
+ /**
22
+ * A concrete "Variant". Most of these are handled by either the {@link Viewer} or {@link VariantInstance}.
23
+ */
24
+ var Variant = /** @class */ (function (_super) {
25
+ tslib_1.__extends(Variant, _super);
26
+ /**
27
+ * Constructor.
28
+ */
29
+ function Variant(name, _structureJson, viewer, parent) {
30
+ var _this = _super.call(this, lodash_es_1.cloneDeep(_structureJson.parameterDeclaration), lodash_es_1.cloneDeep(_structureJson.parameters)) || this;
31
+ _this.name = name;
32
+ _this._structureJson = _structureJson;
33
+ _this.viewer = viewer;
34
+ _this.parent = parent;
35
+ _this.elements = [];
36
+ _this.viewerLights = [];
37
+ _this._children = new Map();
38
+ _this._parameterObservers = new Map();
39
+ /**
40
+ * @internal
41
+ */
42
+ _this.parametersInitialized = false;
43
+ for (var parameter in _structureJson.parameterDeclaration) {
44
+ if (!(parameter in (_structureJson.parameters || []))) {
45
+ throw new Error("No default value for parameter \"" + parameter + "\" defined.");
46
+ }
47
+ }
48
+ _this.assetContainer = new assetContainer_1.AssetContainer(viewer.scene);
49
+ _this.structureJson = lodash_es_1.cloneDeep(_structureJson);
50
+ return _this;
51
+ }
52
+ /**
53
+ * Creates a {@link Variant} based on given parameters.
54
+ *
55
+ * @throws Error if "gltf" property is provided without a filename
56
+ */
57
+ Variant.create = function (name, structureJson, viewer, parent) {
58
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
59
+ var variant;
60
+ return tslib_1.__generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ variant = new Variant(name, structureJson, viewer, parent);
64
+ return [4 /*yield*/, variant.loadAssets()];
65
+ case 1:
66
+ _a.sent();
67
+ return [2 /*return*/, variant];
68
+ }
69
+ });
70
+ });
71
+ };
72
+ Object.defineProperty(Variant.prototype, "ancestors", {
73
+ /**
74
+ * The ancestor {@link Variant}s ordered from top to bottom in the built tree.
75
+ */
76
+ get: function () {
77
+ var ancestors = [];
78
+ var variant = this;
79
+ while (variant.parent) {
80
+ ancestors.unshift(variant.parent);
81
+ variant = variant.parent;
82
+ }
83
+ return ancestors;
84
+ },
85
+ enumerable: false,
86
+ configurable: true
87
+ });
88
+ Object.defineProperty(Variant.prototype, "root", {
89
+ /**
90
+ * The root {@link Variant}.
91
+ */
92
+ get: function () {
93
+ var _a;
94
+ return (_a = this.ancestors[0]) !== null && _a !== void 0 ? _a : this;
95
+ },
96
+ enumerable: false,
97
+ configurable: true
98
+ });
99
+ Object.defineProperty(Variant.prototype, "dottedPath", {
100
+ /**
101
+ * The {@link DottedPath} in the built tree of {@link Variant}s.
102
+ * E.g. "_.top-1.sub-2.sub-sub-3"
103
+ */
104
+ get: function () {
105
+ var parentIds = this.ancestors.map(function (ancestor) {
106
+ return ancestor.name;
107
+ });
108
+ return dottedPath_1.DottedPath.createFromParts(parentIds).addPart(this.name);
109
+ },
110
+ enumerable: false,
111
+ configurable: true
112
+ });
113
+ Object.defineProperty(Variant.prototype, "id", {
114
+ /**
115
+ * The id representing a {@link DottedPath}.
116
+ */
117
+ get: function () {
118
+ var dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
119
+ dottedPath.shiftPart(); // remove root
120
+ return dottedPath.path || '_';
121
+ },
122
+ enumerable: false,
123
+ configurable: true
124
+ });
125
+ Object.defineProperty(Variant.prototype, "glTF", {
126
+ /**
127
+ * The defined glTF Asset.
128
+ */
129
+ get: function () {
130
+ if (this.structureJson.glTF) {
131
+ if (lodash_es_1.isString(this.structureJson.glTF)) {
132
+ return {
133
+ rootUrl: this.structureJson.glTF,
134
+ fileName: undefined
135
+ };
136
+ }
137
+ if (lodash_es_1.isEmpty(this.structureJson.glTF.rootUrl)) {
138
+ throw new Error("No \"rootUrl\" defined in \"glTF\" definition for variant \"" + this.id + "\".");
139
+ }
140
+ return this.structureJson.glTF;
141
+ }
142
+ },
143
+ enumerable: false,
144
+ configurable: true
145
+ });
146
+ Object.defineProperty(Variant.prototype, "glTFUri", {
147
+ /**
148
+ * The defined glTF URI.
149
+ */
150
+ get: function () {
151
+ if (this.glTF) {
152
+ return [this.glTF.rootUrl, this.glTF.fileName].join('');
153
+ }
154
+ },
155
+ enumerable: false,
156
+ configurable: true
157
+ });
158
+ Object.defineProperty(Variant.prototype, "inheritedGlTFUri", {
159
+ /**
160
+ * The inherited defined glTF URI.
161
+ */
162
+ get: function () {
163
+ if (!this.glTFUri && this.parent) {
164
+ return this.parent.inheritedGlTFUri;
165
+ }
166
+ return this.glTFUri;
167
+ },
168
+ enumerable: false,
169
+ configurable: true
170
+ });
171
+ Object.defineProperty(Variant.prototype, "nodes", {
172
+ /**
173
+ * The TransformNodes of the {@link Variant}.
174
+ */
175
+ get: function () {
176
+ var rootNodes = this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode && !n.parent; });
177
+ return rootNodes;
178
+ },
179
+ enumerable: false,
180
+ configurable: true
181
+ });
182
+ Object.defineProperty(Variant.prototype, "lights", {
183
+ /**
184
+ * The {@link ViewerLight}s of the {@link Variant}.
185
+ */
186
+ get: function () {
187
+ return this.assetContainer.lights;
188
+ },
189
+ enumerable: false,
190
+ configurable: true
191
+ });
192
+ Object.defineProperty(Variant.prototype, "dottedNodes", {
193
+ /**
194
+ * All TransformNodes of the {@link Variant} mapped flat with a {@link DottedPath}.
195
+ */
196
+ get: function () {
197
+ if (!this._dottedNodes) {
198
+ var nodes = this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode; });
199
+ var dottedNodes_1 = new Map();
200
+ nodes.forEach(function (node) {
201
+ dottedNodes_1.set(node.metadata.dottedPath, node);
202
+ });
203
+ this._dottedNodes = dottedNodes_1;
204
+ }
205
+ return this._dottedNodes;
206
+ },
207
+ enumerable: false,
208
+ configurable: true
209
+ });
210
+ Object.defineProperty(Variant.prototype, "materials", {
211
+ /**
212
+ * The Materials of the {@link Variant}.
213
+ */
214
+ get: function () {
215
+ return this.assetContainer.materials;
216
+ },
217
+ enumerable: false,
218
+ configurable: true
219
+ });
220
+ Object.defineProperty(Variant.prototype, "inheritedElements", {
221
+ /**
222
+ * All {@link Element}s from this {@link Variant}'s parents.
223
+ */
224
+ get: function () {
225
+ var elements = [];
226
+ this.ancestors.forEach(function (ancestor) {
227
+ elements = lodash_es_1.concat(elements, ancestor.elements);
228
+ });
229
+ return lodash_es_1.concat(elements, this.elements);
230
+ },
231
+ enumerable: false,
232
+ configurable: true
233
+ });
234
+ Object.defineProperty(Variant.prototype, "inheritedViewerLights", {
235
+ /**
236
+ * All {@link ViewerLight}s inherited from this {@link Variant}'s parents.
237
+ */
238
+ get: function () {
239
+ var viewerLights = [];
240
+ this.ancestors.forEach(function (ancestor) {
241
+ viewerLights = lodash_es_1.concat(viewerLights, ancestor.viewerLights);
242
+ });
243
+ return lodash_es_1.concat(viewerLights, this.viewerLights);
244
+ },
245
+ enumerable: false,
246
+ configurable: true
247
+ });
248
+ Object.defineProperty(Variant.prototype, "inheritedNodes", {
249
+ /**
250
+ * All TransformNodes inherited from this {@link Variant}'s parents.
251
+ */
252
+ get: function () {
253
+ var nodes = [];
254
+ this.ancestors.forEach(function (ancestor) {
255
+ nodes = lodash_es_1.concat(nodes, ancestor.nodes);
256
+ });
257
+ return lodash_es_1.concat(nodes, this.nodes);
258
+ },
259
+ enumerable: false,
260
+ configurable: true
261
+ });
262
+ Object.defineProperty(Variant.prototype, "inheritedDottedNodes", {
263
+ /**
264
+ * All TransformNodes inherited from this {@link Variant}'s parents mapped flat with a {@link DottedPath}.
265
+ */
266
+ get: function () {
267
+ var dottedNodes = this.dottedNodes;
268
+ this.ancestors.forEach(function (ancestor) {
269
+ dottedNodes = resourceHelper_1.mergeMaps(dottedNodes, ancestor.dottedNodes);
270
+ });
271
+ return dottedNodes;
272
+ },
273
+ enumerable: false,
274
+ configurable: true
275
+ });
276
+ Object.defineProperty(Variant.prototype, "inheritedLights", {
277
+ /**
278
+ * All Lights inherited from this {@link Variant}'s parents.
279
+ */
280
+ get: function () {
281
+ var lights = [];
282
+ this.ancestors.forEach(function (ancestor) {
283
+ lights = lodash_es_1.concat(lights, ancestor.lights);
284
+ });
285
+ return lodash_es_1.concat(lights, this.lights);
286
+ },
287
+ enumerable: false,
288
+ configurable: true
289
+ });
290
+ Object.defineProperty(Variant.prototype, "inheritedParameterDeclaration", {
291
+ /**
292
+ * The {@link ParameterDeclarations} inherited from this {@link Variant}'s parents.
293
+ */
294
+ get: function () {
295
+ var declaration = {};
296
+ this.ancestors.forEach(function (ancestor) {
297
+ lodash_es_1.merge(declaration, ancestor.parameterDeclaration);
298
+ });
299
+ return lodash_es_1.merge(declaration, this.parameterDeclaration);
300
+ },
301
+ enumerable: false,
302
+ configurable: true
303
+ });
304
+ Object.defineProperty(Variant.prototype, "inheritedParameters", {
305
+ /**
306
+ * The {@link ParameterBag} inherited from this {@link Variant}'s parents.
307
+ */
308
+ get: function () {
309
+ var parameters = {};
310
+ this.ancestors.forEach(function (ancestor) {
311
+ lodash_es_1.merge(parameters, ancestor.parameters);
312
+ });
313
+ return lodash_es_1.merge(parameters, this.parameters);
314
+ },
315
+ enumerable: false,
316
+ configurable: true
317
+ });
318
+ Object.defineProperty(Variant.prototype, "inheritedMaterials", {
319
+ /**
320
+ * All Materials from this {@link Variant}'s parents.
321
+ */
322
+ get: function () {
323
+ var materials = [];
324
+ this.ancestors.forEach(function (ancestor) {
325
+ materials = lodash_es_1.concat(materials, ancestor.materials);
326
+ });
327
+ return lodash_es_1.concat(materials, this.materials);
328
+ },
329
+ enumerable: false,
330
+ configurable: true
331
+ });
332
+ /**
333
+ * Gets the direct children of the current {@link Variant}.
334
+ */
335
+ Variant.prototype.getChildren = function () {
336
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
337
+ var children, _a, _b, _i, name_1, _c, _d;
338
+ return tslib_1.__generator(this, function (_e) {
339
+ switch (_e.label) {
340
+ case 0:
341
+ children = [];
342
+ _a = [];
343
+ for (_b in this.structureJson.variants)
344
+ _a.push(_b);
345
+ _i = 0;
346
+ _e.label = 1;
347
+ case 1:
348
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
349
+ name_1 = _a[_i];
350
+ _d = (_c = children).push;
351
+ return [4 /*yield*/, this.getDescendant(name_1)];
352
+ case 2:
353
+ _d.apply(_c, [_e.sent()]);
354
+ _e.label = 3;
355
+ case 3:
356
+ _i++;
357
+ return [3 /*break*/, 1];
358
+ case 4: return [2 /*return*/, children];
359
+ }
360
+ });
361
+ });
362
+ };
363
+ /**
364
+ * Gets a descendant {@link Variant} of the current {@link Variant} relative to its {@link DottedPath}.
365
+ * If you have the dotted path `_.product_x.variant_blue.with_yellow_highlight` in a tree and you operate on the
366
+ * `product_x`, you can call `this.getDescendant('variant_blue.with_yellow_highlight')` to get the lowermost
367
+ * {@link Variant}.
368
+ */
369
+ Variant.prototype.getDescendant = function (dottedPath) {
370
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
371
+ var _dottedPath, _a, name, descendantParts, variant, file, _b, _c, _d;
372
+ return tslib_1.__generator(this, function (_e) {
373
+ switch (_e.label) {
374
+ case 0:
375
+ _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
376
+ _a = _dottedPath.parts, name = _a[0], descendantParts = _a.slice(1);
377
+ if (!this._children.has(name)) return [3 /*break*/, 1];
378
+ variant = this._children.get(name);
379
+ return [3 /*break*/, 7];
380
+ case 1:
381
+ if (!this.structureJson.variants) {
382
+ throw new Error("Missing key \"variants\" in JSON structure for variant \"" + this.id + "\".");
383
+ }
384
+ if (!this.structureJson.variants[name]) {
385
+ throw new Error("Variant \"" + _dottedPath.path + "\" not defined in JSON structure for variant \"" + this.id + "\".");
386
+ }
387
+ if (!this.structureJson.variants[name].file) return [3 /*break*/, 4];
388
+ file = this.structureJson.variants[name].file;
389
+ _c = (_b = Variant).create;
390
+ _d = [name];
391
+ return [4 /*yield*/, resourceHelper_1.loadJson(file)];
392
+ case 2: return [4 /*yield*/, _c.apply(_b, _d.concat([_e.sent(), this.viewer, this]))];
393
+ case 3:
394
+ variant = _e.sent();
395
+ return [3 /*break*/, 6];
396
+ case 4: return [4 /*yield*/, Variant.create(name, this.structureJson.variants[name], this.viewer, this)];
397
+ case 5:
398
+ variant = _e.sent();
399
+ _e.label = 6;
400
+ case 6:
401
+ this._children.set(name, variant);
402
+ _e.label = 7;
403
+ case 7:
404
+ if (!variant) {
405
+ throw new Error("Variant \"" + _dottedPath.path + "\" was not created.");
406
+ }
407
+ if (!(descendantParts.length > 0)) return [3 /*break*/, 9];
408
+ return [4 /*yield*/, variant.getDescendant(dottedPath_1.DottedPath.createFromParts(descendantParts))];
409
+ case 8: return [2 /*return*/, _e.sent()];
410
+ case 9: return [2 /*return*/, variant];
411
+ }
412
+ });
413
+ });
414
+ };
415
+ /**
416
+ * Gets the desired {@link Element} of the current {@link Variant} relative to its {@link DottedPath}.
417
+ * Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
418
+ */
419
+ Variant.prototype.getElement = function (dottedPath) {
420
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
421
+ var _dottedPath, elementName, variant, element;
422
+ return tslib_1.__generator(this, function (_a) {
423
+ switch (_a.label) {
424
+ case 0:
425
+ _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
426
+ elementName = _dottedPath.popPart();
427
+ variant = this;
428
+ if (!(_dottedPath.parts.length > 0)) return [3 /*break*/, 2];
429
+ return [4 /*yield*/, this.getDescendant(_dottedPath)];
430
+ case 1:
431
+ variant = _a.sent();
432
+ _a.label = 2;
433
+ case 2:
434
+ if (variant.inheritedElements.length === 0) {
435
+ throw new Error("No elements for variant \"" + variant.id + "\" found. " +
436
+ "Either none are defined or they are not initialized (are you operating on the appropriate living?).");
437
+ }
438
+ variant.inheritedElements.forEach(function (_element) {
439
+ if (_element.name === elementName) {
440
+ element = _element;
441
+ }
442
+ });
443
+ if (!element) {
444
+ throw new Error("Element with name \"" + elementName + "\" does not exist for variant \"" + variant.id + "\".");
445
+ }
446
+ return [2 /*return*/, element];
447
+ }
448
+ });
449
+ });
450
+ };
451
+ /**
452
+ * Gets the desired {@link ViewerLight} of the current {@link Variant} relative to its {@link DottedPath}.
453
+ * Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
454
+ */
455
+ Variant.prototype.getViewerLight = function (dottedPath) {
456
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
457
+ var _dottedPath, viewerLightName, variant, viewerLight;
458
+ return tslib_1.__generator(this, function (_a) {
459
+ switch (_a.label) {
460
+ case 0:
461
+ _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
462
+ viewerLightName = _dottedPath.popPart();
463
+ variant = this;
464
+ if (!(_dottedPath.parts.length > 0)) return [3 /*break*/, 2];
465
+ return [4 /*yield*/, this.getDescendant(_dottedPath)];
466
+ case 1:
467
+ variant = _a.sent();
468
+ _a.label = 2;
469
+ case 2:
470
+ if (variant.inheritedViewerLights.length === 0) {
471
+ throw new Error("No viewerLights for variant \"" + variant.id + "\" found. " +
472
+ "Either none are defined or they are not initialized (are you operating on the appropriate living?).");
473
+ }
474
+ variant.inheritedViewerLights.forEach(function (_viewerLight) {
475
+ if (_viewerLight.name === viewerLightName) {
476
+ viewerLight = _viewerLight;
477
+ }
478
+ });
479
+ if (!viewerLight) {
480
+ throw new Error("ViewerLight with name \"" + viewerLightName + "\" does not exist for variant \"" + variant.id + "\".");
481
+ }
482
+ return [2 /*return*/, viewerLight];
483
+ }
484
+ });
485
+ });
486
+ };
487
+ /**
488
+ * A proxy for directly getting a Node from an {@link Element} by its {@link DottedPath}s.
489
+ */
490
+ Variant.prototype.getNode = function (elementDottedPath, nodeDottedPath) {
491
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
492
+ var element;
493
+ return tslib_1.__generator(this, function (_a) {
494
+ switch (_a.label) {
495
+ case 0: return [4 /*yield*/, this.getElement(elementDottedPath)];
496
+ case 1:
497
+ element = _a.sent();
498
+ return [2 /*return*/, element.getNode(nodeDottedPath)];
499
+ }
500
+ });
501
+ });
502
+ };
503
+ /**
504
+ * A proxy for directly getting a Mesh from an {@link Element} by its {@link DottedPath}s.
505
+ */
506
+ Variant.prototype.getMesh = function (elementDottedPath, meshDottedPath) {
507
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
508
+ var element;
509
+ return tslib_1.__generator(this, function (_a) {
510
+ switch (_a.label) {
511
+ case 0: return [4 /*yield*/, this.getElement(elementDottedPath)];
512
+ case 1:
513
+ element = _a.sent();
514
+ return [2 /*return*/, element.getMesh(meshDottedPath)];
515
+ }
516
+ });
517
+ });
518
+ };
519
+ /**
520
+ * Gets the Material defined in one of the variants glTFs by its id.
521
+ */
522
+ Variant.prototype.getMaterial = function (id) {
523
+ for (var _i = 0, _a = this.inheritedMaterials; _i < _a.length; _i++) {
524
+ var material = _a[_i];
525
+ if (material.id === id) {
526
+ return material;
527
+ }
528
+ }
529
+ // fallback to dynamically created materials on scene
530
+ for (var _b = 0, _c = this.viewer.scene.materials; _b < _c.length; _b++) {
531
+ var material = _c[_b];
532
+ if (material.id === id) {
533
+ return material;
534
+ }
535
+ }
536
+ throw new Error("Material with id \"" + id + "\" does not exist for variant \"" + this.id + "\".");
537
+ };
538
+ /**
539
+ * Creates a living clone of this {@link Variant}. Will clone all parent {@link Variant}s in tree.
540
+ *
541
+ * @emit {@link Event.VARIANT_CREATED}
542
+ * @ignore
543
+ */
544
+ Variant.prototype.createLiving = function (parameters) {
545
+ var _a;
546
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
547
+ var parent, variant;
548
+ return tslib_1.__generator(this, function (_b) {
549
+ switch (_b.label) {
550
+ case 0: return [4 /*yield*/, ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.createLiving())];
551
+ case 1:
552
+ parent = _b.sent();
553
+ variant = new Variant(this.name, this._structureJson, this.viewer, parent);
554
+ parent === null || parent === void 0 ? void 0 : parent._children.set(variant.name, variant);
555
+ variant.assetContainer = this.assetContainer;
556
+ variant.parameterObservers = lodash_es_1.cloneDeep(this.parameterObservers);
557
+ return [4 /*yield*/, variant.createElements()];
558
+ case 2:
559
+ _b.sent();
560
+ return [4 /*yield*/, variant.createViewerLights()];
561
+ case 3:
562
+ _b.sent();
563
+ variant.addParameterObservers();
564
+ return [4 /*yield*/, variant.bootstrapParameters(parameters)];
565
+ case 4:
566
+ _b.sent();
567
+ this.broadcastEvent(event_1.Event.VARIANT_CREATED, variant);
568
+ return [2 /*return*/, variant];
569
+ }
570
+ });
571
+ });
572
+ };
573
+ /**
574
+ * Destroys this {@link Variant}, all parents and destroy the {@link Element}s.
575
+ */
576
+ Variant.prototype.destroy = function () {
577
+ this.elements.forEach(function (element) { return element.destroy(); });
578
+ if (this.parent) {
579
+ this.parent.destroy();
580
+ }
581
+ this.broadcastEvent(event_1.Event.VARIANT_DESTROYED, this);
582
+ return this;
583
+ };
584
+ /**
585
+ * Places the given {@link ParameterBag} in the {@link Variant}'s parameters, replaces all patterns in the
586
+ * {@link StructureJson}, broadcasts all {@link ParameterObserver}s and delegates them to its {@link Element}s.
587
+ *
588
+ * @emit {@link Event.VARIANT_PARAMETER_COMMITTED}
589
+ */
590
+ Variant.prototype.commitParameters = function (parameters) {
591
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
592
+ var oldParameters, _parameters, parameter, value, search, mergedParameters, structureParameters, _structureParameters, parameter, value, search, replacedStructureParameters, differentStructureParameters, parameter, newParameters, structure, parameter, value, search, observerPromises, _loop_1, this_1, parameter;
593
+ var _this = this;
594
+ return tslib_1.__generator(this, function (_a) {
595
+ switch (_a.label) {
596
+ case 0:
597
+ parameters = lodash_es_1.merge({}, parameters);
598
+ oldParameters = lodash_es_1.cloneDeep(this.inheritedParameters);
599
+ _parameters = JSON.stringify(parameters);
600
+ for (parameter in this.inheritedParameters) {
601
+ value = this.inheritedParameters[parameter];
602
+ search = new RegExp("\\$\\{" + parameter + "\\}", 'g');
603
+ _parameters = _parameters.replace(search, value.toString());
604
+ }
605
+ lodash_es_1.merge(parameters, JSON.parse(_parameters));
606
+ mergedParameters = lodash_es_1.merge({}, this.inheritedParameters, parameters);
607
+ structureParameters = this._structureJson.parameters || {};
608
+ _structureParameters = JSON.stringify(structureParameters);
609
+ for (parameter in mergedParameters) {
610
+ value = mergedParameters[parameter];
611
+ search = new RegExp("\\$\\{" + parameter + "\\}", 'g');
612
+ _structureParameters = _structureParameters.replace(search, value.toString());
613
+ }
614
+ replacedStructureParameters = JSON.parse(_structureParameters);
615
+ differentStructureParameters = {};
616
+ for (parameter in replacedStructureParameters) {
617
+ if (!lodash_es_1.isEqual(structureParameters[parameter], replacedStructureParameters[parameter])) {
618
+ differentStructureParameters[parameter] = replacedStructureParameters[parameter];
619
+ }
620
+ }
621
+ // merge replaced structure parameters and given inherited parameters to structure parameters
622
+ lodash_es_1.merge(this.parameters, mergedParameters, differentStructureParameters);
623
+ newParameters = this.inheritedParameters;
624
+ structure = JSON.stringify(this._structureJson);
625
+ for (parameter in newParameters) {
626
+ value = newParameters[parameter];
627
+ search = new RegExp("\\$\\{" + parameter + "\\}", 'g');
628
+ structure = structure.replace(search, value.toString());
629
+ }
630
+ this.structureJson = JSON.parse(structure);
631
+ observerPromises = [];
632
+ _loop_1 = function (parameter) {
633
+ var oldParameterValue = oldParameters[parameter];
634
+ var newParameterValue = newParameters[parameter];
635
+ this_1.assertParameter(this_1.inheritedParameterDeclaration, parameter, newParameterValue);
636
+ if (oldParameterValue === newParameterValue && this_1.parametersInitialized) {
637
+ return "continue";
638
+ }
639
+ // parameter changed
640
+ var parameterObservers = resourceHelper_1.mergeMaps(this_1._parameterObservers, this_1.parameterObservers);
641
+ if (parameterObservers.has(parameter)) {
642
+ var observers = parameterObservers.get(parameter);
643
+ observerPromises = lodash_es_1.concat(observerPromises, observers.map(function (observer) {
644
+ var observerResult = observer(_this, oldParameterValue, newParameterValue);
645
+ return Promise.resolve(observerResult).then(function () {
646
+ if (_this.parametersInitialized) {
647
+ _this.broadcastEvent(event_1.Event.VARIANT_PARAMETER_COMMITTED, _this, parameter, oldParameterValue, newParameterValue);
648
+ }
649
+ });
650
+ }));
651
+ }
652
+ };
653
+ this_1 = this;
654
+ for (parameter in newParameters) {
655
+ _loop_1(parameter);
656
+ }
657
+ return [4 /*yield*/, Promise.all(observerPromises)];
658
+ case 1:
659
+ _a.sent();
660
+ // broadcast that bag has been committed
661
+ this.broadcastEvent(event_1.Event.VARIANT_PARAMETER_BAG_COMMITTED, this, oldParameters, newParameters);
662
+ // commit parameters to elements
663
+ return [4 /*yield*/, this.commitParametersToElements(newParameters)];
664
+ case 2:
665
+ // commit parameters to elements
666
+ _a.sent();
667
+ // commit parameters to lights
668
+ return [4 /*yield*/, this.commitParametersToViewerLights(newParameters)];
669
+ case 3:
670
+ // commit parameters to lights
671
+ _a.sent();
672
+ if (!this.parent) return [3 /*break*/, 5];
673
+ return [4 /*yield*/, this.parent.commitParameters(this.parameters)];
674
+ case 4:
675
+ _a.sent();
676
+ _a.label = 5;
677
+ case 5: return [2 /*return*/, this];
678
+ }
679
+ });
680
+ });
681
+ };
682
+ /**
683
+ * Adds an observer function for camera matrix changes for given `dottedPath` representing the {@link Element}
684
+ * and the `traceable`. The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
685
+ */
686
+ Variant.prototype.addTraceableObserver = function (dottedPath, observer, payload) {
687
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
688
+ var _dottedPath, traceableName, element;
689
+ return tslib_1.__generator(this, function (_a) {
690
+ switch (_a.label) {
691
+ case 0:
692
+ _dottedPath = dottedPath_1.DottedPath.create(dottedPath);
693
+ traceableName = _dottedPath.popPart();
694
+ if (!traceableName) {
695
+ throw new Error("The dottedPath must consist of the element and the name of the defined corresponding " +
696
+ ("traceable (\"" + _dottedPath.path + "\" given)."));
697
+ }
698
+ return [4 /*yield*/, this.getElement(_dottedPath)];
699
+ case 1:
700
+ element = _a.sent();
701
+ return [2 /*return*/, element.addTraceableObserver(traceableName, observer, payload)];
702
+ }
703
+ });
704
+ });
705
+ };
706
+ /**
707
+ * Loads {@link glTFUri} with assets, adds them to the {@link Variant}'s `assetContainer` and deactivates the meshes.
708
+ * (for further processing).
709
+ * @emits {@link Event.ASSET_LOADING_START}
710
+ * @emits {@link Event.ASSET_LOADING_END}
711
+ */
712
+ Variant.prototype.loadAssets = function () {
713
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
714
+ var _this = this;
715
+ return tslib_1.__generator(this, function (_a) {
716
+ this.broadcastEvent(event_1.Event.ASSET_LOADING_START, this);
717
+ return [2 /*return*/, new Promise(function (resolve) {
718
+ if (!_this.structureJson) {
719
+ _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
720
+ return resolve(_this);
721
+ }
722
+ if (!_this.glTF) {
723
+ _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
724
+ return resolve(_this);
725
+ }
726
+ sceneLoader_1.SceneLoader.LoadAssetContainerAsync(_this.glTF.rootUrl, _this.glTF.fileName, _this.viewer.scene).then(function (container) {
727
+ _this.assetContainer = container;
728
+ var nodes = _this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode; });
729
+ nodes.forEach(function (node) {
730
+ babylonHelper_1.deactivateTransformNode(node, false);
731
+ babylonHelper_1.injectNodeMetadata(node, { dottedPath: babylonHelper_1.getDottedPathForNode(node) }, false);
732
+ });
733
+ _this.assetContainer.lights.forEach(function (light) {
734
+ light.setEnabled(false);
735
+ babylonHelper_1.injectNodeMetadata(light, { dottedPath: babylonHelper_1.getDottedPathForNode(light) }, false);
736
+ _this.viewer.scene.addLight(light);
737
+ });
738
+ _this.assetContainer.cameras.forEach(function (camera) {
739
+ camera.setEnabled(false);
740
+ babylonHelper_1.injectNodeMetadata(camera, { dottedPath: babylonHelper_1.getDottedPathForNode(camera) }, false);
741
+ _this.viewer.scene.addCamera(camera);
742
+ });
743
+ _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
744
+ resolve(_this);
745
+ }).catch(function (reason) {
746
+ _this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
747
+ throw new Error("Error loading assets for variant \"" + _this.id + "\": " + reason + ".");
748
+ });
749
+ })];
750
+ });
751
+ });
752
+ };
753
+ /**
754
+ * Commits given parameters to all {@link Element}s.
755
+ */
756
+ Variant.prototype.commitParametersToElements = function (parameters) {
757
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
758
+ var _this = this;
759
+ return tslib_1.__generator(this, function (_a) {
760
+ switch (_a.label) {
761
+ case 0: return [4 /*yield*/, Promise.all(this.elements.map(function (element) { return _this.commitParametersToVariantParameterizable(parameters, element, 'elements'); }))];
762
+ case 1:
763
+ _a.sent();
764
+ return [2 /*return*/];
765
+ }
766
+ });
767
+ });
768
+ };
769
+ /**
770
+ * Commits given parameters to all {@link ViewerLight}s.
771
+ */
772
+ Variant.prototype.commitParametersToViewerLights = function (parameters) {
773
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
774
+ var _this = this;
775
+ return tslib_1.__generator(this, function (_a) {
776
+ switch (_a.label) {
777
+ case 0: return [4 /*yield*/, Promise.all(this.viewerLights.map(function (viewerLight) { return _this.commitParametersToVariantParameterizable(parameters, viewerLight, 'lights'); }))];
778
+ case 1:
779
+ _a.sent();
780
+ return [2 /*return*/];
781
+ }
782
+ });
783
+ });
784
+ };
785
+ /**
786
+ * Commits given parameters to a {@link VariantParameterizable} and updates the according definition with given
787
+ * key in the {@link StructureJson}. The `definitionKey` "elements" for example will update the definition in
788
+ * `this.structureJson.elements`.
789
+ */
790
+ Variant.prototype.commitParametersToVariantParameterizable = function (parameters, parameterizable, definitionKey) {
791
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
792
+ var initialDefinition, initialDefinitionStr, _parameters, parameter, dpp, parameterValue, parameterizableParameter, search, definition;
793
+ return tslib_1.__generator(this, function (_a) {
794
+ switch (_a.label) {
795
+ case 0:
796
+ initialDefinition = lodash_es_1.get(this._structureJson, definitionKey)[parameterizable.name];
797
+ initialDefinitionStr = JSON.stringify(initialDefinition);
798
+ _parameters = {};
799
+ for (parameter in parameters) {
800
+ dpp = dottedPath_1.DottedPath.create(parameter);
801
+ if (dpp.shiftPart() !== parameterizable.name) {
802
+ continue;
803
+ }
804
+ parameterValue = parameters[parameter];
805
+ parameterizableParameter = dpp.path;
806
+ // If the variant is explicitly hidden, we must not override the visibility with element parameters. We need
807
+ // an exception for visibility to avoid overloading already applied element parameters with element parameters
808
+ // defined in the variant spec ("dotted parameters").
809
+ // @see https://github.com/Combeenation/3d-viewer/issues/44
810
+ if (parameterizableParameter === parameter_1.Parameter.VISIBLE && parameters[parameter_1.Parameter.VISIBLE] === false) {
811
+ parameterValue = false;
812
+ }
813
+ _parameters[parameterizableParameter] = parameterValue;
814
+ search = new RegExp("\\$\\{" + parameterizableParameter + "\\}", 'g');
815
+ initialDefinitionStr = initialDefinitionStr.replace(search, parameterValue.toString());
816
+ }
817
+ definition = lodash_es_1.get(this.structureJson, definitionKey);
818
+ definition[this.name] = JSON.parse(initialDefinitionStr);
819
+ lodash_es_1.set(this.structureJson, definitionKey, definition);
820
+ return [4 /*yield*/, parameterizable.commitParameters(_parameters)];
821
+ case 1: return [2 /*return*/, _a.sent()];
822
+ }
823
+ });
824
+ });
825
+ };
826
+ /**
827
+ * Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
828
+ */
829
+ Variant.prototype.commitParameterToElements = function (parameter, value) {
830
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
831
+ var promises, _i, _a, element;
832
+ return tslib_1.__generator(this, function (_b) {
833
+ switch (_b.label) {
834
+ case 0:
835
+ promises = [];
836
+ for (_i = 0, _a = this.elements; _i < _a.length; _i++) {
837
+ element = _a[_i];
838
+ promises.push(element.commitParameter(parameter, value));
839
+ }
840
+ return [4 /*yield*/, Promise.all(promises)];
841
+ case 1:
842
+ _b.sent();
843
+ return [2 /*return*/];
844
+ }
845
+ });
846
+ });
847
+ };
848
+ /**
849
+ * Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
850
+ */
851
+ Variant.prototype.commitParameterToViewerLights = function (parameter, value) {
852
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
853
+ var promises, _i, _a, viewerLight;
854
+ return tslib_1.__generator(this, function (_b) {
855
+ switch (_b.label) {
856
+ case 0:
857
+ promises = [];
858
+ for (_i = 0, _a = this.viewerLights; _i < _a.length; _i++) {
859
+ viewerLight = _a[_i];
860
+ promises.push(viewerLight.commitParameter(parameter, value));
861
+ }
862
+ return [4 /*yield*/, Promise.all(promises)];
863
+ case 1:
864
+ _b.sent();
865
+ return [2 /*return*/];
866
+ }
867
+ });
868
+ });
869
+ };
870
+ /**
871
+ * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
872
+ */
873
+ Variant.prototype.addParameterObservers = function () {
874
+ var _this = this;
875
+ this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
876
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
877
+ return tslib_1.__generator(this, function (_a) {
878
+ switch (_a.label) {
879
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.VISIBLE, newValue)];
880
+ case 1:
881
+ _a.sent();
882
+ return [2 /*return*/];
883
+ }
884
+ });
885
+ }); }
886
+ ]);
887
+ this._parameterObservers.set(parameter_1.Parameter.SCALING, [
888
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
889
+ return tslib_1.__generator(this, function (_a) {
890
+ switch (_a.label) {
891
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.SCALING, newValue)];
892
+ case 1:
893
+ _a.sent();
894
+ return [2 /*return*/];
895
+ }
896
+ });
897
+ }); }
898
+ ]);
899
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL, [
900
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
901
+ return tslib_1.__generator(this, function (_a) {
902
+ switch (_a.label) {
903
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.MATERIAL, newValue)];
904
+ case 1:
905
+ _a.sent();
906
+ return [2 /*return*/];
907
+ }
908
+ });
909
+ }); }
910
+ ]);
911
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_COLOR, [
912
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
913
+ return tslib_1.__generator(this, function (_a) {
914
+ switch (_a.label) {
915
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.MATERIAL_COLOR, newValue)];
916
+ case 1:
917
+ _a.sent();
918
+ return [2 /*return*/];
919
+ }
920
+ });
921
+ }); }
922
+ ]);
923
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_METALLNESS, [
924
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
925
+ return tslib_1.__generator(this, function (_a) {
926
+ switch (_a.label) {
927
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.MATERIAL_METALLNESS, newValue)];
928
+ case 1:
929
+ _a.sent();
930
+ return [2 /*return*/];
931
+ }
932
+ });
933
+ }); }
934
+ ]);
935
+ this._parameterObservers.set(parameter_1.Parameter.MATERIAL_ROUGHNESS, [
936
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
937
+ return tslib_1.__generator(this, function (_a) {
938
+ switch (_a.label) {
939
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.MATERIAL_ROUGHNESS, newValue)];
940
+ case 1:
941
+ _a.sent();
942
+ return [2 /*return*/];
943
+ }
944
+ });
945
+ }); }
946
+ ]);
947
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHT_COLOR, [
948
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
949
+ return tslib_1.__generator(this, function (_a) {
950
+ switch (_a.label) {
951
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.HIGHLIGHT_COLOR, newValue)];
952
+ case 1:
953
+ _a.sent();
954
+ return [2 /*return*/];
955
+ }
956
+ });
957
+ }); }
958
+ ]);
959
+ this._parameterObservers.set(parameter_1.Parameter.HIGHLIGHTED, [
960
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
961
+ return tslib_1.__generator(this, function (_a) {
962
+ switch (_a.label) {
963
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.HIGHLIGHTED, newValue)];
964
+ case 1:
965
+ _a.sent();
966
+ return [2 /*return*/];
967
+ }
968
+ });
969
+ }); }
970
+ ]);
971
+ this._parameterObservers.set(parameter_1.Parameter.POSITION, [
972
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
973
+ return tslib_1.__generator(this, function (_a) {
974
+ switch (_a.label) {
975
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.POSITION, newValue)];
976
+ case 1:
977
+ _a.sent();
978
+ return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.POSITION, newValue)];
979
+ case 2:
980
+ _a.sent();
981
+ return [2 /*return*/];
982
+ }
983
+ });
984
+ }); }
985
+ ]);
986
+ this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
987
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
988
+ return tslib_1.__generator(this, function (_a) {
989
+ switch (_a.label) {
990
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.ROTATION, newValue)];
991
+ case 1:
992
+ _a.sent();
993
+ return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.ROTATION, newValue)];
994
+ case 2:
995
+ _a.sent();
996
+ return [2 /*return*/];
997
+ }
998
+ });
999
+ }); }
1000
+ ]);
1001
+ this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW, [
1002
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1003
+ return tslib_1.__generator(this, function (_a) {
1004
+ switch (_a.label) {
1005
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.CAST_SHADOW, newValue)];
1006
+ case 1:
1007
+ _a.sent();
1008
+ return [2 /*return*/];
1009
+ }
1010
+ });
1011
+ }); }
1012
+ ]);
1013
+ this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, [
1014
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1015
+ return tslib_1.__generator(this, function (_a) {
1016
+ switch (_a.label) {
1017
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, newValue)];
1018
+ case 1:
1019
+ _a.sent();
1020
+ return [2 /*return*/];
1021
+ }
1022
+ });
1023
+ }); }
1024
+ ]);
1025
+ this._parameterObservers.set(parameter_1.Parameter.RECEIVE_SHADOWS, [
1026
+ function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1027
+ return tslib_1.__generator(this, function (_a) {
1028
+ switch (_a.label) {
1029
+ case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.RECEIVE_SHADOWS, newValue)];
1030
+ case 1:
1031
+ _a.sent();
1032
+ return [2 /*return*/];
1033
+ }
1034
+ });
1035
+ }); }
1036
+ ]);
1037
+ return this;
1038
+ };
1039
+ /**
1040
+ * Creates {@link Element}s and clones nodes into them.
1041
+ */
1042
+ Variant.prototype.createElements = function () {
1043
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1044
+ var _a, _b, _i, name_2, _c, _d;
1045
+ var _this = this;
1046
+ return tslib_1.__generator(this, function (_e) {
1047
+ switch (_e.label) {
1048
+ case 0:
1049
+ _a = [];
1050
+ for (_b in this.structureJson.elements || {})
1051
+ _a.push(_b);
1052
+ _i = 0;
1053
+ _e.label = 1;
1054
+ case 1:
1055
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
1056
+ name_2 = _a[_i];
1057
+ _d = (_c = this.elements).push;
1058
+ return [4 /*yield*/, element_1.Element.create(this, name_2)];
1059
+ case 2:
1060
+ _d.apply(_c, [_e.sent()]);
1061
+ _e.label = 3;
1062
+ case 3:
1063
+ _i++;
1064
+ return [3 /*break*/, 1];
1065
+ case 4:
1066
+ // inject node meta to all inherited elements
1067
+ // we do this to inject the deepest and most concrete variant information to all cloned nodes in the tree
1068
+ this.inheritedElements.forEach(function (element) {
1069
+ element.nodes.forEach(function (node) {
1070
+ babylonHelper_1.injectNodeMetadata(node, { variant: _this, element: element });
1071
+ });
1072
+ });
1073
+ return [2 /*return*/, this];
1074
+ }
1075
+ });
1076
+ });
1077
+ };
1078
+ /**
1079
+ * Creates {@link ViewerLight}s.
1080
+ */
1081
+ Variant.prototype.createViewerLights = function () {
1082
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1083
+ var _a, _b, _i, name_3, _c, _d;
1084
+ return tslib_1.__generator(this, function (_e) {
1085
+ switch (_e.label) {
1086
+ case 0:
1087
+ _a = [];
1088
+ for (_b in this.structureJson.lights || {})
1089
+ _a.push(_b);
1090
+ _i = 0;
1091
+ _e.label = 1;
1092
+ case 1:
1093
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
1094
+ name_3 = _a[_i];
1095
+ _d = (_c = this.viewerLights).push;
1096
+ return [4 /*yield*/, viewerLight_1.ViewerLight.create(this, name_3)];
1097
+ case 2:
1098
+ _d.apply(_c, [_e.sent()]);
1099
+ _e.label = 3;
1100
+ case 3:
1101
+ _i++;
1102
+ return [3 /*break*/, 1];
1103
+ case 4: return [2 /*return*/, this];
1104
+ }
1105
+ });
1106
+ });
1107
+ };
1108
+ /**
1109
+ * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
1110
+ */
1111
+ Variant.prototype.bootstrapParameters = function (parameters) {
1112
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1113
+ return tslib_1.__generator(this, function (_a) {
1114
+ switch (_a.label) {
1115
+ case 0: return [4 /*yield*/, this.commitParameters(lodash_es_1.merge(lodash_es_1.cloneDeep(this.parameters), parameters))];
1116
+ case 1:
1117
+ _a.sent();
1118
+ lodash_es_1.concat(this.ancestors, this).forEach(function (ancestor) { return ancestor.parametersInitialized = true; });
1119
+ return [2 /*return*/, this];
1120
+ }
1121
+ });
1122
+ });
1123
+ };
1124
+ return Variant;
1125
+ }(parameterizable_1.Parameterizable));
1126
+ exports.Variant = Variant;
771
1127
  //# sourceMappingURL=variant.js.map