From fdb2b6ffc5b73682c5c6bc3ce19a802a812f2cca Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sat, 16 Mar 2024 19:49:41 +0100 Subject: [PATCH] Some progress with new graph editor. --- src/AnimGraph/AnimGraphEditor.cc | 58 ++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/AnimGraph/AnimGraphEditor.cc b/src/AnimGraph/AnimGraphEditor.cc index ba6a6bf..73786d8 100644 --- a/src/AnimGraph/AnimGraphEditor.cc +++ b/src/AnimGraph/AnimGraphEditor.cc @@ -14,6 +14,7 @@ #include "misc/cpp/imgui_stdlib.h" static AnimGraphResource sGraphGresource = AnimGraphResource(); +static bool sGraphLoadedThisFrame = false; ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) { switch (socket_type) { @@ -261,6 +262,7 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) { // i, // ImVec2(node_resource.m_position[0], node_resource.m_position[1])); // } + sGraphLoadedThisFrame = true; } if (ImGui::Button("Clear")) { sGraphGresource.clear(); @@ -283,6 +285,8 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) { ax::NodeEditor::SetCurrentEditor(context); ax::NodeEditor::Begin("Graph Editor"); + int node_editor_id = 0; + for (size_t node_id = 0, n = sGraphGresource.m_nodes.size(); node_id < n; node_id++) { AnimNodeResource& node_resource = sGraphGresource.m_nodes[node_id]; @@ -291,31 +295,35 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) { // continue; } + node_editor_id++; - ax::NodeEditor::BeginNode(node_id); + if (sGraphLoadedThisFrame) { + ax::NodeEditor::SetNodePosition(node_editor_id, ImVec2(node_resource.m_position[0], node_resource.m_position[1])); + } + ax::NodeEditor::BeginNode(node_editor_id); ImGui::Text("%s", node_resource.m_type_name.c_str()); - // Inputs - std::vector& node_inputs = - node_resource.m_socket_accessor->m_inputs; - for (size_t j = 0, ni = node_inputs.size(); j < ni; j++) { - Socket& socket = node_inputs[j]; - int pin_id = static_cast(node_id) + j * 1000; - ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Input); - ImGui::Text("%s", socket.m_name.c_str()); - ax::NodeEditor::EndPin(); - } - - // Outputs - const std::vector& node_outputs = - node_resource.m_socket_accessor->m_outputs; - for (size_t j = 0, ni = node_outputs.size(); j < ni; j++) { - const Socket& socket = node_outputs[j]; - int pin_id = static_cast(node_id) + j * 1000 * 1000; - ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Output); - ImGui::Text("%s", socket.m_name.c_str()); - ax::NodeEditor::EndPin(); - } +// // Inputs +// std::vector& node_inputs = +// node_resource.m_socket_accessor->m_inputs; +// for (size_t j = 0, ni = node_inputs.size(); j < ni; j++) { +// Socket& socket = node_inputs[j]; +// int pin_id = static_cast(node_id) + j * 1000; +// ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Input); +// ImGui::Text("%s", socket.m_name.c_str()); +// ax::NodeEditor::EndPin(); +// } +// +// // Outputs +// const std::vector& node_outputs = +// node_resource.m_socket_accessor->m_outputs; +// for (size_t j = 0, ni = node_outputs.size(); j < ni; j++) { +// const Socket& socket = node_outputs[j]; +// int pin_id = static_cast(node_id) + j * 1000 * 1000; +// ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Output); +// ImGui::Text("%s", socket.m_name.c_str()); +// ax::NodeEditor::EndPin(); +// } ax::NodeEditor::EndNode(); } @@ -366,6 +374,12 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) { ax::NodeEditor::End(); ax::NodeEditor::SetCurrentEditor(nullptr); + + if (sGraphLoadedThisFrame) { + ax::NodeEditor::NavigateToContent(); + } + + sGraphLoadedThisFrame = false; } void LegacyAnimGraphEditorUpdate() {