Add normal map preview

master
Jeremy Hu 2018-11-16 13:55:52 +08:00
parent 69d97c7780
commit e39acc9f25
2 changed files with 33 additions and 8 deletions

View File

@ -63,14 +63,14 @@ ExportPreviewWidget::ExportPreviewWidget(Document *document, QWidget *parent) :
containerLayout->setSpacing(0); containerLayout->setSpacing(0);
containerLayout->setContentsMargins(0, 0, 0, 0); containerLayout->setContentsMargins(0, 0, 0, 0);
containerLayout->addWidget(m_colorPreviewLabel, 0, 0); containerLayout->addWidget(m_colorPreviewLabel, 0, 0);
//containerLayout->addWidget(m_normalPreviewLabel, 1, 0); containerLayout->addWidget(m_normalPreviewLabel, 0, 1);
//containerLayout->addWidget(m_metalnessRoughnessAmbientOcclusionPreviewLabel, 2, 0); containerLayout->addWidget(m_metalnessRoughnessAmbientOcclusionPreviewLabel, 0, 2);
containerLayout->setRowStretch(0, 1); //containerLayout->setRowStretch(0, 1);
containerLayout->setColumnStretch(0, 1); //containerLayout->setColumnStretch(0, 1);
m_textureRenderWidget = new ModelWidget; m_textureRenderWidget = new ModelWidget;
m_textureRenderWidget->setMinimumSize(128, 128); m_textureRenderWidget->setMinimumSize(128, 128);
m_textureRenderWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //m_textureRenderWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *renderLayout = new QVBoxLayout; QVBoxLayout *renderLayout = new QVBoxLayout;
renderLayout->setSpacing(0); renderLayout->setSpacing(0);
@ -113,17 +113,28 @@ void ExportPreviewWidget::resizeEvent(QResizeEvent *event)
void ExportPreviewWidget::resizePreviewImages() void ExportPreviewWidget::resizePreviewImages()
{ {
{ if (m_colorImage.isNull()) {
m_colorPreviewLabel->hide();
} else {
QPixmap pixmap = QPixmap::fromImage(m_colorImage); QPixmap pixmap = QPixmap::fromImage(m_colorImage);
m_colorPreviewLabel->setPixmap(pixmap.scaled(m_colorPreviewLabel->width(), m_colorPreviewLabel->height(), Qt::KeepAspectRatio)); m_colorPreviewLabel->setPixmap(pixmap.scaled(m_colorPreviewLabel->width(), m_colorPreviewLabel->height(), Qt::KeepAspectRatio));
m_colorPreviewLabel->show();
} }
{
if (m_normalImage.isNull()) {
m_normalPreviewLabel->hide();
} else {
QPixmap pixmap = QPixmap::fromImage(m_normalImage); QPixmap pixmap = QPixmap::fromImage(m_normalImage);
m_normalPreviewLabel->setPixmap(pixmap.scaled(m_normalPreviewLabel->width(), m_normalPreviewLabel->height(), Qt::KeepAspectRatio)); m_normalPreviewLabel->setPixmap(pixmap.scaled(m_normalPreviewLabel->width(), m_normalPreviewLabel->height(), Qt::KeepAspectRatio));
m_normalPreviewLabel->show();
} }
{
if (m_metalnessRoughnessAmbientOcclusionImage.isNull()) {
m_metalnessRoughnessAmbientOcclusionPreviewLabel->hide();
} else {
QPixmap pixmap = QPixmap::fromImage(m_metalnessRoughnessAmbientOcclusionImage); QPixmap pixmap = QPixmap::fromImage(m_metalnessRoughnessAmbientOcclusionImage);
m_metalnessRoughnessAmbientOcclusionPreviewLabel->setPixmap(pixmap.scaled(m_metalnessRoughnessAmbientOcclusionPreviewLabel->width(), m_metalnessRoughnessAmbientOcclusionPreviewLabel->height(), Qt::KeepAspectRatio)); m_metalnessRoughnessAmbientOcclusionPreviewLabel->setPixmap(pixmap.scaled(m_metalnessRoughnessAmbientOcclusionPreviewLabel->width(), m_metalnessRoughnessAmbientOcclusionPreviewLabel->height(), Qt::KeepAspectRatio));
m_metalnessRoughnessAmbientOcclusionPreviewLabel->show();
} }
} }
@ -161,10 +172,16 @@ void ExportPreviewWidget::updateTexturePreview()
{ {
if (m_document->textureGuideImage) if (m_document->textureGuideImage)
m_colorImage = *m_document->textureGuideImage; m_colorImage = *m_document->textureGuideImage;
else
m_colorImage = QImage();
if (m_document->textureNormalImage) if (m_document->textureNormalImage)
m_normalImage = *m_document->textureNormalImage; m_normalImage = *m_document->textureNormalImage;
else
m_normalImage = QImage();
if (m_document->textureMetalnessRoughnessAmbientOcclusionImage) if (m_document->textureMetalnessRoughnessAmbientOcclusionImage)
m_metalnessRoughnessAmbientOcclusionImage = *m_document->textureMetalnessRoughnessAmbientOcclusionImage; m_metalnessRoughnessAmbientOcclusionImage = *m_document->textureMetalnessRoughnessAmbientOcclusionImage;
else
m_metalnessRoughnessAmbientOcclusionImage = QImage();
m_textureRenderWidget->updateMesh(m_document->takeResultTextureMesh()); m_textureRenderWidget->updateMesh(m_document->takeResultTextureMesh());
resizePreviewImages(); resizePreviewImages();
checkSpinner(); checkSpinner();

View File

@ -202,6 +202,7 @@ void TextureGenerator::generate()
const auto &triangleVertexUvs = *m_outcome->triangleVertexUvs(); const auto &triangleVertexUvs = *m_outcome->triangleVertexUvs();
const auto &triangleSourceNodes = *m_outcome->triangleSourceNodes(); const auto &triangleSourceNodes = *m_outcome->triangleSourceNodes();
const auto &triangleNormals = m_outcome->triangleNormals;
std::map<std::pair<QUuid, QUuid>, const OutcomeNode *> nodeMap; std::map<std::pair<QUuid, QUuid>, const OutcomeNode *> nodeMap;
for (const auto &item: m_outcome->nodes) { for (const auto &item: m_outcome->nodes) {
@ -304,6 +305,13 @@ void TextureGenerator::generate()
textureNormalPainter.drawImage(0, 0, findNormalTextureResult->second); textureNormalPainter.drawImage(0, 0, findNormalTextureResult->second);
textureNormalPainter.setClipping(false); textureNormalPainter.setClipping(false);
hasNormalMap = true; hasNormalMap = true;
} else {
const auto &triangleNormal = triangleNormals[i];
QColor brushColor;
brushColor.setRedF((triangleNormal.x() + 1) / 2);
brushColor.setGreenF((triangleNormal.y() + 1) / 2);
brushColor.setBlueF((triangleNormal.z() + 1) / 2);
textureNormalPainter.fillPath(path, brushColor);
} }
// Copy metalness texture if there is one // Copy metalness texture if there is one
auto findMetalnessTextureResult = m_partMetalnessTextureMap.find(source.first); auto findMetalnessTextureResult = m_partMetalnessTextureMap.find(source.first);