Add preference: Interpolation enabling toggle

Disabling interpolation would remove the auto generated intermediate nodes, then reduce the generated triangles.
master
huxingyi 2020-12-07 19:47:25 +09:30
parent eacc96d13b
commit cef6deeda3
7 changed files with 52 additions and 2 deletions

View File

@ -85,6 +85,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); connect(&Preferences::instance(), &Preferences::textureSizeChanged, this, &Document::applyPreferenceTextureSizeChange);
connect(&Preferences::instance(), &Preferences::interpolationEnabledChanged, this, &Document::applyPreferenceInterpolationChange);
} }
void Document::applyPreferencePartColorChange() void Document::applyPreferencePartColorChange()
@ -103,6 +104,11 @@ void Document::applyPreferenceTextureSizeChange()
generateTexture(); generateTexture();
} }
void Document::applyPreferenceInterpolationChange()
{
regenerateMesh();
}
Document::~Document() Document::~Document()
{ {
delete m_resultMesh; delete m_resultMesh;
@ -2055,6 +2061,7 @@ void Document::generateMesh()
m_meshGenerator = new MeshGenerator(snapshot); m_meshGenerator = new MeshGenerator(snapshot);
m_meshGenerator->setId(m_nextMeshGenerationId++); m_meshGenerator->setId(m_nextMeshGenerationId++);
m_meshGenerator->setDefaultPartColor(Preferences::instance().partColor()); m_meshGenerator->setDefaultPartColor(Preferences::instance().partColor());
m_meshGenerator->setInterpolationEnabled(Preferences::instance().interpolationEnabled());
if (nullptr == m_generatedCacheContext) if (nullptr == m_generatedCacheContext)
m_generatedCacheContext = new GeneratedCacheContext; m_generatedCacheContext = new GeneratedCacheContext;
m_meshGenerator->setGeneratedCacheContext(m_generatedCacheContext); m_meshGenerator->setGeneratedCacheContext(m_generatedCacheContext);

View File

@ -633,6 +633,7 @@ public slots:
void applyPreferencePartColorChange(); void applyPreferencePartColorChange();
void applyPreferenceFlatShadingChange(); void applyPreferenceFlatShadingChange();
void applyPreferenceTextureSizeChange(); void applyPreferenceTextureSizeChange();
void applyPreferenceInterpolationChange();
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

@ -1021,11 +1021,11 @@ MeshCombiner::Mesh *MeshGenerator::combineComponentMesh(const QString &component
QString partIdString = valueOfKeyInMapOrEmpty(*component, "linkData"); QString partIdString = valueOfKeyInMapOrEmpty(*component, "linkData");
bool hasError = false; bool hasError = false;
bool retryable = true; bool retryable = true;
mesh = combinePartMesh(partIdString, &hasError, &retryable); mesh = combinePartMesh(partIdString, &hasError, &retryable, m_interpolationEnabled);
if (hasError) { if (hasError) {
delete mesh; delete mesh;
mesh = nullptr; mesh = nullptr;
if (retryable) { if (retryable && m_interpolationEnabled) {
hasError = false; hasError = false;
qDebug() << "Try combine part again without adding intermediate nodes"; qDebug() << "Try combine part again without adding intermediate nodes";
mesh = combinePartMesh(partIdString, &hasError, &retryable, false); mesh = combinePartMesh(partIdString, &hasError, &retryable, false);
@ -1411,6 +1411,11 @@ void MeshGenerator::setSmoothShadingThresholdAngleDegrees(float degrees)
m_smoothShadingThresholdAngleDegrees = degrees; m_smoothShadingThresholdAngleDegrees = degrees;
} }
void MeshGenerator::setInterpolationEnabled(bool interpolationEnabled)
{
m_interpolationEnabled = interpolationEnabled;
}
void MeshGenerator::process() void MeshGenerator::process()
{ {
generate(); generate();

View File

@ -96,6 +96,7 @@ public:
void generate(); void generate();
void setGeneratedCacheContext(GeneratedCacheContext *cacheContext); void setGeneratedCacheContext(GeneratedCacheContext *cacheContext);
void setSmoothShadingThresholdAngleDegrees(float degrees); void setSmoothShadingThresholdAngleDegrees(float degrees);
void setInterpolationEnabled(bool interpolationEnabled);
void setDefaultPartColor(const QColor &color); void setDefaultPartColor(const QColor &color);
void setId(quint64 id); void setId(quint64 id);
void setWeldEnabled(bool enabled); void setWeldEnabled(bool enabled);
@ -130,6 +131,7 @@ private:
std::vector<QVector3D> m_clothCollisionVertices; std::vector<QVector3D> m_clothCollisionVertices;
std::vector<std::vector<size_t>> m_clothCollisionTriangles; std::vector<std::vector<size_t>> m_clothCollisionTriangles;
bool m_weldEnabled = true; bool m_weldEnabled = true;
bool m_interpolationEnabled = true;
void collectParts(); void collectParts();
void collectIncombinableComponentMeshes(const QString &componentIdString); void collectIncombinableComponentMeshes(const QString &componentIdString);

View File

@ -19,6 +19,7 @@ void Preferences::loadDefault()
m_toonLine = ToonLine::WithoutLine; m_toonLine = ToonLine::WithoutLine;
m_textureSize = 1024; m_textureSize = 1024;
m_scriptEnabled = false; m_scriptEnabled = false;
m_interpolationEnabled = true;
} }
Preferences::Preferences() Preferences::Preferences()
@ -65,6 +66,13 @@ Preferences::Preferences()
else else
m_scriptEnabled = isTrueValueString(value); m_scriptEnabled = isTrueValueString(value);
} }
{
QString value = m_settings.value("interpolationEnabled").toString();
if (value.isEmpty())
m_interpolationEnabled = true;
else
m_interpolationEnabled = isTrueValueString(value);
}
} }
CombineMode Preferences::componentCombineMode() const CombineMode Preferences::componentCombineMode() const
@ -87,6 +95,11 @@ bool Preferences::scriptEnabled() const
return m_scriptEnabled; return m_scriptEnabled;
} }
bool Preferences::interpolationEnabled() const
{
return m_interpolationEnabled;
}
bool Preferences::toonShading() const bool Preferences::toonShading() const
{ {
return m_toonShading; return m_toonShading;
@ -138,6 +151,15 @@ void Preferences::setScriptEnabled(bool enabled)
emit scriptEnabledChanged(); emit scriptEnabledChanged();
} }
void Preferences::setInterpolationEnabled(bool enabled)
{
if (m_interpolationEnabled == enabled)
return;
m_interpolationEnabled = enabled;
m_settings.setValue("interpolationEnabled", enabled ? "true" : "false");
emit interpolationEnabledChanged();
}
void Preferences::setToonShading(bool toonShading) void Preferences::setToonShading(bool toonShading)
{ {
if (m_toonShading == toonShading) if (m_toonShading == toonShading)
@ -186,4 +208,5 @@ void Preferences::reset()
emit toonLineChanged(); emit toonLineChanged();
emit textureSizeChanged(); emit textureSizeChanged();
emit scriptEnabledChanged(); emit scriptEnabledChanged();
emit interpolationEnabledChanged();
} }

