diff --git a/application/application.pro b/application/application.pro index 58c79bd8..1c91db3b 100644 --- a/application/application.pro +++ b/application/application.pro @@ -161,8 +161,6 @@ HEADERS += sources/mesh_generator.h SOURCES += sources/mesh_generator.cc HEADERS += sources/mesh_preview_images_generator.h SOURCES += sources/mesh_preview_images_generator.cc -HEADERS += sources/mesh_result_post_processor.h -SOURCES += sources/mesh_result_post_processor.cc HEADERS += sources/model_mesh.h SOURCES += sources/model_mesh.cc HEADERS += sources/model_offscreen_render.h diff --git a/application/sources/document.cc b/application/sources/document.cc index 5931e921..34d7fe09 100644 --- a/application/sources/document.cc +++ b/application/sources/document.cc @@ -2,7 +2,6 @@ #include "bone_generator.h" #include "image_forever.h" #include "mesh_generator.h" -#include "mesh_result_post_processor.h" #include "uv_map_generator.h" #include #include @@ -2167,7 +2166,6 @@ void Document::meshReady() qDebug() << "Mesh generation done"; - m_isPostProcessResultObsolete = true; emit resultMeshChanged(); if (m_isResultMeshObsolete) { @@ -2175,11 +2173,6 @@ void Document::meshReady() } } -bool Document::isPostProcessResultObsolete() const -{ - return m_isPostProcessResultObsolete; -} - void Document::batchChangeBegin() { m_batchChangeRefCount++; @@ -2257,12 +2250,15 @@ void Document::generateTexture() return; } - qDebug() << "Texture guide generating.."; - emit textureGenerating(); - m_isTextureObsolete = false; - auto object = std::make_unique(*m_uvMappedObject); + if (nullptr == m_currentObject) + return; + + qDebug() << "UV mapping generating.."; + emit textureGenerating(); + + auto object = std::make_unique(*m_currentObject); auto snapshot = std::make_unique(); toSnapshot(snapshot.get()); @@ -2298,7 +2294,7 @@ void Document::textureReady() delete m_textureGenerator; m_textureGenerator = nullptr; - qDebug() << "Texture guide generation done"; + qDebug() << "UV mapping generation done(meshId:" << (nullptr != m_resultTextureMesh ? m_resultTextureMesh->meshId() : 0) << ")"; emit resultTextureChanged(); @@ -2309,47 +2305,9 @@ void Document::textureReady() } } -void Document::postProcess() +quint64 Document::resultTextureImageUpdateVersion() { - if (nullptr != m_postProcessor) { - m_isPostProcessResultObsolete = true; - return; - } - - m_isPostProcessResultObsolete = false; - - if (!m_currentObject) { - qDebug() << "Model is null"; - return; - } - - qDebug() << "Post processing.."; - emit postProcessing(); - - QThread* thread = new QThread; - m_postProcessor = new MeshResultPostProcessor(*m_currentObject); - m_postProcessor->moveToThread(thread); - connect(thread, &QThread::started, m_postProcessor, &MeshResultPostProcessor::process); - connect(m_postProcessor, &MeshResultPostProcessor::finished, this, &Document::postProcessedMeshResultReady); - connect(m_postProcessor, &MeshResultPostProcessor::finished, thread, &QThread::quit); - connect(thread, &QThread::finished, thread, &QThread::deleteLater); - thread->start(); -} - -void Document::postProcessedMeshResultReady() -{ - m_uvMappedObject.reset(m_postProcessor->takePostProcessedObject()); - - delete m_postProcessor; - m_postProcessor = nullptr; - - qDebug() << "Post process done"; - - emit postProcessedResultChanged(); - - if (m_isPostProcessResultObsolete) { - postProcess(); - } + return m_textureImageUpdateVersion; } const dust3d::Object& Document::currentUvMappedObject() const @@ -2797,10 +2755,10 @@ bool Document::isEdgeEditable(dust3d::Uuid edgeId) const bool Document::isExportReady() const { - if (m_meshGenerator || m_textureGenerator || m_postProcessor) + if (m_meshGenerator || m_textureGenerator || m_boneGenerator) return false; - if (m_isResultMeshObsolete || m_isTextureObsolete || m_isPostProcessResultObsolete) + if (m_isResultMeshObsolete || m_isTextureObsolete || m_isResultBoneObsolete) return false; return true; @@ -2817,11 +2775,6 @@ bool Document::isMeshGenerating() const return nullptr != m_meshGenerator; } -bool Document::isPostProcessing() const -{ - return nullptr != m_postProcessor; -} - bool Document::isTextureGenerating() const { return nullptr != m_textureGenerator; @@ -3065,9 +3018,12 @@ void Document::generateBone() m_isResultBoneObsolete = false; + if (nullptr == m_currentObject) + return; + emit boneGenerating(); - auto object = std::make_unique(*m_uvMappedObject); + auto object = std::make_unique(*m_currentObject); auto snapshot = std::make_unique(); toSnapshot(snapshot.get()); diff --git a/application/sources/document.h b/application/sources/document.h index 1fc76582..3625b9f7 100644 --- a/application/sources/document.h +++ b/application/sources/document.h @@ -23,7 +23,6 @@ class UvMapGenerator; class MeshGenerator; -class MeshResultPostProcessor; class BoneGenerator; class Document : public QObject { @@ -230,7 +229,6 @@ signals: void turnaroundChanged(); void editModeChanged(); void resultTextureChanged(); - void postProcessedResultChanged(); void partSubdivStateChanged(dust3d::Uuid partId); void partXmirrorStateChanged(dust3d::Uuid partId); void partDeformThicknessChanged(dust3d::Uuid partId); @@ -260,7 +258,6 @@ signals: void checkNode(dust3d::Uuid nodeId); void checkEdge(dust3d::Uuid edgeId); void meshGenerating(); - void postProcessing(); void textureGenerating(); void textureChanged(); void partAdded(dust3d::Uuid partId); @@ -361,6 +358,7 @@ public: quint64 resultTextureMeshId(); ModelMesh* takeResultBodyBonePreviewMesh(); quint64 resultBodyBonePreviewMeshId(); + quint64 resultTextureImageUpdateVersion(); void updateTurnaround(const QImage& image); void clearTurnaround(); void updateTextureImage(QImage* image); @@ -370,9 +368,7 @@ public: void updateTextureAmbientOcclusionImage(QImage* image); const dust3d::Object& currentUvMappedObject() const; bool isExportReady() const; - bool isPostProcessResultObsolete() const; bool isMeshGenerating() const; - bool isPostProcessing() const; bool isTextureGenerating() const; bool isBoneGenerating() const; void collectCutFaceList(std::vector& cutFaces) const; @@ -451,8 +447,6 @@ public slots: void meshReady(); void generateTexture(); void textureReady(); - void postProcess(); - void postProcessedMeshResultReady(); void generateBone(); void boneReady(); void setPartSubdivState(dust3d::Uuid partId, bool subdived); @@ -571,11 +565,9 @@ private: dust3d::Object* m_currentObject = nullptr; bool m_isTextureObsolete = false; UvMapGenerator* m_textureGenerator = nullptr; - bool m_isPostProcessResultObsolete = false; - MeshResultPostProcessor* m_postProcessor = nullptr; std::unique_ptr m_uvMappedObject = std::make_unique(); ModelMesh* m_resultTextureMesh = nullptr; - unsigned long long m_textureImageUpdateVersion = 0; + quint64 m_textureImageUpdateVersion = 0; bool m_smoothNormal = false; quint64 m_meshGenerationId = 0; quint64 m_nextMeshGenerationId = 0; diff --git a/application/sources/document_window.cc b/application/sources/document_window.cc index 446f213f..f61ae663 100644 --- a/application/sources/document_window.cc +++ b/application/sources/document_window.cc @@ -205,10 +205,8 @@ DocumentWindow::DocumentWindow() connect(m_document, &Document::resultBodyBonePreviewMeshChanged, this, &DocumentWindow::updateInprogressIndicator); connect(m_document, &Document::resultComponentPreviewMeshesChanged, this, &DocumentWindow::generateComponentPreviewImages); connect(m_document, &Document::textureChanged, this, &DocumentWindow::generateComponentPreviewImages); - connect(m_document, &Document::postProcessing, this, &DocumentWindow::updateInprogressIndicator); connect(m_document, &Document::textureGenerating, this, &DocumentWindow::updateInprogressIndicator); connect(m_document, &Document::resultTextureChanged, this, &DocumentWindow::updateInprogressIndicator); - connect(m_document, &Document::postProcessedResultChanged, this, &DocumentWindow::updateInprogressIndicator); connect(m_document, &Document::boneGenerating, this, &DocumentWindow::updateInprogressIndicator); connect(m_document, &Document::resultBoneChanged, this, &DocumentWindow::updateInprogressIndicator); connect(m_document, &Document::resultBonePreviewMeshesChanged, this, &DocumentWindow::generateBonePreviewImages); @@ -634,10 +632,9 @@ DocumentWindow::DocumentWindow() connect(m_document, &Document::skeletonChanged, m_document, &Document::generateMesh); connect(m_document, &Document::textureChanged, m_document, &Document::generateTexture); - connect(m_document, &Document::resultMeshChanged, m_document, &Document::postProcess); - connect(m_document, &Document::postProcessedResultChanged, m_document, &Document::generateTexture); + connect(m_document, &Document::resultMeshChanged, m_document, &Document::generateTexture); connect(m_document, &Document::rigChanged, m_document, &Document::generateBone); - connect(m_document, &Document::postProcessedResultChanged, m_document, &Document::generateBone); + connect(m_document, &Document::resultMeshChanged, m_document, &Document::generateBone); connect(m_document, &Document::resultTextureChanged, this, &DocumentWindow::updateRenderModel); connect(m_document, &Document::resultBodyBonePreviewMeshChanged, this, &DocumentWindow::updateRenderModel); @@ -680,7 +677,7 @@ DocumentWindow::DocumentWindow() void DocumentWindow::updateInprogressIndicator() { - bool inprogress = m_document->isMeshGenerating() || m_document->isPostProcessing() || m_document->isTextureGenerating() || m_document->isBoneGenerating() || nullptr != m_componentPreviewImagesGenerator || nullptr != m_componentPreviewImagesDecorator; + bool inprogress = m_document->isMeshGenerating() || m_document->isTextureGenerating() || m_document->isBoneGenerating() || nullptr != m_componentPreviewImagesGenerator || nullptr != m_componentPreviewImagesDecorator; if (inprogress == m_inprogressIndicator->isSpinning()) return; m_inprogressIndicator->showSpinner(inprogress); @@ -1460,12 +1457,13 @@ void DocumentWindow::forceUpdateRenderModel() mesh = m_document->takeResultBodyBonePreviewMesh(); m_currentUpdatedMeshId = m_document->resultBodyBonePreviewMeshId(); } else { - if (m_document->isMeshGenerating() || m_document->isPostProcessing() || m_document->isTextureGenerating()) { + if (m_document->isMeshGenerating() || m_document->isTextureGenerating()) { mesh = m_document->takeResultMesh(); m_currentUpdatedMeshId = m_document->resultMeshId(); } else { mesh = m_document->takeResultTextureMesh(); m_currentUpdatedMeshId = m_document->resultTextureMeshId(); + m_currentTextureImageUpdateVersion = m_document->resultTextureImageUpdateVersion(); } if (m_modelRemoveColor && mesh) mesh->removeColor(); @@ -1476,15 +1474,19 @@ void DocumentWindow::forceUpdateRenderModel() void DocumentWindow::updateRenderModel() { qint64 shouldShowId = 0; - if (m_document->isMeshGenerating() || m_document->isPostProcessing() || m_document->isTextureGenerating()) { + quint64 shouldShowTextureVersion = m_currentTextureImageUpdateVersion; + if (m_document->isMeshGenerating() || m_document->isTextureGenerating()) { shouldShowId = m_document->resultMeshId(); } else { shouldShowId = -(qint64)m_document->resultTextureMeshId(); + shouldShowTextureVersion = m_document->resultTextureImageUpdateVersion(); } - if (shouldShowId == m_currentUpdatedMeshId) + if (shouldShowId == m_currentUpdatedMeshId && shouldShowTextureVersion == m_currentTextureImageUpdateVersion) { return; - if (std::abs(shouldShowId) < std::abs(m_currentUpdatedMeshId)) + } + if (std::abs(shouldShowId) < std::abs(m_currentUpdatedMeshId)) { return; + } forceUpdateRenderModel(); } diff --git a/application/sources/document_window.h b/application/sources/document_window.h index 1cfce786..3ba038a1 100644 --- a/application/sources/document_window.h +++ b/application/sources/document_window.h @@ -119,6 +119,7 @@ private: bool m_isLastMeshGenerationSucceed = true; qint64 m_currentUpdatedMeshId = 0; quint64 m_currentUpdatedWireframeId = 0; + quint64 m_currentTextureImageUpdateVersion = 0; QStringList m_waitingForExportToFilenames; QString m_currentFilename; diff --git a/application/sources/mesh_result_post_processor.cc b/application/sources/mesh_result_post_processor.cc deleted file mode 100644 index 3ae71225..00000000 --- a/application/sources/mesh_result_post_processor.cc +++ /dev/null @@ -1,50 +0,0 @@ -#include "mesh_result_post_processor.h" -#include -#include - -MeshResultPostProcessor::MeshResultPostProcessor(const dust3d::Object& object) -{ - m_object = new dust3d::Object; - *m_object = object; -} - -MeshResultPostProcessor::~MeshResultPostProcessor() -{ - delete m_object; -} - -dust3d::Object* MeshResultPostProcessor::takePostProcessedObject() -{ - dust3d::Object* object = m_object; - m_object = nullptr; - return object; -} - -void MeshResultPostProcessor::poseProcess() -{ - //if (!m_object->nodes.empty()) { - /* - { - std::vector> triangleVertexUvs; - std::set seamVertices; - std::map> partUvRects; - dust3d::unwrapUv(*m_object, triangleVertexUvs, seamVertices, partUvRects); - m_object->setTriangleVertexUvs(triangleVertexUvs); - m_object->setPartUvRects(partUvRects); - } - - { - std::vector triangleTangents; - dust3d::resolveTriangleTangent(*m_object, triangleTangents); - m_object->setTriangleTangents(triangleTangents); - } - */ - //} -} - -void MeshResultPostProcessor::process() -{ - poseProcess(); - - emit finished(); -} diff --git a/application/sources/mesh_result_post_processor.h b/application/sources/mesh_result_post_processor.h deleted file mode 100644 index cfe041bf..00000000 --- a/application/sources/mesh_result_post_processor.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef DUST3D_APPLICATION_MESH_RESULT_POST_PROCESSOR_H_ -#define DUST3D_APPLICATION_MESH_RESULT_POST_PROCESSOR_H_ - -#include -#include - -class MeshResultPostProcessor : public QObject { - Q_OBJECT -public: - MeshResultPostProcessor(const dust3d::Object& object); - ~MeshResultPostProcessor(); - dust3d::Object* takePostProcessedObject(); - void poseProcess(); -signals: - void finished(); -public slots: - void process(); - -private: - dust3d::Object* m_object = nullptr; -}; - -#endif diff --git a/dust3d/rig/bone_generator.cc b/dust3d/rig/bone_generator.cc index 81039bf9..2760a805 100644 --- a/dust3d/rig/bone_generator.cc +++ b/dust3d/rig/bone_generator.cc @@ -275,7 +275,7 @@ void BoneGenerator::generateBonePreviews() } } } - std::vector bodyVertexColors(m_vertices.size()); + std::vector bodyVertexColors(m_vertices.size(), Color(0.0, 0.0, 0.0, 0.0)); for (const auto& it : vertexSkinColors) { Color color; for (const auto& colorIt : it.second)