From 07d02a2e423bdb20d2fb6c6429b84a35757c39fc Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 16 Mar 2025 22:58:14 +0100 Subject: [PATCH] AnimGraphEvalTests now compiles again. --- CMakeLists.txt | 2 +- tests/AnimGraphEvalTests.cc | 110 ++++++++++++++++++++++-------------- 2 files changed, 69 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c34a946..a43735a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,7 +147,7 @@ set(ozz_offline_test_objs target_sources(runtests PRIVATE tests/AnimGraphResourceTests.cc tests/AnimGraphEditorTests.cc - # tests/AnimGraphEvalTests.cc + tests/AnimGraphEvalTests.cc tests/NodeDescriptorTests.cc tests/SyncTrackTests.cc tests/main.cc diff --git a/tests/AnimGraphEvalTests.cc b/tests/AnimGraphEvalTests.cc index 2dc60d3..c33ae1d 100644 --- a/tests/AnimGraphEvalTests.cc +++ b/tests/AnimGraphEvalTests.cc @@ -2,18 +2,21 @@ // Created by martin on 04.02.22. // -#include "AnimGraph/AnimGraph.h" -#include "AnimGraph/AnimGraphBlendTreeResource.h" -#include "AnimGraph/AnimGraphEditor.h" +#include "AnimGraph/AnimGraphBlendTree.h" +#include "AnimGraph/AnimGraphResource.h" +#include "AnimGraphEditor/AnimGraphEditor.h" #include "catch.hpp" #include "ozz/animation/offline/animation_builder.h" #include "ozz/animation/offline/raw_animation.h" #include "ozz/animation/offline/raw_skeleton.h" #include "ozz/animation/offline/skeleton_builder.h" #include "ozz/animation/runtime/animation.h" +#include "ozz/animation/runtime/sampling_job.h" +#include "ozz/animation/runtime/skeleton.h" #include "ozz/base/io/archive.h" #include "ozz/base/io/stream.h" #include "ozz/base/log.h" +#include "ozz/base/maths/soa_transform.h" struct SimpleAnimFixture { ozz::unique_ptr skeleton = nullptr; @@ -134,54 +137,64 @@ TEST_CASE("AnimDataPlacementNew", "[AnimGraphEval]") { anim_data_ptr->m_local_matrices.vector::~vector(); delete[] buf; - } TEST_CASE_METHOD( SimpleAnimFixture, "AnimGraphSimpleEval", "[AnimGraphEvalTests]") { - AnimGraphBlendTreeResource graph_resource; + BlendTreeResource* blend_tree_resource = + dynamic_cast(AnimNodeResourceFactory("BlendTree")); // Add nodes size_t trans_x_node_index = - graph_resource.addNode(AnimNodeResourceFactory("AnimSampler")); + blend_tree_resource->AddNode(AnimNodeResourceFactory("AnimSampler")); size_t trans_y_node_index = - graph_resource.addNode(AnimNodeResourceFactory("AnimSampler")); + blend_tree_resource->AddNode(AnimNodeResourceFactory("AnimSampler")); size_t blend_node_index = - graph_resource.addNode(AnimNodeResourceFactory("Blend2")); + blend_tree_resource->AddNode(AnimNodeResourceFactory("Blend2")); // Setup nodes - AnimNodeResource& trans_x_node = graph_resource.m_nodes[trans_x_node_index]; - trans_x_node.m_socket_accessor->SetPropertyValue("Filename", std::string("trans_x")); - trans_x_node.m_name = "trans_x"; + AnimNodeResource* trans_x_node = + blend_tree_resource->GetNode(trans_x_node_index); + trans_x_node->m_virtual_socket_accessor->SetPropertyValue( + "Filename", + std::string("trans_x")); + trans_x_node->m_name = "trans_x"; - AnimNodeResource& trans_y_node = graph_resource.m_nodes[trans_y_node_index]; - trans_y_node.m_socket_accessor->SetPropertyValue("Filename", std::string("trans_y")); - trans_y_node.m_name = "trans_y"; + AnimNodeResource* trans_y_node = + blend_tree_resource->GetNode(trans_y_node_index); + trans_y_node->m_virtual_socket_accessor->SetPropertyValue( + "Filename", + std::string("trans_y")); + trans_y_node->m_name = "trans_y"; - AnimNodeResource& blend_node = graph_resource.m_nodes[blend_node_index]; - blend_node.m_name = "BlendWalkRun"; + AnimNodeResource* blend_node = blend_tree_resource->GetNode(blend_node_index); + blend_node->m_name = "BlendWalkRun"; // Setup graph outputs and inputs - AnimNodeResource& graph_output_node = graph_resource.getGraphOutputNode(); - graph_output_node.m_socket_accessor->RegisterInput("GraphOutput", nullptr); + AnimNodeResource* graph_output_node = + blend_tree_resource->GetGraphOutputNode(); - AnimNodeResource& graph_input_node = - graph_resource.getGraphInputNode(); - graph_input_node.m_socket_accessor->RegisterOutput( - "GraphFloatInput", - nullptr); + blend_tree_resource->RegisterBlendTreeInputSocket("GraphFloatInput"); // Wire up nodes - graph_resource.connectSockets(trans_x_node, "Output", blend_node, "Input0"); - graph_resource.connectSockets(trans_y_node, "Output", blend_node, "Input1"); - graph_resource.connectSockets( + CHECK(blend_tree_resource + ->ConnectSockets(trans_x_node, "Output", blend_node, "Input0")); + CHECK(blend_tree_resource + ->ConnectSockets(trans_y_node, "Output", blend_node, "Input1")); + + CHECK(blend_tree_resource->ConnectSockets( blend_node, "Output", - graph_resource.getGraphOutputNode(), - "GraphOutput"); - REQUIRE(graph_resource.connectSockets(graph_input_node, "GraphFloatInput", blend_node, "Weight")); + blend_tree_resource->GetGraphOutputNode(), + "Output")); + + CHECK(blend_tree_resource->ConnectSockets( + blend_tree_resource->GetGraphInputNode(), + "GraphFloatInput", + blend_node, + "Weight")); // Prepare animation maps AnimGraphContext graph_context; @@ -190,29 +203,42 @@ TEST_CASE_METHOD( graph_context.m_animation_map["trans_y"] = animation_translate_y.get(); // Instantiate graph - AnimGraph graph; - graph_resource.createInstance(graph); - graph.init(graph_context); + AnimGraphBlendTree blend_tree; + blend_tree_resource->CreateBlendTreeInstance(blend_tree); + + blend_tree.Init(graph_context); // Get runtime graph inputs and outputs float graph_float_input = 0.f; - graph.SetInput("GraphFloatInput", &graph_float_input); + blend_tree.SetInput("GraphFloatInput", &graph_float_input); AnimData graph_anim_output; graph_anim_output.m_local_matrices.resize(skeleton->num_joints()); - graph.SetOutput("GraphOutput", &graph_anim_output); + blend_tree.SetOutput("GraphOutput", &graph_anim_output); // Evaluate graph graph_float_input = 0.1f; - graph.markActiveNodes(); - CHECK(graph.m_nodes[trans_x_node_index]->m_state == AnimNodeEvalState::Activated); - CHECK(graph.m_nodes[trans_y_node_index]->m_state == AnimNodeEvalState::Activated); - CHECK(graph.m_nodes[blend_node_index]->m_state == AnimNodeEvalState::Activated); + blend_tree.StartUpdateTick(); + blend_tree.MarkActiveInputs(blend_tree.GetGraphOutputConnections()); - graph.updateTime(0.5f); - graph.evaluate(graph_context); + CHECK( + blend_tree.m_nodes[trans_x_node_index]->m_state + == AnimNodeEvalState::Activated); + CHECK( + blend_tree.m_nodes[trans_y_node_index]->m_state + == AnimNodeEvalState::Activated); + CHECK( + blend_tree.m_nodes[blend_node_index]->m_state + == AnimNodeEvalState::Activated); - CHECK(graph_anim_output.m_local_matrices[0].translation.x[0] == Approx(0.5).margin(0.1)); - CHECK(graph_anim_output.m_local_matrices[0].translation.y[0] == Approx(0.05).margin(0.01)); + blend_tree.UpdateTime(0.0, 0.5f); + blend_tree.Evaluate(graph_context); + + CHECK( + graph_anim_output.m_local_matrices[0].translation.x[0] + == Approx(0.5).margin(0.1)); + CHECK( + graph_anim_output.m_local_matrices[0].translation.y[0] + == Approx(0.05).margin(0.01)); } \ No newline at end of file