@colijnit/configurator 259.1.2 → 259.1.3

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.
@@ -383,6 +383,9 @@ class SceneUtils {
383
383
  const con2Name = (con2.constructor.name === 'Mesh' || con2.constructor.name === 'Object3D') ? con2.name : con2.connector;
384
384
  const sameParent = (con1.constructor.name === 'Mesh' || con1.constructor.name === 'Object3D') &&
385
385
  (con2.constructor.name === 'Mesh' || con2.constructor.name === 'Object3D') ? con1.parent === con2.parent : false;
386
+ if (!con1Name || !con2Name) {
387
+ return false;
388
+ }
386
389
  const parts1 = con1Name.toUpperCase().split('_'), parts2 = con2Name.toUpperCase().split('_');
387
390
  if (parts1.length >= 3 && parts2.length >= 3 && !sameParent) {
388
391
  const connectable = parts1[0] === 'C' && parts2[0] === 'C' &&
@@ -408,8 +411,8 @@ class SceneUtils {
408
411
  if (!scene || !parent) {
409
412
  return false;
410
413
  }
411
- con1['connectedTo'] = con2.parent.name;
412
- con2['connectedTo'] = con1.parent.name;
414
+ con1['connectedTo'] = con2 && con2.parent ? con2.parent.name : '';
415
+ con2['connectedTo'] = con1 && con1.parent ? con1.parent.name : '';
413
416
  const motherRotation = new THREE.Euler(0, 0, 0);
414
417
  const motherPosition = new THREE.Vector3(0, 0, 0);
415
418
  parent.updateMatrixWorld();
@@ -419,33 +422,53 @@ class SceneUtils {
419
422
  parent.position.set(0, 0, 0);
420
423
  scene.updateMatrixWorld(true);
421
424
  const con1Quat = new THREE.Quaternion();
422
- con1.getWorldQuaternion(con1Quat);
425
+ if (con1) {
426
+ con1.getWorldQuaternion(con1Quat);
427
+ }
423
428
  const con2Quat = new THREE.Quaternion();
424
- con2.getWorldQuaternion(con2Quat);
429
+ if (con2) {
430
+ con2.getWorldQuaternion(con2Quat);
431
+ }
425
432
  const con1QuatParent = new THREE.Quaternion();
426
- con1.parent.getWorldQuaternion(con1QuatParent);
433
+ if (con1 && con1.parent) {
434
+ con1.parent.getWorldQuaternion(con1QuatParent);
435
+ }
427
436
  const con2QuatParent = new THREE.Quaternion();
428
- con2.parent.getWorldQuaternion(con2QuatParent);
437
+ if (con2 && con2.parent) {
438
+ con2.parent.getWorldQuaternion(con2QuatParent);
439
+ }
429
440
  const rotation = new THREE.Quaternion().multiplyQuaternions(con1Quat.invert(), con2Quat).multiply(new THREE.Quaternion().multiplyQuaternions(con1QuatParent, con1QuatParent));
430
- con2.parent.quaternion.copy(rotation);
441
+ if (con2 && con2.parent) {
442
+ con2.parent.quaternion.copy(rotation);
443
+ }
431
444
  // Update because the matrix has been tempered with
432
445
  scene.updateMatrixWorld(true);
433
446
  // Move the connectors towards eachother
434
447
  const con1Pos = new THREE.Vector3();
435
- con1.getWorldPosition(con1Pos);
448
+ if (con1) {
449
+ con1.getWorldPosition(con1Pos);
450
+ }
436
451
  const con2Pos = new THREE.Vector3();
437
- con2.getWorldPosition(con2Pos);
452
+ if (con2) {
453
+ con2.getWorldPosition(con2Pos);
454
+ }
438
455
  const move = con1Pos.sub(con2Pos);
439
- con2.parent.position.x += move.x;
440
- con2.parent.position.y += move.y;
441
- con2.parent.position.z += move.z;
456
+ if (con2 && con2.parent) {
457
+ con2.parent.position.x += move.x;
458
+ con2.parent.position.y += move.y;
459
+ con2.parent.position.z += move.z;
460
+ }
442
461
  // reset parent's objects rotation and position
443
462
  parent.rotation.copy(motherRotation);
444
463
  parent.position.copy(motherPosition);
445
464
  scene.updateMatrixWorld(true);
446
465
  // Set the connected flag
447
- con1['connected'] = true;
448
- con2['connected'] = true;
466
+ if (con1) {
467
+ con1['connected'] = true;
468
+ }
469
+ if (con2) {
470
+ con2['connected'] = true;
471
+ }
449
472
  return true;
450
473
  }
451
474
  }
@@ -513,40 +536,46 @@ class Material {
513
536
  }
514
537
  }
515
538
 
539
+ class BaseUtils {
540
+ log(message) {
541
+ if (this.debug) {
542
+ this.debug(message);
543
+ console.log(new Date(), message);
544
+ }
545
+ }
546
+ }
547
+
516
548
  // @dynamic
517
- class ImageUtils {
549
+ class ImageUtils extends BaseUtils {
518
550
  static CreateTextureFromBase64(id, base64, material, defaultFlip = false) {
519
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
551
+ var _a, _b;
552
+ return __awaiter(this, void 0, void 0, function* () {
520
553
  if (ImageUtils.textures.has(id)) {
521
- resolve(ImageUtils.textures.get(id));
554
+ return ImageUtils.textures.get(id);
522
555
  }
523
- else {
524
- if (!base64) {
525
- resolve(new THREE.Texture());
526
- }
527
- else {
528
- if (window.hasOwnProperty('textureLoader')) {
529
- resolve(yield window.textureLoader(base64));
530
- }
531
- else {
532
- const loader = new THREE.TextureLoader();
533
- loader.load(base64, (texture) => {
534
- texture.anisotropy = 16;
535
- texture.wrapS = THREE.RepeatWrapping;
536
- texture.wrapT = THREE.RepeatWrapping;
537
- texture.repeat = new THREE.Vector2(material ? material.repeatX : 1, material ? material.repeatY : 1);
538
- texture.flipY = defaultFlip;
539
- texture.needsUpdate = true;
540
- ImageUtils.textures.set(id, texture);
541
- resolve(texture);
542
- }, () => {
543
- }, () => {
544
- resolve(new THREE.Texture());
545
- });
546
- }
547
- }
556
+ try {
557
+ if (window.textureLoader) {
558
+ const texture = yield window.textureLoader(base64, material);
559
+ ImageUtils.textures.set(id, texture);
560
+ return texture;
561
+ }
562
+ const loader = new THREE.TextureLoader();
563
+ const texture = yield new Promise((resolve, reject) => {
564
+ loader.load(base64, resolve, undefined, (err) => reject(err));
565
+ });
566
+ texture.anisotropy = 16;
567
+ texture.wrapS = THREE.RepeatWrapping;
568
+ texture.wrapT = THREE.RepeatWrapping;
569
+ texture.repeat = new THREE.Vector2((_a = material === null || material === void 0 ? void 0 : material.repeatX) !== null && _a !== void 0 ? _a : 1, (_b = material === null || material === void 0 ? void 0 : material.repeatY) !== null && _b !== void 0 ? _b : 1);
570
+ texture.flipY = defaultFlip;
571
+ texture.needsUpdate = true;
572
+ ImageUtils.textures.set(id, texture);
573
+ return texture;
548
574
  }
549
- }));
575
+ catch (err) {
576
+ return null;
577
+ }
578
+ });
550
579
  }
551
580
  static getDocBodyWithMimeTypeDefinition(fileName, documentBody) {
552
581
  if (documentBody === null) {
@@ -1058,8 +1087,9 @@ class VariationUtils {
1058
1087
  }
1059
1088
  VariationUtils.MaterialCache = new Map();
1060
1089
 
1061
- class VariationHelper {
1090
+ class VariationHelper extends BaseUtils {
1062
1091
  constructor() {
1092
+ super(...arguments);
1063
1093
  this._variations = [];
1064
1094
  this._lastKnownVariations = new Map();
1065
1095
  }
@@ -1157,7 +1187,7 @@ class VariationHelper {
1157
1187
  }
1158
1188
  }
1159
1189
  catch (e) {
1160
- this._log(e.message);
1190
+ this.log(e.message);
1161
1191
  }
1162
1192
  });
1163
1193
  }
@@ -1567,12 +1597,6 @@ class VariationHelper {
1567
1597
  }
1568
1598
  return new Color();
1569
1599
  }
