@colijnit/configurator 12.0.7 → 12.0.8

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.
@@ -9,6 +9,7 @@ import axios from 'axios';
9
9
  import { DecoNodeKind } from '@colijnit/configuratorapi/build/enum/deco-node-kind.enum';
10
10
  import { Subject, BehaviorSubject } from 'rxjs';
11
11
  import JSZip from 'jszip';
12
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
12
13
  import { Article } from '@colijnit/configuratorapi/build/model/article';
13
14
  import { Configurator } from '@colijnit/configuratorapi/build/configurator';
14
15
  import { notNill } from '@colijnit/configuratorapi/build/utils/function/not-nill.function';
@@ -793,15 +794,21 @@ class VariationUtils {
793
794
  let index;
794
795
  variationSettings.id = id;
795
796
  if (zipContent) {
796
- if (zipContent.files['index.json']) {
797
- const indexFile = yield zipContent.files['index.json'].async('string');
798
- index = JSON.parse(indexFile);
799
- }
800
- if (index) {
801
- yield VariationUtils.CreateSettingsBasedOnIndex(index, variationSettings, zipContent);
797
+ if (zipContent.files['material.glb']) {
798
+ const material = yield zipContent.files['material.glb'].async('arraybuffer');
799
+ variationSettings.material = yield VariationUtils.LoadMaterialFromGlb(material);
802
800
  }
803
801
  else {
804
- yield VariationUtils.CreateSettingsBasedOnFileName(variationSettings, zipContent);
802
+ if (zipContent.files['index.json']) {
803
+ const indexFile = yield zipContent.files['index.json'].async('string');
804
+ index = JSON.parse(indexFile);
805
+ }
806
+ if (index) {
807
+ yield VariationUtils.CreateSettingsBasedOnIndex(index, variationSettings, zipContent);
808
+ }
809
+ else {
810
+ yield VariationUtils.CreateSettingsBasedOnFileName(variationSettings, zipContent);
811
+ }
805
812
  }
806
813
  }
807
814
  return variationSettings;
@@ -945,6 +952,25 @@ class VariationUtils {
945
952
  yield Promise.all(allLoaded);
946
953
  });
947
954
  }
955
+ static LoadMaterialFromJson(material) {
956
+ const loader = new THREE.MaterialLoader();
957
+ if (material.textures) {
958
+ const textures = {};
959
+ for (let i = 0; i < material.textures.length; i++) {
960
+ textures[material.textures[i].uuid] = material.textures[i];
961
+ }
962
+ loader.setTextures(textures);
963
+ }
964
+ return loader.parse(material);
965
+ }
966
+ static LoadMaterialFromGlb(material) {
967
+ return new Promise((resolve) => {
968
+ const loader = new GLTFLoader();
969
+ loader.parse(material, null, (object) => {
970
+ return resolve(object.scene.children[0].material);
971
+ });
972
+ });
973
+ }
948
974
  static LoadFileContentFromZip(zip, fileName, base64 = true) {
949
975
  return new Promise((resolve) => {
950
976
  if (zip && fileName) {
@@ -1088,7 +1114,7 @@ class VariationHelper {
1088
1114
  newVariation.gameObjectName = variations[j].gameObjectName;
1089
1115
  newVariation.supplierArticleNr = variations[j].supplierArticleNr;
1090
1116
  newVariation.materialId = variations[j].materialId;
1091
- newVariation.material = yield AssetUtils.CreateMaterialFromAsset(variationSettings);
1117
+ newVariation.material = variationSettings.material ? variationSettings.material : yield AssetUtils.CreateMaterialFromAsset(variationSettings);
1092
1118
  lastKnownVariations.push(newVariation);
1093
1119
  })));
1094
1120
  }
@@ -1120,7 +1146,7 @@ class VariationHelper {
1120
1146
  this._variations.push(variations);
1121
1147
  }
1122
1148
  }
