From 9bc1bc47a2012abb73afc937b9a892c2301f9b63 Mon Sep 17 00:00:00 2001 From: seefo Date: Tue, 6 Jun 2017 14:57:42 -0700 Subject: [PATCH 1/5] Added CLI to Oven tool --- tools/oven/src/BakerCLI.cpp | 69 +++++++++++++++++++++++++++++++++++++ tools/oven/src/BakerCLI.h | 32 +++++++++++++++++ tools/oven/src/Oven.cpp | 32 +++++++++++++---- 3 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 tools/oven/src/BakerCLI.cpp create mode 100644 tools/oven/src/BakerCLI.h diff --git a/tools/oven/src/BakerCLI.cpp b/tools/oven/src/BakerCLI.cpp new file mode 100644 index 0000000000..cb23eff224 --- /dev/null +++ b/tools/oven/src/BakerCLI.cpp @@ -0,0 +1,69 @@ +// +// BakerCLI.cpp +// tools/oven/src +// +// Created by Robbie Uvanni on 6/6/17. +// Copyright 2017 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 + +#include +#include +#include "ModelBakingLoggingCategory.h" + +#include "Oven.h" +#include "BakerCLI.h" + +#include "FBXBaker.h" +#include "TextureBaker.h" + +void BakerCLI::bakeFile(const QString inputFilename, const QString outputFilename) { + QUrl inputUrl(inputFilename); + + // if the URL doesn't have a scheme, assume it is a local file + if (inputUrl.scheme() != "http" && inputUrl.scheme() != "https" && inputUrl.scheme() != "ftp") { + inputUrl.setScheme("file"); + } + + static const QString MODEL_EXTENSION { ".fbx" }; + + // check what kind of baker we should be creating + bool isFBX = inputFilename.endsWith(MODEL_EXTENSION, Qt::CaseInsensitive); + bool isSupportedImage = false; + + for (QByteArray format : QImageReader::supportedImageFormats()) { + isSupportedImage |= inputFilename.endsWith(format, Qt::CaseInsensitive); + } + + // create our appropiate baker + Baker* baker; + + if (isFBX) { + baker = new FBXBaker(inputUrl, outputFilename, []() -> QThread* { + return qApp->getNextWorkerThread(); + }); + baker->moveToThread(qApp->getFBXBakerThread()); + } else if (isSupportedImage) { + baker = new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputFilename); + baker->moveToThread(qApp->getNextWorkerThread()); + } else { + qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl; + return; + } + + // invoke the bake method on the baker thread + QMetaObject::invokeMethod(baker, "bake"); + + // make sure we hear about the results of this baker when it is done + connect(baker, &Baker::finished, this, &BakerCLI::handleFinishedBaker); +} + +void BakerCLI::handleFinishedBaker() { + qCDebug(model_baking) << "Finished baking file."; + sender()->deleteLater(); + QApplication::quit(); +} \ No newline at end of file diff --git a/tools/oven/src/BakerCLI.h b/tools/oven/src/BakerCLI.h new file mode 100644 index 0000000000..6e613aeefc --- /dev/null +++ b/tools/oven/src/BakerCLI.h @@ -0,0 +1,32 @@ +// +// BakerCLI.h +// tools/oven/src +// +// Created by Robbie Uvanni on 6/6/17. +// Copyright 2017 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_BakerCLI_h +#define hifi_BakerCLI_h + +#include +#include + +#include +#include + +class BakerCLI : public QObject { + Q_OBJECT + +public: + void bakeFile(const QString inputFilename, const QString outputFilename); + +private slots: + void handleFinishedBaker(); + +}; + +#endif // hifi_BakerCLI_h \ No newline at end of file diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index af660e9795..57252b4cf9 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -11,13 +11,16 @@ #include #include +#include +#include #include #include #include "ui/OvenMainWindow.h" - +#include "ModelBakingLoggingCategory.h" #include "Oven.h" +#include "BakerCli.h" static const QString OUTPUT_FOLDER = "/Users/birarda/code/hifi/lod/test-oven/export"; @@ -30,24 +33,39 @@ Oven::Oven(int argc, char* argv[]) : // init the settings interface so we can save and load settings Setting::init(); + // parse the command line parameters + QCommandLineParser parser; + + parser.addOptions({ + { "i", "Input filename.", "input" }, + { "o", "Output filename.", "output" } + }); + parser.addHelpOption(); + + parser.process(*this); + // 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 - _mainWindow = new OvenMainWindow; - _mainWindow->show(); - // setup our worker threads setupWorkerThreads(QThread::idealThreadCount() - 1); // Autodesk's SDK means that we need a single thread for all FBX importing/exporting in the same process // setup the FBX Baker thread setupFBXBakerThread(); + + // check if we were passed any command line arguments that would tell us just to run without the GUI + if (parser.isSet("i") && parser.isSet("o")) { + BakerCLI* cli = new BakerCLI(); + cli->bakeFile(parser.value("i"), parser.value("o")); + } else { + // setup the GUI + _mainWindow = new OvenMainWindow; + _mainWindow->show(); + } } Oven::~Oven() { From 46400f41222ddd5ecea1995f8cf7ffb7666a670d Mon Sep 17 00:00:00 2001 From: seefo Date: Tue, 6 Jun 2017 15:05:26 -0700 Subject: [PATCH 2/5] Cleaned up oven CLI --- tools/oven/src/BakerCLI.cpp | 3 --- tools/oven/src/BakerCLI.h | 4 ---- tools/oven/src/Oven.cpp | 7 ++----- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/oven/src/BakerCLI.cpp b/tools/oven/src/BakerCLI.cpp index cb23eff224..3a0d1eeef7 100644 --- a/tools/oven/src/BakerCLI.cpp +++ b/tools/oven/src/BakerCLI.cpp @@ -9,15 +9,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include #include #include "ModelBakingLoggingCategory.h" #include "Oven.h" #include "BakerCLI.h" - #include "FBXBaker.h" #include "TextureBaker.h" diff --git a/tools/oven/src/BakerCLI.h b/tools/oven/src/BakerCLI.h index 6e613aeefc..7803aa6c86 100644 --- a/tools/oven/src/BakerCLI.h +++ b/tools/oven/src/BakerCLI.h @@ -12,10 +12,6 @@ #ifndef hifi_BakerCLI_h #define hifi_BakerCLI_h -#include -#include - -#include #include class BakerCLI : public QObject { diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index 57252b4cf9..3d356a5f1e 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -12,13 +12,11 @@ #include #include #include -#include #include #include #include "ui/OvenMainWindow.h" -#include "ModelBakingLoggingCategory.h" #include "Oven.h" #include "BakerCli.h" @@ -37,11 +35,10 @@ Oven::Oven(int argc, char* argv[]) : QCommandLineParser parser; parser.addOptions({ - { "i", "Input filename.", "input" }, - { "o", "Output filename.", "output" } + { "i", "Path to file that you would like to bake.", "input" }, + { "o", "Path to folder that will be used as output.", "output" } }); parser.addHelpOption(); - parser.process(*this); // enable compression in image library, except for cube maps From a3d2fa2630b713b31297e221284a1efe4184b90a Mon Sep 17 00:00:00 2001 From: seefo Date: Tue, 6 Jun 2017 16:13:18 -0700 Subject: [PATCH 3/5] Made requested changed to Oven CLI --- tools/oven/src/BakerCLI.cpp | 12 ++++++++---- tools/oven/src/BakerCLI.h | 5 ++++- tools/oven/src/Oven.cpp | 13 ++++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/oven/src/BakerCLI.cpp b/tools/oven/src/BakerCLI.cpp index 3a0d1eeef7..04d43853da 100644 --- a/tools/oven/src/BakerCLI.cpp +++ b/tools/oven/src/BakerCLI.cpp @@ -9,16 +9,20 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include -#include "ModelBakingLoggingCategory.h" +#include "ModelBakingLoggingCategory.h" #include "Oven.h" #include "BakerCLI.h" #include "FBXBaker.h" #include "TextureBaker.h" -void BakerCLI::bakeFile(const QString inputFilename, const QString outputFilename) { +BakerCLI::BakerCLI(Oven* parent) : QObject() { +} + +void BakerCLI::bakeFile(const QString inputFilename, const QString outputPath) { QUrl inputUrl(inputFilename); // if the URL doesn't have a scheme, assume it is a local file @@ -40,12 +44,12 @@ void BakerCLI::bakeFile(const QString inputFilename, const QString outputFilenam Baker* baker; if (isFBX) { - baker = new FBXBaker(inputUrl, outputFilename, []() -> QThread* { + baker = new FBXBaker(inputUrl, outputPath, []() -> QThread* { return qApp->getNextWorkerThread(); }); baker->moveToThread(qApp->getFBXBakerThread()); } else if (isSupportedImage) { - baker = new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputFilename); + baker = new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputPath); baker->moveToThread(qApp->getNextWorkerThread()); } else { qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl; diff --git a/tools/oven/src/BakerCLI.h b/tools/oven/src/BakerCLI.h index 7803aa6c86..88ea028b9f 100644 --- a/tools/oven/src/BakerCLI.h +++ b/tools/oven/src/BakerCLI.h @@ -14,11 +14,14 @@ #include +#include "Oven.h" + class BakerCLI : public QObject { Q_OBJECT public: - void bakeFile(const QString inputFilename, const QString outputFilename); + BakerCLI(Oven* parent); + void bakeFile(const QString inputFilename, const QString outputPath); private slots: void handleFinishedBaker(); diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index 3d356a5f1e..7431863ba5 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -22,6 +22,9 @@ static const QString OUTPUT_FOLDER = "/Users/birarda/code/hifi/lod/test-oven/export"; +static const QString CLI_INPUT_PARAMETER = "i"; +static const QString CLI_OUTPUT_PARAMETER = "o"; + Oven::Oven(int argc, char* argv[]) : QApplication(argc, argv) { @@ -35,8 +38,8 @@ Oven::Oven(int argc, char* argv[]) : QCommandLineParser parser; parser.addOptions({ - { "i", "Path to file that you would like to bake.", "input" }, - { "o", "Path to folder that will be used as output.", "output" } + { CLI_INPUT_PARAMETER, "Path to file that you would like to bake.", "input" }, + { CLI_OUTPUT_PARAMETER, "Path to folder that will be used as output.", "output" } }); parser.addHelpOption(); parser.process(*this); @@ -55,9 +58,9 @@ Oven::Oven(int argc, char* argv[]) : setupFBXBakerThread(); // check if we were passed any command line arguments that would tell us just to run without the GUI - if (parser.isSet("i") && parser.isSet("o")) { - BakerCLI* cli = new BakerCLI(); - cli->bakeFile(parser.value("i"), parser.value("o")); + if (parser.isSet(CLI_INPUT_PARAMETER) && parser.isSet(CLI_OUTPUT_PARAMETER)) { + BakerCLI* cli = new BakerCLI(this); + cli->bakeFile(parser.value(CLI_INPUT_PARAMETER), parser.value(CLI_OUTPUT_PARAMETER)); } else { // setup the GUI _mainWindow = new OvenMainWindow; From 99e9e108829eb60369212620b816470dea5f91d3 Mon Sep 17 00:00:00 2001 From: seefo Date: Wed, 7 Jun 2017 10:35:20 -0700 Subject: [PATCH 4/5] Made requested changes to OvenCLI constructor --- tools/oven/src/BakerCLI.cpp | 9 ++++----- tools/oven/src/BakerCLI.h | 2 +- tools/oven/src/Oven.cpp | 11 ++++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/oven/src/BakerCLI.cpp b/tools/oven/src/BakerCLI.cpp index 04d43853da..b76e00269f 100644 --- a/tools/oven/src/BakerCLI.cpp +++ b/tools/oven/src/BakerCLI.cpp @@ -19,11 +19,10 @@ #include "FBXBaker.h" #include "TextureBaker.h" -BakerCLI::BakerCLI(Oven* parent) : QObject() { +BakerCLI::BakerCLI(Oven* parent) : QObject(parent) { } -void BakerCLI::bakeFile(const QString inputFilename, const QString outputPath) { - QUrl inputUrl(inputFilename); +void BakerCLI::bakeFile(QUrl inputUrl, const QString outputPath) { // if the URL doesn't have a scheme, assume it is a local file if (inputUrl.scheme() != "http" && inputUrl.scheme() != "https" && inputUrl.scheme() != "ftp") { @@ -33,11 +32,11 @@ void BakerCLI::bakeFile(const QString inputFilename, const QString outputPath) { static const QString MODEL_EXTENSION { ".fbx" }; // check what kind of baker we should be creating - bool isFBX = inputFilename.endsWith(MODEL_EXTENSION, Qt::CaseInsensitive); + bool isFBX = inputUrl.toDisplayString().endsWith(MODEL_EXTENSION, Qt::CaseInsensitive); bool isSupportedImage = false; for (QByteArray format : QImageReader::supportedImageFormats()) { - isSupportedImage |= inputFilename.endsWith(format, Qt::CaseInsensitive); + isSupportedImage |= inputUrl.toDisplayString().endsWith(format, Qt::CaseInsensitive); } // create our appropiate baker diff --git a/tools/oven/src/BakerCLI.h b/tools/oven/src/BakerCLI.h index 88ea028b9f..5935151bb5 100644 --- a/tools/oven/src/BakerCLI.h +++ b/tools/oven/src/BakerCLI.h @@ -21,7 +21,7 @@ class BakerCLI : public QObject { public: BakerCLI(Oven* parent); - void bakeFile(const QString inputFilename, const QString outputPath); + void bakeFile(QUrl inputUrl, const QString outputPath); private slots: void handleFinishedBaker(); diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index 7431863ba5..a38aaa2b97 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -58,9 +58,14 @@ Oven::Oven(int argc, char* argv[]) : setupFBXBakerThread(); // check if we were passed any command line arguments that would tell us just to run without the GUI - if (parser.isSet(CLI_INPUT_PARAMETER) && parser.isSet(CLI_OUTPUT_PARAMETER)) { - BakerCLI* cli = new BakerCLI(this); - cli->bakeFile(parser.value(CLI_INPUT_PARAMETER), parser.value(CLI_OUTPUT_PARAMETER)); + if (parser.isSet(CLI_INPUT_PARAMETER) || parser.isSet(CLI_OUTPUT_PARAMETER)) { + if (parser.isSet(CLI_INPUT_PARAMETER) && parser.isSet(CLI_OUTPUT_PARAMETER)) { + BakerCLI* cli = new BakerCLI(this); + cli->bakeFile(parser.value(CLI_INPUT_PARAMETER), parser.value(CLI_OUTPUT_PARAMETER)); + } else { + parser.showHelp(); + QApplication::quit(); + } } else { // setup the GUI _mainWindow = new OvenMainWindow; From 0c7ffa0ac6416ac040590ed61940416a2e1b640c Mon Sep 17 00:00:00 2001 From: seefo Date: Thu, 8 Jun 2017 09:47:01 -0700 Subject: [PATCH 5/5] Replaced baker in OvenCLI with an std::unique_ptr --- tools/oven/src/BakerCLI.cpp | 17 ++++++----------- tools/oven/src/BakerCLI.h | 5 ++++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/oven/src/BakerCLI.cpp b/tools/oven/src/BakerCLI.cpp index b76e00269f..7bdd221514 100644 --- a/tools/oven/src/BakerCLI.cpp +++ b/tools/oven/src/BakerCLI.cpp @@ -40,30 +40,25 @@ void BakerCLI::bakeFile(QUrl inputUrl, const QString outputPath) { } // create our appropiate baker - Baker* baker; - if (isFBX) { - baker = new FBXBaker(inputUrl, outputPath, []() -> QThread* { - return qApp->getNextWorkerThread(); - }); - baker->moveToThread(qApp->getFBXBakerThread()); + _baker = std::unique_ptr { new FBXBaker(inputUrl, outputPath, []() -> QThread* { return qApp->getNextWorkerThread(); }) }; + _baker->moveToThread(qApp->getFBXBakerThread()); } else if (isSupportedImage) { - baker = new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputPath); - baker->moveToThread(qApp->getNextWorkerThread()); + _baker = std::unique_ptr { new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputPath) }; + _baker->moveToThread(qApp->getNextWorkerThread()); } else { qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl; return; } // invoke the bake method on the baker thread - QMetaObject::invokeMethod(baker, "bake"); + QMetaObject::invokeMethod(_baker.get(), "bake"); // make sure we hear about the results of this baker when it is done - connect(baker, &Baker::finished, this, &BakerCLI::handleFinishedBaker); + connect(_baker.get(), &Baker::finished, this, &BakerCLI::handleFinishedBaker); } void BakerCLI::handleFinishedBaker() { qCDebug(model_baking) << "Finished baking file."; - sender()->deleteLater(); QApplication::quit(); } \ No newline at end of file diff --git a/tools/oven/src/BakerCLI.h b/tools/oven/src/BakerCLI.h index 5935151bb5..cb2b908059 100644 --- a/tools/oven/src/BakerCLI.h +++ b/tools/oven/src/BakerCLI.h @@ -14,6 +14,7 @@ #include +#include "Baker.h" #include "Oven.h" class BakerCLI : public QObject { @@ -24,8 +25,10 @@ public: void bakeFile(QUrl inputUrl, const QString outputPath); private slots: - void handleFinishedBaker(); + void handleFinishedBaker(); +private: + std::unique_ptr _baker; }; #endif // hifi_BakerCLI_h \ No newline at end of file