forked from galacean/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKHR_materials_pbrSpecularGlossiness.ts
49 lines (42 loc) · 1.83 KB
/
KHR_materials_pbrSpecularGlossiness.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { PBRSpecularMaterial } from "@oasis-engine/core";
import { Color } from "@oasis-engine/math";
import { GLTFResource } from "../GLTFResource";
import { MaterialParser } from "../parser/MaterialParser";
import { registerExtension } from "../parser/Parser";
import { ExtensionParser } from "./ExtensionParser";
import { IKHRMaterialsPbrSpecularGlossiness } from "./Schema";
@registerExtension("KHR_materials_pbrSpecularGlossiness")
class KHR_materials_pbrSpecularGlossiness extends ExtensionParser {
createEngineResource(schema: IKHRMaterialsPbrSpecularGlossiness, context: GLTFResource): PBRSpecularMaterial {
const { engine, textures } = context;
const material = new PBRSpecularMaterial(engine);
const { diffuseFactor, diffuseTexture, specularFactor, glossinessFactor, specularGlossinessTexture } = schema;
if (diffuseFactor) {
material.baseColor = new Color(
Color.linearToGammaSpace(diffuseFactor[0]),
Color.linearToGammaSpace(diffuseFactor[1]),
Color.linearToGammaSpace(diffuseFactor[2]),
diffuseFactor[3]
);
}
if (diffuseTexture) {
material.baseTexture = textures[diffuseTexture.index];
MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
}
if (specularFactor) {
material.specularColor = new Color(
Color.linearToGammaSpace(specularFactor[0]),
Color.linearToGammaSpace(specularFactor[1]),
Color.linearToGammaSpace(specularFactor[2])
);
}
if (glossinessFactor !== undefined) {
material.glossiness = glossinessFactor;
}
if (specularGlossinessTexture) {
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
}
return material;
}
}