63074610d67dcd1b00d30b6b4e7d70b70884516d373105e93fde7623d95bc9a8.json 7.7 KB

1
  1. {"ast":null,"code":"import { Color3 } from \"@babylonjs/core/Maths/math.color.js\";\nimport { PBRMaterial } from \"@babylonjs/core/Materials/PBR/pbrMaterial.js\";\nimport { GLTFLoader } from \"../glTFLoader.js\";\nconst NAME = \"KHR_materials_unlit\";\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_unlit/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_materials_unlit {\n /**\n * @internal\n */\n constructor(loader) {\n /**\n * The name of this extension.\n */\n this.name = NAME;\n /**\n * Defines a number that determines the order the extensions are applied.\n */\n this.order = 210;\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n /** @internal */\n dispose() {\n this._loader = null;\n }\n /**\n * @internal\n */\n loadMaterialPropertiesAsync(context, material, babylonMaterial) {\n return GLTFLoader.LoadExtensionAsync(context, material, this.name, () => {\n return this._loadUnlitPropertiesAsync(context, material, babylonMaterial);\n });\n }\n _loadUnlitPropertiesAsync(context, material, babylonMaterial) {\n if (!(babylonMaterial instanceof PBRMaterial)) {\n throw new Error(`${context}: Material type not supported`);\n }\n const promises = new Array();\n babylonMaterial.unlit = true;\n const properties = material.pbrMetallicRoughness;\n if (properties) {\n if (properties.baseColorFactor) {\n babylonMaterial.albedoColor = Color3.FromArray(properties.baseColorFactor);\n babylonMaterial.alpha = properties.baseColorFactor[3];\n } else {\n babylonMaterial.albedoColor = Color3.White();\n }\n if (properties.baseColorTexture) {\n promises.push(this._loader.loadTextureInfoAsync(`${context}/baseColorTexture`, properties.baseColorTexture, texture => {\n texture.name = `${babylonMaterial.name} (Base Color)`;\n babylonMaterial.albedoTexture = texture;\n }));\n }\n }\n if (material.doubleSided) {\n babylonMaterial.backFaceCulling = false;\n babylonMaterial.twoSidedLighting = true;\n }\n this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);\n return Promise.all(promises).then(() => {});\n }\n}\nGLTFLoader.RegisterExtension(NAME, loader => new KHR_materials_unlit(loader));","map":{"version":3,"names":["Color3","PBRMaterial","GLTFLoader","NAME","KHR_materials_unlit","constructor","loader","name","order","_loader","enabled","isExtensionUsed","dispose","loadMaterialPropertiesAsync","context","material","babylonMaterial","LoadExtensionAsync","_loadUnlitPropertiesAsync","Error","promises","Array","unlit","properties","pbrMetallicRoughness","baseColorFactor","albedoColor","FromArray","alpha","White","baseColorTexture","push","loadTextureInfoAsync","texture","albedoTexture","doubleSided","backFaceCulling","twoSidedLighting","loadMaterialAlphaProperties","Promise","all","then","RegisterExtension"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_unlit.js"],"sourcesContent":["import { Color3 } from \"@babylonjs/core/Maths/math.color.js\";\nimport { PBRMaterial } from \"@babylonjs/core/Materials/PBR/pbrMaterial.js\";\nimport { GLTFLoader } from \"../glTFLoader.js\";\nconst NAME = \"KHR_materials_unlit\";\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_unlit/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_materials_unlit {\n /**\n * @internal\n */\n constructor(loader) {\n /**\n * The name of this extension.\n */\n this.name = NAME;\n /**\n * Defines a number that determines the order the extensions are applied.\n */\n this.order = 210;\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n /** @internal */\n dispose() {\n this._loader = null;\n }\n /**\n * @internal\n */\n loadMaterialPropertiesAsync(context, material, babylonMaterial) {\n return GLTFLoader.LoadExtensionAsync(context, material, this.name, () => {\n return this._loadUnlitPropertiesAsync(context, material, babylonMaterial);\n });\n }\n _loadUnlitPropertiesAsync(context, material, babylonMaterial) {\n if (!(babylonMaterial instanceof PBRMaterial)) {\n throw new Error(`${context}: Material type not supported`);\n }\n const promises = new Array();\n babylonMaterial.unlit = true;\n const properties = material.pbrMetallicRoughness;\n if (properties) {\n if (properties.baseColorFactor) {\n babylonMaterial.albedoColor = Color3.FromArray(properties.baseColorFactor);\n babylonMaterial.alpha = properties.baseColorFactor[3];\n }\n else {\n babylonMaterial.albedoColor = Color3.White();\n }\n if (properties.baseColorTexture) {\n promises.push(this._loader.loadTextureInfoAsync(`${context}/baseColorTexture`, properties.baseColorTexture, (texture) => {\n texture.name = `${babylonMaterial.name} (Base Color)`;\n babylonMaterial.albedoTexture = texture;\n }));\n }\n }\n if (material.doubleSided) {\n babylonMaterial.backFaceCulling = false;\n babylonMaterial.twoSidedLighting = true;\n }\n this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);\n return Promise.all(promises).then(() => { });\n }\n}\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_unlit(loader));\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qCAAqC;AAC5D,SAASC,WAAW,QAAQ,8CAA8C;AAC1E,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,MAAMC,IAAI,GAAG,qBAAqB;AAClC;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,CAAC;EAC7B;AACJ;AACA;EACIC,WAAWA,CAACC,MAAM,EAAE;IAChB;AACR;AACA;IACQ,IAAI,CAACC,IAAI,GAAGJ,IAAI;IAChB;AACR;AACA;IACQ,IAAI,CAACK,KAAK,GAAG,GAAG;IAChB,IAAI,CAACC,OAAO,GAAGH,MAAM;IACrB,IAAI,CAACI,OAAO,GAAG,IAAI,CAACD,OAAO,CAACE,eAAe,CAACR,IAAI,CAAC;EACrD;EACA;EACAS,OAAOA,CAAA,EAAG;IACN,IAAI,CAACH,OAAO,GAAG,IAAI;EACvB;EACA;AACJ;AACA;EACII,2BAA2BA,CAACC,OAAO,EAAEC,QAAQ,EAAEC,eAAe,EAAE;IAC5D,OAAOd,UAAU,CAACe,kBAAkB,CAACH,OAAO,EAAEC,QAAQ,EAAE,IAAI,CAACR,IAAI,EAAE,MAAM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