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_unlit";
|
5 |
|
6 |
|
7 |
|
8 | var KHR_materials_unlit = (function () {
|
9 |
|
10 | function KHR_materials_unlit(loader) {
|
11 |
|
12 | this.name = NAME;
|
13 |
|
14 | this.enabled = true;
|
15 | this._loader = loader;
|
16 | }
|
17 |
|
18 | KHR_materials_unlit.prototype.dispose = function () {
|
19 | delete this._loader;
|
20 | };
|
21 |
|
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 | }());
|
59 | export { KHR_materials_unlit };
|
60 | GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
|
61 |
|
\ | No newline at end of file |