1570
- _log(message) {
1571
- if (this.debug) {
1572
- this.debug(message);
1573
- console.log(new Date(), message);
1574
- }
1575
- }
1576
1600
  }
1577
1601
 
1578
1602
  class ConfiguratorService {
@@ -1601,11 +1625,13 @@ class ConfiguratorService {
1601
1625
  }
1602
1626
  getSelections(showLoader = false, publicationCode = 2) {
1603
1627
  return __awaiter(this, void 0, void 0, function* () {
1604
- const selections = yield this._configuratorApi.getSelections(showLoader);
1605
- selections.resultObjects.filter((s) => {
1606
- (isNill(s.hierarchicalPublicationCode) || ((s.hierarchicalPublicationCode & publicationCode) > 0)) && ((s.nodeType === NodeType.Question && (((s.questionPublicationCode & publicationCode) > 0) || isNill(s.questionPublicationCode))) ||
1607
- (s.nodeType === NodeType.Answer && (((s.answerPublicationCode & publicationCode) > 0) || isNill(s.answerPublicationCode))));
1608
- });
1628
+ let selections = yield this._configuratorApi.getSelections(showLoader);
1629
+ if (selections && selections.resultObjects) {
1630
+ selections.resultObjects.filter((s) => {
1631
+ (isNill(s.hierarchicalPublicationCode) || ((s.hierarchicalPublicationCode & publicationCode) > 0)) && ((s.nodeType === NodeType.Question && (((s.questionPublicationCode & publicationCode) > 0) || isNill(s.questionPublicationCode))) ||
1632
+ (s.nodeType === NodeType.Answer && (((s.answerPublicationCode & publicationCode) > 0) || isNill(s.answerPublicationCode))));
1633
+ });
1634
+ }
1609
1635
  return selections;
1610
1636
  });
1611
1637
  }
@@ -1617,11 +1643,13 @@ class ConfiguratorService {
1617
1643
  getQuestionAndAnswers(showLoader = false, publicationCode = 2) {
1618
1644
  return __awaiter(this, void 0, void 0, function* () {
1619
1645
  const questionAndAnswers = yield this._configuratorApi.getQuestionAndAnswers(showLoader);
1620
- questionAndAnswers.answers.filter((answer) => {
1621
- (notNill(answer.hierarchicalPublicationCode) && (answer.hierarchicalPublicationCode & publicationCode) === 0) ||
1622
- (answer.type === NodeType.Question && (answer.questionPublicationCode & publicationCode) === 0 && notNill(answer.questionPublicationCode)) ||
1623
- (answer.type === NodeType.Answer && (answer.publicationCode & publicationCode) === 0 && notNill(answer.publicationCode));
1624
- });
1646
+ if (questionAndAnswers && questionAndAnswers.answers) {
1647
+ questionAndAnswers.answers.filter((answer) => {
1648
+ (notNill(answer.hierarchicalPublicationCode) && (answer.hierarchicalPublicationCode & publicationCode) === 0) ||
1649
+ (answer.type === NodeType.Question && (answer.questionPublicationCode & publicationCode) === 0 && notNill(answer.questionPublicationCode)) ||
1650
+ (answer.type === NodeType.Answer && (answer.publicationCode & publicationCode) === 0 && notNill(answer.publicationCode));
1651
+ });
1652
+ }
1625
1653
  return questionAndAnswers;
1626
1654
  });
1627
1655
  }
@@ -1647,18 +1675,20 @@ class ConfiguratorService {
1647
1675
 
1648
1676
  class ObjectUtils {
1649
1677
  static DisposeNode(node) {
1650
- node.traverse((obj) => {
1651
- if (obj instanceof Mesh) {
1652
- if (obj.geometry) {
1653
- obj.geometry.dispose();
1678
+ if (node) {
1679
+ node.traverse((obj) => {
1680
+ if (obj instanceof Mesh) {
1681
+ if (obj.geometry) {
1682
+ obj.geometry.dispose();
1683
+ }
1684
+ ObjectUtils.DisposeMaterial(obj.material);
1654
1685
  }
1655
- ObjectUtils.DisposeMaterial(obj.material);
1656
- }
1657
- if (typeof obj.dispose === 'function') {
1658
- // @ts-ignore
1659
- obj.dispose();
1660
- }
1661
- });
1686
+ if (typeof obj.dispose === 'function') {
1687
+ // @ts-ignore
1688
+ obj.dispose();
1689
+ }
1690
+ });
1691
+ }
1662
1692
  }
1663
1693
  static DisposeMaterial(material) {
1664
1694
  if (!material) {
@@ -1817,15 +1847,15 @@ class Builder {
1817
1847
  getQuestionAndAnswers(publicationCode) {
1818
1848
  return __awaiter(this, void 0, void 0, function* () {
1819
1849
  const questionsAndAnswers = yield this._configuratorService.getQuestionAndAnswers(false, publicationCode);
1820
- this._answers = questionsAndAnswers.answers;
1821
- this.answersReceived.next(questionsAndAnswers.answers);
1850
+ this._answers = questionsAndAnswers && questionsAndAnswers.answers ? questionsAndAnswers.answers : [];
1851
+ this.answersReceived.next(this._answers);
1822
1852
  });
1823
1853
  }
1824
1854
  selectAnswer(answer) {
1825
1855
  return __awaiter(this, void 0, void 0, function* () {
1826
1856
  yield this._configuratorService.selectAnswer(answer, false);
1827
1857
  yield this.getQuestionAndAnswers();
1828
- if (this._answers.length === 0) {
1858
+ if (this._answers && this._answers.length === 0) {
1829
1859
  this._build();
1830
1860
  }
1831
1861
  });
@@ -1878,9 +1908,12 @@ class Builder {
1878
1908
  }
1879
1909
  }
1880
1910
  _preloadMaterials() {
1881
- this._variationHelper.preloadVariations(this._decos
1882
- .filter(d => d.gameObjectName && d.type === DecoNodeType.Variation)
1883
- .map(d => d.gameObjectName));
1911
+ if (this._decos && this._decos.length) {
1912
+ const materials = [...new Set(this._decos
1913
+ .filter(d => d.gameObjectName && d.type === DecoNodeType.Variation)
1914
+ .map(d => d.gameObjectName))];
1915
+ this._variationHelper.preloadVariations(materials);
1916
+ }
1884
1917
  }
1885
1918
  _setInstanceId(sku, instanceId, goodId) {
1886
1919
  return __awaiter(this, void 0, void 0, function* () {
@@ -1996,6 +2029,9 @@ class Builder {
1996
2029
  });
1997
2030
  }
1998
2031
  _prepareTheSelections() {
2032
+ if (!this._selections || !this._selections.length) {
2033
+ return;
2034
+ }
1999
2035
  const selections = this._selections.slice();
2000
2036
  const selectionOfArticle = selections.find(s => s.nodeType === NodeType.Article);
2001
2037
  const adjustableSelections = selections.filter(s => s.addAdjust === '2');
@@ -2121,17 +2157,19 @@ class Builder {
2121
2157
  * @private
2122
2158
  */
2123
2159
  _getMaterialIdFromParent(id) {
2124
- const idx = this._selections.findIndex(s => s.node === id);
2125
- let currentLevel = 999;
2126
- if (idx > -1) {
2127
- for (let i = idx; i > 0; i--) {
2128
- const selection = this._selections[i];
2129
- if (selection.presentationLevel >= currentLevel) {
2130
- break;
2131
- }
2132
- currentLevel = selection.presentationLevel;
2133
- if (selection.hdecoGameObject) {
2134
- return selection.hdecoGameObject;
2160
+ if (this._selections) {
2161
+ const idx = this._selections.findIndex(s => s.node === id);
2162
+ let currentLevel = 999;
2163
+ if (idx > -1) {
2164
+ for (let i = idx; i > 0; i--) {
2165
+ const selection = this._selections[i];
2166
+ if (selection.presentationLevel >= currentLevel) {
2167
+ break;
2168
+ }
2169
+ currentLevel = selection.presentationLevel;
2170
+ if (selection.hdecoGameObject) {
2171
+ return selection.hdecoGameObject;
2172
+ }
2135
2173
  }
2136
2174
  }
2137
2175
  }
@@ -2213,7 +2251,7 @@ class Builder {
2213
2251
  _getGoodIdFromSku(sku) {
2214
2252
  return __awaiter(this, void 0, void 0, function* () {
2215
2253
  const response = yield this._configuratorService.getGoodIdFromSku(sku, false);
2216
- if (response.validationResult.success && response.resultObject) {
2254
+ if (response && response.validationResult && response.validationResult.success && response.resultObject) {
2217
2255
  return response.resultObject;
2218
2256
  }
2219
2257
  });
@@ -2232,7 +2270,7 @@ class Builder {
2232
2270
  }
2233
2271
  let article;
2234
2272
  const articleResponse = yield this._configuratorService.getArticleQuickSel(goodId, false);
2235
- if (articleResponse.validationResult.success && articleResponse.resultObject) {
2273
+ if (articleResponse && articleResponse.validationResult && articleResponse.validationResult.success && articleResponse.resultObject) {
2236
2274
  if (articleResponse.resultObject.hasOwnProperty('oArticle')) {
2237
2275
  const obj = Array.isArray(articleResponse.resultObject['oArticle']) ? articleResponse.resultObject['oArticle'][0] : articleResponse.resultObject['oArticle'];
2238
2276
  article = this._boFactory.makeWithRawBackendData(Article, obj);
@@ -2250,7 +2288,7 @@ class Builder {
2250
2288
  return __awaiter(this, void 0, void 0, function* () {
2251
2289
  this._selections = [];
2252
2290
  const selectionResponse = yield this._configuratorService.getSelections(false, publicationCode);
2253
- if (selectionResponse.resultObjects && selectionResponse.resultObjects.length > 0) {
2291
+ if (selectionResponse && selectionResponse.resultObjects && selectionResponse.resultObjects.length > 0) {
2254
2292
  this._selections = this._boFactory.makeBOArrayFromRawBackendDataArray(Selection, selectionResponse.resultObjects);
2255
2293
  this._selections.forEach(s => s.instanceId = instanceId);
2256
2294
  // const filtered: Selection[] = this._selections.filter(s => s.nodeType !== NodeType.Article && s.presentationLevel === 1);
@@ -2265,7 +2303,7 @@ class Builder {
2265
2303
  return __awaiter(this, void 0, void 0, function* () {
2266
2304
  this._decos = [];
2267
2305
  const decosResponse = yield this._configuratorService.getDecos(false);
2268
- if (decosResponse.resultObjects && decosResponse.resultObjects.length > 0) {
2306
+ if (decosResponse && decosResponse.resultObjects && decosResponse.resultObjects.length > 0) {
2269
2307
  this._decos = this._boFactory.makeBOArrayFromRawBackendDataArray(DecoNode, decosResponse.resultObjects);
2270
2308
  this.decosReceived.next(this._decos);
2271
2309
  }
@@ -2275,6 +2313,9 @@ class Builder {
2275
2313
  });
2276
2314
  }
2277
2315
  _linkSelectionsAndDecos() {
2316
+ if (!this._selections || !this._selections.length) {
2317
+ return;
2318
+ }
2278
2319
  const len = this._selections.length;
2279
2320
  for (let i = 0; i < len; i++) {
2280
2321
  // const id: string = this.selections[i].artNodeIdDeco;
@@ -2292,9 +2333,12 @@ class Builder {
2292
2333
  }
2293
2334
  }
2294
2335
  _getVariations() {
2295
- return this._decos.filter((deco) => {
2296
- return deco.type === DecoNodeType.Variation;
2297
- });
2336
+ if (this._decos && this._decos.length) {
2337
+ return this._decos.filter((deco) => {
2338
+ return deco.type === DecoNodeType.Variation;
2339
+ });
2340
+ }
2341
+ return [];
2298
2342
  }
2299
2343
  _loadVariations(obj) {
2300
2344
  return __awaiter(this, void 0, void 0, function* () {
@@ -2310,6 +2354,9 @@ class Builder {
2310
2354
  });
2311
2355
  }
2312
2356
  _getAdjustables() {
2357
+ if (!this._selections || !this._selections.length) {
2358
+ return [];
2359
+ }
2313
2360
  return this._selections.filter(s => {
2314
2361
  const node = s.decoNode;
2315
2362
  return node && node.gameObjectName && node.type === DecoNodeType.Part && node.kind === DecoNodeKind.Adjustable;
@@ -2615,8 +2662,8 @@ class SelectionViewModel {
2615
2662
  class SelectionsComponent {
2616
2663
  constructor(_builder) {
2617
2664
  this._builder = _builder;
2618
- this.selectionViewModels = [];
2619
2665
  this.selectionClick = new EventEmitter();
2666
+ this.selectionViewModels = [];
2620
2667
  }
2621
2668
  set selections(value) {
2622
2669
  this._prepareSelections(value);