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