diff --git a/tools/oven/src/BakerCLI.cpp b/tools/oven/src/BakerCLI.cpp new file mode 100644 index 0000000000..7bdd221514 --- /dev/null +++ b/tools/oven/src/BakerCLI.cpp @@ -0,0 +1,64 @@ +// +// 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" + +BakerCLI::BakerCLI(Oven* parent) : QObject(parent) { +} + +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") { + inputUrl.setScheme("file"); + } + + static const QString MODEL_EXTENSION { ".fbx" }; + + // check what kind of baker we should be creating + bool isFBX = inputUrl.toDisplayString().endsWith(MODEL_EXTENSION, Qt::CaseInsensitive); + bool isSupportedImage = false; + + for (QByteArray format : QImageReader::supportedImageFormats()) { + isSupportedImage |= inputUrl.toDisplayString().endsWith(format, Qt::CaseInsensitive); + } + + // create our appropiate baker + if (isFBX) { + _baker = std::unique_ptr { new FBXBaker(inputUrl, outputPath, []() -> QThread* { return qApp->getNextWorkerThread(); }) }; + _baker->moveToThread(qApp->getFBXBakerThread()); + } else if (isSupportedImage) { + _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.get(), "bake"); + + // make sure we hear about the results of this baker when it is done + connect(_baker.get(), &Baker::finished, this, &BakerCLI::handleFinishedBaker); +} + +void BakerCLI::handleFinishedBaker() { + qCDebug(model_baking) << "Finished baking file."; + 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..cb2b908059 --- /dev/null +++ b/tools/oven/src/BakerCLI.h @@ -0,0 +1,34 @@ +// +// 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 "Baker.h" +#include "Oven.h" + +class BakerCLI : public QObject { + Q_OBJECT + +public: + BakerCLI(Oven* parent); + void bakeFile(QUrl inputUrl, const QString outputPath); + +private slots: + void handleFinishedBaker(); + +private: + std::unique_ptr _baker; +}; + +#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..a38aaa2b97 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -11,16 +11,20 @@ #include #include +#include #include #include #include "ui/OvenMainWindow.h" - #include "Oven.h" +#include "BakerCli.h" 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) { @@ -30,24 +34,43 @@ 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({ + { 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); + // 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(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; + _mainWindow->show(); + } } Oven::~Oven() {