From 87b0f704609cb28a052d63e5c2f1c83be3d5ab27 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 5 Sep 2018 11:14:36 +0800 Subject: [PATCH] Add mtl export with obj --- src/modelmeshbinder.cpp | 2 +- src/modelmeshbinder.h | 2 +- src/modelwidget.cpp | 2 +- src/skeletondocumentwindow.cpp | 37 ++++++++++++++++++++++++---------- src/skeletondocumentwindow.h | 8 +++++--- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/modelmeshbinder.cpp b/src/modelmeshbinder.cpp index 9cc3633b..7277f85c 100644 --- a/src/modelmeshbinder.cpp +++ b/src/modelmeshbinder.cpp @@ -57,7 +57,7 @@ void ModelMeshBinder::exportMeshAsObj(const QString &filename) } } -void ModelMeshBinder::exportMeshAdObjPlusMaterials(const QString &filename) +void ModelMeshBinder::exportMeshAsObjPlusMaterials(const QString &filename) { QMutexLocker lock(&m_meshMutex); if (m_mesh) { diff --git a/src/modelmeshbinder.h b/src/modelmeshbinder.h index 4686b267..9505769d 100644 --- a/src/modelmeshbinder.h +++ b/src/modelmeshbinder.h @@ -15,7 +15,7 @@ public: ~ModelMeshBinder(); void updateMesh(MeshLoader *mesh); void exportMeshAsObj(const QString &filename); - void exportMeshAdObjPlusMaterials(const QString &filename); + void exportMeshAsObjPlusMaterials(const QString &filename); void initialize(); void paint(ModelShaderProgram *program); void cleanup(); diff --git a/src/modelwidget.cpp b/src/modelwidget.cpp index 053fce5a..4484577e 100644 --- a/src/modelwidget.cpp +++ b/src/modelwidget.cpp @@ -296,6 +296,6 @@ void ModelWidget::exportMeshAsObj(const QString &filename) void ModelWidget::exportMeshAsObjPlusMaterials(const QString &filename) { - m_meshBinder.exportMeshAdObjPlusMaterials(filename); + m_meshBinder.exportMeshAsObjPlusMaterials(filename); } diff --git a/src/skeletondocumentwindow.cpp b/src/skeletondocumentwindow.cpp index a7a422bd..0bc945b3 100644 --- a/src/skeletondocumentwindow.cpp +++ b/src/skeletondocumentwindow.cpp @@ -250,13 +250,17 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : m_fileMenu->addSeparator(); - m_exportModelAction = new QAction(tr("Wavefront (.obj)..."), this); - connect(m_exportModelAction, &QAction::triggered, this, &SkeletonDocumentWindow::exportModelResult, Qt::QueuedConnection); - m_exportMenu->addAction(m_exportModelAction); + m_exportAsObjAction = new QAction(tr("Wavefront (.obj)..."), this); + connect(m_exportAsObjAction, &QAction::triggered, this, &SkeletonDocumentWindow::exportObjResult, Qt::QueuedConnection); + m_exportMenu->addAction(m_exportAsObjAction); + + m_exportAsObjPlusMaterialsAction = new QAction(tr("Wavefront (.obj + .mtl)..."), this); + connect(m_exportAsObjPlusMaterialsAction, &QAction::triggered, this, &SkeletonDocumentWindow::exportObjPlusMaterialsResult, Qt::QueuedConnection); + m_exportMenu->addAction(m_exportAsObjPlusMaterialsAction); - m_exportSkeletonAction = new QAction(tr("GL Transmission Format (.gltf)..."), this); - connect(m_exportSkeletonAction, &QAction::triggered, this, &SkeletonDocumentWindow::showExportPreview, Qt::QueuedConnection); - m_exportMenu->addAction(m_exportSkeletonAction); + m_exportAsGltfAction = new QAction(tr("GL Transmission Format (.gltf)..."), this); + connect(m_exportAsGltfAction, &QAction::triggered, this, &SkeletonDocumentWindow::showExportPreview, Qt::QueuedConnection); + m_exportMenu->addAction(m_exportAsGltfAction); m_fileMenu->addSeparator(); @@ -267,8 +271,9 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : m_fileMenu->addSeparator(); connect(m_fileMenu, &QMenu::aboutToShow, [=]() { - m_exportModelAction->setEnabled(m_graphicsWidget->hasItems()); - m_exportSkeletonAction->setEnabled(m_graphicsWidget->hasItems()); + m_exportAsObjAction->setEnabled(m_graphicsWidget->hasItems()); + m_exportAsObjPlusMaterialsAction->setEnabled(m_graphicsWidget->hasItems()); + m_exportAsGltfAction->setEnabled(m_graphicsWidget->hasItems()); }); m_editMenu = menuBar()->addMenu(tr("Edit")); @@ -930,7 +935,7 @@ void SkeletonDocumentWindow::open() setCurrentFilename(filename); } -void SkeletonDocumentWindow::exportModelResult() +void SkeletonDocumentWindow::exportObjResult() { QString filename = QFileDialog::getSaveFileName(this, QString(), QString(), tr("Wavefront (*.obj)")); @@ -938,12 +943,22 @@ void SkeletonDocumentWindow::exportModelResult() return; } QApplication::setOverrideCursor(Qt::WaitCursor); - // Must update mesh before export, because there may be an animation clip playing which breaks the original mesh. - m_modelRenderWidget->updateMesh(m_document->takeResultMesh()); m_modelRenderWidget->exportMeshAsObj(filename); QApplication::restoreOverrideCursor(); } +void SkeletonDocumentWindow::exportObjPlusMaterialsResult() +{ + QString filename = QFileDialog::getSaveFileName(this, QString(), QString(), + tr("Wavefront (*.obj)")); + if (filename.isEmpty()) { + return; + } + QApplication::setOverrideCursor(Qt::WaitCursor); + m_modelRenderWidget->exportMeshAsObjPlusMaterials(filename); + QApplication::restoreOverrideCursor(); +} + void SkeletonDocumentWindow::showExportPreview() { if (nullptr == m_exportPreviewWidget) { diff --git a/src/skeletondocumentwindow.h b/src/skeletondocumentwindow.h index d72dc87b..260b825a 100644 --- a/src/skeletondocumentwindow.h +++ b/src/skeletondocumentwindow.h @@ -34,7 +34,8 @@ public slots: void save(); void saveTo(const QString &saveAsFilename); void open(); - void exportModelResult(); + void exportObjResult(); + void exportObjPlusMaterialsResult(); void exportGltfResult(); void showExportPreview(); void newWindow(); @@ -77,8 +78,9 @@ private: QMenu *m_exportMenu; QAction *m_changeTurnaroundAction; - QAction *m_exportModelAction; - QAction *m_exportSkeletonAction; + QAction *m_exportAsObjAction; + QAction *m_exportAsObjPlusMaterialsAction; + QAction *m_exportAsGltfAction; QMenu *m_editMenu; QAction *m_addAction;