@shapediver/viewer.data-engine.geometry-engine 3.9.0 → 3.9.2
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/GeometryEngine.d.ts +2 -2
- package/dist/GeometryEngine.d.ts.map +1 -1
- package/dist/GeometryEngine.js +47 -30
- package/dist/GeometryEngine.js.map +1 -1
- package/dist/gltfv1/GLTFLoader.d.ts +2 -2
- package/dist/gltfv1/GLTFLoader.d.ts.map +1 -1
- package/dist/gltfv1/GLTFLoader.js +143 -75
- package/dist/gltfv1/GLTFLoader.js.map +1 -1
- package/dist/gltfv1/SDGTFLoader.d.ts +1 -1
- package/dist/gltfv1/SDGTFLoader.d.ts.map +1 -1
- package/dist/gltfv1/SDGTFLoader.js +95 -74
- package/dist/gltfv1/SDGTFLoader.js.map +1 -1
- package/dist/gltfv2/GLTFLoader.d.ts +6 -6
- package/dist/gltfv2/GLTFLoader.d.ts.map +1 -1
- package/dist/gltfv2/GLTFLoader.js +200 -112
- package/dist/gltfv2/GLTFLoader.js.map +1 -1
- package/dist/gltfv2/draco/draco_decoder.d.ts.map +1 -1
- package/dist/gltfv2/draco/draco_decoder.js +101696 -49810
- package/dist/gltfv2/draco/draco_decoder.js.map +1 -1
- package/dist/gltfv2/loaders/AccessorLoader.d.ts +3 -3
- package/dist/gltfv2/loaders/AccessorLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/AccessorLoader.js +21 -13
- package/dist/gltfv2/loaders/AccessorLoader.js.map +1 -1
- package/dist/gltfv2/loaders/BufferLoader.d.ts +1 -1
- package/dist/gltfv2/loaders/BufferLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/BufferLoader.js +10 -8
- package/dist/gltfv2/loaders/BufferLoader.js.map +1 -1
- package/dist/gltfv2/loaders/BufferViewLoader.d.ts +2 -2
- package/dist/gltfv2/loaders/BufferViewLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/BufferViewLoader.js +5 -5
- package/dist/gltfv2/loaders/BufferViewLoader.js.map +1 -1
- package/dist/gltfv2/loaders/GeometryLoader.d.ts +7 -7
- package/dist/gltfv2/loaders/GeometryLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/GeometryLoader.js +39 -28
- package/dist/gltfv2/loaders/GeometryLoader.js.map +1 -1
- package/dist/gltfv2/loaders/MaterialLoader.d.ts +3 -3
- package/dist/gltfv2/loaders/MaterialLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/MaterialLoader.js +301 -108
- package/dist/gltfv2/loaders/MaterialLoader.js.map +1 -1
- package/dist/gltfv2/loaders/TextureLoader.d.ts +2 -2
- package/dist/gltfv2/loaders/TextureLoader.d.ts.map +1 -1
- package/dist/gltfv2/loaders/TextureLoader.js +23 -15
- package/dist/gltfv2/loaders/TextureLoader.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/package.json +57 -57
|
@@ -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.MaterialLoader = void 0;
|
|
13
|
+
const viewer_data_engine_material_engine_1 = require("@shapediver/viewer.data-engine.material-engine");
|
|
13
14
|
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
14
|
-
const gl_matrix_1 = require("gl-matrix");
|
|
15
15
|
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
16
|
-
const
|
|
16
|
+
const gl_matrix_1 = require("gl-matrix");
|
|
17
17
|
const GLTFLoader_1 = require("../GLTFLoader");
|
|
18
18
|
class MaterialLoader {
|
|
19
19
|
// #endregion Properties (4)
|
|
@@ -30,11 +30,11 @@ class MaterialLoader {
|
|
|
30
30
|
// #region Public Methods (2)
|
|
31
31
|
getMaterial(materialId) {
|
|
32
32
|
if (!this._content.materials)
|
|
33
|
-
throw new Error(
|
|
33
|
+
throw new Error("MaterialLoader.getMaterial: Materials not available.");
|
|
34
34
|
if (!this._content.materials[materialId])
|
|
35
|
-
throw new Error(
|
|
35
|
+
throw new Error("MaterialLoader.getMaterial: Material not available.");
|
|
36
36
|
if (!this._loaded[materialId])
|
|
37
|
-
throw new Error(
|
|
37
|
+
throw new Error("MaterialLoader.getMaterial: Material not loaded.");
|
|
38
38
|
return this._loaded[materialId];
|
|
39
39
|
}
|
|
40
40
|
load() {
|
|
@@ -54,8 +54,9 @@ class MaterialLoader {
|
|
|
54
54
|
const materialPreset = materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.SHAPEDIVER_MATERIALS_PRESET];
|
|
55
55
|
promises.push(new Promise((resolve, reject) => {
|
|
56
56
|
try {
|
|
57
|
-
this._materialEngine
|
|
58
|
-
.
|
|
57
|
+
this._materialEngine
|
|
58
|
+
.loadPresetMaterial(materialPreset.materialpreset)
|
|
59
|
+
.then((materialData) => {
|
|
59
60
|
materialData.name = material.name;
|
|
60
61
|
materialData.color = materialPreset.color;
|
|
61
62
|
this._loaded[materialId] = materialData;
|
|
@@ -72,73 +73,155 @@ class MaterialLoader {
|
|
|
72
73
|
if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_PBRSPECULARGLOSSINESS]) {
|
|
73
74
|
const pbrSpecularGlossiness = materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_PBRSPECULARGLOSSINESS];
|
|
74
75
|
const specularGlossinessMaterialDataProperties = materialDataProperties;
|
|
75
|
-
specularGlossinessMaterialDataProperties.color =
|
|
76
|
+
specularGlossinessMaterialDataProperties.color = "#ffffff";
|
|
76
77
|
specularGlossinessMaterialDataProperties.opacity = 1.0;
|
|
77
78
|
if (pbrSpecularGlossiness.diffuseFactor !== undefined) {
|
|
78
|
-
specularGlossinessMaterialDataProperties.color = [
|
|
79
|
-
|
|
79
|
+
specularGlossinessMaterialDataProperties.color = [
|
|
80
|
+
pbrSpecularGlossiness.diffuseFactor[0] * 255,
|
|
81
|
+
pbrSpecularGlossiness.diffuseFactor[1] * 255,
|
|
82
|
+
pbrSpecularGlossiness.diffuseFactor[2] * 255,
|
|
83
|
+
];
|
|
84
|
+
specularGlossinessMaterialDataProperties.opacity =
|
|
85
|
+
pbrSpecularGlossiness.diffuseFactor[3];
|
|
80
86
|
}
|
|
81
87
|
if (pbrSpecularGlossiness.diffuseTexture !== undefined) {
|
|
82
|
-
const diffuseTextureOptions = pbrSpecularGlossiness.diffuseTexture.extensions &&
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
const diffuseTextureOptions = pbrSpecularGlossiness.diffuseTexture.extensions &&
|
|
89
|
+
pbrSpecularGlossiness.diffuseTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
90
|
+
? pbrSpecularGlossiness.diffuseTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
91
|
+
: {};
|
|
92
|
+
if (pbrSpecularGlossiness.diffuseTexture.texCoord !==
|
|
93
|
+
undefined)
|
|
94
|
+
diffuseTextureOptions.texCoord =
|
|
95
|
+
pbrSpecularGlossiness.diffuseTexture.texCoord;
|
|
85
96
|
specularGlossinessMaterialDataProperties.map = this.loadMap(pbrSpecularGlossiness.diffuseTexture.index, diffuseTextureOptions);
|
|
86
97
|
}
|
|
87
|
-
specularGlossinessMaterialDataProperties.emissiveness =
|
|
88
|
-
|
|
89
|
-
specularGlossinessMaterialDataProperties.
|
|
98
|
+
specularGlossinessMaterialDataProperties.emissiveness =
|
|
99
|
+
"#000000";
|
|
100
|
+
specularGlossinessMaterialDataProperties.glossiness =
|
|
101
|
+
pbrSpecularGlossiness.glossinessFactor !== undefined
|
|
102
|
+
? pbrSpecularGlossiness.glossinessFactor
|
|
103
|
+
: 1.0;
|
|
104
|
+
specularGlossinessMaterialDataProperties.specular = "#ffffff";
|
|
90
105
|
if (pbrSpecularGlossiness.specularFactor !== undefined) {
|
|
91
|
-
specularGlossinessMaterialDataProperties.specular = [
|
|
106
|
+
specularGlossinessMaterialDataProperties.specular = [
|
|
107
|
+
pbrSpecularGlossiness.specularFactor[0] * 255,
|
|
108
|
+
pbrSpecularGlossiness.specularFactor[1] * 255,
|
|
109
|
+
pbrSpecularGlossiness.specularFactor[2] * 255,
|
|
110
|
+
];
|
|
92
111
|
}
|
|
93
|
-
if (pbrSpecularGlossiness.specularGlossinessTexture !==
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
if (pbrSpecularGlossiness.specularGlossinessTexture !==
|
|
113
|
+
undefined) {
|
|
114
|
+
const specularGlossinessTextureOptions = pbrSpecularGlossiness.specularGlossinessTexture
|
|
115
|
+
.extensions &&
|
|
116
|
+
pbrSpecularGlossiness.specularGlossinessTexture
|
|
117
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
118
|
+
? pbrSpecularGlossiness.specularGlossinessTexture
|
|
119
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
120
|
+
: {};
|
|
121
|
+
if (pbrSpecularGlossiness.specularGlossinessTexture
|
|
122
|
+
.texCoord !== undefined)
|
|
123
|
+
specularGlossinessTextureOptions.texCoord =
|
|
124
|
+
pbrSpecularGlossiness.specularGlossinessTexture.texCoord;
|
|
125
|
+
specularGlossinessMaterialDataProperties.specularGlossinessMap =
|
|
126
|
+
this.loadMap(pbrSpecularGlossiness.specularGlossinessTexture
|
|
127
|
+
.index, specularGlossinessTextureOptions);
|
|
98
128
|
}
|
|
99
129
|
}
|
|
100
130
|
else if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_UNLIT]) {
|
|
101
131
|
const unlitMaterialDataProperties = materialDataProperties;
|
|
102
|
-
unlitMaterialDataProperties.color =
|
|
132
|
+
unlitMaterialDataProperties.color = "#ffffff";
|
|
103
133
|
unlitMaterialDataProperties.opacity = 1.0;
|
|
104
134
|
if (material.pbrMetallicRoughness !== undefined) {
|
|
105
|
-
if (material.pbrMetallicRoughness.baseColorFactor !==
|
|
106
|
-
|
|
107
|
-
unlitMaterialDataProperties.
|
|
135
|
+
if (material.pbrMetallicRoughness.baseColorFactor !==
|
|
136
|
+
undefined) {
|
|
137
|
+
unlitMaterialDataProperties.color = [
|
|
138
|
+
material.pbrMetallicRoughness.baseColorFactor[0] *
|
|
139
|
+
255,
|
|
140
|
+
material.pbrMetallicRoughness.baseColorFactor[1] *
|
|
141
|
+
255,
|
|
142
|
+
material.pbrMetallicRoughness.baseColorFactor[2] *
|
|
143
|
+
255,
|
|
144
|
+
];
|
|
145
|
+
unlitMaterialDataProperties.opacity =
|
|
146
|
+
material.pbrMetallicRoughness.baseColorFactor[3];
|
|
108
147
|
}
|
|
109
|
-
if (material.pbrMetallicRoughness.baseColorTexture !==
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
148
|
+
if (material.pbrMetallicRoughness.baseColorTexture !==
|
|
149
|
+
undefined) {
|
|
150
|
+
const baseColorTextureOptions = material.pbrMetallicRoughness.baseColorTexture
|
|
151
|
+
.extensions &&
|
|
152
|
+
material.pbrMetallicRoughness.baseColorTexture
|
|
153
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
154
|
+
? material.pbrMetallicRoughness.baseColorTexture
|
|
155
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
156
|
+
: {};
|
|
157
|
+
if (material.pbrMetallicRoughness.baseColorTexture
|
|
158
|
+
.texCoord !== undefined)
|
|
159
|
+
baseColorTextureOptions.texCoord =
|
|
160
|
+
material.pbrMetallicRoughness.baseColorTexture.texCoord;
|
|
161
|
+
unlitMaterialDataProperties.map = this.loadMap(material.pbrMetallicRoughness.baseColorTexture
|
|
162
|
+
.index, baseColorTextureOptions);
|
|
114
163
|
}
|
|
115
164
|
}
|
|
116
165
|
}
|
|
117
166
|
else {
|
|
118
167
|
const standardMaterialDataProperties = materialDataProperties;
|
|
119
168
|
if (material.pbrMetallicRoughness !== undefined) {
|
|
120
|
-
standardMaterialDataProperties.color =
|
|
121
|
-
if (material.pbrMetallicRoughness.baseColorFactor !==
|
|
122
|
-
|
|
123
|
-
standardMaterialDataProperties.
|
|
169
|
+
standardMaterialDataProperties.color = "#ffffff";
|
|
170
|
+
if (material.pbrMetallicRoughness.baseColorFactor !==
|
|
171
|
+
undefined) {
|
|
172
|
+
standardMaterialDataProperties.color = [
|
|
173
|
+
material.pbrMetallicRoughness.baseColorFactor[0] *
|
|
174
|
+
255,
|
|
175
|
+
material.pbrMetallicRoughness.baseColorFactor[1] *
|
|
176
|
+
255,
|
|
177
|
+
material.pbrMetallicRoughness.baseColorFactor[2] *
|
|
178
|
+
255,
|
|
179
|
+
];
|
|
180
|
+
standardMaterialDataProperties.opacity =
|
|
181
|
+
material.pbrMetallicRoughness.baseColorFactor[3];
|
|
124
182
|
}
|
|
125
|
-
if (material.pbrMetallicRoughness.baseColorTexture !==
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
183
|
+
if (material.pbrMetallicRoughness.baseColorTexture !==
|
|
184
|
+
undefined) {
|
|
185
|
+
const baseColorTextureOptions = material.pbrMetallicRoughness.baseColorTexture
|
|
186
|
+
.extensions &&
|
|
187
|
+
material.pbrMetallicRoughness.baseColorTexture
|
|
188
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
189
|
+
? material.pbrMetallicRoughness.baseColorTexture
|
|
190
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
191
|
+
: {};
|
|
192
|
+
if (material.pbrMetallicRoughness.baseColorTexture
|
|
193
|
+
.texCoord !== undefined)
|
|
194
|
+
baseColorTextureOptions.texCoord =
|
|
195
|
+
material.pbrMetallicRoughness.baseColorTexture.texCoord;
|
|
196
|
+
standardMaterialDataProperties.map = this.loadMap(material.pbrMetallicRoughness.baseColorTexture
|
|
197
|
+
.index, baseColorTextureOptions);
|
|
130
198
|
}
|
|
131
|
-
if (material.pbrMetallicRoughness.metallicFactor !==
|
|
132
|
-
|
|
199
|
+
if (material.pbrMetallicRoughness.metallicFactor !==
|
|
200
|
+
undefined) {
|
|
201
|
+
standardMaterialDataProperties.metalness =
|
|
202
|
+
material.pbrMetallicRoughness.metallicFactor;
|
|
133
203
|
}
|
|
134
|
-
if (material.pbrMetallicRoughness.roughnessFactor !==
|
|
135
|
-
|
|
204
|
+
if (material.pbrMetallicRoughness.roughnessFactor !==
|
|
205
|
+
undefined) {
|
|
206
|
+
standardMaterialDataProperties.roughness =
|
|
207
|
+
material.pbrMetallicRoughness.roughnessFactor;
|
|
136
208
|
}
|
|
137
|
-
if (material.pbrMetallicRoughness
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
209
|
+
if (material.pbrMetallicRoughness
|
|
210
|
+
.metallicRoughnessTexture !== undefined) {
|
|
211
|
+
const metallicRoughnessTextureOptions = material.pbrMetallicRoughness
|
|
212
|
+
.metallicRoughnessTexture.extensions &&
|
|
213
|
+
material.pbrMetallicRoughness
|
|
214
|
+
.metallicRoughnessTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
215
|
+
? material.pbrMetallicRoughness
|
|
216
|
+
.metallicRoughnessTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
217
|
+
: {};
|
|
218
|
+
if (material.pbrMetallicRoughness
|
|
219
|
+
.metallicRoughnessTexture.texCoord !== undefined)
|
|
220
|
+
metallicRoughnessTextureOptions.texCoord =
|
|
221
|
+
material.pbrMetallicRoughness.metallicRoughnessTexture.texCoord;
|
|
222
|
+
standardMaterialDataProperties.metalnessRoughnessMap =
|
|
223
|
+
this.loadMap(material.pbrMetallicRoughness
|
|
224
|
+
.metallicRoughnessTexture.index, metallicRoughnessTextureOptions);
|
|
142
225
|
}
|
|
143
226
|
}
|
|
144
227
|
}
|
|
@@ -146,44 +229,73 @@ class MaterialLoader {
|
|
|
146
229
|
* Loading of the general properties
|
|
147
230
|
*/
|
|
148
231
|
if (material.normalTexture !== undefined) {
|
|
149
|
-
const normalTextureOptions = material.normalTexture.extensions &&
|
|
232
|
+
const normalTextureOptions = material.normalTexture.extensions &&
|
|
233
|
+
material.normalTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
234
|
+
? material.normalTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
235
|
+
: {};
|
|
150
236
|
if (material.normalTexture.texCoord !== undefined)
|
|
151
|
-
normalTextureOptions.texCoord =
|
|
237
|
+
normalTextureOptions.texCoord =
|
|
238
|
+
material.normalTexture.texCoord;
|
|
152
239
|
materialDataProperties.normalMap = this.loadMap(material.normalTexture.index, normalTextureOptions);
|
|
153
240
|
materialDataProperties.normalScale = 1;
|
|
154
241
|
if (material.normalTexture.scale !== undefined) {
|
|
155
|
-
materialDataProperties.normalScale =
|
|
242
|
+
materialDataProperties.normalScale =
|
|
243
|
+
material.normalTexture.scale;
|
|
156
244
|
}
|
|
157
245
|
}
|
|
158
246
|
if (material.occlusionTexture !== undefined) {
|
|
159
|
-
const occlusionTextureOptions = material.occlusionTexture.extensions &&
|
|
247
|
+
const occlusionTextureOptions = material.occlusionTexture.extensions &&
|
|
248
|
+
material.occlusionTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
249
|
+
? material.occlusionTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
250
|
+
: {};
|
|
160
251
|
if (material.occlusionTexture.texCoord !== undefined)
|
|
161
|
-
occlusionTextureOptions.texCoord =
|
|
252
|
+
occlusionTextureOptions.texCoord =
|
|
253
|
+
material.occlusionTexture.texCoord;
|
|
162
254
|
materialDataProperties.aoMap = this.loadMap(material.occlusionTexture.index, occlusionTextureOptions);
|
|
163
255
|
if (material.occlusionTexture.strength !== undefined) {
|
|
164
|
-
materialDataProperties.aoMapIntensity =
|
|
256
|
+
materialDataProperties.aoMapIntensity =
|
|
257
|
+
material.occlusionTexture.strength;
|
|
165
258
|
}
|
|
166
259
|
}
|
|
167
260
|
if (material.emissiveTexture !== undefined) {
|
|
168
|
-
const emissiveTextureOptions = material.emissiveTexture.extensions &&
|
|
261
|
+
const emissiveTextureOptions = material.emissiveTexture.extensions &&
|
|
262
|
+
material.emissiveTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
263
|
+
? material.emissiveTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
264
|
+
: {};
|
|
169
265
|
if (material.emissiveTexture.texCoord !== undefined)
|
|
170
|
-
emissiveTextureOptions.texCoord =
|
|
266
|
+
emissiveTextureOptions.texCoord =
|
|
267
|
+
material.emissiveTexture.texCoord;
|
|
171
268
|
materialDataProperties.emissiveMap = this.loadMap(material.emissiveTexture.index, emissiveTextureOptions);
|
|
172
269
|
}
|
|
173
270
|
if (material.emissiveFactor !== undefined) {
|
|
174
|
-
materialDataProperties.emissiveness = [
|
|
271
|
+
materialDataProperties.emissiveness = [
|
|
272
|
+
material.emissiveFactor[0] * 255,
|
|
273
|
+
material.emissiveFactor[1] * 255,
|
|
274
|
+
material.emissiveFactor[2] * 255,
|
|
275
|
+
];
|
|
175
276
|
}
|
|
176
277
|
if (material.alphaMode !== undefined) {
|
|
177
|
-
materialDataProperties.alphaMode =
|
|
278
|
+
materialDataProperties.alphaMode =
|
|
279
|
+
material.alphaMode.toLowerCase() === viewer_shared_types_1.MATERIAL_ALPHA.MASK
|
|
280
|
+
? viewer_shared_types_1.MATERIAL_ALPHA.MASK
|
|
281
|
+
: material.alphaMode.toLowerCase() ===
|
|
282
|
+
viewer_shared_types_1.MATERIAL_ALPHA.BLEND
|
|
283
|
+
? viewer_shared_types_1.MATERIAL_ALPHA.BLEND
|
|
284
|
+
: viewer_shared_types_1.MATERIAL_ALPHA.OPAQUE;
|
|
178
285
|
if (materialDataProperties.alphaMode === viewer_shared_types_1.MATERIAL_ALPHA.MASK) {
|
|
179
|
-
materialDataProperties.alphaCutoff =
|
|
286
|
+
materialDataProperties.alphaCutoff =
|
|
287
|
+
material.alphaCutoff !== undefined
|
|
288
|
+
? material.alphaCutoff
|
|
289
|
+
: 0.5;
|
|
180
290
|
}
|
|
181
291
|
}
|
|
182
292
|
if (material.alphaCutoff !== undefined) {
|
|
183
293
|
materialDataProperties.alphaCutoff = material.alphaCutoff;
|
|
184
294
|
}
|
|
185
295
|
if (material.doubleSided !== undefined) {
|
|
186
|
-
materialDataProperties.side = material.doubleSided
|
|
296
|
+
materialDataProperties.side = material.doubleSided
|
|
297
|
+
? viewer_shared_types_1.MATERIAL_SIDE.DOUBLE
|
|
298
|
+
: viewer_shared_types_1.MATERIAL_SIDE.FRONT;
|
|
187
299
|
}
|
|
188
300
|
/**
|
|
189
301
|
* Early exit for specular glossiness and unlit materials
|
|
@@ -204,28 +316,50 @@ class MaterialLoader {
|
|
|
204
316
|
if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_CLEARCOAT]) {
|
|
205
317
|
const clearcoatExtension = materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_CLEARCOAT];
|
|
206
318
|
if (clearcoatExtension.clearcoatFactor !== undefined) {
|
|
207
|
-
standardMaterialDataProperties.clearcoat =
|
|
319
|
+
standardMaterialDataProperties.clearcoat =
|
|
320
|
+
clearcoatExtension.clearcoatFactor;
|
|
208
321
|
}
|
|
209
322
|
if (clearcoatExtension.clearcoatTexture !== undefined) {
|
|
210
|
-
const clearcoatTextureOptions = clearcoatExtension.clearcoatTexture.extensions &&
|
|
211
|
-
|
|
212
|
-
|
|
323
|
+
const clearcoatTextureOptions = clearcoatExtension.clearcoatTexture.extensions &&
|
|
324
|
+
clearcoatExtension.clearcoatTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
325
|
+
? clearcoatExtension.clearcoatTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
326
|
+
: {};
|
|
327
|
+
if (clearcoatExtension.clearcoatTexture.texCoord !==
|
|
328
|
+
undefined)
|
|
329
|
+
clearcoatTextureOptions.texCoord =
|
|
330
|
+
clearcoatExtension.clearcoatTexture.texCoord;
|
|
213
331
|
standardMaterialDataProperties.clearcoatMap = this.loadMap(clearcoatExtension.clearcoatTexture.index, clearcoatTextureOptions);
|
|
214
332
|
}
|
|
215
333
|
if (clearcoatExtension.clearcoatRoughnessFactor !== undefined) {
|
|
216
|
-
standardMaterialDataProperties.clearcoatRoughness =
|
|
334
|
+
standardMaterialDataProperties.clearcoatRoughness =
|
|
335
|
+
clearcoatExtension.clearcoatRoughnessFactor;
|
|
217
336
|
}
|
|
218
337
|
if (clearcoatExtension.clearcoatRoughnessTexture !== undefined) {
|
|
219
|
-
const clearcoatRoughnessTextureOptions = clearcoatExtension.clearcoatRoughnessTexture
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
338
|
+
const clearcoatRoughnessTextureOptions = clearcoatExtension.clearcoatRoughnessTexture
|
|
339
|
+
.extensions &&
|
|
340
|
+
clearcoatExtension.clearcoatRoughnessTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
341
|
+
? clearcoatExtension.clearcoatRoughnessTexture
|
|
342
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
343
|
+
: {};
|
|
344
|
+
if (clearcoatExtension.clearcoatRoughnessTexture
|
|
345
|
+
.texCoord !== undefined)
|
|
346
|
+
clearcoatRoughnessTextureOptions.texCoord =
|
|
347
|
+
clearcoatExtension.clearcoatRoughnessTexture.texCoord;
|
|
348
|
+
standardMaterialDataProperties.clearcoatRoughnessMap =
|
|
349
|
+
this.loadMap(clearcoatExtension.clearcoatRoughnessTexture.index, clearcoatRoughnessTextureOptions);
|
|
223
350
|
}
|
|
224
351
|
if (clearcoatExtension.clearcoatNormalTexture !== undefined) {
|
|
225
|
-
const clearcoatNormalTextureOptions = clearcoatExtension.clearcoatNormalTexture.extensions &&
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
352
|
+
const clearcoatNormalTextureOptions = clearcoatExtension.clearcoatNormalTexture.extensions &&
|
|
353
|
+
clearcoatExtension.clearcoatNormalTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
354
|
+
? clearcoatExtension.clearcoatNormalTexture
|
|
355
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
356
|
+
: {};
|
|
357
|
+
if (clearcoatExtension.clearcoatNormalTexture.texCoord !==
|
|
358
|
+
undefined)
|
|
359
|
+
clearcoatNormalTextureOptions.texCoord =
|
|
360
|
+
clearcoatExtension.clearcoatNormalTexture.texCoord;
|
|
361
|
+
standardMaterialDataProperties.clearcoatNormalMap =
|
|
362
|
+
this.loadMap(clearcoatExtension.clearcoatNormalTexture.index, clearcoatNormalTextureOptions);
|
|
229
363
|
}
|
|
230
364
|
}
|
|
231
365
|
if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_IOR]) {
|
|
@@ -237,74 +371,123 @@ class MaterialLoader {
|
|
|
237
371
|
if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_TRANSMISSION]) {
|
|
238
372
|
const transmissionExtension = materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_TRANSMISSION];
|
|
239
373
|
if (transmissionExtension.transmissionFactor !== undefined) {
|
|
240
|
-
standardMaterialDataProperties.transmission =
|
|
374
|
+
standardMaterialDataProperties.transmission =
|
|
375
|
+
transmissionExtension.transmissionFactor;
|
|
241
376
|
}
|
|
242
377
|
if (transmissionExtension.transmissionTexture !== undefined) {
|
|
243
|
-
const transmissionTextureOptions = transmissionExtension.transmissionTexture.extensions &&
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
378
|
+
const transmissionTextureOptions = transmissionExtension.transmissionTexture.extensions &&
|
|
379
|
+
transmissionExtension.transmissionTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
380
|
+
? transmissionExtension.transmissionTexture
|
|
381
|
+
.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
382
|
+
: {};
|
|
383
|
+
if (transmissionExtension.transmissionTexture.texCoord !==
|
|
384
|
+
undefined)
|
|
385
|
+
transmissionTextureOptions.texCoord =
|
|
386
|
+
transmissionExtension.transmissionTexture.texCoord;
|
|
387
|
+
standardMaterialDataProperties.transmissionMap =
|
|
388
|
+
this.loadMap(transmissionExtension.transmissionTexture.index, transmissionTextureOptions);
|
|
247
389
|
}
|
|
248
390
|
}
|
|
249
391
|
if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_VOLUME]) {
|
|
250
392
|
const volumeExtension = materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_VOLUME];
|
|
251
393
|
if (volumeExtension.thicknessFactor !== undefined) {
|
|
252
|
-
standardMaterialDataProperties.thickness =
|
|
394
|
+
standardMaterialDataProperties.thickness =
|
|
395
|
+
volumeExtension.thicknessFactor;
|
|
253
396
|
}
|
|
254
397
|
if (volumeExtension.thicknessTexture !== undefined) {
|
|
255
|
-
const thicknessTextureOptions = volumeExtension.thicknessTexture.extensions &&
|
|
398
|
+
const thicknessTextureOptions = volumeExtension.thicknessTexture.extensions &&
|
|
399
|
+
volumeExtension.thicknessTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
400
|
+
? volumeExtension.thicknessTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
401
|
+
: {};
|
|
256
402
|
if (volumeExtension.thicknessTexture.texCoord !== undefined)
|
|
257
|
-
thicknessTextureOptions.texCoord =
|
|
403
|
+
thicknessTextureOptions.texCoord =
|
|
404
|
+
volumeExtension.thicknessTexture.texCoord;
|
|
258
405
|
standardMaterialDataProperties.thicknessMap = this.loadMap(volumeExtension.thicknessTexture.index, thicknessTextureOptions);
|
|
259
406
|
}
|
|
260
407
|
if (volumeExtension.attenuationDistance !== undefined) {
|
|
261
|
-
standardMaterialDataProperties.attenuationDistance =
|
|
408
|
+
standardMaterialDataProperties.attenuationDistance =
|
|
409
|
+
volumeExtension.attenuationDistance;
|
|
262
410
|
}
|
|
263
411
|
if (volumeExtension.attenuationColor !== undefined) {
|
|
264
|
-
standardMaterialDataProperties.attenuationColor = [
|
|
412
|
+
standardMaterialDataProperties.attenuationColor = [
|
|
413
|
+
volumeExtension.attenuationColor[0] * 255,
|
|
414
|
+
volumeExtension.attenuationColor[1] * 255,
|
|
415
|
+
volumeExtension.attenuationColor[2] * 255,
|
|
416
|
+
];
|
|
265
417
|
}
|
|
266
418
|
}
|
|
267
419
|
if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_SHEEN]) {
|
|
268
420
|
const sheenExtension = materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_SHEEN];
|
|
269
421
|
standardMaterialDataProperties.sheen = 1.0;
|
|
270
422
|
if (sheenExtension.sheenColorFactor !== undefined) {
|
|
271
|
-
standardMaterialDataProperties.sheenColor = [
|
|
423
|
+
standardMaterialDataProperties.sheenColor = [
|
|
424
|
+
sheenExtension.sheenColorFactor[0] * 255,
|
|
425
|
+
sheenExtension.sheenColorFactor[1] * 255,
|
|
426
|
+
sheenExtension.sheenColorFactor[2] * 255,
|
|
427
|
+
];
|
|
272
428
|
}
|
|
273
429
|
if (sheenExtension.sheenRoughnessFactor !== undefined) {
|
|
274
|
-
standardMaterialDataProperties.sheenRoughness =
|
|
430
|
+
standardMaterialDataProperties.sheenRoughness =
|
|
431
|
+
sheenExtension.sheenRoughnessFactor;
|
|
275
432
|
}
|
|
276
433
|
if (sheenExtension.sheenColorTexture !== undefined) {
|
|
277
|
-
const sheenColorTextureOptions = sheenExtension.sheenColorTexture.extensions &&
|
|
434
|
+
const sheenColorTextureOptions = sheenExtension.sheenColorTexture.extensions &&
|
|
435
|
+
sheenExtension.sheenColorTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
436
|
+
? sheenExtension.sheenColorTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
437
|
+
: {};
|
|
278
438
|
if (sheenExtension.sheenColorTexture.texCoord !== undefined)
|
|
279
|
-
sheenColorTextureOptions.texCoord =
|
|
439
|
+
sheenColorTextureOptions.texCoord =
|
|
440
|
+
sheenExtension.sheenColorTexture.texCoord;
|
|
280
441
|
standardMaterialDataProperties.sheenColorMap = this.loadMap(sheenExtension.sheenColorTexture.index, sheenColorTextureOptions);
|
|
281
442
|
}
|
|
282
443
|
if (sheenExtension.sheenRoughnessTexture !== undefined) {
|
|
283
|
-
const sheenRoughnessTextureOptions = sheenExtension.sheenRoughnessTexture.extensions &&
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
444
|
+
const sheenRoughnessTextureOptions = sheenExtension.sheenRoughnessTexture.extensions &&
|
|
445
|
+
sheenExtension.sheenRoughnessTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
446
|
+
? sheenExtension.sheenRoughnessTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
447
|
+
: {};
|
|
448
|
+
if (sheenExtension.sheenRoughnessTexture.texCoord !==
|
|
449
|
+
undefined)
|
|
450
|
+
sheenRoughnessTextureOptions.texCoord =
|
|
451
|
+
sheenExtension.sheenRoughnessTexture.texCoord;
|
|
452
|
+
standardMaterialDataProperties.sheenRoughnessMap =
|
|
453
|
+
this.loadMap(sheenExtension.sheenRoughnessTexture.index, sheenRoughnessTextureOptions);
|
|
287
454
|
}
|
|
288
455
|
}
|
|
289
456
|
if (materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_SPECULAR]) {
|
|
290
457
|
const specularExtension = materialExtensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_MATERIALS_SPECULAR];
|
|
291
458
|
if (specularExtension.specularFactor !== undefined) {
|
|
292
|
-
standardMaterialDataProperties.specularIntensity =
|
|
459
|
+
standardMaterialDataProperties.specularIntensity =
|
|
460
|
+
specularExtension.specularFactor;
|
|
293
461
|
}
|
|
294
462
|
if (specularExtension.specularColorFactor !== undefined) {
|
|
295
|
-
standardMaterialDataProperties.specularColor = [
|
|
463
|
+
standardMaterialDataProperties.specularColor = [
|
|
464
|
+
specularExtension.specularColorFactor[0] * 255,
|
|
465
|
+
specularExtension.specularColorFactor[1] * 255,
|
|
466
|
+
specularExtension.specularColorFactor[2] * 255,
|
|
467
|
+
];
|
|
296
468
|
}
|
|
297
469
|
if (specularExtension.specularColorTexture !== undefined) {
|
|
298
|
-
const specularColorTextureOptions = specularExtension.specularColorTexture.extensions &&
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
470
|
+
const specularColorTextureOptions = specularExtension.specularColorTexture.extensions &&
|
|
471
|
+
specularExtension.specularColorTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
472
|
+
? specularExtension.specularColorTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
473
|
+
: {};
|
|
474
|
+
if (specularExtension.specularColorTexture.texCoord !==
|
|
475
|
+
undefined)
|
|
476
|
+
specularColorTextureOptions.texCoord =
|
|
477
|
+
specularExtension.specularColorTexture.texCoord;
|
|
478
|
+
standardMaterialDataProperties.specularColorMap =
|
|
479
|
+
this.loadMap(specularExtension.specularColorTexture.index, specularColorTextureOptions);
|
|
302
480
|
}
|
|
303
481
|
if (specularExtension.specularTexture !== undefined) {
|
|
304
|
-
const specularTextureOptions = specularExtension.specularTexture.extensions &&
|
|
482
|
+
const specularTextureOptions = specularExtension.specularTexture.extensions &&
|
|
483
|
+
specularExtension.specularTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
484
|
+
? specularExtension.specularTexture.extensions[GLTFLoader_1.GLTF_EXTENSIONS.KHR_TEXTURE_TRANSFORM]
|
|
485
|
+
: {};
|
|
305
486
|
if (specularExtension.specularTexture.texCoord !== undefined)
|
|
306
|
-
specularTextureOptions.texCoord =
|
|
307
|
-
|
|
487
|
+
specularTextureOptions.texCoord =
|
|
488
|
+
specularExtension.specularTexture.texCoord;
|
|
489
|
+
standardMaterialDataProperties.specularIntensityMap =
|
|
490
|
+
this.loadMap(specularExtension.specularTexture.index, specularTextureOptions);
|
|
308
491
|
}
|
|
309
492
|
}
|
|
310
493
|
const materialData = new viewer_shared_types_1.MaterialStandardData(standardMaterialDataProperties);
|
|
@@ -317,11 +500,15 @@ class MaterialLoader {
|
|
|
317
500
|
// #region Private Methods (1)
|
|
318
501
|
loadMap(textureId, properties) {
|
|
319
502
|
if (!this._content.textures)
|
|
320
|
-
throw new Error(
|
|
503
|
+
throw new Error("Textures not available.");
|
|
321
504
|
const texture = this._content.textures[textureId];
|
|
322
505
|
if (!this._content.images)
|
|
323
|
-
throw new Error(
|
|
324
|
-
const sampler = this._content.samplers &&
|
|
506
|
+
throw new Error("Images not available.");
|
|
507
|
+
const sampler = this._content.samplers &&
|
|
508
|
+
texture.sampler &&
|
|
509
|
+
this._content.samplers[texture.sampler]
|
|
510
|
+
? this._content.samplers[texture.sampler]
|
|
511
|
+
: {};
|
|
325
512
|
const loadedTexture = this._textureLoader.getTexture(textureId);
|
|
326
513
|
if (!loadedTexture)
|
|
327
514
|
return;
|
|
@@ -331,11 +518,17 @@ class MaterialLoader {
|
|
|
331
518
|
wrapT: sampler.wrapT,
|
|
332
519
|
minFilter: sampler.minFilter,
|
|
333
520
|
magFilter: sampler.magFilter,
|
|
334
|
-
offset: properties && properties.offset
|
|
335
|
-
|
|
336
|
-
|
|
521
|
+
offset: properties && properties.offset
|
|
522
|
+
? gl_matrix_1.vec2.fromValues(properties.offset[0], properties.offset[1])
|
|
523
|
+
: gl_matrix_1.vec2.create(),
|
|
524
|
+
repeat: properties && properties.scale
|
|
525
|
+
? gl_matrix_1.vec2.fromValues(properties.scale[0], properties.scale[1])
|
|
526
|
+
: gl_matrix_1.vec2.fromValues(1, 1),
|
|
527
|
+
rotation: properties && properties.rotation !== undefined
|
|
528
|
+
? properties.rotation
|
|
529
|
+
: 0,
|
|
337
530
|
texCoord: properties === null || properties === void 0 ? void 0 : properties.texCoord,
|
|
338
|
-
flipY: false
|
|
531
|
+
flipY: false,
|
|
339
532
|
});
|
|
340
533
|
}
|
|
341
534
|
}
|