Added mesh LOD distance option.

This commit is contained in:
Leonardo Zide 2020-08-15 16:16:26 -07:00
parent c8acaeb2f0
commit 0828fd1e2c
11 changed files with 55 additions and 4 deletions

View file

@ -24,6 +24,7 @@ void lcPreferences::LoadDefaults()
mDrawEdgeLines = lcGetProfileInt(LC_PROFILE_DRAW_EDGE_LINES); mDrawEdgeLines = lcGetProfileInt(LC_PROFILE_DRAW_EDGE_LINES);
mLineWidth = lcGetProfileFloat(LC_PROFILE_LINE_WIDTH); mLineWidth = lcGetProfileFloat(LC_PROFILE_LINE_WIDTH);
mAllowLOD = lcGetProfileInt(LC_PROFILE_ALLOW_LOD); mAllowLOD = lcGetProfileInt(LC_PROFILE_ALLOW_LOD);
mMeshLODDistance = lcGetProfileFloat(LC_PROFILE_LOD_DISTANCE);
mFadeSteps = lcGetProfileInt(LC_PROFILE_FADE_STEPS); mFadeSteps = lcGetProfileInt(LC_PROFILE_FADE_STEPS);
mFadeStepsColor = lcGetProfileInt(LC_PROFILE_FADE_STEPS_COLOR); mFadeStepsColor = lcGetProfileInt(LC_PROFILE_FADE_STEPS_COLOR);
mHighlightNewParts = lcGetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS); mHighlightNewParts = lcGetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS);
@ -56,6 +57,7 @@ void lcPreferences::SaveDefaults()
lcSetProfileInt(LC_PROFILE_DRAW_EDGE_LINES, mDrawEdgeLines); lcSetProfileInt(LC_PROFILE_DRAW_EDGE_LINES, mDrawEdgeLines);
lcSetProfileFloat(LC_PROFILE_LINE_WIDTH, mLineWidth); lcSetProfileFloat(LC_PROFILE_LINE_WIDTH, mLineWidth);
lcSetProfileInt(LC_PROFILE_ALLOW_LOD, mAllowLOD); lcSetProfileInt(LC_PROFILE_ALLOW_LOD, mAllowLOD);
lcSetProfileFloat(LC_PROFILE_LOD_DISTANCE, mMeshLODDistance);
lcSetProfileInt(LC_PROFILE_FADE_STEPS, mFadeSteps); lcSetProfileInt(LC_PROFILE_FADE_STEPS, mFadeSteps);
lcSetProfileInt(LC_PROFILE_FADE_STEPS_COLOR, mFadeStepsColor); lcSetProfileInt(LC_PROFILE_FADE_STEPS_COLOR, mFadeStepsColor);
lcSetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS, mHighlightNewParts); lcSetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS, mHighlightNewParts);

View file

@ -43,6 +43,7 @@ public:
bool mDrawEdgeLines; bool mDrawEdgeLines;
float mLineWidth; float mLineWidth;
bool mAllowLOD; bool mAllowLOD;
float mMeshLODDistance;
bool mFadeSteps; bool mFadeSteps;
quint32 mFadeStepsColor; quint32 mFadeStepsColor;
bool mHighlightNewParts; bool mHighlightNewParts;

View file

@ -496,7 +496,7 @@ int lcMesh::GetLodIndex(float Distance) const
if (lcGetPiecesLibrary()->GetStudLogo()) if (lcGetPiecesLibrary()->GetStudLogo())
return LC_MESH_LOD_HIGH; return LC_MESH_LOD_HIGH;
if (mLods[LC_MESH_LOD_LOW].NumSections && (Distance - mRadius) > 250.0f) if (mLods[LC_MESH_LOD_LOW].NumSections && (Distance > mRadius))
return LC_MESH_LOD_LOW; return LC_MESH_LOD_LOW;
else else
return LC_MESH_LOD_HIGH; return LC_MESH_LOD_HIGH;

