@shapediver/viewer.data-engine.material-engine 3.3.3 → 3.3.6
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/package.json +8 -9
- package/src/MaterialEngine.ts +0 -785
- package/src/index.ts +0 -5
- package/src/materialDatabase.ts +0 -180
- package/tsconfig.json +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.data-engine.material-engine",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -10,11 +10,10 @@
|
|
|
10
10
|
"test": "__tests__"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"dist",
|
|
14
|
-
"src",
|
|
15
13
|
"package.json",
|
|
14
|
+
"dist/",
|
|
16
15
|
"README.md",
|
|
17
|
-
"
|
|
16
|
+
"LICENSE"
|
|
18
17
|
],
|
|
19
18
|
"publishConfig": {
|
|
20
19
|
"access": "public"
|
|
@@ -40,12 +39,12 @@
|
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"@shapediver/sdk.geometry-api-sdk-v2": "1.11.0",
|
|
43
|
-
"@shapediver/viewer.data-engine.shared-types": "3.3.
|
|
44
|
-
"@shapediver/viewer.shared.node-tree": "3.3.
|
|
45
|
-
"@shapediver/viewer.shared.services": "3.3.
|
|
46
|
-
"@shapediver/viewer.shared.types": "3.3.
|
|
42
|
+
"@shapediver/viewer.data-engine.shared-types": "3.3.6",
|
|
43
|
+
"@shapediver/viewer.shared.node-tree": "3.3.6",
|
|
44
|
+
"@shapediver/viewer.shared.services": "3.3.6",
|
|
45
|
+
"@shapediver/viewer.shared.types": "3.3.6",
|
|
47
46
|
"axios": "^1.2.6",
|
|
48
47
|
"gl-matrix": "3.3.0"
|
|
49
48
|
},
|
|
50
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "13aea937b128a001e6e93be300674c4a04624c29"
|
|
51
50
|
}
|
package/src/MaterialEngine.ts
DELETED
|
@@ -1,785 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Converter,
|
|
3
|
-
HttpClient,
|
|
4
|
-
Logger,
|
|
5
|
-
ShapeDiverViewerDataProcessingError
|
|
6
|
-
} from '@shapediver/viewer.shared.services';
|
|
7
|
-
import {
|
|
8
|
-
IMaterialContentData,
|
|
9
|
-
IMaterialContentDataV1,
|
|
10
|
-
IMaterialContentDataV2,
|
|
11
|
-
IMaterialContentDataV3,
|
|
12
|
-
IPresetMaterialDefinition,
|
|
13
|
-
ITexture
|
|
14
|
-
} from '@shapediver/viewer.data-engine.shared-types';
|
|
15
|
-
import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
16
|
-
import { materialDatabase } from './materialDatabase';
|
|
17
|
-
import { ShapeDiverResponseOutputContent } from '@shapediver/sdk.geometry-api-sdk-v2';
|
|
18
|
-
import { vec2, vec4 } from 'gl-matrix';
|
|
19
|
-
/* eslint-disable no-prototype-builtins */
|
|
20
|
-
import {
|
|
21
|
-
IMapDataPropertiesDefinition,
|
|
22
|
-
IMaterialAbstractData,
|
|
23
|
-
IMaterialAbstractDataProperties,
|
|
24
|
-
IMaterialAbstractDataPropertiesDefinition,
|
|
25
|
-
IMaterialGemDataProperties,
|
|
26
|
-
IMaterialGemDataPropertiesDefinition,
|
|
27
|
-
IMaterialSpecularGlossinessDataProperties,
|
|
28
|
-
IMaterialSpecularGlossinessDataPropertiesDefinition,
|
|
29
|
-
IMaterialStandardDataProperties,
|
|
30
|
-
IMaterialStandardDataPropertiesDefinition,
|
|
31
|
-
IMaterialUnlitDataProperties,
|
|
32
|
-
IMaterialUnlitDataPropertiesDefinition,
|
|
33
|
-
MapData,
|
|
34
|
-
MATERIAL_SIDE,
|
|
35
|
-
MATERIAL_TYPE,
|
|
36
|
-
MaterialGemData,
|
|
37
|
-
MaterialSpecularGlossinessData,
|
|
38
|
-
MaterialStandardData,
|
|
39
|
-
MaterialUnlitData,
|
|
40
|
-
TEXTURE_FILTERING,
|
|
41
|
-
TEXTURE_WRAPPING,
|
|
42
|
-
} from '@shapediver/viewer.shared.types';
|
|
43
|
-
|
|
44
|
-
export class MaterialEngine {
|
|
45
|
-
// #region Properties (4)
|
|
46
|
-
|
|
47
|
-
private readonly _converter: Converter = Converter.instance;
|
|
48
|
-
private readonly _httpClient: HttpClient = HttpClient.instance;
|
|
49
|
-
private readonly _logger: Logger = Logger.instance;
|
|
50
|
-
|
|
51
|
-
private static _instance: MaterialEngine;
|
|
52
|
-
|
|
53
|
-
// #endregion Properties (4)
|
|
54
|
-
|
|
55
|
-
// #region Public Static Getters And Setters (1)
|
|
56
|
-
|
|
57
|
-
public static get instance() {
|
|
58
|
-
return this._instance || (this._instance = new this());
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// #endregion Public Static Getters And Setters (1)
|
|
62
|
-
|
|
63
|
-
// #region Public Methods (12)
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Create a material data based on the material properties
|
|
67
|
-
*
|
|
68
|
-
* @param materialProperties
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
public createMaterialData(materialProperties: IMaterialAbstractDataProperties): IMaterialAbstractData {
|
|
72
|
-
const materialType = materialProperties.type || MATERIAL_TYPE.STANDARD;
|
|
73
|
-
switch (materialType) {
|
|
74
|
-
case MATERIAL_TYPE.SPECULAR_GLOSSINESS:
|
|
75
|
-
return new MaterialSpecularGlossinessData(materialProperties);
|
|
76
|
-
case MATERIAL_TYPE.UNLIT:
|
|
77
|
-
return new MaterialUnlitData(materialProperties);
|
|
78
|
-
case MATERIAL_TYPE.GEM:
|
|
79
|
-
return new MaterialGemData(materialProperties);
|
|
80
|
-
default:
|
|
81
|
-
return new MaterialStandardData(materialProperties);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public async createMaterialDataFromDefinition(definition: IMaterialAbstractDataPropertiesDefinition): Promise<IMaterialAbstractData> {
|
|
86
|
-
const materialType = definition.type || MATERIAL_TYPE.STANDARD;
|
|
87
|
-
|
|
88
|
-
const promises: Promise<MapData | undefined>[] = [];
|
|
89
|
-
|
|
90
|
-
const abstractProperties: IMaterialAbstractDataProperties = {};
|
|
91
|
-
|
|
92
|
-
abstractProperties.alphaCutoff = definition.alphaCutoff;
|
|
93
|
-
promises.push(this.loadMapFromDefinition(definition.alphaMap).then(map => {
|
|
94
|
-
if (map) abstractProperties.alphaMap = map;
|
|
95
|
-
return map;
|
|
96
|
-
}));
|
|
97
|
-
abstractProperties.alphaMode = definition.alphaMode;
|
|
98
|
-
promises.push(this.loadMapFromDefinition(definition.aoMap).then(map => {
|
|
99
|
-
if (map) abstractProperties.aoMap = map;
|
|
100
|
-
return map;
|
|
101
|
-
}));
|
|
102
|
-
abstractProperties.aoMapIntensity = definition.aoMapIntensity;
|
|
103
|
-
promises.push(this.loadMapFromDefinition(definition.bumpMap).then(map => {
|
|
104
|
-
if (map) abstractProperties.bumpMap = map;
|
|
105
|
-
return map;
|
|
106
|
-
}));
|
|
107
|
-
abstractProperties.bumpScale = definition.bumpScale;
|
|
108
|
-
abstractProperties.color = definition.color ? definition.color : undefined;
|
|
109
|
-
abstractProperties.depthTest = definition.depthTest;
|
|
110
|
-
abstractProperties.depthWrite = definition.depthWrite;
|
|
111
|
-
promises.push(this.loadMapFromDefinition(definition.emissiveMap).then(map => {
|
|
112
|
-
if (map) abstractProperties.emissiveMap = map;
|
|
113
|
-
return map;
|
|
114
|
-
}));
|
|
115
|
-
abstractProperties.emissiveness = definition.emissiveness ? definition.emissiveness : undefined;
|
|
116
|
-
promises.push(this.loadMapFromDefinition(definition.map).then(map => {
|
|
117
|
-
if (map) abstractProperties.map = map;
|
|
118
|
-
return map;
|
|
119
|
-
}));
|
|
120
|
-
abstractProperties.name = definition.name;
|
|
121
|
-
promises.push(this.loadMapFromDefinition(definition.normalMap).then(map => {
|
|
122
|
-
if (map) abstractProperties.normalMap = map;
|
|
123
|
-
return map;
|
|
124
|
-
}));
|
|
125
|
-
abstractProperties.normalScale = definition.normalScale;
|
|
126
|
-
abstractProperties.opacity = definition.opacity;
|
|
127
|
-
abstractProperties.shading = definition.shading;
|
|
128
|
-
abstractProperties.side = definition.side;
|
|
129
|
-
abstractProperties.transparent = definition.transparent;
|
|
130
|
-
abstractProperties.type = materialType;
|
|
131
|
-
|
|
132
|
-
switch (materialType) {
|
|
133
|
-
case MATERIAL_TYPE.SPECULAR_GLOSSINESS:
|
|
134
|
-
{
|
|
135
|
-
const specularGlossinessProperties: IMaterialSpecularGlossinessDataProperties = abstractProperties;
|
|
136
|
-
const specularGlossinessDefinition: IMaterialSpecularGlossinessDataPropertiesDefinition = definition as IMaterialSpecularGlossinessDataPropertiesDefinition;
|
|
137
|
-
|
|
138
|
-
specularGlossinessProperties.envMap = specularGlossinessDefinition.envMap;
|
|
139
|
-
specularGlossinessProperties.glossiness = specularGlossinessDefinition.glossiness;
|
|
140
|
-
specularGlossinessProperties.specular = specularGlossinessDefinition.specular;
|
|
141
|
-
|
|
142
|
-
if (specularGlossinessDefinition.specularGlossinessMap) {
|
|
143
|
-
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.specularGlossinessMap).then(map => {
|
|
144
|
-
if (map) specularGlossinessProperties.specularGlossinessMap = map;
|
|
145
|
-
return map;
|
|
146
|
-
}));
|
|
147
|
-
} else {
|
|
148
|
-
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.specularMap).then(map => {
|
|
149
|
-
if (map) specularGlossinessProperties.specularMap = map;
|
|
150
|
-
return map;
|
|
151
|
-
}));
|
|
152
|
-
promises.push(this.loadMapFromDefinition(specularGlossinessDefinition.glossinessMap).then(map => {
|
|
153
|
-
if (map) specularGlossinessProperties.glossinessMap = map;
|
|
154
|
-
return map;
|
|
155
|
-
}));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
await Promise.all(promises);
|
|
159
|
-
return new MaterialSpecularGlossinessData(specularGlossinessProperties);
|
|
160
|
-
}
|
|
161
|
-
case MATERIAL_TYPE.UNLIT:
|
|
162
|
-
{
|
|
163
|
-
const unlitProperties: IMaterialUnlitDataProperties = abstractProperties;
|
|
164
|
-
const unlitDefinition: IMaterialUnlitDataPropertiesDefinition = definition;
|
|
165
|
-
unlitProperties.envMap = unlitDefinition.envMap;
|
|
166
|
-
await Promise.all(promises);
|
|
167
|
-
return new MaterialUnlitData(unlitProperties);
|
|
168
|
-
}
|
|
169
|
-
case MATERIAL_TYPE.GEM:
|
|
170
|
-
{
|
|
171
|
-
const gemProperties: IMaterialGemDataProperties = abstractProperties;
|
|
172
|
-
const gemDefinition: IMaterialGemDataPropertiesDefinition = definition;
|
|
173
|
-
|
|
174
|
-
gemProperties.brightness = gemDefinition.brightness;
|
|
175
|
-
gemProperties.center = gemDefinition.center;
|
|
176
|
-
gemProperties.colorTransferBegin = gemDefinition.colorTransferBegin;
|
|
177
|
-
gemProperties.colorTransferEnd = gemDefinition.colorTransferEnd;
|
|
178
|
-
gemProperties.contrast = gemDefinition.contrast;
|
|
179
|
-
gemProperties.dispersion = gemDefinition.dispersion;
|
|
180
|
-
gemProperties.envMap = gemDefinition.envMap;
|
|
181
|
-
gemProperties.gamma = gemDefinition.gamma;
|
|
182
|
-
promises.push(this.loadMapFromDefinition(gemDefinition.impurityMap).then(map => {
|
|
183
|
-
if (map) gemProperties.impurityMap = map;
|
|
184
|
-
return map;
|
|
185
|
-
}));
|
|
186
|
-
gemProperties.impurityScale = gemDefinition.impurityScale;
|
|
187
|
-
gemProperties.radius = gemDefinition.radius;
|
|
188
|
-
gemProperties.refractionIndex = gemDefinition.refractionIndex;
|
|
189
|
-
promises.push(this.loadMapFromDefinition(gemDefinition.sphericalNormalMap).then(map => {
|
|
190
|
-
if (map) gemProperties.sphericalNormalMap = map;
|
|
191
|
-
return map;
|
|
192
|
-
}));
|
|
193
|
-
gemProperties.tracingDepth = gemDefinition.tracingDepth;
|
|
194
|
-
gemProperties.tracingOpacity = gemDefinition.tracingOpacity;
|
|
195
|
-
|
|
196
|
-
await Promise.all(promises);
|
|
197
|
-
return new MaterialGemData(gemProperties);
|
|
198
|
-
}
|
|
199
|
-
default:
|
|
200
|
-
{
|
|
201
|
-
const standardProperties: IMaterialStandardDataProperties = abstractProperties;
|
|
202
|
-
const standardDefinition: IMaterialStandardDataPropertiesDefinition = definition;
|
|
203
|
-
|
|
204
|
-
standardProperties.attenuationColor = standardDefinition.attenuationColor;
|
|
205
|
-
standardProperties.attenuationDistance = standardDefinition.attenuationDistance;
|
|
206
|
-
standardProperties.clearcoat = standardDefinition.clearcoat;
|
|
207
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatMap).then(map => {
|
|
208
|
-
if (map) standardProperties.clearcoatMap = map;
|
|
209
|
-
return map;
|
|
210
|
-
}));
|
|
211
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatNormalMap).then(map => {
|
|
212
|
-
if (map) standardProperties.clearcoatNormalMap = map;
|
|
213
|
-
return map;
|
|
214
|
-
}));
|
|
215
|
-
standardProperties.clearcoatRoughness = standardDefinition.clearcoatRoughness;
|
|
216
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.clearcoatRoughnessMap).then(map => {
|
|
217
|
-
if (map) standardProperties.clearcoatRoughnessMap = map;
|
|
218
|
-
return map;
|
|
219
|
-
}));
|
|
220
|
-
standardProperties.displacementBias = standardDefinition.displacementBias;
|
|
221
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.displacementMap).then(map => {
|
|
222
|
-
if (map) standardProperties.displacementMap = map;
|
|
223
|
-
return map;
|
|
224
|
-
}));
|
|
225
|
-
standardProperties.displacementScale = standardDefinition.displacementScale;
|
|
226
|
-
standardProperties.envMap = standardDefinition.envMap;
|
|
227
|
-
standardProperties.ior = standardDefinition.ior;
|
|
228
|
-
standardProperties.metalness = standardDefinition.metalness;
|
|
229
|
-
if (standardDefinition.metalnessRoughnessMap) {
|
|
230
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.metalnessMap).then(map => {
|
|
231
|
-
if (map) standardProperties.metalnessMap = map;
|
|
232
|
-
return map;
|
|
233
|
-
}));
|
|
234
|
-
} else {
|
|
235
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.metalnessMap).then(map => {
|
|
236
|
-
if (map) standardProperties.metalnessMap = map;
|
|
237
|
-
return map;
|
|
238
|
-
}));
|
|
239
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.roughnessMap).then(map => {
|
|
240
|
-
if (map) standardProperties.roughnessMap = map;
|
|
241
|
-
return map;
|
|
242
|
-
}));
|
|
243
|
-
}
|
|
244
|
-
standardProperties.roughness = standardDefinition.roughness;
|
|
245
|
-
standardProperties.sheen = standardDefinition.sheen;
|
|
246
|
-
standardProperties.sheenColor = standardDefinition.sheenColor;
|
|
247
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.sheenColorMap).then(map => {
|
|
248
|
-
if (map) standardProperties.sheenColorMap = map;
|
|
249
|
-
return map;
|
|
250
|
-
}));
|
|
251
|
-
standardProperties.sheenRoughness = standardDefinition.sheenRoughness;
|
|
252
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.sheenRoughnessMap).then(map => {
|
|
253
|
-
if (map) standardProperties.sheenRoughnessMap = map;
|
|
254
|
-
return map;
|
|
255
|
-
}));
|
|
256
|
-
standardProperties.specularColor = standardDefinition.specularColor;
|
|
257
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.specularColorMap).then(map => {
|
|
258
|
-
if (map) standardProperties.specularColorMap = map;
|
|
259
|
-
return map;
|
|
260
|
-
}));
|
|
261
|
-
standardProperties.specularIntensity = standardDefinition.specularIntensity;
|
|
262
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.specularIntensityMap).then(map => {
|
|
263
|
-
if (map) standardProperties.specularIntensityMap = map;
|
|
264
|
-
return map;
|
|
265
|
-
}));
|
|
266
|
-
standardProperties.thickness = standardDefinition.thickness;
|
|
267
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.thicknessMap).then(map => {
|
|
268
|
-
if (map) standardProperties.thicknessMap = map;
|
|
269
|
-
return map;
|
|
270
|
-
}));
|
|
271
|
-
standardProperties.transmission = standardDefinition.transmission;
|
|
272
|
-
promises.push(this.loadMapFromDefinition(standardDefinition.transmissionMap).then(map => {
|
|
273
|
-
if (map) standardProperties.transmissionMap = map;
|
|
274
|
-
return map;
|
|
275
|
-
}));
|
|
276
|
-
|
|
277
|
-
await Promise.all(promises);
|
|
278
|
-
return new MaterialStandardData(standardProperties);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Load the material content into a scene graph node.
|
|
285
|
-
*
|
|
286
|
-
* @param content the material content
|
|
287
|
-
* @returns the scene graph node
|
|
288
|
-
*/
|
|
289
|
-
public async loadContent(content: ShapeDiverResponseOutputContent): Promise<ITreeNode> {
|
|
290
|
-
const node = new TreeNode(content.name || 'material');
|
|
291
|
-
if (!content)
|
|
292
|
-
throw new ShapeDiverViewerDataProcessingError('MaterialEngine.loadContent: Invalid content was provided to material engine.');
|
|
293
|
-
|
|
294
|
-
let material = new MaterialStandardData();
|
|
295
|
-
|
|
296
|
-
if (content.data) {
|
|
297
|
-
const data: IMaterialContentData = content.data;
|
|
298
|
-
let presetData: IMaterialContentDataV3 | undefined;
|
|
299
|
-
if (data.materialpreset)
|
|
300
|
-
presetData = this.loadPresetMaterialDefinition(data.materialpreset);
|
|
301
|
-
|
|
302
|
-
if (data.materialType && data.materialType !== 'standard') {
|
|
303
|
-
// gem material https://shapediver.atlassian.net/browse/SS-2514
|
|
304
|
-
} else {
|
|
305
|
-
if (data.version) {
|
|
306
|
-
if (data.version === '1.0') {
|
|
307
|
-
material = await this.loadMaterialV3(this.loadMaterialDefinitionV1(data, presetData));
|
|
308
|
-
} else if (data.version === '2.0') {
|
|
309
|
-
material = await this.loadMaterialV3(this.loadMaterialDefinitionV2(data, presetData));
|
|
310
|
-
} else if (data.version === '3.0') {
|
|
311
|
-
material = await this.loadMaterialV3(this.loadMaterialDefinitionV3(data, presetData));
|
|
312
|
-
} else {
|
|
313
|
-
throw new ShapeDiverViewerDataProcessingError('MaterialEngine.loadContent: Material data version not supported.');
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
} else {
|
|
318
|
-
throw new ShapeDiverViewerDataProcessingError('MaterialEngine.loadContent: No material data was provided to material engine.');
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
node.data.push(material);
|
|
322
|
-
return node;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
public async loadMap(url: string, id?: string): Promise<MapData | undefined> {
|
|
326
|
-
let response;
|
|
327
|
-
if (!id) {
|
|
328
|
-
response = await this._httpClient.loadTexture(url);
|
|
329
|
-
} else {
|
|
330
|
-
response = await this._httpClient.loadTexture('https://viewer.shapediver.com/v2/materials/1024/' + id + '/' + url);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if(!response)
|
|
334
|
-
return;
|
|
335
|
-
|
|
336
|
-
if (typeof window !== 'undefined') {
|
|
337
|
-
const image = await Converter.instance.responseToImage(response);
|
|
338
|
-
return new MapData(image, { blob: response.data.blob });
|
|
339
|
-
} else {
|
|
340
|
-
return new MapData(response.data.buffer, { blob: response.data.blob });
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Load a map from a definition.
|
|
346
|
-
*
|
|
347
|
-
* @param definition
|
|
348
|
-
* @returns
|
|
349
|
-
*/
|
|
350
|
-
public async loadMapFromDefinition(definition?: IMapDataPropertiesDefinition): Promise<MapData | undefined> {
|
|
351
|
-
if (!definition) return undefined;
|
|
352
|
-
|
|
353
|
-
if (typeof definition === 'string') {
|
|
354
|
-
return this.loadMap(definition);
|
|
355
|
-
} else if (definition.image) {
|
|
356
|
-
if (typeof definition.image === 'string') {
|
|
357
|
-
return this.loadMapWithProperties({
|
|
358
|
-
href: definition.image,
|
|
359
|
-
wrapS: definition.wrapS,
|
|
360
|
-
wrapT: definition.wrapT,
|
|
361
|
-
center: definition.center as number[] | undefined,
|
|
362
|
-
color: definition.color ? this._converter.toColorArray(definition.color) : undefined,
|
|
363
|
-
offset: definition.offset as number[] | undefined,
|
|
364
|
-
repeat: definition.repeat as number[] | undefined,
|
|
365
|
-
rotation: definition.rotation
|
|
366
|
-
});
|
|
367
|
-
} else {
|
|
368
|
-
return new MapData(definition.image);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
public async loadMapWithProperties(texture: ITexture): Promise<MapData | undefined> {
|
|
375
|
-
const response = await this._httpClient.loadTexture(texture.href!);
|
|
376
|
-
|
|
377
|
-
if(!response)
|
|
378
|
-
return;
|
|
379
|
-
|
|
380
|
-
const wrapS = texture.wrapS === 1 ? TEXTURE_WRAPPING.CLAMP_TO_EDGE : texture.wrapS === 2 ? TEXTURE_WRAPPING.MIRRORED_REPEAT : TEXTURE_WRAPPING.REPEAT;
|
|
381
|
-
const wrapT = texture.wrapT === 1 ? TEXTURE_WRAPPING.CLAMP_TO_EDGE : texture.wrapT === 2 ? TEXTURE_WRAPPING.MIRRORED_REPEAT : TEXTURE_WRAPPING.REPEAT;
|
|
382
|
-
const center = texture.center ? vec2.fromValues(texture.center[0], texture.center[1]) : vec2.fromValues(0, 0);
|
|
383
|
-
const color = texture.color ? vec4.fromValues(texture.color[0] / 255, texture.color[1] / 255, texture.color[2] / 255, texture.color[3] / 255) : vec4.fromValues(1, 1, 1, 1);
|
|
384
|
-
const offset = texture.offset ? vec2.fromValues(texture.offset[0], texture.offset[1]) : vec2.fromValues(0, 0);
|
|
385
|
-
const repeat = texture.repeat ? vec2.fromValues(texture.repeat[0], texture.repeat[1]) : vec2.fromValues(1, 1);
|
|
386
|
-
|
|
387
|
-
if (typeof window !== 'undefined') {
|
|
388
|
-
const image = await Converter.instance.responseToImage(response);
|
|
389
|
-
return new MapData(image, { blob: response.data.blob, wrapS, wrapT, minFilter: TEXTURE_FILTERING.LINEAR_MIPMAP_LINEAR, magFilter: TEXTURE_FILTERING.LINEAR, center, color, offset, repeat, rotation: texture.rotation || 0 });
|
|
390
|
-
} else {
|
|
391
|
-
return new MapData(response.data.buffer, { blob: response.data.blob, wrapS, wrapT, minFilter: TEXTURE_FILTERING.LINEAR_MIPMAP_LINEAR, magFilter: TEXTURE_FILTERING.LINEAR, center, color, offset, repeat, rotation: texture.rotation || 0 });
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
public loadMaterialDefinitionV1(data: IMaterialContentDataV1, presetData: IMaterialContentDataV3 = {}): IMaterialContentDataV3 {
|
|
396
|
-
// ambient is ignored
|
|
397
|
-
|
|
398
|
-
if (data.color) {
|
|
399
|
-
presetData.color = this.multiplyColors(data.color, presetData.color);
|
|
400
|
-
} else if (data.diffuse) {
|
|
401
|
-
// multiply color with diffuse
|
|
402
|
-
presetData.color = this.multiplyColors(data.diffuse, presetData.color);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// emission is ignored
|
|
406
|
-
|
|
407
|
-
// specular is ignored
|
|
408
|
-
|
|
409
|
-
if (data.shine || data.shine === 0) {
|
|
410
|
-
presetData.metalness = Math.min(1, data.shine);
|
|
411
|
-
presetData.roughness = 1 - (Math.min(1, data.shine));
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (data.hasOwnProperty('transparency'))
|
|
415
|
-
presetData.transparency = data.transparency!;
|
|
416
|
-
|
|
417
|
-
if (data.bitmaptexture)
|
|
418
|
-
presetData.bitmaptexture = {
|
|
419
|
-
href: data.bitmaptexture
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
if (data.bumptexture)
|
|
423
|
-
presetData.bumptexture = {
|
|
424
|
-
href: data.bumptexture
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
if (data.transparencytexture)
|
|
428
|
-
presetData.transparencytexture = {
|
|
429
|
-
href: data.transparencytexture
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
return presetData;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
public loadMaterialDefinitionV2(data: IMaterialContentDataV2, presetData: IMaterialContentDataV3 = {}): IMaterialContentDataV3 {
|
|
436
|
-
// ambient is ignored
|
|
437
|
-
|
|
438
|
-
if (data.color)
|
|
439
|
-
presetData.color = this.multiplyColors(data.color, presetData.color);
|
|
440
|
-
|
|
441
|
-
presetData.side = data.side;
|
|
442
|
-
|
|
443
|
-
if (data.metalness || data.metalness === 0)
|
|
444
|
-
presetData.metalness = data.metalness;
|
|
445
|
-
|
|
446
|
-
if (data.roughness || data.roughness === 0)
|
|
447
|
-
presetData.roughness = data.roughness;
|
|
448
|
-
|
|
449
|
-
if (data.hasOwnProperty('transparency'))
|
|
450
|
-
presetData.transparency = data.transparency!;
|
|
451
|
-
|
|
452
|
-
if (data.alphaThreshold || data.alphaThreshold === 0)
|
|
453
|
-
presetData.alphaThreshold = data.alphaThreshold;
|
|
454
|
-
|
|
455
|
-
if (data.bitmaptexture)
|
|
456
|
-
presetData.bitmaptexture = {
|
|
457
|
-
href: data.bitmaptexture
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
if (data.metalnesstexture)
|
|
461
|
-
presetData.metalnesstexture = {
|
|
462
|
-
href: data.metalnesstexture
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
if (data.roughnesstexture)
|
|
466
|
-
presetData.roughnesstexture = {
|
|
467
|
-
href: data.roughnesstexture
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
if (data.bumptexture)
|
|
471
|
-
presetData.bumptexture = {
|
|
472
|
-
href: data.bumptexture
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
if (data.normaltexture)
|
|
476
|
-
presetData.normaltexture = {
|
|
477
|
-
href: data.normaltexture
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
if (data.transparencytexture)
|
|
481
|
-
presetData.transparencytexture = {
|
|
482
|
-
href: data.transparencytexture
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
return presetData;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
public loadMaterialDefinitionV3(data: IMaterialContentDataV3, presetData: IMaterialContentDataV3 = {}): IMaterialContentDataV3 {
|
|
489
|
-
// ambient is ignored
|
|
490
|
-
|
|
491
|
-
if (data.color)
|
|
492
|
-
presetData.color = this.multiplyColors(data.color, presetData.color);
|
|
493
|
-
|
|
494
|
-
presetData.side = data.side;
|
|
495
|
-
|
|
496
|
-
if (data.metalness || data.metalness === 0)
|
|
497
|
-
presetData.metalness = data.metalness;
|
|
498
|
-
|
|
499
|
-
if (data.roughness || data.roughness === 0)
|
|
500
|
-
presetData.roughness = data.roughness;
|
|
501
|
-
|
|
502
|
-
if (data.hasOwnProperty('transparency'))
|
|
503
|
-
presetData.transparency = data.transparency!;
|
|
504
|
-
|
|
505
|
-
if (data.alphaThreshold || data.alphaThreshold === 0)
|
|
506
|
-
presetData.alphaThreshold = data.alphaThreshold;
|
|
507
|
-
|
|
508
|
-
if (data.bumpAmplitude || data.bumpAmplitude === 0)
|
|
509
|
-
presetData.bumpAmplitude = data.bumpAmplitude;
|
|
510
|
-
|
|
511
|
-
if (data.bitmaptexture)
|
|
512
|
-
presetData.bitmaptexture = data.bitmaptexture;
|
|
513
|
-
|
|
514
|
-
if (data.metalnesstexture)
|
|
515
|
-
presetData.metalnesstexture = data.metalnesstexture;
|
|
516
|
-
|
|
517
|
-
if (data.roughnesstexture)
|
|
518
|
-
presetData.roughnesstexture = data.roughnesstexture;
|
|
519
|
-
|
|
520
|
-
if (data.bumptexture)
|
|
521
|
-
presetData.bumptexture = data.bumptexture;
|
|
522
|
-
|
|
523
|
-
if (data.normaltexture)
|
|
524
|
-
presetData.normaltexture = data.normaltexture;
|
|
525
|
-
|
|
526
|
-
if (data.transparencytexture)
|
|
527
|
-
presetData.transparencytexture = data.transparencytexture;
|
|
528
|
-
|
|
529
|
-
// line material https://shapediver.atlassian.net/browse/SS-2272
|
|
530
|
-
|
|
531
|
-
return presetData;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
public async loadMaterialV3(data: IMaterialContentDataV3): Promise<MaterialStandardData> {
|
|
535
|
-
const material = new MaterialStandardData();
|
|
536
|
-
const promises: Promise<MapData | undefined>[] = [];
|
|
537
|
-
// ambient is ignored
|
|
538
|
-
|
|
539
|
-
if (data.color)
|
|
540
|
-
material.color = data.color;
|
|
541
|
-
|
|
542
|
-
material.side = data.side === 'front' ? MATERIAL_SIDE.FRONT : data.side === 'back' ? MATERIAL_SIDE.BACK : MATERIAL_SIDE.DOUBLE;
|
|
543
|
-
|
|
544
|
-
if (data.metalness || data.metalness === 0)
|
|
545
|
-
material.metalness = data.metalness;
|
|
546
|
-
|
|
547
|
-
if (data.roughness || data.roughness === 0)
|
|
548
|
-
material.roughness = data.roughness;
|
|
549
|
-
|
|
550
|
-
if (data.hasOwnProperty('transparency'))
|
|
551
|
-
material.opacity = 1 - data.transparency!;
|
|
552
|
-
|
|
553
|
-
if (data.alphaThreshold || data.alphaThreshold === 0)
|
|
554
|
-
material.alphaCutoff = data.alphaThreshold;
|
|
555
|
-
|
|
556
|
-
if (data.bumpAmplitude || data.bumpAmplitude === 0)
|
|
557
|
-
material.bumpScale = data.bumpAmplitude;
|
|
558
|
-
|
|
559
|
-
if (data.bitmaptexture) {
|
|
560
|
-
promises.push(
|
|
561
|
-
this.loadMapWithProperties(data.bitmaptexture).then(map => {
|
|
562
|
-
if (map) material.map = map;
|
|
563
|
-
return map;
|
|
564
|
-
})
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
if (data.metalnesstexture) {
|
|
569
|
-
promises.push(
|
|
570
|
-
this.loadMapWithProperties(data.metalnesstexture).then(map => {
|
|
571
|
-
if (map) material.metalnessMap = map;
|
|
572
|
-
return map;
|
|
573
|
-
})
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (data.roughnesstexture) {
|
|
578
|
-
promises.push(
|
|
579
|
-
this.loadMapWithProperties(data.roughnesstexture).then(map => {
|
|
580
|
-
if (map) material.roughnessMap = map;
|
|
581
|
-
return map;
|
|
582
|
-
})
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
if (data.bumptexture) {
|
|
587
|
-
promises.push(
|
|
588
|
-
this.loadMapWithProperties(data.bumptexture).then(map => {
|
|
589
|
-
if (map) material.bumpMap = map;
|
|
590
|
-
return map;
|
|
591
|
-
})
|
|
592
|
-
);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
if (data.normaltexture) {
|
|
596
|
-
promises.push(
|
|
597
|
-
this.loadMapWithProperties(data.normaltexture).then(map => {
|
|
598
|
-
if (map) material.normalMap = map;
|
|
599
|
-
return map;
|
|
600
|
-
})
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
if (data.transparencytexture) {
|
|
605
|
-
promises.push(
|
|
606
|
-
this.loadMapWithProperties(data.transparencytexture).then(map => {
|
|
607
|
-
if (map) material.alphaMap = map;
|
|
608
|
-
return map;
|
|
609
|
-
})
|
|
610
|
-
);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
// line material https://shapediver.atlassian.net/browse/SS-2272
|
|
614
|
-
await Promise.all(promises);
|
|
615
|
-
|
|
616
|
-
return material;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
public async loadPresetMaterial(preset: number): Promise<MaterialStandardData> {
|
|
620
|
-
return this.loadMaterialV3(this.loadPresetMaterialDefinition(preset));
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
public loadPresetMaterialDefinition(preset: number): IMaterialContentDataV3 {
|
|
624
|
-
const definition: IMaterialContentDataV3 = {};
|
|
625
|
-
const idStrings = this.getClassAndSpecificId(preset);
|
|
626
|
-
if (materialDatabase[idStrings.class] && materialDatabase[idStrings.class][idStrings.specific]) {
|
|
627
|
-
this.assignSpecificDefinition(idStrings, materialDatabase[idStrings.class][idStrings.specific], definition);
|
|
628
|
-
this.assignGeneralDefinition(idStrings, materialDatabase[idStrings.class].properties, materialDatabase[idStrings.class][idStrings.specific], definition);
|
|
629
|
-
} else if (materialDatabase[idStrings.class] && materialDatabase[idStrings.class]['00']) {
|
|
630
|
-
this.assignSpecificDefinition({ class: idStrings.class, specific: '00' }, materialDatabase[idStrings.class]['00'], definition);
|
|
631
|
-
this.assignGeneralDefinition({ class: idStrings.class, specific: '00' }, materialDatabase[idStrings.class].properties, materialDatabase[idStrings.class]['00'], definition);
|
|
632
|
-
} else {
|
|
633
|
-
this.assignSpecificDefinition({ class: '00', specific: '00' }, materialDatabase['00']['00'], definition);
|
|
634
|
-
this.assignGeneralDefinition({ class: '00', specific: '00' }, materialDatabase['00'].properties, materialDatabase['00']['00'], definition);
|
|
635
|
-
}
|
|
636
|
-
return definition;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// #endregion Public Methods (12)
|
|
640
|
-
|
|
641
|
-
// #region Private Methods (4)
|
|
642
|
-
|
|
643
|
-
private assignGeneralDefinition(id: { class: string, specific: string }, generalDefinition: IPresetMaterialDefinition, specificDefinition: IPresetMaterialDefinition, definition: IMaterialContentDataV3) {
|
|
644
|
-
if (generalDefinition.transparencytexture && !specificDefinition.transparencytexture)
|
|
645
|
-
definition.transparencytexture = {
|
|
646
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + generalDefinition.transparencytexture
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
if (generalDefinition.hasOwnProperty('alphaThreshold') && !specificDefinition.hasOwnProperty('alphaThreshold'))
|
|
650
|
-
definition.alphaThreshold = generalDefinition.alphaThreshold;
|
|
651
|
-
|
|
652
|
-
if (generalDefinition.bumptexture && !specificDefinition.bumptexture)
|
|
653
|
-
definition.bumptexture = {
|
|
654
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + generalDefinition.bumptexture
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
if (generalDefinition.hasOwnProperty('bumpAmplitude') && !specificDefinition.hasOwnProperty('bumpAmplitude'))
|
|
658
|
-
definition.bumpAmplitude = generalDefinition.bumpAmplitude!;
|
|
659
|
-
|
|
660
|
-
if (generalDefinition.color && !specificDefinition.color)
|
|
661
|
-
definition.color = generalDefinition.color;
|
|
662
|
-
|
|
663
|
-
if (generalDefinition.bitmaptexture && !specificDefinition.bitmaptexture)
|
|
664
|
-
definition.bitmaptexture = {
|
|
665
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + generalDefinition.bitmaptexture
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
if (generalDefinition.hasOwnProperty('metalness') && !specificDefinition.hasOwnProperty('metalness'))
|
|
669
|
-
definition.metalness = generalDefinition.metalness!;
|
|
670
|
-
|
|
671
|
-
if (generalDefinition.metalnesstexture && !specificDefinition.metalnesstexture)
|
|
672
|
-
definition.metalnesstexture = {
|
|
673
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + generalDefinition.metalnesstexture
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
if (generalDefinition.normaltexture && !specificDefinition.normaltexture)
|
|
677
|
-
definition.normaltexture = {
|
|
678
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + generalDefinition.normaltexture
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
if (generalDefinition.hasOwnProperty('transparency') && !specificDefinition.hasOwnProperty('transparency'))
|
|
682
|
-
definition.transparency = generalDefinition.transparency;
|
|
683
|
-
|
|
684
|
-
if (generalDefinition.hasOwnProperty('roughness') && !specificDefinition.hasOwnProperty('roughness'))
|
|
685
|
-
definition.roughness = generalDefinition.roughness!;
|
|
686
|
-
|
|
687
|
-
if (generalDefinition.roughnesstexture && !specificDefinition.roughnesstexture)
|
|
688
|
-
definition.roughnesstexture = {
|
|
689
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + generalDefinition.roughnesstexture
|
|
690
|
-
};
|
|
691
|
-
|
|
692
|
-
if (generalDefinition.side && !specificDefinition.side)
|
|
693
|
-
definition.side = generalDefinition.side;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
private assignSpecificDefinition(id: { class: string, specific: string }, specificDefinition: IPresetMaterialDefinition, definition: IMaterialContentDataV3) {
|
|
697
|
-
if (specificDefinition.transparencytexture)
|
|
698
|
-
definition.transparencytexture = {
|
|
699
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + id.specific + '/' + specificDefinition.transparencytexture
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
if (specificDefinition.hasOwnProperty('alphaThreshold'))
|
|
703
|
-
definition.alphaThreshold = specificDefinition.alphaThreshold!;
|
|
704
|
-
|
|
705
|
-
if (specificDefinition.bumptexture)
|
|
706
|
-
definition.bumptexture = {
|
|
707
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + id.specific + '/' + specificDefinition.bumptexture
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
if (specificDefinition.hasOwnProperty('bumpAmplitude'))
|
|
711
|
-
definition.bumpAmplitude = specificDefinition.bumpAmplitude!;
|
|
712
|
-
|
|
713
|
-
if (specificDefinition.color)
|
|
714
|
-
definition.color = specificDefinition.color;
|
|
715
|
-
|
|
716
|
-
if (specificDefinition.bitmaptexture)
|
|
717
|
-
definition.bitmaptexture = {
|
|
718
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + id.specific + '/' + specificDefinition.bitmaptexture
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
if (specificDefinition.hasOwnProperty('metalness'))
|
|
722
|
-
definition.metalness = specificDefinition.metalness!;
|
|
723
|
-
|
|
724
|
-
if (specificDefinition.metalnesstexture)
|
|
725
|
-
definition.metalnesstexture = {
|
|
726
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + id.specific + '/' + specificDefinition.metalnesstexture
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
if (specificDefinition.normaltexture)
|
|
730
|
-
definition.normaltexture = {
|
|
731
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + id.specific + '/' + specificDefinition.normaltexture
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
if (specificDefinition.hasOwnProperty('transparency'))
|
|
735
|
-
definition.transparency = specificDefinition.transparency!;
|
|
736
|
-
|
|
737
|
-
if (specificDefinition.hasOwnProperty('roughness'))
|
|
738
|
-
definition.roughness = specificDefinition.roughness!;
|
|
739
|
-
|
|
740
|
-
if (specificDefinition.roughnesstexture)
|
|
741
|
-
definition.roughnesstexture = {
|
|
742
|
-
href: 'https://viewer.shapediver.com/v2/materials/1024/' + id.class + '/' + id.specific + '/' + specificDefinition.roughnesstexture
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
if (specificDefinition.side)
|
|
746
|
-
definition.side = specificDefinition.side;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
private getClassAndSpecificId(id: number): { class: string, specific: string } {
|
|
750
|
-
// for a while, we had documented the presets to be 10, 20, 30 and 40 here, we allow for the few cases where this was used to succeed
|
|
751
|
-
if (id < 100 && id % 10 == 0) id /= 10;
|
|
752
|
-
|
|
753
|
-
// if the id is less than 10, multiply it by 100
|
|
754
|
-
if (id < 10) id *= 100;
|
|
755
|
-
|
|
756
|
-
const cast = (id: number): string => {
|
|
757
|
-
const idString = String(id);
|
|
758
|
-
return idString.padStart(2, '0').slice(0, 2);
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
return {
|
|
762
|
-
class: cast(Math.floor(id / 100)),
|
|
763
|
-
specific: cast(id - (Math.floor(id / 100) * 100))
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* Multiply two colors
|
|
769
|
-
*
|
|
770
|
-
* @param color1
|
|
771
|
-
* @param color2
|
|
772
|
-
* @returns
|
|
773
|
-
*/
|
|
774
|
-
private multiplyColors(color1: number[], color2?: number[]): number[] {
|
|
775
|
-
if (!color2) return color1;
|
|
776
|
-
return [
|
|
777
|
-
Math.min(255, (color1[0] * color2[0]) / 255),
|
|
778
|
-
Math.min(255, (color1[1] * color2[1]) / 255),
|
|
779
|
-
Math.min(255, (color1[2] * color2[2]) / 255),
|
|
780
|
-
Math.min(255, ((color1[3] !== undefined ? color1[3] : 255) * (color2[3] !== undefined ? color2[3] : 255)) / 255)
|
|
781
|
-
];
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
// #endregion Private Methods (4)
|
|
785
|
-
}
|
package/src/index.ts
DELETED
package/src/materialDatabase.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
export const materialDatabase: { [key: string]: any } = {
|
|
2
|
-
"00": {
|
|
3
|
-
"00": {
|
|
4
|
-
"name": "Default material",
|
|
5
|
-
"color": [211, 211, 211, 255],
|
|
6
|
-
"metalness": 0,
|
|
7
|
-
"roughness": 1
|
|
8
|
-
},
|
|
9
|
-
"properties": {
|
|
10
|
-
"name": "Default materials"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"01": {
|
|
14
|
-
"01": {
|
|
15
|
-
"name": "Default groundplane material",
|
|
16
|
-
"color": [211, 211, 211, 255],
|
|
17
|
-
"metalness": 0,
|
|
18
|
-
"roughness": 1
|
|
19
|
-
},
|
|
20
|
-
"properties": {
|
|
21
|
-
"name": "Groundplane materials"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"02": {
|
|
25
|
-
"00": {
|
|
26
|
-
"name": "Default plastic material",
|
|
27
|
-
"color": [211, 211, 211, 255],
|
|
28
|
-
"metalness": 0,
|
|
29
|
-
"roughness": 1,
|
|
30
|
-
"normaltexture": "normalMap.jpg",
|
|
31
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
32
|
-
},
|
|
33
|
-
"properties": {
|
|
34
|
-
"name": "Plastic materials"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"03": {
|
|
38
|
-
"00": {
|
|
39
|
-
"name": "Default metal material",
|
|
40
|
-
"color": [205, 205, 205, 255],
|
|
41
|
-
"roughness": 0.25
|
|
42
|
-
},
|
|
43
|
-
"01": {
|
|
44
|
-
"name": "Used metal material 1",
|
|
45
|
-
"color": [205, 205, 205, 255],
|
|
46
|
-
"roughness": 1,
|
|
47
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
48
|
-
},
|
|
49
|
-
"02": {
|
|
50
|
-
"name": "Used metal material 2",
|
|
51
|
-
"color": [205, 205, 205, 255],
|
|
52
|
-
"roughness": 1,
|
|
53
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
54
|
-
},
|
|
55
|
-
"03": {
|
|
56
|
-
"name": "Used metal material 3",
|
|
57
|
-
"color": [205, 205, 205, 255],
|
|
58
|
-
"roughness": 1,
|
|
59
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
60
|
-
},
|
|
61
|
-
"10": {
|
|
62
|
-
"name": "Gold material",
|
|
63
|
-
"color": [230, 207, 92, 255],
|
|
64
|
-
"roughness": 0
|
|
65
|
-
},
|
|
66
|
-
"11": {
|
|
67
|
-
"name": "Used gold material",
|
|
68
|
-
"color": [230, 207, 92, 255],
|
|
69
|
-
"roughness": 0,
|
|
70
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
71
|
-
},
|
|
72
|
-
"21": {
|
|
73
|
-
"name": "Hammered metal material",
|
|
74
|
-
"color": [205, 205, 205, 255],
|
|
75
|
-
"roughness": 1,
|
|
76
|
-
"normaltexture": "normalMap.jpg"
|
|
77
|
-
},
|
|
78
|
-
"properties": {
|
|
79
|
-
"name": "Metal materials",
|
|
80
|
-
"metalness": 1
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
"04": {
|
|
84
|
-
"00": {
|
|
85
|
-
"name": "Default glass material",
|
|
86
|
-
"color": [211, 211, 211, 255],
|
|
87
|
-
"metalness": 1,
|
|
88
|
-
"roughness": 0,
|
|
89
|
-
"transparency": 0.75
|
|
90
|
-
},
|
|
91
|
-
"properties": { "name": "Glass materials" }
|
|
92
|
-
},
|
|
93
|
-
"05": {
|
|
94
|
-
"00": {
|
|
95
|
-
"bitmaptexture": "map.jpg",
|
|
96
|
-
"name": "Default wood material",
|
|
97
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
98
|
-
"normaltexture": "normalMap.jpg",
|
|
99
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
100
|
-
},
|
|
101
|
-
"01": {
|
|
102
|
-
"bitmaptexture": "map.jpg",
|
|
103
|
-
"name": "Wood floor material",
|
|
104
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
105
|
-
"normaltexture": "normalMap.jpg",
|
|
106
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
107
|
-
},
|
|
108
|
-
"10": {
|
|
109
|
-
"bitmaptexture": "map.jpg",
|
|
110
|
-
"name": "Natural oak material",
|
|
111
|
-
"normaltexture": "normalMap.jpg",
|
|
112
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
113
|
-
},
|
|
114
|
-
"11": {
|
|
115
|
-
"bitmaptexture": "map.jpg",
|
|
116
|
-
"name": "Premium oak material",
|
|
117
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
118
|
-
},
|
|
119
|
-
"properties": {
|
|
120
|
-
"name": "Wood materials",
|
|
121
|
-
"color": [211, 211, 211, 255],
|
|
122
|
-
"metalness": 0,
|
|
123
|
-
"roughness": 1
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
"06": {
|
|
127
|
-
"00": {
|
|
128
|
-
"bitmaptexture": "map.jpg",
|
|
129
|
-
"name": "Default leather material",
|
|
130
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
131
|
-
"normaltexture": "normalMap.jpg",
|
|
132
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
133
|
-
},
|
|
134
|
-
"01": {
|
|
135
|
-
"bitmaptexture": "map.jpg",
|
|
136
|
-
"name": "Dark brown leather material",
|
|
137
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
138
|
-
"normaltexture": "normalMap.jpg",
|
|
139
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
140
|
-
},
|
|
141
|
-
"02": {
|
|
142
|
-
"bitmaptexture": "map.jpg",
|
|
143
|
-
"name": "Black leather material",
|
|
144
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
145
|
-
"normaltexture": "normalMap.jpg",
|
|
146
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
147
|
-
},
|
|
148
|
-
"10": {
|
|
149
|
-
"bitmaptexture": "map.jpg",
|
|
150
|
-
"name": "Worn leather material",
|
|
151
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
152
|
-
"normaltexture": "normalMap.jpg",
|
|
153
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
154
|
-
},
|
|
155
|
-
"properties": {
|
|
156
|
-
"name": "Leather materials",
|
|
157
|
-
"metalness": 0, "roughness": 1
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
"07": {
|
|
161
|
-
"00": {
|
|
162
|
-
"bitmaptexture": "map.jpg",
|
|
163
|
-
"name": "Default fabric material",
|
|
164
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
165
|
-
"normaltexture": "normalMap.jpg",
|
|
166
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
167
|
-
},
|
|
168
|
-
"01": {
|
|
169
|
-
"bitmaptexture": "map.jpg",
|
|
170
|
-
"name": "Grey fabric material",
|
|
171
|
-
"metalnesstexture": "metalnessMap.jpg",
|
|
172
|
-
"normaltexture": "normalMap.jpg",
|
|
173
|
-
"roughnesstexture": "roughnessMap.jpg"
|
|
174
|
-
},
|
|
175
|
-
"properties": {
|
|
176
|
-
"name": "Fabric materials",
|
|
177
|
-
"metalness": 1, "roughness": 1
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
package/tsconfig.json
DELETED