mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 18:15:49 +02:00
Make material baking output unique textures per usage like model baking does
This commit is contained in:
parent
c8209aa976
commit
c54b23f647
6 changed files with 73 additions and 25 deletions
libraries/baking/src
|
@ -129,8 +129,10 @@ void MaterialBaker::processMaterial() {
|
|||
|
||||
QPair<QUrl, image::TextureUsage::Type> textureKey(textureURL, it->second);
|
||||
if (!_textureBakers.contains(textureKey)) {
|
||||
auto baseTextureFileName = _textureFileNamer.createBaseTextureFileName(textureURL.fileName(), it->second);
|
||||
|
||||
QSharedPointer<TextureBaker> textureBaker {
|
||||
new TextureBaker(textureURL, it->second, _textureOutputDir),
|
||||
new TextureBaker(textureURL, it->second, _textureOutputDir, "", baseTextureFileName),
|
||||
&TextureBaker::deleteLater
|
||||
};
|
||||
textureBaker->setMapChannel(mapChannel);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "Baker.h"
|
||||
|
||||
#include "TextureBaker.h"
|
||||
#include "baking/TextureFileNamer.h"
|
||||
|
||||
#include <material-networking/MaterialCache.h>
|
||||
|
||||
|
@ -60,6 +61,7 @@ private:
|
|||
|
||||
QScriptEngine _scriptEngine;
|
||||
static std::function<QThread*()> _getNextOvenWorkerThreadOperator;
|
||||
TextureFileNamer _textureFileNamer;
|
||||
};
|
||||
|
||||
#endif // !hifi_MaterialBaker_h
|
||||
|
|
|
@ -417,7 +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, textureType);
|
||||
baseTextureFileName = _textureFileNamer.createBaseTextureFileName(modelTextureFileInfo, textureType);
|
||||
_remappedTexturePaths[urlToTexture] = baseTextureFileName;
|
||||
}
|
||||
|
||||
|
@ -628,28 +628,6 @@ void ModelBaker::checkIfTexturesFinished() {
|
|||
}
|
||||
}
|
||||
|
||||
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[baseTextureFileName];
|
||||
|
||||
if (nameMatches > 0) {
|
||||
// there are already nameMatches texture with this name
|
||||
// append - and that number to our baked texture file name so that it is unique
|
||||
baseTextureFileName += "-" + QString::number(nameMatches);
|
||||
}
|
||||
|
||||
// increment the number of name matches
|
||||
++nameMatches;
|
||||
|
||||
return baseTextureFileName;
|
||||
}
|
||||
|
||||
void ModelBaker::setWasAborted(bool wasAborted) {
|
||||
if (wasAborted != _wasAborted.load()) {
|
||||
Baker::setWasAborted(wasAborted);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "Baker.h"
|
||||
#include "TextureBaker.h"
|
||||
#include "baking/TextureFileNamer.h"
|
||||
|
||||
#include "ModelBakingLoggingCategory.h"
|
||||
|
||||
|
@ -97,7 +98,6 @@ private slots:
|
|||
void handleAbortedTexture();
|
||||
|
||||
private:
|
||||
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);
|
||||
|
@ -109,6 +109,8 @@ private:
|
|||
bool _pendingErrorEmission { false };
|
||||
|
||||
bool _hasBeenBaked { false };
|
||||
|
||||
TextureFileNamer _textureFileNamer;
|
||||
};
|
||||
|
||||
#endif // hifi_ModelBaker_h
|
||||
|
|
34
libraries/baking/src/baking/TextureFileNamer.cpp
Normal file
34
libraries/baking/src/baking/TextureFileNamer.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// TextureFileNamer.cpp
|
||||
// libraries/baking/src/baking
|
||||
//
|
||||
// Created by Sabrina Shanman on 2019/03/14.
|
||||
// Copyright 2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "TextureFileNamer.h"
|
||||
|
||||
QString TextureFileNamer::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.baseName() + 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[baseTextureFileName];
|
||||
|
||||
if (nameMatches > 0) {
|
||||
// there are already nameMatches texture with this name
|
||||
// append - and that number to our baked texture file name so that it is unique
|
||||
baseTextureFileName += "-" + QString::number(nameMatches);
|
||||
}
|
||||
|
||||
// increment the number of name matches
|
||||
++nameMatches;
|
||||
|
||||
return baseTextureFileName;
|
||||
}
|
30
libraries/baking/src/baking/TextureFileNamer.h
Normal file
30
libraries/baking/src/baking/TextureFileNamer.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// TextureFileNamer.h
|
||||
// libraries/baking/src/baking
|
||||
//
|
||||
// Created by Sabrina Shanman on 2019/03/14.
|
||||
// Copyright 2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_TextureFileNamer_h
|
||||
#define hifi_TextureFileNamer_h
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QHash>
|
||||
|
||||
#include <image/Image.h>
|
||||
|
||||
class TextureFileNamer {
|
||||
public:
|
||||
TextureFileNamer() {}
|
||||
|
||||
QString createBaseTextureFileName(const QFileInfo& textureFileInfo, const image::TextureUsage::Type textureType);
|
||||
|
||||
protected:
|
||||
QHash<QString, int> _textureNameMatchCount;
|
||||
};
|
||||
|
||||
#endif // hifi_TextureFileNamer_h
|
Loading…
Reference in a new issue