mirror of
https://github.com/overte-org/overte.git
synced 2025-06-20 13:21:04 +02:00
put fbx bakers on their own thread from ModelBakeWidget
This commit is contained in:
parent
c5fbd28ecf
commit
7c5376bb1f
2 changed files with 31 additions and 10 deletions
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QThread>
|
||||||
|
|
||||||
#include "ModelBakeWidget.h"
|
#include "ModelBakeWidget.h"
|
||||||
|
|
||||||
|
@ -27,11 +28,18 @@ static const QString MODEL_START_DIR_SETTING_KEY = "model_search_directory";
|
||||||
ModelBakeWidget::ModelBakeWidget(QWidget* parent, Qt::WindowFlags flags) :
|
ModelBakeWidget::ModelBakeWidget(QWidget* parent, Qt::WindowFlags flags) :
|
||||||
QWidget(parent, flags),
|
QWidget(parent, flags),
|
||||||
_exportDirectory(EXPORT_DIR_SETTING_KEY),
|
_exportDirectory(EXPORT_DIR_SETTING_KEY),
|
||||||
_modelStartDirectory(MODEL_START_DIR_SETTING_KEY)
|
_modelStartDirectory(MODEL_START_DIR_SETTING_KEY),
|
||||||
|
_bakerThread(new QThread(this))
|
||||||
{
|
{
|
||||||
setupUI();
|
setupUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModelBakeWidget::~ModelBakeWidget() {
|
||||||
|
// before we go down, stop the baker thread and make sure it's done
|
||||||
|
_bakerThread->quit();
|
||||||
|
_bakerThread->wait();
|
||||||
|
}
|
||||||
|
|
||||||
void ModelBakeWidget::setupUI() {
|
void ModelBakeWidget::setupUI() {
|
||||||
// setup a grid layout to hold everything
|
// setup a grid layout to hold everything
|
||||||
QGridLayout* gridLayout = new QGridLayout;
|
QGridLayout* gridLayout = new QGridLayout;
|
||||||
|
@ -115,15 +123,14 @@ void ModelBakeWidget::chooseFileButtonClicked() {
|
||||||
// set the contents of the model file text box to be the path to the selected file
|
// set the contents of the model file text box to be the path to the selected file
|
||||||
_modelLineEdit->setText(selectedFiles.join(','));
|
_modelLineEdit->setText(selectedFiles.join(','));
|
||||||
|
|
||||||
|
if (_outputDirLineEdit->text().isEmpty()) {
|
||||||
auto directoryOfModel = QFileInfo(selectedFiles[0]).absolutePath();
|
auto directoryOfModel = QFileInfo(selectedFiles[0]).absolutePath();
|
||||||
|
|
||||||
// save the directory containing this model so we can default to it next time we show the file dialog
|
|
||||||
_modelStartDirectory.set(directoryOfModel);
|
|
||||||
|
|
||||||
// if our output directory is not yet set, set it to the directory of this model
|
// if our output directory is not yet set, set it to the directory of this model
|
||||||
_outputDirLineEdit->setText(directoryOfModel);
|
_outputDirLineEdit->setText(directoryOfModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ModelBakeWidget::chooseOutputDirButtonClicked() {
|
void ModelBakeWidget::chooseOutputDirButtonClicked() {
|
||||||
// pop a file dialog so the user can select the output directory
|
// pop a file dialog so the user can select the output directory
|
||||||
|
@ -153,13 +160,11 @@ void ModelBakeWidget::bakeButtonClicked() {
|
||||||
QDir outputDirectory(_outputDirLineEdit->text());
|
QDir outputDirectory(_outputDirLineEdit->text());
|
||||||
|
|
||||||
if (!outputDirectory.exists()) {
|
if (!outputDirectory.exists()) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we have a non empty URL to a model to bake
|
// make sure we have a non empty URL to a model to bake
|
||||||
if (_modelLineEdit->text().isEmpty()) {
|
if (_modelLineEdit->text().isEmpty()) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +181,19 @@ void ModelBakeWidget::bakeButtonClicked() {
|
||||||
|
|
||||||
// everything seems to be in place, kick off a bake for this model now
|
// everything seems to be in place, kick off a bake for this model now
|
||||||
auto baker = new FBXBaker(modelToBakeURL, outputDirectory.absolutePath(), false);
|
auto baker = new FBXBaker(modelToBakeURL, outputDirectory.absolutePath(), false);
|
||||||
baker->bake();
|
|
||||||
|
// move the baker to the baker thread
|
||||||
|
baker->moveToThread(_bakerThread);
|
||||||
|
|
||||||
|
// make sure we start the baker thread if it isn't already running
|
||||||
|
if (!_bakerThread->isRunning()) {
|
||||||
|
_bakerThread->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// invoke the bake method on the baker thread
|
||||||
|
QMetaObject::invokeMethod(baker, "bake");
|
||||||
|
|
||||||
|
// keep a unique_ptr to this baker
|
||||||
_bakers.emplace_back(baker);
|
_bakers.emplace_back(baker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,14 @@
|
||||||
#include <FBXBaker.h>
|
#include <FBXBaker.h>
|
||||||
|
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
class QThread;
|
||||||
|
|
||||||
class ModelBakeWidget : public QWidget {
|
class ModelBakeWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModelBakeWidget(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
|
ModelBakeWidget(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
|
||||||
|
~ModelBakeWidget();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void chooseFileButtonClicked();
|
void chooseFileButtonClicked();
|
||||||
|
@ -44,6 +46,8 @@ private:
|
||||||
|
|
||||||
Setting::Handle<QString> _exportDirectory;
|
Setting::Handle<QString> _exportDirectory;
|
||||||
Setting::Handle<QString> _modelStartDirectory;
|
Setting::Handle<QString> _modelStartDirectory;
|
||||||
|
|
||||||
|
QThread* _bakerThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ModelBakeWidget_h
|
#endif // hifi_ModelBakeWidget_h
|
||||||
|
|
Loading…
Reference in a new issue