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));
}