Skip to content

Commit b9c0bc7

Browse files
Persist Model Viewer view options across model switches; default Color by Bone Index Raw to off
1 parent 117a681 commit b9c0bc7

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

SourceFiles/ModelViewer/ModelViewer.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,22 @@ void ActivateModelViewer(MapRenderer* mapRenderer)
6060
// Defer camera fit to first frame when viewport is properly set
6161
g_modelViewerState.needsCameraFit = true;
6262

63-
// Enable bone visualization by default in model viewer
64-
g_animationState.visualization.showBones = true;
65-
g_modelViewerState.options.showBones = true;
63+
// Re-apply persistent model viewer visualization settings whenever a new model is loaded.
64+
auto& vis = g_animationState.visualization;
65+
const auto& options = g_modelViewerState.options;
66+
vis.showMesh = options.showMesh;
67+
vis.wireframeMode = options.showWireframe;
68+
vis.meshAlpha = options.meshAlpha;
69+
vis.showBones = options.showBones;
70+
vis.jointRadius = options.boneRadius;
71+
vis.lockRootPosition = options.lockRootPosition;
72+
vis.colorByBoneIndex = options.colorByBoneIndex;
73+
vis.showRawBoneIndex = options.showRawBoneIndex;
74+
75+
if (g_animationState.controller)
76+
{
77+
g_animationState.controller->SetLockRootPosition(vis.lockRootPosition);
78+
}
6679
}
6780

6881
void DeactivateModelViewer(MapRenderer* mapRenderer)

SourceFiles/ModelViewer/ModelViewer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ struct ModelViewerOptions
3838
bool showWireframe = false;
3939
bool showBones = true;
4040
bool showBoneLabels = true;
41+
float meshAlpha = 1.0f;
42+
bool lockRootPosition = false;
43+
bool colorByBoneIndex = false;
44+
bool showRawBoneIndex = false; // Default to remapped skeleton bone indices.
4145

4246
// Background color
4347
DirectX::XMFLOAT4 backgroundColor = { 0.1f, 0.1f, 0.15f, 1.0f };

SourceFiles/ModelViewer/ModelViewerPanel.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ void draw_model_viewer_panel(MapRenderer* mapRenderer, std::map<int, std::unique
130130
auto& options = state.options;
131131
auto& vis = g_animationState.visualization;
132132

133+
// Keep newly created animation controllers aligned with persisted model viewer settings.
134+
if (g_animationState.controller &&
135+
g_animationState.controller->IsRootPositionLocked() != vis.lockRootPosition)
136+
{
137+
g_animationState.controller->SetLockRootPosition(vis.lockRootPosition);
138+
}
139+
133140
// Sync bone info from animation state
134141
if (g_animationState.clip && g_animationState.clip->boneTracks.size() != state.bones.size())
135142
{
@@ -1042,7 +1049,10 @@ void draw_model_viewer_panel(MapRenderer* mapRenderer, std::map<int, std::unique
10421049

10431050
// Mesh alpha
10441051
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
1045-
ImGui::SliderFloat("##MeshAlpha", &vis.meshAlpha, 0.0f, 1.0f, "Mesh Alpha: %.2f");
1052+
if (ImGui::SliderFloat("##MeshAlpha", &vis.meshAlpha, 0.0f, 1.0f, "Mesh Alpha: %.2f"))
1053+
{
1054+
options.meshAlpha = vis.meshAlpha;
1055+
}
10461056

10471057
// Lock root position option
10481058
if (g_animationState.hasAnimation && g_animationState.controller)
@@ -1051,6 +1061,7 @@ void draw_model_viewer_panel(MapRenderer* mapRenderer, std::map<int, std::unique
10511061
if (ImGui::Checkbox("Lock Root Position", &lockRoot))
10521062
{
10531063
vis.lockRootPosition = lockRoot;
1064+
options.lockRootPosition = lockRoot;
10541065
g_animationState.controller->SetLockRootPosition(lockRoot);
10551066
}
10561067
if (ImGui::IsItemHovered())
@@ -1064,7 +1075,10 @@ void draw_model_viewer_panel(MapRenderer* mapRenderer, std::map<int, std::unique
10641075
ImGui::Spacing();
10651076

10661077
// Debug: color by bone index
1067-
ImGui::Checkbox("Color by Bone Index", &vis.colorByBoneIndex);
1078+
if (ImGui::Checkbox("Color by Bone Index", &vis.colorByBoneIndex))
1079+
{
1080+
options.colorByBoneIndex = vis.colorByBoneIndex;
1081+
}
10681082
if (ImGui::IsItemHovered())
10691083
{
10701084
ImGui::SetTooltip("Color vertices by bone index.\nUseful for debugging bone assignments.");
@@ -1075,7 +1089,7 @@ void draw_model_viewer_panel(MapRenderer* mapRenderer, std::map<int, std::unique
10751089
ImGui::SameLine();
10761090
if (ImGui::Checkbox("Raw", &vis.showRawBoneIndex))
10771091
{
1078-
// No rebuild needed, just changes shader mode
1092+
options.showRawBoneIndex = vis.showRawBoneIndex;
10791093
}
10801094
if (ImGui::IsItemHovered())
10811095
{

0 commit comments

Comments
 (0)