@colijnit/configurator 12.0.4 → 12.0.7

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
  }
@@ -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() {
@@ -1186,44 +1186,53 @@
1186
1186
  };
1187
1187
  VariationUtils.LoadVariation = function (assetPath, fileName) {
1188
1188
  return __awaiter(this, void 0, void 0, function () {
1189
- var id, file, err_1, mute;
1189
+ var _this = this;
1190
1190
  return __generator(this, function (_a) {
1191
- switch (_a.label) {
1192
- case 0:
1193
- if (!fileName) {
1194
- return [2 /*return*/, null];
1195
- }
1196
- if (fileName.indexOf('ione3d') < 0) {
1197
- fileName = fileName.concat('.ione3d');
1198
- }
1199
- id = fileName.substr(0, fileName.lastIndexOf('.ione3d'));
1200
- _a.label = 1;
1201
- case 1:
1202
- _a.trys.push([1, 6, , 7]);
1203
- if (!assetPath.endsWith('/')) {
1204
- assetPath += '/';
1205
- }
1206
- if (!window.hasOwnProperty('downloadVariation')) {
1207
- console.error('downloadVariation not defined in window global');
1208
- return [2 /*return*/, null];
1209
- }
1210
- file = void 0;
1211
- if (!this.MaterialCache.has(id)) return [3 /*break*/, 2];
1212
- file = this.MaterialCache.get(id);
1213
- return [3 /*break*/, 4];
1214
- case 2: return [4 /*yield*/, window.downloadVariation(assetPath.replace('https://cdn1.colijn-it.nl/', '') + "variation/" + fileName)];
1215
- case 3:
1216
- file = _a.sent();
1217
- this.MaterialCache.set(id, file);
1218
- _a.label = 4;
1219
- case 4: return [4 /*yield*/, VariationUtils.GetVariationSettingsFromFile(id, file)];
1220
- case 5: return [2 /*return*/, _a.sent()];
1221
- case 6:
1222
- err_1 = _a.sent();
1223
- mute = err_1;
1224
- return [2 /*return*/, null];
1225
- case 7: return [2 /*return*/];
1226
- }
1191
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1192
+ var id, file, settings, err_1, mute;
1193
+ return __generator(this, function (_a) {
1194
+ switch (_a.label) {
1195
+ case 0:
1196
+ if (!fileName) {
1197
+ resolve(null);
1198
+ }
1199
+ if (fileName.indexOf('ione3d') < 0) {
1200
+ fileName = fileName.concat('.ione3d');
1201
+ }
1202
+ id = fileName.substr(0, fileName.lastIndexOf('.ione3d'));
1203
+ _a.label = 1;
1204
+ case 1:
1205
+ _a.trys.push([1, 6, , 7]);
1206
+ if (!assetPath.endsWith('/')) {
1207
+ assetPath += '/';
1208
+ }
1209
+ if (!window.hasOwnProperty('downloadVariation')) {
1210
+ console.error('downloadVariation not defined in window global');
1211
+ reject('downloadVariation not defined in window global');
1212
+ }
1213
+ file = void 0;
1214
+ if (!this.MaterialCache.has(id)) return [3 /*break*/, 2];
1215
+ resolve(this.MaterialCache.get(id));
1216
+ return [3 /*break*/, 5];
1217
+ case 2: return [4 /*yield*/, window.downloadVariation(assetPath.replace('https://cdn1.colijn-it.nl/', '') + "variation/" + fileName)];
1218
+ case 3:
1219
+ file = _a.sent();
1220
+ return [4 /*yield*/, VariationUtils.GetVariationSettingsFromFile(id, file)];
1221
+ case 4:
1222
+ settings = _a.sent();
1223
+ this.MaterialCache.set(id, settings);
1224
+ resolve(settings);
1225
+ _a.label = 5;
1226
+ case 5: return [3 /*break*/, 7];
1227
+ case 6:
1228
+ err_1 = _a.sent();
1229
+ mute = err_1;
1230
+ reject(err_1);
1231
+ return [3 /*break*/, 7];
1232
+ case 7: return [2 /*return*/];
1233
+ }
1234
+ });
1235
+ }); })];
1227
1236
  });
