From a7f154a853b3156032152fb7818afdee4a8f3dc3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 May 2017 09:29:04 -0700 Subject: [PATCH 1/7] make a copy of original models file when baking domain --- tools/oven/src/DomainBaker.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/oven/src/DomainBaker.cpp b/tools/oven/src/DomainBaker.cpp index cb2a6bca29..1d38c732dc 100644 --- a/tools/oven/src/DomainBaker.cpp +++ b/tools/oven/src/DomainBaker.cpp @@ -100,6 +100,15 @@ void DomainBaker::loadLocalFile() { // load up the local entities file QFile entitiesFile { _localEntitiesFileURL.toLocalFile() }; + // first make a copy of the local entities file in our output folder + if (!entitiesFile.copy(_uniqueOutputPath + "/" + "original-" + _localEntitiesFileURL.fileName())) { + // add an error to our list to specify that the file could not be copied + handleError("Could not make a copy of entities file"); + + // return to stop processing + return; + } + if (!entitiesFile.open(QIODevice::ReadOnly)) { // add an error to our list to specify that the file could not be read handleError("Could not open entities file"); From 3edbd41027d5c88f47e95745fd9538ba437544ac Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 May 2017 11:27:24 -0700 Subject: [PATCH 2/7] enable image compression at run time in baker --- tools/oven/src/Oven.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index ac8ef505ba..39187aedc4 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include "ui/OvenMainWindow.h" @@ -29,6 +30,12 @@ Oven::Oven(int argc, char* argv[]) : // init the settings interface so we can save and load settings Setting::init(); + // enable compression in image library + image::setColorTexturesCompressionEnabled(true); + image::setGrayscaleTexturesCompressionEnabled(true); + image::setNormalTexturesCompressionEnabled(true); + image::setCubeTexturesCompressionEnabled(true); + // check if we were passed any command line arguments that would tell us just to run without the GUI // setup the GUI From 2ba700d062932bbbb1495f9ac11ec9c7ecfaa92b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 May 2017 11:57:18 -0700 Subject: [PATCH 3/7] add a toggle to domain baker to re-bake originals --- tools/oven/src/DomainBaker.cpp | 28 +++++++++++++++++++++----- tools/oven/src/DomainBaker.h | 5 ++++- tools/oven/src/ui/DomainBakeWidget.cpp | 8 +++++++- tools/oven/src/ui/DomainBakeWidget.h | 2 ++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/tools/oven/src/DomainBaker.cpp b/tools/oven/src/DomainBaker.cpp index 1d38c732dc..fe0808de73 100644 --- a/tools/oven/src/DomainBaker.cpp +++ b/tools/oven/src/DomainBaker.cpp @@ -23,10 +23,12 @@ #include "DomainBaker.h" DomainBaker::DomainBaker(const QUrl& localModelFileURL, const QString& domainName, - const QString& baseOutputPath, const QUrl& destinationPath) : + const QString& baseOutputPath, const QUrl& destinationPath, + bool shouldRebakeOriginals) : _localEntitiesFileURL(localModelFileURL), _domainName(domainName), - _baseOutputPath(baseOutputPath) + _baseOutputPath(baseOutputPath), + _shouldRebakeOriginals(shouldRebakeOriginals) { // make sure the destination path has a trailing slash if (!destinationPath.toString().endsWith('/')) { @@ -168,9 +170,25 @@ void DomainBaker::enumerateEntities() { static const QStringList BAKEABLE_MODEL_EXTENSIONS { ".fbx" }; auto completeLowerExtension = modelFileName.mid(modelFileName.indexOf('.')).toLower(); - if (BAKEABLE_MODEL_EXTENSIONS.contains(completeLowerExtension)) { - // grab a clean version of the URL without a query or fragment - modelURL = modelURL.adjusted(QUrl::RemoveQuery | QUrl::RemoveFragment); + static const QString BAKED_MODEL_EXTENSION = ".baked.fbx"; + + if (BAKEABLE_MODEL_EXTENSIONS.contains(completeLowerExtension) || + (_shouldRebakeOriginals && completeLowerExtension == BAKED_MODEL_EXTENSION)) { + + if (completeLowerExtension == BAKED_MODEL_EXTENSION) { + // grab a URL to the original, that we assume is stored a directory up, in the "original" folder + // with just the fbx extension + qDebug() << "Re-baking original for" << modelURL; + + auto originalFileName = modelFileName; + originalFileName.replace(".baked", ""); + modelURL = modelURL.resolved("../original/" + originalFileName); + + qDebug() << "Original must be present at" << modelURL; + } else { + // grab a clean version of the URL without a query or fragment + modelURL = modelURL.adjusted(QUrl::RemoveQuery | QUrl::RemoveFragment); + } // setup an FBXBaker for this URL, as long as we don't already have one if (!_modelBakers.contains(modelURL)) { diff --git a/tools/oven/src/DomainBaker.h b/tools/oven/src/DomainBaker.h index 5244408115..34c5e11e63 100644 --- a/tools/oven/src/DomainBaker.h +++ b/tools/oven/src/DomainBaker.h @@ -28,7 +28,8 @@ public: // This means that we need to put all of the FBX importing/exporting from the same process on the same thread. // That means you must pass a usable running QThread when constructing a domain baker. DomainBaker(const QUrl& localEntitiesFileURL, const QString& domainName, - const QString& baseOutputPath, const QUrl& destinationPath); + const QString& baseOutputPath, const QUrl& destinationPath, + bool shouldRebakeOriginals = false); signals: void allModelsFinished(); @@ -65,6 +66,8 @@ private: int _totalNumberOfSubBakes { 0 }; int _completedSubBakes { 0 }; + + bool _shouldRebakeOriginals { false }; }; #endif // hifi_DomainBaker_h diff --git a/tools/oven/src/ui/DomainBakeWidget.cpp b/tools/oven/src/ui/DomainBakeWidget.cpp index 7d667305bb..41452c7283 100644 --- a/tools/oven/src/ui/DomainBakeWidget.cpp +++ b/tools/oven/src/ui/DomainBakeWidget.cpp @@ -11,6 +11,7 @@ #include +#include #include #include #include @@ -126,6 +127,10 @@ void DomainBakeWidget::setupUI() { // start a new row for the next component ++rowIndex; + // setup a checkbox to allow re-baking of original assets + _rebakeOriginalsCheckBox = new QCheckBox("Re-bake originals"); + gridLayout->addWidget(_rebakeOriginalsCheckBox, rowIndex, 0); + // add a button that will kickoff the bake QPushButton* bakeButton = new QPushButton("Bake"); connect(bakeButton, &QPushButton::clicked, this, &DomainBakeWidget::bakeButtonClicked); @@ -207,7 +212,8 @@ void DomainBakeWidget::bakeButtonClicked() { auto fileToBakeURL = QUrl::fromLocalFile(_entitiesFileLineEdit->text()); auto domainBaker = std::unique_ptr { new DomainBaker(fileToBakeURL, _domainNameLineEdit->text(), - outputDirectory.absolutePath(), _destinationPathLineEdit->text()) + outputDirectory.absolutePath(), _destinationPathLineEdit->text(), + _rebakeOriginalsCheckBox->isChecked()) }; // make sure we hear from the baker when it is done diff --git a/tools/oven/src/ui/DomainBakeWidget.h b/tools/oven/src/ui/DomainBakeWidget.h index cd8c4a012e..a6f26b3731 100644 --- a/tools/oven/src/ui/DomainBakeWidget.h +++ b/tools/oven/src/ui/DomainBakeWidget.h @@ -19,6 +19,7 @@ #include "../DomainBaker.h" #include "BakeWidget.h" +class QCheckBox; class QLineEdit; class DomainBakeWidget : public BakeWidget { @@ -44,6 +45,7 @@ private: QLineEdit* _entitiesFileLineEdit; QLineEdit* _outputDirLineEdit; QLineEdit* _destinationPathLineEdit; + QCheckBox* _rebakeOriginalsCheckBox; Setting::Handle _domainNameSetting; Setting::Handle _exportDirectory; From 0621ddfd9f8855a02f1e4723b4034886d60f708a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 May 2017 17:47:10 -0700 Subject: [PATCH 4/7] don't enable cube map compression by default --- tools/oven/src/Oven.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index 39187aedc4..df232899d4 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -30,11 +30,10 @@ Oven::Oven(int argc, char* argv[]) : // init the settings interface so we can save and load settings Setting::init(); - // enable compression in image library + // enable compression in image library, except for cube maps image::setColorTexturesCompressionEnabled(true); image::setGrayscaleTexturesCompressionEnabled(true); image::setNormalTexturesCompressionEnabled(true); - image::setCubeTexturesCompressionEnabled(true); // check if we were passed any command line arguments that would tell us just to run without the GUI From 4c652487d0f88e22d2526dfb8473c9e1955c32b2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 May 2017 14:14:22 -0700 Subject: [PATCH 5/7] enable skybox compression (via BC7) by default --- tools/oven/src/Oven.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index df232899d4..af660e9795 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -34,6 +34,7 @@ Oven::Oven(int argc, char* argv[]) : image::setColorTexturesCompressionEnabled(true); image::setGrayscaleTexturesCompressionEnabled(true); image::setNormalTexturesCompressionEnabled(true); + image::setCubeTexturesCompressionEnabled(true); // check if we were passed any command line arguments that would tell us just to run without the GUI From 898433f42e06d91384430019d16dda4685e3a17e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 May 2017 14:16:43 -0700 Subject: [PATCH 6/7] force BC3 instead of BC1a compression for alpha textures --- libraries/image/src/image/Image.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 7f0674b17d..2a72304f5c 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -493,6 +493,10 @@ gpu::TexturePointer TextureUsage::process2DTextureColorFromImage(const QImage& s if (validAlpha) { processTextureAlpha(image, validAlpha, alphaAsMask); + + // NOTE: This disables BC1a compression becuase it was producing odd artifacts on text textures + // for the tutorial. Instead we use BC3 (which is larger) but doesn't produce the same artifacts). + alphaAsMask = false; } gpu::TexturePointer theTexture = nullptr; From 9cdd7cc8959e92abfa656de8caa9ede54c0dbb8f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 May 2017 14:22:16 -0700 Subject: [PATCH 7/7] fix model check for filenames with periods --- libraries/image/src/image/Image.cpp | 2 +- tools/oven/src/DomainBaker.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 2a72304f5c..dcc65e8995 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -494,7 +494,7 @@ gpu::TexturePointer TextureUsage::process2DTextureColorFromImage(const QImage& s if (validAlpha) { processTextureAlpha(image, validAlpha, alphaAsMask); - // NOTE: This disables BC1a compression becuase it was producing odd artifacts on text textures + // NOTE: This disables BC1a compression because it was producing odd artifacts on text textures // for the tutorial. Instead we use BC3 (which is larger) but doesn't produce the same artifacts). alphaAsMask = false; } diff --git a/tools/oven/src/DomainBaker.cpp b/tools/oven/src/DomainBaker.cpp index fe0808de73..03bc350f42 100644 --- a/tools/oven/src/DomainBaker.cpp +++ b/tools/oven/src/DomainBaker.cpp @@ -167,15 +167,15 @@ void DomainBaker::enumerateEntities() { // check if the file pointed to by this URL is a bakeable model, by comparing extensions auto modelFileName = modelURL.fileName(); - static const QStringList BAKEABLE_MODEL_EXTENSIONS { ".fbx" }; - auto completeLowerExtension = modelFileName.mid(modelFileName.indexOf('.')).toLower(); - + static const QString BAKEABLE_MODEL_EXTENSION { ".fbx" }; static const QString BAKED_MODEL_EXTENSION = ".baked.fbx"; - if (BAKEABLE_MODEL_EXTENSIONS.contains(completeLowerExtension) || - (_shouldRebakeOriginals && completeLowerExtension == BAKED_MODEL_EXTENSION)) { + bool isBakedFBX = modelFileName.endsWith(BAKED_MODEL_EXTENSION, Qt::CaseInsensitive); + bool isUnbakedFBX = modelFileName.endsWith(BAKEABLE_MODEL_EXTENSION, Qt::CaseInsensitive) && !isBakedFBX; - if (completeLowerExtension == BAKED_MODEL_EXTENSION) { + if (isUnbakedFBX || (_shouldRebakeOriginals && isBakedFBX)) { + + if (isBakedFBX) { // grab a URL to the original, that we assume is stored a directory up, in the "original" folder // with just the fbx extension qDebug() << "Re-baking original for" << modelURL;