@colijnit/configurator 12.0.3 → 12.0.6

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/app/builder.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare class Builder {
12
12
  decosReceived: BehaviorSubject<DecoNode[]>;
13
13
  answersReceived: BehaviorSubject<Answer[]>;
14
14
  modelLoaded: BehaviorSubject<THREE.Object3D>;
15
+ debug: Function;
15
16
  private _scene;
16
17
  private _instanceId;
17
18
  private _sku;
@@ -42,6 +43,7 @@ export declare class Builder {
42
43
  getImageForSelectionOrAnswer(object: Selection | Answer): Promise<string>;
43
44
  _cleanUp(): void;
44
45
  private _handleResponseData;
46
+ private _preloadMaterials;
45
47
  private _setInstanceId;
46
48
  private _prepareConfiguration;
47
49
  private _downloadAsset;
@@ -61,4 +63,5 @@ export declare class Builder {
61
63
  private _getAdjustables;
62
64
  private _updatePivot;
63
65
  private _reset;
66
+ private _log;
64
67
  }
@@ -14,6 +14,6 @@ export declare class ConfiguratorService {
14
14
  getDecos(showLoader?: boolean): Promise<DataServiceResponseData>;
15
15
  getQuestionAndAnswers(showLoader?: boolean, publicationCode?: number): Promise<QuestionAndAnswers>;
16
16
  getSingleImage(nodeId: number | string, publication: number, includeMimetype: boolean, thumb: boolean, showLoader: boolean): Promise<DataServiceResponseData>;
17
- selectSelection(selection: Selection, showLoader?: boolean): Promise<DataServiceResponseData>;
18
- selectAnswer(answer: Answer, showLoader?: boolean): Promise<DataServiceResponseData>;
17
+ selectSelection(selection: Selection, showLoader?: boolean): Promise<QuestionAndAnswers>;
18
+ selectAnswer(answer: Answer, showLoader?: boolean): Promise<QuestionAndAnswers>;
19
19
  }
@@ -932,6 +932,15 @@
932
932
  return SceneUtils;
933
933
  }());
934
934
 