View file

@ -58,6 +58,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "FixedAxes", false), // LC_PROFILE_FIXED_AXES lcProfileEntry("Settings", "FixedAxes", false), // LC_PROFILE_FIXED_AXES
lcProfileEntry("Settings", "LineWidth", 1.0f), // LC_PROFILE_LINE_WIDTH lcProfileEntry("Settings", "LineWidth", 1.0f), // LC_PROFILE_LINE_WIDTH
lcProfileEntry("Settings", "AllowLOD", true), // LC_PROFILE_ALLOW_LOD lcProfileEntry("Settings", "AllowLOD", true), // LC_PROFILE_ALLOW_LOD
lcProfileEntry("Settings", "LODDistance", 750.0f), // LC_PROFILE_LOD_DISTANCE
lcProfileEntry("Settings", "FadeSteps", false), // LC_PROFILE_FADE_STEPS lcProfileEntry("Settings", "FadeSteps", false), // LC_PROFILE_FADE_STEPS
lcProfileEntry("Settings", "FadeStepsColor", LC_RGBA(128, 128, 128, 128)), // LC_PROFILE_FADE_STEPS_COLOR lcProfileEntry("Settings", "FadeStepsColor", LC_RGBA(128, 128, 128, 128)), // LC_PROFILE_FADE_STEPS_COLOR
lcProfileEntry("Settings", "HighlightNewParts", 0), // LC_PROFILE_HIGHLIGHT_NEW_PARTS lcProfileEntry("Settings", "HighlightNewParts", 0), // LC_PROFILE_HIGHLIGHT_NEW_PARTS

View file

@ -6,6 +6,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_FIXED_AXES, LC_PROFILE_FIXED_AXES,
LC_PROFILE_LINE_WIDTH, LC_PROFILE_LINE_WIDTH,
LC_PROFILE_ALLOW_LOD, LC_PROFILE_ALLOW_LOD,
LC_PROFILE_LOD_DISTANCE,
LC_PROFILE_FADE_STEPS, LC_PROFILE_FADE_STEPS,
LC_PROFILE_FADE_STEPS_COLOR, LC_PROFILE_FADE_STEPS_COLOR,
LC_PROFILE_HIGHLIGHT_NEW_PARTS, LC_PROFILE_HIGHLIGHT_NEW_PARTS,

View file

@ -14,6 +14,7 @@ lcScene::lcScene()
mDrawInterface = false; mDrawInterface = false;
mAllowWireframe = true; mAllowWireframe = true;
mAllowLOD = true; mAllowLOD = true;
mMeshLODDistance = 250.0f;
mHasFadedParts = false; mHasFadedParts = false;
mPreTranslucentCallback = nullptr; mPreTranslucentCallback = nullptr;
} }
@ -69,7 +70,7 @@ void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorInde
RenderMesh.Mesh = Mesh; RenderMesh.Mesh = Mesh;
RenderMesh.ColorIndex = ColorIndex; RenderMesh.ColorIndex = ColorIndex;
RenderMesh.State = State; RenderMesh.State = State;
const float Distance = fabsf(lcMul31(WorldMatrix[3], mViewMatrix).z); const float Distance = fabsf(lcMul31(WorldMatrix[3], mViewMatrix).z) - mMeshLODDistance;
RenderMesh.LodIndex = mAllowLOD ? RenderMesh.Mesh->GetLodIndex(Distance) : LC_MESH_LOD_HIGH; RenderMesh.LodIndex = mAllowLOD ? RenderMesh.Mesh->GetLodIndex(Distance) : LC_MESH_LOD_HIGH;
const bool ForceTranslucent = (mTranslucentFade && State == lcRenderMeshState::Faded); const bool ForceTranslucent = (mTranslucentFade && State == lcRenderMeshState::Faded);

View file

