@onerjs/serializers 8.42.7 → 8.42.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_coat.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_coat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,sDAA2C;AAErE,OAAO,EAAE,eAAe,EAAE,sDAA2C;AACrE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,yDAA8C;AAC7I,OAAO,EAAE,OAAO,EAAE,mDAAwC;AAI1D,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAElC,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;;;;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ACvC,QAAQ,CAAC,gBAAgB,KAAK,IAAI,EACpC,CAAC;oBACC,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;YACrC,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,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsCoat } 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\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\n\r\nconst NAME = \"KHR_materials_coat\";\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.coatRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryCoatTangentTexture;\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/**\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 * Creates a new texture with the anisotropy data merged together for export.\r\n * @param babylonMaterial The source OpenPBR material\r\n * @returns A new texture with the merged anisotropy data\r\n * @internal\r\n */\r\nasync function CreateMergedAnisotropyTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<BaseTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryCoatTangentTexture;\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 * 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_coat 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 if (babylonMaterial.clearCoat.tintTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.tintTexture);\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 if (babylonMaterial.coatColorTexture) {\r\n additionalTextures.push(babylonMaterial.coatColorTexture);\r\n }\r\n if (babylonMaterial.coatRoughnessAnisotropy > 0) {\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n if (this._mergedTexturesMap[texId]) {\r\n additionalTextures.push(this._mergedTexturesMap[texId]);\r\n } else {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._mergedTexturesMap[texId] = anisoTexture;\r\n }\r\n }\r\n return additionalTextures;\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 coatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let coatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n coatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n coatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n let coatColorTextureInfo;\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.tintTexture);\r\n }\r\n\r\n const coatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n const coatIor: number = babylonMaterial.clearCoat.indexOfRefraction;\r\n\r\n const coatInfo: IKHRMaterialsCoat = {\r\n coatFactor: babylonMaterial.clearCoat.intensity,\r\n coatTexture: coatTextureInfo ?? undefined,\r\n coatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n coatRoughnessTexture: coatTextureRoughnessInfo ?? undefined,\r\n coatNormalTexture: coatNormalTextureInfo ?? undefined,\r\n coatColorFactor: babylonMaterial.clearCoat.tintColor.asArray(),\r\n coatColorTexture: coatColorTextureInfo ?? undefined,\r\n coatIor: coatIor !== 1.5 ? coatIor : undefined,\r\n };\r\n\r\n if (coatInfo.coatTexture !== null || coatInfo.coatRoughnessTexture !== null || coatInfo.coatRoughnessTexture !== null || coatInfo.coatColorTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = coatInfo;\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 if (this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId]) {\r\n coatWeightTexture = this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId];\r\n } else {\r\n coatWeightTexture = babylonMaterial.coatWeightTexture;\r\n }\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 if (this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId]) {\r\n coatRoughnessTexture = this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId];\r\n } else {\r\n coatRoughnessTexture = babylonMaterial.coatRoughnessTexture;\r\n }\r\n coatRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(coatRoughnessTexture);\r\n }\r\n\r\n const coatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryCoatNormalTexture);\r\n const coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatColorTexture);\r\n const coatIor: number = babylonMaterial.coatIor;\r\n const coatDarkeningFactor = babylonMaterial.coatDarkening;\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 const roughnessTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessTexture;\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n const mergedAnisoTexture = this._mergedTexturesMap[texId];\r\n let coatAnisotropyStrength = 0;\r\n let coatAnisotropyRotation = 0;\r\n let coatAnisotropyTexture = undefined;\r\n if (babylonMaterial.coatRoughnessAnisotropy > 0.0) {\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.coatRoughness;\r\n let newAnisotropyStrength = babylonMaterial.coatRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.coatRoughness, babylonMaterial.coatRoughnessAnisotropy);\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 coatAnisotropyStrength = newAnisotropyStrength;\r\n coatAnisotropyRotation = babylonMaterial.geometryCoatTangentAngle + Math.PI * 0.5;\r\n coatAnisotropyTexture = undefined;\r\n } else {\r\n const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;\r\n\r\n coatAnisotropyStrength = babylonMaterial.coatRoughnessAnisotropy;\r\n coatAnisotropyRotation = babylonMaterial.geometryCoatTangentAngle;\r\n coatAnisotropyTexture = mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined;\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\r\n const coatInfo: IKHRMaterialsCoat = {\r\n coatFactor: babylonMaterial.coatWeight,\r\n coatTexture: coatTextureInfo ?? undefined,\r\n coatRoughnessFactor: babylonMaterial.coatRoughness,\r\n coatRoughnessTexture: coatRoughnessTextureInfo ?? undefined,\r\n coatNormalTexture: coatNormalTextureInfo ?? undefined,\r\n coatColorFactor: babylonMaterial.coatColor.asArray(),\r\n coatColorTexture: coatColorTextureInfo ?? undefined,\r\n coatIor: coatIor !== 1.5 ? coatIor : undefined,\r\n coatDarkeningFactor: coatDarkeningFactor !== 1.0 ? coatDarkeningFactor : undefined,\r\n coatAnisotropyRotation: coatAnisotropyRotation,\r\n coatAnisotropyStrength: coatAnisotropyStrength,\r\n coatAnisotropyTexture: coatAnisotropyTexture,\r\n };\r\n\r\n if (\r\n coatInfo.coatTexture !== null ||\r\n coatInfo.coatRoughnessTexture !== null ||\r\n coatInfo.coatRoughnessTexture !== null ||\r\n coatInfo.coatAnisotropyTexture !== null ||\r\n coatInfo.coatColorTexture !== null\r\n ) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = coatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_coat(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_materials_coat.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_coat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAA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CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsCoat } 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\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\n\r\nconst NAME = \"KHR_materials_coat\";\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.coatRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryCoatTangentTexture;\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/**\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 * Creates a new texture with the anisotropy data merged together for export.\r\n * @param babylonMaterial The source OpenPBR material\r\n * @returns A new texture with the merged anisotropy data\r\n * @internal\r\n */\r\nasync function CreateMergedAnisotropyTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<BaseTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryCoatTangentTexture;\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 * 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_coat 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 if (babylonMaterial.clearCoat.tintTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.tintTexture);\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 if (babylonMaterial.coatColorTexture) {\r\n additionalTextures.push(babylonMaterial.coatColorTexture);\r\n }\r\n if (babylonMaterial.coatRoughnessAnisotropy > 0) {\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n if (this._mergedTexturesMap[texId]) {\r\n additionalTextures.push(this._mergedTexturesMap[texId]);\r\n } else {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._mergedTexturesMap[texId] = anisoTexture;\r\n }\r\n }\r\n return additionalTextures;\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 coatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let coatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n coatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n coatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n let coatColorTextureInfo;\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.tintTexture);\r\n }\r\n\r\n const coatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n const coatIor: number = babylonMaterial.clearCoat.indexOfRefraction;\r\n\r\n const coatInfo: IKHRMaterialsCoat = {\r\n coatFactor: babylonMaterial.clearCoat.intensity,\r\n coatTexture: coatTextureInfo ?? undefined,\r\n coatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n coatRoughnessTexture: coatTextureRoughnessInfo ?? undefined,\r\n coatNormalTexture: coatNormalTextureInfo ?? undefined,\r\n coatColorFactor: babylonMaterial.clearCoat.tintColor.asArray(),\r\n coatColorTexture: coatColorTextureInfo ?? undefined,\r\n coatIor: coatIor !== 1.5 ? coatIor : undefined,\r\n };\r\n\r\n if (coatInfo.coatTexture !== null || coatInfo.coatRoughnessTexture !== null || coatInfo.coatRoughnessTexture !== null || coatInfo.coatColorTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = coatInfo;\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>;\r\n let coatTextureInfo;\r\n if (babylonMaterial.coatWeightTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId]) {\r\n coatWeightTexture = this._mergedTexturesMap[babylonMaterial.coatWeightTexture.uniqueId];\r\n } else {\r\n coatWeightTexture = babylonMaterial.coatWeightTexture;\r\n }\r\n coatTextureInfo = this._exporter._materialExporter.getTextureInfo(coatWeightTexture);\r\n }\r\n\r\n let coatRoughnessTexture: Nullable<BaseTexture>;\r\n let coatRoughnessTextureInfo;\r\n if (babylonMaterial.coatRoughnessTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId]) {\r\n coatRoughnessTexture = this._mergedTexturesMap[babylonMaterial.coatRoughnessTexture.uniqueId];\r\n } else {\r\n coatRoughnessTexture = babylonMaterial.coatRoughnessTexture;\r\n }\r\n coatRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(coatRoughnessTexture);\r\n }\r\n\r\n const coatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryCoatNormalTexture);\r\n const coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatColorTexture);\r\n const coatIor: number = babylonMaterial.coatIor;\r\n const coatDarkeningFactor = babylonMaterial.coatDarkening;\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 const roughnessTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessTexture;\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n const mergedAnisoTexture = this._mergedTexturesMap[texId];\r\n let coatAnisotropyStrength = 0;\r\n let coatAnisotropyRotation = 0;\r\n let coatAnisotropyTexture = undefined;\r\n if (babylonMaterial.coatRoughnessAnisotropy > 0.0) {\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.coatRoughness;\r\n let newAnisotropyStrength = babylonMaterial.coatRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.coatRoughness, babylonMaterial.coatRoughnessAnisotropy);\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 coatAnisotropyStrength = newAnisotropyStrength;\r\n coatAnisotropyRotation = babylonMaterial.geometryCoatTangentAngle + Math.PI * 0.5;\r\n coatAnisotropyTexture = undefined;\r\n } else {\r\n const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;\r\n\r\n coatAnisotropyStrength = babylonMaterial.coatRoughnessAnisotropy;\r\n coatAnisotropyRotation = babylonMaterial.geometryCoatTangentAngle;\r\n coatAnisotropyTexture = mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined;\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\r\n const coatInfo: IKHRMaterialsCoat = {\r\n coatFactor: babylonMaterial.coatWeight,\r\n coatTexture: coatTextureInfo ?? undefined,\r\n coatRoughnessFactor: babylonMaterial.coatRoughness,\r\n coatRoughnessTexture: coatRoughnessTextureInfo ?? undefined,\r\n coatNormalTexture: coatNormalTextureInfo ?? undefined,\r\n coatColorFactor: babylonMaterial.coatColor.asArray(),\r\n coatColorTexture: coatColorTextureInfo ?? undefined,\r\n coatIor: coatIor !== 1.5 ? coatIor : undefined,\r\n coatDarkeningFactor: coatDarkeningFactor !== 1.0 ? coatDarkeningFactor : undefined,\r\n coatAnisotropyRotation: coatAnisotropyRotation,\r\n coatAnisotropyStrength: coatAnisotropyStrength,\r\n coatAnisotropyTexture: coatAnisotropyTexture,\r\n };\r\n\r\n if (\r\n coatInfo.coatTexture !== null ||\r\n coatInfo.coatRoughnessTexture !== null ||\r\n coatInfo.coatRoughnessTexture !== null ||\r\n coatInfo.coatAnisotropyTexture !== null ||\r\n coatInfo.coatColorTexture !== null\r\n ) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = coatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_coat(exporter));\r\n"]}
@@ -161,7 +161,7 @@ export class KHR_materials_fuzz {
161
161
  if (babylonMaterial.fuzzWeightTexture) {
162
162
  fuzzInfo.fuzzTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.fuzzWeightTexture) ?? undefined;
163
163
  }
