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
Jeremy Hu 2019-07-10 21:39:46 +09:30
parent c73277a4aa
commit d38737e2cb
9 changed files with 51 additions and 4 deletions

View File

@ -59,7 +59,9 @@ Document::Document() :
m_posePreviewsGenerator(nullptr),
m_currentRigSucceed(false),
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::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange);
@ -1754,6 +1756,7 @@ void Document::generateMesh()
toSnapshot(snapshot);
resetDirtyFlags();
m_meshGenerator = new MeshGenerator(snapshot);
m_meshGenerator->setId(m_nextMeshGenerationId++);
m_meshGenerator->setDefaultPartColor(Preferences::instance().partColor());
m_meshGenerator->setGeneratedCacheContext(&m_generatedCacheContext);
if (!m_smoothNormal) {

View File

@ -689,6 +689,8 @@ private: // need initialize
bool m_currentRigSucceed;
MaterialPreviewsGenerator *m_materialPreviewsGenerator;
MotionsGenerator *m_motionsGenerator;
quint64 m_meshGenerationId;
quint64 m_nextMeshGenerationId;
private:
static unsigned long m_maxSnapshot;
std::deque<HistoryItem> m_undoItems;

View File

@ -118,7 +118,8 @@ DocumentWindow::DocumentWindow() :
m_documentSaved(true),
m_exportPreviewWidget(nullptr),
m_preferencesWidget(nullptr),
m_isLastMeshGenerationSucceed(true)
m_isLastMeshGenerationSucceed(true),
m_currentUpdatedMeshId(0)
{
if (!g_logBrowser) {
g_logBrowser = new LogBrowser;
@ -920,11 +921,21 @@ DocumentWindow::DocumentWindow() :
connect(m_document, &Document::resultTextureChanged, [=]() {
if (m_document->isMeshGenerating())
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, [=]() {
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);

View File

@ -80,6 +80,7 @@ private:
PreferencesWidget *m_preferencesWidget;
std::vector<QWidget *> m_dialogs;
bool m_isLastMeshGenerationSucceed;
quint64 m_currentUpdatedMeshId;
private:
QString m_currentFilename;

View File

@ -31,6 +31,16 @@ MeshGenerator::~MeshGenerator()
delete m_nodesCutFaces;
}
void MeshGenerator::setId(quint64 id)
{
m_id = id;
}
quint64 MeshGenerator::id()
{
return m_id;
}
bool MeshGenerator::isSucceed()
{
return m_isSucceed;
@ -1056,6 +1066,7 @@ void MeshGenerator::generate()
countTimeConsumed.start();
m_outcome = new Outcome;
m_outcome->meshId = m_id;
//m_cutFaceTransforms = new std::map<QUuid, nodemesh::Builder::CutFaceTransform>;
//m_nodesCutFaces = new std::map<QUuid, std::map<QString, QVector2D>>;

View File

@ -66,6 +66,8 @@ public:
void setGeneratedCacheContext(GeneratedCacheContext *cacheContext);
void setSmoothShadingThresholdAngleDegrees(float degrees);
void setDefaultPartColor(const QColor &color);
void setId(quint64 id);
quint64 id();
signals:
void finished();
public slots:
@ -91,6 +93,7 @@ private:
float m_smoothShadingThresholdAngleDegrees = 60;
std::map<QUuid, nodemesh::Builder::CutFaceTransform> *m_cutFaceTransforms = nullptr;
std::map<QUuid, std::map<QString, QVector2D>> *m_nodesCutFaces = nullptr;
quint64 m_id = 0;
void collectParts();
bool checkIsComponentDirty(const QString &componentIdString);

View File

@ -54,6 +54,7 @@ MeshLoader::MeshLoader(const MeshLoader &mesh) :
this->m_faces = mesh.m_faces;
this->m_triangulatedVertices = mesh.m_triangulatedVertices;
this->m_triangulatedFaces = mesh.m_triangulatedFaces;
this->m_meshId = mesh.meshId();
}
MeshLoader::MeshLoader(ShaderVertex *triangleVertices, int vertexNum) :
@ -106,6 +107,7 @@ MeshLoader::MeshLoader(Outcome &outcome) :
m_edgeVertexCount(0),
m_textureImage(nullptr)
{
m_meshId = outcome.meshId;
m_vertices = outcome.vertices;
m_faces = outcome.triangleAndQuads;
@ -349,3 +351,13 @@ void MeshLoader::updateTool(ShaderVertex *toolVertices, int vertexNum)
m_toolVertices = toolVertices;
m_toolVertexCount = vertexNum;
}
quint64 MeshLoader::meshId() const
{
return m_meshId;
}
void MeshLoader::setMeshId(quint64 id)
{
m_meshId = id;
}

View File

@ -54,6 +54,8 @@ public:
void exportAsObj(const QString &filename);
void exportAsObj(QTextStream *textStream);
void updateTool(ShaderVertex *toolVertices, int vertexNum);
quint64 meshId() const;
void setMeshId(quint64 id);
private:
ShaderVertex *m_triangleVertices = nullptr;
int m_triangleVertexCount = 0;
@ -71,6 +73,7 @@ private:
bool m_hasMetalnessInImage = false;
bool m_hasRoughnessInImage = false;
bool m_hasAmbientOcclusionInImage = false;
quint64 m_meshId = 0;
};
#endif

View File

@ -35,6 +35,7 @@ public:
std::vector<std::vector<size_t>> triangles;
std::vector<QVector3D> triangleNormals;
std::vector<QColor> triangleColors;
quint64 meshId = 0;
const std::vector<std::pair<QUuid, QUuid>> *triangleSourceNodes() const
{