@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 +3 -0
- package/bundles/colijnit-configurator.umd.js +217 -96
- package/bundles/colijnit-configurator.umd.js.map +1 -1
- package/colijnit-configurator.metadata.json +1 -1
- package/esm2015/app/builder.js +24 -1
- package/esm2015/helper/variation-helper.js +76 -11
- package/esm2015/model/variation.js +1 -1
- package/esm2015/utils/variation-utils.js +29 -26
- package/fesm2015/colijnit-configurator.js +133 -43
- package/fesm2015/colijnit-configurator.js.map +1 -1
- package/helper/variation-helper.d.ts +7 -0
- package/model/variation.d.ts +1 -0
- package/package.json +2 -2
|
@@ -518,6 +518,14 @@ class SceneUtils {
|
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
|
|
521
|
+
class VariationSettings {
|
|
522
|
+
constructor() {
|
|
523
|
+
this.settings = {};
|
|
524
|
+
this.loading = false;
|
|
525
|
+
this.loaded = new Subject();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
521
529
|
class Material {
|
|
522
530
|
constructor() {
|
|
523
531
|
this.specular = new THREE.Color(0.3, 0.3, 0.3);
|
|
@@ -703,14 +711,6 @@ class AssetUtils {
|
|
|
703
711
|
class Variation {
|
|
704
712
|
}
|
|
705
713
|
|
|
706
|
-
class VariationSettings {
|
|
707
|
-
constructor() {
|
|
708
|
-
this.settings = {};
|
|
709
|
-
this.loading = false;
|
|
710
|
-
this.loaded = new Subject();
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
714
|
// @dynamic
|
|
715
715
|
class VariationUtils {
|
|
716
716
|
static ClearCache() {
|
|
@@ -718,35 +718,38 @@ class VariationUtils {
|
|
|
718
718
|
}
|
|
719
719
|
static LoadVariation(assetPath, fileName) {
|
|
720
720
|
return __awaiter(this, void 0, void 0, function* () {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
if (fileName.indexOf('ione3d') < 0) {
|
|
725
|
-
fileName = fileName.concat('.ione3d');
|
|
726
|
-
}
|
|
727
|
-
const id = fileName.substr(0, fileName.lastIndexOf('.ione3d'));
|
|
728
|
-
try {
|
|
729
|
-
if (!assetPath.endsWith('/')) {
|
|
730
|
-
assetPath += '/';
|
|
721
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
722
|
+
if (!fileName) {
|
|
723
|
+
resolve(null);
|
|
731
724
|
}
|
|
732
|
-
if (
|
|
733
|
-
|
|
734
|
-
return null;
|
|
725
|
+
if (fileName.indexOf('ione3d') < 0) {
|
|
726
|
+
fileName = fileName.concat('.ione3d');
|
|
735
727
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
728
|
+
const id = fileName.substr(0, fileName.lastIndexOf('.ione3d'));
|
|
729
|
+
try {
|
|
730
|
+
if (!assetPath.endsWith('/')) {
|
|
731
|
+
assetPath += '/';
|
|
732
|
+
}
|
|
733
|
+
if (!window.hasOwnProperty('downloadVariation')) {
|
|
734
|
+
console.error('downloadVariation not defined in window global');
|
|
735
|
+
reject('downloadVariation not defined in window global');
|
|
736
|
+
}
|
|
737
|
+
let file;
|
|
738
|
+
if (this.MaterialCache.has(id)) {
|
|
739
|
+
resolve(this.MaterialCache.get(id));
|
|
740
|
+
}
|
|
741
|
+
else {
|
|
742
|
+
file = yield window.downloadVariation(`${assetPath.replace('https://cdn1.colijn-it.nl/', '')}variation/${fileName}`);
|
|
743
|
+
const settings = yield VariationUtils.GetVariationSettingsFromFile(id, file);
|
|
744
|
+
this.MaterialCache.set(id, settings);
|
|
745
|
+
resolve(settings);
|
|
746
|
+
}
|
|
739
747
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
748
|
+
catch (err) {
|
|
749
|
+
const mute = err;
|
|
750
|
+
reject(err);
|
|
743
751
|
}
|
|
744
|
-
|
|
745
|
-
}
|
|
746
|
-
catch (err) {
|
|
747
|
-
const mute = err;
|
|
748
|
-
return null;
|
|
749
|
-
}
|
|
752
|
+
}));
|
|
750
753
|
});
|
|
751
754
|
}
|
|
752
755
|
// public static GetMaterialFromName(variationFolder: string, material: any): Promise<MeshStandardMaterial> {
|
|
@@ -1002,6 +1005,7 @@ VariationUtils.MaterialCache = new Map();
|
|
|
1002
1005
|
|
|
1003
1006
|
class VariationHelper {
|
|
1004
1007
|
constructor() {
|
|
1008
|
+
this._variations = [];
|
|
1005
1009
|
this._lastKnownVariations = new Map();
|
|
1006
1010
|
}
|
|
1007
1011
|
clearCache() {
|
|
@@ -1074,18 +1078,22 @@ class VariationHelper {
|
|
|
1074
1078
|
}
|
|
1075
1079
|
}
|
|
1076
1080
|
const lastKnownVariations = [];
|
|
1081
|
+
const variationPromise = [];
|
|
1077
1082
|
for (let j = 0; j < variations.length; j++) {
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1083
|
+
variationPromise.push(this.loadTheVariation(variations[j].gameObjectName || parts[i].decoId).then((variationSettings) => __awaiter(this, void 0, void 0, function* () {
|
|
1084
|
+
const newVariation = new Variation();
|
|
1085
|
+
newVariation.decoId = parseFloat(variations[j].id);
|
|
1086
|
+
newVariation.brandId = variations[j].brandId;
|
|
1087
|
+
newVariation.optionText = variations[j].optionText;
|
|
1088
|
+
newVariation.gameObjectName = variations[j].gameObjectName;
|
|
1089
|
+
newVariation.supplierArticleNr = variations[j].supplierArticleNr;
|
|
1090
|
+
newVariation.materialId = variations[j].materialId;
|
|
1091
|
+
newVariation.material = yield AssetUtils.CreateMaterialFromAsset(variationSettings);
|
|
1092
|
+
lastKnownVariations.push(newVariation);
|
|
1093
|
+
})));
|
|
1087
1094
|
}
|
|
1088
|
-
|
|
1095
|
+
yield Promise.all(variationPromise);
|
|
1096
|
+
this._setLastKnownVariations(`${parts[i].nodeId}_${parts[i].node}`, lastKnownVariations);
|
|
1089
1097
|
parts[i].variations = lastKnownVariations;
|
|
1090
1098
|
this._applyVariations(obj, parts[i], usePbr);
|
|
1091
1099
|
}
|
|
@@ -1095,6 +1103,65 @@ class VariationHelper {
|
|
|
1095
1103
|
}
|
|
1096
1104
|
});
|
|
1097
1105
|
}
|
|
1106
|
+
get(id) {
|
|
1107
|
+
const len = this._variations.length;
|
|
1108
|
+
for (let i = 0; i < len; i++) {
|
|
1109
|
+
if (this._variations[i].id && this._variations[i].id === id) {
|
|
1110
|
+
return this._variations[i];
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
set(variations) {
|
|
1115
|
+
const idx = this._variations.findIndex(v => v.id === variations.id);
|
|
1116
|
+
if (idx > -1) {
|
|
1117
|
+
this._variations[idx] = variations;
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
this._variations.push(variations);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
preloadVariations(schema, fileNames) {
|
|
1124
|
+
fileNames.forEach((fileName) => {
|
|
1125
|
+
if (fileName && !this.get(fileName)) {
|
|
1126
|
+
const settings = new VariationSettings();
|
|
1127
|
+
settings.id = fileName;
|
|
1128
|
+
settings.loading = true;
|
|
1129
|
+
this._variations.push(settings);
|
|
1130
|
+
let assetPath = this.assetPath;
|
|
1131
|
+
if (!assetPath.endsWith('/')) {
|
|
1132
|
+
assetPath += '/';
|
|
1133
|
+
}
|
|
1134
|
+
VariationUtils.LoadVariation(assetPath, fileName).then((variationSettings) => {
|
|
1135
|
+
settings.loading = false;
|
|
1136
|
+
settings.loaded.next(variationSettings);
|
|
1137
|
+
if (variationSettings) {
|
|
1138
|
+
this.set(variationSettings);
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
loadTheVariation(fileName) {
|
|
1145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1146
|
+
if (!fileName) {
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
if (this.get(fileName)) {
|
|
1150
|
+
const settings = this.get(fileName);
|
|
1151
|
+
if (settings.loading) {
|
|
1152
|
+
return yield this._waitForVariationToLoad(settings);
|
|
1153
|
+
}
|
|
1154
|
+
return settings;
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
_waitForVariationToLoad(settings) {
|
|
1159
|
+
return new Promise((resolve) => {
|
|
1160
|
+
settings.loaded.subscribe((value) => {
|
|
1161
|
+
resolve(value);
|
|
1162
|
+
});
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1098
1165
|
_getChildrenFilterByProp(obj, userDataObjectProp, prop, value) {
|
|
1099
1166
|
return obj.children.filter((child) => {
|
|
1100
1167
|
return child.userData &&
|
|
@@ -1530,13 +1597,16 @@ class Builder {
|
|
|
1530
1597
|
return;
|
|
1531
1598
|
}
|
|
1532
1599
|
try {
|
|
1600
|
+
this._log('start build');
|
|
1533
1601
|
yield this._downloadAsset(assetUrl, cdnUrl, schema);
|
|
1534
1602
|
if (selections && selections.length > 1 && decos && decos.length > 0 && this._source) {
|
|
1535
1603
|
this._selections = selections;
|
|
1536
1604
|
this._decos = decos;
|
|
1537
1605
|
this._linkSelectionsAndDecos();
|
|
1606
|
+
this._preloadMaterials(schema);
|
|
1538
1607
|
const build = yield this._build();
|
|
1539
1608
|
this._cleanUp();
|
|
1609
|
+
this._log('finish build');
|
|
1540
1610
|
return build;
|
|
1541
1611
|
}
|
|
1542
1612
|
else {
|
|
@@ -1621,6 +1691,9 @@ class Builder {
|
|
|
1621
1691
|
return '';
|
|
1622
1692
|
}
|
|
1623
1693
|
}
|
|
1694
|
+
_preloadMaterials(schema) {
|
|
1695
|
+
this._variationHelper.preloadVariations(schema, this._decos.map(d => d.gameObjectName));
|
|
1696
|
+
}
|
|
1624
1697
|
_setInstanceId(sku, instanceId, goodId) {
|
|
1625
1698
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1626
1699
|
if (!instanceId && !this._instanceId) {
|
|
@@ -1675,6 +1748,7 @@ class Builder {
|
|
|
1675
1748
|
obj.visible = false; // no need to render visualy
|
|
1676
1749
|
this._scene.add(obj);
|
|
1677
1750
|
let connected = false;
|
|
1751
|
+
this._log('build main model');
|
|
1678
1752
|
for (let i = 0, len = adjustables.length; i < len; i++) {
|
|
1679
1753
|
const adjustable = this._createAdjustable(obj, adjustables[i]);
|
|
1680
1754
|
if (adjustable) {
|
|
@@ -1692,12 +1766,17 @@ class Builder {
|
|
|
1692
1766
|
console.warn('No connection found for: ', adjustable.name);
|
|
1693
1767
|
}
|
|
1694
1768
|
}
|
|
1769
|
+
this._log('place addables');
|
|
1695
1770
|
this._placeAddables(obj);
|
|
1771
|
+
this._log('update pivot');
|
|
1696
1772
|
this._updatePivot(obj);
|
|
1773
|
+
this._log('load variations');
|
|
1697
1774
|
yield this._loadVariations(obj);
|
|
1698
1775
|
// this._variationHelper.clearCache();
|
|
1776
|
+
this._log('remove from scene');
|
|
1699
1777
|
this._scene.remove(obj);
|
|
1700
1778
|
ObjectUtils.DisposeObject(this._source);
|
|
1779
|
+
this._log('ready!');
|
|
1701
1780
|
return obj;
|
|
1702
1781
|
}
|
|
1703
1782
|
else {
|
|
@@ -1965,10 +2044,15 @@ class Builder {
|
|
|
1965
2044
|
}
|
|
1966
2045
|
_loadVariations(obj) {
|
|
1967
2046
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2047
|
+
this._log('load variation for parts');
|
|
1968
2048
|
yield this._variationHelper.loadPart(obj, this._adjustables, true);
|
|
2049
|
+
this._log('load variation for adjustables');
|
|
1969
2050
|
yield this._variationHelper.loadVariation(obj, this._adjustables, true);
|
|
2051
|
+
this._log('load variation for addables');
|
|
1970
2052
|
yield this._variationHelper.loadVariation(obj, this._addables, true);
|
|
2053
|
+
this._log('load variation clear cache');
|
|
1971
2054
|
this._variationHelper.clearCache();
|
|
2055
|
+
this._log('load variations done');
|
|
1972
2056
|
});
|
|
1973
2057
|
}
|
|
1974
2058
|
_getAdjustables() {
|
|
@@ -1994,6 +2078,12 @@ class Builder {
|
|
|
1994
2078
|
this._addables.length = 0;
|
|
1995
2079
|
this._prepareTheSelections();
|
|
1996
2080
|
}
|
|
2081
|
+
_log(message) {
|
|
2082
|
+
if (this.debug) {
|
|
2083
|
+
this.debug(message);
|
|
2084
|
+
console.log(new Date(), message);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
1997
2087
|
}
|
|
1998
2088
|
Builder.ɵprov = i0.ɵɵdefineInjectable({ factory: function Builder_Factory() { return new Builder(); }, token: Builder, providedIn: "root" });
|
|
1999
2089
|
Builder.decorators = [
|