Add rendered model color toggle

master
Jeremy Hu 2020-01-05 14:35:07 +09:30
parent 846270fa80
commit 7ade61ab65
5 changed files with 56 additions and 5 deletions

View File

@ -330,10 +330,6 @@ Tips:
<source>Toggle UV Check</source> <source>Toggle UV Check</source>
<translation>UV</translation> <translation>UV</translation>
</message> </message>
<message>
<source>Toggle rotation</source>
<translation></translation>
</message>
<message> <message>
<source>Colorize</source> <source>Colorize</source>
<translation></translation> <translation></translation>
@ -394,6 +390,14 @@ Tips:
<source>Toggle Rotation</source> <source>Toggle Rotation</source>
<translation>/</translation> <translation>/</translation>
</message> </message>
<message>
<source>Toggle viewport</source>
<translation></translation>
</message>
<message>
<source>Toggle Color</source>
<translation>/</translation>
</message>
</context> </context>
<context> <context>
<name>ExportPreviewWidget</name> <name>ExportPreviewWidget</name>

View File

@ -179,7 +179,7 @@ DocumentWindow::DocumentWindow() :
Theme::initAwesomeButton(zoomOutButton); Theme::initAwesomeButton(zoomOutButton);
m_rotationButton = new QPushButton(QChar(fa::caretsquareoup)); m_rotationButton = new QPushButton(QChar(fa::caretsquareoup));
m_rotationButton->setToolTip(tr("Toggle rotation")); m_rotationButton->setToolTip(tr("Toggle viewport"));
Theme::initAwesomeButton(m_rotationButton); Theme::initAwesomeButton(m_rotationButton);
updateRotationButtonState(); updateRotationButtonState();
@ -733,6 +733,23 @@ DocumentWindow::DocumentWindow() :
}); });
m_viewMenu->addAction(m_toggleRotationAction); 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); m_toggleUvCheckAction = new QAction(tr("Toggle UV Check"), this);
connect(m_toggleUvCheckAction, &QAction::triggered, [=]() { connect(m_toggleUvCheckAction, &QAction::triggered, [=]() {
m_modelRenderWidget->toggleUvCheck(); m_modelRenderWidget->toggleUvCheck();
@ -1080,6 +1097,8 @@ DocumentWindow::DocumentWindow() :
return; return;
} }
} }
if (m_modelRemoveColor && resultTextureMesh)
resultTextureMesh->removeColor();
m_modelRenderWidget->updateMesh(resultTextureMesh); m_modelRenderWidget->updateMesh(resultTextureMesh);
}); });
@ -1087,6 +1106,8 @@ DocumentWindow::DocumentWindow() :
auto resultMesh = m_document->takeResultMesh(); auto resultMesh = m_document->takeResultMesh();
if (nullptr != resultMesh) if (nullptr != resultMesh)
m_currentUpdatedMeshId = resultMesh->meshId(); m_currentUpdatedMeshId = resultMesh->meshId();
if (m_modelRemoveColor && resultMesh)
resultMesh->removeColor();
m_modelRenderWidget->updateMesh(resultMesh); m_modelRenderWidget->updateMesh(resultMesh);
}); });

View File

@ -169,6 +169,8 @@ private:
QAction *m_toggleWireframeAction; QAction *m_toggleWireframeAction;
QAction *m_toggleUvCheckAction; QAction *m_toggleUvCheckAction;
QAction *m_toggleRotationAction; QAction *m_toggleRotationAction;
QAction *m_toggleColorAction;
bool m_modelRemoveColor = false;
QMenu *m_windowMenu; QMenu *m_windowMenu;
QAction *m_showPartsListAction; QAction *m_showPartsListAction;

View File

@ -57,6 +57,29 @@ MeshLoader::MeshLoader(const MeshLoader &mesh) :
this->m_meshId = mesh.meshId(); 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) : MeshLoader::MeshLoader(ShaderVertex *triangleVertices, int vertexNum, ShaderVertex *edgeVertices, int edgeVertexCount) :
m_triangleVertices(triangleVertices), m_triangleVertices(triangleVertices),
m_triangleVertexCount(vertexNum), m_triangleVertexCount(vertexNum),

View File

@ -57,6 +57,7 @@ public:
void updateTriangleVertices(ShaderVertex *triangleVertices, int triangleVertexCount); void updateTriangleVertices(ShaderVertex *triangleVertices, int triangleVertexCount);
quint64 meshId() const; quint64 meshId() const;
void setMeshId(quint64 id); void setMeshId(quint64 id);
void removeColor();
private: private:
ShaderVertex *m_triangleVertices = nullptr; ShaderVertex *m_triangleVertices = nullptr;
int m_triangleVertexCount = 0; int m_triangleVertexCount = 0;