Fix merged texture image

The merged texture image of metalness, roughness and ambient occlusion did not get saved in the document class, this commit fixed it.
master
Jeremy Hu 2018-11-16 06:56:24 +08:00
parent 1f8f7913a7
commit 7f5a47c074
6 changed files with 67 additions and 30 deletions

View File

@ -23,8 +23,9 @@ Document::Document() :
textureGuideImage(nullptr), textureGuideImage(nullptr),
textureImage(nullptr), textureImage(nullptr),
textureBorderImage(nullptr), textureBorderImage(nullptr),
textureAmbientOcclusionImage(nullptr),
textureColorImage(nullptr), textureColorImage(nullptr),
textureNormalImage(nullptr),
textureMetalnessRoughnessAmbientOcclusionImage(nullptr),
rigType(RigType::None), rigType(RigType::None),
weldEnabled(true), weldEnabled(true),
// private // private
@ -62,8 +63,10 @@ Document::~Document()
delete m_postProcessedOutcome; delete m_postProcessedOutcome;
delete textureGuideImage; delete textureGuideImage;
delete textureImage; delete textureImage;
delete textureColorImage;
delete textureNormalImage;
delete textureMetalnessRoughnessAmbientOcclusionImage;
delete textureBorderImage; delete textureBorderImage;
delete textureAmbientOcclusionImage;
delete m_resultTextureMesh; delete m_resultTextureMesh;
delete m_resultRigWeightMesh; delete m_resultRigWeightMesh;
} }
@ -1507,12 +1510,15 @@ void Document::textureReady()
delete textureBorderImage; delete textureBorderImage;
textureBorderImage = m_textureGenerator->takeResultTextureBorderImage(); textureBorderImage = m_textureGenerator->takeResultTextureBorderImage();
delete textureAmbientOcclusionImage;
textureAmbientOcclusionImage = nullptr;
delete textureColorImage; delete textureColorImage;
textureColorImage = m_textureGenerator->takeResultTextureColorImage(); textureColorImage = m_textureGenerator->takeResultTextureColorImage();
delete textureNormalImage;
textureNormalImage = m_textureGenerator->takeResultTextureNormalImage();
delete textureMetalnessRoughnessAmbientOcclusionImage;
textureMetalnessRoughnessAmbientOcclusionImage = m_textureGenerator->takeResultTextureMetalnessRoughnessAmbientOcclusionImage();
delete m_resultTextureMesh; delete m_resultTextureMesh;
m_resultTextureMesh = m_textureGenerator->takeResultMesh(); m_resultTextureMesh = m_textureGenerator->takeResultMesh();

View File

@ -449,8 +449,9 @@ public: // need initialize
QImage *textureGuideImage; QImage *textureGuideImage;
QImage *textureImage; QImage *textureImage;
QImage *textureBorderImage; QImage *textureBorderImage;
QImage *textureAmbientOcclusionImage;
QImage *textureColorImage; QImage *textureColorImage;
QImage *textureNormalImage;
QImage *textureMetalnessRoughnessAmbientOcclusionImage;
RigType rigType; RigType rigType;
bool weldEnabled; bool weldEnabled;
public: public:

View File