View File

@ -16,6 +16,7 @@ public:
const QColor &partColor() const; const QColor &partColor() const;
bool flatShading() const; bool flatShading() const;
bool scriptEnabled() const; bool scriptEnabled() const;
bool interpolationEnabled() const;
bool toonShading() const; bool toonShading() const;
ToonLine toonLine() const; ToonLine toonLine() const;
QSize documentWindowSize() const; QSize documentWindowSize() const;
@ -28,6 +29,7 @@ signals:
void toonShadingChanged(); void toonShadingChanged();
void toonLineChanged(); void toonLineChanged();
void textureSizeChanged(); void textureSizeChanged();
void interpolationEnabledChanged();
void scriptEnabledChanged(); void scriptEnabledChanged();
public slots: public slots:
void setComponentCombineMode(CombineMode mode); void setComponentCombineMode(CombineMode mode);
@ -37,6 +39,7 @@ public slots:
void setToonLine(ToonLine toonLine); void setToonLine(ToonLine toonLine);
void setTextureSize(int textureSize); void setTextureSize(int textureSize);
void setScriptEnabled(bool enabled); void setScriptEnabled(bool enabled);
void setInterpolationEnabled(bool enabled);
void reset(); void reset();
private: private:
CombineMode m_componentCombineMode; CombineMode m_componentCombineMode;
@ -47,6 +50,7 @@ private:
QSettings m_settings; QSettings m_settings;
int m_textureSize; int m_textureSize;
bool m_scriptEnabled; bool m_scriptEnabled;
bool m_interpolationEnabled;
private: private:
void loadDefault(); void loadDefault();
}; };

View File

@ -85,6 +85,12 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
toonShadingLayout->addWidget(toonLineSelectBox); toonShadingLayout->addWidget(toonLineSelectBox);
toonShadingLayout->addStretch(); toonShadingLayout->addStretch();
QCheckBox *interpolationEnabledBox = new QCheckBox();
Theme::initCheckbox(interpolationEnabledBox);
connect(interpolationEnabledBox, &QCheckBox::stateChanged, this, [=]() {
Preferences::instance().setInterpolationEnabled(interpolationEnabledBox->isChecked());
});
QComboBox *textureSizeSelectBox = new QComboBox; QComboBox *textureSizeSelectBox = new QComboBox;
textureSizeSelectBox->addItem("512"); textureSizeSelectBox->addItem("512");
textureSizeSelectBox->addItem("1024"); textureSizeSelectBox->addItem("1024");
@ -104,6 +110,7 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
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("Interpolation:"), interpolationEnabledBox);
formLayout->addRow(tr("Toon shading:"), toonShadingLayout); formLayout->addRow(tr("Toon shading:"), toonShadingLayout);
formLayout->addRow(tr("Texture size:"), textureSizeSelectBox); formLayout->addRow(tr("Texture size:"), textureSizeSelectBox);
formLayout->addRow(tr("Script:"), scriptEnabledBox); formLayout->addRow(tr("Script:"), scriptEnabledBox);
@ -117,6 +124,7 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
textureSizeSelectBox->setCurrentIndex( textureSizeSelectBox->setCurrentIndex(
textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize())) textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize()))
); );
interpolationEnabledBox->setChecked(Preferences::instance().interpolationEnabled());
scriptEnabledBox->setChecked(Preferences::instance().scriptEnabled()); scriptEnabledBox->setChecked(Preferences::instance().scriptEnabled());
}; };