AnimGraphEvalTests now properly evaluates.

This commit is contained in:
Martin Felis
2025-03-17 22:23:12 +01:00
parent 1870a9d214
commit b4eda31242
4 changed files with 120 additions and 31 deletions
+89 -25
View File
@@ -4,7 +4,6 @@
#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"
@@ -14,7 +13,6 @@
#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"
@@ -66,7 +64,7 @@ struct SimpleAnimFixture {
bone0_translations.push_back(translation_key);
translation_key.time = 1.f;
translation_key.value = ozz::math::Float3(1.f, 0.f, 9.f);
translation_key.value = ozz::math::Float3(1.f, 0.f, 0.f);
bone0_translations.push_back(translation_key);
bone0_track.translations = bone0_translations;
@@ -214,31 +212,97 @@ TEST_CASE_METHOD(
AnimData graph_anim_output;
graph_anim_output.m_local_matrices.resize(skeleton->num_joints());
blend_tree.SetOutput("GraphOutput", &graph_anim_output);
blend_tree.SetOutput("Output", &graph_anim_output);
// Evaluate graph
graph_float_input = 0.1f;
WHEN("Blend Weight == 0.") {
// Evaluate graph
graph_float_input = 0.f;
blend_tree.StartUpdateTick();
blend_tree.MarkActiveInputs(blend_tree.GetGraphOutputConnections());
blend_tree.StartUpdateTick();
blend_tree.MarkActiveInputs({});
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);
THEN("Only Blend2 and first input of Blend2 node is active.") {
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::Deactivated);
CHECK(
blend_tree.m_nodes[blend_node_index]->m_state
== AnimNodeEvalState::Activated);
}
blend_tree.UpdateTime(0.0, 0.5f);
blend_tree.Evaluate(graph_context);
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));
CHECK(
graph_anim_output.m_local_matrices[0].translation.x[0]
== Approx(0.5).margin(0.01));
CHECK(
graph_anim_output.m_local_matrices[0].translation.y[0]
== Approx(0.0).margin(0.01));
}
WHEN("Blend Weight 0.1") {
// Evaluate graph
graph_float_input = 0.1f;
blend_tree.StartUpdateTick();
blend_tree.MarkActiveInputs({});
THEN("All nodes are active.") {
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);
}
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.45).margin(0.01));
CHECK(
graph_anim_output.m_local_matrices[0].translation.y[0]
== Approx(0.05).margin(0.01));
}
WHEN("Blend Weight 1.") {
// Evaluate graph
graph_float_input = 1.f;
blend_tree.StartUpdateTick();
blend_tree.MarkActiveInputs({});
THEN("Only Blend2 and second input of Blend2 are active.") {
CHECK(
blend_tree.m_nodes[trans_x_node_index]->m_state
== AnimNodeEvalState::Deactivated);
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);
}
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.).margin(0.01));
CHECK(
graph_anim_output.m_local_matrices[0].translation.y[0]
== Approx(0.5).margin(0.01));
}
delete blend_tree_resource;
}