@combeenation/3d-viewer 4.0.0-beta3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/lib-cjs/api/classes/element.d.ts +14 -9
- package/dist/lib-cjs/api/classes/element.js +148 -87
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/event.d.ts +15 -1
- package/dist/lib-cjs/api/classes/event.js +15 -1
- package/dist/lib-cjs/api/classes/event.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +101 -7
- package/dist/lib-cjs/api/classes/parameter.js +141 -21
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.js +11 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +2 -2
- package/dist/lib-cjs/api/classes/placementAnimation.js +11 -0
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +48 -4
- package/dist/lib-cjs/api/classes/variant.js +320 -46
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +5 -1
- package/dist/lib-cjs/api/classes/variantInstance.js +10 -0
- package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +6 -3
- package/dist/lib-cjs/api/classes/viewer.js +140 -59
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +5 -1
- package/dist/lib-cjs/api/internal/sceneSetup.js +75 -71
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +54 -4
- package/dist/lib-cjs/api/util/babylonHelper.js +160 -8
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +62 -8
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +13 -8
- package/dist/lib-cjs/api/util/resourceHelper.js +14 -14
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/index.d.ts +24 -22
- package/dist/lib-cjs/index.js +42 -38
- package/dist/lib-cjs/index.js.map +1 -1
- package/package.json +5 -5
- package/src/api/classes/element.ts +118 -91
- package/src/api/classes/event.ts +16 -1
- package/src/api/classes/parameter.ts +153 -22
- package/src/api/classes/parameterObservable.ts +9 -31
- package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +12 -1
- package/src/api/classes/placementAnimation.ts +10 -0
- package/src/api/classes/variant.ts +187 -40
- package/src/api/classes/variantInstance.ts +8 -1
- package/src/api/classes/variantParameterizable.ts +73 -0
- package/src/api/classes/viewer.ts +83 -17
- package/src/api/classes/viewerLight.ts +330 -0
- package/src/api/internal/sceneSetup.ts +99 -109
- package/src/api/util/babylonHelper.ts +173 -10
- package/src/api/util/globalTypes.ts +71 -10
- package/src/api/util/resourceHelper.ts +16 -16
- package/src/api/util/stringHelper.ts +26 -0
- package/src/dev.ts +3 -7
- package/src/index.ts +27 -23
- package/src/pagesconfig.json +4 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AssetContainer } from '@babylonjs/core/assetContainer';
|
|
2
|
+
import { Light } from '@babylonjs/core/Lights/light';
|
|
2
3
|
import '@babylonjs/core/Loading/Plugins/babylonFileLoader';
|
|
3
4
|
import { Material } from '@babylonjs/core/Materials/material';
|
|
4
5
|
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
@@ -8,8 +9,11 @@ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_transform';
|
|
|
8
9
|
import '@babylonjs/loaders/glTF/2.0/glTFLoader';
|
|
9
10
|
import { DottedPath } from './dottedPath';
|
|
10
11
|
import { Element } from './element';
|
|
11
|
-
import {
|
|
12
|
+
import { Parameterizable } from './parameterizable';
|
|
13
|
+
import { ParameterObservable } from './parameterObservable';
|
|
14
|
+
import { VariantParameterizable } from './variantParameterizable';
|
|
12
15
|
import { Viewer } from './viewer';
|
|
16
|
+
import { ViewerLight } from './viewerLight';
|
|
13
17
|
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_basisu';
|
|
14
18
|
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_clearcoat';
|
|
15
19
|
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen';
|
|
@@ -23,13 +27,14 @@ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_variants';
|
|
|
23
27
|
/**
|
|
24
28
|
* A concrete "Variant". Most of these are handled by either the {@link Viewer} or {@link VariantInstance}.
|
|
25
29
|
*/
|
|
26
|
-
export declare class Variant extends
|
|
30
|
+
export declare class Variant extends Parameterizable {
|
|
27
31
|
readonly name: string;
|
|
28
32
|
protected readonly _structureJson: StructureJson;
|
|
29
33
|
readonly viewer: Viewer;
|
|
30
34
|
readonly parent?: Variant | undefined;
|
|
31
35
|
assetContainer: AssetContainer;
|
|
32
36
|
readonly elements: Element[];
|
|
37
|
+
readonly viewerLights: ViewerLight[];
|
|
33
38
|
structureJson: StructureJson;
|
|
34
39
|
protected _dottedNodes: Map<DottedPath, TransformNode> | undefined;
|
|
35
40
|
protected readonly _children: Map<string, Variant>;
|
|
@@ -81,6 +86,10 @@ export declare class Variant extends ElementParameterizable {
|
|
|
81
86
|
* The TransformNodes of the {@link Variant}.
|
|
82
87
|
*/
|
|
83
88
|
get nodes(): TransformNode[];
|
|
89
|
+
/**
|
|
90
|
+
* The {@link ViewerLight}s of the {@link Variant}.
|
|
91
|
+
*/
|
|
92
|
+
get lights(): Light[];
|
|
84
93
|
/**
|
|
85
94
|
* All TransformNodes of the {@link Variant} mapped flat with a {@link DottedPath}.
|
|
86
95
|
*/
|
|
@@ -93,6 +102,10 @@ export declare class Variant extends ElementParameterizable {
|
|
|
93
102
|
* All {@link Element}s from this {@link Variant}'s parents.
|
|
94
103
|
*/
|
|
95
104
|
get inheritedElements(): Element[];
|
|
105
|
+
/**
|
|
106
|
+
* All {@link ViewerLight}s inherited from this {@link Variant}'s parents.
|
|
107
|
+
*/
|
|
108
|
+
get inheritedViewerLights(): ViewerLight[];
|
|
96
109
|
/**
|
|
97
110
|
* All TransformNodes inherited from this {@link Variant}'s parents.
|
|
98
111
|
*/
|
|
@@ -101,6 +114,10 @@ export declare class Variant extends ElementParameterizable {
|
|
|
101
114
|
* All TransformNodes inherited from this {@link Variant}'s parents mapped flat with a {@link DottedPath}.
|
|
102
115
|
*/
|
|
103
116
|
get inheritedDottedNodes(): Map<DottedPath, TransformNode>;
|
|
117
|
+
/**
|
|
118
|
+
* All Lights inherited from this {@link Variant}'s parents.
|
|
119
|
+
*/
|
|
120
|
+
get inheritedLights(): Light[];
|
|
104
121
|
/**
|
|
105
122
|
* The {@link ParameterDeclarations} inherited from this {@link Variant}'s parents.
|
|
106
123
|
*/
|
|
@@ -129,6 +146,11 @@ export declare class Variant extends ElementParameterizable {
|
|
|
129
146
|
* Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
|
|
130
147
|
*/
|
|
131
148
|
getElement(dottedPath: DottedPathArgument): Promise<Element>;
|
|
149
|
+
/**
|
|
150
|
+
* Gets the desired {@link ViewerLight} of the current {@link Variant} relative to its {@link DottedPath}.
|
|
151
|
+
* Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
|
|
152
|
+
*/
|
|
153
|
+
getViewerLight(dottedPath: DottedPathArgument): Promise<ViewerLight>;
|
|
132
154
|
/**
|
|
133
155
|
* A proxy for directly getting a Node from an {@link Element} by its {@link DottedPath}s.
|
|
134
156
|
*/
|
|
@@ -171,10 +193,28 @@ export declare class Variant extends ElementParameterizable {
|
|
|
171
193
|
* @emits {@link Event.ASSET_LOADING_END}
|
|
172
194
|
*/
|
|
173
195
|
protected loadAssets(): Promise<Variant>;
|
|
196
|
+
/**
|
|
197
|
+
* Commits given parameters to all {@link Element}s.
|
|
198
|
+
*/
|
|
199
|
+
protected commitParametersToElements(parameters: ParameterBag): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Commits given parameters to all {@link ViewerLight}s.
|
|
202
|
+
*/
|
|
203
|
+
protected commitParametersToViewerLights(parameters: ParameterBag): Promise<void>;
|
|
204
|
+
/**
|
|
205
|
+
* Commits given parameters to a {@link VariantParameterizable} and updates the according definition with given
|
|
206
|
+
* key in the {@link StructureJson}. The `definitionKey` "elements" for example will update the definition in
|
|
207
|
+
* `this.structureJson.elements`.
|
|
208
|
+
*/
|
|
209
|
+
protected commitParametersToVariantParameterizable(parameters: ParameterBag, parameterizable: VariantParameterizable, definitionKey: string): Promise<ParameterObservable>;
|
|
174
210
|
/**
|
|
175
211
|
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
176
212
|
*/
|
|
177
|
-
protected commitParameterToElements(parameter: string, value: ParameterValue): Promise<
|
|
213
|
+
protected commitParameterToElements(parameter: string, value: ParameterValue): Promise<Variant>;
|
|
214
|
+
/**
|
|
215
|
+
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
216
|
+
*/
|
|
217
|
+
protected commitParameterToViewerLights(parameter: string, value: ParameterValue): Promise<Variant>;
|
|
178
218
|
/**
|
|
179
219
|
* Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
|
|
180
220
|
*/
|
|
@@ -182,7 +222,11 @@ export declare class Variant extends ElementParameterizable {
|
|
|
182
222
|
/**
|
|
183
223
|
* Creates {@link Element}s and clones nodes into them.
|
|
184
224
|
*/
|
|
185
|
-
protected createElements(): Variant
|
|
225
|
+
protected createElements(): Promise<Variant>;
|
|
226
|
+
/**
|
|
227
|
+
* Creates {@link ViewerLight}s.
|
|
228
|
+
*/
|
|
229
|
+
protected createViewerLights(): Promise<Variant>;
|
|
186
230
|
/**
|
|
187
231
|
* Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
|
|
188
232
|
*/
|
|
@@ -14,9 +14,10 @@ var babylonHelper_1 = require("../util/babylonHelper");
|
|
|
14
14
|
var resourceHelper_1 = require("../util/resourceHelper");
|
|
15
15
|
var dottedPath_1 = require("./dottedPath");
|
|
16
16
|
var element_1 = require("./element");
|
|
17
|
-
var elementParameterizable_1 = require("./elementParameterizable");
|
|
18
17
|
var event_1 = require("./event");
|
|
19
18
|
var parameter_1 = require("./parameter");
|
|
19
|
+
var parameterizable_1 = require("./parameterizable");
|
|
20
|
+
var viewerLight_1 = require("./viewerLight");
|
|
20
21
|
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_basisu");
|
|
21
22
|
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_clearcoat");
|
|
22
23
|
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen");
|
|
@@ -42,6 +43,7 @@ var Variant = /** @class */ (function (_super) {
|
|
|
42
43
|
_this.viewer = viewer;
|
|
43
44
|
_this.parent = parent;
|
|
44
45
|
_this.elements = [];
|
|
46
|
+
_this.viewerLights = [];
|
|
45
47
|
_this._children = new Map();
|
|
46
48
|
_this._parameterObservers = new Map();
|
|
47
49
|
/**
|
|
@@ -187,6 +189,16 @@ var Variant = /** @class */ (function (_super) {
|
|
|
187
189
|
enumerable: false,
|
|
188
190
|
configurable: true
|
|
189
191
|
});
|
|
192
|
+
Object.defineProperty(Variant.prototype, "lights", {
|
|
193
|
+
/**
|
|
194
|
+
* The {@link ViewerLight}s of the {@link Variant}.
|
|
195
|
+
*/
|
|
196
|
+
get: function () {
|
|
197
|
+
return this.assetContainer.lights;
|
|
198
|
+
},
|
|
199
|
+
enumerable: false,
|
|
200
|
+
configurable: true
|
|
201
|
+
});
|
|
190
202
|
Object.defineProperty(Variant.prototype, "dottedNodes", {
|
|
191
203
|
/**
|
|
192
204
|
* All TransformNodes of the {@link Variant} mapped flat with a {@link DottedPath}.
|
|
@@ -229,6 +241,20 @@ var Variant = /** @class */ (function (_super) {
|
|
|
229
241
|
enumerable: false,
|
|
230
242
|
configurable: true
|
|
231
243
|
});
|
|
244
|
+
Object.defineProperty(Variant.prototype, "inheritedViewerLights", {
|
|
245
|
+
/**
|
|
246
|
+
* All {@link ViewerLight}s inherited from this {@link Variant}'s parents.
|
|
247
|
+
*/
|
|
248
|
+
get: function () {
|
|
249
|
+
var viewerLights = [];
|
|
250
|
+
this.ancestors.forEach(function (ancestor) {
|
|
251
|
+
viewerLights = lodash_es_1.concat(viewerLights, ancestor.viewerLights);
|
|
252
|
+
});
|
|
253
|
+
return lodash_es_1.concat(viewerLights, this.viewerLights);
|
|
254
|
+
},
|
|
255
|
+
enumerable: false,
|
|
256
|
+
configurable: true
|
|
257
|
+
});
|
|
232
258
|
Object.defineProperty(Variant.prototype, "inheritedNodes", {
|
|
233
259
|
/**
|
|
234
260
|
* All TransformNodes inherited from this {@link Variant}'s parents.
|
|
@@ -257,6 +283,20 @@ var Variant = /** @class */ (function (_super) {
|
|
|
257
283
|
enumerable: false,
|
|
258
284
|
configurable: true
|
|
259
285
|
});
|
|
286
|
+
Object.defineProperty(Variant.prototype, "inheritedLights", {
|
|
287
|
+
/**
|
|
288
|
+
* All Lights inherited from this {@link Variant}'s parents.
|
|
289
|
+
*/
|
|
290
|
+
get: function () {
|
|
291
|
+
var lights = [];
|
|
292
|
+
this.ancestors.forEach(function (ancestor) {
|
|
293
|
+
lights = lodash_es_1.concat(lights, ancestor.lights);
|
|
294
|
+
});
|
|
295
|
+
return lodash_es_1.concat(lights, this.lights);
|
|
296
|
+
},
|
|
297
|
+
enumerable: false,
|
|
298
|
+
configurable: true
|
|
299
|
+
});
|
|
260
300
|
Object.defineProperty(Variant.prototype, "inheritedParameterDeclaration", {
|
|
261
301
|
/**
|
|
262
302
|
* The {@link ParameterDeclarations} inherited from this {@link Variant}'s parents.
|
|
@@ -418,6 +458,42 @@ var Variant = /** @class */ (function (_super) {
|
|
|
418
458
|
});
|
|
419
459
|
});
|
|
420
460
|
};
|
|
461
|
+
/**
|
|
462
|
+
* Gets the desired {@link ViewerLight} of the current {@link Variant} relative to its {@link DottedPath}.
|
|
463
|
+
* Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
|
|
464
|
+
*/
|
|
465
|
+
Variant.prototype.getViewerLight = function (dottedPath) {
|
|
466
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
467
|
+
var _dottedPath, viewerLightName, variant, viewerLight;
|
|
468
|
+
return tslib_1.__generator(this, function (_a) {
|
|
469
|
+
switch (_a.label) {
|
|
470
|
+
case 0:
|
|
471
|
+
_dottedPath = dottedPath_1.DottedPath.create(dottedPath);
|
|
472
|
+
viewerLightName = _dottedPath.popPart();
|
|
473
|
+
variant = this;
|
|
474
|
+
if (!(_dottedPath.parts.length > 0)) return [3 /*break*/, 2];
|
|
475
|
+
return [4 /*yield*/, this.getDescendant(_dottedPath)];
|
|
476
|
+
case 1:
|
|
477
|
+
variant = _a.sent();
|
|
478
|
+
_a.label = 2;
|
|
479
|
+
case 2:
|
|
480
|
+
if (variant.inheritedViewerLights.length === 0) {
|
|
481
|
+
throw new Error("No viewerLights for variant \"" + variant.id + "\" found. " +
|
|
482
|
+
"Either none are defined or they are not initialized (are you operating on the appropriate living?).");
|
|
483
|
+
}
|
|
484
|
+
variant.inheritedViewerLights.forEach(function (_viewerLight) {
|
|
485
|
+
if (_viewerLight.name === viewerLightName) {
|
|
486
|
+
viewerLight = _viewerLight;
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
if (!viewerLight) {
|
|
490
|
+
throw new Error("ViewerLight with name \"" + viewerLightName + "\" does not exist for variant \"" + variant.id + "\".");
|
|
491
|
+
}
|
|
492
|
+
return [2 /*return*/, viewerLight];
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
};
|
|
421
497
|
/**
|
|
422
498
|
* A proxy for directly getting a Node from an {@link Element} by its {@link DottedPath}s.
|
|
423
499
|
*/
|
|
@@ -488,10 +564,15 @@ var Variant = /** @class */ (function (_super) {
|
|
|
488
564
|
parent === null || parent === void 0 ? void 0 : parent._children.set(variant.name, variant);
|
|
489
565
|
variant.assetContainer = this.assetContainer;
|
|
490
566
|
variant.parameterObservers = lodash_es_1.cloneDeep(this.parameterObservers);
|
|
491
|
-
variant.createElements();
|
|
567
|
+
return [4 /*yield*/, variant.createElements()];
|
|
568
|
+
case 2:
|
|
569
|
+
_b.sent();
|
|
570
|
+
return [4 /*yield*/, variant.createViewerLights()];
|
|
571
|
+
case 3:
|
|
572
|
+
_b.sent();
|
|
492
573
|
variant.addParameterObservers();
|
|
493
574
|
return [4 /*yield*/, variant.bootstrapParameters(parameters)];
|
|
494
|
-
case
|
|
575
|
+
case 4:
|
|
495
576
|
_b.sent();
|
|
496
577
|
this.broadcastEvent(event_1.Event.VARIANT_CREATED, variant);
|
|
497
578
|
return [2 /*return*/, variant];
|
|
@@ -518,7 +599,7 @@ var Variant = /** @class */ (function (_super) {
|
|
|
518
599
|
*/
|
|
519
600
|
Variant.prototype.commitParameters = function (parameters) {
|
|
520
601
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
521
|
-
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
|
|
602
|
+
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;
|
|
522
603
|
var _this = this;
|
|
523
604
|
return tslib_1.__generator(this, function (_a) {
|
|
524
605
|
switch (_a.label) {
|
|
@@ -588,39 +669,22 @@ var Variant = /** @class */ (function (_super) {
|
|
|
588
669
|
_a.sent();
|
|
589
670
|
// broadcast that bag has been committed
|
|
590
671
|
this.broadcastEvent(event_1.Event.VARIANT_PARAMETER_BAG_COMMITTED, this, oldParameters, newParameters);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
var elementParameters = {};
|
|
594
|
-
for (var parameter in newParameters) {
|
|
595
|
-
if (dottedPath_1.DottedPath.create(parameter).firstPart !== element.name) {
|
|
596
|
-
continue;
|
|
597
|
-
}
|
|
598
|
-
// we got an element parameter
|
|
599
|
-
var newParameterValue = newParameters[parameter];
|
|
600
|
-
var elementParameter = parameter.replace(element.name + ".", '');
|
|
601
|
-
// If the variant is explicitly hidden, we must not override the visibility with element parameters. We need
|
|
602
|
-
// an exception for visibility to avoid overloading already applied element parameters with element parameters
|
|
603
|
-
// defined in the variant spec ("dotted parameters").
|
|
604
|
-
// @see https://github.com/Combeenation/3d-viewer/issues/44
|
|
605
|
-
if (elementParameter === parameter_1.Parameter.VISIBLE && newParameters[parameter_1.Parameter.VISIBLE] === false) {
|
|
606
|
-
newParameterValue = false;
|
|
607
|
-
}
|
|
608
|
-
elementParameters[elementParameter] = newParameterValue;
|
|
609
|
-
var search = new RegExp("\\$\\{" + elementParameter + "\\}", 'g');
|
|
610
|
-
_elementDefinition = _elementDefinition.replace(search, newParameterValue.toString());
|
|
611
|
-
}
|
|
612
|
-
_this.structureJson.elements[_this.name] = JSON.parse(_elementDefinition);
|
|
613
|
-
return element.commitParameters(elementParameters);
|
|
614
|
-
});
|
|
615
|
-
return [4 /*yield*/, Promise.all(elementPromises)];
|
|
672
|
+
// commit parameters to elements
|
|
673
|
+
return [4 /*yield*/, this.commitParametersToElements(newParameters)];
|
|
616
674
|
case 2:
|
|
675
|
+
// commit parameters to elements
|
|
617
676
|
_a.sent();
|
|
618
|
-
|
|
619
|
-
return [4 /*yield*/, this.
|
|
677
|
+
// commit parameters to lights
|
|
678
|
+
return [4 /*yield*/, this.commitParametersToViewerLights(newParameters)];
|
|
620
679
|
case 3:
|
|
680
|
+
// commit parameters to lights
|
|
621
681
|
_a.sent();
|
|
622
|
-
|
|
623
|
-
|
|
682
|
+
if (!this.parent) return [3 /*break*/, 5];
|
|
683
|
+
return [4 /*yield*/, this.parent.commitParameters(this.parameters)];
|
|
684
|
+
case 4:
|
|
685
|
+
_a.sent();
|
|
686
|
+
_a.label = 5;
|
|
687
|
+
case 5: return [2 /*return*/, this];
|
|
624
688
|
}
|
|
625
689
|
});
|
|
626
690
|
});
|
|
@@ -674,7 +738,17 @@ var Variant = /** @class */ (function (_super) {
|
|
|
674
738
|
var nodes = _this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode; });
|
|
675
739
|
nodes.forEach(function (node) {
|
|
676
740
|
babylonHelper_1.deactivateTransformNode(node, false);
|
|
677
|
-
babylonHelper_1.
|
|
741
|
+
babylonHelper_1.injectNodeMetadata(node, { dottedPath: babylonHelper_1.getDottedPathForNode(node) }, false);
|
|
742
|
+
});
|
|
743
|
+
_this.assetContainer.lights.forEach(function (light) {
|
|
744
|
+
light.setEnabled(false);
|
|
745
|
+
babylonHelper_1.injectNodeMetadata(light, { dottedPath: babylonHelper_1.getDottedPathForNode(light) }, false);
|
|
746
|
+
_this.viewer.scene.addLight(light);
|
|
747
|
+
});
|
|
748
|
+
_this.assetContainer.cameras.forEach(function (camera) {
|
|
749
|
+
camera.setEnabled(false);
|
|
750
|
+
babylonHelper_1.injectNodeMetadata(camera, { dottedPath: babylonHelper_1.getDottedPathForNode(camera) }, false);
|
|
751
|
+
_this.viewer.scene.addCamera(camera);
|
|
678
752
|
});
|
|
679
753
|
_this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
|
|
680
754
|
resolve(_this);
|
|
@@ -686,6 +760,79 @@ var Variant = /** @class */ (function (_super) {
|
|
|
686
760
|
});
|
|
687
761
|
});
|
|
688
762
|
};
|
|
763
|
+
/**
|
|
764
|
+
* Commits given parameters to all {@link Element}s.
|
|
765
|
+
*/
|
|
766
|
+
Variant.prototype.commitParametersToElements = function (parameters) {
|
|
767
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
768
|
+
var _this = this;
|
|
769
|
+
return tslib_1.__generator(this, function (_a) {
|
|
770
|
+
switch (_a.label) {
|
|
771
|
+
case 0: return [4 /*yield*/, Promise.all(this.elements.map(function (element) { return _this.commitParametersToVariantParameterizable(parameters, element, 'elements'); }))];
|
|
772
|
+
case 1:
|
|
773
|
+
_a.sent();
|
|
774
|
+
return [2 /*return*/];
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
});
|
|
778
|
+
};
|
|
779
|
+
/**
|
|
780
|
+
* Commits given parameters to all {@link ViewerLight}s.
|
|
781
|
+
*/
|
|
782
|
+
Variant.prototype.commitParametersToViewerLights = function (parameters) {
|
|
783
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
784
|
+
var _this = this;
|
|
785
|
+
return tslib_1.__generator(this, function (_a) {
|
|
786
|
+
switch (_a.label) {
|
|
787
|
+
case 0: return [4 /*yield*/, Promise.all(this.viewerLights.map(function (viewerLight) { return _this.commitParametersToVariantParameterizable(parameters, viewerLight, 'lights'); }))];
|
|
788
|
+
case 1:
|
|
789
|
+
_a.sent();
|
|
790
|
+
return [2 /*return*/];
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
};
|
|
795
|
+
/**
|
|
796
|
+
* Commits given parameters to a {@link VariantParameterizable} and updates the according definition with given
|
|
797
|
+
* key in the {@link StructureJson}. The `definitionKey` "elements" for example will update the definition in
|
|
798
|
+
* `this.structureJson.elements`.
|
|
799
|
+
*/
|
|
800
|
+
Variant.prototype.commitParametersToVariantParameterizable = function (parameters, parameterizable, definitionKey) {
|
|
801
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
802
|
+
var initialDefinition, initialDefinitionStr, _parameters, parameter, dpp, parameterValue, parameterizableParameter, search, definition;
|
|
803
|
+
return tslib_1.__generator(this, function (_a) {
|
|
804
|
+
switch (_a.label) {
|
|
805
|
+
case 0:
|
|
806
|
+
initialDefinition = lodash_es_1.get(this._structureJson, definitionKey)[parameterizable.name];
|
|
807
|
+
initialDefinitionStr = JSON.stringify(initialDefinition);
|
|
808
|
+
_parameters = {};
|
|
809
|
+
for (parameter in parameters) {
|
|
810
|
+
dpp = dottedPath_1.DottedPath.create(parameter);
|
|
811
|
+
if (dpp.shiftPart() !== parameterizable.name) {
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
parameterValue = parameters[parameter];
|
|
815
|
+
parameterizableParameter = dpp.path;
|
|
816
|
+
// If the variant is explicitly hidden, we must not override the visibility with element parameters. We need
|
|
817
|
+
// an exception for visibility to avoid overloading already applied element parameters with element parameters
|
|
818
|
+
// defined in the variant spec ("dotted parameters").
|
|
819
|
+
// @see https://github.com/Combeenation/3d-viewer/issues/44
|
|
820
|
+
if (parameterizableParameter === parameter_1.Parameter.VISIBLE && parameters[parameter_1.Parameter.VISIBLE] === false) {
|
|
821
|
+
parameterValue = false;
|
|
822
|
+
}
|
|
823
|
+
_parameters[parameterizableParameter] = parameterValue;
|
|
824
|
+
search = new RegExp("\\$\\{" + parameterizableParameter + "\\}", 'g');
|
|
825
|
+
initialDefinitionStr = initialDefinitionStr.replace(search, parameterValue.toString());
|
|
826
|
+
}
|
|
827
|
+
definition = lodash_es_1.get(this.structureJson, definitionKey);
|
|
828
|
+
definition[this.name] = JSON.parse(initialDefinitionStr);
|
|
829
|
+
lodash_es_1.set(this.structureJson, definitionKey, definition);
|
|
830
|
+
return [4 /*yield*/, parameterizable.commitParameters(_parameters)];
|
|
831
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
};
|
|
689
836
|
/**
|
|
690
837
|
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
691
838
|
*/
|
|
@@ -703,7 +850,29 @@ var Variant = /** @class */ (function (_super) {
|
|
|
703
850
|
return [4 /*yield*/, Promise.all(promises)];
|
|
704
851
|
case 1:
|
|
705
852
|
_b.sent();
|
|
706
|
-
return [2 /*return
|
|
853
|
+
return [2 /*return*/, this];
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
860
|
+
*/
|
|
861
|
+
Variant.prototype.commitParameterToViewerLights = function (parameter, value) {
|
|
862
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
863
|
+
var promises, _i, _a, viewerLight;
|
|
864
|
+
return tslib_1.__generator(this, function (_b) {
|
|
865
|
+
switch (_b.label) {
|
|
866
|
+
case 0:
|
|
867
|
+
promises = [];
|
|
868
|
+
for (_i = 0, _a = this.viewerLights; _i < _a.length; _i++) {
|
|
869
|
+
viewerLight = _a[_i];
|
|
870
|
+
promises.push(viewerLight.commitParameter(parameter, value));
|
|
871
|
+
}
|
|
872
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
873
|
+
case 1:
|
|
874
|
+
_b.sent();
|
|
875
|
+
return [2 /*return*/, this];
|
|
707
876
|
}
|
|
708
877
|
});
|
|
709
878
|
});
|
|
@@ -719,6 +888,9 @@ var Variant = /** @class */ (function (_super) {
|
|
|
719
888
|
switch (_a.label) {
|
|
720
889
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.VISIBLE, newValue)];
|
|
721
890
|
case 1:
|
|
891
|
+
_a.sent();
|
|
892
|
+
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.VISIBLE, newValue)];
|
|
893
|
+
case 2:
|
|
722
894
|
_a.sent();
|
|
723
895
|
return [2 /*return*/];
|
|
724
896
|
}
|
|
@@ -731,6 +903,9 @@ var Variant = /** @class */ (function (_super) {
|
|
|
731
903
|
switch (_a.label) {
|
|
732
904
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.SCALING, newValue)];
|
|
733
905
|
case 1:
|
|
906
|
+
_a.sent();
|
|
907
|
+
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.SCALING, newValue)];
|
|
908
|
+
case 2:
|
|
734
909
|
_a.sent();
|
|
735
910
|
return [2 /*return*/];
|
|
736
911
|
}
|
|
@@ -815,6 +990,9 @@ var Variant = /** @class */ (function (_super) {
|
|
|
815
990
|
switch (_a.label) {
|
|
816
991
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.POSITION, newValue)];
|
|
817
992
|
case 1:
|
|
993
|
+
_a.sent();
|
|
994
|
+
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.POSITION, newValue)];
|
|
995
|
+
case 2:
|
|
818
996
|
_a.sent();
|
|
819
997
|
return [2 /*return*/];
|
|
820
998
|
}
|
|
@@ -826,6 +1004,45 @@ var Variant = /** @class */ (function (_super) {
|
|
|
826
1004
|
return tslib_1.__generator(this, function (_a) {
|
|
827
1005
|
switch (_a.label) {
|
|
828
1006
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.ROTATION, newValue)];
|
|
1007
|
+
case 1:
|
|
1008
|
+
_a.sent();
|
|
1009
|
+
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.ROTATION, newValue)];
|
|
1010
|
+
case 2:
|
|
1011
|
+
_a.sent();
|
|
1012
|
+
return [2 /*return*/];
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
}); }
|
|
1016
|
+
]);
|
|
1017
|
+
this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW, [
|
|
1018
|
+
function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1019
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1020
|
+
switch (_a.label) {
|
|
1021
|
+
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.CAST_SHADOW, newValue)];
|
|
1022
|
+
case 1:
|
|
1023
|
+
_a.sent();
|
|
1024
|
+
return [2 /*return*/];
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
}); }
|
|
1028
|
+
]);
|
|
1029
|
+
this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, [
|
|
1030
|
+
function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1031
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1032
|
+
switch (_a.label) {
|
|
1033
|
+
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, newValue)];
|
|
1034
|
+
case 1:
|
|
1035
|
+
_a.sent();
|
|
1036
|
+
return [2 /*return*/];
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
}); }
|
|
1040
|
+
]);
|
|
1041
|
+
this._parameterObservers.set(parameter_1.Parameter.RECEIVE_SHADOWS, [
|
|
1042
|
+
function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1043
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1044
|
+
switch (_a.label) {
|
|
1045
|
+
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.RECEIVE_SHADOWS, newValue)];
|
|
829
1046
|
case 1:
|
|
830
1047
|
_a.sent();
|
|
831
1048
|
return [2 /*return*/];
|
|
@@ -839,18 +1056,75 @@ var Variant = /** @class */ (function (_super) {
|
|
|
839
1056
|
* Creates {@link Element}s and clones nodes into them.
|
|
840
1057
|
*/
|
|
841
1058
|
Variant.prototype.createElements = function () {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1059
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1060
|
+
var _a, _b, _i, name_2, _c, _d;
|
|
1061
|
+
var _this = this;
|
|
1062
|
+
return tslib_1.__generator(this, function (_e) {
|
|
1063
|
+
switch (_e.label) {
|
|
1064
|
+
case 0:
|
|
1065
|
+
_a = [];
|
|
1066
|
+
for (_b in this.structureJson.elements || {})
|
|
1067
|
+
_a.push(_b);
|
|
1068
|
+
_i = 0;
|
|
1069
|
+
_e.label = 1;
|
|
1070
|
+
case 1:
|
|
1071
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
1072
|
+
name_2 = _a[_i];
|
|
1073
|
+
_d = (_c = this.elements).push;
|
|
1074
|
+
return [4 /*yield*/, element_1.Element.create(this, name_2)];
|
|
1075
|
+
case 2:
|
|
1076
|
+
_d.apply(_c, [_e.sent()]);
|
|
1077
|
+
_e.label = 3;
|
|
1078
|
+
case 3:
|
|
1079
|
+
_i++;
|
|
1080
|
+
return [3 /*break*/, 1];
|
|
1081
|
+
case 4:
|
|
1082
|
+
// inject node meta to all inherited elements
|
|
1083
|
+
// we do this to inject the deepest and most concrete variant information to all cloned nodes in the tree
|
|
1084
|
+
this.inheritedElements.forEach(function (element) {
|
|
1085
|
+
element.nodes.forEach(function (node) {
|
|
1086
|
+
babylonHelper_1.injectNodeMetadata(node, { variant: _this, variantParameterizable: element });
|
|
1087
|
+
});
|
|
1088
|
+
});
|
|
1089
|
+
return [2 /*return*/, this];
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
});
|
|
1093
|
+
};
|
|
1094
|
+
/**
|
|
1095
|
+
* Creates {@link ViewerLight}s.
|
|
1096
|
+
*/
|
|
1097
|
+
Variant.prototype.createViewerLights = function () {
|
|
1098
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1099
|
+
var _a, _b, _i, name_3, _c, _d;
|
|
1100
|
+
var _this = this;
|
|
1101
|
+
return tslib_1.__generator(this, function (_e) {
|
|
1102
|
+
switch (_e.label) {
|
|
1103
|
+
case 0:
|
|
1104
|
+
_a = [];
|
|
1105
|
+
for (_b in this.structureJson.lights || {})
|
|
1106
|
+
_a.push(_b);
|
|
1107
|
+
_i = 0;
|
|
1108
|
+
_e.label = 1;
|
|
1109
|
+
case 1:
|
|
1110
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
1111
|
+
name_3 = _a[_i];
|
|
1112
|
+
_d = (_c = this.viewerLights).push;
|
|
1113
|
+
return [4 /*yield*/, viewerLight_1.ViewerLight.create(this, name_3)];
|
|
1114
|
+
case 2:
|
|
1115
|
+
_d.apply(_c, [_e.sent()]);
|
|
1116
|
+
_e.label = 3;
|
|
1117
|
+
case 3:
|
|
1118
|
+
_i++;
|
|
1119
|
+
return [3 /*break*/, 1];
|
|
1120
|
+
case 4:
|
|
1121
|
+
this.inheritedViewerLights.forEach(function (viewerLight) {
|
|
1122
|
+
babylonHelper_1.injectNodeMetadata(viewerLight.light, { variant: _this, variantParameterizable: viewerLight });
|
|
1123
|
+
});
|
|
1124
|
+
return [2 /*return*/, this];
|
|
1125
|
+
}
|
|
851
1126
|
});
|
|
852
1127
|
});
|
|
853
|
-
return this;
|
|
854
1128
|
};
|
|
855
1129
|
/**
|
|
856
1130
|
* Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
|
|
@@ -869,6 +1143,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
869
1143
|
});
|
|
870
1144
|
};
|
|
871
1145
|
return Variant;
|
|
872
|
-
}(
|
|
1146
|
+
}(parameterizable_1.Parameterizable));
|
|
873
1147
|
exports.Variant = Variant;
|
|
874
1148
|
//# sourceMappingURL=variant.js.map
|