Skip to content

Commit

Permalink
Remove mesh result post processor
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Dec 10, 2022
1 parent 69ad532 commit f8b2004
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 156 deletions.
2 changes: 0 additions & 2 deletions application/application.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 16 additions & 60 deletions application/sources/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QApplication>
#include <QClipboard>
Expand Down Expand Up @@ -2167,19 +2166,13 @@ void Document::meshReady()

qDebug() << "Mesh generation done";

m_isPostProcessResultObsolete = true;
emit resultMeshChanged();

if (m_isResultMeshObsolete) {
generateMesh();
}
}

bool Document::isPostProcessResultObsolete() const
{
return m_isPostProcessResultObsolete;
}

void Document::batchChangeBegin()
{
m_batchChangeRefCount++;
Expand Down Expand Up @@ -2257,12 +2250,15 @@ void Document::generateTexture()
return;
}

qDebug() << "Texture guide generating..";
emit textureGenerating();

m_isTextureObsolete = false;

auto object = std::make_unique<dust3d::Object>(*m_uvMappedObject);
if (nullptr == m_currentObject)
return;

qDebug() << "UV mapping generating..";
emit textureGenerating();

auto object = std::make_unique<dust3d::Object>(*m_currentObject);

auto snapshot = std::make_unique<dust3d::Snapshot>();
toSnapshot(snapshot.get());
Expand Down Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -3065,9 +3018,12 @@ void Document::generateBone()

m_isResultBoneObsolete = false;

if (nullptr == m_currentObject)
return;

emit boneGenerating();

auto object = std::make_unique<dust3d::Object>(*m_uvMappedObject);
auto object = std::make_unique<dust3d::Object>(*m_currentObject);

auto snapshot = std::make_unique<dust3d::Snapshot>();
toSnapshot(snapshot.get());
Expand Down
12 changes: 2 additions & 10 deletions application/sources/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

class UvMapGenerator;
class MeshGenerator;
class MeshResultPostProcessor;
class BoneGenerator;

class Document : public QObject {
Expand Down Expand Up @@ -230,7 +229,6 @@ class Document : public QObject {
void turnaroundChanged();
void editModeChanged();
void resultTextureChanged();
void postProcessedResultChanged();
void partSubdivStateChanged(dust3d::Uuid partId);
void partXmirrorStateChanged(dust3d::Uuid partId);
void partDeformThicknessChanged(dust3d::Uuid partId);
Expand Down Expand Up @@ -260,7 +258,6 @@ class Document : public QObject {
void checkNode(dust3d::Uuid nodeId);
void checkEdge(dust3d::Uuid edgeId);
void meshGenerating();
void postProcessing();
void textureGenerating();
void textureChanged();
void partAdded(dust3d::Uuid partId);
Expand Down Expand Up @@ -361,6 +358,7 @@ class Document : public QObject {
quint64 resultTextureMeshId();
ModelMesh* takeResultBodyBonePreviewMesh();
quint64 resultBodyBonePreviewMeshId();
quint64 resultTextureImageUpdateVersion();
void updateTurnaround(const QImage& image);
void clearTurnaround();
void updateTextureImage(QImage* image);
Expand All @@ -370,9 +368,7 @@ class Document : public QObject {
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<QString>& cutFaces) const;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -571,11 +565,9 @@ public slots:
dust3d::Object* m_currentObject = nullptr;
bool m_isTextureObsolete = false;
UvMapGenerator* m_textureGenerator = nullptr;
bool m_isPostProcessResultObsolete = false;
MeshResultPostProcessor* m_postProcessor = nullptr;
std::unique_ptr<dust3d::Object> m_uvMappedObject = std::make_unique<dust3d::Object>();
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;
Expand Down
22 changes: 12 additions & 10 deletions application/sources/document_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions application/sources/document_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public slots:
bool m_isLastMeshGenerationSucceed = true;
qint64 m_currentUpdatedMeshId = 0;
quint64 m_currentUpdatedWireframeId = 0;
quint64 m_currentTextureImageUpdateVersion = 0;
QStringList m_waitingForExportToFilenames;

QString m_currentFilename;
Expand Down
50 changes: 0 additions & 50 deletions application/sources/mesh_result_post_processor.cc

This file was deleted.

23 changes: 0 additions & 23 deletions application/sources/mesh_result_post_processor.h

This file was deleted.

2 changes: 1 addition & 1 deletion dust3d/rig/bone_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void BoneGenerator::generateBonePreviews()
}
}
}
std::vector<Color> bodyVertexColors(m_vertices.size());
std::vector<Color> 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)
Expand Down

0 comments on commit f8b2004

Please sign in to comment.