UNPKG

3.78 kBJavaScriptView Raw
1import { Color3 } from "@babylonjs/core/Maths/math";
2import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
3import { GLTFLoader } from "../glTFLoader";
4var NAME = "KHR_materials_pbrSpecularGlossiness";
5/**
6 * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
7 */
8var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
9 /** @hidden */
10 function KHR_materials_pbrSpecularGlossiness(loader) {
11 /** The name of this extension. */
12 this.name = NAME;
13 /** Defines whether this extension is enabled. */
14 this.enabled = true;
15 this._loader = loader;
16 }
17 /** @hidden */
18 KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
19 delete this._loader;
20 };
21 /** @hidden */
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}());
66export { KHR_materials_pbrSpecularGlossiness };
67GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
68//# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map
\No newline at end of file