1228
1237
  });
1229
1238
  };
@@ -1581,6 +1590,7 @@
1581
1590
 
1582
1591
  var VariationHelper = /** @class */ (function () {
1583
1592
  function VariationHelper() {
1593
+ this._variations = [];
1584
1594
  this._lastKnownVariations = new Map();
1585
1595
  }
1586
1596
  VariationHelper.prototype.clearCache = function () {
@@ -1657,68 +1667,155 @@
1657
1667
  VariationHelper.prototype.loadVariation = function (obj, parts, usePbr) {
1658
1668
  if (usePbr === void 0) { usePbr = false; }
1659
1669
  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) {
1670
+ var len, _loop_1, this_1, i, e_2;
1671
+ var _this = this;
1672
+ return __generator(this, function (_a) {
1673
+ switch (_a.label) {
1663
1674
  case 0:
1664
- _b.trys.push([0, 9, , 10]);
1675
+ _a.trys.push([0, 5, , 6]);
1665
1676
  len = parts.length;
1677
+ _loop_1 = function (i) {
1678
+ var variations, lastKnownVariations, variationPromise, _loop_2, j;
1679
+ return __generator(this, function (_b) {
1680
+ switch (_b.label) {
1681
+ case 0:
1682
+ variations = parts[i].variations;
1683
+ if (!variations || variations.length === 0) {
1684
+ if (this_1._getLastKnownVariations(parts[i].nodeId)) {
1685
+ parts[i].variations = this_1._getLastKnownVariations(parts[i].nodeId);
1686
+ this_1._applyVariations(obj, parts[i], usePbr);
1687
+ return [2 /*return*/, "continue"];
1688
+ }
1689
+ else {
1690
+ return [2 /*return*/, "continue"];
1691
+ }
1692
+ }
1693
+ lastKnownVariations = [];
1694
+ variationPromise = [];
1695
+ _loop_2 = function (j) {
1696
+ variationPromise.push(this_1.loadTheVariation(variations[j].gameObjectName || parts[i].decoId).then(function (variationSettings) { return __awaiter(_this, void 0, void 0, function () {
1697
+ var newVariation, _a;
1698
+ return __generator(this, function (_b) {
1699
+ switch (_b.label) {
1700
+ case 0:
1701
+ newVariation = new Variation();
1702
+ newVariation.decoId = parseFloat(variations[j].id);
1703
+ newVariation.brandId = variations[j].brandId;
1704
+ newVariation.optionText = variations[j].optionText;
1705
+ newVariation.gameObjectName = variations[j].gameObjectName;
1706
+ newVariation.supplierArticleNr = variations[j].supplierArticleNr;
1707
+ newVariation.materialId = variations[j].materialId;
1708
+ _a = newVariation;
1709
+ return [4 /*yield*/, AssetUtils.CreateMaterialFromAsset(variationSettings)];
1710
+ case 1:
1711
+ _a.material = _b.sent();
1712
+ lastKnownVariations.push(newVariation);
1713
+ return [2 /*return*/];
1714
+ }
1715
+ });
1716
+ }); }));
1717
+ };
1718
+ for (j = 0; j < variations.length; j++) {
1719
+ _loop_2(j);
1720
+ }
1721
+ return [4 /*yield*/, Promise.all(variationPromise)];
1722
+ case 1:
1723
+ _b.sent();
1724
+ this_1._setLastKnownVariations(parts[i].nodeId + "_" + parts[i].node, lastKnownVariations);
1725
+ parts[i].variations = lastKnownVariations;
1726
+ this_1._applyVariations(obj, parts[i], usePbr);
1727
+ return [2 /*return*/];
1728
+ }
1729
+ });
1730
+ };
1731
+ this_1 = this;
1666
1732
  i = 0;
1667
- _b.label = 1;
1733
+ _a.label = 1;
1668
1734
  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;
1735
+ if (!(i < len)) return [3 /*break*/, 4];
1736
+ return [5 /*yield**/, _loop_1(i)];
1684
1737
  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)];
1738
+ _a.sent();
1739
+ _a.label = 3;
1687
1740
  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
1741
  i++;
1711
1742
  return [3 /*break*/, 1];
1712
- case 8: return [3 /*break*/, 10];
1713
- case 9:
1714
- e_2 = _b.sent();
1743
+ case 4: return [3 /*break*/, 6];
1744
+ case 5:
1745
+ e_2 = _a.sent();
1715
1746
  console.error(e_2);
1716
- return [3 /*break*/, 10];
1717
- case 10: return [2 /*return*/];
1747
+ return [3 /*break*/, 6];
1748
+ case 6: return [2 /*return*/];
1749
+ }
1750
+ });
1751
+ });
1752
+ };
1753
+ VariationHelper.prototype.get = function (id) {
1754
+ var len = this._variations.length;
1755
+ for (var i = 0; i < len; i++) {
1756
+ if (this._variations[i].id && this._variations[i].id === id) {
1757
+ return this._variations[i];
1758
+ }
1759
+ }
1760
+ };
1761
+ VariationHelper.prototype.set = function (variations) {
1762
+ var idx = this._variations.findIndex(function (v) { return v.id === variations.id; });
1763
+ if (idx > -1) {
1764
+ this._variations[idx] = variations;
1765
+ }
1766
+ else {
1767
+ this._variations.push(variations);
1768
+ }
1769
+ };
1770
+ VariationHelper.prototype.preloadVariations = function (schema, fileNames) {
1771
+ var _this = this;
1772
+ fileNames.forEach(function (fileName) {
1773
+ if (fileName && !_this.get(fileName)) {
1774
+ var settings_1 = new VariationSettings();
1775
+ settings_1.id = fileName;
1776
+ settings_1.loading = true;
1777
+ _this._variations.push(settings_1);
1778
+ var assetPath = _this.assetPath;
1779
+ if (!assetPath.endsWith('/')) {
1780
+ assetPath += '/';
1781
+ }
1782
+ VariationUtils.LoadVariation(assetPath, fileName).then(function (variationSettings) {
1783
+ settings_1.loading = false;
1784
+ settings_1.loaded.next(variationSettings);
1785
+ if (variationSettings) {
1786
+ _this.set(variationSettings);
1787
+ }
1788
+ });
1789
+ }
1790
+ });
1791
+ };
1792
+ VariationHelper.prototype.loadTheVariation = function (fileName) {
1793
+ return __awaiter(this, void 0, void 0, function () {
1794
+ var settings;
1795
+ return __generator(this, function (_a) {
1796
+ switch (_a.label) {
1797
+ case 0:
1798
+ if (!fileName) {
1799
+ return [2 /*return*/, null];
1800
+ }
1801
+ if (!this.get(fileName)) return [3 /*break*/, 3];
1802
+ settings = this.get(fileName);
1803
+ if (!settings.loading) return [3 /*break*/, 2];
1804
+ return [4 /*yield*/, this._waitForVariationToLoad(settings)];
1805
+ case 1: return [2 /*return*/, _a.sent()];
1806
+ case 2: return [2 /*return*/, settings];
1807
+ case 3: return [2 /*return*/];
1718
1808
  }
1719
1809
  });
1720
1810
  });
1721
1811
  };
