0b960154dc1cd66c0c7cbfce307f19143bb8b9f78bc3686c5f69761fdcbbbbe8.json 9.9 KB

1
  1. {"ast":null,"code":"import { PBRMaterial } from \"@babylonjs/core/Materials/PBR/pbrMaterial.js\";\nimport { GLTFLoader } from \"../glTFLoader.js\";\nimport { Color3 } from \"@babylonjs/core/Maths/math.color.js\";\nconst NAME = \"KHR_materials_sheen\";\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_sheen/README.md)\n * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_materials_sheen {\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 = 190;\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, (extensionContext, extension) => {\n const promises = new Array();\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\n promises.push(this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));\n return Promise.all(promises).then(() => {});\n });\n }\n _loadSheenPropertiesAsync(context, properties, babylonMaterial) {\n if (!(babylonMaterial instanceof PBRMaterial)) {\n throw new Error(`${context}: Material type not supported`);\n }\n const promises = new Array();\n babylonMaterial.sheen.isEnabled = true;\n babylonMaterial.sheen.intensity = 1;\n if (properties.sheenColorFactor != undefined) {\n babylonMaterial.sheen.color = Color3.FromArray(properties.sheenColorFactor);\n } else {\n babylonMaterial.sheen.color = Color3.Black();\n }\n if (properties.sheenColorTexture) {\n promises.push(this._loader.loadTextureInfoAsync(`${context}/sheenColorTexture`, properties.sheenColorTexture, texture => {\n texture.name = `${babylonMaterial.name} (Sheen Color)`;\n babylonMaterial.sheen.texture = texture;\n }));\n }\n if (properties.sheenRoughnessFactor !== undefined) {\n babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;\n } else {\n babylonMaterial.sheen.roughness = 0;\n }\n if (properties.sheenRoughnessTexture) {\n properties.sheenRoughnessTexture.nonColorData = true;\n promises.push(this._loader.loadTextureInfoAsync(`${context}/sheenRoughnessTexture`, properties.sheenRoughnessTexture, texture => {\n texture.name = `${babylonMaterial.name} (Sheen Roughness)`;\n babylonMaterial.sheen.textureRoughness = texture;\n }));\n }\n babylonMaterial.sheen.albedoScaling = true;\n babylonMaterial.sheen.useRoughnessFromMainTexture = false;\n return Promise.all(promises).then(() => {});\n }\n}\nGLTFLoader.RegisterExtension(NAME, loader => new KHR_materials_sheen(loader));","map":{"version":3,"names":["PBRMaterial","GLTFLoader","Color3","NAME","KHR_materials_sheen","constructor","loader","name","order","_loader","enabled","isExtensionUsed","dispose","loadMaterialPropertiesAsync","context","material","babylonMaterial","LoadExtensionAsync","extensionContext","extension","promises","Array","push","_loadSheenPropertiesAsync","Promise","all","then","properties","Error","sheen","isEnabled","intensity","sheenColorFactor","undefined","color","FromArray","Black","sheenColorTexture","loadTextureInfoAsync","texture","sheenRoughnessFactor","roughness","sheenRoughnessTexture","nonColorData","textureRoughness","albedoScaling","useRoughnessFromMainTexture","RegisterExtension"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen.js"],"sourcesContent":["import { PBRMaterial } from \"@babylonjs/core/Materials/PBR/pbrMaterial.js\";\nimport { GLTFLoader } from \"../glTFLoader.js\";\nimport { Color3 } from \"@babylonjs/core/Maths/math.color.js\";\nconst NAME = \"KHR_materials_sheen\";\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_sheen/README.md)\n * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_materials_sheen {\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 = 190;\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, (extensionContext, extension) => {\n const promises = new Array();\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\n promises.push(this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));\n return Promise.all(promises).then(() => { });\n });\n }\n _loadSheenPropertiesAsync(context, properties, babylonMaterial) {\n if (!(babylonMaterial instanceof PBRMaterial)) {\n throw new Error(`${context}: Material type not supported`);\n }\n const promises = new Array();\n babylonMaterial.sheen.isEnabled = true;\n babylonMaterial.sheen.intensity = 1;\n if (properties.sheenColorFactor != undefined) {\n babylonMaterial.sheen.color = Color3.FromArray(properties.sheenColorFactor);\n }\n else {\n babylonMaterial.sheen.color = Color3.Black();\n }\n if (properties.sheenColorTexture) {\n promises.push(this._loader.loadTextureInfoAsync(`${context}/sheenColorTexture`, properties.sheenColorTexture, (texture) => {\n texture.name = `${babylonMaterial.name} (Sheen Color)`;\n babylonMaterial.sheen.texture = texture;\n }));\n }\n if (properties.sheenRoughnessFactor !== undefined) {\n babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;\n }\n else {\n babylonMaterial.sheen.roughness = 0;\n }\n if (properties.sheenRoughnessTexture) {\n properties.sheenRoughnessTexture.nonColorData = true;\n promises.push(this._loader.loadTextureInfoAsync(`${context}/sheenRoughnessTexture`, properties.sheenRoughnessTexture, (texture) => {\n texture.name = `${babylonMaterial.name} (Sheen Roughness)`;\n babylonMaterial.sheen.textureRoughness = texture;\n }));\n }\n babylonMaterial.sheen.albedoScaling = true;\n babylonMaterial.sheen.useRoughnessFromMainTexture = false;\n return Promise.all(promises).then(() => { });\n }\n}\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_sheen(loader));\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,8CAA8C;AAC1E,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,MAAM,QAAQ,qCAAqC;AAC5D,MAAMC,IAAI,GAAG,qBAAqB;AAClC;AACA;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,OAAOf,UAAU,CAACgB,kBAAkB,CAACH,OAAO,EAAEC,QAAQ,EAAE,IAAI,CAACR,IAAI,EAAE,CAACW,gBAAgB,EAAEC,SAAS,KAAK;MAChG,MAAMC,QAAQ,GAAG,IAAIC,KAAK,CAAC,CAAC;MAC5BD,QAAQ,CAACE,IAAI,CAAC,IAAI,CAACb,OAAO,CAACI,2BAA2B,CAACC,OAAO,EAAEC,QAAQ,EAAEC,eAAe,CAAC,CAAC;MAC3FI,QAAQ,CAACE,IAAI,CAAC,IAAI,CAACC,yBAAyB,CAACL,gBAAgB,EAAEC,SAAS,EAAEH,eAAe,CAAC,CAAC;MAC3F,OAAOQ,OAAO,CAACC,GAAG,CAACL,QAAQ,CAAC,CAACM,IAAI,CAAC,MAAM,CAAE,CAAC,CAAC;IAChD,CA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