935
+ var VariationSettings = /** @class */ (function () {
936
+ function VariationSettings() {
937
+ this.settings = {};
938
+ this.loading = false;
939
+ this.loaded = new rxjs.Subject();
940
+ }
941
+ return VariationSettings;
942
+ }());
943
+
935
944
  var Material = /** @class */ (function () {
936
945
  function Material() {
937
946
  this.specular = new THREE__namespace.Color(0.3, 0.3, 0.3);
@@ -1168,15 +1177,6 @@
1168
1177
  return Variation;
1169
1178
  }());
1170
1179
 
1171
- var VariationSettings = /** @class */ (function () {
1172
- function VariationSettings() {
1173
- this.settings = {};
1174
- this.loading = false;
1175
- this.loaded = new rxjs.Subject();
1176
- }
1177
- return VariationSettings;
1178
- }());
1179
-
1180
1180
  // @dynamic
1181
1181
  var VariationUtils = /** @class */ (function () {
1182
1182
  function VariationUtils() {
@@ -1581,6 +1581,7 @@
1581
1581
 
1582
1582
  var VariationHelper = /** @class */ (function () {
1583
1583
  function VariationHelper() {
1584
+ this._variations = [];
1584
1585
  this._lastKnownVariations = new Map();
1585
1586
  }
1586
1587
  VariationHelper.prototype.clearCache = function () {
@@ -1657,68 +1658,155 @@
1657
1658
  VariationHelper.prototype.loadVariation = function (obj, parts, usePbr) {
1658
1659
  if (usePbr === void 0) { usePbr = false; }
1659
1660
  return __awaiter(this, void 0, void 0, function () {
1660
- var len, i, variations, lastKnownVariations, j, variationSettings, newVariation, _a, e_2;
1661
- return __generator(this, function (_b) {
1662
- switch (_b.label) {
1661
+ var len, _loop_1, this_1, i, e_2;
1662
+ var _this = this;
1663
+ return __generator(this, function (_a) {
1664
+ switch (_a.label) {
1663
1665
  case 0:
1664
- _b.trys.push([0, 9, , 10]);
1666
+ _a.trys.push([0, 5, , 6]);
1665
1667
  len = parts.length;
1668
+ _loop_1 = function (i) {
1669
+ var variations, lastKnownVariations, variationPromise, _loop_2, j;
1670
+ return __generator(this, function (_b) {
1671
+ switch (_b.label) {
1672
+ case 0:
1673
+ variations = parts[i].variations;
1674
+ if (!variations || variations.length === 0) {
1675
+ if (this_1._getLastKnownVariations(parts[i].nodeId)) {
1676
+ parts[i].variations = this_1._getLastKnownVariations(parts[i].nodeId);
1677
+ this_1._applyVariations(obj, parts[i], usePbr);
1678
+ return [2 /*return*/, "continue"];
1679
+ }
1680
+ else {
1681
+ return [2 /*return*/, "continue"];
1682
+ }
1683
+ }
1684
+ lastKnownVariations = [];
1685
+ variationPromise = [];
1686
+ _loop_2 = function (j) {
1687
+ variationPromise.push(this_1.loadTheVariation(variations[j].gameObjectName || parts[i].decoId).then(function (variationSettings) { return __awaiter(_this, void 0, void 0, function () {
1688
+ var newVariation, _a;
1689
+ return __generator(this, function (_b) {
1690
+ switch (_b.label) {
1691
+ case 0:
1692
+ newVariation = new Variation();
1693
+ newVariation.decoId = parseFloat(variations[j].id);
1694
+ newVariation.brandId = variations[j].brandId;
1695
+ newVariation.optionText = variations[j].optionText;
1696
+ newVariation.gameObjectName = variations[j].gameObjectName;
1697
+ newVariation.supplierArticleNr = variations[j].supplierArticleNr;
1698
+ newVariation.materialId = variations[j].materialId;
1699
+ _a = newVariation;
1700
+ return [4 /*yield*/, AssetUtils.CreateMaterialFromAsset(variationSettings)];
1701
+ case 1:
1702
+ _a.material = _b.sent();
1703
+ lastKnownVariations.push(newVariation);
1704
+ return [2 /*return*/];
1705
+ }
1706
+ });
1707
+ }); }));
1708
+ };
1709
+ for (j = 0; j < variations.length; j++) {
1710
+ _loop_2(j);
1711
+ }
1712
+ return [4 /*yield*/, Promise.all(variationPromise)];
1713
+ case 1:
1714
+ _b.sent();
1715
+ this_1._setLastKnownVariations(parts[i].nodeId + "_" + parts[i].node, lastKnownVariations);
1716
+ parts[i].variations = lastKnownVariations;
1717
+ this_1._applyVariations(obj, parts[i], usePbr);
1718
+ return [2 /*return*/];
1719
+ }
1720
+ });
1721
+ };
1722
+ this_1 = this;
1666
1723
  i = 0;
1667
- _b.label = 1;
1724
+ _a.label = 1;
1668
1725
  case 1:
1669
- if (!(i < len)) return [3 /*break*/, 8];
1670
- variations = parts[i].variations;
1671
- if (!variations || variations.length === 0) {
1672
- if (this._getLastKnownVariations(parts[i].nodeId)) {
1673
- parts[i].variations = this._getLastKnownVariations(parts[i].nodeId);
1674
- this._applyVariations(obj, parts[i], usePbr);
1675
- return [3 /*break*/, 7];
1676
- }
1677
- else {
1678
- return [3 /*break*/, 7];
1679
- }
1680
- }
1681
- lastKnownVariations = [];
1682
- j = 0;
1683
- _b.label = 2;
1726
+ if (!(i < len)) return [3 /*break*/, 4];
1727
+ return [5 /*yield**/, _loop_1(i)];
1684
1728
  case 2:
1685
- if (!(j < variations.length)) return [3 /*break*/, 6];
1686
- return [4 /*yield*/, VariationUtils.LoadVariation(this.assetPath, variations[j].gameObjectName || parts[i].decoId)];
1729
+ _a.sent();
1730
+ _a.label = 3;
1687
1731
  case 3:
1688
- variationSettings = _b.sent();
1689
- newVariation = new Variation();
1690
- newVariation.decoId = parseFloat(variations[j].id);
1691
- newVariation.brandId = variations[j].brandId;
1692
- newVariation.gameObjectName = variations[j].gameObjectName;
1693
- newVariation.supplierArticleNr = variations[j].supplierArticleNr;
1694
- newVariation.materialId = variations[j].materialId;
1695
- _a = newVariation;
1696
- return [4 /*yield*/, AssetUtils.CreateMaterialFromAsset(variationSettings)];
1697
- case 4:
1698
- _a.material = _b.sent();
1699
- lastKnownVariations.push(newVariation);
1700
- _b.label = 5;
1701
- case 5:
1702
- j++;
1703
- return [3 /*break*/, 2];
1704
- case 6:
1705
- this._setLastKnownVariations(parts[i].nodeId, lastKnownVariations);
1706
- parts[i].variations = lastKnownVariations;
1707
- this._applyVariations(obj, parts[i], usePbr);
1708
- _b.label = 7;
1709
- case 7:
1710
1732
  i++;
1711
1733
  return [3 /*break*/, 1];
1712
- case 8: return [3 /*break*/, 10];
1713
- case 9:
1714
- e_2 = _b.sent();
1734
+ case 4: return [3 /*break*/, 6];
1735
+ case 5:
1736
+ e_2 = _a.sent();
1715
1737
  console.error(e_2);
1716
- return [3 /*break*/, 10];
1717
- case 10: return [2 /*return*/];
1738
+ return [3 /*break*/, 6];
1739
+ case 6: return [2 /*return*/];
1740
+ }
1741
+ });
1742
+ });
1743
+ };
1744
+ VariationHelper.prototype.get = function (id) {
1745
+ var len = this._variations.length;
1746
+ for (var i = 0; i < len; i++) {
1747
+ if (this._variations[i].id && this._variations[i].id === id) {
1748
+ return this._variations[i];
1749
+ }
1750
+ }
1751
+ };
1752
+ VariationHelper.prototype.set = function (variations) {
1753
+ var idx = this._variations.findIndex(function (v) { return v.id === variations.id; });
1754
+ if (idx > -1) {
1755
+ this._variations[idx] = variations;
1756
+ }
1757
+ else {
1758
+ this._variations.push(variations);
1759
+ }
1760
+ };
1761
+ VariationHelper.prototype.preloadVariations = function (schema, fileNames) {
1762
+ var _this = this;
1763
+ fileNames.forEach(function (fileName) {
1764
+ if (fileName && !_this.get(fileName)) {
1765
+ var settings_1 = new VariationSettings();
1766
+ settings_1.id = fileName;
1767
+ settings_1.loading = true;
1768
+ _this._variations.push(settings_1);
1769
+ var assetPath = _this.assetPath;
1770
+ if (!assetPath.endsWith('/')) {
1771
+ assetPath += '/';
1772
+ }
1773
+ VariationUtils.LoadVariation(assetPath, fileName).then(function (variationSettings) {
1774
+ settings_1.loading = false;
1775
+ settings_1.loaded.next(variationSettings);
1776
+ if (variationSettings) {
1777
+ _this.set(variationSettings);
1778
+ }
1779
+ });
1780
+ }
1781
+ });
1782
+ };
1783
+ VariationHelper.prototype.loadTheVariation = function (fileName) {
1784
+ return __awaiter(this, void 0, void 0, function () {
1785
+ var settings;
1786
+ return __generator(this, function (_a) {
1787
+ switch (_a.label) {
1788
+ case 0:
1789
+ if (!fileName) {
1790
+ return [2 /*return*/, null];
1791
+ }
1792
+ if (!this.get(fileName)) return [3 /*break*/, 3];
1793
+ settings = this.get(fileName);
1794
+ if (!settings.loading) return [3 /*break*/, 2];
1795
+ return [4 /*yield*/, this._waitForVariationToLoad(settings)];
1796
+ case 1: return [2 /*return*/, _a.sent()];
1797
+ case 2: return [2 /*return*/, settings];
1798
+ case 3: return [2 /*return*/];
1718
1799
  }
1719
1800
  });
1720
1801
  });
1721
1802
  };
1803
+ VariationHelper.prototype._waitForVariationToLoad = function (settings) {
1804
+ return new Promise(function (resolve) {
1805
+ settings.loaded.subscribe(function (value) {
1806
+ resolve(value);
1807
+ });
1808
+ });
1809
+ };
1722
1810
  VariationHelper.prototype._getChildrenFilterByProp = function (obj, userDataObjectProp, prop, value) {
1723
1811
  return obj.children.filter(function (child) {
1724
1812
  return child.userData &&
@@ -2255,6 +2343,7 @@
2255
2343
  _a.label = 1;
2256
2344
  case 1:
2257
2345
  _a.trys.push([1, 6, , 7]);
2346
+ this._log('start build');
2258
2347
  return [4 /*yield*/, this._downloadAsset(assetUrl, cdnUrl, schema)];
2259
2348
  case 2:
2260
2349
  _a.sent();
@@ -2262,10 +2351,12 @@
2262
2351
  this._selections = selections;
2263
2352
  this._decos = decos;
2264
2353
  this._linkSelectionsAndDecos();
2354
+ this._preloadMaterials(schema);
2265
2355
  return [4 /*yield*/, this._build()];
2266
2356
  case 3:
2267
2357
  build = _a.sent();
2268
2358
  this._cleanUp();
2359
+ this._log('finish build');
2269
2360
  return [2 /*return*/, build];
2270
2361
  case 4: throw 'Unsufficient data provided!';
2271
2362
  case 5: return [3 /*break*/, 7];
@@ -2377,6 +2468,9 @@
2377
2468
  return '';
2378
2469
  }
2379
2470
  };
2471
+ Builder.prototype._preloadMaterials = function (schema) {
2472
+ this._variationHelper.preloadVariations(schema, this._decos.map(function (d) { return d.gameObjectName; }));
2473
+ };
2380
2474
  Builder.prototype._setInstanceId = function (sku, instanceId, goodId) {
2381
2475
  return __awaiter(this, void 0, void 0, function () {
2382
2476
  var result;
@@ -2470,6 +2564,7 @@
2470
2564
  obj.visible = false; // no need to render visualy
2471
2565
  this._scene.add(obj);
2472
2566
  connected = false;
2567
+ this._log('build main model');
2473
2568
  for (i = 0, len = adjustables.length; i < len; i++) {
2474
2569
  adjustable = this._createAdjustable(obj, adjustables[i]);
2475
2570
  if (adjustable) {
@@ -2487,14 +2582,19 @@
2487
2582
  console.warn('No connection found for: ', adjustable.name);
2488
2583
  }
2489
2584
  }
2585
+ this._log('place addables');
2490
2586
  this._placeAddables(obj);
2587
+ this._log('update pivot');
2491
2588
  this._updatePivot(obj);
2589
+ this._log('load variations');
2492
2590
  return [4 /*yield*/, this._loadVariations(obj)];
2493
2591
  case 1:
2494
2592
  _a.sent();
2495
2593
  // this._variationHelper.clearCache();
2594
+ this._log('remove from scene');
2496
2595
  this._scene.remove(obj);
2497
2596
  ObjectUtils.DisposeObject(this._source);
2597
+ this._log('ready!');
2498
2598
  return [2 /*return*/, obj];
2499
2599
  case 2: throw 'No adjustables found!';
2500
2600
  }
@@ -2794,16 +2894,22 @@
2794
2894
  return __awaiter(this, void 0, void 0, function () {
2795
2895
  return __generator(this, function (_a) {
2796
2896
  switch (_a.label) {
2797
- case 0: return [4 /*yield*/, this._variationHelper.loadPart(obj, this._adjustables, true)];
2897
+ case 0:
2898
+ this._log('load variation for parts');
2899
+ return [4 /*yield*/, this._variationHelper.loadPart(obj, this._adjustables, true)];
2798
2900
  case 1:
2799
2901
  _a.sent();
2902
+ this._log('load variation for adjustables');
2800
2903
  return [4 /*yield*/, this._variationHelper.loadVariation(obj, this._adjustables, true)];
2801
2904
  case 2:
2802
2905
  _a.sent();
2906
+ this._log('load variation for addables');
2803
2907
  return [4 /*yield*/, this._variationHelper.loadVariation(obj, this._addables, true)];
2804
2908
  case 3:
2805
2909
  _a.sent();
2910
+ this._log('load variation clear cache');
2806
2911
  this._variationHelper.clearCache();
2912
+ this._log('load variations done');
2807
2913
  return [2 /*return*/];
2808
2914
  }
2809
2915
  });
@@ -2832,6 +2938,12 @@
2832
2938
  this._addables.length = 0;
2833
2939
  this._prepareTheSelections();
2834
2940
  };
2941
+ Builder.prototype._log = function (message) {
2942
+ if (this.debug) {
2943
+ this.debug(message);
2944
+ console.log(new Date(), message);
2945
+ }
2946
+ };
2835
2947
  return Builder;
2836
2948
  }());
2837
2949
  Builder.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Builder_Factory() { return new Builder(); }, token: Builder, providedIn: "root" });