add a toggle to domain baker to re-bake originals

This commit is contained in:
Stephen Birarda 2017-05-18 11:57:18 -07:00
parent 3edbd41027
commit 2ba700d062
4 changed files with 36 additions and 7 deletions

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('/')) {
@ -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)) {

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

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