@babylonjs/serializers 8.34.0 → 8.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +11 -5
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +8 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +136 -13
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/{KHR_materials_clearcoat_darkening.d.ts → KHR_materials_coat.d.ts} +10 -2
- package/glTF/2.0/Extensions/KHR_materials_coat.js +383 -0
- package/glTF/2.0/Extensions/KHR_materials_coat.js.map +1 -0
- package/glTF/2.0/Extensions/{KHR_materials_clearcoat_color.d.ts → KHR_materials_fuzz.d.ts} +13 -5
- package/glTF/2.0/Extensions/KHR_materials_fuzz.js +194 -0
- package/glTF/2.0/Extensions/KHR_materials_fuzz.js.map +1 -0
- package/glTF/2.0/Extensions/index.d.ts +2 -4
- package/glTF/2.0/Extensions/index.js +2 -4
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFExporter.d.ts +2 -5
- package/glTF/2.0/glTFExporter.js +1 -1
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +1 -3
- package/glTF/2.0/glTFMaterialExporter.js +40 -31
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/package.json +3 -3
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.d.ts +0 -32
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js +0 -152
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js +0 -101
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js +0 -70
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_ior.d.ts +0 -26
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_ior.js +0 -60
- package/glTF/2.0/Extensions/KHR_materials_clearcoat_ior.js.map +0 -1
|
@@ -12,6 +12,13 @@ function OpenpbrAnisotropyStrengthToGltf(baseRoughness, anisotropy) {
|
|
|
12
12
|
const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);
|
|
13
13
|
return { newBaseRoughness, newAnisotropyStrength };
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Generate a unique ID for the merged anisotropy textures based on the internal texture data.
|
|
17
|
+
* This is used for caching merged textures.
|
|
18
|
+
* @param babylonMaterial Source OpenPBR material
|
|
19
|
+
* @returns A unique ID string for the merged anisotropy textures
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
15
22
|
function GetAnisoTextureId(babylonMaterial) {
|
|
16
23
|
const anisoStrengthTexture = babylonMaterial.specularRoughnessAnisotropyTexture;
|
|
17
24
|
const tangentTexture = babylonMaterial.geometryTangentTexture;
|
|
@@ -154,12 +161,11 @@ export class KHR_materials_anisotropy {
|
|
|
154
161
|
extensions: {},
|
|
155
162
|
};
|
|
156
163
|
if (!babylonMaterial._useGltfStyleAnisotropy) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
164
|
+
// Enable OpenPBR extension on this material.
|
|
165
|
+
node.extensions["KHR_materials_openpbr"] = {};
|
|
160
166
|
(_a = this._exporter._glTF).extensionsUsed || (_a.extensionsUsed = []);
|
|
161
|
-
if (this._exporter._glTF.extensionsUsed.indexOf("
|
|
162
|
-
this._exporter._glTF.extensionsUsed.push("
|
|
167
|
+
if (this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr") === -1) {
|
|
168
|
+
this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr");
|
|
163
169
|
}
|
|
164
170
|
}
|
|
165
171
|
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,4DAA8C;AAE7I,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC,8DAA8D;AAC9D,SAAS,+BAA+B,CAAC,aAAqB,EAAE,UAAkB;IAC9E,MAAM,SAAS,GAAG,aAAa,GAAG,aAAa,CAAC;IAChD,MAAM,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5F,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;IACjD,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAErH,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,iB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C;oBAEzD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;gBAC3C,CAAC;YACL,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport type { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n// Convert OpenPBR anisotropy values to glTF-compatible values\r\nfunction OpenpbrAnisotropyStrengthToGltf(baseRoughness: number, anisotropy: number) {\r\n const baseAlpha = baseRoughness * baseRoughness;\r\n const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));\r\n const roughnessB = (1 - anisotropy) * roughnessT;\r\n const newBaseRoughness = Math.sqrt(roughnessB);\r\n const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);\r\n\r\n return { newBaseRoughness, newAnisotropyStrength };\r\n}\r\n\r\nfunction GetAnisoTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture!.getInternalTexture()!.uniqueId : \"NoStrength\";\r\n const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture!.getInternalTexture()!.uniqueId : \"NoTangent\";\r\n return `${strengthId}_${tangentId}`;\r\n}\r\n\r\n// In your postExportMaterialAsync method:\r\nasync function CreateMergedAnisotropyTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<ProceduralTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(anisoStrengthTexture || tangentTexture)) {\r\n return null;\r\n }\r\n\r\n return await MergeTexturesAsync(\r\n \"AnisotropyTexture\",\r\n CreateRGBAConfiguration(\r\n tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel\r\n tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel\r\n anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel\r\n ),\r\n scene\r\n );\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n private _anisoTexturesMap: Record<string, ProceduralTexture> = {};\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with the additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n if (this._anisoTexturesMap[texId]) {\r\n additionalTextures.push(this._anisoTexturesMap[texId]);\r\n } else {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._anisoTexturesMap[texId] = anisoTexture;\r\n }\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n // Check if we can convert from OpenPBR anisotropy to glTF anisotropy\r\n // Conversion involves both specular roughness and anisotropic roughness changes so,\r\n // if there are textures for either, we can't reliably convert due to there potentially\r\n // being different mappings between the textures.\r\n let roughnessTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessTexture;\r\n if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {\r\n roughnessTexture = babylonMaterial.baseMetalnessTexture;\r\n }\r\n const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];\r\n\r\n // If no textures are being used, we'll always output glTF-style anisotropy.\r\n // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.\r\n if (!roughnessTexture && !mergedAnisoTexture) {\r\n // Convert constants\r\n let newBaseRoughness = babylonMaterial.specularRoughness;\r\n let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);\r\n newBaseRoughness = newParams.newBaseRoughness;\r\n newAnisotropyStrength = newParams.newAnisotropyStrength;\r\n }\r\n if (node.pbrMetallicRoughness) {\r\n node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;\r\n }\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: newAnisotropyStrength,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,\r\n anisotropyTexture: undefined,\r\n };\r\n node.extensions[NAME] = anisotropyInfo;\r\n return resolve(node);\r\n }\r\n\r\n const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle,\r\n anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,\r\n extensions: {},\r\n };\r\n\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n anisotropyInfo.extensions![\"EXT_materials_anisotropy_openpbr\"] = {\r\n openPbrAnisotropyEnabled: true,\r\n };\r\n this._exporter._glTF.extensionsUsed ||= [];\r\n if (this._exporter._glTF.extensionsUsed.indexOf(\"EXT_materials_anisotropy_openpbr\") === -1) {\r\n this._exporter._glTF.extensionsUsed.push(\"EXT_materials_anisotropy_openpbr\");\r\n }\r\n }\r\n\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAA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,IAAI,CAAC;oBAE/H,MAAM,cAAc,GAA4B;wBAC5C,kBAAkB,EAAE,eAAe,CAAC,2BAA2B;wBAC/D,kBAAkB,EAAE,eAAe,CAAC,oBAAoB;wBACxD,iBAAiB,EAAE,sBAAsB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,SAAS;wBAC9E,UAAU,EAAE,EAAE;qBACjB,CAAC;oBAEF,IAAI,CAAC,eAAe,CAAC,uBAAuB,EAAE,CAAC;wBAC3C,6CAA6C;wBAC7C,IAAI,CAAC,UAAW,CAAC,uBAAuB,CAAC,GAAG,EAAE,CAAC;wBAC/C,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,EAAC,cAAc,QAAd,cAAc,GAAK,EAAE,EAAC;wBAC3C,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;4BAC9E,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;wBACtE,CAAC;oBACL,CAAC;oBAED,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;oBAEzD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;gBAC3C,CAAC;YACL,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport type { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n// Convert OpenPBR anisotropy values to glTF-compatible values\r\nfunction OpenpbrAnisotropyStrengthToGltf(baseRoughness: number, anisotropy: number) {\r\n const baseAlpha = baseRoughness * baseRoughness;\r\n const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));\r\n const roughnessB = (1 - anisotropy) * roughnessT;\r\n const newBaseRoughness = Math.sqrt(roughnessB);\r\n const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);\r\n\r\n return { newBaseRoughness, newAnisotropyStrength };\r\n}\r\n\r\n/**\r\n * Generate a unique ID for the merged anisotropy textures based on the internal texture data.\r\n * This is used for caching merged textures.\r\n * @param babylonMaterial Source OpenPBR material\r\n * @returns A unique ID string for the merged anisotropy textures\r\n * @internal\r\n */\r\nfunction GetAnisoTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture!.getInternalTexture()!.uniqueId : \"NoStrength\";\r\n const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture!.getInternalTexture()!.uniqueId : \"NoTangent\";\r\n return `${strengthId}_${tangentId}`;\r\n}\r\n\r\n// In your postExportMaterialAsync method:\r\nasync function CreateMergedAnisotropyTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<ProceduralTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(anisoStrengthTexture || tangentTexture)) {\r\n return null;\r\n }\r\n\r\n return await MergeTexturesAsync(\r\n \"AnisotropyTexture\",\r\n CreateRGBAConfiguration(\r\n tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel\r\n tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel\r\n anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel\r\n ),\r\n scene\r\n );\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n private _anisoTexturesMap: Record<string, ProceduralTexture> = {};\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with the additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n if (this._anisoTexturesMap[texId]) {\r\n additionalTextures.push(this._anisoTexturesMap[texId]);\r\n } else {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._anisoTexturesMap[texId] = anisoTexture;\r\n }\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n // Check if we can convert from OpenPBR anisotropy to glTF anisotropy\r\n // Conversion involves both specular roughness and anisotropic roughness changes so,\r\n // if there are textures for either, we can't reliably convert due to there potentially\r\n // being different mappings between the textures.\r\n let roughnessTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessTexture;\r\n if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {\r\n roughnessTexture = babylonMaterial.baseMetalnessTexture;\r\n }\r\n const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];\r\n\r\n // If no textures are being used, we'll always output glTF-style anisotropy.\r\n // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.\r\n if (!roughnessTexture && !mergedAnisoTexture) {\r\n // Convert constants\r\n let newBaseRoughness = babylonMaterial.specularRoughness;\r\n let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);\r\n newBaseRoughness = newParams.newBaseRoughness;\r\n newAnisotropyStrength = newParams.newAnisotropyStrength;\r\n }\r\n if (node.pbrMetallicRoughness) {\r\n node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;\r\n }\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: newAnisotropyStrength,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,\r\n anisotropyTexture: undefined,\r\n };\r\n node.extensions[NAME] = anisotropyInfo;\r\n return resolve(node);\r\n }\r\n\r\n const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle,\r\n anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,\r\n extensions: {},\r\n };\r\n\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n // Enable OpenPBR extension on this material.\r\n node.extensions![\"KHR_materials_openpbr\"] = {};\r\n this._exporter._glTF.extensionsUsed ||= [];\r\n if (this._exporter._glTF.extensionsUsed.indexOf(\"KHR_materials_openpbr\") === -1) {\r\n this._exporter._glTF.extensionsUsed.push(\"KHR_materials_openpbr\");\r\n }\r\n }\r\n\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}
|
|
@@ -16,6 +16,14 @@ export declare class KHR_materials_clearcoat implements IGLTFExporterExtensionV2
|
|
|
16
16
|
private _exporter;
|
|
17
17
|
private _wasUsed;
|
|
18
18
|
constructor(exporter: GLTFExporter);
|
|
19
|
+
/**
|
|
20
|
+
* Cache that holds temporary merged textures created during export
|
|
21
|
+
*/
|
|
22
|
+
private _mergedTexturesMap;
|
|
23
|
+
/**
|
|
24
|
+
* Cache that holds internal textures of merged textures created during export
|
|
25
|
+
*/
|
|
26
|
+
private _cachedInternalTexturesMap;
|
|
19
27
|
dispose(): void;
|
|
20
28
|
/** @internal */
|
|
21
29
|
get wasUsed(): boolean;
|
|
@@ -2,7 +2,64 @@ import { GLTFExporter } from "../glTFExporter.js";
|
|
|
2
2
|
import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
|
|
3
3
|
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
4
4
|
import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openpbrMaterial.js";
|
|
5
|
+
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
|
6
|
+
import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@babylonjs/core/Materials/Textures/textureMerger.js";
|
|
5
7
|
const NAME = "KHR_materials_clearcoat";
|
|
8
|
+
/**
|
|
9
|
+
* Generate a unique ID for the merged coat textures based on the internal texture data.
|
|
10
|
+
* This is used for caching merged textures.
|
|
11
|
+
* @param babylonMaterial Source OpenPBR material
|
|
12
|
+
* @returns A unique ID string for the merged coat textures
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
function GetCoatTextureId(babylonMaterial) {
|
|
16
|
+
const coatTexture = babylonMaterial.coatWeightTexture;
|
|
17
|
+
const coatId = coatTexture && coatTexture.getInternalTexture() ? coatTexture.getInternalTexture().uniqueId : "NoCoat";
|
|
18
|
+
const coatRoughnessTexture = babylonMaterial.coatRoughnessTexture;
|
|
19
|
+
const roughnessId = coatRoughnessTexture && coatRoughnessTexture.getInternalTexture() ? coatRoughnessTexture.getInternalTexture().uniqueId : "NoRoughness";
|
|
20
|
+
return `${coatId}_${roughnessId}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Using the coat weight and coat roughness textures, create a merged internal texture that can be used
|
|
24
|
+
* for multiple textures (with potentially different transforms) on export.
|
|
25
|
+
* @param babylonMaterial The source OpenPBR material
|
|
26
|
+
* @returns A new, internal texture with the coat weight in the red channel and coat roughness in the green channel
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
async function CreateMergedCoatInternalTextureAsync(babylonMaterial) {
|
|
30
|
+
const scene = babylonMaterial.getScene();
|
|
31
|
+
const coatTexture = babylonMaterial.coatWeightTexture;
|
|
32
|
+
const coatRoughnessTexture = babylonMaterial.coatRoughnessTexture;
|
|
33
|
+
// If we don't have any textures, we don't need to generate anything.
|
|
34
|
+
if (!(coatTexture || coatRoughnessTexture)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const texture = await MergeTexturesAsync("CoatTexture", CreateRGBAConfiguration(coatTexture ? CreateTextureInput(coatTexture, 0) : CreateConstantInput(1.0), // coat weight from red channel
|
|
38
|
+
// coat roughness goes in the green channel but may come from red or green channels in the source
|
|
39
|
+
coatRoughnessTexture ? CreateTextureInput(coatRoughnessTexture, babylonMaterial._useCoatRoughnessFromGreenChannel ? 1 : 0) : CreateConstantInput(1.0)), scene);
|
|
40
|
+
return texture.getInternalTexture();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a temporary texture based on the source texture.
|
|
44
|
+
* @param internalTexture The source internal texture
|
|
45
|
+
* @param sourceTexture The source of the new texture's name, and sampler info
|
|
46
|
+
* @returns The new texture
|
|
47
|
+
*/
|
|
48
|
+
function CreateTempTexture(internalTexture, sourceTexture) {
|
|
49
|
+
const tempTexture = new Texture(sourceTexture.name, sourceTexture.getScene());
|
|
50
|
+
tempTexture._texture = internalTexture;
|
|
51
|
+
tempTexture.coordinatesIndex = sourceTexture.coordinatesIndex;
|
|
52
|
+
if (sourceTexture instanceof Texture) {
|
|
53
|
+
tempTexture.uOffset = sourceTexture.uOffset;
|
|
54
|
+
tempTexture.vOffset = sourceTexture.vOffset;
|
|
55
|
+
tempTexture.uScale = sourceTexture.uScale;
|
|
56
|
+
tempTexture.vScale = sourceTexture.vScale;
|
|
57
|
+
tempTexture.wAng = sourceTexture.wAng;
|
|
58
|
+
}
|
|
59
|
+
tempTexture.wrapU = sourceTexture.wrapU;
|
|
60
|
+
tempTexture.wrapV = sourceTexture.wrapV;
|
|
61
|
+
return tempTexture;
|
|
62
|
+
}
|
|
6
63
|
/**
|
|
7
64
|
* @internal
|
|
8
65
|
*/
|
|
@@ -16,9 +73,28 @@ export class KHR_materials_clearcoat {
|
|
|
16
73
|
/** Defines whether this extension is required */
|
|
17
74
|
this.required = false;
|
|
18
75
|
this._wasUsed = false;
|
|
76
|
+
/**
|
|
77
|
+
* Cache that holds temporary merged textures created during export
|
|
78
|
+
*/
|
|
79
|
+
this._mergedTexturesMap = {};
|
|
80
|
+
/**
|
|
81
|
+
* Cache that holds internal textures of merged textures created during export
|
|
82
|
+
*/
|
|
83
|
+
this._cachedInternalTexturesMap = {};
|
|
19
84
|
this._exporter = exporter;
|
|
20
85
|
}
|
|
21
|
-
dispose() {
|
|
86
|
+
dispose() {
|
|
87
|
+
for (const key of Object.keys(this._mergedTexturesMap)) {
|
|
88
|
+
const texture = this._mergedTexturesMap[key];
|
|
89
|
+
texture.dispose();
|
|
90
|
+
}
|
|
91
|
+
this._mergedTexturesMap = {};
|
|
92
|
+
for (const key of Object.keys(this._cachedInternalTexturesMap)) {
|
|
93
|
+
const internalTexture = this._cachedInternalTexturesMap[key];
|
|
94
|
+
internalTexture.dispose();
|
|
95
|
+
}
|
|
96
|
+
this._cachedInternalTexturesMap = {};
|
|
97
|
+
}
|
|
22
98
|
/** @internal */
|
|
23
99
|
get wasUsed() {
|
|
24
100
|
return this._wasUsed;
|
|
@@ -41,15 +117,58 @@ export class KHR_materials_clearcoat {
|
|
|
41
117
|
}
|
|
42
118
|
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
43
119
|
if (babylonMaterial.coatWeight > 0) {
|
|
120
|
+
// We will merge the coat_weight and coat_roughness textures, if needed.
|
|
121
|
+
// However, we want to retain the original texture's transforms and sampling info.
|
|
122
|
+
let coatNeedsMerge = false;
|
|
44
123
|
if (babylonMaterial.coatWeightTexture) {
|
|
45
|
-
|
|
124
|
+
// If we don't have a coat_roughness texture or if the coat_weight and coat_roughness
|
|
125
|
+
// textures are already merged, export them as-is.
|
|
126
|
+
if (!babylonMaterial.coatRoughnessTexture) {
|
|
127
|
+
additionalTextures.push(babylonMaterial.coatWeightTexture);
|
|
128
|
+
}
|
|
129
|
+
else if (babylonMaterial._useCoatRoughnessFromGreenChannel &&
|
|
130
|
+
babylonMaterial.coatWeightTexture.getInternalTexture() === babylonMaterial.coatRoughnessTexture.getInternalTexture()) {
|
|
131
|
+
additionalTextures.push(babylonMaterial.coatWeightTexture);
|
|
132
|
+
additionalTextures.push(babylonMaterial.coatRoughnessTexture);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
coatNeedsMerge = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (babylonMaterial.coatRoughnessTexture) {
|
|
139
|
+
if (babylonMaterial._useCoatRoughnessFromGreenChannel) {
|
|
140
|
+
additionalTextures.push(babylonMaterial.coatRoughnessTexture);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
coatNeedsMerge = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (coatNeedsMerge) {
|
|
147
|
+
// Merge the two textures together but retain the transforms for each.
|
|
148
|
+
// We do this by caching the internal texture that is created during the merge,
|
|
149
|
+
// and then creating temporary textures that use that internal texture but
|
|
150
|
+
// have the original texture's transforms/sampling info.
|
|
151
|
+
const texId = GetCoatTextureId(babylonMaterial);
|
|
152
|
+
if (!this._cachedInternalTexturesMap[texId]) {
|
|
153
|
+
const internalTexture = await CreateMergedCoatInternalTextureAsync(babylonMaterial);
|
|
154
|
+
if (internalTexture) {
|
|
155
|
+
this._cachedInternalTexturesMap[texId] = internalTexture;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (this._cachedInternalTexturesMap[texId]) {
|
|
159
|
+
if (babylonMaterial.coatWeightTexture) {
|
|
160
|
+
this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId] = CreateTempTexture(this._cachedInternalTexturesMap[texId], babylonMaterial.coatWeightTexture);
|
|
161
|
+
additionalTextures.push(this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId]);
|
|
162
|
+
}
|
|
163
|
+
if (babylonMaterial.coatRoughnessTexture) {
|
|
164
|
+
this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId] = CreateTempTexture(this._cachedInternalTexturesMap[texId], babylonMaterial.coatRoughnessTexture);
|
|
165
|
+
additionalTextures.push(this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
46
168
|
}
|
|
47
169
|
if (babylonMaterial.geometryCoatNormalTexture) {
|
|
48
170
|
additionalTextures.push(babylonMaterial.geometryCoatNormalTexture);
|
|
49
171
|
}
|
|
50
|
-
if (babylonMaterial.coatRoughnessTexture) {
|
|
51
|
-
additionalTextures.push(babylonMaterial.coatRoughnessTexture);
|
|
52
|
-
}
|
|
53
172
|
return additionalTextures;
|
|
54
173
|
}
|
|
55
174
|
}
|
|
@@ -99,13 +218,17 @@ export class KHR_materials_clearcoat {
|
|
|
99
218
|
}
|
|
100
219
|
this._wasUsed = true;
|
|
101
220
|
node.extensions = node.extensions || {};
|
|
102
|
-
|
|
103
|
-
let
|
|
104
|
-
if (babylonMaterial.
|
|
105
|
-
|
|
221
|
+
let coatWeightTexture = null;
|
|
222
|
+
let coatTextureInfo;
|
|
223
|
+
if (babylonMaterial.coatWeightTexture) {
|
|
224
|
+
coatWeightTexture = this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId];
|
|
225
|
+
coatTextureInfo = this._exporter._materialExporter.getTextureInfo(coatWeightTexture);
|
|
106
226
|
}
|
|
107
|
-
|
|
108
|
-
|
|
227
|
+
let coatRoughnessTexture = null;
|
|
228
|
+
let coatRoughnessTextureInfo;
|
|
229
|
+
if (babylonMaterial.coatRoughnessTexture) {
|
|
230
|
+
coatRoughnessTexture = this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId];
|
|
231
|
+
coatRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(coatRoughnessTexture);
|
|
109
232
|
}
|
|
110
233
|
if (babylonMaterial.coatColorTexture) {
|
|
111
234
|
Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);
|
|
@@ -113,9 +236,9 @@ export class KHR_materials_clearcoat {
|
|
|
113
236
|
const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryCoatNormalTexture);
|
|
114
237
|
const clearCoatInfo = {
|
|
115
238
|
clearcoatFactor: babylonMaterial.coatWeight,
|
|
116
|
-
clearcoatTexture:
|
|
239
|
+
clearcoatTexture: coatTextureInfo ?? undefined,
|
|
117
240
|
clearcoatRoughnessFactor: babylonMaterial.coatRoughness,
|
|
118
|
-
clearcoatRoughnessTexture:
|
|
241
|
+
clearcoatRoughnessTexture: coatRoughnessTextureInfo ?? undefined,
|
|
119
242
|
clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,
|
|
120
243
|
};
|
|
121
244
|
if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_clearcoat.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,uBAAuB;IAchC,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,yC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;qBAAM,CAAC;oBACJ,6BAA6B,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,cAAc,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC;gBAC1H,CAAC;gBAED,IAAI,eAAe,CAAC,gBAAgB,EAAE,CAAC;oBACnC,KAAK,CAAC,IAAI,CAAC,oEAAoE,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC3G,CAAC;gBAED,MAAM,0BAA0B,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,cAAc,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC;gBAE9H,MAAM,aAAa,GAA2B;oBAC1C,eAAe,EAAE,eAAe,CAAC,UAAU;oBAC3C,gBAAgB,EAAE,oBAAoB,IAAI,SAAS;oBACnD,wBAAwB,EAAE,eAAe,CAAC,aAAa;oBACvD,yBAAyB,EAAE,6BAA6B,IAAI,SAAS;oBACrE,sBAAsB,EAAE,0BAA0B,IAAI,SAAS;iBAClE,CAAC;gBAEF,IAAI,aAAa,CAAC,gBAAgB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,EAAE,CAAC;oBAClJ,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;YAC1C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsClearcoat } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.clearCoat.isEnabled) {\r\n if (babylonMaterial.clearCoat.texture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.texture);\r\n }\r\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\r\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n if (babylonMaterial.clearCoat.bumpTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.coatWeight > 0) {\r\n if (babylonMaterial.coatWeightTexture) {\r\n additionalTextures.push(babylonMaterial.coatWeightTexture);\r\n }\r\n if (babylonMaterial.geometryCoatNormalTexture) {\r\n additionalTextures.push(babylonMaterial.geometryCoatNormalTexture);\r\n }\r\n if (babylonMaterial.coatRoughnessTexture) {\r\n additionalTextures.push(babylonMaterial.coatRoughnessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.clearCoat.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\r\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.coatWeight == 0.0) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.useCoatRoughnessFromWeightTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatRoughnessTexture);\r\n }\r\n\r\n if (babylonMaterial.coatColorTexture) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryCoatNormalTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.coatWeight,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.coatRoughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_materials_clearcoat.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,4DAA8C;AAG7I,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,eAAgC;IACtD,MAAM,WAAW,GAA0B,eAAe,CAAC,iBAAiB,CAAC;IAC7E,MAAM,MAAM,GAAG,WAAW,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,WAAY,CAAC,kBAAkB,EAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxH,MAAM,oBAAoB,GAA0B,eAAe,CAAC,oBAAoB,CAAC;IACzF,MAAM,WAAW,GAAG,oBAAoB,IAAI,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,oBAAqB,CAAC,kBAAkB,EAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC;IAC7J,OAAO,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,o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,GAA2B;oBAC1C,eAAe,EAAE,eAAe,CAAC,UAAU;oBAC3C,gBAAgB,EAAE,eAAe,IAAI,SAAS;oBAC9C,wBAAwB,EAAE,eAAe,CAAC,aAAa;oBACvD,yBAAyB,EAAE,wBAAwB,IAAI,SAAS;oBAChE,sBAAsB,EAAE,0BAA0B,IAAI,SAAS;iBAClE,CAAC;gBAEF,IAAI,aAAa,CAAC,gBAAgB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,EAAE,CAAC;oBAClJ,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;YAC1C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsClearcoat } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\r\n\r\n/**\r\n * Generate a unique ID for the merged coat textures based on the internal texture data.\r\n * This is used for caching merged textures.\r\n * @param babylonMaterial Source OpenPBR material\r\n * @returns A unique ID string for the merged coat textures\r\n * @internal\r\n */\r\nfunction GetCoatTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const coatTexture: Nullable<BaseTexture> = babylonMaterial.coatWeightTexture;\r\n const coatId = coatTexture && coatTexture.getInternalTexture() ? coatTexture!.getInternalTexture()!.uniqueId : \"NoCoat\";\r\n const coatRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessTexture;\r\n const roughnessId = coatRoughnessTexture && coatRoughnessTexture.getInternalTexture() ? coatRoughnessTexture!.getInternalTexture()!.uniqueId : \"NoRoughness\";\r\n return `${coatId}_${roughnessId}`;\r\n}\r\n\r\n/**\r\n * Using the coat weight and coat roughness textures, create a merged internal texture that can be used\r\n * for multiple textures (with potentially different transforms) on export.\r\n * @param babylonMaterial The source OpenPBR material\r\n * @returns A new, internal texture with the coat weight in the red channel and coat roughness in the green channel\r\n * @internal\r\n */\r\nasync function CreateMergedCoatInternalTextureAsync(babylonMaterial: OpenPBRMaterial): Promise<Nullable<InternalTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n const coatTexture: Nullable<BaseTexture> = babylonMaterial.coatWeightTexture;\r\n const coatRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessTexture;\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(coatTexture || coatRoughnessTexture)) {\r\n return null;\r\n }\r\n\r\n const texture = await MergeTexturesAsync(\r\n \"CoatTexture\",\r\n CreateRGBAConfiguration(\r\n coatTexture ? CreateTextureInput(coatTexture, 0) : CreateConstantInput(1.0), // coat weight from red channel\r\n // coat roughness goes in the green channel but may come from red or green channels in the source\r\n coatRoughnessTexture ? CreateTextureInput(coatRoughnessTexture, babylonMaterial._useCoatRoughnessFromGreenChannel ? 1 : 0) : CreateConstantInput(1.0)\r\n ),\r\n scene\r\n );\r\n\r\n return texture.getInternalTexture();\r\n}\r\n\r\n/**\r\n * Creates a temporary texture based on the source texture.\r\n * @param internalTexture The source internal texture\r\n * @param sourceTexture The source of the new texture's name, and sampler info\r\n * @returns The new texture\r\n */\r\nfunction CreateTempTexture(internalTexture: InternalTexture, sourceTexture: BaseTexture): Texture {\r\n const tempTexture = new Texture(sourceTexture.name, sourceTexture.getScene());\r\n tempTexture._texture = internalTexture;\r\n tempTexture.coordinatesIndex = sourceTexture.coordinatesIndex;\r\n if (sourceTexture instanceof Texture) {\r\n tempTexture.uOffset = sourceTexture.uOffset;\r\n tempTexture.vOffset = sourceTexture.vOffset;\r\n tempTexture.uScale = sourceTexture.uScale;\r\n tempTexture.vScale = sourceTexture.vScale;\r\n tempTexture.wAng = sourceTexture.wAng;\r\n }\r\n tempTexture.wrapU = sourceTexture.wrapU;\r\n tempTexture.wrapV = sourceTexture.wrapV;\r\n return tempTexture;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /**\r\n * Cache that holds temporary merged textures created during export\r\n */\r\n private _mergedTexturesMap: Record<string, BaseTexture> = {};\r\n\r\n /**\r\n * Cache that holds internal textures of merged textures created during export\r\n */\r\n private _cachedInternalTexturesMap: Record<string, InternalTexture> = {};\r\n\r\n public dispose() {\r\n for (const key of Object.keys(this._mergedTexturesMap)) {\r\n const texture = this._mergedTexturesMap[key];\r\n texture.dispose();\r\n }\r\n this._mergedTexturesMap = {};\r\n for (const key of Object.keys(this._cachedInternalTexturesMap)) {\r\n const internalTexture = this._cachedInternalTexturesMap[key];\r\n internalTexture.dispose();\r\n }\r\n this._cachedInternalTexturesMap = {};\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.clearCoat.isEnabled) {\r\n if (babylonMaterial.clearCoat.texture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.texture);\r\n }\r\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\r\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n if (babylonMaterial.clearCoat.bumpTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.coatWeight > 0) {\r\n // We will merge the coat_weight and coat_roughness textures, if needed.\r\n // However, we want to retain the original texture's transforms and sampling info.\r\n let coatNeedsMerge = false;\r\n if (babylonMaterial.coatWeightTexture) {\r\n // If we don't have a coat_roughness texture or if the coat_weight and coat_roughness\r\n // textures are already merged, export them as-is.\r\n if (!babylonMaterial.coatRoughnessTexture) {\r\n additionalTextures.push(babylonMaterial.coatWeightTexture);\r\n } else if (\r\n babylonMaterial._useCoatRoughnessFromGreenChannel &&\r\n babylonMaterial.coatWeightTexture.getInternalTexture() === babylonMaterial.coatRoughnessTexture.getInternalTexture()\r\n ) {\r\n additionalTextures.push(babylonMaterial.coatWeightTexture);\r\n additionalTextures.push(babylonMaterial.coatRoughnessTexture);\r\n } else {\r\n coatNeedsMerge = true;\r\n }\r\n } else if (babylonMaterial.coatRoughnessTexture) {\r\n if (babylonMaterial._useCoatRoughnessFromGreenChannel) {\r\n additionalTextures.push(babylonMaterial.coatRoughnessTexture);\r\n } else {\r\n coatNeedsMerge = true;\r\n }\r\n }\r\n if (coatNeedsMerge) {\r\n // Merge the two textures together but retain the transforms for each.\r\n // We do this by caching the internal texture that is created during the merge,\r\n // and then creating temporary textures that use that internal texture but\r\n // have the original texture's transforms/sampling info.\r\n const texId = GetCoatTextureId(babylonMaterial);\r\n if (!this._cachedInternalTexturesMap[texId]) {\r\n const internalTexture = await CreateMergedCoatInternalTextureAsync(babylonMaterial);\r\n if (internalTexture) {\r\n this._cachedInternalTexturesMap[texId] = internalTexture;\r\n }\r\n }\r\n if (this._cachedInternalTexturesMap[texId]) {\r\n if (babylonMaterial.coatWeightTexture) {\r\n this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.coatWeightTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId]);\r\n }\r\n if (babylonMaterial.coatRoughnessTexture) {\r\n this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.coatRoughnessTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId]);\r\n }\r\n }\r\n }\r\n\r\n if (babylonMaterial.geometryCoatNormalTexture) {\r\n additionalTextures.push(babylonMaterial.geometryCoatNormalTexture);\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.clearCoat.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\r\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.coatWeight == 0.0) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n let coatWeightTexture: Nullable<BaseTexture> = null;\r\n let coatTextureInfo;\r\n if (babylonMaterial.coatWeightTexture) {\r\n coatWeightTexture = this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId];\r\n coatTextureInfo = this._exporter._materialExporter.getTextureInfo(coatWeightTexture);\r\n }\r\n\r\n let coatRoughnessTexture: Nullable<BaseTexture> = null;\r\n let coatRoughnessTextureInfo;\r\n if (babylonMaterial.coatRoughnessTexture) {\r\n coatRoughnessTexture = this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId];\r\n coatRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(coatRoughnessTexture);\r\n }\r\n\r\n if (babylonMaterial.coatColorTexture) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryCoatNormalTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.coatWeight,\r\n clearcoatTexture: coatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.coatRoughness,\r\n clearcoatRoughnessTexture: coatRoughnessTextureInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));\r\n"]}
|
package/glTF/2.0/Extensions/{KHR_materials_clearcoat_darkening.d.ts → KHR_materials_coat.d.ts}
RENAMED
|
@@ -6,9 +6,9 @@ import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class KHR_materials_coat implements IGLTFExporterExtensionV2 {
|
|
10
10
|
/** Name of this extension */
|
|
11
|
-
readonly name = "
|
|
11
|
+
readonly name = "KHR_materials_coat";
|
|
12
12
|
/** Defines whether this extension is enabled */
|
|
13
13
|
enabled: boolean;
|
|
14
14
|
/** Defines whether this extension is required */
|
|
@@ -16,6 +16,14 @@ export declare class KHR_materials_clearcoat_darkening implements IGLTFExporterE
|
|
|
16
16
|
private _exporter;
|
|
17
17
|
private _wasUsed;
|
|
18
18
|
constructor(exporter: GLTFExporter);
|
|
19
|
+
/**
|
|
20
|
+
* Cache that holds temporary merged textures created during export
|
|
21
|
+
*/
|
|
22
|
+
private _mergedTexturesMap;
|
|
23
|
+
/**
|
|
24
|
+
* Cache that holds internal textures of merged textures created during export
|
|
25
|
+
*/
|
|
26
|
+
private _cachedInternalTexturesMap;
|
|
19
27
|
dispose(): void;
|
|
20
28
|
/** @internal */
|
|
21
29
|
get wasUsed(): boolean;
|