From 9bc1bc47a2012abb73afc937b9a892c2301f9b63 Mon Sep 17 00:00:00 2001 From: seefo Date: Tue, 6 Jun 2017 14:57:42 -0700 Subject: [PATCH] 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() {