Add mtl export with obj

master
Jeremy Hu 2018-09-05 11:14:36 +08:00
parent e0621edff1
commit 87b0f70460
5 changed files with 34 additions and 17 deletions

View File

@ -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) {

View File

@ -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();

View File

@ -296,6 +296,6 @@ void ModelWidget::exportMeshAsObj(const QString &filename)
void ModelWidget::exportMeshAsObjPlusMaterials(const QString &filename)
{
m_meshBinder.exportMeshAdObjPlusMaterials(filename);
m_meshBinder.exportMeshAsObjPlusMaterials(filename);
}

View File

@ -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_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_exportAsObjPlusMaterialsAction = new QAction(tr("Wavefront (.obj + .mtl)..."), this);
connect(m_exportAsObjPlusMaterialsAction, &QAction::triggered, this, &SkeletonDocumentWindow::exportObjPlusMaterialsResult, Qt::QueuedConnection);
m_exportMenu->addAction(m_exportAsObjPlusMaterialsAction);
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) {

View File

@ -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;