Merge pull request #10503 from birarda/bake-textures

update baking tool to enable compression and re-baking
This commit is contained in:
Clément Brisset 2017-05-25 10:38:23 -07:00 committed by GitHub
commit aa4059eb05
6 changed files with 58 additions and 9 deletions

View file

@ -493,6 +493,10 @@ gpu::TexturePointer TextureUsage::process2DTextureColorFromImage(const QImage& s
if (validAlpha) {
processTextureAlpha(image, validAlpha, alphaAsMask);
// 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;
}
gpu::TexturePointer theTexture = nullptr;

View file

@ -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('/')) {
@ -100,6 +102,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");
@ -156,12 +167,28 @@ 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)) {
// grab a clean version of the URL without a query or fragment
modelURL = modelURL.adjusted(QUrl::RemoveQuery | QUrl::RemoveFragment);
bool isBakedFBX = modelFileName.endsWith(BAKED_MODEL_EXTENSION, Qt::CaseInsensitive);
bool isUnbakedFBX = modelFileName.endsWith(BAKEABLE_MODEL_EXTENSION, Qt::CaseInsensitive) && !isBakedFBX;
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;
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)) {

View file

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

View file

@ -12,6 +12,7 @@
#include <QtCore/QDebug>
#include <QtCore/QThread>
#include <image/Image.h>
#include <SettingInterface.h>
#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, 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
// setup the GUI

View file

@ -11,6 +11,7 @@
#include <QtConcurrent>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
@ -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<DomainBaker> {
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

View file

@ -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<QString> _domainNameSetting;
Setting::Handle<QString> _exportDirectory;