diff --git a/src/document.cpp b/src/document.cpp index c6cd59cd..8d3303be 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -82,6 +82,7 @@ Document::Document() : { connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange); connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange); + connect(&Preferences::instance(), &Preferences::textureSizeChanged, this, &Document::applyPreferenceTextureSizeChange); } void Document::applyPreferencePartColorChange() @@ -95,6 +96,11 @@ void Document::applyPreferenceFlatShadingChange() regenerateMesh(); } +void Document::applyPreferenceTextureSizeChange() +{ + generateTexture(); +} + Document::~Document() { delete m_resultMesh; diff --git a/src/document.h b/src/document.h index 16f27f6d..780dbf58 100644 --- a/src/document.h +++ b/src/document.h @@ -736,6 +736,7 @@ public slots: void renameMaterial(QUuid materialId, QString name); void applyPreferencePartColorChange(); void applyPreferenceFlatShadingChange(); + void applyPreferenceTextureSizeChange(); void initScript(const QString &script); void updateScript(const QString &script); void runScript(); diff --git a/src/preferences.cpp b/src/preferences.cpp index ed007771..25b42eec 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -15,6 +15,7 @@ void Preferences::loadDefault() m_componentCombineMode = CombineMode::Normal; m_partColor = Qt::white; m_flatShading = true; + m_textureSize = 1024; } Preferences::Preferences() @@ -37,6 +38,11 @@ Preferences::Preferences() else m_flatShading = isTrueValueString(value); } + { + QString value = m_settings.value("textureSize").toString(); + if (!value.isEmpty()) + m_textureSize = value.toInt(); + } } CombineMode Preferences::componentCombineMode() const @@ -54,6 +60,11 @@ bool Preferences::flatShading() const return m_flatShading; } +int Preferences::textureSize() const +{ + return m_textureSize; +} + void Preferences::setComponentCombineMode(CombineMode mode) { if (m_componentCombineMode == mode) @@ -81,6 +92,15 @@ void Preferences::setFlatShading(bool flatShading) emit flatShadingChanged(); } +void Preferences::setTextureSize(int textureSize) +{ + if (m_textureSize == textureSize) + return; + m_textureSize = textureSize; + m_settings.setValue("textureSize", QString::number(m_textureSize)); + emit textureSizeChanged(); +} + QSize Preferences::documentWindowSize() const { return m_settings.value("documentWindowSize", QSize()).toSize(); @@ -98,4 +118,5 @@ void Preferences::reset() emit componentCombineModeChanged(); emit partColorChanged(); emit flatShadingChanged(); + emit textureSizeChanged(); } diff --git a/src/preferences.h b/src/preferences.h index d558e9e3..bd010bc4 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -16,20 +16,24 @@ public: bool flatShading() const; QSize documentWindowSize() const; void setDocumentWindowSize(const QSize&); + int textureSize() const; signals: void componentCombineModeChanged(); void partColorChanged(); void flatShadingChanged(); + void textureSizeChanged(); public slots: void setComponentCombineMode(CombineMode mode); void setPartColor(const QColor &color); void setFlatShading(bool flatShading); + void setTextureSize(int textureSize); void reset(); private: CombineMode m_componentCombineMode; QColor m_partColor; bool m_flatShading; QSettings m_settings; + int m_textureSize; private: void loadDefault(); }; diff --git a/src/preferenceswidget.cpp b/src/preferenceswidget.cpp index 4f359dc8..e1c4720c 100644 --- a/src/preferenceswidget.cpp +++ b/src/preferenceswidget.cpp @@ -65,15 +65,28 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent) Preferences::instance().setFlatShading(flatShadingBox->isChecked()); }); + QComboBox *textureSizeSelectBox = new QComboBox; + textureSizeSelectBox->addItem("512"); + textureSizeSelectBox->addItem("1024"); + textureSizeSelectBox->addItem("2048"); + textureSizeSelectBox->addItem("4096"); + connect(textureSizeSelectBox, static_cast(&QComboBox::currentIndexChanged), this, [=](int index) { + Preferences::instance().setTextureSize(textureSizeSelectBox->itemText(index).toInt()); + }); + QFormLayout *formLayout = new QFormLayout; formLayout->addRow(tr("Part color:"), colorLayout); formLayout->addRow(tr("Combine mode:"), combineModeSelectBox); formLayout->addRow(tr("Flat shading:"), flatShadingBox); + formLayout->addRow(tr("Texture size:"), textureSizeSelectBox); auto loadFromPreferences = [=]() { updatePickButtonColor(); combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode()); flatShadingBox->setChecked(Preferences::instance().flatShading()); + textureSizeSelectBox->setCurrentIndex( + textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize())) + ); }; loadFromPreferences(); diff --git a/src/texturegenerator.cpp b/src/texturegenerator.cpp index ca587df7..eeb07d08 100644 --- a/src/texturegenerator.cpp +++ b/src/texturegenerator.cpp @@ -9,8 +9,8 @@ #include "util.h" #include "texturetype.h" #include "material.h" +#include "preferences.h" -int TextureGenerator::m_textureSize = 1024; QColor TextureGenerator::m_defaultTextureColor = Qt::transparent; TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) : @@ -25,10 +25,13 @@ TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) : m_resultTextureAmbientOcclusionImage(nullptr), m_resultMesh(nullptr), m_snapshot(snapshot), - m_hasTransparencySettings(false) + m_hasTransparencySettings(false), + m_textureSize(Preferences::instance().textureSize()) { m_outcome = new Outcome(); *m_outcome = outcome; + if (m_textureSize <= 0) + m_textureSize = 1024; } TextureGenerator::~TextureGenerator() diff --git a/src/texturegenerator.h b/src/texturegenerator.h index eb72c4a0..7191c894 100644 --- a/src/texturegenerator.h +++ b/src/texturegenerator.h @@ -38,7 +38,6 @@ signals: public slots: void process(); public: - static int m_textureSize; static QColor m_defaultTextureColor; private: void prepare(); @@ -62,6 +61,7 @@ private: std::set m_countershadedPartIds; Snapshot *m_snapshot; bool m_hasTransparencySettings; + int m_textureSize; }; #endif