Fix mesh preview flashback
Before this commit, outdated textured preview will override the updated untextured preview. From user's perspective, sometimes, the mesh preview flashback for a short time span, although it will finally been updated to the latest.master
parent
c73277a4aa
commit
d38737e2cb
|
@ -59,7 +59,9 @@ Document::Document() :
|
||||||
m_posePreviewsGenerator(nullptr),
|
m_posePreviewsGenerator(nullptr),
|
||||||
m_currentRigSucceed(false),
|
m_currentRigSucceed(false),
|
||||||
m_materialPreviewsGenerator(nullptr),
|
m_materialPreviewsGenerator(nullptr),
|
||||||
m_motionsGenerator(nullptr)
|
m_motionsGenerator(nullptr),
|
||||||
|
m_meshGenerationId(0),
|
||||||
|
m_nextMeshGenerationId(1)
|
||||||
{
|
{
|
||||||
connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange);
|
connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange);
|
||||||
connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange);
|
connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange);
|
||||||
|
@ -1754,6 +1756,7 @@ void Document::generateMesh()
|
||||||
toSnapshot(snapshot);
|
toSnapshot(snapshot);
|
||||||
resetDirtyFlags();
|
resetDirtyFlags();
|
||||||
m_meshGenerator = new MeshGenerator(snapshot);
|
m_meshGenerator = new MeshGenerator(snapshot);
|
||||||
|
m_meshGenerator->setId(m_nextMeshGenerationId++);
|
||||||
m_meshGenerator->setDefaultPartColor(Preferences::instance().partColor());
|
m_meshGenerator->setDefaultPartColor(Preferences::instance().partColor());
|
||||||
m_meshGenerator->setGeneratedCacheContext(&m_generatedCacheContext);
|
m_meshGenerator->setGeneratedCacheContext(&m_generatedCacheContext);
|
||||||
if (!m_smoothNormal) {
|
if (!m_smoothNormal) {
|
||||||
|
|
|
@ -689,6 +689,8 @@ private: // need initialize
|
||||||
bool m_currentRigSucceed;
|
bool m_currentRigSucceed;
|
||||||
MaterialPreviewsGenerator *m_materialPreviewsGenerator;
|
MaterialPreviewsGenerator *m_materialPreviewsGenerator;
|
||||||
MotionsGenerator *m_motionsGenerator;
|
MotionsGenerator *m_motionsGenerator;
|
||||||
|
quint64 m_meshGenerationId;
|
||||||
|
quint64 m_nextMeshGenerationId;
|
||||||
private:
|
private:
|
||||||
static unsigned long m_maxSnapshot;
|
static unsigned long m_maxSnapshot;
|
||||||
std::deque<HistoryItem> m_undoItems;
|
std::deque<HistoryItem> m_undoItems;
|
||||||
|
|
|
@ -118,7 +118,8 @@ DocumentWindow::DocumentWindow() :
|
||||||
m_documentSaved(true),
|
m_documentSaved(true),
|
||||||
m_exportPreviewWidget(nullptr),
|
m_exportPreviewWidget(nullptr),
|
||||||
m_preferencesWidget(nullptr),
|
m_preferencesWidget(nullptr),
|
||||||
m_isLastMeshGenerationSucceed(true)
|
m_isLastMeshGenerationSucceed(true),
|
||||||
|
m_currentUpdatedMeshId(0)
|
||||||
{
|
{
|
||||||
if (!g_logBrowser) {
|
if (!g_logBrowser) {
|
||||||
g_logBrowser = new LogBrowser;
|
g_logBrowser = new LogBrowser;
|
||||||
|
@ -920,11 +921,21 @@ DocumentWindow::DocumentWindow() :
|
||||||
connect(m_document, &Document::resultTextureChanged, [=]() {
|
connect(m_document, &Document::resultTextureChanged, [=]() {
|
||||||
if (m_document->isMeshGenerating())
|
if (m_document->isMeshGenerating())
|
||||||
return;
|
return;
|
||||||
m_modelRenderWidget->updateMesh(m_document->takeResultTextureMesh());
|
auto resultTextureMesh = m_document->takeResultTextureMesh();
|
||||||
|
if (nullptr != resultTextureMesh) {
|
||||||
|
if (resultTextureMesh->meshId() < m_currentUpdatedMeshId) {
|
||||||
|
delete resultTextureMesh;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_modelRenderWidget->updateMesh(resultTextureMesh);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_document, &Document::resultMeshChanged, [=]() {
|
connect(m_document, &Document::resultMeshChanged, [=]() {
|
||||||
m_modelRenderWidget->updateMesh(m_document->takeResultMesh());
|
auto resultMesh = m_document->takeResultMesh();
|
||||||
|
if (nullptr != resultMesh)
|
||||||
|
m_currentUpdatedMeshId = resultMesh->meshId();
|
||||||
|
m_modelRenderWidget->updateMesh(resultMesh);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_document, &Document::posesChanged, m_document, &Document::generateMotions);
|
connect(m_document, &Document::posesChanged, m_document, &Document::generateMotions);
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
PreferencesWidget *m_preferencesWidget;
|
PreferencesWidget *m_preferencesWidget;
|
||||||
std::vector<QWidget *> m_dialogs;
|
std::vector<QWidget *> m_dialogs;
|
||||||
bool m_isLastMeshGenerationSucceed;
|
bool m_isLastMeshGenerationSucceed;
|
||||||
|
quint64 m_currentUpdatedMeshId;
|
||||||
private:
|
private:
|
||||||
QString m_currentFilename;
|
QString m_currentFilename;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,16 @@ MeshGenerator::~MeshGenerator()
|
||||||
delete m_nodesCutFaces;
|
delete m_nodesCutFaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshGenerator::setId(quint64 id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint64 MeshGenerator::id()
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
bool MeshGenerator::isSucceed()
|
bool MeshGenerator::isSucceed()
|
||||||
{
|
{
|
||||||
return m_isSucceed;
|
return m_isSucceed;
|
||||||
|
@ -1056,6 +1066,7 @@ void MeshGenerator::generate()
|
||||||
countTimeConsumed.start();
|
countTimeConsumed.start();
|
||||||
|
|
||||||
m_outcome = new Outcome;
|
m_outcome = new Outcome;
|
||||||
|
m_outcome->meshId = m_id;
|
||||||
//m_cutFaceTransforms = new std::map<QUuid, nodemesh::Builder::CutFaceTransform>;
|
//m_cutFaceTransforms = new std::map<QUuid, nodemesh::Builder::CutFaceTransform>;
|
||||||
//m_nodesCutFaces = new std::map<QUuid, std::map<QString, QVector2D>>;
|
//m_nodesCutFaces = new std::map<QUuid, std::map<QString, QVector2D>>;
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,8 @@ public:
|
||||||
void setGeneratedCacheContext(GeneratedCacheContext *cacheContext);
|
void setGeneratedCacheContext(GeneratedCacheContext *cacheContext);
|
||||||
void setSmoothShadingThresholdAngleDegrees(float degrees);
|
void setSmoothShadingThresholdAngleDegrees(float degrees);
|
||||||
void setDefaultPartColor(const QColor &color);
|
void setDefaultPartColor(const QColor &color);
|
||||||
|
void setId(quint64 id);
|
||||||
|
quint64 id();
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -91,6 +93,7 @@ private:
|
||||||
float m_smoothShadingThresholdAngleDegrees = 60;
|
float m_smoothShadingThresholdAngleDegrees = 60;
|
||||||
std::map<QUuid, nodemesh::Builder::CutFaceTransform> *m_cutFaceTransforms = nullptr;
|
std::map<QUuid, nodemesh::Builder::CutFaceTransform> *m_cutFaceTransforms = nullptr;
|
||||||
std::map<QUuid, std::map<QString, QVector2D>> *m_nodesCutFaces = nullptr;
|
std::map<QUuid, std::map<QString, QVector2D>> *m_nodesCutFaces = nullptr;
|
||||||
|
quint64 m_id = 0;
|
||||||
|
|
||||||
void collectParts();
|
void collectParts();
|
||||||
bool checkIsComponentDirty(const QString &componentIdString);
|
bool checkIsComponentDirty(const QString &componentIdString);
|
||||||
|
|
|
@ -54,6 +54,7 @@ MeshLoader::MeshLoader(const MeshLoader &mesh) :
|
||||||
this->m_faces = mesh.m_faces;
|
this->m_faces = mesh.m_faces;
|
||||||
this->m_triangulatedVertices = mesh.m_triangulatedVertices;
|
this->m_triangulatedVertices = mesh.m_triangulatedVertices;
|
||||||
this->m_triangulatedFaces = mesh.m_triangulatedFaces;
|
this->m_triangulatedFaces = mesh.m_triangulatedFaces;
|
||||||
|
this->m_meshId = mesh.meshId();
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshLoader::MeshLoader(ShaderVertex *triangleVertices, int vertexNum) :
|
MeshLoader::MeshLoader(ShaderVertex *triangleVertices, int vertexNum) :
|
||||||
|
@ -106,6 +107,7 @@ MeshLoader::MeshLoader(Outcome &outcome) :
|
||||||
m_edgeVertexCount(0),
|
m_edgeVertexCount(0),
|
||||||
m_textureImage(nullptr)
|
m_textureImage(nullptr)
|
||||||
{
|
{
|
||||||
|
m_meshId = outcome.meshId;
|
||||||
m_vertices = outcome.vertices;
|
m_vertices = outcome.vertices;
|
||||||
m_faces = outcome.triangleAndQuads;
|
m_faces = outcome.triangleAndQuads;
|
||||||
|
|
||||||
|
@ -349,3 +351,13 @@ void MeshLoader::updateTool(ShaderVertex *toolVertices, int vertexNum)
|
||||||
m_toolVertices = toolVertices;
|
m_toolVertices = toolVertices;
|
||||||
m_toolVertexCount = vertexNum;
|
m_toolVertexCount = vertexNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quint64 MeshLoader::meshId() const
|
||||||
|
{
|
||||||
|
return m_meshId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshLoader::setMeshId(quint64 id)
|
||||||
|
{
|
||||||
|
m_meshId = id;
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
void exportAsObj(const QString &filename);
|
void exportAsObj(const QString &filename);
|
||||||
void exportAsObj(QTextStream *textStream);
|
void exportAsObj(QTextStream *textStream);
|
||||||
void updateTool(ShaderVertex *toolVertices, int vertexNum);
|
void updateTool(ShaderVertex *toolVertices, int vertexNum);
|
||||||
|
quint64 meshId() const;
|
||||||
|
void setMeshId(quint64 id);
|
||||||
private:
|
private:
|
||||||
ShaderVertex *m_triangleVertices = nullptr;
|
ShaderVertex *m_triangleVertices = nullptr;
|
||||||
int m_triangleVertexCount = 0;
|
int m_triangleVertexCount = 0;
|
||||||
|
@ -71,6 +73,7 @@ private:
|
||||||
bool m_hasMetalnessInImage = false;
|
bool m_hasMetalnessInImage = false;
|
||||||
bool m_hasRoughnessInImage = false;
|
bool m_hasRoughnessInImage = false;
|
||||||
bool m_hasAmbientOcclusionInImage = false;
|
bool m_hasAmbientOcclusionInImage = false;
|
||||||
|
quint64 m_meshId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
std::vector<std::vector<size_t>> triangles;
|
std::vector<std::vector<size_t>> triangles;
|
||||||
std::vector<QVector3D> triangleNormals;
|
std::vector<QVector3D> triangleNormals;
|
||||||
std::vector<QColor> triangleColors;
|
std::vector<QColor> triangleColors;
|
||||||
|
quint64 meshId = 0;
|
||||||
|
|
||||||
const std::vector<std::pair<QUuid, QUuid>> *triangleSourceNodes() const
|
const std::vector<std::pair<QUuid, QUuid>> *triangleSourceNodes() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue