Working on graph evaluations. WIP.

This commit is contained in:
Martin Felis
2022-04-13 15:48:39 +02:00
parent b518220576
commit 2da07ef961
7 changed files with 233 additions and 68 deletions
+83 -1
View File
@@ -63,7 +63,7 @@ struct SimpleAnimFixture {
bone0_translations.push_back(translation_key);
translation_key.time = 1.f;
translation_key.value = ozz::math::Float3(1.f, 6.f, 9.f);
translation_key.value = ozz::math::Float3(1.f, 0.f, 9.f);
bone0_translations.push_back(translation_key);
bone0_track.translations = bone0_translations;
@@ -119,3 +119,85 @@ TEST_CASE_METHOD(
CHECK(
sampled_translation.z[0] == Approx(translation_key.value.z).margin(0.01));
}
TEST_CASE_METHOD(
SimpleAnimFixture,
"AnimGraphSimpleEval",
"[AnimGraphEvalTests]") {
AnimGraphResource graph_resource;
// Add nodes
size_t trans_x_node_index =
graph_resource.addNode(AnimNodeResourceFactory("AnimSampler"));
size_t trans_y_node_index =
graph_resource.addNode(AnimNodeResourceFactory("AnimSampler"));
size_t blend_node_index =
graph_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", "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", "trans_y");
trans_y_node.m_name = "trans_y";
AnimNodeResource& blend_node = graph_resource.m_nodes[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<AnimData>("GraphOutput", nullptr);
AnimNodeResource& graph_input_node =
graph_resource.getGraphInputNode();
graph_input_node.m_socket_accessor->RegisterOutput<float>(
"GraphFloatInput",
nullptr);
// 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(
blend_node,
"Output",
graph_resource.getGraphOutputNode(),
"GraphOutput");
REQUIRE(graph_resource.connectSockets(graph_input_node, "GraphFloatInput", blend_node, "Weight"));
// Prepare animation maps
AnimGraphContext graph_context;
graph_context.m_skeleton = skeleton.get();
graph_context.m_animation_map["trans_x"] = animation_translate_x.get();
graph_context.m_animation_map["trans_y"] = animation_translate_y.get();
// Instantiate graph
AnimGraph graph = graph_resource.createInstance();
graph_context.m_graph = &graph;
graph.init(graph_context);
// Get runtime graph inputs and outputs
float* graph_float_input = nullptr;
graph_float_input =
static_cast<float*>(graph.getInputPtr("GraphFloatInput"));
Socket* anim_output_socket =
graph.getOutputSocket("GraphOutput");
AnimData* graph_anim_output = static_cast<AnimData*>(graph.getOutputPtr("GraphOutput"));
// 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);
graph.updateTime(0.5f);
graph.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));
}
+29 -12
View File
@@ -129,23 +129,31 @@ TEST_CASE("BasicGraph", "[AnimGraphResource]") {
REQUIRE(anim_sampler_run->m_animation != nullptr);
WHEN("Emulating Graph Evaluation") {
CHECK(graph.m_anim_data_work_buffer.m_available_data.size() == 5);
graph.prepareNodeEval(walk_node_index);
CHECK(graph.m_anim_data_work_buffer.size() == 0);
graph.prepareNodeEval(graph_context, walk_node_index);
graph.finishNodeEval(walk_node_index);
CHECK(graph.m_anim_data_work_buffer.m_available_data.size() == 4);
graph.prepareNodeEval(run_node_index);
CHECK(graph.m_anim_data_work_buffer.m_num_allocations == 1);
CHECK(graph.m_anim_data_work_buffer.size() == 0);
graph.prepareNodeEval(graph_context, run_node_index);
graph.finishNodeEval(run_node_index);
CHECK(graph.m_anim_data_work_buffer.m_available_data.size() == 3);
graph.prepareNodeEval(blend_node_index);
CHECK(graph.m_anim_data_work_buffer.m_num_allocations == 2);
CHECK(graph.m_anim_data_work_buffer.size() == 0);
graph.prepareNodeEval(graph_context, blend_node_index);
CHECK(blend2_instance->i_input0 == anim_sampler_walk->o_output);
CHECK(blend2_instance->i_input1 == anim_sampler_run->o_output);
CHECK(graph.m_anim_data_work_buffer.m_available_data.size() == 2);
CHECK(graph.m_anim_data_work_buffer.m_num_allocations == 3);
CHECK(graph.m_anim_data_work_buffer.size() == 0);
graph.finishNodeEval(blend_node_index);
CHECK(anim_sampler_walk->o_output == nullptr);
CHECK(anim_sampler_run->o_output == nullptr);
CHECK(graph.m_anim_data_work_buffer.m_available_data.size() == 4);
CHECK(graph.m_anim_data_work_buffer.m_num_allocations == 3);
CHECK(graph.m_anim_data_work_buffer.size() == 2);
graph.prepareNodeEval(0);
// TODO: rethink output node evaluation
graph.prepareNodeEval(graph_context, 0);
const Socket* graph_output_socket = graph.getOutputSocket("GraphOutput");
CHECK(blend2_instance->o_output == (*graph_output_socket->m_reference.ptr_ptr));
AnimData* graph_output =
@@ -153,8 +161,11 @@ TEST_CASE("BasicGraph", "[AnimGraphResource]") {
graph.finishNodeEval(0);
CHECK(blend2_instance->o_output == nullptr);
CHECK(graph_output == (*graph_output_socket->m_reference.ptr_ptr));
CHECK(graph.m_anim_data_work_buffer.m_available_data.size() == 5);
CHECK(graph.m_anim_data_work_buffer.m_num_allocations == 3);
CHECK(graph.m_anim_data_work_buffer.size() == 3);
}
graph_context.freeAnimations();
}
TEST_CASE("InputAttributeConversion", "[AnimGraphResource]") {
@@ -282,7 +293,8 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
*graph_float_input = 123.456f;
AND_WHEN("Evaluating Graph") {
AnimGraphContext context = {&anim_graph, nullptr};
AnimGraphContext context;
context.m_graph = &anim_graph;
anim_graph.updateTime(0.f);
anim_graph.evaluate(context);
@@ -299,6 +311,8 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
CHECK(vec3_output[1] == *graph_float_input);
CHECK(vec3_output[2] == *graph_float_input);
}
context.freeAnimations();
}
}
}
@@ -414,7 +428,8 @@ TEST_CASE("SimpleMathEvaluations", "[AnimGraphResource]") {
*graph_float_input = 123.456f;
AND_WHEN("Evaluating Graph") {
AnimGraphContext context = {&anim_graph, nullptr};
AnimGraphContext context;
context.m_graph = &anim_graph;
anim_graph.updateTime(0.f);
anim_graph.evaluate(context);
@@ -442,6 +457,8 @@ TEST_CASE("SimpleMathEvaluations", "[AnimGraphResource]") {
CHECK(float1_output == Approx(*graph_float_input * 2.));
CHECK(float2_output == Approx(*graph_float_input * 3.));
}
context.freeAnimations();
}
}
}