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>
<translation>UV</translation>
</message>
<message>
<source>Toggle rotation</source>
<translation></translation>
</message>
<message>
<source>Colorize</source>
<translation></translation>
@ -394,6 +390,14 @@ Tips:
<source>Toggle Rotation</source>
<translation>/</translation>
</message>
<message>
<source>Toggle viewport</source>
<translation></translation>
</message>
<message>
<source>Toggle Color</source>
<translation>/</translation>
</message>
</context>
<context>
<name>ExportPreviewWidget</name>

View File

@ -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);
});

View File

@ -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;

View File

@ -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),

View File

@ -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;