Some progress with new graph editor.

RefactorUnifiedBlendTreeStateMachineHandling
Martin Felis 2024-03-16 19:49:41 +01:00
parent e61180c4a7
commit fdb2b6ffc5
1 changed files with 36 additions and 22 deletions

View File

@ -14,6 +14,7 @@
#include "misc/cpp/imgui_stdlib.h" #include "misc/cpp/imgui_stdlib.h"
static AnimGraphResource sGraphGresource = AnimGraphResource(); static AnimGraphResource sGraphGresource = AnimGraphResource();
static bool sGraphLoadedThisFrame = false;
ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) { ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) {
switch (socket_type) { switch (socket_type) {
@ -261,6 +262,7 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
// i, // i,
// ImVec2(node_resource.m_position[0], node_resource.m_position[1])); // ImVec2(node_resource.m_position[0], node_resource.m_position[1]));
// } // }
sGraphLoadedThisFrame = true;
} }
if (ImGui::Button("Clear")) { if (ImGui::Button("Clear")) {
sGraphGresource.clear(); sGraphGresource.clear();
@ -283,6 +285,8 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
ax::NodeEditor::SetCurrentEditor(context); ax::NodeEditor::SetCurrentEditor(context);
ax::NodeEditor::Begin("Graph Editor"); ax::NodeEditor::Begin("Graph Editor");
int node_editor_id = 0;
for (size_t node_id = 0, n = sGraphGresource.m_nodes.size(); node_id < n; for (size_t node_id = 0, n = sGraphGresource.m_nodes.size(); node_id < n;
node_id++) { node_id++) {
AnimNodeResource& node_resource = sGraphGresource.m_nodes[node_id]; AnimNodeResource& node_resource = sGraphGresource.m_nodes[node_id];
@ -291,31 +295,35 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
// continue; // 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()); ImGui::Text("%s", node_resource.m_type_name.c_str());
// Inputs // // Inputs
std::vector<Socket>& node_inputs = // std::vector<Socket>& node_inputs =
node_resource.m_socket_accessor->m_inputs; // node_resource.m_socket_accessor->m_inputs;
for (size_t j = 0, ni = node_inputs.size(); j < ni; j++) { // for (size_t j = 0, ni = node_inputs.size(); j < ni; j++) {
Socket& socket = node_inputs[j]; // Socket& socket = node_inputs[j];
int pin_id = static_cast<int>(node_id) + j * 1000; // int pin_id = static_cast<int>(node_id) + j * 1000;
ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Input); // ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Input);
ImGui::Text("%s", socket.m_name.c_str()); // ImGui::Text("%s", socket.m_name.c_str());
ax::NodeEditor::EndPin(); // ax::NodeEditor::EndPin();
} // }
//
// Outputs // // Outputs
const std::vector<Socket>& node_outputs = // const std::vector<Socket>& node_outputs =
node_resource.m_socket_accessor->m_outputs; // node_resource.m_socket_accessor->m_outputs;
for (size_t j = 0, ni = node_outputs.size(); j < ni; j++) { // for (size_t j = 0, ni = node_outputs.size(); j < ni; j++) {
const Socket& socket = node_outputs[j]; // const Socket& socket = node_outputs[j];
int pin_id = static_cast<int>(node_id) + j * 1000 * 1000; // int pin_id = static_cast<int>(node_id) + j * 1000 * 1000;
ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Output); // ax::NodeEditor::BeginPin(pin_id, ax::NodeEditor::PinKind::Output);
ImGui::Text("%s", socket.m_name.c_str()); // ImGui::Text("%s", socket.m_name.c_str());
ax::NodeEditor::EndPin(); // ax::NodeEditor::EndPin();
} // }
ax::NodeEditor::EndNode(); ax::NodeEditor::EndNode();
} }
@ -366,6 +374,12 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
ax::NodeEditor::End(); ax::NodeEditor::End();
ax::NodeEditor::SetCurrentEditor(nullptr); ax::NodeEditor::SetCurrentEditor(nullptr);
if (sGraphLoadedThisFrame) {
ax::NodeEditor::NavigateToContent();
}
sGraphLoadedThisFrame = false;
} }
void LegacyAnimGraphEditorUpdate() { void LegacyAnimGraphEditorUpdate() {