1 | import { Color3 } from "@babylonjs/core/Maths/math";
|
2 | import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
|
3 | import { GLTFLoader } from "../glTFLoader";
|
4 | var NAME = "KHR_materials_pbrSpecularGlossiness";
|
5 |
|
6 |
|
7 |
|
8 | var KHR_materials_pbrSpecularGlossiness = (function () {
|
9 |
|
10 | function KHR_materials_pbrSpecularGlossiness(loader) {
|
11 |
|
12 | this.name = NAME;
|
13 |
|
14 | this.enabled = true;
|
15 | this._loader = loader;
|
16 | }
|
17 |
|
18 | KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
|
19 | delete this._loader;
|
20 | };
|
21 |
|
22 | KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
|
23 | var _this = this;
|
24 | return GLTFLoader.LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
|
25 | var promises = new Array();
|
26 | promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
27 | promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
|
28 | _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
|
29 | return Promise.all(promises).then(function () { });
|
30 | });
|
31 | };
|
32 | KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
|
33 | if (!(babylonMaterial instanceof PBRMaterial)) {
|
34 | throw new Error(context + ": Material type not supported");
|
35 | }
|
36 | var promises = new Array();
|
37 | babylonMaterial.metallic = null;
|
38 | babylonMaterial.roughness = null;
|
39 | if (properties.diffuseFactor) {
|
40 | babylonMaterial.albedoColor = Color3.FromArray(properties.diffuseFactor);
|
41 | babylonMaterial.alpha = properties.diffuseFactor[3];
|
42 | }
|
43 | else {
|
44 | babylonMaterial.albedoColor = Color3.White();
|
45 | }
|
46 | babylonMaterial.reflectivityColor = properties.specularFactor ? Color3.FromArray(properties.specularFactor) : Color3.White();
|
47 | babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
|
48 | if (properties.diffuseTexture) {
|
49 | promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
|
50 | texture.name = babylonMaterial.name + " (Diffuse)";
|
51 | babylonMaterial.albedoTexture = texture;
|
52 | }));
|
53 | }
|
54 | if (properties.specularGlossinessTexture) {
|
55 | promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
|
56 | texture.name = babylonMaterial.name + " (Specular Glossiness)";
|
57 | babylonMaterial.reflectivityTexture = texture;
|
58 | }));
|
59 | babylonMaterial.reflectivityTexture.hasAlpha = true;
|
60 | babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
|
61 | }
|
62 | return Promise.all(promises).then(function () { });
|
63 | };
|
64 | return KHR_materials_pbrSpecularGlossiness;
|
65 | }());
|
66 | export { KHR_materials_pbrSpecularGlossiness };
|
67 | GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
|
68 |
|
\ | No newline at end of file |