Some more improvements of editor persistence.

AnimGraphEditor
Martin Felis 2023-03-26 00:13:19 +01:00
parent 3d387a5dad
commit bf3189ff49
2 changed files with 52 additions and 11 deletions

View File

@ -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();
}

View File

@ -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