164
- let fuzzColorTexture = null;
164
+ let fuzzColorTexture;
165
165
  if (babylonMaterial.fuzzColorTexture) {
166
166
  if (this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]) {
167
167
  fuzzColorTexture = this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId];
@@ -171,7 +171,7 @@ export class KHR_materials_fuzz {
171
171
  }
172
172
  fuzzInfo.fuzzColorTexture = this._exporter._materialExporter.getTextureInfo(fuzzColorTexture) ?? undefined;
173
173
  }
174
- let fuzzRoughnessTexture = null;
174
+ let fuzzRoughnessTexture;
175
175
  if (babylonMaterial.fuzzRoughnessTexture) {
176
176
  if (this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]) {
177
177
  fuzzRoughnessTexture = this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId];
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_fuzz.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_fuzz.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,sDAA2C;AACrE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,yDAA8C;AAI7I,OAAO,EAAE,OAAO,EAAE,mDAAwC;AAE1D,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,eAAgC;IAC3D,MAAM,gBAAgB,GAA0B,eAAe,CAAC,gBAAgB,CAAC;IACjF,MAAM,WAAW,GAAG,gBAAgB,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,gBAAiB,CAAC,kBAAkB,EAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC;IACjJ,MAAM,oBAAoB,GAA0B,eAAe,CAAC,oBAAoB,CAAC;IACzF,MAAM,eAAe,GAAG,oBAAoB,IAAI,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,oBAAqB,CAAC,kBAAkB,EAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACrK,OAAO,aAAa,WAAW,kBAAkB,eAAe,EAAE,CAAC;AACvE,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,+BA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,CAAC,eAAe,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;wBACzE,oBAAoB,GAAG,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;oBAClG,CAAC;yBAAM,CAAC;wBACJ,oBAAoB,GAAG,eAAe,CAAC,oBAAoB,CAAC;oBAChE,CAAC;oBACD,QAAQ,CAAC,oBAAoB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,cAAc,CAAC,oBAAoB,CAAC,IAAI,SAAS,CAAC;gBACvH,CAAC;gBAED,IAAI,QAAQ,CAAC,gBAAgB,KAAK,IAAI,IAAI,QAAQ,CAAC,oBAAoB,KAAK,IAAI,EAAE,CAAC;oBAC/E,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;YACrC,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,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsFuzz } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\n\r\nconst NAME = \"KHR_materials_fuzz\";\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 GetFuzzColorTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const fuzzColorTexture: Nullable<BaseTexture> = babylonMaterial.fuzzColorTexture;\r\n const fuzzColorId = fuzzColorTexture && fuzzColorTexture.getInternalTexture() ? fuzzColorTexture!.getInternalTexture()!.uniqueId : \"NoFuzzColor\";\r\n const fuzzRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.fuzzRoughnessTexture;\r\n const fuzzRoughnessId = fuzzRoughnessTexture && fuzzRoughnessTexture.getInternalTexture() ? fuzzRoughnessTexture!.getInternalTexture()!.uniqueId : \"NoFuzzRoughness\";\r\n return `FuzzColor_${fuzzColorId}_FuzzRoughness_${fuzzRoughnessId}`;\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 CreateMergedFuzzInternalTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<InternalTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n const fuzzColorTexture: Nullable<BaseTexture> = babylonMaterial.fuzzColorTexture;\r\n const fuzzRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.fuzzRoughnessTexture;\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(fuzzColorTexture || fuzzRoughnessTexture)) {\r\n return null;\r\n }\r\n\r\n const texture = await MergeTexturesAsync(\r\n \"FuzzTexture\",\r\n CreateRGBAConfiguration(\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 0) : CreateConstantInput(1.0), // fuzz color from red channel\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 1) : CreateConstantInput(1.0), // fuzz color from green channel\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 2) : CreateConstantInput(1.0), // fuzz color from blue channel\r\n // fuzz roughness goes in the alpha channel but may come from red or alpha channels in the source\r\n fuzzRoughnessTexture ? CreateTextureInput(fuzzRoughnessTexture, babylonMaterial._useFuzzRoughnessFromTextureAlpha ? 3 : 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_fuzz 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 _wasUsed = false;\r\n\r\n private _exporter: GLTFExporter;\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 if (babylonMaterial instanceof OpenPBRMaterial) {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial.fuzzWeight > 0.0) {\r\n if (babylonMaterial.fuzzWeightTexture) {\r\n additionalTextures.push(babylonMaterial.fuzzWeightTexture);\r\n }\r\n let fuzzTexturesNeedMerge = false;\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n if (babylonMaterial._useFuzzRoughnessFromTextureAlpha) {\r\n additionalTextures.push(babylonMaterial.fuzzRoughnessTexture);\r\n } else {\r\n fuzzTexturesNeedMerge = true;\r\n }\r\n }\r\n if (babylonMaterial.fuzzColorTexture && !fuzzTexturesNeedMerge) {\r\n additionalTextures.push(babylonMaterial.fuzzColorTexture);\r\n }\r\n if (fuzzTexturesNeedMerge) {\r\n const texId = GetFuzzColorTextureId(babylonMaterial);\r\n if (!this._cachedInternalTexturesMap[texId]) {\r\n const mergedInternalTexture = await CreateMergedFuzzInternalTexture(babylonMaterial);\r\n if (mergedInternalTexture) {\r\n this._cachedInternalTexturesMap[texId] = mergedInternalTexture;\r\n }\r\n }\r\n if (this._cachedInternalTexturesMap[texId]) {\r\n if (babylonMaterial.fuzzColorTexture) {\r\n this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.fuzzColorTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]);\r\n }\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.fuzzRoughnessTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]);\r\n }\r\n }\r\n }\r\n }\r\n return additionalTextures;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public async postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return await new Promise((resolve) => {\r\n if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.fuzzWeight == 0.0) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n const fuzzInfo: IKHRMaterialsFuzz = {\r\n fuzzFactor: babylonMaterial.fuzzWeight,\r\n fuzzColorFactor: babylonMaterial.fuzzColor.asArray(),\r\n fuzzRoughnessFactor: babylonMaterial.fuzzRoughness,\r\n };\r\n\r\n if (babylonMaterial.fuzzWeightTexture) {\r\n fuzzInfo.fuzzTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.fuzzWeightTexture) ?? undefined;\r\n }\r\n\r\n let fuzzColorTexture: Nullable<BaseTexture> = null;\r\n if (babylonMaterial.fuzzColorTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]) {\r\n fuzzColorTexture = this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId];\r\n } else {\r\n fuzzColorTexture = babylonMaterial.fuzzColorTexture;\r\n }\r\n fuzzInfo.fuzzColorTexture = this._exporter._materialExporter.getTextureInfo(fuzzColorTexture) ?? undefined;\r\n }\r\n\r\n let fuzzRoughnessTexture: Nullable<BaseTexture> = null;\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]) {\r\n fuzzRoughnessTexture = this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId];\r\n } else {\r\n fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;\r\n }\r\n fuzzInfo.fuzzRoughnessTexture = this._exporter._materialExporter.getTextureInfo(fuzzRoughnessTexture) ?? undefined;\r\n }\r\n\r\n if (fuzzInfo.fuzzColorTexture !== null || fuzzInfo.fuzzRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = fuzzInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_fuzz(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_materials_fuzz.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_fuzz.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,sDAA2C;AACrE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,yDAA8C;AAI7I,OAAO,EAAE,OAAO,EAAE,mDAAwC;AAE1D,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,eAAgC;IAC3D,MAAM,gBAAgB,GAA0B,eAAe,CAAC,gBAAgB,CAAC;IACjF,MAAM,WAAW,GAAG,gBAA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AC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsFuzz } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\n\r\nconst NAME = \"KHR_materials_fuzz\";\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 GetFuzzColorTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const fuzzColorTexture: Nullable<BaseTexture> = babylonMaterial.fuzzColorTexture;\r\n const fuzzColorId = fuzzColorTexture && fuzzColorTexture.getInternalTexture() ? fuzzColorTexture!.getInternalTexture()!.uniqueId : \"NoFuzzColor\";\r\n const fuzzRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.fuzzRoughnessTexture;\r\n const fuzzRoughnessId = fuzzRoughnessTexture && fuzzRoughnessTexture.getInternalTexture() ? fuzzRoughnessTexture!.getInternalTexture()!.uniqueId : \"NoFuzzRoughness\";\r\n return `FuzzColor_${fuzzColorId}_FuzzRoughness_${fuzzRoughnessId}`;\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 CreateMergedFuzzInternalTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<InternalTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n const fuzzColorTexture: Nullable<BaseTexture> = babylonMaterial.fuzzColorTexture;\r\n const fuzzRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.fuzzRoughnessTexture;\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(fuzzColorTexture || fuzzRoughnessTexture)) {\r\n return null;\r\n }\r\n\r\n const texture = await MergeTexturesAsync(\r\n \"FuzzTexture\",\r\n CreateRGBAConfiguration(\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 0) : CreateConstantInput(1.0), // fuzz color from red channel\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 1) : CreateConstantInput(1.0), // fuzz color from green channel\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 2) : CreateConstantInput(1.0), // fuzz color from blue channel\r\n // fuzz roughness goes in the alpha channel but may come from red or alpha channels in the source\r\n fuzzRoughnessTexture ? CreateTextureInput(fuzzRoughnessTexture, babylonMaterial._useFuzzRoughnessFromTextureAlpha ? 3 : 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_fuzz 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 _wasUsed = false;\r\n\r\n private _exporter: GLTFExporter;\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 if (babylonMaterial instanceof OpenPBRMaterial) {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial.fuzzWeight > 0.0) {\r\n if (babylonMaterial.fuzzWeightTexture) {\r\n additionalTextures.push(babylonMaterial.fuzzWeightTexture);\r\n }\r\n let fuzzTexturesNeedMerge = false;\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n if (babylonMaterial._useFuzzRoughnessFromTextureAlpha) {\r\n additionalTextures.push(babylonMaterial.fuzzRoughnessTexture);\r\n } else {\r\n fuzzTexturesNeedMerge = true;\r\n }\r\n }\r\n if (babylonMaterial.fuzzColorTexture && !fuzzTexturesNeedMerge) {\r\n additionalTextures.push(babylonMaterial.fuzzColorTexture);\r\n }\r\n if (fuzzTexturesNeedMerge) {\r\n const texId = GetFuzzColorTextureId(babylonMaterial);\r\n if (!this._cachedInternalTexturesMap[texId]) {\r\n const mergedInternalTexture = await CreateMergedFuzzInternalTexture(babylonMaterial);\r\n if (mergedInternalTexture) {\r\n this._cachedInternalTexturesMap[texId] = mergedInternalTexture;\r\n }\r\n }\r\n if (this._cachedInternalTexturesMap[texId]) {\r\n if (babylonMaterial.fuzzColorTexture) {\r\n this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.fuzzColorTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]);\r\n }\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.fuzzRoughnessTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]);\r\n }\r\n }\r\n }\r\n }\r\n return additionalTextures;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public async postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return await new Promise((resolve) => {\r\n if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.fuzzWeight == 0.0) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n const fuzzInfo: IKHRMaterialsFuzz = {\r\n fuzzFactor: babylonMaterial.fuzzWeight,\r\n fuzzColorFactor: babylonMaterial.fuzzColor.asArray(),\r\n fuzzRoughnessFactor: babylonMaterial.fuzzRoughness,\r\n };\r\n\r\n if (babylonMaterial.fuzzWeightTexture) {\r\n fuzzInfo.fuzzTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.fuzzWeightTexture) ?? undefined;\r\n }\r\n\r\n let fuzzColorTexture: Nullable<BaseTexture>;\r\n if (babylonMaterial.fuzzColorTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]) {\r\n fuzzColorTexture = this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId];\r\n } else {\r\n fuzzColorTexture = babylonMaterial.fuzzColorTexture;\r\n }\r\n fuzzInfo.fuzzColorTexture = this._exporter._materialExporter.getTextureInfo(fuzzColorTexture) ?? undefined;\r\n }\r\n\r\n let fuzzRoughnessTexture: Nullable<BaseTexture>;\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]) {\r\n fuzzRoughnessTexture = this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId];\r\n } else {\r\n fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;\r\n }\r\n fuzzInfo.fuzzRoughnessTexture = this._exporter._materialExporter.getTextureInfo(fuzzRoughnessTexture) ?? undefined;\r\n }\r\n\r\n if (fuzzInfo.fuzzColorTexture !== null || fuzzInfo.fuzzRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = fuzzInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_fuzz(exporter));\r\n"]}
@@ -361,7 +361,7 @@ export class _GLTFAnimation {
361
361
  */
362
362
  if (morphAnimationChannels) {
363
363
  let index = 0;
364
- let currentInput = 0;
364
+ let currentInput;
365
365
  const newInputs = [];
366
366
  while (animationData.inputs.length > 0) {
367
367
  currentInput = animationData.inputs.shift();
@@ -464,14 +464,13 @@ export class _GLTFAnimation {
464
464
  let previousTime = null;
465
465
  let time;
466
466
  let maxUsedFrame = null;
467
- let currKeyFrame = null;
468
- let nextKeyFrame = null;
469
- let prevKeyFrame = null;
470
- let endFrame = null;
467
+ let currKeyFrame;
468
+ let nextKeyFrame;
469
+ let prevKeyFrame;
470
+ let endFrame;
471
471
  minMaxFrames.min = Tools.FloatRound(minFrame / fps);
472
472
  const keyFrames = animation.getKeys();
473
473
  for (let i = 0, length = keyFrames.length; i < length; ++i) {
474
- endFrame = null;
475
474
  currKeyFrame = keyFrames[i];
476
475
  if (i + 1 < length) {
477
476
  nextKeyFrame = keyFrames[i + 1];