From bf3189ff49fa0ccfad5358470e61919f77748cc8 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 26 Mar 2023 00:13:19 +0100 Subject: [PATCH] Some more improvements of editor persistence. --- src/SkinnedMesh.cc | 9 +++++--- src/main.cc | 54 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/SkinnedMesh.cc b/src/SkinnedMesh.cc index f113cb1..10c39ab 100644 --- a/src/SkinnedMesh.cc +++ b/src/SkinnedMesh.cc @@ -101,7 +101,12 @@ void SkinnedMesh::CalcModelMatrices() { void SkinnedMesh::DrawSkeleton() {} void SkinnedMesh::DrawDebugUi() { - ImGui::Begin("SkinnedMesh"); + if (ImGui::TreeNode("Bones")) { + for (int i = 0; i < m_skeleton.num_joints(); i++) { + ImGui::Text(m_skeleton.joint_names()[i]); + } + ImGui::TreePop(); + } ImGui::Text("Animations"); @@ -132,6 +137,4 @@ void SkinnedMesh::DrawDebugUi() { } } } - - ImGui::End(); } \ No newline at end of file diff --git a/src/main.cc b/src/main.cc index e0d8e72..40ede66 100644 --- a/src/main.cc +++ b/src/main.cc @@ -115,13 +115,18 @@ struct ApplicationConfig { int position[2] = {20, 20}; int size[2] = {800, 500}; }; - GraphEditor graph_editor; + struct SkinnedMeshWidget { + bool visible = false; + int position[2] = {20, 20}; + int size[2] = {800, 500}; + }; + SkinnedMeshWidget skinned_mesh_widget; + bool show_imgui_demo_window = false; bool show_another_window = false; bool show_camera_widget = false; - bool show_skinned_mesh_widget = false; }; void to_json(nlohmann::json& j, const ApplicationConfig& config) { @@ -140,7 +145,12 @@ void to_json(nlohmann::json& j, const ApplicationConfig& config) { j["graph_editor"]["size"][0] = config.graph_editor.size[0]; j["graph_editor"]["size"][1] = config.graph_editor.size[1]; - j["skinned_mesh_widget"]["visible"] = config.show_skinned_mesh_widget; + j["skinned_mesh_widget"]["visible"] = config.skinned_mesh_widget.visible; + j["skinned_mesh_widget"]["position"][0] = config.skinned_mesh_widget.position[0]; + j["skinned_mesh_widget"]["position"][1] = config.skinned_mesh_widget.position[1]; + j["skinned_mesh_widget"]["size"][0] = config.skinned_mesh_widget.size[0]; + j["skinned_mesh_widget"]["size"][1] = config.skinned_mesh_widget.size[1]; + j["camera_widget"]["visible"] = config.show_camera_widget; } @@ -177,10 +187,23 @@ void from_json(const nlohmann::json& j, ApplicationConfig& config) { } } - if (j.contains("skinned_mesh_widget") and j["skinned_mesh_widget"].contains("visible")) { - config.show_skinned_mesh_widget = j["skinned_mesh_widget"]["visible"]; - } + + if (j.contains("skinned_mesh_widget")) { + if (j["skinned_mesh_widget"].contains("visible")) { + config.skinned_mesh_widget.visible = j["skinned_mesh_widget"]["visible"]; + } + + if (j["skinned_mesh_widget"].contains("position") and j["skinned_mesh_widget"]["position"].size() == 2) { + config.skinned_mesh_widget.position[0] = j["skinned_mesh_widget"]["position"].at(0); + config.skinned_mesh_widget.position[1] = j["skinned_mesh_widget"]["position"].at(1); + } + if (j["skinned_mesh_widget"].contains("size") and j["skinned_mesh_widget"]["size"].size() == 2) { + config.skinned_mesh_widget.size[0] = j["skinned_mesh_widget"]["size"].at(0); + config.skinned_mesh_widget.size[1] = j["skinned_mesh_widget"]["size"].at(1); + } + } + if (j.contains("camera_widget") and j["camera_widget"].contains("visible")) { config.show_camera_widget = j["camera_widget"]["visible"]; } @@ -592,7 +615,7 @@ int main() { &gApplicationConfig.show_camera_widget); ImGui::Checkbox( "Skinned Mesh", - &gApplicationConfig.show_skinned_mesh_widget); + &gApplicationConfig.skinned_mesh_widget.visible); ImGui::Separator(); ImGui::Checkbox( "ImGui Demo", @@ -624,8 +647,23 @@ int main() { draw_grid(); - if (gApplicationConfig.show_skinned_mesh_widget) { + if (gApplicationConfig.skinned_mesh_widget.visible) { + ImGui::SetNextWindowPos(ImVec2(gApplicationConfig.skinned_mesh_widget.position[0], gApplicationConfig.skinned_mesh_widget.position[1]), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(gApplicationConfig.skinned_mesh_widget.size[0], gApplicationConfig.skinned_mesh_widget.size[1]), ImGuiCond_FirstUseEver); + + ImGui::Begin("SkinnedMesh", &gApplicationConfig.skinned_mesh_widget.visible); + + ImVec2 skinned_mesh_widget_position = ImGui::GetWindowPos(); + gApplicationConfig.skinned_mesh_widget.position[0] = skinned_mesh_widget_position.x; + gApplicationConfig.skinned_mesh_widget.position[1] = skinned_mesh_widget_position.y; + + ImVec2 skinned_mesh_widget_size = ImGui::GetWindowSize(); + gApplicationConfig.skinned_mesh_widget.size[0] = skinned_mesh_widget_size.x; + gApplicationConfig.skinned_mesh_widget.size[1] = skinned_mesh_widget_size.y; + skinned_mesh.DrawDebugUi(); + + ImGui::End(); } // TODO: add AnimGraph to calculate pose