Cleaned up some compilation issues for the AnimGraphEditor.

RefactorUnifiedBlendTreeStateMachineHandling
Martin Felis 2024-04-05 00:44:37 +02:00
parent 1741238a61
commit 9f9ac60f9c
4 changed files with 146 additions and 95 deletions

View File

@ -13,8 +13,7 @@
#include "imnodes.h" #include "imnodes.h"
#include "misc/cpp/imgui_stdlib.h" #include "misc/cpp/imgui_stdlib.h"
static AnimGraphResource sGraphGresource = static AnimGraphResource sGraphGresource = AnimGraphResource();
AnimGraphResource();
static bool sGraphLoadedThisFrame = false; static bool sGraphLoadedThisFrame = false;
ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) { ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) {
@ -58,14 +57,14 @@ void NodeSocketEditor(Socket& socket) {
} }
} }
void RemoveConnectionsForSocket( void RemoveBlendTreeConnectionsForSocket(
AnimGraphResource& graph_resource, BlendTreeResource& blend_tree_resource,
AnimNodeResource& node_resource, AnimNodeResource* node_resource,
Socket& socket) { Socket& socket) {
std::vector<BlendTreeConnectionResource>::iterator iter = std::vector<BlendTreeConnectionResource>::iterator iter =
graph_resource.m_blend_tree_resource.m_connections.begin(); blend_tree_resource.m_connections.begin();
while (iter != graph_resource.m_blend_tree_resource.m_connections.end()) { while (iter != blend_tree_resource.m_connections.end()) {
// TODO adjust for refactor // TODO adjust for refactor
assert(false); assert(false);
@ -160,24 +159,24 @@ void SkinnedMeshWidget(SkinnedMesh* skinned_mesh) {
} }
void AnimGraphEditorRenderSidebar( void AnimGraphEditorRenderSidebar(
AnimGraphBlendTreeResource& graph_resource, BlendTreeResource& blend_tree_resource,
AnimNodeResource& node_resource) { AnimNodeResource* node_resource) {
ImGui::Text("[%s]", node_resource.m_node_type_name.c_str()); ImGui::Text("[%s]", node_resource->m_node_type_name.c_str());
char node_name_buffer[256]; char node_name_buffer[256];
memset(node_name_buffer, 0, sizeof(node_name_buffer)); memset(node_name_buffer, 0, sizeof(node_name_buffer));
strncpy( strncpy(
node_name_buffer, node_name_buffer,
node_resource.m_name.c_str(), node_resource->m_name.c_str(),
std::min(node_resource.m_name.size(), sizeof(node_name_buffer))); std::min(node_resource->m_name.size(), sizeof(node_name_buffer)));
if (ImGui::InputText("Name", node_name_buffer, sizeof(node_name_buffer))) { if (ImGui::InputText("Name", node_name_buffer, sizeof(node_name_buffer))) {
node_resource.m_name = node_name_buffer; node_resource->m_name = node_name_buffer;
} }
int num_properties = node_resource.m_socket_accessor->m_properties.size(); int num_properties = node_resource->m_socket_accessor->m_properties.size();
for (int i = 0; i < num_properties; i++) { for (int i = 0; i < num_properties; i++) {
Socket& property = node_resource.m_socket_accessor->m_properties[i]; Socket& property = node_resource->m_socket_accessor->m_properties[i];
if (property.m_type == SocketType::SocketTypeInt) { if (property.m_type == SocketType::SocketTypeInt) {
ImGui::InputInt( ImGui::InputInt(
property.m_name.c_str(), property.m_name.c_str(),
@ -212,11 +211,11 @@ void AnimGraphEditorRenderSidebar(
} }
} }
if (&node_resource == &graph_resource.getGraphOutputNode()) { if (node_resource == blend_tree_resource.GetGraphOutputNode()) {
ImGui::Text("Outputs"); ImGui::Text("Outputs");
// Graph outputs are the inputs of the output node! // Graph outputs are the inputs of the output node!
std::vector<Socket>& outputs = node_resource.m_socket_accessor->m_inputs; std::vector<Socket>& outputs = node_resource->m_socket_accessor->m_inputs;
std::vector<Socket>::iterator iter = outputs.begin(); std::vector<Socket>::iterator iter = outputs.begin();
while (iter != outputs.end()) { while (iter != outputs.end()) {
@ -224,7 +223,10 @@ void AnimGraphEditorRenderSidebar(
ImGui::PushID(&output); ImGui::PushID(&output);
NodeSocketEditor(output); NodeSocketEditor(output);
if (ImGui::Button("X")) { if (ImGui::Button("X")) {
RemoveConnectionsForSocket(graph_resource, node_resource, output); RemoveBlendTreeConnectionsForSocket(
blend_tree_resource,
node_resource,
output);
iter = outputs.erase(iter); iter = outputs.erase(iter);
} else { } else {
iter++; iter++;
@ -233,11 +235,11 @@ void AnimGraphEditorRenderSidebar(
} }
} }
if (&node_resource == &graph_resource.getGraphInputNode()) { if (node_resource == blend_tree_resource.GetGraphInputNode()) {
ImGui::Text("Inputs"); ImGui::Text("Inputs");
// Graph inputs are the outputs of the input node! // Graph inputs are the outputs of the input node!
std::vector<Socket>& inputs = node_resource.m_socket_accessor->m_outputs; std::vector<Socket>& inputs = node_resource->m_socket_accessor->m_outputs;
std::vector<Socket>::iterator iter = inputs.begin(); std::vector<Socket>::iterator iter = inputs.begin();
while (iter != inputs.end()) { while (iter != inputs.end()) {
@ -245,7 +247,10 @@ void AnimGraphEditorRenderSidebar(
ImGui::PushID(&input); ImGui::PushID(&input);
NodeSocketEditor(input); NodeSocketEditor(input);
if (ImGui::Button("X")) { if (ImGui::Button("X")) {
RemoveConnectionsForSocket(graph_resource, node_resource, input); RemoveBlendTreeConnectionsForSocket(
blend_tree_resource,
node_resource,
input);
iter = inputs.erase(iter); iter = inputs.erase(iter);
} else { } else {
iter++; iter++;
@ -258,10 +263,10 @@ void AnimGraphEditorRenderSidebar(
void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) { void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
ImGui::BeginMenuBar(); ImGui::BeginMenuBar();
if (ImGui::Button("Save")) { if (ImGui::Button("Save")) {
sGraphGresource.saveToFile("editor_graph.json"); sGraphGresource.SaveToFile("editor_graph.json");
} }
if (ImGui::Button("Load")) { if (ImGui::Button("Load")) {
sGraphGresource.loadFromFile("editor_graph.json"); sGraphGresource.LoadFromFile("editor_graph.json");
sGraphLoadedThisFrame = true; sGraphLoadedThisFrame = true;
// for (size_t i = 0, n = sGraphGresource.m_nodes.size(); i < n; i++) { // for (size_t i = 0, n = sGraphGresource.m_nodes.size(); i < n; i++) {
@ -272,7 +277,7 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
// } // }
} }
if (ImGui::Button("Clear")) { if (ImGui::Button("Clear")) {
sGraphGresource.clear(); sGraphGresource.Clear();
} }
char graph_name_buffer[256]; char graph_name_buffer[256];
memset(graph_name_buffer, 0, sizeof(graph_name_buffer)); memset(graph_name_buffer, 0, sizeof(graph_name_buffer));
@ -293,9 +298,12 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
ax::NodeEditor::Begin("Graph Editor"); ax::NodeEditor::Begin("Graph Editor");
#if 1 #if 1
for (size_t node_id = 0, n = sGraphGresource.m_nodes.size(); node_id < n; for (size_t node_id = 0,
n = sGraphGresource.m_blend_tree_resource.m_nodes.size();
node_id < n;
node_id++) { node_id++) {
AnimNodeResource& node_resource = sGraphGresource.m_nodes[node_id]; AnimNodeResource* node_resource =
sGraphGresource.m_blend_tree_resource.m_nodes[node_id];
if (node_id == 0 || node_id == 1) { if (node_id == 0 || node_id == 1) {
// continue; // continue;
@ -304,14 +312,14 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
if (sGraphLoadedThisFrame) { if (sGraphLoadedThisFrame) {
ax::NodeEditor::SetNodePosition( ax::NodeEditor::SetNodePosition(
node_id, node_id,
ImVec2(node_resource.m_position[0], node_resource.m_position[1])); ImVec2(node_resource->m_position[0], node_resource->m_position[1]));
} }
ax::NodeEditor::BeginNode(node_id); ax::NodeEditor::BeginNode(node_id);
ImGui::Text("%s", node_resource.m_node_type_name.c_str()); ImGui::Text("%s", node_resource->m_node_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];
ax::NodeEditor::BeginPin( ax::NodeEditor::BeginPin(
@ -323,7 +331,7 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
// Outputs // Outputs
std::vector<Socket>& node_outputs = 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++) {
Socket& socket = node_outputs[j]; Socket& socket = node_outputs[j];
ax::NodeEditor::BeginPin( ax::NodeEditor::BeginPin(
@ -337,26 +345,39 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
} }
int link_id = 0; int link_id = 0;
for (size_t connection_id = 0, n = sGraphGresource.m_connections.size(); connection_id < n; for (size_t connection_id = 0,
n = sGraphGresource.m_blend_tree_resource.m_connections.size();
connection_id < n;
connection_id++) { connection_id++) {
const AnimGraphConnectionResource& connection_resource = sGraphGresource.m_connections[connection_id]; const BlendTreeConnectionResource& connection_resource =
sGraphGresource.m_blend_tree_resource.m_connections[connection_id];
const AnimNodeResource& source_node_resource = sGraphGresource.m_nodes[connection_resource.source_node_index]; const AnimNodeResource* source_node_resource =
int source_socket_index = source_node_resource.m_socket_accessor->GetOutputIndex(connection_resource.source_socket_name.c_str()); sGraphGresource.m_blend_tree_resource
.m_nodes[connection_resource.source_node_index];
int source_socket_index =
source_node_resource->m_socket_accessor->GetOutputIndex(
connection_resource.source_socket_name.c_str());
const AnimNodeResource& target_node_resource = sGraphGresource.m_nodes[connection_resource.target_node_index]; const AnimNodeResource* target_node_resource =
int target_socket_index = target_node_resource.m_socket_accessor->GetInputIndex(connection_resource.target_socket_name.c_str()); sGraphGresource.m_blend_tree_resource
.m_nodes[connection_resource.target_node_index];
int target_socket_index =
target_node_resource->m_socket_accessor->GetInputIndex(
connection_resource.target_socket_name.c_str());
int source_socket_id = GetNodeOutputSocketId(static_cast<int>(connection_resource.source_node_index), source_socket_index); int source_socket_id = GetNodeOutputSocketId(
int target_socket_id = GetNodeInputSocketId(static_cast<int>(connection_resource.target_node_index), target_socket_index); static_cast<int>(connection_resource.source_node_index),
source_socket_index);
int target_socket_id = GetNodeInputSocketId(
static_cast<int>(connection_resource.target_node_index),
target_socket_index);
ax::NodeEditor::Link(link_id++, source_socket_id, target_socket_id); ax::NodeEditor::Link(link_id++, source_socket_id, target_socket_id);
} }
#endif #endif
#if 1 #if 1
// Create Connections // Create Connections
if (ax::NodeEditor::BeginCreate()) { if (ax::NodeEditor::BeginCreate()) {
@ -381,20 +402,23 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
void LegacyAnimGraphEditorUpdate() { void LegacyAnimGraphEditorUpdate() {
ImGui::BeginMenuBar(); ImGui::BeginMenuBar();
if (ImGui::Button("Save")) { if (ImGui::Button("Save")) {
sGraphGresource.saveToFile("editor_graph.json"); sGraphGresource.SaveToFile("editor_graph.json");
} }
if (ImGui::Button("Load")) { if (ImGui::Button("Load")) {
sGraphGresource.loadFromFile("editor_graph.json"); sGraphGresource.LoadFromFile("editor_graph.json");
for (size_t i = 0, n = sGraphGresource.m_nodes.size(); i < n; i++) { for (size_t i = 0, n = sGraphGresource.m_blend_tree_resource.m_nodes.size();
const AnimNodeResource& node_resource = sGraphGresource.m_nodes[i]; i < n;
i++) {
const AnimNodeResource* node_resource =
sGraphGresource.m_blend_tree_resource.m_nodes[i];
ImNodes::SetNodeGridSpacePos( ImNodes::SetNodeGridSpacePos(
i, i,
ImVec2(node_resource.m_position[0], node_resource.m_position[1])); ImVec2(node_resource->m_position[0], node_resource->m_position[1]));
} }
} }
if (ImGui::Button("Clear")) { if (ImGui::Button("Clear")) {
sGraphGresource.clear(); sGraphGresource.Clear();
} }
char graph_name_buffer[256]; char graph_name_buffer[256];
memset(graph_name_buffer, 0, sizeof(graph_name_buffer)); memset(graph_name_buffer, 0, sizeof(graph_name_buffer));
@ -459,11 +483,11 @@ void LegacyAnimGraphEditorUpdate() {
} }
if (node_type_name != "") { if (node_type_name != "") {
AnimNodeResource node_resource = AnimNodeResource* node_resource =
AnimNodeResourceFactory(node_type_name); AnimNodeResourceFactory(node_type_name);
size_t node_id = sGraphGresource.m_nodes.size(); size_t node_id = sGraphGresource.m_blend_tree_resource.m_nodes.size();
ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos()); ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos());
sGraphGresource.m_nodes.push_back(node_resource); sGraphGresource.m_blend_tree_resource.m_nodes.push_back(node_resource);
} }
ImGui::EndPopup(); ImGui::EndPopup();
@ -472,26 +496,32 @@ void LegacyAnimGraphEditorUpdate() {
ImGui::PopStyleVar(ImGuiStyleVar_WindowPadding); ImGui::PopStyleVar(ImGuiStyleVar_WindowPadding);
} }
for (size_t i = 0, n = sGraphGresource.m_nodes.size(); i < n; i++) { for (size_t i = 0, n = sGraphGresource.m_blend_tree_resource.m_nodes.size();
AnimNodeResource& node_resource = sGraphGresource.m_nodes[i]; i < n;
i++) {
AnimNodeResource* node_resource =
sGraphGresource.m_blend_tree_resource.m_nodes[i];
ImNodes::BeginNode(i); ImNodes::BeginNode(i);
ImGui::PushItemWidth(110.0f); ImGui::PushItemWidth(110.0f);
// Header // Header
ImNodes::BeginNodeTitleBar(); ImNodes::BeginNodeTitleBar();
if (&node_resource == &sGraphGresource.getGraphOutputNode()) { if (node_resource
== sGraphGresource.m_blend_tree_resource.GetGraphOutputNode()) {
ImGui::TextUnformatted("Graph Outputs"); ImGui::TextUnformatted("Graph Outputs");
} else if (&node_resource == &sGraphGresource.getGraphInputNode()) { } else if (
node_resource
== sGraphGresource.m_blend_tree_resource.GetGraphInputNode()) {
ImGui::TextUnformatted("Graph Inputs"); ImGui::TextUnformatted("Graph Inputs");
} else { } else {
ImGui::TextUnformatted(node_resource.m_node_type_name.c_str()); ImGui::TextUnformatted(node_resource->m_node_type_name.c_str());
} }
ImNodes::EndNodeTitleBar(); ImNodes::EndNodeTitleBar();
// 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];
@ -507,7 +537,9 @@ void LegacyAnimGraphEditorUpdate() {
ImGui::TextUnformatted(socket.m_name.c_str()); ImGui::TextUnformatted(socket.m_name.c_str());
bool socket_connected = bool socket_connected =
sGraphGresource.isSocketConnected(node_resource, socket.m_name); sGraphGresource.m_blend_tree_resource.IsSocketConnected(
node_resource,
socket.m_name);
if (!socket_connected && (socket.m_type == SocketType::SocketTypeFloat)) { if (!socket_connected && (socket.m_type == SocketType::SocketTypeFloat)) {
ImGui::SameLine(); ImGui::SameLine();
float socket_value = socket.m_value.float_value; float socket_value = socket.m_value.float_value;
@ -537,7 +569,7 @@ void LegacyAnimGraphEditorUpdate() {
// 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];
ImNodes::BeginOutputAttribute( ImNodes::BeginOutputAttribute(
@ -553,27 +585,27 @@ void LegacyAnimGraphEditorUpdate() {
// Graph output node // Graph output node
if (i == 0) { if (i == 0) {
if (ImGui::Button("+Output")) { if (ImGui::Button("+Output")) {
AnimNodeResource& graph_output_node = AnimNodeResource* graph_output_node =
sGraphGresource.getGraphOutputNode(); sGraphGresource.m_blend_tree_resource.GetGraphOutputNode();
static float bla = 0.f; static float bla = 0.f;
std::string socket_name = "Output"; std::string socket_name = "Output";
socket_name += std::to_string( socket_name += std::to_string(
graph_output_node.m_socket_accessor->m_inputs.size()); graph_output_node->m_socket_accessor->m_inputs.size());
graph_output_node.m_socket_accessor->RegisterInput<float>( graph_output_node->m_socket_accessor->RegisterInput<float>(
socket_name.c_str(), socket_name.c_str(),
nullptr); nullptr);
} }
} else if (i == 1) { } else if (i == 1) {
if (ImGui::Button("+Input")) { if (ImGui::Button("+Input")) {
AnimNodeResource& graph_input_node = AnimNodeResource* graph_input_node =
sGraphGresource.getGraphInputNode(); sGraphGresource.m_blend_tree_resource.GetGraphInputNode();
static float bla = 0.f; static float bla = 0.f;
std::string socket_name = "Input"; std::string socket_name = "Input";
socket_name += std::to_string( socket_name += std::to_string(
graph_input_node.m_socket_accessor->m_outputs.size()); graph_input_node->m_socket_accessor->m_outputs.size());
graph_input_node.m_socket_accessor->RegisterOutput<float>( graph_input_node->m_socket_accessor->RegisterOutput<float>(
socket_name.c_str(), socket_name.c_str(),
nullptr); nullptr);
} }
@ -581,29 +613,34 @@ void LegacyAnimGraphEditorUpdate() {
// Save state in node resource // Save state in node resource
ImVec2 node_pos = ImNodes::GetNodeGridSpacePos(i); ImVec2 node_pos = ImNodes::GetNodeGridSpacePos(i);
node_resource.m_position[0] = node_pos[0]; node_resource->m_position[0] = node_pos[0];
node_resource.m_position[1] = node_pos[1]; node_resource->m_position[1] = node_pos[1];
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImNodes::EndNode(); ImNodes::EndNode();
// Ensure flags such as SocketFlagAffectsTime are properly set. // Ensure flags such as SocketFlagAffectsTime are properly set.
node_resource.m_socket_accessor->UpdateFlags(); node_resource->m_socket_accessor->UpdateFlags();
} }
for (size_t i = 0, n = sGraphGresource.m_connections.size(); i < n; i++) { for (size_t i = 0,
const AnimGraphConnectionResource& connection = n = sGraphGresource.m_blend_tree_resource.m_connections.size();
sGraphGresource.m_connections[i]; i < n;
i++) {
const BlendTreeConnectionResource& connection =
sGraphGresource.m_blend_tree_resource.m_connections[i];
int start_attr, end_attr; int start_attr, end_attr;
const AnimNodeResource& source_node = const AnimNodeResource* source_node =
sGraphGresource.m_nodes[connection.source_node_index]; sGraphGresource.m_blend_tree_resource
int source_socket_index = source_node.m_socket_accessor->GetOutputIndex( .m_nodes[connection.source_node_index];
int source_socket_index = source_node->m_socket_accessor->GetOutputIndex(
connection.source_socket_name.c_str()); connection.source_socket_name.c_str());
const AnimNodeResource& target_node = const AnimNodeResource* target_node =
sGraphGresource.m_nodes[connection.target_node_index]; sGraphGresource.m_blend_tree_resource
int target_socket_index = target_node.m_socket_accessor->GetInputIndex( .m_nodes[connection.target_node_index];
int target_socket_index = target_node->m_socket_accessor->GetInputIndex(
connection.target_socket_name.c_str()); connection.target_socket_name.c_str());
start_attr = GenerateOutputAttributeId( start_attr = GenerateOutputAttributeId(
@ -632,20 +669,21 @@ void LegacyAnimGraphEditorUpdate() {
int node_end_input_index; int node_end_input_index;
SplitInputAttributeId(end_attr, &node_end_id, &node_end_input_index); SplitInputAttributeId(end_attr, &node_end_id, &node_end_input_index);
AnimGraphConnectionResource connection; BlendTreeConnectionResource connection;
connection.source_node_index = node_start_id; connection.source_node_index = node_start_id;
const AnimNodeResource& source_node = const AnimNodeResource* source_node =
sGraphGresource.m_nodes[node_start_id]; sGraphGresource.m_blend_tree_resource.m_nodes[node_start_id];
connection.source_socket_name = connection.source_socket_name =
source_node.m_socket_accessor->m_outputs[node_start_output_index] source_node->m_socket_accessor->m_outputs[node_start_output_index]
.m_name; .m_name;
connection.target_node_index = node_end_id; connection.target_node_index = node_end_id;
const AnimNodeResource& target_node = sGraphGresource.m_nodes[node_end_id]; const AnimNodeResource* target_node =
sGraphGresource.m_blend_tree_resource.m_nodes[node_end_id];
connection.target_socket_name = connection.target_socket_name =
target_node.m_socket_accessor->m_inputs[node_end_input_index].m_name; target_node->m_socket_accessor->m_inputs[node_end_input_index].m_name;
sGraphGresource.m_connections.push_back(connection); sGraphGresource.m_blend_tree_resource.m_connections.push_back(connection);
} }
if (ImGui::IsKeyPressed(ImGuiKey_Delete, false)) { if (ImGui::IsKeyPressed(ImGuiKey_Delete, false)) {
@ -655,8 +693,8 @@ void LegacyAnimGraphEditorUpdate() {
// Handle link detachements. // Handle link detachements.
int link_id = 0; int link_id = 0;
if (ImNodes::IsLinkDestroyed(&link_id)) { if (ImNodes::IsLinkDestroyed(&link_id)) {
sGraphGresource.m_connections.erase( sGraphGresource.m_blend_tree_resource.m_connections.erase(
sGraphGresource.m_connections.begin() + link_id); sGraphGresource.m_blend_tree_resource.m_connections.begin() + link_id);
} }
int selected_nodes[ImNodes::NumSelectedNodes()]; int selected_nodes[ImNodes::NumSelectedNodes()];
@ -668,16 +706,19 @@ void LegacyAnimGraphEditorUpdate() {
ImGui::NextColumn(); ImGui::NextColumn();
if (ImNodes::NumSelectedNodes() == 1) { if (ImNodes::NumSelectedNodes() == 1) {
if (selected_nodes[0] < sGraphGresource.m_nodes.size()) { if (selected_nodes[0]
AnimNodeResource& selected_node = < sGraphGresource.m_blend_tree_resource.m_nodes.size()) {
sGraphGresource.m_nodes[selected_nodes[0]]; AnimNodeResource* selected_node =
AnimGraphEditorRenderSidebar(sGraphGresource, selected_node); sGraphGresource.m_blend_tree_resource.m_nodes[selected_nodes[0]];
AnimGraphEditorRenderSidebar(
sGraphGresource.m_blend_tree_resource,
selected_node);
} }
} }
ImGui::Columns(1); ImGui::Columns(1);
} }
void AnimGraphEditorGetRuntimeGraph(AnimGraph& anim_graph) { void AnimGraphEditorGetRuntimeGraph(AnimGraphBlendTree& blend_tree) {
sGraphGresource.createInstance(anim_graph); sGraphGresource.CreateBlendTreeInstance(blend_tree);
} }

View File

@ -10,6 +10,8 @@ struct EditorContext;
} // namespace ax::NodeEditor } // namespace ax::NodeEditor
struct SkinnedMesh; struct SkinnedMesh;
struct AnimGraphBlendTree;
struct SyncTrack;
inline int GenerateInputAttributeId(int node_id, int input_index) { inline int GenerateInputAttributeId(int node_id, int input_index) {
return ((input_index + 1) << 14) + node_id; return ((input_index + 1) << 14) + node_id;
@ -39,6 +41,6 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context);
void LegacyAnimGraphEditorUpdate(); void LegacyAnimGraphEditorUpdate();
void AnimGraphEditorGetRuntimeGraph(AnimGraph& anim_graph); void AnimGraphEditorGetRuntimeGraph(AnimGraphBlendTree& anim_graph);
#endif //ANIMTESTBED_ANIMGRAPHEDITOR_H #endif //ANIMTESTBED_ANIMGRAPHEDITOR_H

View File

@ -115,8 +115,8 @@ struct AnimSamplerNode : public AnimNode {
ozz::animation::SamplingJob::Context m_sampling_context; ozz::animation::SamplingJob::Context m_sampling_context;
ozz::animation::Animation* m_animation = nullptr; ozz::animation::Animation* m_animation = nullptr;
virtual ~AnimSamplerNode(); ~AnimSamplerNode() noexcept override;
virtual bool Init(AnimGraphContext& context) override; bool Init(AnimGraphContext& context) override;
void UpdateTime(float time_last, float time_now) override { void UpdateTime(float time_last, float time_now) override {
m_time_last = time_last; m_time_last = time_last;
m_time_now = time_now; m_time_now = time_now;

View File

@ -107,6 +107,13 @@ struct BlendTreeResource {
return result; return result;
} }
bool IsSocketConnected(
const AnimNodeResource* source_node,
const std::string& socket_name) {
assert(false && "Not yet implemented");
return false;
}
size_t GetNodeIndexForOutputSocket(const std::string& socket_name) const { size_t GetNodeIndexForOutputSocket(const std::string& socket_name) const {
for (size_t i = 0; i < m_connections.size(); i++) { for (size_t i = 0; i < m_connections.size(); i++) {
const BlendTreeConnectionResource& connection = m_connections[i]; const BlendTreeConnectionResource& connection = m_connections[i];
@ -156,6 +163,7 @@ struct AnimGraphResource : AnimNodeResource {
BlendTreeResource m_blend_tree_resource; BlendTreeResource m_blend_tree_resource;
StateMachineResource m_state_machine_resource; StateMachineResource m_state_machine_resource;
void Clear() { m_blend_tree_resource.Reset(); }
bool SaveToFile(const char* filename) const; bool SaveToFile(const char* filename) const;
bool LoadFromFile(const char* filename); bool LoadFromFile(const char* filename);