UNPKG

2.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_unlit";
5/**
6 * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
7 */
8var KHR_materials_unlit = /** @class */ (function () {
9 /** @hidden */
10 function KHR_materials_unlit(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_unlit.prototype.dispose = function () {
19 delete this._loader;
20 };
21 /** @hidden */
22 KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
23 var _this = this;
24 return GLTFLoader.LoadExtensionAsync(context, material, this.name, function () {
25 return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
26 });
27 };
28 KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
29 if (!(babylonMaterial instanceof PBRMaterial)) {
30 throw new Error(context + ": Material type not supported");
31 }
32 var promises = new Array();
33 babylonMaterial.unlit = true;
34 var properties = material.pbrMetallicRoughness;
35 if (properties) {
36 if (properties.baseColorFactor) {
37 babylonMaterial.albedoColor = Color3.FromArray(properties.baseColorFactor);
38 babylonMaterial.alpha = properties.baseColorFactor[3];
39 }
40 else {
41 babylonMaterial.albedoColor = Color3.White();
42 }
43 if (properties.baseColorTexture) {
44 promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
45 texture.name = babylonMaterial.name + " (Base Color)";
46 babylonMaterial.albedoTexture = texture;
47 }));
48 }
49 }
50 if (material.doubleSided) {
51 babylonMaterial.backFaceCulling = false;
52 babylonMaterial.twoSidedLighting = true;
53 }
54 this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
55 return Promise.all(promises).then(function () { });
56 };
57 return KHR_materials_unlit;
58}());
59export { KHR_materials_unlit };
60GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
61//# sourceMappingURL=KHR_materials_unlit.js.map
\No newline at end of file