@combeenation/3d-viewer 4.0.0-alpha7 → 4.0.0-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 +1 -0
- package/dist/lib-cjs/api/classes/element.d.ts +12 -16
- package/dist/lib-cjs/api/classes/element.js +125 -180
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/event.d.ts +1 -15
- package/dist/lib-cjs/api/classes/event.js +1 -15
- package/dist/lib-cjs/api/classes/event.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +7 -101
- package/dist/lib-cjs/api/classes/parameter.js +21 -141
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.js +36 -11
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +14 -48
- package/dist/lib-cjs/api/classes/variant.js +56 -315
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +1 -5
- package/dist/lib-cjs/api/classes/variantInstance.js +0 -10
- package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +1 -0
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.js +27 -19
- package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +1 -5
- package/dist/lib-cjs/api/internal/sceneSetup.js +71 -75
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +4 -51
- package/dist/lib-cjs/api/util/babylonHelper.js +8 -141
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +11 -53
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +8 -4
- package/dist/lib-cjs/api/util/resourceHelper.js +25 -59
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/index.d.ts +22 -24
- package/dist/lib-cjs/index.js +38 -42
- package/dist/lib-cjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/classes/element.ts +112 -133
- package/src/api/classes/{parameterizable.ts → elementParameterizable.ts} +1 -12
- package/src/api/classes/event.ts +1 -16
- package/src/api/classes/parameter.ts +22 -153
- package/src/api/classes/parameterObservable.ts +31 -9
- package/src/api/classes/variant.ts +51 -184
- package/src/api/classes/variantInstance.ts +1 -8
- package/src/api/classes/viewer.ts +1 -0
- package/src/api/internal/sceneSetup.ts +109 -99
- package/src/api/util/babylonHelper.ts +9 -153
- package/src/api/util/globalTypes.ts +13 -64
- package/src/api/util/resourceHelper.ts +24 -26
- package/src/dev.ts +7 -5
- package/src/index.ts +23 -27
- package/src/pagesconfig.json +13 -8
- package/dist/lib-cjs/api/emitter.d.ts +0 -35
- package/dist/lib-cjs/api/emitter.js +0 -61
- package/dist/lib-cjs/api/emitter.js.map +0 -1
- package/src/api/classes/variantParameterizable.ts +0 -73
- package/src/api/classes/viewerLight.ts +0 -326
- package/src/api/util/stringHelper.ts +0 -26
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AssetContainer } from '@babylonjs/core/assetContainer';
|
|
2
|
-
import { Light } from '@babylonjs/core/Lights/light';
|
|
3
2
|
import '@babylonjs/core/Loading/Plugins/babylonFileLoader';
|
|
4
3
|
import { Material } from '@babylonjs/core/Materials/material';
|
|
5
4
|
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
@@ -9,22 +8,28 @@ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_transform';
|
|
|
9
8
|
import '@babylonjs/loaders/glTF/2.0/glTFLoader';
|
|
10
9
|
import { DottedPath } from './dottedPath';
|
|
11
10
|
import { Element } from './element';
|
|
12
|
-
import {
|
|
13
|
-
import { ParameterObservable } from './parameterObservable';
|
|
14
|
-
import { VariantParameterizable } from './variantParameterizable';
|
|
11
|
+
import { ElementParameterizable } from './elementParameterizable';
|
|
15
12
|
import { Viewer } from './viewer';
|
|
16
|
-
import
|
|
13
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_basisu';
|
|
14
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_clearcoat';
|
|
15
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen';
|
|
16
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_ior';
|
|
17
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness';
|
|
18
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_specular';
|
|
19
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_translucency';
|
|
20
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_transmission';
|
|
21
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_unlit';
|
|
22
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_variants';
|
|
17
23
|
/**
|
|
18
24
|
* A concrete "Variant". Most of these are handled by either the {@link Viewer} or {@link VariantInstance}.
|
|
19
25
|
*/
|
|
20
|
-
export declare class Variant extends
|
|
26
|
+
export declare class Variant extends ElementParameterizable {
|
|
21
27
|
readonly name: string;
|
|
22
28
|
protected readonly _structureJson: StructureJson;
|
|
23
29
|
readonly viewer: Viewer;
|
|
24
30
|
readonly parent?: Variant | undefined;
|
|
25
31
|
assetContainer: AssetContainer;
|
|
26
32
|
readonly elements: Element[];
|
|
27
|
-
readonly viewerLights: ViewerLight[];
|
|
28
33
|
structureJson: StructureJson;
|
|
29
34
|
protected _dottedNodes: Map<DottedPath, TransformNode> | undefined;
|
|
30
35
|
protected readonly _children: Map<string, Variant>;
|
|
@@ -76,10 +81,6 @@ export declare class Variant extends Parameterizable {
|
|
|
76
81
|
* The TransformNodes of the {@link Variant}.
|
|
77
82
|
*/
|
|
78
83
|
get nodes(): TransformNode[];
|
|
79
|
-
/**
|
|
80
|
-
* The {@link ViewerLight}s of the {@link Variant}.
|
|
81
|
-
*/
|
|
82
|
-
get lights(): Light[];
|
|
83
84
|
/**
|
|
84
85
|
* All TransformNodes of the {@link Variant} mapped flat with a {@link DottedPath}.
|
|
85
86
|
*/
|
|
@@ -92,10 +93,6 @@ export declare class Variant extends Parameterizable {
|
|
|
92
93
|
* All {@link Element}s from this {@link Variant}'s parents.
|
|
93
94
|
*/
|
|
94
95
|
get inheritedElements(): Element[];
|
|
95
|
-
/**
|
|
96
|
-
* All {@link ViewerLight}s inherited from this {@link Variant}'s parents.
|
|
97
|
-
*/
|
|
98
|
-
get inheritedViewerLights(): ViewerLight[];
|
|
99
96
|
/**
|
|
100
97
|
* All TransformNodes inherited from this {@link Variant}'s parents.
|
|
101
98
|
*/
|
|
@@ -104,10 +101,6 @@ export declare class Variant extends Parameterizable {
|
|
|
104
101
|
* All TransformNodes inherited from this {@link Variant}'s parents mapped flat with a {@link DottedPath}.
|
|
105
102
|
*/
|
|
106
103
|
get inheritedDottedNodes(): Map<DottedPath, TransformNode>;
|
|
107
|
-
/**
|
|
108
|
-
* All Lights inherited from this {@link Variant}'s parents.
|
|
109
|
-
*/
|
|
110
|
-
get inheritedLights(): Light[];
|
|
111
104
|
/**
|
|
112
105
|
* The {@link ParameterDeclarations} inherited from this {@link Variant}'s parents.
|
|
113
106
|
*/
|
|
@@ -136,11 +129,6 @@ export declare class Variant extends Parameterizable {
|
|
|
136
129
|
* Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
|
|
137
130
|
*/
|
|
138
131
|
getElement(dottedPath: DottedPathArgument): Promise<Element>;
|
|
139
|
-
/**
|
|
140
|
-
* Gets the desired {@link ViewerLight} of the current {@link Variant} relative to its {@link DottedPath}.
|
|
141
|
-
* Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
|
|
142
|
-
*/
|
|
143
|
-
getViewerLight(dottedPath: DottedPathArgument): Promise<ViewerLight>;
|
|
144
132
|
/**
|
|
145
133
|
* A proxy for directly getting a Node from an {@link Element} by its {@link DottedPath}s.
|
|
146
134
|
*/
|
|
@@ -183,28 +171,10 @@ export declare class Variant extends Parameterizable {
|
|
|
183
171
|
* @emits {@link Event.ASSET_LOADING_END}
|
|
184
172
|
*/
|
|
185
173
|
protected loadAssets(): Promise<Variant>;
|
|
186
|
-
/**
|
|
187
|
-
* Commits given parameters to all {@link Element}s.
|
|
188
|
-
*/
|
|
189
|
-
protected commitParametersToElements(parameters: ParameterBag): Promise<void>;
|
|
190
|
-
/**
|
|
191
|
-
* Commits given parameters to all {@link ViewerLight}s.
|
|
192
|
-
*/
|
|
193
|
-
protected commitParametersToViewerLights(parameters: ParameterBag): Promise<void>;
|
|
194
|
-
/**
|
|
195
|
-
* Commits given parameters to a {@link VariantParameterizable} and updates the according definition with given
|
|
196
|
-
* key in the {@link StructureJson}. The `definitionKey` "elements" for example will update the definition in
|
|
197
|
-
* `this.structureJson.elements`.
|
|
198
|
-
*/
|
|
199
|
-
protected commitParametersToVariantParameterizable(parameters: ParameterBag, parameterizable: VariantParameterizable, definitionKey: string): Promise<ParameterObservable>;
|
|
200
174
|
/**
|
|
201
175
|
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
202
176
|
*/
|
|
203
|
-
protected commitParameterToElements(parameter: string, value: ParameterValue): Promise<
|
|
204
|
-
/**
|
|
205
|
-
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
206
|
-
*/
|
|
207
|
-
protected commitParameterToViewerLights(parameter: string, value: ParameterValue): Promise<Variant>;
|
|
177
|
+
protected commitParameterToElements(parameter: string, value: ParameterValue): Promise<void>;
|
|
208
178
|
/**
|
|
209
179
|
* Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
|
|
210
180
|
*/
|
|
@@ -212,11 +182,7 @@ export declare class Variant extends Parameterizable {
|
|
|
212
182
|
/**
|
|
213
183
|
* Creates {@link Element}s and clones nodes into them.
|
|
214
184
|
*/
|
|
215
|
-
protected createElements():
|
|
216
|
-
/**
|
|
217
|
-
* Creates {@link ViewerLight}s.
|
|
218
|
-
*/
|
|
219
|
-
protected createViewerLights(): Promise<Variant>;
|
|
185
|
+
protected createElements(): Variant;
|
|
220
186
|
/**
|
|
221
187
|
* Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
|
|
222
188
|
*/
|
|
@@ -14,10 +14,19 @@ 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");
|
|
17
18
|
var event_1 = require("./event");
|
|
18
19
|
var parameter_1 = require("./parameter");
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_basisu");
|
|
21
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_clearcoat");
|
|
22
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen");
|
|
23
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_ior");
|
|
24
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness");
|
|
25
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_specular");
|
|
26
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_translucency");
|
|
27
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_transmission");
|
|
28
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_unlit");
|
|
29
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_variants");
|
|
21
30
|
/**
|
|
22
31
|
* A concrete "Variant". Most of these are handled by either the {@link Viewer} or {@link VariantInstance}.
|
|
23
32
|
*/
|
|
@@ -33,7 +42,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
33
42
|
_this.viewer = viewer;
|
|
34
43
|
_this.parent = parent;
|
|
35
44
|
_this.elements = [];
|
|
36
|
-
_this.viewerLights = [];
|
|
37
45
|
_this._children = new Map();
|
|
38
46
|
_this._parameterObservers = new Map();
|
|
39
47
|
/**
|
|
@@ -179,16 +187,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
179
187
|
enumerable: false,
|
|
180
188
|
configurable: true
|
|
181
189
|
});
|
|
182
|
-
Object.defineProperty(Variant.prototype, "lights", {
|
|
183
|
-
/**
|
|
184
|
-
* The {@link ViewerLight}s of the {@link Variant}.
|
|
185
|
-
*/
|
|
186
|
-
get: function () {
|
|
187
|
-
return this.assetContainer.lights;
|
|
188
|
-
},
|
|
189
|
-
enumerable: false,
|
|
190
|
-
configurable: true
|
|
191
|
-
});
|
|
192
190
|
Object.defineProperty(Variant.prototype, "dottedNodes", {
|
|
193
191
|
/**
|
|
194
192
|
* All TransformNodes of the {@link Variant} mapped flat with a {@link DottedPath}.
|
|
@@ -231,20 +229,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
231
229
|
enumerable: false,
|
|
232
230
|
configurable: true
|
|
233
231
|
});
|
|
234
|
-
Object.defineProperty(Variant.prototype, "inheritedViewerLights", {
|
|
235
|
-
/**
|
|
236
|
-
* All {@link ViewerLight}s inherited from this {@link Variant}'s parents.
|
|
237
|
-
*/
|
|
238
|
-
get: function () {
|
|
239
|
-
var viewerLights = [];
|
|
240
|
-
this.ancestors.forEach(function (ancestor) {
|
|
241
|
-
viewerLights = lodash_es_1.concat(viewerLights, ancestor.viewerLights);
|
|
242
|
-
});
|
|
243
|
-
return lodash_es_1.concat(viewerLights, this.viewerLights);
|
|
244
|
-
},
|
|
245
|
-
enumerable: false,
|
|
246
|
-
configurable: true
|
|
247
|
-
});
|
|
248
232
|
Object.defineProperty(Variant.prototype, "inheritedNodes", {
|
|
249
233
|
/**
|
|
250
234
|
* All TransformNodes inherited from this {@link Variant}'s parents.
|
|
@@ -273,20 +257,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
273
257
|
enumerable: false,
|
|
274
258
|
configurable: true
|
|
275
259
|
});
|
|
276
|
-
Object.defineProperty(Variant.prototype, "inheritedLights", {
|
|
277
|
-
/**
|
|
278
|
-
* All Lights inherited from this {@link Variant}'s parents.
|
|
279
|
-
*/
|
|
280
|
-
get: function () {
|
|
281
|
-
var lights = [];
|
|
282
|
-
this.ancestors.forEach(function (ancestor) {
|
|
283
|
-
lights = lodash_es_1.concat(lights, ancestor.lights);
|
|
284
|
-
});
|
|
285
|
-
return lodash_es_1.concat(lights, this.lights);
|
|
286
|
-
},
|
|
287
|
-
enumerable: false,
|
|
288
|
-
configurable: true
|
|
289
|
-
});
|
|
290
260
|
Object.defineProperty(Variant.prototype, "inheritedParameterDeclaration", {
|
|
291
261
|
/**
|
|
292
262
|
* The {@link ParameterDeclarations} inherited from this {@link Variant}'s parents.
|
|
@@ -448,42 +418,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
448
418
|
});
|
|
449
419
|
});
|
|
450
420
|
};
|
|
451
|
-
/**
|
|
452
|
-
* Gets the desired {@link ViewerLight} of the current {@link Variant} relative to its {@link DottedPath}.
|
|
453
|
-
* Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
|
|
454
|
-
*/
|
|
455
|
-
Variant.prototype.getViewerLight = function (dottedPath) {
|
|
456
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
457
|
-
var _dottedPath, viewerLightName, variant, viewerLight;
|
|
458
|
-
return tslib_1.__generator(this, function (_a) {
|
|
459
|
-
switch (_a.label) {
|
|
460
|
-
case 0:
|
|
461
|
-
_dottedPath = dottedPath_1.DottedPath.create(dottedPath);
|
|
462
|
-
viewerLightName = _dottedPath.popPart();
|
|
463
|
-
variant = this;
|
|
464
|
-
if (!(_dottedPath.parts.length > 0)) return [3 /*break*/, 2];
|
|
465
|
-
return [4 /*yield*/, this.getDescendant(_dottedPath)];
|
|
466
|
-
case 1:
|
|
467
|
-
variant = _a.sent();
|
|
468
|
-
_a.label = 2;
|
|
469
|
-
case 2:
|
|
470
|
-
if (variant.inheritedViewerLights.length === 0) {
|
|
471
|
-
throw new Error("No viewerLights for variant \"" + variant.id + "\" found. " +
|
|
472
|
-
"Either none are defined or they are not initialized (are you operating on the appropriate living?).");
|
|
473
|
-
}
|
|
474
|
-
variant.inheritedViewerLights.forEach(function (_viewerLight) {
|
|
475
|
-
if (_viewerLight.name === viewerLightName) {
|
|
476
|
-
viewerLight = _viewerLight;
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
if (!viewerLight) {
|
|
480
|
-
throw new Error("ViewerLight with name \"" + viewerLightName + "\" does not exist for variant \"" + variant.id + "\".");
|
|
481
|
-
}
|
|
482
|
-
return [2 /*return*/, viewerLight];
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
};
|
|
487
421
|
/**
|
|
488
422
|
* A proxy for directly getting a Node from an {@link Element} by its {@link DottedPath}s.
|
|
489
423
|
*/
|
|
@@ -554,15 +488,10 @@ var Variant = /** @class */ (function (_super) {
|
|
|
554
488
|
parent === null || parent === void 0 ? void 0 : parent._children.set(variant.name, variant);
|
|
555
489
|
variant.assetContainer = this.assetContainer;
|
|
556
490
|
variant.parameterObservers = lodash_es_1.cloneDeep(this.parameterObservers);
|
|
557
|
-
|
|
558
|
-
case 2:
|
|
559
|
-
_b.sent();
|
|
560
|
-
return [4 /*yield*/, variant.createViewerLights()];
|
|
561
|
-
case 3:
|
|
562
|
-
_b.sent();
|
|
491
|
+
variant.createElements();
|
|
563
492
|
variant.addParameterObservers();
|
|
564
493
|
return [4 /*yield*/, variant.bootstrapParameters(parameters)];
|
|
565
|
-
case
|
|
494
|
+
case 2:
|
|
566
495
|
_b.sent();
|
|
567
496
|
this.broadcastEvent(event_1.Event.VARIANT_CREATED, variant);
|
|
568
497
|
return [2 /*return*/, variant];
|
|
@@ -589,7 +518,7 @@ var Variant = /** @class */ (function (_super) {
|
|
|
589
518
|
*/
|
|
590
519
|
Variant.prototype.commitParameters = function (parameters) {
|
|
591
520
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
592
|
-
var oldParameters, _parameters, parameter, value, search, mergedParameters, structureParameters, _structureParameters, parameter, value, search, replacedStructureParameters, differentStructureParameters, parameter, newParameters, structure, parameter, value, search, observerPromises, _loop_1, this_1, parameter;
|
|
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, elementPromises;
|
|
593
522
|
var _this = this;
|
|
594
523
|
return tslib_1.__generator(this, function (_a) {
|
|
595
524
|
switch (_a.label) {
|
|
@@ -659,22 +588,39 @@ var Variant = /** @class */ (function (_super) {
|
|
|
659
588
|
_a.sent();
|
|
660
589
|
// broadcast that bag has been committed
|
|
661
590
|
this.broadcastEvent(event_1.Event.VARIANT_PARAMETER_BAG_COMMITTED, this, oldParameters, newParameters);
|
|
662
|
-
|
|
663
|
-
|
|
591
|
+
elementPromises = this.elements.map(function (element) {
|
|
592
|
+
var _elementDefinition = JSON.stringify(_this._structureJson.elements[element.name]);
|
|
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)];
|
|
664
616
|
case 2:
|
|
665
|
-
// commit parameters to elements
|
|
666
|
-
_a.sent();
|
|
667
|
-
// commit parameters to lights
|
|
668
|
-
return [4 /*yield*/, this.commitParametersToViewerLights(newParameters)];
|
|
669
|
-
case 3:
|
|
670
|
-
// commit parameters to lights
|
|
671
617
|
_a.sent();
|
|
672
|
-
if (!this.parent) return [3 /*break*/,
|
|
618
|
+
if (!this.parent) return [3 /*break*/, 4];
|
|
673
619
|
return [4 /*yield*/, this.parent.commitParameters(this.parameters)];
|
|
674
|
-
case
|
|
620
|
+
case 3:
|
|
675
621
|
_a.sent();
|
|
676
|
-
_a.label =
|
|
677
|
-
case
|
|
622
|
+
_a.label = 4;
|
|
623
|
+
case 4: return [2 /*return*/, this];
|
|
678
624
|
}
|
|
679
625
|
});
|
|
680
626
|
});
|
|
@@ -728,17 +674,7 @@ var Variant = /** @class */ (function (_super) {
|
|
|
728
674
|
var nodes = _this.assetContainer.getNodes().filter(function (n) { return n instanceof transformNode_1.TransformNode; });
|
|
729
675
|
nodes.forEach(function (node) {
|
|
730
676
|
babylonHelper_1.deactivateTransformNode(node, false);
|
|
731
|
-
babylonHelper_1.
|
|
732
|
-
});
|
|
733
|
-
_this.assetContainer.lights.forEach(function (light) {
|
|
734
|
-
light.setEnabled(false);
|
|
735
|
-
babylonHelper_1.injectNodeMetadata(light, { dottedPath: babylonHelper_1.getDottedPathForNode(light) }, false);
|
|
736
|
-
_this.viewer.scene.addLight(light);
|
|
737
|
-
});
|
|
738
|
-
_this.assetContainer.cameras.forEach(function (camera) {
|
|
739
|
-
camera.setEnabled(false);
|
|
740
|
-
babylonHelper_1.injectNodeMetadata(camera, { dottedPath: babylonHelper_1.getDottedPathForNode(camera) }, false);
|
|
741
|
-
_this.viewer.scene.addCamera(camera);
|
|
677
|
+
babylonHelper_1.injectTransformNodeMetadata(node, { dottedPath: babylonHelper_1.getDottedPathForTransformNode(node) }, false);
|
|
742
678
|
});
|
|
743
679
|
_this.broadcastEvent(event_1.Event.ASSET_LOADING_END, _this);
|
|
744
680
|
resolve(_this);
|
|
@@ -750,79 +686,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
750
686
|
});
|
|
751
687
|
});
|
|
752
688
|
};
|
|
753
|
-
/**
|
|
754
|
-
* Commits given parameters to all {@link Element}s.
|
|
755
|
-
*/
|
|
756
|
-
Variant.prototype.commitParametersToElements = function (parameters) {
|
|
757
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
758
|
-
var _this = this;
|
|
759
|
-
return tslib_1.__generator(this, function (_a) {
|
|
760
|
-
switch (_a.label) {
|
|
761
|
-
case 0: return [4 /*yield*/, Promise.all(this.elements.map(function (element) { return _this.commitParametersToVariantParameterizable(parameters, element, 'elements'); }))];
|
|
762
|
-
case 1:
|
|
763
|
-
_a.sent();
|
|
764
|
-
return [2 /*return*/];
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
});
|
|
768
|
-
};
|
|
769
|
-
/**
|
|
770
|
-
* Commits given parameters to all {@link ViewerLight}s.
|
|
771
|
-
*/
|
|
772
|
-
Variant.prototype.commitParametersToViewerLights = function (parameters) {
|
|
773
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
774
|
-
var _this = this;
|
|
775
|
-
return tslib_1.__generator(this, function (_a) {
|
|
776
|
-
switch (_a.label) {
|
|
777
|
-
case 0: return [4 /*yield*/, Promise.all(this.viewerLights.map(function (viewerLight) { return _this.commitParametersToVariantParameterizable(parameters, viewerLight, 'lights'); }))];
|
|
778
|
-
case 1:
|
|
779
|
-
_a.sent();
|
|
780
|
-
return [2 /*return*/];
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
});
|
|
784
|
-
};
|
|
785
|
-
/**
|
|
786
|
-
* Commits given parameters to a {@link VariantParameterizable} and updates the according definition with given
|
|
787
|
-
* key in the {@link StructureJson}. The `definitionKey` "elements" for example will update the definition in
|
|
788
|
-
* `this.structureJson.elements`.
|
|
789
|
-
*/
|
|
790
|
-
Variant.prototype.commitParametersToVariantParameterizable = function (parameters, parameterizable, definitionKey) {
|
|
791
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
792
|
-
var initialDefinition, initialDefinitionStr, _parameters, parameter, dpp, parameterValue, parameterizableParameter, search, definition;
|
|
793
|
-
return tslib_1.__generator(this, function (_a) {
|
|
794
|
-
switch (_a.label) {
|
|
795
|
-
case 0:
|
|
796
|
-
initialDefinition = lodash_es_1.get(this._structureJson, definitionKey)[parameterizable.name];
|
|
797
|
-
initialDefinitionStr = JSON.stringify(initialDefinition);
|
|
798
|
-
_parameters = {};
|
|
799
|
-
for (parameter in parameters) {
|
|
800
|
-
dpp = dottedPath_1.DottedPath.create(parameter);
|
|
801
|
-
if (dpp.shiftPart() !== parameterizable.name) {
|
|
802
|
-
continue;
|
|
803
|
-
}
|
|
804
|
-
parameterValue = parameters[parameter];
|
|
805
|
-
parameterizableParameter = dpp.path;
|
|
806
|
-
// If the variant is explicitly hidden, we must not override the visibility with element parameters. We need
|
|
807
|
-
// an exception for visibility to avoid overloading already applied element parameters with element parameters
|
|
808
|
-
// defined in the variant spec ("dotted parameters").
|
|
809
|
-
// @see https://github.com/Combeenation/3d-viewer/issues/44
|
|
810
|
-
if (parameterizableParameter === parameter_1.Parameter.VISIBLE && parameters[parameter_1.Parameter.VISIBLE] === false) {
|
|
811
|
-
parameterValue = false;
|
|
812
|
-
}
|
|
813
|
-
_parameters[parameterizableParameter] = parameterValue;
|
|
814
|
-
search = new RegExp("\\$\\{" + parameterizableParameter + "\\}", 'g');
|
|
815
|
-
initialDefinitionStr = initialDefinitionStr.replace(search, parameterValue.toString());
|
|
816
|
-
}
|
|
817
|
-
definition = lodash_es_1.get(this.structureJson, definitionKey);
|
|
818
|
-
definition[this.name] = JSON.parse(initialDefinitionStr);
|
|
819
|
-
lodash_es_1.set(this.structureJson, definitionKey, definition);
|
|
820
|
-
return [4 /*yield*/, parameterizable.commitParameters(_parameters)];
|
|
821
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
822
|
-
}
|
|
823
|
-
});
|
|
824
|
-
});
|
|
825
|
-
};
|
|
826
689
|
/**
|
|
827
690
|
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
828
691
|
*/
|
|
@@ -840,29 +703,7 @@ var Variant = /** @class */ (function (_super) {
|
|
|
840
703
|
return [4 /*yield*/, Promise.all(promises)];
|
|
841
704
|
case 1:
|
|
842
705
|
_b.sent();
|
|
843
|
-
return [2 /*return
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
|
-
};
|
|
848
|
-
/**
|
|
849
|
-
* Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
|
|
850
|
-
*/
|
|
851
|
-
Variant.prototype.commitParameterToViewerLights = function (parameter, value) {
|
|
852
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
853
|
-
var promises, _i, _a, viewerLight;
|
|
854
|
-
return tslib_1.__generator(this, function (_b) {
|
|
855
|
-
switch (_b.label) {
|
|
856
|
-
case 0:
|
|
857
|
-
promises = [];
|
|
858
|
-
for (_i = 0, _a = this.viewerLights; _i < _a.length; _i++) {
|
|
859
|
-
viewerLight = _a[_i];
|
|
860
|
-
promises.push(viewerLight.commitParameter(parameter, value));
|
|
861
|
-
}
|
|
862
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
863
|
-
case 1:
|
|
864
|
-
_b.sent();
|
|
865
|
-
return [2 /*return*/, this];
|
|
706
|
+
return [2 /*return*/];
|
|
866
707
|
}
|
|
867
708
|
});
|
|
868
709
|
});
|
|
@@ -878,9 +719,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
878
719
|
switch (_a.label) {
|
|
879
720
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.VISIBLE, newValue)];
|
|
880
721
|
case 1:
|
|
881
|
-
_a.sent();
|
|
882
|
-
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.VISIBLE, newValue)];
|
|
883
|
-
case 2:
|
|
884
722
|
_a.sent();
|
|
885
723
|
return [2 /*return*/];
|
|
886
724
|
}
|
|
@@ -893,9 +731,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
893
731
|
switch (_a.label) {
|
|
894
732
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.SCALING, newValue)];
|
|
895
733
|
case 1:
|
|
896
|
-
_a.sent();
|
|
897
|
-
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.SCALING, newValue)];
|
|
898
|
-
case 2:
|
|
899
734
|
_a.sent();
|
|
900
735
|
return [2 /*return*/];
|
|
901
736
|
}
|
|
@@ -980,9 +815,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
980
815
|
switch (_a.label) {
|
|
981
816
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.POSITION, newValue)];
|
|
982
817
|
case 1:
|
|
983
|
-
_a.sent();
|
|
984
|
-
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.POSITION, newValue)];
|
|
985
|
-
case 2:
|
|
986
818
|
_a.sent();
|
|
987
819
|
return [2 /*return*/];
|
|
988
820
|
}
|
|
@@ -994,45 +826,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
994
826
|
return tslib_1.__generator(this, function (_a) {
|
|
995
827
|
switch (_a.label) {
|
|
996
828
|
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.ROTATION, newValue)];
|
|
997
|
-
case 1:
|
|
998
|
-
_a.sent();
|
|
999
|
-
return [4 /*yield*/, variant.commitParameterToViewerLights(parameter_1.Parameter.ROTATION, newValue)];
|
|
1000
|
-
case 2:
|
|
1001
|
-
_a.sent();
|
|
1002
|
-
return [2 /*return*/];
|
|
1003
|
-
}
|
|
1004
|
-
});
|
|
1005
|
-
}); }
|
|
1006
|
-
]);
|
|
1007
|
-
this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW, [
|
|
1008
|
-
function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1009
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1010
|
-
switch (_a.label) {
|
|
1011
|
-
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.CAST_SHADOW, newValue)];
|
|
1012
|
-
case 1:
|
|
1013
|
-
_a.sent();
|
|
1014
|
-
return [2 /*return*/];
|
|
1015
|
-
}
|
|
1016
|
-
});
|
|
1017
|
-
}); }
|
|
1018
|
-
]);
|
|
1019
|
-
this._parameterObservers.set(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, [
|
|
1020
|
-
function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1021
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1022
|
-
switch (_a.label) {
|
|
1023
|
-
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.CAST_SHADOW_FROM_LIGHTS, newValue)];
|
|
1024
|
-
case 1:
|
|
1025
|
-
_a.sent();
|
|
1026
|
-
return [2 /*return*/];
|
|
1027
|
-
}
|
|
1028
|
-
});
|
|
1029
|
-
}); }
|
|
1030
|
-
]);
|
|
1031
|
-
this._parameterObservers.set(parameter_1.Parameter.RECEIVE_SHADOWS, [
|
|
1032
|
-
function (variant, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1033
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1034
|
-
switch (_a.label) {
|
|
1035
|
-
case 0: return [4 /*yield*/, variant.commitParameterToElements(parameter_1.Parameter.RECEIVE_SHADOWS, newValue)];
|
|
1036
829
|
case 1:
|
|
1037
830
|
_a.sent();
|
|
1038
831
|
return [2 /*return*/];
|
|
@@ -1046,70 +839,18 @@ var Variant = /** @class */ (function (_super) {
|
|
|
1046
839
|
* Creates {@link Element}s and clones nodes into them.
|
|
1047
840
|
*/
|
|
1048
841
|
Variant.prototype.createElements = function () {
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
_i = 0;
|
|
1059
|
-
_e.label = 1;
|
|
1060
|
-
case 1:
|
|
1061
|
-
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
1062
|
-
name_2 = _a[_i];
|
|
1063
|
-
_d = (_c = this.elements).push;
|
|
1064
|
-
return [4 /*yield*/, element_1.Element.create(this, name_2)];
|
|
1065
|
-
case 2:
|
|
1066
|
-
_d.apply(_c, [_e.sent()]);
|
|
1067
|
-
_e.label = 3;
|
|
1068
|
-
case 3:
|
|
1069
|
-
_i++;
|
|
1070
|
-
return [3 /*break*/, 1];
|
|
1071
|
-
case 4:
|
|
1072
|
-
// inject node meta to all inherited elements
|
|
1073
|
-
// we do this to inject the deepest and most concrete variant information to all cloned nodes in the tree
|
|
1074
|
-
this.inheritedElements.forEach(function (element) {
|
|
1075
|
-
element.nodes.forEach(function (node) {
|
|
1076
|
-
babylonHelper_1.injectNodeMetadata(node, { variant: _this, element: element });
|
|
1077
|
-
});
|
|
1078
|
-
});
|
|
1079
|
-
return [2 /*return*/, this];
|
|
1080
|
-
}
|
|
1081
|
-
});
|
|
1082
|
-
});
|
|
1083
|
-
};
|
|
1084
|
-
/**
|
|
1085
|
-
* Creates {@link ViewerLight}s.
|
|
1086
|
-
*/
|
|
1087
|
-
Variant.prototype.createViewerLights = function () {
|
|
1088
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1089
|
-
var _a, _b, _i, name_3, _c, _d;
|
|
1090
|
-
return tslib_1.__generator(this, function (_e) {
|
|
1091
|
-
switch (_e.label) {
|
|
1092
|
-
case 0:
|
|
1093
|
-
_a = [];
|
|
1094
|
-
for (_b in this.structureJson.lights || {})
|
|
1095
|
-
_a.push(_b);
|
|
1096
|
-
_i = 0;
|
|
1097
|
-
_e.label = 1;
|
|
1098
|
-
case 1:
|
|
1099
|
-
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
1100
|
-
name_3 = _a[_i];
|
|
1101
|
-
_d = (_c = this.viewerLights).push;
|
|
1102
|
-
return [4 /*yield*/, viewerLight_1.ViewerLight.create(this, name_3)];
|
|
1103
|
-
case 2:
|
|
1104
|
-
_d.apply(_c, [_e.sent()]);
|
|
1105
|
-
_e.label = 3;
|
|
1106
|
-
case 3:
|
|
1107
|
-
_i++;
|
|
1108
|
-
return [3 /*break*/, 1];
|
|
1109
|
-
case 4: return [2 /*return*/, this];
|
|
1110
|
-
}
|
|
842
|
+
var _this = this;
|
|
843
|
+
for (var elementName in this.structureJson.elements || {}) {
|
|
844
|
+
this.elements.push(new element_1.Element(this, elementName));
|
|
845
|
+
}
|
|
846
|
+
// inject node meta to all inherited elements
|
|
847
|
+
// we do this to inject the deepest and most concrete variant information to all cloned nodes in the tree
|
|
848
|
+
this.inheritedElements.forEach(function (element) {
|
|
849
|
+
element.nodes.forEach(function (node) {
|
|
850
|
+
babylonHelper_1.injectTransformNodeMetadata(node, { variant: _this, element: element });
|
|
1111
851
|
});
|
|
1112
852
|
});
|
|
853
|
+
return this;
|
|
1113
854
|
};
|
|
1114
855
|
/**
|
|
1115
856
|
* Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
|
|
@@ -1128,6 +869,6 @@ var Variant = /** @class */ (function (_super) {
|
|
|
1128
869
|
});
|
|
1129
870
|
};
|
|
1130
871
|
return Variant;
|
|
1131
|
-
}(
|
|
872
|
+
}(elementParameterizable_1.ElementParameterizable));
|
|
1132
873
|
exports.Variant = Variant;
|
|
1133
874
|
//# sourceMappingURL=variant.js.map
|