1123
- preloadVariations(schema, fileNames) {
1149
+ preloadVariations(fileNames) {
1124
1150
  fileNames.forEach((fileName) => {
1125
1151
  if (fileName && !this.get(fileName)) {
1126
1152
  const settings = new VariationSettings();
@@ -1210,13 +1236,23 @@ class VariationHelper {
1210
1236
  if (Array.isArray(mesh.material)) { // multimaterial support
1211
1237
  for (let m = 0, mlen = mesh.material.length; m < mlen; m++) {
1212
1238
  if (mesh.material[m].name.toLowerCase().indexOf(materialToSearch) !== -1) {
1213
- mesh.material[m] = this._setMeshMaterialFromVariation(mesh.material[m].name, variation, usePbr);
1239
+ if (variation.material instanceof THREE.Material) {
1240
+ mesh.material[m] = variation.material;
1241
+ }
1242
+ else {
1243
+ mesh.material[m] = this._setMeshMaterialFromVariation(mesh.material[m].name, variation, usePbr);
1244
+ }
1214
1245
  }
1215
1246
  }
1216
1247
  }
1217
1248
  else {
1218
1249
  if (mesh.material.name.toLowerCase().indexOf(materialToSearch) !== -1) {
1219
- mesh.material = this._setMeshMaterialFromVariation(mesh.material.name, variation, usePbr);
1250
+ if (variation.material instanceof THREE.Material) {
1251
+ mesh.material = variation.material;
1252
+ }
1253
+ else {
1254
+ mesh.material = this._setMeshMaterialFromVariation(mesh.material.name, variation, usePbr);
1255
+ }
1220
1256
  }
1221
1257
  }
1222
1258
  }
@@ -1574,12 +1610,12 @@ class Builder {
1574
1610
  promises.push(this._getSelections(this._instanceId));
1575
1611
  promises.push(this._getDecos());
1576
1612
  yield Promise.all(promises);
1613
+ this._preloadMaterials();
1577
1614
  if (this._answers.length > 0) {
1578
1615
  return;
1579
1616
  }
1580
1617
  this._linkSelectionsAndDecos();
1581
1618
  const build = yield this._build();
1582
- this._cleanUp();
1583
1619
  return build;
1584
1620
  }
1585
1621
  else {
@@ -1603,7 +1639,7 @@ class Builder {
1603
1639
  this._selections = selections;
1604
1640
  this._decos = decos;
1605
1641
  this._linkSelectionsAndDecos();
1606
- this._preloadMaterials(schema);
1642
+ this._preloadMaterials();
1607
1643
  const build = yield this._build();
1608
1644
  this._cleanUp();
1609
1645
  this._log('finish build');
@@ -1627,8 +1663,9 @@ class Builder {
1627
1663
  }
1628
1664
  selectSelection(selection) {
1629
1665
  return __awaiter(this, void 0, void 0, function* () {
1630
- yield this._configuratorService.selectSelection(selection, false);
1631
- this.getQuestionAndAnswers();
1666
+ const questionsAndAnswers = yield this._configuratorService.selectSelection(selection, false);
1667
+ this._answers = questionsAndAnswers.answers;
1668
+ this.answersReceived.next(questionsAndAnswers.answers);
1632
1669
  });
1633
1670
  }
1634
1671
  getQuestionAndAnswers(publicationCode) {
@@ -1640,8 +1677,12 @@ class Builder {
1640
1677
  }
1641
1678
  selectAnswer(answer) {
1642
1679
  return __awaiter(this, void 0, void 0, function* () {
1643
- yield this._configuratorService.selectAnswer(answer, false);
1644
- this.modelLoaded.next(yield this.buildModel());
1680
+ const questionsAndAnswers = yield this._configuratorService.selectAnswer(answer, false);
1681
+ this._answers = questionsAndAnswers.answers;
1682
+ this.answersReceived.next(questionsAndAnswers.answers);
1683
+ if (questionsAndAnswers.answers.length === 0) {
1684
+ this._build();
1685
+ }
1645
1686
  });
1646
1687
  }
1647
1688
  getImageForSelectionOrAnswer(object) {
@@ -1691,8 +1732,8 @@ class Builder {
1691
1732
  return '';
1692
1733
  }
1693
1734
  }
1694
- _preloadMaterials(schema) {
1695
- this._variationHelper.preloadVariations(schema, this._decos.map(d => d.gameObjectName));
1735
+ _preloadMaterials() {
1736
+ this._variationHelper.preloadVariations([...new Set(this._decos.filter(d => d.gameObjectName !== undefined).map(d => d.gameObjectName))]);
1696
1737
  }
1697
1738
  _setInstanceId(sku, instanceId, goodId) {
1698
1739
  return __awaiter(this, void 0, void 0, function* () {
@@ -1776,7 +1817,9 @@ class Builder {
1776
1817
  this._log('remove from scene');
1777
1818
  this._scene.remove(obj);
1778
1819
  ObjectUtils.DisposeObject(this._source);
1820
+ // this._cleanUp();
1779
1821
  this._log('ready!');
1822
+ this.modelLoaded.next(obj);
1780
1823
  return obj;
1781
1824
  }
1782
1825
  else {