diff --git a/application/sources/document_window.cc b/application/sources/document_window.cc index 311095e8..03b02acb 100644 --- a/application/sources/document_window.cc +++ b/application/sources/document_window.cc @@ -706,13 +706,15 @@ DocumentWindow::DocumentWindow() void DocumentWindow::updateInprogressIndicator() { - if (m_document->isMeshGenerating() || - m_document->isPostProcessing() || - m_document->isTextureGenerating()) { - m_inprogressIndicator->showSpinner(true); - } else { - m_inprogressIndicator->showSpinner(false); - } + bool inprogress = m_document->isMeshGenerating() || + m_document->isPostProcessing() || + m_document->isTextureGenerating() || + nullptr != m_componentPreviewImagesGenerator || + nullptr != m_componentPreviewImagesDecorator; + if (inprogress == m_inprogressIndicator->isSpinning()) + return; + m_inprogressIndicator->showSpinner(inprogress); + emit workingStatusChanged(inprogress); } void DocumentWindow::toggleRotation() @@ -1211,6 +1213,8 @@ void DocumentWindow::generateComponentPreviewImages() connect(m_componentPreviewImagesGenerator, &MeshPreviewImagesGenerator::finished, thread, &QThread::quit); connect(thread, &QThread::finished, thread, &QThread::deleteLater); thread->start(); + + updateInprogressIndicator(); } void DocumentWindow::componentPreviewImagesReady() @@ -1230,6 +1234,8 @@ void DocumentWindow::componentPreviewImagesReady() if (m_isComponentPreviewImagesObsolete) generateComponentPreviewImages(); + else + updateInprogressIndicator(); } void DocumentWindow::decorateComponentPreviewImages() @@ -1263,6 +1269,8 @@ void DocumentWindow::decorateComponentPreviewImages() connect(m_componentPreviewImagesDecorator.get(), &ComponentPreviewImagesDecorator::finished, thread, &QThread::quit); connect(thread, &QThread::finished, thread, &QThread::deleteLater); thread->start(); + + updateInprogressIndicator(); } void DocumentWindow::componentPreviewImageDecorationsReady() @@ -1280,6 +1288,8 @@ void DocumentWindow::componentPreviewImageDecorationsReady() if (m_isComponentPreviewImageDecorationsObsolete) decorateComponentPreviewImages(); + else + updateInprogressIndicator(); } ModelWidget *DocumentWindow::modelWidget() @@ -1394,4 +1404,9 @@ void DocumentWindow::updateRecentFileActions() QString DocumentWindow::strippedName(const QString &fullFileName) { return QFileInfo(fullFileName).fileName(); -} \ No newline at end of file +} + +bool DocumentWindow::isWorking() +{ + return nullptr == m_inprogressIndicator || m_inprogressIndicator->isSpinning(); +} diff --git a/application/sources/document_window.h b/application/sources/document_window.h index 1376a437..d6ca8d03 100644 --- a/application/sources/document_window.h +++ b/application/sources/document_window.h @@ -30,11 +30,13 @@ signals: void initialized(); void uninialized(); void waitingExportFinished(const QString &filename, bool isSuccessful); + void workingStatusChanged(bool isWorking); public: DocumentWindow(); ~DocumentWindow(); Document *document(); ModelWidget *modelWidget(); + bool isWorking(); static DocumentWindow *createDocumentWindow(); static const std::map &documentWindows(); static void showAcknowlegements(); diff --git a/application/sources/main.cc b/application/sources/main.cc index 60b06c61..8abd9fca 100644 --- a/application/sources/main.cc +++ b/application/sources/main.cc @@ -4,6 +4,7 @@ #include #include #include "document_window.h" +#include "document.h" #include "theme.h" #include "version.h" @@ -25,7 +26,81 @@ int main(int argc, char *argv[]) //freopen("dust3d.log", "w", stdout); //setvbuf(stdout, 0, _IONBF, 0); - DocumentWindow::createDocumentWindow(); + DocumentWindow *firstWindow = DocumentWindow::createDocumentWindow(); + + QStringList openFileList; + QStringList waitingExportList; + for (int i = 1; i < argc; ++i) { + if ('-' == argv[i][0]) { + if (0 == strcmp(argv[i], "-output") || + 0 == strcmp(argv[i], "-o")) { + ++i; + if (i < argc) + waitingExportList.append(argv[i]); + continue; + } + qDebug() << "Unknown option:" << argv[i]; + continue; + } + QString arg = argv[i]; + if (arg.endsWith(".ds3")) { + openFileList.append(arg); + continue; + } + } + + int finishedExportFileNum = 0; + int totalExportFileNum = 0; + int succeedExportNum = 0; + int exitCode = -1; + std::vector windowList; + auto checkToSafelyExit = [&]() { + if (-1 == exitCode) + return; + for (int i = 0; i < openFileList.size(); ++i) { + if (windowList[i]->isWorking()) + return; + } + app.exit(exitCode); + }; + if (!openFileList.empty()) { + windowList.push_back(firstWindow); + for (int i = 1; i < openFileList.size(); ++i) { + windowList.push_back(DocumentWindow::createDocumentWindow()); + } + if (!waitingExportList.empty() && + openFileList.size() == 1) { + totalExportFileNum = openFileList.size() * waitingExportList.size(); + for (int i = 0; i < openFileList.size(); ++i) { + QObject::connect(windowList[i], &DocumentWindow::workingStatusChanged, &app, checkToSafelyExit); + } + for (int i = 0; i < openFileList.size(); ++i) { + QObject::connect(windowList[i], &DocumentWindow::waitingExportFinished, &app, [&](const QString &filename, bool isSuccessful) { + qDebug() << "Export to" << filename << (isSuccessful ? "isSuccessful" : "failed"); + ++finishedExportFileNum; + if (isSuccessful) + ++succeedExportNum; + if (finishedExportFileNum == totalExportFileNum) { + if (succeedExportNum == totalExportFileNum) { + exitCode = 0; + checkToSafelyExit(); + return; + } + exitCode = 1; + checkToSafelyExit(); + return; + } + }); + } + for (int i = 0; i < openFileList.size(); ++i) { + QObject::connect(windowList[i]->document(), &Document::exportReady, windowList[i], &DocumentWindow::checkExportWaitingList); + windowList[i]->setExportWaitingList(waitingExportList); + } + } + for (int i = 0; i < openFileList.size(); ++i) { + windowList[i]->openPathAs(openFileList[i], openFileList[i]); + } + } return app.exec(); } diff --git a/application/sources/model_mesh.h b/application/sources/model_mesh.h index 044b9c82..e8962334 100644 --- a/application/sources/model_mesh.h +++ b/application/sources/model_mesh.h @@ -18,7 +18,7 @@ public: const std::vector> &triangleVertexNormals, const dust3d::Color &color=dust3d::Color::createWhite(), float metalness=0.0, - float roughness=0.0, + float roughness=1.0, const std::vector> *vertexProperties=nullptr); ModelMesh(dust3d::Object &object); ModelMesh(ModelOpenGLVertex *triangleVertices, int vertexNum);