Initial graph editor and graph instantiation from file.

This commit is contained in:
Martin Felis
2022-02-11 16:51:18 +01:00
parent fd4785afcd
commit c5b0d1f976
48 changed files with 87227 additions and 41 deletions
+99
View File
@@ -0,0 +1,99 @@
//
// Created by martin on 04.02.22.
//
#include "AnimGraphResource.h"
#include "catch.hpp"
TEST_CASE("BasicGraph", "[AnimGraphResource]") {
AnimGraphResource graph_resource;
graph_resource.m_name = "WalkRunBlendGraph";
AnimNodeResource walk_node;
walk_node.m_name = "WalkAnim";
walk_node.m_type_name = "AnimSampler";
graph_resource.m_nodes.push_back(walk_node);
AnimNodeResource run_node;
run_node.m_name = "RunAnim";
run_node.m_type_name = "AnimSampler";
graph_resource.m_nodes.push_back(run_node);
AnimNodeResource blend_node;
blend_node.m_name = "BlendWalkRun";
blend_node.m_type_name = "Blend2";
graph_resource.m_nodes.push_back(blend_node);
AnimGraphConnection walk_to_blend;
walk_to_blend.m_source_node = &walk_node;
walk_to_blend.m_source_socket_name = "Output";
walk_to_blend.m_target_node = &blend_node;
walk_to_blend.m_target_socket_name = "Input0";
graph_resource.m_connections.push_back(walk_to_blend);
AnimGraphConnection run_to_blend;
run_to_blend.m_source_node = &run_node;
run_to_blend.m_source_socket_name = "Output";
run_to_blend.m_target_node = &blend_node;
run_to_blend.m_target_socket_name = "Input1";
graph_resource.m_connections.push_back(run_to_blend);
AnimGraphConnection blend_to_output;
blend_to_output.m_source_node = &blend_node;
blend_to_output.m_source_socket_name = "Output";
blend_to_output.m_target_socket_name = "GraphOutput";
graph_resource.m_connections.push_back(blend_to_output);
graph_resource.saveToFile("WalkGraph.animgraph.json");
AnimGraph graph = AnimGraph::createFromResource(graph_resource);
for (size_t i = 0; i < graph.m_nodes.size(); i++) {
const AnimNode* node = graph.m_nodes[i];
std::cout << node->m_name << " [" << node->m_node_type_name << "]"
<< std::endl;
}
CHECK(graph.m_nodes.size() == 3);
CHECK(graph.m_nodes[0]->m_node_type_name == "AnimSampler");
CHECK(graph.m_nodes[1]->m_node_type_name == "AnimSampler");
CHECK(graph.m_nodes[2]->m_node_type_name == "Blend2");
AnimSamplerNode* anim_sampler_instance0 =
dynamic_cast<AnimSamplerNode*>(graph.m_nodes[0]);
AnimSamplerNode* anim_sampler_instance1 =
dynamic_cast<AnimSamplerNode*>(graph.m_nodes[1]);
Blend2Node* blend2_instance = dynamic_cast<Blend2Node*>(graph.m_nodes[2]);
CHECK(anim_sampler_instance0->m_output == &blend2_instance->m_input0);
CHECK(anim_sampler_instance1->m_output == &blend2_instance->m_input1);
size_t anim_sampler_index0 = graph.getAnimNodeIndex(anim_sampler_instance0);
size_t anim_sampler_index1 = graph.getAnimNodeIndex(anim_sampler_instance1);
size_t blend_index = graph.getAnimNodeIndex(blend2_instance);
CHECK(graph.m_node_inputs[anim_sampler_index0].size() == 0);
CHECK(graph.m_node_inputs[anim_sampler_index1].size() == 0);
CHECK(graph.m_node_inputs[blend_index].size() == 2);
CHECK(graph.m_node_inputs[blend_index][0] == anim_sampler_instance0);
CHECK(graph.m_node_inputs[blend_index][1] == anim_sampler_instance1);
}
TEST_CASE("InputAttributeConversion", "[AnimGraphResource]") {
int node_id = 3321;
int input_index = 221;
int output_index = 125;
int parsed_node_id;
int parsed_input_index;
int parsed_output_index;
int attribute_id = GenerateInputAttributeId(node_id, input_index);
SplitInputAttributeId(attribute_id, &parsed_node_id, &parsed_input_index);
CHECK(node_id == parsed_node_id);
CHECK(input_index == parsed_input_index);
attribute_id = GenerateOutputAttributeId(node_id, output_index);
SplitOutputAttributeId(attribute_id, &parsed_node_id, &parsed_output_index);
CHECK(node_id == parsed_node_id);
CHECK(output_index == parsed_output_index);
}
+10 -10
View File
@@ -95,7 +95,7 @@ TEST_CASE("Sample single bone channel", "[AnimSamplerNode]") {
ozz::math::Transform calculated_root_transform;
calc_bone_translation(ratio, 0, animation, calculated_root_transform);
std::cout << "ratio: " << ratio << "\t" << "err: " << ozz::math::Length(sampled_root_transform.translation - calculated_root_transform.translation) << std::endl;
// std::cout << "ratio: " << ratio << "\t" << "err: " << ozz::math::Length(sampled_root_transform.translation - calculated_root_transform.translation) << std::endl;
}
ozz::math::Transform root_transform_1;
@@ -114,13 +114,13 @@ TEST_CASE("Root Bone Sampling", "[AnimSamplerNode]") {
2,
walking_markers);
AnimationController anim_controller(&skinned_mesh);
AnimSamplerNode test_node(&anim_controller);
test_node.SetAnimation(skinned_mesh.m_animations[0], SyncTrack());
test_node.Reset();
test_node.UpdateTime(0.2f);
ozz::math::Transform root_transform;
test_node.Evaluate(&skinned_mesh.m_local_matrices, &root_transform);
// AnimationController anim_controller(&skinned_mesh);
// AnimSamplerNode test_node(&anim_controller);
// test_node.SetAnimation(skinned_mesh.m_animations[0], SyncTrack());
//
// test_node.Reset();
// test_node.UpdateTime(0.2f);
//
// ozz::math::Transform root_transform;
// test_node.Evaluate(&skinned_mesh.m_local_matrices, &root_transform);
}