diff --git a/libraries/baking/src/FBXBaker.h b/libraries/baking/src/FBXBaker.h index 3c95273f8f..257efbe983 100644 --- a/libraries/baking/src/FBXBaker.h +++ b/libraries/baking/src/FBXBaker.h @@ -43,7 +43,6 @@ private: void replaceMeshNodeWithDraco(FBXNode& meshNode, const QByteArray& dracoMeshBytes, const std::vector& dracoMaterialList); hfm::Model::Pointer _hfmModel; - QHash _textureNameMatchCount; QHash _remappedTexturePaths; bool _pendingErrorEmission { false }; diff --git a/libraries/baking/src/ModelBaker.cpp b/libraries/baking/src/ModelBaker.cpp index d906abca8f..77584beb1b 100644 --- a/libraries/baking/src/ModelBaker.cpp +++ b/libraries/baking/src/ModelBaker.cpp @@ -417,10 +417,7 @@ QString ModelBaker::compressTexture(QString modelTextureFileName, image::Texture // construct the new baked texture file name and file path // ensuring that the baked texture will have a unique name // even if there was another texture with the same name at a different path - baseTextureFileName = createBaseTextureFileName(modelTextureFileInfo); - // If two textures have the same URL but are used differently, we need to process them separately - QString addMapChannel = QString::fromStdString("_" + std::to_string(textureType)); - baseTextureFileName += addMapChannel; + baseTextureFileName = createBaseTextureFileName(modelTextureFileInfo, textureType); _remappedTexturePaths[urlToTexture] = baseTextureFileName; } @@ -631,12 +628,15 @@ void ModelBaker::checkIfTexturesFinished() { } } -QString ModelBaker::createBaseTextureFileName(const QFileInfo& textureFileInfo) { +QString ModelBaker::createBaseTextureFileName(const QFileInfo& textureFileInfo, const image::TextureUsage::Type textureType) { + // If two textures have the same URL but are used differently, we need to process them separately + QString addMapChannel = QString::fromStdString("_" + std::to_string(textureType)); + + QString baseTextureFileName{ textureFileInfo.completeBaseName() + addMapChannel }; + // first make sure we have a unique base name for this texture // in case another texture referenced by this model has the same base name - auto& nameMatches = _textureNameMatchCount[textureFileInfo.baseName()]; - - QString baseTextureFileName{ textureFileInfo.completeBaseName() }; + auto& nameMatches = _textureNameMatchCount[baseTextureFileName]; if (nameMatches > 0) { // there are already nameMatches texture with this name diff --git a/libraries/baking/src/ModelBaker.h b/libraries/baking/src/ModelBaker.h index f1ef6db56d..6ee7511ce3 100644 --- a/libraries/baking/src/ModelBaker.h +++ b/libraries/baking/src/ModelBaker.h @@ -97,7 +97,7 @@ private slots: void handleAbortedTexture(); private: - QString createBaseTextureFileName(const QFileInfo & textureFileInfo); + QString createBaseTextureFileName(const QFileInfo & textureFileInfo, const image::TextureUsage::Type textureType); QUrl getTextureURL(const QFileInfo& textureFileInfo, QString relativeFileName, bool isEmbedded = false); void bakeTexture(const QUrl & textureURL, image::TextureUsage::Type textureType, const QDir & outputDir, const QString & bakedFilename, const QByteArray & textureContent);