Compare commits

..

No commits in common. "9f9ac60f9c4c347fa6d885cb1f7c13e5d6344b40" and "8694a114165d8c2c7aff814c0748ad9070b5b2fd" have entirely different histories.

5 changed files with 96 additions and 147 deletions

View File

@ -13,7 +13,8 @@
#include "imnodes.h" #include "imnodes.h"
#include "misc/cpp/imgui_stdlib.h" #include "misc/cpp/imgui_stdlib.h"
static AnimGraphResource sGraphGresource = AnimGraphResource(); static AnimGraphResource sGraphGresource =
AnimGraphResource();
static bool sGraphLoadedThisFrame = false; static bool sGraphLoadedThisFrame = false;
ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) { ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) {
@ -57,14 +58,14 @@ void NodeSocketEditor(Socket& socket) {
} }
} }
void RemoveBlendTreeConnectionsForSocket( void RemoveConnectionsForSocket(
BlendTreeResource& blend_tree_resource, AnimGraphResource& graph_resource,
AnimNodeResource* node_resource, AnimNodeResource& node_resource,
Socket& socket) { Socket& socket) {
std::vector<BlendTreeConnectionResource>::iterator iter = std::vector<BlendTreeConnectionResource>::iterator iter =
blend_tree_resource.m_connections.begin(); graph_resource.m_blend_tree_resource.m_connections.begin();
while (iter != blend_tree_resource.m_connections.end()) { while (iter != graph_resource.m_blend_tree_resource.m_connections.end()) {
// TODO adjust for refactor // TODO adjust for refactor
assert(false); assert(false);
@ -159,24 +160,24 @@ void SkinnedMeshWidget(SkinnedMesh* skinned_mesh) {
} }
void AnimGraphEditorRenderSidebar( void AnimGraphEditorRenderSidebar(
BlendTreeResource& blend_tree_resource, AnimGraphBlendTreeResource& graph_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(),
@ -211,11 +212,11 @@ void AnimGraphEditorRenderSidebar(
} }
} }
if (node_resource == blend_tree_resource.GetGraphOutputNode()) { if (&node_resource == &graph_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()) {
@ -223,10 +224,7 @@ void AnimGraphEditorRenderSidebar(
ImGui::PushID(&output); ImGui::PushID(&output);
NodeSocketEditor(output); NodeSocketEditor(output);
if (ImGui::Button("X")) { if (ImGui::Button("X")) {
RemoveBlendTreeConnectionsForSocket( RemoveConnectionsForSocket(graph_resource, node_resource, output);
blend_tree_resource,
node_resource,
output);
iter = outputs.erase(iter); iter = outputs.erase(iter);
} else { } else {
iter++; iter++;
@ -235,11 +233,11 @@ void AnimGraphEditorRenderSidebar(
} }
} }
if (node_resource == blend_tree_resource.GetGraphInputNode()) { if (&node_resource == &graph_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()) {
@ -247,10 +245,7 @@ void AnimGraphEditorRenderSidebar(
ImGui::PushID(&input); ImGui::PushID(&input);
NodeSocketEditor(input); NodeSocketEditor(input);
if (ImGui::Button("X")) { if (ImGui::Button("X")) {
RemoveBlendTreeConnectionsForSocket( RemoveConnectionsForSocket(graph_resource, node_resource, input);
blend_tree_resource,
node_resource,
input);
iter = inputs.erase(iter); iter = inputs.erase(iter);
} else { } else {
iter++; iter++;
@ -263,10 +258,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++) {
@ -277,7 +272,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));
@ -298,12 +293,9 @@ 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, for (size_t node_id = 0, n = sGraphGresource.m_nodes.size(); node_id < n;
n = sGraphGresource.m_blend_tree_resource.m_nodes.size();
node_id < n;
node_id++) { node_id++) {
AnimNodeResource* node_resource = AnimNodeResource& node_resource = sGraphGresource.m_nodes[node_id];
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;
@ -312,14 +304,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(
@ -331,7 +323,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(
@ -345,39 +337,26 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
} }
int link_id = 0; int link_id = 0;
for (size_t connection_id = 0, for (size_t connection_id = 0, n = sGraphGresource.m_connections.size(); connection_id < n;
n = sGraphGresource.m_blend_tree_resource.m_connections.size();
connection_id < n;
connection_id++) { connection_id++) {
const BlendTreeConnectionResource& connection_resource = const AnimGraphConnectionResource& connection_resource = sGraphGresource.m_connections[connection_id];
sGraphGresource.m_blend_tree_resource.m_connections[connection_id];
const AnimNodeResource* source_node_resource = const AnimNodeResource& source_node_resource = sGraphGresource.m_nodes[connection_resource.source_node_index];
sGraphGresource.m_blend_tree_resource int source_socket_index = source_node_resource.m_socket_accessor->GetOutputIndex(connection_resource.source_socket_name.c_str());
.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 = const AnimNodeResource& target_node_resource = sGraphGresource.m_nodes[connection_resource.target_node_index];
sGraphGresource.m_blend_tree_resource int target_socket_index = target_node_resource.m_socket_accessor->GetInputIndex(connection_resource.target_socket_name.c_str());
.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( int source_socket_id = GetNodeOutputSocketId(static_cast<int>(connection_resource.source_node_index), source_socket_index);
static_cast<int>(connection_resource.source_node_index), int target_socket_id = GetNodeInputSocketId(static_cast<int>(connection_resource.target_node_index), target_socket_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()) {
@ -402,23 +381,20 @@ 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_blend_tree_resource.m_nodes.size(); for (size_t i = 0, n = sGraphGresource.m_nodes.size(); i < n; i++) {
i < n; const AnimNodeResource& node_resource = sGraphGresource.m_nodes[i];
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));
@ -483,11 +459,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_blend_tree_resource.m_nodes.size(); size_t node_id = sGraphGresource.m_nodes.size();
ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos()); ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos());
sGraphGresource.m_blend_tree_resource.m_nodes.push_back(node_resource); sGraphGresource.m_nodes.push_back(node_resource);
} }
ImGui::EndPopup(); ImGui::EndPopup();
@ -496,32 +472,26 @@ void LegacyAnimGraphEditorUpdate() {
ImGui::PopStyleVar(ImGuiStyleVar_WindowPadding); ImGui::PopStyleVar(ImGuiStyleVar_WindowPadding);
} }
for (size_t i = 0, n = sGraphGresource.m_blend_tree_resource.m_nodes.size(); for (size_t i = 0, n = sGraphGresource.m_nodes.size(); i < n; i++) {
i < n; AnimNodeResource& node_resource = sGraphGresource.m_nodes[i];
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 if (&node_resource == &sGraphGresource.getGraphOutputNode()) {
== sGraphGresource.m_blend_tree_resource.GetGraphOutputNode()) {
ImGui::TextUnformatted("Graph Outputs"); ImGui::TextUnformatted("Graph Outputs");
} else if ( } else if (&node_resource == &sGraphGresource.getGraphInputNode()) {
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];
@ -537,9 +507,7 @@ void LegacyAnimGraphEditorUpdate() {
ImGui::TextUnformatted(socket.m_name.c_str()); ImGui::TextUnformatted(socket.m_name.c_str());
bool socket_connected = bool socket_connected =
sGraphGresource.m_blend_tree_resource.IsSocketConnected( sGraphGresource.isSocketConnected(node_resource, socket.m_name);
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;
@ -569,7 +537,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(
@ -585,27 +553,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.m_blend_tree_resource.GetGraphOutputNode(); sGraphGresource.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.m_blend_tree_resource.GetGraphInputNode(); sGraphGresource.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);
} }
@ -613,34 +581,29 @@ 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, for (size_t i = 0, n = sGraphGresource.m_connections.size(); i < n; i++) {
n = sGraphGresource.m_blend_tree_resource.m_connections.size(); const AnimGraphConnectionResource& connection =
i < n; sGraphGresource.m_connections[i];
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_blend_tree_resource sGraphGresource.m_nodes[connection.source_node_index];
.m_nodes[connection.source_node_index]; int source_socket_index = source_node.m_socket_accessor->GetOutputIndex(
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_blend_tree_resource sGraphGresource.m_nodes[connection.target_node_index];
.m_nodes[connection.target_node_index]; int target_socket_index = target_node.m_socket_accessor->GetInputIndex(
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(
@ -669,21 +632,20 @@ 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);
BlendTreeConnectionResource connection; AnimGraphConnectionResource 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_blend_tree_resource.m_nodes[node_start_id]; sGraphGresource.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 = const AnimNodeResource& target_node = sGraphGresource.m_nodes[node_end_id];
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_blend_tree_resource.m_connections.push_back(connection); sGraphGresource.m_connections.push_back(connection);
} }
if (ImGui::IsKeyPressed(ImGuiKey_Delete, false)) { if (ImGui::IsKeyPressed(ImGuiKey_Delete, false)) {
@ -693,8 +655,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_blend_tree_resource.m_connections.erase( sGraphGresource.m_connections.erase(
sGraphGresource.m_blend_tree_resource.m_connections.begin() + link_id); sGraphGresource.m_connections.begin() + link_id);
} }
int selected_nodes[ImNodes::NumSelectedNodes()]; int selected_nodes[ImNodes::NumSelectedNodes()];
@ -706,19 +668,16 @@ void LegacyAnimGraphEditorUpdate() {
ImGui::NextColumn(); ImGui::NextColumn();
if (ImNodes::NumSelectedNodes() == 1) { if (ImNodes::NumSelectedNodes() == 1) {
if (selected_nodes[0] if (selected_nodes[0] < sGraphGresource.m_nodes.size()) {
< sGraphGresource.m_blend_tree_resource.m_nodes.size()) { AnimNodeResource& selected_node =
AnimNodeResource* selected_node = sGraphGresource.m_nodes[selected_nodes[0]];
sGraphGresource.m_blend_tree_resource.m_nodes[selected_nodes[0]]; AnimGraphEditorRenderSidebar(sGraphGresource, selected_node);
AnimGraphEditorRenderSidebar(
sGraphGresource.m_blend_tree_resource,
selected_node);
} }
} }
ImGui::Columns(1); ImGui::Columns(1);
} }
void AnimGraphEditorGetRuntimeGraph(AnimGraphBlendTree& blend_tree) { void AnimGraphEditorGetRuntimeGraph(AnimGraph& anim_graph) {
sGraphGresource.CreateBlendTreeInstance(blend_tree); sGraphGresource.createInstance(anim_graph);
} }

View File

@ -10,8 +10,6 @@ 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;
@ -41,6 +39,6 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context);
void LegacyAnimGraphEditorUpdate(); void LegacyAnimGraphEditorUpdate();
void AnimGraphEditorGetRuntimeGraph(AnimGraphBlendTree& anim_graph); void AnimGraphEditorGetRuntimeGraph(AnimGraph& 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;
~AnimSamplerNode() noexcept override; virtual ~AnimSamplerNode();
bool Init(AnimGraphContext& context) override; virtual 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,13 +107,6 @@ 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];
@ -163,7 +156,6 @@ 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);

View File

@ -343,7 +343,7 @@ class EmbeddedTreeBlend2GraphResource {
embedded_run_node_index = embedded_blend_tree_resource->m_nodes.size() - 1; embedded_run_node_index = embedded_blend_tree_resource->m_nodes.size() - 1;
// Configure node resources // Configure node resources
embedded_blend2_node_resource = AnimNodeResource* embedded_blend2_node_resource =
embedded_blend_tree_resource->m_nodes[embedded_blend2_node_index]; embedded_blend_tree_resource->m_nodes[embedded_blend2_node_index];
embedded_blend2_node_resource->m_socket_accessor->SetInputValue( embedded_blend2_node_resource->m_socket_accessor->SetInputValue(
"Weight", "Weight",