handle texturebakers with same url but different usage

This commit is contained in:
SamGondelman 2019-04-22 13:24:34 -07:00
parent 2a7ef5c5bb
commit 7245d1a037
4 changed files with 11 additions and 8 deletions

View file

@ -133,7 +133,7 @@ void MaterialBaker::processMaterial() {
QString extension = idx >= 0 ? cleanURL.mid(idx + 1).toLower() : "";
if (QImageReader::supportedImageFormats().contains(extension.toLatin1())) {
QPair<QUrl, image::TextureUsage::Type> textureKey(textureURL, type);
TextureKey textureKey(textureURL, type);
if (!_textureBakers.contains(textureKey)) {
auto baseTextureFileName = _textureFileNamer.createBaseTextureFileName(textureURL.fileName(), type);
@ -170,7 +170,7 @@ void MaterialBaker::handleFinishedTextureBaker() {
auto baker = qobject_cast<TextureBaker*>(sender());
if (baker) {
QPair<QUrl, image::TextureUsage::Type> textureKey = { baker->getTextureURL(), baker->getTextureType() };
TextureKey textureKey = { baker->getTextureURL(), baker->getTextureType() };
if (!baker->hasErrors()) {
// this TextureBaker is done and everything went according to plan
qCDebug(material_baking) << "Re-writing texture references to" << baker->getTextureURL();

View file

@ -21,6 +21,8 @@
static const QString BAKED_MATERIAL_EXTENSION = ".baked.json";
using TextureKey = QPair<QUrl, image::TextureUsage::Type>;
class MaterialBaker : public Baker {
Q_OBJECT
public:
@ -55,8 +57,8 @@ private:
NetworkMaterialResourcePointer _materialResource;
QHash<QPair<QUrl, image::TextureUsage::Type>, QSharedPointer<TextureBaker>> _textureBakers;
QMultiHash<QPair<QUrl, image::TextureUsage::Type>, std::shared_ptr<NetworkMaterial>> _materialsNeedingRewrite;
QHash<TextureKey, QSharedPointer<TextureBaker>> _textureBakers;
QMultiHash<TextureKey, std::shared_ptr<NetworkMaterial>> _materialsNeedingRewrite;
QString _bakedOutputDir;
QString _textureOutputDir;

View file

@ -194,9 +194,10 @@ void DomainBaker::addTextureBaker(const QString& property, const QString& url, i
if (QImageReader::supportedImageFormats().contains(extension.toLatin1())) {
// grab a clean version of the URL without a query or fragment
QUrl textureURL = QUrl(url).adjusted(QUrl::RemoveQuery | QUrl::RemoveFragment);
TextureKey key = { textureURL, type };
// setup a texture baker for this URL, as long as we aren't baking a texture already
if (!_textureBakers.contains(textureURL)) {
if (!_textureBakers.contains(key)) {
// setup a baker for this texture
QSharedPointer<TextureBaker> textureBaker {
@ -208,7 +209,7 @@ void DomainBaker::addTextureBaker(const QString& property, const QString& url, i
connect(textureBaker.data(), &TextureBaker::finished, this, &DomainBaker::handleFinishedTextureBaker);
// insert it into our bakers hash so we hold a strong pointer to it
_textureBakers.insert(textureURL, textureBaker);
_textureBakers.insert(key, textureBaker);
// move the baker to a worker thread and kickoff the bake
textureBaker->moveToThread(Oven::instance().getNextWorkerThread());
@ -557,7 +558,7 @@ void DomainBaker::handleFinishedTextureBaker() {
_entitiesNeedingRewrite.remove(baker->getTextureURL());
// drop our shared pointer to this baker so that it gets cleaned up
_textureBakers.remove(baker->getTextureURL());
_textureBakers.remove({ baker->getTextureURL(), baker->getTextureType() });
// emit progress to tell listeners how many textures we have baked
emit bakeProgress(++_completedSubBakes, _totalNumberOfSubBakes);

View file

@ -62,7 +62,7 @@ private:
QJsonArray _entities;
QHash<QUrl, QSharedPointer<ModelBaker>> _modelBakers;
QHash<QUrl, QSharedPointer<TextureBaker>> _textureBakers;
QHash<TextureKey, QSharedPointer<TextureBaker>> _textureBakers;
QHash<QUrl, QSharedPointer<JSBaker>> _scriptBakers;
QHash<QUrl, QSharedPointer<MaterialBaker>> _materialBakers;