@ -12,16 +12,24 @@
ExportPreviewWidget::ExportPreviewWidget(Document *document, QWidget *parent) : ExportPreviewWidget::ExportPreviewWidget(Document *document, QWidget *parent) :
QDialog(parent), QDialog(parent),
m_document(document), m_document(document),
m_previewLabel(nullptr), m_colorPreviewLabel(nullptr),
m_spinnerWidget(nullptr) m_spinnerWidget(nullptr)
{ {
QHBoxLayout *toolButtonLayout = new QHBoxLayout; QHBoxLayout *toolButtonLayout = new QHBoxLayout;
toolButtonLayout->setSpacing(0); toolButtonLayout->setSpacing(0);
//toolButtonLayout->setContentsMargins(5, 10, 4, 0); //toolButtonLayout->setContentsMargins(5, 10, 4, 0);
m_previewLabel = new QLabel; m_colorPreviewLabel = new QLabel;
m_previewLabel->setMinimumSize(128, 128); m_colorPreviewLabel->setMinimumSize(128, 128);
m_previewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_colorPreviewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_normalPreviewLabel = new QLabel;
m_normalPreviewLabel->setMinimumSize(64, 64);
m_normalPreviewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_metalnessRoughnessAmbientOcclusionPreviewLabel = new QLabel;
m_metalnessRoughnessAmbientOcclusionPreviewLabel->setMinimumSize(64, 64);
m_metalnessRoughnessAmbientOcclusionPreviewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
//QPushButton *regenerateButton = new QPushButton(QChar(fa::recycle)); //QPushButton *regenerateButton = new QPushButton(QChar(fa::recycle));
//initAwesomeButton(regenerateButton); //initAwesomeButton(regenerateButton);
@ -54,7 +62,9 @@ ExportPreviewWidget::ExportPreviewWidget(Document *document, QWidget *parent) :
QGridLayout *containerLayout = new QGridLayout; QGridLayout *containerLayout = new QGridLayout;
containerLayout->setSpacing(0); containerLayout->setSpacing(0);
containerLayout->setContentsMargins(0, 0, 0, 0); containerLayout->setContentsMargins(0, 0, 0, 0);
containerLayout->addWidget(m_previewLabel); containerLayout->addWidget(m_colorPreviewLabel, 0, 0);
//containerLayout->addWidget(m_normalPreviewLabel, 1, 0);
//containerLayout->addWidget(m_metalnessRoughnessAmbientOcclusionPreviewLabel, 2, 0);
containerLayout->setRowStretch(0, 1); containerLayout->setRowStretch(0, 1);
containerLayout->setColumnStretch(0, 1); containerLayout->setColumnStretch(0, 1);
@ -84,7 +94,7 @@ ExportPreviewWidget::ExportPreviewWidget(Document *document, QWidget *parent) :
setMinimumSize(256, 256); setMinimumSize(256, 256);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_spinnerWidget = new WaitingSpinnerWidget(m_previewLabel); m_spinnerWidget = new WaitingSpinnerWidget(m_colorPreviewLabel);
m_spinnerWidget->setColor(Theme::white); m_spinnerWidget->setColor(Theme::white);
m_spinnerWidget->setInnerRadius(Theme::miniIconFontSize / 4); m_spinnerWidget->setInnerRadius(Theme::miniIconFontSize / 4);
m_spinnerWidget->setNumberOfLines(12); m_spinnerWidget->setNumberOfLines(12);
@ -95,23 +105,26 @@ ExportPreviewWidget::ExportPreviewWidget(Document *document, QWidget *parent) :
emit updateTexturePreview(); emit updateTexturePreview();
} }
void ExportPreviewWidget::updateTexturePreviewImage(const QImage &image)
{
m_previewImage = image;
resizePreviewImage();
checkSpinner();
}
void ExportPreviewWidget::resizeEvent(QResizeEvent *event) void ExportPreviewWidget::resizeEvent(QResizeEvent *event)
{ {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
resizePreviewImage(); resizePreviewImages();
} }
void ExportPreviewWidget::resizePreviewImage() void ExportPreviewWidget::resizePreviewImages()
{ {
QPixmap pixmap = QPixmap::fromImage(m_previewImage); {
m_previewLabel->setPixmap(pixmap.scaled(m_previewLabel->width(), m_previewLabel->height(), Qt::KeepAspectRatio)); QPixmap pixmap = QPixmap::fromImage(m_colorImage);
m_colorPreviewLabel->setPixmap(pixmap.scaled(m_colorPreviewLabel->width(), m_colorPreviewLabel->height(), Qt::KeepAspectRatio));
}
{
QPixmap pixmap = QPixmap::fromImage(m_normalImage);
m_normalPreviewLabel->setPixmap(pixmap.scaled(m_normalPreviewLabel->width(), m_normalPreviewLabel->height(), Qt::KeepAspectRatio));
}
{
QPixmap pixmap = QPixmap::fromImage(m_metalnessRoughnessAmbientOcclusionImage);
m_metalnessRoughnessAmbientOcclusionPreviewLabel->setPixmap(pixmap.scaled(m_metalnessRoughnessAmbientOcclusionPreviewLabel->width(), m_metalnessRoughnessAmbientOcclusionPreviewLabel->height(), Qt::KeepAspectRatio));
}
} }
void ExportPreviewWidget::initAwesomeButton(QPushButton *button) void ExportPreviewWidget::initAwesomeButton(QPushButton *button)
@ -147,7 +160,13 @@ void ExportPreviewWidget::checkSpinner()
void ExportPreviewWidget::updateTexturePreview() void ExportPreviewWidget::updateTexturePreview()
{ {
if (m_document->textureGuideImage) if (m_document->textureGuideImage)
updateTexturePreviewImage(*m_document->textureGuideImage); m_colorImage = *m_document->textureGuideImage;
if (m_document->textureNormalImage)
m_normalImage = *m_document->textureNormalImage;
if (m_document->textureMetalnessRoughnessAmbientOcclusionImage)
m_metalnessRoughnessAmbientOcclusionImage = *m_document->textureMetalnessRoughnessAmbientOcclusionImage;
m_textureRenderWidget->updateMesh(m_document->takeResultTextureMesh()); m_textureRenderWidget->updateMesh(m_document->takeResultTextureMesh());
resizePreviewImages();
checkSpinner();
} }

