From 7ade61ab654c2f176bbd7bbf65c86a3b941c3ca4 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 5 Jan 2020 14:35:07 +0930 Subject: [PATCH] Add rendered model color toggle --- languages/dust3d_zh_CN.ts | 12 ++++++++---- src/documentwindow.cpp | 23 ++++++++++++++++++++++- src/documentwindow.h | 2 ++ src/meshloader.cpp | 23 +++++++++++++++++++++++ src/meshloader.h | 1 + 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/languages/dust3d_zh_CN.ts b/languages/dust3d_zh_CN.ts index b9aee422..95458196 100644 --- a/languages/dust3d_zh_CN.ts +++ b/languages/dust3d_zh_CN.ts @@ -330,10 +330,6 @@ Tips: Toggle UV Check 切换UV检查 - - Toggle rotation - 旋转视角 - Colorize 着色 @@ -394,6 +390,14 @@ Tips: Toggle Rotation 打开/关闭自动旋转 + + Toggle viewport + 切换视图 + + + Toggle Color + 打开/关闭颜色 + ExportPreviewWidget diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 53fbde30..cf62e4c6 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -179,7 +179,7 @@ DocumentWindow::DocumentWindow() : Theme::initAwesomeButton(zoomOutButton); m_rotationButton = new QPushButton(QChar(fa::caretsquareoup)); - m_rotationButton->setToolTip(tr("Toggle rotation")); + m_rotationButton->setToolTip(tr("Toggle viewport")); Theme::initAwesomeButton(m_rotationButton); updateRotationButtonState(); @@ -733,6 +733,23 @@ DocumentWindow::DocumentWindow() : }); m_viewMenu->addAction(m_toggleRotationAction); + m_toggleColorAction = new QAction(tr("Toggle Color"), this); + connect(m_toggleColorAction, &QAction::triggered, [&]() { + m_modelRemoveColor = !m_modelRemoveColor; + MeshLoader *mesh = nullptr; + if (m_document->isMeshGenerating() && + m_document->isPostProcessing() && + m_document->isTextureGenerating()) { + mesh = m_document->takeResultMesh(); + } else { + mesh = m_document->takeResultTextureMesh(); + } + if (m_modelRemoveColor && mesh) + mesh->removeColor(); + m_modelRenderWidget->updateMesh(mesh); + }); + m_viewMenu->addAction(m_toggleColorAction); + m_toggleUvCheckAction = new QAction(tr("Toggle UV Check"), this); connect(m_toggleUvCheckAction, &QAction::triggered, [=]() { m_modelRenderWidget->toggleUvCheck(); @@ -1080,6 +1097,8 @@ DocumentWindow::DocumentWindow() : return; } } + if (m_modelRemoveColor && resultTextureMesh) + resultTextureMesh->removeColor(); m_modelRenderWidget->updateMesh(resultTextureMesh); }); @@ -1087,6 +1106,8 @@ DocumentWindow::DocumentWindow() : auto resultMesh = m_document->takeResultMesh(); if (nullptr != resultMesh) m_currentUpdatedMeshId = resultMesh->meshId(); + if (m_modelRemoveColor && resultMesh) + resultMesh->removeColor(); m_modelRenderWidget->updateMesh(resultMesh); }); diff --git a/src/documentwindow.h b/src/documentwindow.h index 0f98e5bf..9a6926ad 100644 --- a/src/documentwindow.h +++ b/src/documentwindow.h @@ -169,6 +169,8 @@ private: QAction *m_toggleWireframeAction; QAction *m_toggleUvCheckAction; QAction *m_toggleRotationAction; + QAction *m_toggleColorAction; + bool m_modelRemoveColor = false; QMenu *m_windowMenu; QAction *m_showPartsListAction; diff --git a/src/meshloader.cpp b/src/meshloader.cpp index 3b8d0155..085e4513 100644 --- a/src/meshloader.cpp +++ b/src/meshloader.cpp @@ -57,6 +57,29 @@ MeshLoader::MeshLoader(const MeshLoader &mesh) : this->m_meshId = mesh.meshId(); } +void MeshLoader::removeColor() +{ + delete this->m_textureImage; + this->m_textureImage = nullptr; + + delete this->m_normalMapImage; + this->m_normalMapImage = nullptr; + + delete this->m_metalnessRoughnessAmbientOcclusionImage; + this->m_metalnessRoughnessAmbientOcclusionImage = nullptr; + + this->m_hasMetalnessInImage = false; + this->m_hasRoughnessInImage = false; + this->m_hasAmbientOcclusionInImage = false; + + for (int i = 0; i < this->m_triangleVertexCount; ++i) { + auto &vertex = this->m_triangleVertices[i]; + vertex.colorR = 1.0; + vertex.colorG = 1.0; + vertex.colorB = 1.0; + } +} + MeshLoader::MeshLoader(ShaderVertex *triangleVertices, int vertexNum, ShaderVertex *edgeVertices, int edgeVertexCount) : m_triangleVertices(triangleVertices), m_triangleVertexCount(vertexNum), diff --git a/src/meshloader.h b/src/meshloader.h index 1ad8e75e..b00b8d92 100644 --- a/src/meshloader.h +++ b/src/meshloader.h @@ -57,6 +57,7 @@ public: void updateTriangleVertices(ShaderVertex *triangleVertices, int triangleVertexCount); quint64 meshId() const; void setMeshId(quint64 id); + void removeColor(); private: ShaderVertex *m_triangleVertices = nullptr; int m_triangleVertexCount = 0;