@ -69,6 +69,11 @@ public:
mAllowLOD = AllowLOD; mAllowLOD = AllowLOD;
} }
void SetLODDistance(float Distance)
{
mMeshLODDistance = Distance;
}
void SetPreTranslucentCallback(std::function<void()> Callback) void SetPreTranslucentCallback(std::function<void()> Callback)
{ {
mPreTranslucentCallback = Callback; mPreTranslucentCallback = Callback;
@ -102,6 +107,7 @@ protected:
bool mDrawInterface; bool mDrawInterface;
bool mAllowWireframe; bool mAllowWireframe;
bool mAllowLOD; bool mAllowLOD;
float mMeshLODDistance;
lcVector4 mFadeColor; lcVector4 mFadeColor;
lcVector4 mHighlightColor; lcVector4 mHighlightColor;

View file

@ -813,6 +813,7 @@ void View::OnDraw()
const bool DrawInterface = mWidget != nullptr; const bool DrawInterface = mWidget != nullptr;
mScene.SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr); mScene.SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr);
mScene.SetLODDistance(Preferences.mMeshLODDistance);
mScene.Begin(mCamera->mWorldView); mScene.Begin(mCamera->mWorldView);

View file

@ -89,6 +89,10 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
ui->LineWidthSlider->setValue((mOptions->Preferences.mLineWidth - mLineWidthRange[0]) / mLineWidthGranularity); ui->LineWidthSlider->setValue((mOptions->Preferences.mLineWidth - mLineWidthRange[0]) / mLineWidthGranularity);
ui->MeshLOD->setChecked(mOptions->Preferences.mAllowLOD); ui->MeshLOD->setChecked(mOptions->Preferences.mAllowLOD);
ui->MeshLODSlider->setRange(0, 1500.0f / mMeshLODMultiplier);
ui->MeshLODSlider->setValue(mOptions->Preferences.mMeshLODDistance / mMeshLODMultiplier);
ui->FadeSteps->setChecked(mOptions->Preferences.mFadeSteps); ui->FadeSteps->setChecked(mOptions->Preferences.mFadeSteps);
ui->HighlightNewParts->setChecked(mOptions->Preferences.mHighlightNewParts); ui->HighlightNewParts->setChecked(mOptions->Preferences.mHighlightNewParts);
ui->gridStuds->setChecked(mOptions->Preferences.mDrawGridStuds); ui->gridStuds->setChecked(mOptions->Preferences.mDrawGridStuds);
@ -165,6 +169,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
on_antiAliasing_toggled(); on_antiAliasing_toggled();
on_edgeLines_toggled(); on_edgeLines_toggled();
on_LineWidthSlider_valueChanged(); on_LineWidthSlider_valueChanged();
on_MeshLODSlider_valueChanged();
on_FadeSteps_toggled(); on_FadeSteps_toggled();
on_HighlightNewParts_toggled(); on_HighlightNewParts_toggled();
on_gridStuds_toggled(); on_gridStuds_toggled();
@ -236,6 +241,7 @@ void lcQPreferencesDialog::accept()
mOptions->Preferences.mDrawEdgeLines = ui->edgeLines->isChecked(); mOptions->Preferences.mDrawEdgeLines = ui->edgeLines->isChecked();
mOptions->Preferences.mLineWidth = mLineWidthRange[0] + static_cast<float>(ui->LineWidthSlider->value()) * mLineWidthGranularity; mOptions->Preferences.mLineWidth = mLineWidthRange[0] + static_cast<float>(ui->LineWidthSlider->value()) * mLineWidthGranularity;
mOptions->Preferences.mAllowLOD = ui->MeshLOD->isChecked(); mOptions->Preferences.mAllowLOD = ui->MeshLOD->isChecked();
mOptions->Preferences.mMeshLODDistance = ui->MeshLODSlider->value() * mMeshLODMultiplier;
mOptions->Preferences.mFadeSteps = ui->FadeSteps->isChecked(); mOptions->Preferences.mFadeSteps = ui->FadeSteps->isChecked();
mOptions->Preferences.mHighlightNewParts = ui->HighlightNewParts->isChecked(); mOptions->Preferences.mHighlightNewParts = ui->HighlightNewParts->isChecked();
@ -440,6 +446,12 @@ void lcQPreferencesDialog::on_LineWidthSlider_valueChanged()
ui->LineWidthLabel->setText(QString::number(Value)); ui->LineWidthLabel->setText(QString::number(Value));
} }
void lcQPreferencesDialog::on_MeshLODSlider_valueChanged()
{
float Value = ui->MeshLODSlider->value() * mMeshLODMultiplier;
ui->MeshLODLabel->setText(QString::number(static_cast<int>(Value)));
}
void lcQPreferencesDialog::on_FadeSteps_toggled() void lcQPreferencesDialog::on_FadeSteps_toggled()
{ {
ui->FadeStepsColor->setEnabled(ui->FadeSteps->isChecked()); ui->FadeStepsColor->setEnabled(ui->FadeSteps->isChecked());

View file

@ -37,6 +37,7 @@ public slots:
void on_antiAliasing_toggled(); void on_antiAliasing_toggled();
void on_edgeLines_toggled(); void on_edgeLines_toggled();
void on_LineWidthSlider_valueChanged(); void on_LineWidthSlider_valueChanged();
void on_MeshLODSlider_valueChanged();
void on_FadeSteps_toggled(); void on_FadeSteps_toggled();
void on_HighlightNewParts_toggled(); void on_HighlightNewParts_toggled();
void on_gridStuds_toggled(); void on_gridStuds_toggled();
@ -73,4 +74,5 @@ private:
float mLineWidthRange[2]; float mLineWidthRange[2];
float mLineWidthGranularity; float mLineWidthGranularity;
static constexpr float mMeshLODMultiplier = 25.0f;
}; };

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>598</width> <width>598</width>
<height>494</height> <height>503</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -499,6 +499,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1">
<widget class="QSlider" name="MeshLODSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLabel" name="MeshLODLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -1322,6 +1345,7 @@
<tabstop>authorName</tabstop> <tabstop>authorName</tabstop>
<tabstop>fixedDirectionKeys</tabstop> <tabstop>fixedDirectionKeys</tabstop>
<tabstop>autoLoadMostRecent</tabstop> <tabstop>autoLoadMostRecent</tabstop>
<tabstop>RestoreTabLayout</tabstop>
<tabstop>antiAliasing</tabstop> <tabstop>antiAliasing</tabstop>
<tabstop>antiAliasingSamples</tabstop> <tabstop>antiAliasingSamples</tabstop>
<tabstop>studLogo</tabstop> <tabstop>studLogo</tabstop>
@ -1329,6 +1353,7 @@
<tabstop>edgeLines</tabstop> <tabstop>edgeLines</tabstop>
<tabstop>LineWidthSlider</tabstop> <tabstop>LineWidthSlider</tabstop>
<tabstop>MeshLOD</tabstop> <tabstop>MeshLOD</tabstop>
<tabstop>MeshLODSlider</tabstop>
<tabstop>FadeSteps</tabstop> <tabstop>FadeSteps</tabstop>
<tabstop>FadeStepsColor</tabstop> <tabstop>FadeStepsColor</tabstop>
<tabstop>HighlightNewParts</tabstop> <tabstop>HighlightNewParts</tabstop>
@ -1373,7 +1398,6 @@
<tabstop>mouseAssign</tabstop> <tabstop>mouseAssign</tabstop>
<tabstop>mouseRemove</tabstop> <tabstop>mouseRemove</tabstop>
<tabstop>mouseSensitivity</tabstop> <tabstop>mouseSensitivity</tabstop>
<tabstop>RestoreTabLayout</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>