Working on unified BlendTree and StateMachine handling.
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
//
|
||||
|
||||
#include "AnimGraph/AnimGraph.h"
|
||||
#include "AnimGraph/AnimGraphBlendTreeResource.h"
|
||||
#include "AnimGraph/AnimGraphEditor.h"
|
||||
#include "AnimGraph/AnimGraphResource.h"
|
||||
#include "catch.hpp"
|
||||
#include "ozz/animation/offline/animation_builder.h"
|
||||
#include "ozz/animation/offline/raw_animation.h"
|
||||
@@ -141,7 +141,7 @@ TEST_CASE_METHOD(
|
||||
SimpleAnimFixture,
|
||||
"AnimGraphSimpleEval",
|
||||
"[AnimGraphEvalTests]") {
|
||||
AnimGraphResource graph_resource;
|
||||
AnimGraphBlendTreeResource graph_resource;
|
||||
|
||||
// Add nodes
|
||||
size_t trans_x_node_index =
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
//
|
||||
|
||||
#include "AnimGraph/AnimGraph.h"
|
||||
#include "AnimGraph/AnimGraphBlendTree.h"
|
||||
#include "AnimGraph/AnimGraphEditor.h"
|
||||
#include "AnimGraph/AnimGraphNodes.h"
|
||||
#include "AnimGraph/AnimGraphResource.h"
|
||||
#include "catch.hpp"
|
||||
#include "ozz/base/io/archive.h"
|
||||
@@ -33,61 +35,65 @@ bool load_skeleton(ozz::animation::Skeleton& skeleton, const char* filename) {
|
||||
|
||||
TEST_CASE("AnimSamplerGraph", "[AnimGraphResource]") {
|
||||
AnimGraphResource graph_resource;
|
||||
graph_resource.m_name = "AnimSamplerBlendTree";
|
||||
graph_resource.m_type = "BlendTree";
|
||||
|
||||
graph_resource.clear();
|
||||
graph_resource.m_name = "AnimSamplerGraph";
|
||||
BlendTreeResource& blend_tree_resource = graph_resource.m_blend_tree_resource;
|
||||
blend_tree_resource.Reset();
|
||||
blend_tree_resource.InitGraphConnectors();
|
||||
|
||||
// Prepare graph inputs and outputs
|
||||
size_t walk_node_index =
|
||||
graph_resource.addNode(AnimNodeResourceFactory("AnimSampler"));
|
||||
blend_tree_resource.m_nodes.push_back(AnimNodeResourceFactory("AnimSampler"));
|
||||
size_t walk_node_index = blend_tree_resource.m_nodes.size() - 1;
|
||||
|
||||
AnimNodeResource& walk_node = graph_resource.m_nodes[walk_node_index];
|
||||
AnimNodeResource& walk_node = blend_tree_resource.m_nodes[walk_node_index];
|
||||
walk_node.m_name = "WalkAnim";
|
||||
walk_node.m_socket_accessor->SetPropertyValue(
|
||||
"Filename",
|
||||
std::string("media/Walking-loop.ozz"));
|
||||
|
||||
AnimNodeResource& graph_node = graph_resource.m_nodes[0];
|
||||
AnimNodeResource& graph_node = blend_tree_resource.m_nodes[0];
|
||||
graph_node.m_socket_accessor->RegisterInput<AnimData>("GraphOutput", nullptr);
|
||||
|
||||
graph_resource.connectSockets(
|
||||
blend_tree_resource.ConnectSockets(
|
||||
walk_node,
|
||||
"Output",
|
||||
graph_resource.getGraphOutputNode(),
|
||||
blend_tree_resource.GetGraphOutputNode(),
|
||||
"GraphOutput");
|
||||
|
||||
graph_resource.saveToFile("AnimSamplerGraph.animgraph.json");
|
||||
AnimGraphResource graph_resource_loaded;
|
||||
graph_resource_loaded.loadFromFile("AnimSamplerGraph.animgraph.json");
|
||||
graph_resource.SaveToFile("AnimSamplerBlendTree.json");
|
||||
|
||||
AnimGraph graph;
|
||||
graph_resource_loaded.createInstance(graph);
|
||||
AnimGraphResource graph_resource_loaded;
|
||||
graph_resource_loaded.LoadFromFile("AnimSamplerBlendTree.json");
|
||||
|
||||
AnimGraphBlendTree anim_graph_blend_tree;
|
||||
graph_resource_loaded.CreateBlendTreeInstance(anim_graph_blend_tree);
|
||||
AnimGraphContext graph_context;
|
||||
|
||||
ozz::animation::Skeleton skeleton;
|
||||
REQUIRE(load_skeleton(skeleton, "media/skeleton.ozz"));
|
||||
graph_context.m_skeleton = &skeleton;
|
||||
|
||||
REQUIRE(graph.init(graph_context));
|
||||
REQUIRE(anim_graph_blend_tree.Init(graph_context));
|
||||
|
||||
REQUIRE(graph.m_nodes.size() == 3);
|
||||
REQUIRE(graph.m_nodes[0]->m_node_type_name == "BlendTree");
|
||||
REQUIRE(graph.m_nodes[1]->m_node_type_name == "BlendTree");
|
||||
REQUIRE(graph.m_nodes[2]->m_node_type_name == "AnimSampler");
|
||||
REQUIRE(anim_graph_blend_tree.m_nodes.size() == 3);
|
||||
REQUIRE(anim_graph_blend_tree.m_nodes[0]->m_node_type_name == "BlendTree");
|
||||
REQUIRE(anim_graph_blend_tree.m_nodes[1]->m_node_type_name == "BlendTree");
|
||||
REQUIRE(anim_graph_blend_tree.m_nodes[2]->m_node_type_name == "AnimSampler");
|
||||
|
||||
// connections within the graph
|
||||
AnimSamplerNode* anim_sampler_walk =
|
||||
dynamic_cast<AnimSamplerNode*>(graph.m_nodes[2]);
|
||||
dynamic_cast<AnimSamplerNode*>(anim_graph_blend_tree.m_nodes[2]);
|
||||
|
||||
BlendTreeNode* graph_output_node =
|
||||
dynamic_cast<BlendTreeNode*>(graph.m_nodes[0]);
|
||||
dynamic_cast<BlendTreeNode*>(anim_graph_blend_tree.m_nodes[0]);
|
||||
|
||||
// check node input dependencies
|
||||
size_t anim_sampler_index = anim_sampler_walk->m_index;
|
||||
size_t anim_sampler_index = anim_graph_blend_tree.GetAnimNodeIndex(anim_sampler_walk);
|
||||
|
||||
REQUIRE(graph.m_node_output_connections[anim_sampler_index].size() == 1);
|
||||
REQUIRE(anim_graph_blend_tree.m_node_output_connections[anim_sampler_index].size() == 1);
|
||||
CHECK(
|
||||
graph.m_node_output_connections[anim_sampler_index][0].m_target_node
|
||||
anim_graph_blend_tree.m_node_output_connections[anim_sampler_index][0].m_target_node
|
||||
== graph_output_node);
|
||||
|
||||
// Ensure animation sampler nodes use the correct files
|
||||
@@ -97,11 +103,11 @@ TEST_CASE("AnimSamplerGraph", "[AnimGraphResource]") {
|
||||
// Ensure that outputs are properly propagated.
|
||||
AnimData output;
|
||||
output.m_local_matrices.resize(skeleton.num_soa_joints());
|
||||
graph.SetOutput("GraphOutput", &output);
|
||||
anim_graph_blend_tree.SetOutput("GraphOutput", &output);
|
||||
REQUIRE(anim_sampler_walk->o_output == &output);
|
||||
|
||||
WHEN("Emulating Graph Evaluation") {
|
||||
CHECK(graph.m_anim_data_allocator.size() == 0);
|
||||
CHECK(anim_graph_blend_tree.m_anim_data_allocator.size() == 0);
|
||||
anim_sampler_walk->Evaluate(graph_context);
|
||||
}
|
||||
|
||||
@@ -109,10 +115,12 @@ TEST_CASE("AnimSamplerGraph", "[AnimGraphResource]") {
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that node const inputs are properly set.
|
||||
*/
|
||||
|
||||
//
|
||||
// Checks that node const inputs are properly set.
|
||||
//
|
||||
TEST_CASE("AnimSamplerSpeedScaleGraph", "[AnimGraphResource]") {
|
||||
AnimGraphResource graph_resource;
|
||||
AnimGraphBlendTreeResource graph_resource;
|
||||
|
||||
graph_resource.clear();
|
||||
graph_resource.m_name = "AnimSamplerSpeedScaleGraph";
|
||||
@@ -150,7 +158,7 @@ TEST_CASE("AnimSamplerSpeedScaleGraph", "[AnimGraphResource]") {
|
||||
"GraphOutput");
|
||||
|
||||
graph_resource.saveToFile("AnimSamplerSpeedScaleGraph.animgraph.json");
|
||||
AnimGraphResource graph_resource_loaded;
|
||||
AnimGraphBlendTreeResource graph_resource_loaded;
|
||||
graph_resource_loaded.loadFromFile(
|
||||
"AnimSamplerSpeedScaleGraph.animgraph.json");
|
||||
|
||||
@@ -172,7 +180,7 @@ TEST_CASE("AnimSamplerSpeedScaleGraph", "[AnimGraphResource]") {
|
||||
|
||||
|
||||
TEST_CASE("Blend2Graph", "[AnimGraphResource]") {
|
||||
AnimGraphResource graph_resource;
|
||||
AnimGraphBlendTreeResource graph_resource;
|
||||
|
||||
graph_resource.clear();
|
||||
graph_resource.m_name = "WalkRunBlendGraph";
|
||||
@@ -214,7 +222,7 @@ TEST_CASE("Blend2Graph", "[AnimGraphResource]") {
|
||||
"GraphOutput");
|
||||
|
||||
graph_resource.saveToFile("Blend2Graph.animgraph.json");
|
||||
AnimGraphResource graph_resource_loaded;
|
||||
AnimGraphBlendTreeResource graph_resource_loaded;
|
||||
graph_resource_loaded.loadFromFile("Blend2Graph.animgraph.json");
|
||||
|
||||
AnimGraph graph;
|
||||
@@ -311,7 +319,7 @@ TEST_CASE("InputAttributeConversion", "[AnimGraphResource]") {
|
||||
}
|
||||
|
||||
TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
||||
AnimGraphResource graph_resource_origin;
|
||||
AnimGraphBlendTreeResource graph_resource_origin;
|
||||
|
||||
graph_resource_origin.clear();
|
||||
graph_resource_origin.m_name = "TestInputOutputGraph";
|
||||
@@ -370,7 +378,7 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
||||
const char* filename = "ResourceSaveLoadGraphInputs.json";
|
||||
graph_resource_origin.saveToFile(filename);
|
||||
|
||||
AnimGraphResource graph_resource_loaded;
|
||||
AnimGraphBlendTreeResource graph_resource_loaded;
|
||||
graph_resource_loaded.loadFromFile(filename);
|
||||
|
||||
const AnimNodeResource& graph_loaded_output_node =
|
||||
@@ -444,7 +452,7 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
||||
}
|
||||
|
||||
TEST_CASE("SimpleMathEvaluations", "[AnimGraphResource]") {
|
||||
AnimGraphResource graph_resource_origin;
|
||||
AnimGraphBlendTreeResource graph_resource_origin;
|
||||
|
||||
graph_resource_origin.clear();
|
||||
graph_resource_origin.m_name = "TestInputOutputGraph";
|
||||
@@ -529,7 +537,7 @@ TEST_CASE("SimpleMathEvaluations", "[AnimGraphResource]") {
|
||||
const char* filename = "ResourceSaveLoadGraphInputs.json";
|
||||
graph_resource_origin.saveToFile(filename);
|
||||
|
||||
AnimGraphResource graph_resource_loaded;
|
||||
AnimGraphBlendTreeResource graph_resource_loaded;
|
||||
graph_resource_loaded.loadFromFile(filename);
|
||||
|
||||
const AnimNodeResource& graph_loaded_output_node =
|
||||
@@ -580,3 +588,5 @@ TEST_CASE("SimpleMathEvaluations", "[AnimGraphResource]") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user