mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:29:03 +02:00
Added CLI to Oven tool
This commit is contained in:
parent
f1dd5fbb14
commit
9bc1bc47a2
3 changed files with 126 additions and 7 deletions
69
tools/oven/src/BakerCLI.cpp
Normal file
69
tools/oven/src/BakerCLI.cpp
Normal file
|
@ -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 <memory>
|
||||||
|
|
||||||
|
#include <QImageReader>
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
#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();
|
||||||
|
}
|
32
tools/oven/src/BakerCLI.h
Normal file
32
tools/oven/src/BakerCLI.h
Normal file
|
@ -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 <QString>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
class BakerCLI : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
void bakeFile(const QString inputFilename, const QString outputFilename);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void handleFinishedBaker();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_BakerCLI_h
|
|
@ -11,13 +11,16 @@
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QCommandLineParser>
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
#include <image/Image.h>
|
#include <image/Image.h>
|
||||||
#include <SettingInterface.h>
|
#include <SettingInterface.h>
|
||||||
|
|
||||||
#include "ui/OvenMainWindow.h"
|
#include "ui/OvenMainWindow.h"
|
||||||
|
#include "ModelBakingLoggingCategory.h"
|
||||||
#include "Oven.h"
|
#include "Oven.h"
|
||||||
|
#include "BakerCli.h"
|
||||||
|
|
||||||
static const QString OUTPUT_FOLDER = "/Users/birarda/code/hifi/lod/test-oven/export";
|
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
|
// init the settings interface so we can save and load settings
|
||||||
Setting::init();
|
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
|
// enable compression in image library, except for cube maps
|
||||||
image::setColorTexturesCompressionEnabled(true);
|
image::setColorTexturesCompressionEnabled(true);
|
||||||
image::setGrayscaleTexturesCompressionEnabled(true);
|
image::setGrayscaleTexturesCompressionEnabled(true);
|
||||||
image::setNormalTexturesCompressionEnabled(true);
|
image::setNormalTexturesCompressionEnabled(true);
|
||||||
image::setCubeTexturesCompressionEnabled(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
|
// setup our worker threads
|
||||||
setupWorkerThreads(QThread::idealThreadCount() - 1);
|
setupWorkerThreads(QThread::idealThreadCount() - 1);
|
||||||
|
|
||||||
// Autodesk's SDK means that we need a single thread for all FBX importing/exporting in the same process
|
// Autodesk's SDK means that we need a single thread for all FBX importing/exporting in the same process
|
||||||
// setup the FBX Baker thread
|
// setup the FBX Baker thread
|
||||||
setupFBXBakerThread();
|
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() {
|
Oven::~Oven() {
|
||||||
|
|
Loading…
Reference in a new issue