1812
+ VariationHelper.prototype._waitForVariationToLoad = function (settings) {
1813
+ return new Promise(function (resolve) {
1814
+ settings.loaded.subscribe(function (value) {
1815
+ resolve(value);
1816
+ });
1817
+ });
1818
+ };
1722
1819
  VariationHelper.prototype._getChildrenFilterByProp = function (obj, userDataObjectProp, prop, value) {
1723
1820
  return obj.children.filter(function (child) {
1724
1821
  return child.userData &&
@@ -2255,6 +2352,7 @@
2255
2352
  _a.label = 1;
2256
2353
  case 1:
2257
2354
  _a.trys.push([1, 6, , 7]);
2355
+ this._log('start build');
2258
2356
  return [4 /*yield*/, this._downloadAsset(assetUrl, cdnUrl, schema)];
2259
2357
  case 2:
2260
2358
  _a.sent();
@@ -2262,10 +2360,12 @@
2262
2360
  this._selections = selections;
2263
2361
  this._decos = decos;
2264
2362
  this._linkSelectionsAndDecos();
2363
+ this._preloadMaterials(schema);
2265
2364
  return [4 /*yield*/, this._build()];
2266
2365
  case 3:
2267
2366
  build = _a.sent();
2268
2367
  this._cleanUp();
2368
+ this._log('finish build');
2269
2369
  return [2 /*return*/, build];
2270
2370
  case 4: throw 'Unsufficient data provided!';
2271
2371
  case 5: return [3 /*break*/, 7];
@@ -2377,6 +2477,9 @@
2377
2477
  return '';
2378
2478
  }
2379
2479
  };
2480
+ Builder.prototype._preloadMaterials = function (schema) {
2481
+ this._variationHelper.preloadVariations(schema, this._decos.map(function (d) { return d.gameObjectName; }));
2482
+ };
2380
2483
  Builder.prototype._setInstanceId = function (sku, instanceId, goodId) {
2381
2484
  return __awaiter(this, void 0, void 0, function () {
2382
2485
  var result;
@@ -2470,6 +2573,7 @@
2470
2573
  obj.visible = false; // no need to render visualy
2471
2574
  this._scene.add(obj);
2472
2575
  connected = false;
2576
+ this._log('build main model');
2473
2577
  for (i = 0, len = adjustables.length; i < len; i++) {
2474
2578
  adjustable = this._createAdjustable(obj, adjustables[i]);
2475
2579
  if (adjustable) {
@@ -2487,14 +2591,19 @@
2487
2591
  console.warn('No connection found for: ', adjustable.name);
2488
2592
  }
2489
2593
  }
2594
+ this._log('place addables');
2490
2595
  this._placeAddables(obj);
2596
+ this._log('update pivot');
2491
2597
  this._updatePivot(obj);
2598
+ this._log('load variations');
2492
2599
  return [4 /*yield*/, this._loadVariations(obj)];
2493
2600
  case 1:
2494
2601
  _a.sent();
2495
2602
  // this._variationHelper.clearCache();
2603
+ this._log('remove from scene');
2496
2604
  this._scene.remove(obj);
2497
2605
  ObjectUtils.DisposeObject(this._source);
2606
+ this._log('ready!');
2498
2607
  return [2 /*return*/, obj];
2499
2608
  case 2: throw 'No adjustables found!';
2500
2609
  }
@@ -2794,16 +2903,22 @@
2794
2903
  return __awaiter(this, void 0, void 0, function () {
2795
2904
  return __generator(this, function (_a) {
2796
2905
  switch (_a.label) {
2797
- case 0: return [4 /*yield*/, this._variationHelper.loadPart(obj, this._adjustables, true)];
2906
+ case 0:
2907
+ this._log('load variation for parts');
2908
+ return [4 /*yield*/, this._variationHelper.loadPart(obj, this._adjustables, true)];
2798
2909
  case 1:
2799
2910
  _a.sent();
2911
+ this._log('load variation for adjustables');
2800
2912
  return [4 /*yield*/, this._variationHelper.loadVariation(obj, this._adjustables, true)];
2801
2913
  case 2:
2802
2914
  _a.sent();
2915
+ this._log('load variation for addables');
2803
2916
  return [4 /*yield*/, this._variationHelper.loadVariation(obj, this._addables, true)];
2804
2917
  case 3:
2805
2918
  _a.sent();
2919
+ this._log('load variation clear cache');
2806
2920
  this._variationHelper.clearCache();
2921
+ this._log('load variations done');
2807
2922
  return [2 /*return*/];
2808
2923
  }
2809
2924
  });
@@ -2832,6 +2947,12 @@
2832
2947
  this._addables.length = 0;
2833
2948
  this._prepareTheSelections();
2834
2949
  };
2950
+ Builder.prototype._log = function (message) {
2951
+ if (this.debug) {
2952
+ this.debug(message);
2953
+ console.log(new Date(), message);
2954
+ }
2955
+ };
2835
2956
  return Builder;
2836
2957
  }());
2837
2958
  Builder.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Builder_Factory() { return new Builder(); }, token: Builder, providedIn: "root" });