bg2e-js 2.2.3 → 2.2.4
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/dist/bg2e-js.js +1 -1
- package/dist/bg2e-js.js.map +1 -1
- package/package.json +1 -1
- package/src/shaders/webgl/uniforms.glsl +1 -1
- package/src/tools/MaterialModifier.ts +286 -116
package/package.json
CHANGED
|
@@ -65,7 +65,7 @@ float sampleLightEmission(sampler2D tex, vec2 uv0, vec2 uv1, PBRMaterialData mat
|
|
|
65
65
|
vec3 sampleNormal(sampler2D tex, vec2 uv0, vec2 uv1, PBRMaterialData mat, mat3 TBN)
|
|
66
66
|
{
|
|
67
67
|
vec2 uv = mat.normalUVSet == 0 ? uv0 : uv1;
|
|
68
|
-
vec3 normal = texture2D(tex, uv).xyz * 2.0 - 1.0;
|
|
68
|
+
vec3 normal = texture2D(tex, uv * mat.normalScale).xyz * 2.0 - 1.0;
|
|
69
69
|
return normalize(TBN * normal);
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -8,55 +8,89 @@ import Material from "../base/Material";
|
|
|
8
8
|
import Texture from "../base/Texture";
|
|
9
9
|
import Vec from "../math/Vec";
|
|
10
10
|
import Color from "../base/Color";
|
|
11
|
+
import Drawable from "../scene/Drawable";
|
|
12
|
+
import Canvas from "../app/Canvas";
|
|
13
|
+
import TextureCache from "./TextureCache";
|
|
11
14
|
|
|
12
15
|
const checkImageData = (texture: Texture | Color | number | null): Promise<void> => {
|
|
13
16
|
return texture instanceof Texture ? texture.loadImageData() : Promise.resolve();
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
const loadTexture = async (canvas: Canvas, fileName: string, relativePath: string): Promise<Texture> => {
|
|
20
|
+
const texture = new Texture(canvas);
|
|
21
|
+
texture.fileName = relativePath + fileName;
|
|
22
|
+
await texture.loadImageData();
|
|
23
|
+
return texture;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface MaterialModifierData {
|
|
17
27
|
class?: string;
|
|
18
28
|
alphaCutoff?: number;
|
|
19
29
|
castShadows?: boolean;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
normalScale?: any;
|
|
32
|
-
roughness?: any;
|
|
30
|
+
albedo?: [number, number, number, number];
|
|
31
|
+
albedoTexture?: string;
|
|
32
|
+
albedoScale?: [number, number];
|
|
33
|
+
normalTexture?: string;
|
|
34
|
+
normalScale?: [number, number];
|
|
35
|
+
metalness?: number;
|
|
36
|
+
metalnessTexture?: string;
|
|
37
|
+
metalnessChannel?: number;
|
|
38
|
+
metalnessScale?: [number, number];
|
|
39
|
+
roughness?: number;
|
|
40
|
+
roughnessTexture?: string;
|
|
33
41
|
roughnessChannel?: number;
|
|
34
|
-
roughnessScale?:
|
|
42
|
+
roughnessScale?: [number, number];
|
|
43
|
+
fresnelTint?: [number, number, number, number];
|
|
44
|
+
sheenIntensity?: number;
|
|
45
|
+
sheenColor?: [number, number, number, number];
|
|
46
|
+
lightEmission?: number;
|
|
47
|
+
lightEmissionTexture?: string;
|
|
48
|
+
lightEmissionChannel?: number;
|
|
49
|
+
lightEmissionScale?: [number, number];
|
|
50
|
+
isTransparent?: boolean;
|
|
35
51
|
unlit?: boolean;
|
|
52
|
+
|
|
53
|
+
// Deprecated properties
|
|
54
|
+
diffuse?: string | [number, number, number, number];
|
|
55
|
+
diffuseScale?: [number, number];
|
|
56
|
+
normal?: string;
|
|
57
|
+
fresnel?: [number, number, number, number];
|
|
58
|
+
metallic?: string | number;
|
|
59
|
+
metallicChannel?: number;
|
|
60
|
+
metallicScale?: [number, number];
|
|
36
61
|
}
|
|
37
62
|
|
|
38
63
|
// TODO: Update all material properties (difuse -> albedo, etc)
|
|
39
64
|
export default class MaterialModifier {
|
|
40
65
|
private _alphaCutoff?: number;
|
|
41
66
|
private _castShadows?: boolean;
|
|
42
|
-
private
|
|
43
|
-
private
|
|
44
|
-
private
|
|
45
|
-
private
|
|
46
|
-
private
|
|
47
|
-
private
|
|
48
|
-
private
|
|
49
|
-
private
|
|
50
|
-
private
|
|
51
|
-
private
|
|
52
|
-
private
|
|
53
|
-
private _normalScale?: any;
|
|
54
|
-
private _roughness?: any;
|
|
67
|
+
private _albedo?: [number, number, number, number];
|
|
68
|
+
private _albedoTexture?: string;
|
|
69
|
+
private _albedoScale?: [number, number];
|
|
70
|
+
private _normalTexture?: string;
|
|
71
|
+
private _normalScale?: [number, number];
|
|
72
|
+
private _metalness?: number;
|
|
73
|
+
private _metalnessTexture?: string;
|
|
74
|
+
private _metalnessChannel?: number;
|
|
75
|
+
private _metalnessScale?: [number, number];
|
|
76
|
+
private _roughness?: number;
|
|
77
|
+
private _roughnessTexture?: string;
|
|
55
78
|
private _roughnessChannel?: number;
|
|
56
|
-
private _roughnessScale?:
|
|
79
|
+
private _roughnessScale?: [number, number];
|
|
80
|
+
private _fresnelTint?: [number, number, number, number];
|
|
81
|
+
private _sheenIntensity?: number;
|
|
82
|
+
private _sheenColor?: [number, number, number, number];
|
|
83
|
+
private _lightEmission?: [number, number, number, number];
|
|
84
|
+
private _lightEmissionTexture?: string;
|
|
85
|
+
private _lightEmissionChannel?: number;
|
|
86
|
+
private _lightEmissionScale?: [number, number];
|
|
87
|
+
private _isTransparent?: boolean;
|
|
57
88
|
private _unlit?: boolean;
|
|
58
89
|
|
|
59
|
-
|
|
90
|
+
private _texturesPath: string = "";
|
|
91
|
+
|
|
92
|
+
constructor(jsonData: MaterialModifierData | null = null, texturesPath: string = "") {
|
|
93
|
+
this._texturesPath = texturesPath;
|
|
60
94
|
if (jsonData) {
|
|
61
95
|
if (jsonData['class'] && jsonData['class'] !== "PBRMaterial") {
|
|
62
96
|
console.warn(`Could not apply material modifier because of class "${jsonData['class']}". Check the valid material types in bg2 engine v2`);
|
|
@@ -70,58 +104,89 @@ export default class MaterialModifier {
|
|
|
70
104
|
this.castShadows = jsonData.castShadows;
|
|
71
105
|
}
|
|
72
106
|
|
|
73
|
-
if (jsonData.diffuse !== undefined) {
|
|
74
|
-
this.
|
|
107
|
+
if (jsonData.diffuse !== undefined && typeof jsonData.diffuse === "string") {
|
|
108
|
+
this.albedoTexture = jsonData.diffuse;
|
|
109
|
+
}
|
|
110
|
+
else if (jsonData.diffuse !== undefined && Array.isArray(jsonData.diffuse)) {
|
|
111
|
+
this.albedo = jsonData.diffuse;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (jsonData.albedoTexture !== undefined) {
|
|
115
|
+
this.albedoTexture = jsonData.albedoTexture;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (jsonData.albedoScale !== undefined) {
|
|
119
|
+
this.albedoScale = jsonData.albedoScale;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (jsonData.albedo !== undefined) {
|
|
123
|
+
this.albedo = jsonData.albedo;
|
|
75
124
|
}
|
|
76
125
|
|
|
77
126
|
if (jsonData.diffuseScale !== undefined) {
|
|
78
|
-
this.
|
|
127
|
+
this.albedoScale = jsonData.diffuseScale;
|
|
79
128
|
}
|
|
80
129
|
|
|
81
|
-
if (jsonData.
|
|
82
|
-
this.
|
|
130
|
+
if (jsonData.normal !== undefined) {
|
|
131
|
+
this.normalTexture = jsonData.normal;
|
|
83
132
|
}
|
|
84
133
|
|
|
85
|
-
if (jsonData.
|
|
86
|
-
this.
|
|
134
|
+
if (jsonData.normalTexture !== undefined) {
|
|
135
|
+
this.normalTexture = jsonData.normalTexture;
|
|
87
136
|
}
|
|
88
137
|
|
|
89
|
-
if (jsonData.
|
|
90
|
-
this.
|
|
138
|
+
if (jsonData.normalScale !== undefined) {
|
|
139
|
+
this.normalScale = jsonData.normalScale;
|
|
91
140
|
}
|
|
92
141
|
|
|
93
|
-
if (jsonData.
|
|
94
|
-
this.
|
|
142
|
+
if (jsonData.normalScale !== undefined) {
|
|
143
|
+
this.normalScale = jsonData.normalScale;
|
|
95
144
|
}
|
|
96
145
|
|
|
97
|
-
if (jsonData.
|
|
98
|
-
this.
|
|
146
|
+
if (jsonData.metallic !== undefined && typeof jsonData.metallic === "string") {
|
|
147
|
+
this.metalnessTexture
|
|
148
|
+
= jsonData.metallic;
|
|
99
149
|
}
|
|
100
150
|
|
|
101
|
-
if (jsonData.metallic !== undefined) {
|
|
102
|
-
this.
|
|
151
|
+
if (jsonData.metallic !== undefined && typeof jsonData.metallic === "number") {
|
|
152
|
+
this.metalness = jsonData.metallic;
|
|
103
153
|
}
|
|
104
154
|
|
|
105
155
|
if (jsonData.metallicChannel !== undefined) {
|
|
106
|
-
this.
|
|
156
|
+
this.metalnessChannel = jsonData.metallicChannel;
|
|
107
157
|
}
|
|
108
158
|
|
|
109
159
|
if (jsonData.metallicScale !== undefined) {
|
|
110
|
-
this.
|
|
160
|
+
this.metalnessScale = jsonData.metallicScale;
|
|
111
161
|
}
|
|
112
162
|
|
|
113
|
-
if (jsonData.
|
|
114
|
-
this.
|
|
163
|
+
if (jsonData.metalnessTexture !== undefined) {
|
|
164
|
+
this.metalnessTexture = jsonData.metalnessTexture;
|
|
115
165
|
}
|
|
116
166
|
|
|
117
|
-
if (jsonData.
|
|
118
|
-
this.
|
|
167
|
+
if (jsonData.metalness !== undefined) {
|
|
168
|
+
this.metalness = jsonData.metalness;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (jsonData.metalnessScale !== undefined) {
|
|
172
|
+
this.metalnessScale = jsonData.metalnessScale;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (jsonData.metalnessChannel !== undefined) {
|
|
176
|
+
this.metalnessChannel = jsonData.metalnessChannel;
|
|
119
177
|
}
|
|
120
178
|
|
|
121
|
-
if (jsonData.roughness !== undefined) {
|
|
179
|
+
if (jsonData.roughness !== undefined && typeof jsonData.roughness === "string") {
|
|
180
|
+
this.roughnessTexture = jsonData.roughness;
|
|
181
|
+
}
|
|
182
|
+
else if (jsonData.roughness !== undefined && typeof jsonData.roughness === "number") {
|
|
122
183
|
this.roughness = jsonData.roughness;
|
|
123
184
|
}
|
|
124
185
|
|
|
186
|
+
if (jsonData.roughnessTexture !== undefined) {
|
|
187
|
+
this.roughnessTexture = jsonData.roughnessTexture;
|
|
188
|
+
}
|
|
189
|
+
|
|
125
190
|
if (jsonData.roughnessChannel !== undefined) {
|
|
126
191
|
this.roughnessChannel = jsonData.roughnessChannel;
|
|
127
192
|
}
|
|
@@ -130,6 +195,43 @@ export default class MaterialModifier {
|
|
|
130
195
|
this.roughnessScale = jsonData.roughnessScale;
|
|
131
196
|
}
|
|
132
197
|
|
|
198
|
+
|
|
199
|
+
if (jsonData.fresnel !== undefined) {
|
|
200
|
+
this.fresnelTint = jsonData.fresnel;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (jsonData.fresnelTint !== undefined) {
|
|
204
|
+
this.fresnelTint = jsonData.fresnelTint;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (jsonData.sheenIntensity !== undefined) {
|
|
208
|
+
this.sheenIntensity = jsonData.sheenIntensity;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (jsonData.sheenColor !== undefined) {
|
|
212
|
+
this.sheenColor = jsonData.sheenColor;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (jsonData.lightEmission !== undefined) {
|
|
216
|
+
this.lightEmission = jsonData.lightEmission;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (jsonData.lightEmissionTexture !== undefined) {
|
|
220
|
+
this.lightEmissionTexture = jsonData.lightEmissionTexture;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (jsonData.lightEmissionChannel !== undefined) {
|
|
224
|
+
this.lightEmissionChannel = jsonData.lightEmissionChannel;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (jsonData.lightEmissionScale !== undefined) {
|
|
228
|
+
this.lightEmissionScale = jsonData.lightEmissionScale;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (jsonData.isTransparent !== undefined) {
|
|
232
|
+
this.isTransparent = jsonData.isTransparent;
|
|
233
|
+
}
|
|
234
|
+
|
|
133
235
|
if (jsonData.unlit !== undefined) {
|
|
134
236
|
this.unlit = jsonData.unlit;
|
|
135
237
|
}
|
|
@@ -143,56 +245,90 @@ export default class MaterialModifier {
|
|
|
143
245
|
get castShadows(): boolean | undefined { return this._castShadows; }
|
|
144
246
|
set castShadows(v: boolean | undefined) { this._castShadows = v; }
|
|
145
247
|
|
|
146
|
-
get
|
|
147
|
-
set
|
|
248
|
+
get albedo(): [number, number, number, number] | undefined { return this._albedo; }
|
|
249
|
+
set albedo(v: [number, number, number, number] | undefined) { this._albedo = v; }
|
|
148
250
|
|
|
149
|
-
get
|
|
150
|
-
set
|
|
251
|
+
get albedoTexture(): string | undefined { return this._albedoTexture; }
|
|
252
|
+
set albedoTexture(v: string | undefined) { this._albedoTexture = v; }
|
|
151
253
|
|
|
152
|
-
get
|
|
153
|
-
set
|
|
254
|
+
get albedoScale(): [number, number] | undefined { return this._albedoScale; }
|
|
255
|
+
set albedoScale(v: [number, number] | undefined) { this._albedoScale = v; }
|
|
154
256
|
|
|
155
|
-
get
|
|
156
|
-
set
|
|
257
|
+
get normalTexture(): string | undefined { return this._normalTexture; }
|
|
258
|
+
set normalTexture(v: string | undefined) { this._normalTexture = v; }
|
|
157
259
|
|
|
158
|
-
get
|
|
159
|
-
set
|
|
260
|
+
get normalScale(): [number, number] | undefined { return this._normalScale; }
|
|
261
|
+
set normalScale(v: [number, number] | undefined) { this._normalScale = v; }
|
|
160
262
|
|
|
161
|
-
get
|
|
162
|
-
set
|
|
163
|
-
|
|
164
|
-
get lightEmissionScale(): any { return this._lightEmissionScale; }
|
|
165
|
-
set lightEmissionScale(v: any) { this._lightEmissionScale = v; }
|
|
166
|
-
|
|
167
|
-
get metallic(): any { return this._metallic; }
|
|
168
|
-
set metallic(v: any) { this._metallic = v; }
|
|
263
|
+
get metalness(): number | undefined { return this._metalness; }
|
|
264
|
+
set metalness(v: number | undefined) { this._metalness = v; }
|
|
169
265
|
|
|
170
|
-
get
|
|
171
|
-
set
|
|
266
|
+
get metalnessTexture(): string | undefined { return this._metalnessTexture; }
|
|
267
|
+
set metalnessTexture(v: string | undefined) { this._metalnessTexture = v; }
|
|
172
268
|
|
|
173
|
-
get
|
|
174
|
-
set
|
|
269
|
+
get metalnessChannel(): number | undefined { return this._metalnessChannel; }
|
|
270
|
+
set metalnessChannel(v: number | undefined) { this._metalnessChannel = v; }
|
|
175
271
|
|
|
176
|
-
get
|
|
177
|
-
set
|
|
272
|
+
get metalnessScale(): [number, number] | undefined { return this._metalnessScale; }
|
|
273
|
+
set metalnessScale(v: [number, number] | undefined) { this._metalnessScale = v; }
|
|
178
274
|
|
|
179
|
-
get
|
|
180
|
-
set
|
|
275
|
+
get roughness(): number | undefined { return this._roughness; }
|
|
276
|
+
set roughness(v: number | undefined) { this._roughness = v; }
|
|
181
277
|
|
|
182
|
-
get
|
|
183
|
-
set
|
|
278
|
+
get roughnessTexture(): string | undefined { return this._roughnessTexture; }
|
|
279
|
+
set roughnessTexture(v: string | undefined) { this._roughnessTexture = v; }
|
|
184
280
|
|
|
185
281
|
get roughnessChannel(): number | undefined { return this._roughnessChannel; }
|
|
186
282
|
set roughnessChannel(v: number | undefined) { this._roughnessChannel = v; }
|
|
187
283
|
|
|
188
|
-
get roughnessScale():
|
|
189
|
-
set roughnessScale(v:
|
|
284
|
+
get roughnessScale(): [number, number] | undefined { return this._roughnessScale; }
|
|
285
|
+
set roughnessScale(v: [number, number] | undefined) { this._roughnessScale = v; }
|
|
286
|
+
|
|
287
|
+
get fresnelTint(): [number, number, number, number] | undefined { return this._fresnelTint; }
|
|
288
|
+
set fresnelTint(v: [number, number, number, number] | undefined) { this._fresnelTint = v; }
|
|
289
|
+
|
|
290
|
+
get sheenIntensity(): number | undefined { return this._sheenIntensity; }
|
|
291
|
+
set sheenIntensity(v: number | undefined) { this._sheenIntensity = v; }
|
|
292
|
+
|
|
293
|
+
get sheenColor(): [number, number, number, number] | undefined { return this._sheenColor; }
|
|
294
|
+
set sheenColor(v: [number, number, number, number] | undefined) { this._sheenColor = v; }
|
|
295
|
+
|
|
296
|
+
get isTransparent(): boolean | undefined { return this._isTransparent; }
|
|
297
|
+
set isTransparent(v: boolean | undefined) { this._isTransparent = v; }
|
|
298
|
+
|
|
299
|
+
get lightEmission(): any { return this._lightEmission; }
|
|
300
|
+
set lightEmission(v: any) { this._lightEmission = v; }
|
|
301
|
+
|
|
302
|
+
get lightEmissionTexture(): string | undefined { return this._lightEmissionTexture; }
|
|
303
|
+
set lightEmissionTexture(v: string | undefined) { this._lightEmissionTexture = v; }
|
|
304
|
+
|
|
305
|
+
get lightEmissionChannel(): number | undefined { return this._lightEmissionChannel; }
|
|
306
|
+
set lightEmissionChannel(v: number | undefined) { this._lightEmissionChannel = v; }
|
|
307
|
+
|
|
308
|
+
get lightEmissionScale(): any { return this._lightEmissionScale; }
|
|
309
|
+
set lightEmissionScale(v: any) { this._lightEmissionScale = v; }
|
|
190
310
|
|
|
191
311
|
get unlit(): boolean | undefined { return this._unlit; }
|
|
192
312
|
set unlit(v: boolean | undefined) { this._unlit = v; }
|
|
193
313
|
|
|
194
|
-
|
|
314
|
+
get texturesPath(): string { return this._texturesPath; }
|
|
315
|
+
set texturesPath(v: string) { this._texturesPath = v; }
|
|
316
|
+
|
|
317
|
+
async applyDrawable(canvas: Canvas, drawable: Drawable, { groupName, groupRE } : { groupName?: string, groupRE?: RegExp } = {}): Promise<void> {
|
|
318
|
+
drawable.items.forEach(item => {
|
|
319
|
+
if ( (groupName && item.polyList.groupName === groupName) ||
|
|
320
|
+
(groupRE && item.polyList.groupName && groupRE.test(item.polyList.groupName)) ||
|
|
321
|
+
(!groupName && !groupRE))
|
|
322
|
+
{
|
|
323
|
+
this.apply(canvas, item.material);
|
|
324
|
+
}
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async apply(canvas: Canvas, material: Material): Promise<void> {
|
|
329
|
+
const relativePath = this._texturesPath;
|
|
195
330
|
const promises: Promise<void>[] = [];
|
|
331
|
+
|
|
196
332
|
if (this.alphaCutoff !== undefined) {
|
|
197
333
|
material.alphaCutoff = this.alphaCutoff;
|
|
198
334
|
}
|
|
@@ -201,75 +337,109 @@ export default class MaterialModifier {
|
|
|
201
337
|
material.castShadows = this.castShadows;
|
|
202
338
|
}
|
|
203
339
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
//(material as any).diffuse = deserializeColorTexture(this.diffuse, relativePath);
|
|
207
|
-
//promises.push(checkImageData((material as any).diffuse));
|
|
340
|
+
if (this.albedo !== undefined) {
|
|
341
|
+
material.albedo = new Color(this.albedo);
|
|
208
342
|
}
|
|
209
343
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
344
|
+
if (this.albedoTexture !== undefined) {
|
|
345
|
+
promises.push(new Promise<void>(async (resolve) => {
|
|
346
|
+
material.albedoTexture = await loadTexture(canvas, this.albedoTexture!, relativePath);
|
|
347
|
+
resolve();
|
|
348
|
+
}));
|
|
213
349
|
}
|
|
214
350
|
|
|
215
|
-
if (this.
|
|
216
|
-
|
|
351
|
+
if (this.albedoScale !== undefined) {
|
|
352
|
+
material.albedoScale = new Vec(this.albedoScale);
|
|
217
353
|
}
|
|
218
354
|
|
|
219
|
-
if (this.
|
|
220
|
-
|
|
355
|
+
if (this.normalTexture !== undefined) {
|
|
356
|
+
promises.push(new Promise<void>(async (resolve) => {
|
|
357
|
+
material.normalTexture = await loadTexture(canvas, this.normalTexture!, relativePath);
|
|
358
|
+
resolve();
|
|
359
|
+
}));
|
|
221
360
|
}
|
|
222
361
|
|
|
223
|
-
if (this.
|
|
362
|
+
if (this.normalScale !== undefined) {
|
|
363
|
+
material.normalScale = new Vec(this.normalScale);
|
|
364
|
+
}
|
|
224
365
|
|
|
366
|
+
if (this.metalness !== undefined) {
|
|
367
|
+
material.metalness = this.metalness;
|
|
225
368
|
}
|
|
226
369
|
|
|
227
|
-
if (this.
|
|
370
|
+
if (this.metalnessTexture !== undefined) {
|
|
371
|
+
promises.push(new Promise<void>(async (resolve) => {
|
|
372
|
+
material.metalnessTexture = await loadTexture(canvas, this.metalnessTexture!, relativePath);
|
|
373
|
+
resolve();
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
228
376
|
|
|
377
|
+
if (this.metalnessChannel !== undefined) {
|
|
378
|
+
material.metalnessChannel = this.metalnessChannel;
|
|
229
379
|
}
|
|
230
380
|
|
|
231
|
-
if (this.
|
|
381
|
+
if (this.metalnessScale !== undefined) {
|
|
382
|
+
material.metalnessScale = new Vec(this.metalnessScale);
|
|
383
|
+
}
|
|
232
384
|
|
|
385
|
+
if (this.roughness !== undefined) {
|
|
386
|
+
material.roughness = this.roughness;
|
|
233
387
|
}
|
|
234
388
|
|
|
235
|
-
if (this.
|
|
236
|
-
|
|
237
|
-
|
|
389
|
+
if (this.roughnessTexture !== undefined) {
|
|
390
|
+
promises.push(new Promise<void>(async (resolve) => {
|
|
391
|
+
material.roughnessTexture = await loadTexture(canvas, this.roughnessTexture!, relativePath);
|
|
392
|
+
resolve();
|
|
393
|
+
}));
|
|
238
394
|
}
|
|
239
395
|
|
|
240
|
-
if (this.
|
|
241
|
-
|
|
396
|
+
if (this.roughnessChannel !== undefined) {
|
|
397
|
+
material.roughnessChannel = this.roughnessChannel;
|
|
242
398
|
}
|
|
243
399
|
|
|
244
|
-
if (this.
|
|
245
|
-
|
|
400
|
+
if (this.roughnessScale !== undefined) {
|
|
401
|
+
material.roughnessScale = new Vec(this.roughnessScale);
|
|
246
402
|
}
|
|
247
403
|
|
|
248
|
-
if (this.
|
|
249
|
-
|
|
250
|
-
//promises.push(checkImageData((material as any).normal));
|
|
404
|
+
if (this.fresnelTint !== undefined) {
|
|
405
|
+
material.fresnelTint = new Color(this.fresnelTint);
|
|
251
406
|
}
|
|
252
407
|
|
|
253
|
-
if (this.
|
|
254
|
-
|
|
408
|
+
if (this.sheenIntensity !== undefined) {
|
|
409
|
+
material.sheenIntensity = this.sheenIntensity;
|
|
255
410
|
}
|
|
256
411
|
|
|
257
|
-
if (this.
|
|
258
|
-
|
|
259
|
-
//promises.push(checkImageData((material as any).roughness));
|
|
412
|
+
if (this.sheenColor !== undefined) {
|
|
413
|
+
material.sheenColor = new Color(this.sheenColor);
|
|
260
414
|
}
|
|
261
415
|
|
|
262
|
-
if (this.
|
|
263
|
-
material.
|
|
416
|
+
if (this.isTransparent !== undefined) {
|
|
417
|
+
material.isTransparent = this.isTransparent;
|
|
264
418
|
}
|
|
265
419
|
|
|
266
|
-
if (this.
|
|
267
|
-
|
|
420
|
+
if (this.lightEmission !== undefined) {
|
|
421
|
+
material.lightEmission = this.lightEmission;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (this.lightEmissionTexture !== undefined) {
|
|
425
|
+
promises.push(new Promise<void>(async (resolve) => {
|
|
426
|
+
material.lightEmissionTexture = await loadTexture(canvas, this.lightEmissionTexture!, relativePath);
|
|
427
|
+
resolve();
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (this.lightEmissionChannel !== undefined) {
|
|
432
|
+
material.lightEmissionChannel = this.lightEmissionChannel;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (this.lightEmissionScale !== undefined) {
|
|
436
|
+
material.lightEmissionScale = this.lightEmissionScale;
|
|
268
437
|
}
|
|
269
438
|
|
|
270
439
|
if (this.unlit !== undefined) {
|
|
271
440
|
material.unlit = this.unlit;
|
|
272
441
|
}
|
|
442
|
+
|
|
273
443
|
await Promise.allSettled(promises);
|
|
274
444
|
}
|
|
275
445
|
|