View File

@ -25,13 +25,16 @@ protected:
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);
private: private:
void resizePreviewImage(); void resizePreviewImages();
void initAwesomeButton(QPushButton *button); void initAwesomeButton(QPushButton *button);
void updateTexturePreviewImage(const QImage &image);
private: private:
Document *m_document; Document *m_document;
QLabel *m_previewLabel; QLabel *m_colorPreviewLabel;
QImage m_previewImage; QLabel *m_normalPreviewLabel;
QLabel *m_metalnessRoughnessAmbientOcclusionPreviewLabel;
QImage m_colorImage;
QImage m_normalImage;
QImage m_metalnessRoughnessAmbientOcclusionImage;
ModelWidget *m_textureRenderWidget; ModelWidget *m_textureRenderWidget;
WaitingSpinnerWidget *m_spinnerWidget; WaitingSpinnerWidget *m_spinnerWidget;
QPushButton *m_saveButton; QPushButton *m_saveButton;

View File

@ -79,6 +79,13 @@ QImage *TextureGenerator::takeResultTextureNormalImage()
return resultTextureNormalImage; return resultTextureNormalImage;
} }
QImage *TextureGenerator::takeResultTextureMetalnessRoughnessAmbientOcclusionImage()
{
QImage *resultTextureMetalnessRoughnessAmbientOcclusionImage = m_resultTextureMetalnessRoughnessAmbientOcclusionImage;
m_resultTextureMetalnessRoughnessAmbientOcclusionImage = nullptr;
return resultTextureMetalnessRoughnessAmbientOcclusionImage;
}
Outcome *TextureGenerator::takeOutcome() Outcome *TextureGenerator::takeOutcome()
{ {
Outcome *outcome = m_outcome; Outcome *outcome = m_outcome;
@ -213,7 +220,7 @@ void TextureGenerator::generate()
m_resultTextureNormalImage->fill(Qt::transparent); m_resultTextureNormalImage->fill(Qt::transparent);
m_resultTextureMetalnessRoughnessAmbientOcclusionImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32); m_resultTextureMetalnessRoughnessAmbientOcclusionImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32);
m_resultTextureMetalnessRoughnessAmbientOcclusionImage->fill(Qt::transparent); m_resultTextureMetalnessRoughnessAmbientOcclusionImage->fill(QColor(255, 255, 0));
m_resultTextureMetalnessImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32); m_resultTextureMetalnessImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32);
m_resultTextureMetalnessImage->fill(Qt::black); m_resultTextureMetalnessImage->fill(Qt::black);
@ -361,7 +368,7 @@ void TextureGenerator::generate()
} else { } else {
for (int row = 0; row < m_resultTextureMetalnessRoughnessAmbientOcclusionImage->height(); ++row) { for (int row = 0; row < m_resultTextureMetalnessRoughnessAmbientOcclusionImage->height(); ++row) {
for (int col = 0; col < m_resultTextureMetalnessRoughnessAmbientOcclusionImage->width(); ++col) { for (int col = 0; col < m_resultTextureMetalnessRoughnessAmbientOcclusionImage->width(); ++col) {
QColor color; QColor color(255, 255, 0);
if (hasMetalnessMap) if (hasMetalnessMap)
color.setBlue(qGray(m_resultTextureMetalnessImage->pixel(col, row))); color.setBlue(qGray(m_resultTextureMetalnessImage->pixel(col, row)));
if (hasRoughnessMap) if (hasRoughnessMap)

View File

@ -18,6 +18,7 @@ public:
QImage *takeResultTextureBorderImage(); QImage *takeResultTextureBorderImage();
QImage *takeResultTextureColorImage(); QImage *takeResultTextureColorImage();
QImage *takeResultTextureNormalImage(); QImage *takeResultTextureNormalImage();
QImage *takeResultTextureMetalnessRoughnessAmbientOcclusionImage();
Outcome *takeOutcome(); Outcome *takeOutcome();
MeshLoader *takeResultMesh(); MeshLoader *takeResultMesh();
void addPartColorMap(QUuid partId, const QImage *image); void addPartColorMap(QUuid partId, const QImage *image);