@shapediver/viewer.data-engine.material-engine 3.8.15 → 3.9.1
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/README.md +1 -1
- package/dist/MaterialEngine.d.ts +9 -9
- package/dist/MaterialEngine.d.ts.map +1 -1
- package/dist/MaterialEngine.js +413 -236
- package/dist/MaterialEngine.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/materialDatabase.d.ts.map +1 -1
- package/dist/materialDatabase.js +130 -128
- package/dist/materialDatabase.js.map +1 -1
- package/package.json +48 -48
package/dist/MaterialEngine.js
CHANGED
|
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MaterialEngine = void 0;
|
|
13
|
-
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
14
13
|
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
15
|
-
const
|
|
14
|
+
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
16
15
|
const gl_matrix_1 = require("gl-matrix");
|
|
16
|
+
const materialDatabase_1 = require("./materialDatabase");
|
|
17
17
|
/* eslint-disable no-prototype-builtins */
|
|
18
18
|
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
19
19
|
class MaterialEngine {
|
|
@@ -46,6 +46,10 @@ class MaterialEngine {
|
|
|
46
46
|
return new viewer_shared_types_1.MaterialUnlitData(materialProperties);
|
|
47
47
|
case viewer_shared_types_1.MATERIAL_TYPE.GEM:
|
|
48
48
|
return new viewer_shared_types_1.MaterialGemData(materialProperties);
|
|
49
|
+
case viewer_shared_types_1.MATERIAL_TYPE.PHONG:
|
|
50
|
+
return new viewer_shared_types_1.MaterialPhongData(materialProperties);
|
|
51
|
+
case viewer_shared_types_1.MATERIAL_TYPE.LAMBERT:
|
|
52
|
+
return new viewer_shared_types_1.MaterialLambertData(materialProperties);
|
|
49
53
|
default:
|
|
50
54
|
return new viewer_shared_types_1.MaterialStandardData(materialProperties);
|
|
51
55
|
}
|
|
@@ -56,40 +60,44 @@ class MaterialEngine {
|
|
|
56
60
|
const promises = [];
|
|
57
61
|
const abstractProperties = {};
|
|
58
62
|
abstractProperties.alphaCutoff = definition.alphaCutoff;
|
|
59
|
-
promises.push(this.loadMapFromDefinition(definition.alphaMap).then(map => {
|
|
63
|
+
promises.push(this.loadMapFromDefinition(definition.alphaMap).then((map) => {
|
|
60
64
|
if (map)
|
|
61
65
|
abstractProperties.alphaMap = map;
|
|
62
66
|
return map;
|
|
63
67
|
}));
|
|
64
68
|
abstractProperties.alphaMode = definition.alphaMode;
|
|
65
|
-
promises.push(this.loadMapFromDefinition(definition.aoMap).then(map => {
|
|
69
|
+
promises.push(this.loadMapFromDefinition(definition.aoMap).then((map) => {
|
|
66
70
|
if (map)
|
|
67
71
|
abstractProperties.aoMap = map;
|
|
68
72
|
return map;
|
|
69
73
|
}));
|
|
70
74
|
abstractProperties.aoMapIntensity = definition.aoMapIntensity;
|
|
71
|
-
promises.push(this.loadMapFromDefinition(definition.bumpMap).then(map => {
|
|
75
|
+
promises.push(this.loadMapFromDefinition(definition.bumpMap).then((map) => {
|
|
72
76
|
if (map)
|
|
73
77
|
abstractProperties.bumpMap = map;
|
|
74
78
|
return map;
|
|
75
79
|
}));
|
|
76
80
|
abstractProperties.bumpScale = definition.bumpScale;
|
|
77
|
-
abstractProperties.color = definition.color
|
|
81
|
+
abstractProperties.color = definition.color
|
|
82
|
+
? definition.color
|
|
83
|
+
: undefined;
|
|
78
84
|
abstractProperties.depthTest = definition.depthTest;
|
|
79
85
|
abstractProperties.depthWrite = definition.depthWrite;
|
|
80
|
-
promises.push(this.loadMapFromDefinition(definition.emissiveMap).then(map => {
|
|
86
|
+
promises.push(this.loadMapFromDefinition(definition.emissiveMap).then((map) => {
|
|
81
87
|
if (map)
|
|
82
88
|
abstractProperties.emissiveMap = map;
|
|
83
89
|
return map;
|
|
84
90
|
}));
|
|
85
|
-
abstractProperties.emissiveness = definition.emissiveness
|
|
86
|
-
|
|
91
|
+
abstractProperties.emissiveness = definition.emissiveness
|
|
92
|
+
? definition.emissiveness
|
|
93
|
+
: undefined;
|
|
94
|
+
promises.push(this.loadMapFromDefinition(definition.map).then((map) => {
|
|
87
95
|
if (map)
|
|
88
96
|
abstractProperties.map = map;
|
|
89
97
|
return map;
|
|
90
98
|
}));
|
|
91
99
|
abstractProperties.name = definition.name;
|
|
92
|
-
promises.push(this.loadMapFromDefinition(definition.normalMap).then(map => {
|
|
100
|
+
promises.push(this.loadMapFromDefinition(definition.normalMap).then((map) => {
|
|
93
101
|
if (map)
|
|
94
102
|
abstractProperties.normalMap = map;
|
|
95
103
|
return map;
|
|
@@ -101,208 +109,265 @@ class MaterialEngine {
|
|
|
101
109
|
abstractProperties.transparent = definition.transparent;
|
|
102
110
|
abstractProperties.type = materialType;
|
|
103
111
|
switch (materialType) {
|
|
104
|
-
case viewer_shared_types_1.MATERIAL_TYPE.SPECULAR_GLOSSINESS:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return map;
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.specularMap).then(map => {
|
|
120
|
-
if (map)
|
|
121
|
-
specularGlossinessProperties.specularMap = map;
|
|
122
|
-
return map;
|
|
123
|
-
}));
|
|
124
|
-
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.glossinessMap).then(map => {
|
|
125
|
-
if (map)
|
|
126
|
-
specularGlossinessProperties.glossinessMap = map;
|
|
127
|
-
return map;
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
yield Promise.all(promises);
|
|
131
|
-
return new viewer_shared_types_1.MaterialSpecularGlossinessData(specularGlossinessProperties);
|
|
132
|
-
}
|
|
133
|
-
case viewer_shared_types_1.MATERIAL_TYPE.UNLIT:
|
|
134
|
-
{
|
|
135
|
-
const unlitProperties = abstractProperties;
|
|
136
|
-
const unlitDefinition = definition;
|
|
137
|
-
unlitProperties.envMap = unlitDefinition.envMap;
|
|
138
|
-
yield Promise.all(promises);
|
|
139
|
-
return new viewer_shared_types_1.MaterialUnlitData(unlitProperties);
|
|
140
|
-
}
|
|
141
|
-
case viewer_shared_types_1.MATERIAL_TYPE.GEM:
|
|
142
|
-
{
|
|
143
|
-
const gemProperties = abstractProperties;
|
|
144
|
-
const gemDefinition = definition;
|
|
145
|
-
gemProperties.brightness = gemDefinition.brightness;
|
|
146
|
-
gemProperties.center = gemDefinition.center;
|
|
147
|
-
gemProperties.colorTransferBegin = gemDefinition.colorTransferBegin;
|
|
148
|
-
gemProperties.colorTransferEnd = gemDefinition.colorTransferEnd;
|
|
149
|
-
gemProperties.contrast = gemDefinition.contrast;
|
|
150
|
-
gemProperties.dispersion = gemDefinition.dispersion;
|
|
151
|
-
gemProperties.envMap = gemDefinition.envMap;
|
|
152
|
-
gemProperties.gamma = gemDefinition.gamma;
|
|
153
|
-
promises.push(this.loadMapFromDefinition(gemDefinition.impurityMap).then(map => {
|
|
154
|
-
if (map)
|
|
155
|
-
gemProperties.impurityMap = map;
|
|
156
|
-
return map;
|
|
157
|
-
}));
|
|
158
|
-
gemProperties.impurityScale = gemDefinition.impurityScale;
|
|
159
|
-
gemProperties.radius = gemDefinition.radius;
|
|
160
|
-
gemProperties.refractionIndex = gemDefinition.refractionIndex;
|
|
161
|
-
promises.push(this.loadMapFromDefinition(gemDefinition.sphericalNormalMap).then(map => {
|
|
112
|
+
case viewer_shared_types_1.MATERIAL_TYPE.SPECULAR_GLOSSINESS: {
|
|
113
|
+
const specularGlossinessProperties = abstractProperties;
|
|
114
|
+
const specularGlossinessDefinition = definition;
|
|
115
|
+
specularGlossinessProperties.envMap =
|
|
116
|
+
specularGlossinessDefinition.envMap;
|
|
117
|
+
specularGlossinessProperties.glossiness =
|
|
118
|
+
specularGlossinessDefinition.glossiness;
|
|
119
|
+
specularGlossinessProperties.specular =
|
|
120
|
+
specularGlossinessDefinition.specular;
|
|
121
|
+
if (specularGlossinessDefinition.specularGlossinessMap) {
|
|
122
|
+
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.specularGlossinessMap).then((map) => {
|
|
162
123
|
if (map)
|
|
163
|
-
|
|
124
|
+
specularGlossinessProperties.specularGlossinessMap =
|
|
125
|
+
map;
|
|
164
126
|
return map;
|
|
165
127
|
}));
|
|
166
|
-
gemProperties.tracingDepth = gemDefinition.tracingDepth;
|
|
167
|
-
gemProperties.tracingOpacity = gemDefinition.tracingOpacity;
|
|
168
|
-
yield Promise.all(promises);
|
|
169
|
-
return new viewer_shared_types_1.MaterialGemData(gemProperties);
|
|
170
128
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const standardProperties = abstractProperties;
|
|
174
|
-
const standardDefinition = definition;
|
|
175
|
-
standardProperties.attenuationColor = standardDefinition.attenuationColor;
|
|
176
|
-
standardProperties.attenuationDistance = standardDefinition.attenuationDistance;
|
|
177
|
-
standardProperties.clearcoat = standardDefinition.clearcoat;
|
|
178
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatMap).then(map => {
|
|
179
|
-
if (map)
|
|
180
|
-
standardProperties.clearcoatMap = map;
|
|
181
|
-
return map;
|
|
182
|
-
}));
|
|
183
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatNormalMap).then(map => {
|
|
184
|
-
if (map)
|
|
185
|
-
standardProperties.clearcoatNormalMap = map;
|
|
186
|
-
return map;
|
|
187
|
-
}));
|
|
188
|
-
standardProperties.clearcoatRoughness = standardDefinition.clearcoatRoughness;
|
|
189
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatRoughnessMap).then(map => {
|
|
190
|
-
if (map)
|
|
191
|
-
standardProperties.clearcoatRoughnessMap = map;
|
|
192
|
-
return map;
|
|
193
|
-
}));
|
|
194
|
-
standardProperties.displacementBias = standardDefinition.displacementBias;
|
|
195
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.displacementMap).then(map => {
|
|
196
|
-
if (map)
|
|
197
|
-
standardProperties.displacementMap = map;
|
|
198
|
-
return map;
|
|
199
|
-
}));
|
|
200
|
-
standardProperties.displacementScale = standardDefinition.displacementScale;
|
|
201
|
-
standardProperties.envMap = standardDefinition.envMap;
|
|
202
|
-
standardProperties.ior = standardDefinition.ior;
|
|
203
|
-
standardProperties.metalness = standardDefinition.metalness;
|
|
204
|
-
if (standardDefinition.metalnessRoughnessMap) {
|
|
205
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.metalnessMap).then(map => {
|
|
206
|
-
if (map)
|
|
207
|
-
standardProperties.metalnessMap = map;
|
|
208
|
-
return map;
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.metalnessMap).then(map => {
|
|
213
|
-
if (map)
|
|
214
|
-
standardProperties.metalnessMap = map;
|
|
215
|
-
return map;
|
|
216
|
-
}));
|
|
217
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.roughnessMap).then(map => {
|
|
218
|
-
if (map)
|
|
219
|
-
standardProperties.roughnessMap = map;
|
|
220
|
-
return map;
|
|
221
|
-
}));
|
|
222
|
-
}
|
|
223
|
-
standardProperties.roughness = standardDefinition.roughness;
|
|
224
|
-
standardProperties.sheen = standardDefinition.sheen;
|
|
225
|
-
standardProperties.sheenColor = standardDefinition.sheenColor;
|
|
226
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.sheenColorMap).then(map => {
|
|
227
|
-
if (map)
|
|
228
|
-
standardProperties.sheenColorMap = map;
|
|
229
|
-
return map;
|
|
230
|
-
}));
|
|
231
|
-
standardProperties.sheenRoughness = standardDefinition.sheenRoughness;
|
|
232
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.sheenRoughnessMap).then(map => {
|
|
129
|
+
else {
|
|
130
|
+
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.specularMap).then((map) => {
|
|
233
131
|
if (map)
|
|
234
|
-
|
|
132
|
+
specularGlossinessProperties.specularMap = map;
|
|
235
133
|
return map;
|
|
236
134
|
}));
|
|
237
|
-
|
|
238
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.specularColorMap).then(map => {
|
|
135
|
+
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.glossinessMap).then((map) => {
|
|
239
136
|
if (map)
|
|
240
|
-
|
|
137
|
+
specularGlossinessProperties.glossinessMap =
|
|
138
|
+
map;
|
|
241
139
|
return map;
|
|
242
140
|
}));
|
|
243
|
-
|
|
244
|
-
|
|
141
|
+
}
|
|
142
|
+
yield Promise.all(promises);
|
|
143
|
+
return new viewer_shared_types_1.MaterialSpecularGlossinessData(specularGlossinessProperties);
|
|
144
|
+
}
|
|
145
|
+
case viewer_shared_types_1.MATERIAL_TYPE.UNLIT: {
|
|
146
|
+
const unlitProperties = abstractProperties;
|
|
147
|
+
const unlitDefinition = definition;
|
|
148
|
+
unlitProperties.envMap = unlitDefinition.envMap;
|
|
149
|
+
yield Promise.all(promises);
|
|
150
|
+
return new viewer_shared_types_1.MaterialUnlitData(unlitProperties);
|
|
151
|
+
}
|
|
152
|
+
case viewer_shared_types_1.MATERIAL_TYPE.PHONG: {
|
|
153
|
+
const phongProperties = abstractProperties;
|
|
154
|
+
const phongDefinition = definition;
|
|
155
|
+
phongProperties.displacementBias =
|
|
156
|
+
phongDefinition.displacementBias;
|
|
157
|
+
promises.push(this.loadMapFromDefinition(phongDefinition.displacementMap).then((map) => {
|
|
158
|
+
if (map)
|
|
159
|
+
phongProperties.displacementMap = map;
|
|
160
|
+
return map;
|
|
161
|
+
}));
|
|
162
|
+
phongProperties.displacementScale =
|
|
163
|
+
phongDefinition.displacementScale;
|
|
164
|
+
phongProperties.envMap = phongDefinition.envMap;
|
|
165
|
+
phongProperties.reflectivity = phongDefinition.reflectivity;
|
|
166
|
+
phongProperties.shininess = phongDefinition.shininess;
|
|
167
|
+
phongProperties.specular = phongDefinition.specular;
|
|
168
|
+
promises.push(this.loadMapFromDefinition(phongDefinition.specularMap).then((map) => {
|
|
169
|
+
if (map)
|
|
170
|
+
phongProperties.specularMap = map;
|
|
171
|
+
return map;
|
|
172
|
+
}));
|
|
173
|
+
yield Promise.all(promises);
|
|
174
|
+
return new viewer_shared_types_1.MaterialPhongData(phongProperties);
|
|
175
|
+
}
|
|
176
|
+
case viewer_shared_types_1.MATERIAL_TYPE.LAMBERT: {
|
|
177
|
+
const lambertProperties = abstractProperties;
|
|
178
|
+
const lambertDefinition = definition;
|
|
179
|
+
lambertProperties.displacementBias =
|
|
180
|
+
lambertDefinition.displacementBias;
|
|
181
|
+
promises.push(this.loadMapFromDefinition(lambertDefinition.displacementMap).then((map) => {
|
|
182
|
+
if (map)
|
|
183
|
+
lambertProperties.displacementMap = map;
|
|
184
|
+
return map;
|
|
185
|
+
}));
|
|
186
|
+
lambertProperties.displacementScale =
|
|
187
|
+
lambertDefinition.displacementScale;
|
|
188
|
+
lambertProperties.envMap = lambertDefinition.envMap;
|
|
189
|
+
lambertProperties.reflectivity = lambertDefinition.reflectivity;
|
|
190
|
+
promises.push(this.loadMapFromDefinition(lambertDefinition.specularMap).then((map) => {
|
|
191
|
+
if (map)
|
|
192
|
+
lambertProperties.specularMap = map;
|
|
193
|
+
return map;
|
|
194
|
+
}));
|
|
195
|
+
yield Promise.all(promises);
|
|
196
|
+
return new viewer_shared_types_1.MaterialLambertData(lambertProperties);
|
|
197
|
+
}
|
|
198
|
+
case viewer_shared_types_1.MATERIAL_TYPE.GEM: {
|
|
199
|
+
const gemProperties = abstractProperties;
|
|
200
|
+
const gemDefinition = definition;
|
|
201
|
+
gemProperties.brightness = gemDefinition.brightness;
|
|
202
|
+
gemProperties.center = gemDefinition.center;
|
|
203
|
+
gemProperties.colorTransferBegin =
|
|
204
|
+
gemDefinition.colorTransferBegin;
|
|
205
|
+
gemProperties.colorTransferEnd = gemDefinition.colorTransferEnd;
|
|
206
|
+
gemProperties.contrast = gemDefinition.contrast;
|
|
207
|
+
gemProperties.dispersion = gemDefinition.dispersion;
|
|
208
|
+
gemProperties.envMap = gemDefinition.envMap;
|
|
209
|
+
gemProperties.gamma = gemDefinition.gamma;
|
|
210
|
+
promises.push(this.loadMapFromDefinition(gemDefinition.impurityMap).then((map) => {
|
|
211
|
+
if (map)
|
|
212
|
+
gemProperties.impurityMap = map;
|
|
213
|
+
return map;
|
|
214
|
+
}));
|
|
215
|
+
gemProperties.impurityScale = gemDefinition.impurityScale;
|
|
216
|
+
gemProperties.radius = gemDefinition.radius;
|
|
217
|
+
gemProperties.refractionIndex = gemDefinition.refractionIndex;
|
|
218
|
+
promises.push(this.loadMapFromDefinition(gemDefinition.sphericalNormalMap).then((map) => {
|
|
219
|
+
if (map)
|
|
220
|
+
gemProperties.sphericalNormalMap = map;
|
|
221
|
+
return map;
|
|
222
|
+
}));
|
|
223
|
+
gemProperties.tracingDepth = gemDefinition.tracingDepth;
|
|
224
|
+
gemProperties.tracingOpacity = gemDefinition.tracingOpacity;
|
|
225
|
+
yield Promise.all(promises);
|
|
226
|
+
return new viewer_shared_types_1.MaterialGemData(gemProperties);
|
|
227
|
+
}
|
|
228
|
+
default: {
|
|
229
|
+
const standardProperties = abstractProperties;
|
|
230
|
+
const standardDefinition = definition;
|
|
231
|
+
standardProperties.attenuationColor =
|
|
232
|
+
standardDefinition.attenuationColor;
|
|
233
|
+
standardProperties.attenuationDistance =
|
|
234
|
+
standardDefinition.attenuationDistance;
|
|
235
|
+
standardProperties.clearcoat = standardDefinition.clearcoat;
|
|
236
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatMap).then((map) => {
|
|
237
|
+
if (map)
|
|
238
|
+
standardProperties.clearcoatMap = map;
|
|
239
|
+
return map;
|
|
240
|
+
}));
|
|
241
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatNormalMap).then((map) => {
|
|
242
|
+
if (map)
|
|
243
|
+
standardProperties.clearcoatNormalMap = map;
|
|
244
|
+
return map;
|
|
245
|
+
}));
|
|
246
|
+
standardProperties.clearcoatRoughness =
|
|
247
|
+
standardDefinition.clearcoatRoughness;
|
|
248
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatRoughnessMap).then((map) => {
|
|
249
|
+
if (map)
|
|
250
|
+
standardProperties.clearcoatRoughnessMap = map;
|
|
251
|
+
return map;
|
|
252
|
+
}));
|
|
253
|
+
standardProperties.displacementBias =
|
|
254
|
+
standardDefinition.displacementBias;
|
|
255
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.displacementMap).then((map) => {
|
|
256
|
+
if (map)
|
|
257
|
+
standardProperties.displacementMap = map;
|
|
258
|
+
return map;
|
|
259
|
+
}));
|
|
260
|
+
standardProperties.displacementScale =
|
|
261
|
+
standardDefinition.displacementScale;
|
|
262
|
+
standardProperties.envMap = standardDefinition.envMap;
|
|
263
|
+
standardProperties.ior = standardDefinition.ior;
|
|
264
|
+
standardProperties.metalness = standardDefinition.metalness;
|
|
265
|
+
if (standardDefinition.metalnessRoughnessMap) {
|
|
266
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.metalnessMap).then((map) => {
|
|
245
267
|
if (map)
|
|
246
|
-
standardProperties.
|
|
268
|
+
standardProperties.metalnessMap = map;
|
|
247
269
|
return map;
|
|
248
270
|
}));
|
|
249
|
-
|
|
250
|
-
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.metalnessMap).then((map) => {
|
|
251
274
|
if (map)
|
|
252
|
-
standardProperties.
|
|
275
|
+
standardProperties.metalnessMap = map;
|
|
253
276
|
return map;
|
|
254
277
|
}));
|
|
255
|
-
|
|
256
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.transmissionMap).then(map => {
|
|
278
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.roughnessMap).then((map) => {
|
|
257
279
|
if (map)
|
|
258
|
-
standardProperties.
|
|
280
|
+
standardProperties.roughnessMap = map;
|
|
259
281
|
return map;
|
|
260
282
|
}));
|
|
261
|
-
yield Promise.all(promises);
|
|
262
|
-
return new viewer_shared_types_1.MaterialStandardData(standardProperties);
|
|
263
283
|
}
|
|
284
|
+
standardProperties.roughness = standardDefinition.roughness;
|
|
285
|
+
standardProperties.sheen = standardDefinition.sheen;
|
|
286
|
+
standardProperties.sheenColor = standardDefinition.sheenColor;
|
|
287
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.sheenColorMap).then((map) => {
|
|
288
|
+
if (map)
|
|
289
|
+
standardProperties.sheenColorMap = map;
|
|
290
|
+
return map;
|
|
291
|
+
}));
|
|
292
|
+
standardProperties.sheenRoughness =
|
|
293
|
+
standardDefinition.sheenRoughness;
|
|
294
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.sheenRoughnessMap).then((map) => {
|
|
295
|
+
if (map)
|
|
296
|
+
standardProperties.sheenRoughnessMap = map;
|
|
297
|
+
return map;
|
|
298
|
+
}));
|
|
299
|
+
standardProperties.specularColor =
|
|
300
|
+
standardDefinition.specularColor;
|
|
301
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.specularColorMap).then((map) => {
|
|
302
|
+
if (map)
|
|
303
|
+
standardProperties.specularColorMap = map;
|
|
304
|
+
return map;
|
|
305
|
+
}));
|
|
306
|
+
standardProperties.specularIntensity =
|
|
307
|
+
standardDefinition.specularIntensity;
|
|
308
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.specularIntensityMap).then((map) => {
|
|
309
|
+
if (map)
|
|
310
|
+
standardProperties.specularIntensityMap = map;
|
|
311
|
+
return map;
|
|
312
|
+
}));
|
|
313
|
+
standardProperties.thickness = standardDefinition.thickness;
|
|
314
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.thicknessMap).then((map) => {
|
|
315
|
+
if (map)
|
|
316
|
+
standardProperties.thicknessMap = map;
|
|
317
|
+
return map;
|
|
318
|
+
}));
|
|
319
|
+
standardProperties.transmission =
|
|
320
|
+
standardDefinition.transmission;
|
|
321
|
+
promises.push(this.loadMapFromDefinition(standardDefinition.transmissionMap).then((map) => {
|
|
322
|
+
if (map)
|
|
323
|
+
standardProperties.transmissionMap = map;
|
|
324
|
+
return map;
|
|
325
|
+
}));
|
|
326
|
+
yield Promise.all(promises);
|
|
327
|
+
return new viewer_shared_types_1.MaterialStandardData(standardProperties);
|
|
328
|
+
}
|
|
264
329
|
}
|
|
265
330
|
});
|
|
266
331
|
}
|
|
267
332
|
/**
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
333
|
+
* Load the material content into a scene graph node.
|
|
334
|
+
*
|
|
335
|
+
* @param content the material content
|
|
336
|
+
* @returns the scene graph node
|
|
337
|
+
*/
|
|
273
338
|
loadContent(content) {
|
|
274
339
|
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
-
const node = new viewer_shared_node_tree_1.TreeNode(content.name ||
|
|
340
|
+
const node = new viewer_shared_node_tree_1.TreeNode(content.name || "material");
|
|
276
341
|
if (!content)
|
|
277
|
-
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError(
|
|
342
|
+
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError("MaterialEngine.loadContent: Invalid content was provided to material engine.");
|
|
278
343
|
let material = new viewer_shared_types_1.MaterialStandardData();
|
|
279
344
|
if (content.data) {
|
|
280
345
|
const data = content.data;
|
|
281
346
|
let presetData;
|
|
282
347
|
if (data.materialpreset)
|
|
283
348
|
presetData = this.loadPresetMaterialDefinition(data.materialpreset);
|
|
284
|
-
if (data.materialType && data.materialType !==
|
|
349
|
+
if (data.materialType && data.materialType !== "standard") {
|
|
285
350
|
// gem material https://shapediver.atlassian.net/browse/SS-2514
|
|
286
351
|
}
|
|
287
352
|
else {
|
|
288
353
|
if (data.version) {
|
|
289
|
-
if (data.version ===
|
|
354
|
+
if (data.version === "1.0") {
|
|
290
355
|
material = yield this.loadMaterialV3(this.loadMaterialDefinitionV1(data, presetData));
|
|
291
356
|
}
|
|
292
|
-
else if (data.version ===
|
|
357
|
+
else if (data.version === "2.0") {
|
|
293
358
|
material = yield this.loadMaterialV3(this.loadMaterialDefinitionV2(data, presetData));
|
|
294
359
|
}
|
|
295
|
-
else if (data.version ===
|
|
360
|
+
else if (data.version === "3.0") {
|
|
296
361
|
material = yield this.loadMaterialV3(this.loadMaterialDefinitionV3(data, presetData));
|
|
297
362
|
}
|
|
298
363
|
else {
|
|
299
|
-
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError(
|
|
364
|
+
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError("MaterialEngine.loadContent: Material data version not supported.");
|
|
300
365
|
}
|
|
301
366
|
}
|
|
302
367
|
}
|
|
303
368
|
}
|
|
304
369
|
else {
|
|
305
|
-
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError(
|
|
370
|
+
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError("MaterialEngine.loadContent: No material data was provided to material engine.");
|
|
306
371
|
}
|
|
307
372
|
node.data.push(material);
|
|
308
373
|
return node;
|
|
@@ -315,16 +380,21 @@ class MaterialEngine {
|
|
|
315
380
|
response = yield this._httpClient.loadTexture(url);
|
|
316
381
|
}
|
|
317
382
|
else {
|
|
318
|
-
response = yield this._httpClient.loadTexture(
|
|
383
|
+
response = yield this._httpClient.loadTexture("https://viewer.shapediver.com/v2/materials/1024/" +
|
|
384
|
+
id +
|
|
385
|
+
"/" +
|
|
386
|
+
url);
|
|
319
387
|
}
|
|
320
388
|
if (!response)
|
|
321
389
|
return;
|
|
322
|
-
if (typeof window !==
|
|
390
|
+
if (typeof window !== "undefined") {
|
|
323
391
|
const image = yield viewer_shared_services_1.Converter.instance.responseToImage(response);
|
|
324
392
|
return new viewer_shared_types_1.MapData(image, { blob: response.data.blob });
|
|
325
393
|
}
|
|
326
394
|
else {
|
|
327
|
-
return new viewer_shared_types_1.MapData(response.data.buffer, {
|
|
395
|
+
return new viewer_shared_types_1.MapData(response.data.buffer, {
|
|
396
|
+
blob: response.data.blob,
|
|
397
|
+
});
|
|
328
398
|
}
|
|
329
399
|
});
|
|
330
400
|
}
|
|
@@ -338,20 +408,22 @@ class MaterialEngine {
|
|
|
338
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
339
409
|
if (!definition)
|
|
340
410
|
return undefined;
|
|
341
|
-
if (typeof definition ===
|
|
411
|
+
if (typeof definition === "string") {
|
|
342
412
|
return this.loadMap(definition);
|
|
343
413
|
}
|
|
344
414
|
else if (definition.image) {
|
|
345
|
-
if (typeof definition.image ===
|
|
415
|
+
if (typeof definition.image === "string") {
|
|
346
416
|
return this.loadMapWithProperties({
|
|
347
417
|
href: definition.image,
|
|
348
418
|
wrapS: definition.wrapS,
|
|
349
419
|
wrapT: definition.wrapT,
|
|
350
420
|
center: definition.center,
|
|
351
|
-
color: definition.color
|
|
421
|
+
color: definition.color
|
|
422
|
+
? this._converter.toColorArray(definition.color)
|
|
423
|
+
: undefined,
|
|
352
424
|
offset: definition.offset,
|
|
353
425
|
repeat: definition.repeat,
|
|
354
|
-
rotation: definition.rotation
|
|
426
|
+
rotation: definition.rotation,
|
|
355
427
|
});
|
|
356
428
|
}
|
|
357
429
|
else {
|
|
@@ -366,18 +438,56 @@ class MaterialEngine {
|
|
|
366
438
|
const response = yield this._httpClient.loadTexture(texture.href);
|
|
367
439
|
if (!response)
|
|
368
440
|
return;
|
|
369
|
-
const wrapS = texture.wrapS === 1
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
|
|
441
|
+
const wrapS = texture.wrapS === 1
|
|
442
|
+
? viewer_shared_types_1.TEXTURE_WRAPPING.CLAMP_TO_EDGE
|
|
443
|
+
: texture.wrapS === 2
|
|
444
|
+
? viewer_shared_types_1.TEXTURE_WRAPPING.MIRRORED_REPEAT
|
|
445
|
+
: viewer_shared_types_1.TEXTURE_WRAPPING.REPEAT;
|
|
446
|
+
const wrapT = texture.wrapT === 1
|
|
447
|
+
? viewer_shared_types_1.TEXTURE_WRAPPING.CLAMP_TO_EDGE
|
|
448
|
+
: texture.wrapT === 2
|
|
449
|
+
? viewer_shared_types_1.TEXTURE_WRAPPING.MIRRORED_REPEAT
|
|
450
|
+
: viewer_shared_types_1.TEXTURE_WRAPPING.REPEAT;
|
|
451
|
+
const center = texture.center
|
|
452
|
+
? gl_matrix_1.vec2.fromValues(texture.center[0], texture.center[1])
|
|
453
|
+
: gl_matrix_1.vec2.fromValues(0, 0);
|
|
454
|
+
const color = texture.color
|
|
455
|
+
? gl_matrix_1.vec4.fromValues(texture.color[0] / 255, texture.color[1] / 255, texture.color[2] / 255, texture.color[3] / 255)
|
|
456
|
+
: gl_matrix_1.vec4.fromValues(1, 1, 1, 1);
|
|
457
|
+
const offset = texture.offset
|
|
458
|
+
? gl_matrix_1.vec2.fromValues(texture.offset[0], texture.offset[1])
|
|
459
|
+
: gl_matrix_1.vec2.fromValues(0, 0);
|
|
460
|
+
const repeat = texture.repeat
|
|
461
|
+
? gl_matrix_1.vec2.fromValues(texture.repeat[0], texture.repeat[1])
|
|
462
|
+
: gl_matrix_1.vec2.fromValues(1, 1);
|
|
463
|
+
if (typeof window !== "undefined") {
|
|
376
464
|
const image = yield viewer_shared_services_1.Converter.instance.responseToImage(response);
|
|
377
|
-
return new viewer_shared_types_1.MapData(image, {
|
|
465
|
+
return new viewer_shared_types_1.MapData(image, {
|
|
466
|
+
blob: response.data.blob,
|
|
467
|
+
wrapS,
|
|
468
|
+
wrapT,
|
|
469
|
+
minFilter: viewer_shared_types_1.TEXTURE_FILTERING.LINEAR_MIPMAP_LINEAR,
|
|
470
|
+
magFilter: viewer_shared_types_1.TEXTURE_FILTERING.LINEAR,
|
|
471
|
+
center,
|
|
472
|
+
color,
|
|
473
|
+
offset,
|
|
474
|
+
repeat,
|
|
475
|
+
rotation: texture.rotation || 0,
|
|
476
|
+
});
|
|
378
477
|
}
|
|
379
478
|
else {
|
|
380
|
-
return new viewer_shared_types_1.MapData(response.data.buffer, {
|
|
479
|
+
return new viewer_shared_types_1.MapData(response.data.buffer, {
|
|
480
|
+
blob: response.data.blob,
|
|
481
|
+
wrapS,
|
|
482
|
+
wrapT,
|
|
483
|
+
minFilter: viewer_shared_types_1.TEXTURE_FILTERING.LINEAR_MIPMAP_LINEAR,
|
|
484
|
+
magFilter: viewer_shared_types_1.TEXTURE_FILTERING.LINEAR,
|
|
485
|
+
center,
|
|
486
|
+
color,
|
|
487
|
+
offset,
|
|
488
|
+
repeat,
|
|
489
|
+
rotation: texture.rotation || 0,
|
|
490
|
+
});
|
|
381
491
|
}
|
|
382
492
|
});
|
|
383
493
|
}
|
|
@@ -394,21 +504,21 @@ class MaterialEngine {
|
|
|
394
504
|
// specular is ignored
|
|
395
505
|
if (data.shine || data.shine === 0) {
|
|
396
506
|
presetData.metalness = Math.min(1, data.shine);
|
|
397
|
-
presetData.roughness = 1 -
|
|
507
|
+
presetData.roughness = 1 - Math.min(1, data.shine);
|
|
398
508
|
}
|
|
399
|
-
if (data.hasOwnProperty(
|
|
509
|
+
if (data.hasOwnProperty("transparency"))
|
|
400
510
|
presetData.transparency = data.transparency;
|
|
401
511
|
if (data.bitmaptexture)
|
|
402
512
|
presetData.bitmaptexture = {
|
|
403
|
-
href: data.bitmaptexture
|
|
513
|
+
href: data.bitmaptexture,
|
|
404
514
|
};
|
|
405
515
|
if (data.bumptexture)
|
|
406
516
|
presetData.bumptexture = {
|
|
407
|
-
href: data.bumptexture
|
|
517
|
+
href: data.bumptexture,
|
|
408
518
|
};
|
|
409
519
|
if (data.transparencytexture)
|
|
410
520
|
presetData.transparencytexture = {
|
|
411
|
-
href: data.transparencytexture
|
|
521
|
+
href: data.transparencytexture,
|
|
412
522
|
};
|
|
413
523
|
return presetData;
|
|
414
524
|
}
|
|
@@ -421,33 +531,33 @@ class MaterialEngine {
|
|
|
421
531
|
presetData.metalness = data.metalness;
|
|
422
532
|
if (data.roughness || data.roughness === 0)
|
|
423
533
|
presetData.roughness = data.roughness;
|
|
424
|
-
if (data.hasOwnProperty(
|
|
534
|
+
if (data.hasOwnProperty("transparency"))
|
|
425
535
|
presetData.transparency = data.transparency;
|
|
426
536
|
if (data.alphaThreshold || data.alphaThreshold === 0)
|
|
427
537
|
presetData.alphaThreshold = data.alphaThreshold;
|
|
428
538
|
if (data.bitmaptexture)
|
|
429
539
|
presetData.bitmaptexture = {
|
|
430
|
-
href: data.bitmaptexture
|
|
540
|
+
href: data.bitmaptexture,
|
|
431
541
|
};
|
|
432
542
|
if (data.metalnesstexture)
|
|
433
543
|
presetData.metalnesstexture = {
|
|
434
|
-
href: data.metalnesstexture
|
|
544
|
+
href: data.metalnesstexture,
|
|
435
545
|
};
|
|
436
546
|
if (data.roughnesstexture)
|
|
437
547
|
presetData.roughnesstexture = {
|
|
438
|
-
href: data.roughnesstexture
|
|
548
|
+
href: data.roughnesstexture,
|
|
439
549
|
};
|
|
440
550
|
if (data.bumptexture)
|
|
441
551
|
presetData.bumptexture = {
|
|
442
|
-
href: data.bumptexture
|
|
552
|
+
href: data.bumptexture,
|
|
443
553
|
};
|
|
444
554
|
if (data.normaltexture)
|
|
445
555
|
presetData.normaltexture = {
|
|
446
|
-
href: data.normaltexture
|
|
556
|
+
href: data.normaltexture,
|
|
447
557
|
};
|
|
448
558
|
if (data.transparencytexture)
|
|
449
559
|
presetData.transparencytexture = {
|
|
450
|
-
href: data.transparencytexture
|
|
560
|
+
href: data.transparencytexture,
|
|
451
561
|
};
|
|
452
562
|
return presetData;
|
|
453
563
|
}
|
|
@@ -460,7 +570,7 @@ class MaterialEngine {
|
|
|
460
570
|
presetData.metalness = data.metalness;
|
|
461
571
|
if (data.roughness || data.roughness === 0)
|
|
462
572
|
presetData.roughness = data.roughness;
|
|
463
|
-
if (data.hasOwnProperty(
|
|
573
|
+
if (data.hasOwnProperty("transparency"))
|
|
464
574
|
presetData.transparency = data.transparency;
|
|
465
575
|
if (data.alphaThreshold || data.alphaThreshold === 0)
|
|
466
576
|
presetData.alphaThreshold = data.alphaThreshold;
|
|
@@ -488,54 +598,59 @@ class MaterialEngine {
|
|
|
488
598
|
// ambient is ignored
|
|
489
599
|
if (data.color)
|
|
490
600
|
material.color = data.color;
|
|
491
|
-
material.side =
|
|
601
|
+
material.side =
|
|
602
|
+
data.side === "front"
|
|
603
|
+
? viewer_shared_types_1.MATERIAL_SIDE.FRONT
|
|
604
|
+
: data.side === "back"
|
|
605
|
+
? viewer_shared_types_1.MATERIAL_SIDE.BACK
|
|
606
|
+
: viewer_shared_types_1.MATERIAL_SIDE.DOUBLE;
|
|
492
607
|
if (data.metalness || data.metalness === 0)
|
|
493
608
|
material.metalness = data.metalness;
|
|
494
609
|
if (data.roughness || data.roughness === 0)
|
|
495
610
|
material.roughness = data.roughness;
|
|
496
|
-
if (data.hasOwnProperty(
|
|
611
|
+
if (data.hasOwnProperty("transparency"))
|
|
497
612
|
material.opacity = 1 - data.transparency;
|
|
498
613
|
if (data.alphaThreshold || data.alphaThreshold === 0)
|
|
499
614
|
material.alphaCutoff = data.alphaThreshold;
|
|
500
615
|
if (data.bumpAmplitude || data.bumpAmplitude === 0)
|
|
501
616
|
material.bumpScale = data.bumpAmplitude;
|
|
502
617
|
if (data.bitmaptexture) {
|
|
503
|
-
promises.push(this.loadMapWithProperties(data.bitmaptexture).then(map => {
|
|
618
|
+
promises.push(this.loadMapWithProperties(data.bitmaptexture).then((map) => {
|
|
504
619
|
if (map)
|
|
505
620
|
material.map = map;
|
|
506
621
|
return map;
|
|
507
622
|
}));
|
|
508
623
|
}
|
|
509
624
|
if (data.metalnesstexture) {
|
|
510
|
-
promises.push(this.loadMapWithProperties(data.metalnesstexture).then(map => {
|
|
625
|
+
promises.push(this.loadMapWithProperties(data.metalnesstexture).then((map) => {
|
|
511
626
|
if (map)
|
|
512
627
|
material.metalnessMap = map;
|
|
513
628
|
return map;
|
|
514
629
|
}));
|
|
515
630
|
}
|
|
516
631
|
if (data.roughnesstexture) {
|
|
517
|
-
promises.push(this.loadMapWithProperties(data.roughnesstexture).then(map => {
|
|
632
|
+
promises.push(this.loadMapWithProperties(data.roughnesstexture).then((map) => {
|
|
518
633
|
if (map)
|
|
519
634
|
material.roughnessMap = map;
|
|
520
635
|
return map;
|
|
521
636
|
}));
|
|
522
637
|
}
|
|
523
638
|
if (data.bumptexture) {
|
|
524
|
-
promises.push(this.loadMapWithProperties(data.bumptexture).then(map => {
|
|
639
|
+
promises.push(this.loadMapWithProperties(data.bumptexture).then((map) => {
|
|
525
640
|
if (map)
|
|
526
641
|
material.bumpMap = map;
|
|
527
642
|
return map;
|
|
528
643
|
}));
|
|
529
644
|
}
|
|
530
645
|
if (data.normaltexture) {
|
|
531
|
-
promises.push(this.loadMapWithProperties(data.normaltexture).then(map => {
|
|
646
|
+
promises.push(this.loadMapWithProperties(data.normaltexture).then((map) => {
|
|
532
647
|
if (map)
|
|
533
648
|
material.normalMap = map;
|
|
534
649
|
return map;
|
|
535
650
|
}));
|
|
536
651
|
}
|
|
537
652
|
if (data.transparencytexture) {
|
|
538
|
-
promises.push(this.loadMapWithProperties(data.transparencytexture).then(map => {
|
|
653
|
+
promises.push(this.loadMapWithProperties(data.transparencytexture).then((map) => {
|
|
539
654
|
if (map)
|
|
540
655
|
material.alphaMap = map;
|
|
541
656
|
return map;
|
|
@@ -554,58 +669,88 @@ class MaterialEngine {
|
|
|
554
669
|
loadPresetMaterialDefinition(preset) {
|
|
555
670
|
const definition = {};
|
|
556
671
|
const idStrings = this.getClassAndSpecificId(preset);
|
|
557
|
-
if (materialDatabase_1.materialDatabase[idStrings.class] &&
|
|
672
|
+
if (materialDatabase_1.materialDatabase[idStrings.class] &&
|
|
673
|
+
materialDatabase_1.materialDatabase[idStrings.class][idStrings.specific]) {
|
|
558
674
|
this.assignSpecificDefinition(idStrings, materialDatabase_1.materialDatabase[idStrings.class][idStrings.specific], definition);
|
|
559
675
|
this.assignGeneralDefinition(idStrings, materialDatabase_1.materialDatabase[idStrings.class].properties, materialDatabase_1.materialDatabase[idStrings.class][idStrings.specific], definition);
|
|
560
676
|
}
|
|
561
|
-
else if (materialDatabase_1.materialDatabase[idStrings.class] &&
|
|
562
|
-
|
|
563
|
-
this.
|
|
677
|
+
else if (materialDatabase_1.materialDatabase[idStrings.class] &&
|
|
678
|
+
materialDatabase_1.materialDatabase[idStrings.class]["00"]) {
|
|
679
|
+
this.assignSpecificDefinition({ class: idStrings.class, specific: "00" }, materialDatabase_1.materialDatabase[idStrings.class]["00"], definition);
|
|
680
|
+
this.assignGeneralDefinition({ class: idStrings.class, specific: "00" }, materialDatabase_1.materialDatabase[idStrings.class].properties, materialDatabase_1.materialDatabase[idStrings.class]["00"], definition);
|
|
564
681
|
}
|
|
565
682
|
else {
|
|
566
|
-
this.assignSpecificDefinition({ class:
|
|
567
|
-
this.assignGeneralDefinition({ class:
|
|
683
|
+
this.assignSpecificDefinition({ class: "00", specific: "00" }, materialDatabase_1.materialDatabase["00"]["00"], definition);
|
|
684
|
+
this.assignGeneralDefinition({ class: "00", specific: "00" }, materialDatabase_1.materialDatabase["00"].properties, materialDatabase_1.materialDatabase["00"]["00"], definition);
|
|
568
685
|
}
|
|
569
686
|
return definition;
|
|
570
687
|
}
|
|
571
688
|
// #endregion Public Methods (12)
|
|
572
689
|
// #region Private Methods (4)
|
|
573
690
|
assignGeneralDefinition(id, generalDefinition, specificDefinition, definition) {
|
|
574
|
-
if (generalDefinition.transparencytexture &&
|
|
691
|
+
if (generalDefinition.transparencytexture &&
|
|
692
|
+
!specificDefinition.transparencytexture)
|
|
575
693
|
definition.transparencytexture = {
|
|
576
|
-
href:
|
|
694
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
695
|
+
id.class +
|
|
696
|
+
"/" +
|
|
697
|
+
generalDefinition.transparencytexture,
|
|
577
698
|
};
|
|
578
|
-
if (generalDefinition.hasOwnProperty(
|
|
699
|
+
if (generalDefinition.hasOwnProperty("alphaThreshold") &&
|
|
700
|
+
!specificDefinition.hasOwnProperty("alphaThreshold"))
|
|
579
701
|
definition.alphaThreshold = generalDefinition.alphaThreshold;
|
|
580
702
|
if (generalDefinition.bumptexture && !specificDefinition.bumptexture)
|
|
581
703
|
definition.bumptexture = {
|
|
582
|
-
href:
|
|
704
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
705
|
+
id.class +
|
|
706
|
+
"/" +
|
|
707
|
+
generalDefinition.bumptexture,
|
|
583
708
|
};
|
|
584
|
-
if (generalDefinition.hasOwnProperty(
|
|
709
|
+
if (generalDefinition.hasOwnProperty("bumpAmplitude") &&
|
|
710
|
+
!specificDefinition.hasOwnProperty("bumpAmplitude"))
|
|
585
711
|
definition.bumpAmplitude = generalDefinition.bumpAmplitude;
|
|
586
712
|
if (generalDefinition.color && !specificDefinition.color)
|
|
587
713
|
definition.color = generalDefinition.color;
|
|
588
|
-
if (generalDefinition.bitmaptexture &&
|
|
714
|
+
if (generalDefinition.bitmaptexture &&
|
|
715
|
+
!specificDefinition.bitmaptexture)
|
|
589
716
|
definition.bitmaptexture = {
|
|
590
|
-
href:
|
|
717
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
718
|
+
id.class +
|
|
719
|
+
"/" +
|
|
720
|
+
generalDefinition.bitmaptexture,
|
|
591
721
|
};
|
|
592
|
-
if (generalDefinition.hasOwnProperty(
|
|
722
|
+
if (generalDefinition.hasOwnProperty("metalness") &&
|
|
723
|
+
!specificDefinition.hasOwnProperty("metalness"))
|
|
593
724
|
definition.metalness = generalDefinition.metalness;
|
|
594
|
-
if (generalDefinition.metalnesstexture &&
|
|
725
|
+
if (generalDefinition.metalnesstexture &&
|
|
726
|
+
!specificDefinition.metalnesstexture)
|
|
595
727
|
definition.metalnesstexture = {
|
|
596
|
-
href:
|
|
728
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
729
|
+
id.class +
|
|
730
|
+
"/" +
|
|
731
|
+
generalDefinition.metalnesstexture,
|
|
597
732
|
};
|
|
598
|
-
if (generalDefinition.normaltexture &&
|
|
733
|
+
if (generalDefinition.normaltexture &&
|
|
734
|
+
!specificDefinition.normaltexture)
|
|
599
735
|
definition.normaltexture = {
|
|
600
|
-
href:
|
|
736
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
737
|
+
id.class +
|
|
738
|
+
"/" +
|
|
739
|
+
generalDefinition.normaltexture,
|
|
601
740
|
};
|
|
602
|
-
if (generalDefinition.hasOwnProperty(
|
|
741
|
+
if (generalDefinition.hasOwnProperty("transparency") &&
|
|
742
|
+
!specificDefinition.hasOwnProperty("transparency"))
|
|
603
743
|
definition.transparency = generalDefinition.transparency;
|
|
604
|
-
if (generalDefinition.hasOwnProperty(
|
|
744
|
+
if (generalDefinition.hasOwnProperty("roughness") &&
|
|
745
|
+
!specificDefinition.hasOwnProperty("roughness"))
|
|
605
746
|
definition.roughness = generalDefinition.roughness;
|
|
606
|
-
if (generalDefinition.roughnesstexture &&
|
|
747
|
+
if (generalDefinition.roughnesstexture &&
|
|
748
|
+
!specificDefinition.roughnesstexture)
|
|
607
749
|
definition.roughnesstexture = {
|
|
608
|
-
href:
|
|
750
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
751
|
+
id.class +
|
|
752
|
+
"/" +
|
|
753
|
+
generalDefinition.roughnesstexture,
|
|
609
754
|
};
|
|
610
755
|
if (generalDefinition.side && !specificDefinition.side)
|
|
611
756
|
definition.side = generalDefinition.side;
|
|
@@ -613,39 +758,69 @@ class MaterialEngine {
|
|
|
613
758
|
assignSpecificDefinition(id, specificDefinition, definition) {
|
|
614
759
|
if (specificDefinition.transparencytexture)
|
|
615
760
|
definition.transparencytexture = {
|
|
616
|
-
href:
|
|
761
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
762
|
+
id.class +
|
|
763
|
+
"/" +
|
|
764
|
+
id.specific +
|
|
765
|
+
"/" +
|
|
766
|
+
specificDefinition.transparencytexture,
|
|
617
767
|
};
|
|
618
|
-
if (specificDefinition.hasOwnProperty(
|
|
768
|
+
if (specificDefinition.hasOwnProperty("alphaThreshold"))
|
|
619
769
|
definition.alphaThreshold = specificDefinition.alphaThreshold;
|
|
620
770
|
if (specificDefinition.bumptexture)
|
|
621
771
|
definition.bumptexture = {
|
|
622
|
-
href:
|
|
772
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
773
|
+
id.class +
|
|
774
|
+
"/" +
|
|
775
|
+
id.specific +
|
|
776
|
+
"/" +
|
|
777
|
+
specificDefinition.bumptexture,
|
|
623
778
|
};
|
|
624
|
-
if (specificDefinition.hasOwnProperty(
|
|
779
|
+
if (specificDefinition.hasOwnProperty("bumpAmplitude"))
|
|
625
780
|
definition.bumpAmplitude = specificDefinition.bumpAmplitude;
|
|
626
781
|
if (specificDefinition.color)
|
|
627
782
|
definition.color = specificDefinition.color;
|
|
628
783
|
if (specificDefinition.bitmaptexture)
|
|
629
784
|
definition.bitmaptexture = {
|
|
630
|
-
href:
|
|
785
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
786
|
+
id.class +
|
|
787
|
+
"/" +
|
|
788
|
+
id.specific +
|
|
789
|
+
"/" +
|
|
790
|
+
specificDefinition.bitmaptexture,
|
|
631
791
|
};
|
|
632
|
-
if (specificDefinition.hasOwnProperty(
|
|
792
|
+
if (specificDefinition.hasOwnProperty("metalness"))
|
|
633
793
|
definition.metalness = specificDefinition.metalness;
|
|
634
794
|
if (specificDefinition.metalnesstexture)
|
|
635
795
|
definition.metalnesstexture = {
|
|
636
|
-
href:
|
|
796
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
797
|
+
id.class +
|
|
798
|
+
"/" +
|
|
799
|
+
id.specific +
|
|
800
|
+
"/" +
|
|
801
|
+
specificDefinition.metalnesstexture,
|
|
637
802
|
};
|
|
638
803
|
if (specificDefinition.normaltexture)
|
|
639
804
|
definition.normaltexture = {
|
|
640
|
-
href:
|
|
805
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
806
|
+
id.class +
|
|
807
|
+
"/" +
|
|
808
|
+
id.specific +
|
|
809
|
+
"/" +
|
|
810
|
+
specificDefinition.normaltexture,
|
|
641
811
|
};
|
|
642
|
-
if (specificDefinition.hasOwnProperty(
|
|
812
|
+
if (specificDefinition.hasOwnProperty("transparency"))
|
|
643
813
|
definition.transparency = specificDefinition.transparency;
|
|
644
|
-
if (specificDefinition.hasOwnProperty(
|
|
814
|
+
if (specificDefinition.hasOwnProperty("roughness"))
|
|
645
815
|
definition.roughness = specificDefinition.roughness;
|
|
646
816
|
if (specificDefinition.roughnesstexture)
|
|
647
817
|
definition.roughnesstexture = {
|
|
648
|
-
href:
|
|
818
|
+
href: "https://viewer.shapediver.com/v2/materials/1024/" +
|
|
819
|
+
id.class +
|
|
820
|
+
"/" +
|
|
821
|
+
id.specific +
|
|
822
|
+
"/" +
|
|
823
|
+
specificDefinition.roughnesstexture,
|
|
649
824
|
};
|
|
650
825
|
if (specificDefinition.side)
|
|
651
826
|
definition.side = specificDefinition.side;
|
|
@@ -659,11 +834,11 @@ class MaterialEngine {
|
|
|
659
834
|
id *= 100;
|
|
660
835
|
const cast = (id) => {
|
|
661
836
|
const idString = String(id);
|
|
662
|
-
return idString.padStart(2,
|
|
837
|
+
return idString.padStart(2, "0").slice(0, 2);
|
|
663
838
|
};
|
|
664
839
|
return {
|
|
665
840
|
class: cast(Math.floor(id / 100)),
|
|
666
|
-
specific: cast(id -
|
|
841
|
+
specific: cast(id - Math.floor(id / 100) * 100),
|
|
667
842
|
};
|
|
668
843
|
}
|
|
669
844
|
/**
|
|
@@ -680,7 +855,9 @@ class MaterialEngine {
|
|
|
680
855
|
Math.min(255, (color1[0] * color2[0]) / 255),
|
|
681
856
|
Math.min(255, (color1[1] * color2[1]) / 255),
|
|
682
857
|
Math.min(255, (color1[2] * color2[2]) / 255),
|
|
683
|
-
Math.min(255, ((color1[3] !== undefined ? color1[3] : 255) *
|
|
858
|
+
Math.min(255, ((color1[3] !== undefined ? color1[3] : 255) *
|
|
859
|
+
(color2[3] !== undefined ? color2[3] : 255)) /
|
|
860
|
+
255),
|
|
684
861
|
];
|
|
685
862
|
}
|
|
686
863
|
}
|