Add texture size preference setting

master
Jeremy Hu 2020-02-27 20:23:50 +09:30
parent c4639d77ae
commit 6e2c1286a3
7 changed files with 51 additions and 3 deletions

View File

@ -82,6 +82,7 @@ Document::Document() :
{ {
connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange); connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange);
connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange); connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange);
connect(&Preferences::instance(), &Preferences::textureSizeChanged, this, &Document::applyPreferenceTextureSizeChange);
} }
void Document::applyPreferencePartColorChange() void Document::applyPreferencePartColorChange()
@ -95,6 +96,11 @@ void Document::applyPreferenceFlatShadingChange()
regenerateMesh(); regenerateMesh();
} }
void Document::applyPreferenceTextureSizeChange()
{
generateTexture();
}
Document::~Document() Document::~Document()
{ {
delete m_resultMesh; delete m_resultMesh;

View File

@ -736,6 +736,7 @@ public slots:
void renameMaterial(QUuid materialId, QString name); void renameMaterial(QUuid materialId, QString name);
void applyPreferencePartColorChange(); void applyPreferencePartColorChange();
void applyPreferenceFlatShadingChange(); void applyPreferenceFlatShadingChange();
void applyPreferenceTextureSizeChange();
void initScript(const QString &script); void initScript(const QString &script);
void updateScript(const QString &script); void updateScript(const QString &script);
void runScript(); void runScript();

View File

@ -15,6 +15,7 @@ void Preferences::loadDefault()
m_componentCombineMode = CombineMode::Normal; m_componentCombineMode = CombineMode::Normal;
m_partColor = Qt::white; m_partColor = Qt::white;
m_flatShading = true; m_flatShading = true;
m_textureSize = 1024;
} }
Preferences::Preferences() Preferences::Preferences()
@ -37,6 +38,11 @@ Preferences::Preferences()
else else
m_flatShading = isTrueValueString(value); m_flatShading = isTrueValueString(value);
} }
{
QString value = m_settings.value("textureSize").toString();
if (!value.isEmpty())
m_textureSize = value.toInt();
}
} }
CombineMode Preferences::componentCombineMode() const CombineMode Preferences::componentCombineMode() const
@ -54,6 +60,11 @@ bool Preferences::flatShading() const
return m_flatShading; return m_flatShading;
} }
int Preferences::textureSize() const
{
return m_textureSize;
}
void Preferences::setComponentCombineMode(CombineMode mode) void Preferences::setComponentCombineMode(CombineMode mode)
{ {
if (m_componentCombineMode == mode) if (m_componentCombineMode == mode)
@ -81,6 +92,15 @@ void Preferences::setFlatShading(bool flatShading)
emit flatShadingChanged(); 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 QSize Preferences::documentWindowSize() const
{ {
return m_settings.value("documentWindowSize", QSize()).toSize(); return m_settings.value("documentWindowSize", QSize()).toSize();
@ -98,4 +118,5 @@ void Preferences::reset()
emit componentCombineModeChanged(); emit componentCombineModeChanged();
emit partColorChanged(); emit partColorChanged();
emit flatShadingChanged(); emit flatShadingChanged();
emit textureSizeChanged();
} }

View File

@ -16,20 +16,24 @@ public:
bool flatShading() const; bool flatShading() const;
QSize documentWindowSize() const; QSize documentWindowSize() const;
void setDocumentWindowSize(const QSize&); void setDocumentWindowSize(const QSize&);
int textureSize() const;
signals: signals:
void componentCombineModeChanged(); void componentCombineModeChanged();
void partColorChanged(); void partColorChanged();
void flatShadingChanged(); void flatShadingChanged();
void textureSizeChanged();
public slots: public slots:
void setComponentCombineMode(CombineMode mode); void setComponentCombineMode(CombineMode mode);
void setPartColor(const QColor &color); void setPartColor(const QColor &color);
void setFlatShading(bool flatShading); void setFlatShading(bool flatShading);
void setTextureSize(int textureSize);
void reset(); void reset();
private: private:
CombineMode m_componentCombineMode; CombineMode m_componentCombineMode;
QColor m_partColor; QColor m_partColor;
bool m_flatShading; bool m_flatShading;
QSettings m_settings; QSettings m_settings;
int m_textureSize;
private: private:
void loadDefault(); void loadDefault();
}; };

View File

@ -65,15 +65,28 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
Preferences::instance().setFlatShading(flatShadingBox->isChecked()); 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<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
Preferences::instance().setTextureSize(textureSizeSelectBox->itemText(index).toInt());
});
QFormLayout *formLayout = new QFormLayout; QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(tr("Part color:"), colorLayout); formLayout->addRow(tr("Part color:"), colorLayout);
formLayout->addRow(tr("Combine mode:"), combineModeSelectBox); formLayout->addRow(tr("Combine mode:"), combineModeSelectBox);
formLayout->addRow(tr("Flat shading:"), flatShadingBox); formLayout->addRow(tr("Flat shading:"), flatShadingBox);
formLayout->addRow(tr("Texture size:"), textureSizeSelectBox);
auto loadFromPreferences = [=]() { auto loadFromPreferences = [=]() {
updatePickButtonColor(); updatePickButtonColor();
combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode()); combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode());
flatShadingBox->setChecked(Preferences::instance().flatShading()); flatShadingBox->setChecked(Preferences::instance().flatShading());
textureSizeSelectBox->setCurrentIndex(
textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize()))
);
}; };
loadFromPreferences(); loadFromPreferences();

View File

@ -9,8 +9,8 @@
#include "util.h" #include "util.h"
#include "texturetype.h" #include "texturetype.h"
#include "material.h" #include "material.h"
#include "preferences.h"
int TextureGenerator::m_textureSize = 1024;
QColor TextureGenerator::m_defaultTextureColor = Qt::transparent; QColor TextureGenerator::m_defaultTextureColor = Qt::transparent;
TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) : TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) :
@ -25,10 +25,13 @@ TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) :
m_resultTextureAmbientOcclusionImage(nullptr), m_resultTextureAmbientOcclusionImage(nullptr),
m_resultMesh(nullptr), m_resultMesh(nullptr),
m_snapshot(snapshot), m_snapshot(snapshot),
m_hasTransparencySettings(false) m_hasTransparencySettings(false),
m_textureSize(Preferences::instance().textureSize())
{ {
m_outcome = new Outcome(); m_outcome = new Outcome();
*m_outcome = outcome; *m_outcome = outcome;
if (m_textureSize <= 0)
m_textureSize = 1024;
} }
TextureGenerator::~TextureGenerator() TextureGenerator::~TextureGenerator()

View File

@ -38,7 +38,6 @@ signals:
public slots: public slots:
void process(); void process();
public: public:
static int m_textureSize;
static QColor m_defaultTextureColor; static QColor m_defaultTextureColor;
private: private:
void prepare(); void prepare();
@ -62,6 +61,7 @@ private:
std::set<QUuid> m_countershadedPartIds; std::set<QUuid> m_countershadedPartIds;
Snapshot *m_snapshot; Snapshot *m_snapshot;
bool m_hasTransparencySettings; bool m_hasTransparencySettings;
int m_textureSize;
}; };
#endif #endif