Fix ModelBaker not properly checking if texture file name exists

This commit is contained in:
sabrina-shanman 2019-03-13 17:26:02 -07:00
parent 27c7bf5c92
commit 5b75eb34e8
3 changed files with 9 additions and 10 deletions

View file

@ -43,7 +43,6 @@ private:
void replaceMeshNodeWithDraco(FBXNode& meshNode, const QByteArray& dracoMeshBytes, const std::vector<hifi::ByteArray>& dracoMaterialList);
hfm::Model::Pointer _hfmModel;
QHash<QString, int> _textureNameMatchCount;
QHash<QUrl, QString> _remappedTexturePaths;
bool _pendingErrorEmission { false };

View file

@ -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

View file

@ -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);