Add preference: Interpolation enabling toggle
Disabling interpolation would remove the auto generated intermediate nodes, then reduce the generated triangles.master
parent
eacc96d13b
commit
cef6deeda3
|
@ -85,6 +85,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);
|
||||
connect(&Preferences::instance(), &Preferences::interpolationEnabledChanged, this, &Document::applyPreferenceInterpolationChange);
|
||||
}
|
||||
|
||||
void Document::applyPreferencePartColorChange()
|
||||
|
@ -103,6 +104,11 @@ void Document::applyPreferenceTextureSizeChange()
|
|||
generateTexture();
|
||||
}
|
||||
|
||||
void Document::applyPreferenceInterpolationChange()
|
||||
{
|
||||
regenerateMesh();
|
||||
}
|
||||
|
||||
Document::~Document()
|
||||
{
|
||||
delete m_resultMesh;
|
||||
|
@ -2055,6 +2061,7 @@ void Document::generateMesh()
|
|||
m_meshGenerator = new MeshGenerator(snapshot);
|
||||
m_meshGenerator->setId(m_nextMeshGenerationId++);
|
||||
m_meshGenerator->setDefaultPartColor(Preferences::instance().partColor());
|
||||
m_meshGenerator->setInterpolationEnabled(Preferences::instance().interpolationEnabled());
|
||||
if (nullptr == m_generatedCacheContext)
|
||||
m_generatedCacheContext = new GeneratedCacheContext;
|
||||
m_meshGenerator->setGeneratedCacheContext(m_generatedCacheContext);
|
||||
|
|
|
@ -633,6 +633,7 @@ public slots:
|
|||
void applyPreferencePartColorChange();
|
||||
void applyPreferenceFlatShadingChange();
|
||||
void applyPreferenceTextureSizeChange();
|
||||
void applyPreferenceInterpolationChange();
|
||||
void initScript(const QString &script);
|
||||
void updateScript(const QString &script);
|
||||
void runScript();
|
||||
|
|
|
@ -1021,11 +1021,11 @@ MeshCombiner::Mesh *MeshGenerator::combineComponentMesh(const QString &component
|
|||
QString partIdString = valueOfKeyInMapOrEmpty(*component, "linkData");
|
||||
bool hasError = false;
|
||||
bool retryable = true;
|
||||
mesh = combinePartMesh(partIdString, &hasError, &retryable);
|
||||
mesh = combinePartMesh(partIdString, &hasError, &retryable, m_interpolationEnabled);
|
||||
if (hasError) {
|
||||
delete mesh;
|
||||
mesh = nullptr;
|
||||
if (retryable) {
|
||||
if (retryable && m_interpolationEnabled) {
|
||||
hasError = false;
|
||||
qDebug() << "Try combine part again without adding intermediate nodes";
|
||||
mesh = combinePartMesh(partIdString, &hasError, &retryable, false);
|
||||
|
@ -1411,6 +1411,11 @@ void MeshGenerator::setSmoothShadingThresholdAngleDegrees(float degrees)
|
|||
m_smoothShadingThresholdAngleDegrees = degrees;
|
||||
}
|
||||
|
||||
void MeshGenerator::setInterpolationEnabled(bool interpolationEnabled)
|
||||
{
|
||||
m_interpolationEnabled = interpolationEnabled;
|
||||
}
|
||||
|
||||
void MeshGenerator::process()
|
||||
{
|
||||
generate();
|
||||
|
|
|
@ -96,6 +96,7 @@ public:
|
|||
void generate();
|
||||
void setGeneratedCacheContext(GeneratedCacheContext *cacheContext);
|
||||
void setSmoothShadingThresholdAngleDegrees(float degrees);
|
||||
void setInterpolationEnabled(bool interpolationEnabled);
|
||||
void setDefaultPartColor(const QColor &color);
|
||||
void setId(quint64 id);
|
||||
void setWeldEnabled(bool enabled);
|
||||
|
@ -130,6 +131,7 @@ private:
|
|||
std::vector<QVector3D> m_clothCollisionVertices;
|
||||
std::vector<std::vector<size_t>> m_clothCollisionTriangles;
|
||||
bool m_weldEnabled = true;
|
||||
bool m_interpolationEnabled = true;
|
||||
|
||||
void collectParts();
|
||||
void collectIncombinableComponentMeshes(const QString &componentIdString);
|
||||
|
|
|
@ -19,6 +19,7 @@ void Preferences::loadDefault()
|
|||
m_toonLine = ToonLine::WithoutLine;
|
||||
m_textureSize = 1024;
|
||||
m_scriptEnabled = false;
|
||||
m_interpolationEnabled = true;
|
||||
}
|
||||
|
||||
Preferences::Preferences()
|
||||
|
@ -65,6 +66,13 @@ Preferences::Preferences()
|
|||
else
|
||||
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
|
||||
|
@ -87,6 +95,11 @@ bool Preferences::scriptEnabled() const
|
|||
return m_scriptEnabled;
|
||||
}
|
||||
|
||||
bool Preferences::interpolationEnabled() const
|
||||
{
|
||||
return m_interpolationEnabled;
|
||||
}
|
||||
|
||||
bool Preferences::toonShading() const
|
||||
{
|
||||
return m_toonShading;
|
||||
|
@ -138,6 +151,15 @@ void Preferences::setScriptEnabled(bool enabled)
|
|||
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)
|
||||
{
|
||||
if (m_toonShading == toonShading)
|
||||
|
@ -186,4 +208,5 @@ void Preferences::reset()
|
|||
emit toonLineChanged();
|
||||
emit textureSizeChanged();
|
||||
emit scriptEnabledChanged();
|
||||
emit interpolationEnabledChanged();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
const QColor &partColor() const;
|
||||
bool flatShading() const;
|
||||
bool scriptEnabled() const;
|
||||
bool interpolationEnabled() const;
|
||||
bool toonShading() const;
|
||||
ToonLine toonLine() const;
|
||||
QSize documentWindowSize() const;
|
||||
|
@ -28,6 +29,7 @@ signals:
|
|||
void toonShadingChanged();
|
||||
void toonLineChanged();
|
||||
void textureSizeChanged();
|
||||
void interpolationEnabledChanged();
|
||||
void scriptEnabledChanged();
|
||||
public slots:
|
||||
void setComponentCombineMode(CombineMode mode);
|
||||
|
@ -37,6 +39,7 @@ public slots:
|
|||
void setToonLine(ToonLine toonLine);
|
||||
void setTextureSize(int textureSize);
|
||||
void setScriptEnabled(bool enabled);
|
||||
void setInterpolationEnabled(bool enabled);
|
||||
void reset();
|
||||
private:
|
||||
CombineMode m_componentCombineMode;
|
||||
|
@ -47,6 +50,7 @@ private:
|
|||
QSettings m_settings;
|
||||
int m_textureSize;
|
||||
bool m_scriptEnabled;
|
||||
bool m_interpolationEnabled;
|
||||
private:
|
||||
void loadDefault();
|
||||
};
|
||||
|
|
|
@ -85,6 +85,12 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
|
|||
toonShadingLayout->addWidget(toonLineSelectBox);
|
||||
toonShadingLayout->addStretch();
|
||||
|
||||
QCheckBox *interpolationEnabledBox = new QCheckBox();
|
||||
Theme::initCheckbox(interpolationEnabledBox);
|
||||
connect(interpolationEnabledBox, &QCheckBox::stateChanged, this, [=]() {
|
||||
Preferences::instance().setInterpolationEnabled(interpolationEnabledBox->isChecked());
|
||||
});
|
||||
|
||||
QComboBox *textureSizeSelectBox = new QComboBox;
|
||||
textureSizeSelectBox->addItem("512");
|
||||
textureSizeSelectBox->addItem("1024");
|
||||
|
@ -104,6 +110,7 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
|
|||
formLayout->addRow(tr("Part color:"), colorLayout);
|
||||
formLayout->addRow(tr("Combine mode:"), combineModeSelectBox);
|
||||
formLayout->addRow(tr("Flat shading:"), flatShadingBox);
|
||||
formLayout->addRow(tr("Interpolation:"), interpolationEnabledBox);
|
||||
formLayout->addRow(tr("Toon shading:"), toonShadingLayout);
|
||||
formLayout->addRow(tr("Texture size:"), textureSizeSelectBox);
|
||||
formLayout->addRow(tr("Script:"), scriptEnabledBox);
|
||||
|
@ -117,6 +124,7 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
|
|||
textureSizeSelectBox->setCurrentIndex(
|
||||
textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize()))
|
||||
);
|
||||
interpolationEnabledBox->setChecked(Preferences::instance().interpolationEnabled());
|
||||
scriptEnabledBox->setChecked(Preferences::instance().scriptEnabled());
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue