@babylonjs/loaders
Version:
The Babylon.js file loaders library is an extension you can use to load different 3D file types into a Babylon scene.
61 lines • 2.78 kB
JavaScript
import { Color3 } from "@babylonjs/core/Maths/math";
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
import { GLTFLoader } from "../glTFLoader";
var NAME = "KHR_materials_unlit";
/**
* [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
*/
var KHR_materials_unlit = /** @class */ (function () {
/** @hidden */
function KHR_materials_unlit(loader) {
/** The name of this extension. */
this.name = NAME;
/** Defines whether this extension is enabled. */
this.enabled = true;
this._loader = loader;
}
/** @hidden */
KHR_materials_unlit.prototype.dispose = function () {
delete this._loader;
};
/** @hidden */
KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
var _this = this;
return GLTFLoader.LoadExtensionAsync(context, material, this.name, function () {
return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
});
};
KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
if (!(babylonMaterial instanceof PBRMaterial)) {
throw new Error(context + ": Material type not supported");
}
var promises = new Array();
babylonMaterial.unlit = true;
var properties = material.pbrMetallicRoughness;
if (properties) {
if (properties.baseColorFactor) {
babylonMaterial.albedoColor = Color3.FromArray(properties.baseColorFactor);
babylonMaterial.alpha = properties.baseColorFactor[3];
}
else {
babylonMaterial.albedoColor = Color3.White();
}
if (properties.baseColorTexture) {
promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
texture.name = babylonMaterial.name + " (Base Color)";
babylonMaterial.albedoTexture = texture;
}));
}
}
if (material.doubleSided) {
babylonMaterial.backFaceCulling = false;
babylonMaterial.twoSidedLighting = true;
}
this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
return Promise.all(promises).then(function () { });
};
return KHR_materials_unlit;
}());
export { KHR_materials_unlit };
GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
//# sourceMappingURL=KHR_materials_unlit.js.map