2022-02-11 16:51:18 +01:00
|
|
|
//
|
|
|
|
// Created by martin on 04.02.22.
|
|
|
|
//
|
|
|
|
|
2024-03-17 22:06:27 +01:00
|
|
|
#include "AnimGraph/AnimGraphBlendTree.h"
|
2022-03-25 11:46:44 +01:00
|
|
|
#include "AnimGraph/AnimGraphEditor.h"
|
2024-03-17 22:06:27 +01:00
|
|
|
#include "AnimGraph/AnimGraphNodes.h"
|
2022-04-03 21:05:11 +02:00
|
|
|
#include "AnimGraph/AnimGraphResource.h"
|
2022-03-25 11:46:44 +01:00
|
|
|
#include "catch.hpp"
|
2023-04-02 16:26:24 +02:00
|
|
|
#include "ozz/base/io/archive.h"
|
|
|
|
#include "ozz/base/io/stream.h"
|
|
|
|
#include "ozz/base/log.h"
|
2022-02-19 00:25:51 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
class SimpleAnimSamplerGraphResource {
|
|
|
|
protected:
|
|
|
|
AnimGraphResource graph_resource;
|
|
|
|
BlendTreeResource* blend_tree_resource = nullptr;
|
|
|
|
size_t walk_node_index = -1;
|
|
|
|
AnimNodeResource* walk_node = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SimpleAnimSamplerGraphResource() {
|
|
|
|
graph_resource.m_name = "AnimSamplerBlendTree";
|
|
|
|
graph_resource.m_node_type_name = "BlendTree";
|
|
|
|
graph_resource.m_graph_type_name = "BlendTree";
|
|
|
|
|
|
|
|
blend_tree_resource = &graph_resource.m_blend_tree_resource;
|
|
|
|
blend_tree_resource->InitGraphConnectors();
|
|
|
|
|
|
|
|
// Prepare graph inputs and outputs
|
|
|
|
blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("AnimSampler"));
|
|
|
|
walk_node_index = blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
|
|
|
|
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 = blend_tree_resource->GetGraphOutputNode();
|
|
|
|
graph_node->m_socket_accessor->RegisterInput<AnimData>(
|
|
|
|
"GraphOutput",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
blend_tree_resource->ConnectSockets(
|
|
|
|
walk_node,
|
|
|
|
"Output",
|
|
|
|
blend_tree_resource->GetGraphOutputNode(),
|
|
|
|
"GraphOutput");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Blend2GraphResource {
|
|
|
|
protected:
|
|
|
|
AnimGraphResource graph_resource;
|
|
|
|
BlendTreeResource* blend_tree_resource = nullptr;
|
|
|
|
size_t walk_node_index = -1;
|
|
|
|
size_t run_node_index = -1;
|
|
|
|
size_t blend_node_index = -1;
|
|
|
|
AnimNodeResource* walk_node = nullptr;
|
|
|
|
AnimNodeResource* run_node = nullptr;
|
|
|
|
AnimNodeResource* blend_node = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Blend2GraphResource() {
|
|
|
|
graph_resource.m_name = "WalkRunBlendGraph";
|
|
|
|
graph_resource.m_node_type_name = "BlendTree";
|
|
|
|
graph_resource.m_graph_type_name = "BlendTree";
|
|
|
|
|
|
|
|
blend_tree_resource = &graph_resource.m_blend_tree_resource;
|
|
|
|
blend_tree_resource->InitGraphConnectors();
|
|
|
|
|
|
|
|
// Prepare graph inputs and outputs
|
|
|
|
blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("AnimSampler"));
|
|
|
|
walk_node_index = blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
|
|
|
|
blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("AnimSampler"));
|
|
|
|
run_node_index = blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
|
|
|
|
blend_tree_resource->m_nodes.push_back(AnimNodeResourceFactory("Blend2"));
|
|
|
|
blend_node_index = blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
|
|
|
|
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"));
|
|
|
|
run_node = blend_tree_resource->m_nodes[run_node_index];
|
|
|
|
run_node->m_socket_accessor->SetPropertyValue(
|
|
|
|
"Filename",
|
|
|
|
std::string("media/Running0-loop.ozz"));
|
|
|
|
run_node->m_name = "RunAnim";
|
|
|
|
blend_node = blend_tree_resource->m_nodes[blend_node_index];
|
|
|
|
blend_node->m_name = "BlendWalkRun";
|
|
|
|
|
|
|
|
AnimNodeResource* graph_node = blend_tree_resource->GetGraphOutputNode();
|
|
|
|
graph_node->m_socket_accessor->RegisterInput<AnimData>(
|
|
|
|
"GraphOutput",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
REQUIRE(graph_node->m_socket_accessor->m_inputs.size() == 1);
|
|
|
|
REQUIRE(blend_node->m_socket_accessor->GetInputIndex("Input0") == 0);
|
|
|
|
REQUIRE(blend_node->m_socket_accessor->GetInputIndex("Input1") == 1);
|
|
|
|
blend_node->m_socket_accessor->SetInputValue("Weight", 0.123f);
|
|
|
|
|
|
|
|
blend_tree_resource
|
|
|
|
->ConnectSockets(walk_node, "Output", blend_node, "Input0");
|
|
|
|
blend_tree_resource
|
|
|
|
->ConnectSockets(run_node, "Output", blend_node, "Input1");
|
|
|
|
blend_tree_resource->ConnectSockets(
|
|
|
|
blend_node,
|
|
|
|
"Output",
|
|
|
|
blend_tree_resource->GetGraphOutputNode(),
|
|
|
|
"GraphOutput");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Used for tests with a BlendTree within a BlendTree
|
|
|
|
//
|
|
|
|
// +-----------Parent BlendTree-------------+
|
|
|
|
// | |
|
|
|
|
// | +-----Embd Btree---+ |
|
|
|
|
// | AnmSmpl--+-\ | |
|
|
|
|
// | | \-SpdScale------+--Out |
|
|
|
|
// | |------------------+ |
|
|
|
|
// | |
|
|
|
|
// +----------------------------------------+
|
|
|
|
//
|
|
|
|
class EmbeddedBlendTreeGraphResource {
|
|
|
|
protected:
|
|
|
|
AnimGraphResource parent_graph_resource;
|
|
|
|
BlendTreeResource* parent_blend_tree_resource = nullptr;
|
|
|
|
|
|
|
|
AnimGraphResource* embedded_graph = nullptr;
|
|
|
|
BlendTreeResource* embedded_blend_tree_resource = nullptr;
|
|
|
|
|
|
|
|
size_t walk_node_index = -1;
|
2024-04-01 12:33:23 +02:00
|
|
|
AnimNodeResource* walk_node_resource = nullptr;
|
|
|
|
size_t embedded_blend_tree_node_index = -1;
|
|
|
|
size_t embedded_speed_scale_index = -1;
|
2024-03-25 21:10:27 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
EmbeddedBlendTreeGraphResource() {
|
|
|
|
parent_graph_resource.m_name = "ParentBlendTree";
|
|
|
|
parent_graph_resource.m_graph_type_name = "BlendTree";
|
|
|
|
parent_graph_resource.m_node_type_name = "BlendTree";
|
|
|
|
|
|
|
|
parent_blend_tree_resource = &parent_graph_resource.m_blend_tree_resource;
|
|
|
|
parent_blend_tree_resource->Reset();
|
|
|
|
parent_blend_tree_resource->InitGraphConnectors();
|
|
|
|
|
|
|
|
// Setup parent outputs
|
|
|
|
AnimNodeResource* parent_blend_tree_outputs =
|
|
|
|
parent_blend_tree_resource->GetGraphOutputNode();
|
|
|
|
parent_blend_tree_outputs->m_socket_accessor->RegisterInput<AnimData>(
|
|
|
|
"Output",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Parent AnimSampler
|
|
|
|
parent_blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("AnimSampler"));
|
2024-04-01 12:33:23 +02:00
|
|
|
walk_node_index = parent_blend_tree_resource->m_nodes.size() - 1;
|
2024-03-25 21:10:27 +01:00
|
|
|
|
2024-04-01 12:33:23 +02:00
|
|
|
walk_node_resource = parent_blend_tree_resource->m_nodes[walk_node_index];
|
|
|
|
walk_node_resource->m_name = "WalkAnim";
|
|
|
|
walk_node_resource->m_socket_accessor->SetPropertyValue(
|
2024-03-25 21:10:27 +01:00
|
|
|
"Filename",
|
|
|
|
std::string("media/Walking-loop.ozz"));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Embedded Tree
|
|
|
|
//
|
|
|
|
parent_blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("BlendTree"));
|
2024-04-01 12:33:23 +02:00
|
|
|
embedded_blend_tree_node_index =
|
2024-03-25 21:10:27 +01:00
|
|
|
parent_blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
embedded_graph = dynamic_cast<AnimGraphResource*>(
|
|
|
|
parent_blend_tree_resource->m_nodes.back());
|
|
|
|
embedded_graph->m_name = "EmbeddedBlendTree";
|
|
|
|
embedded_graph->m_node_type_name = "BlendTree";
|
2024-03-25 22:26:29 +01:00
|
|
|
embedded_graph->m_graph_type_name = "BlendTree";
|
2024-03-25 21:10:27 +01:00
|
|
|
embedded_blend_tree_resource = &embedded_graph->m_blend_tree_resource;
|
|
|
|
|
|
|
|
// Embedded: outputs
|
|
|
|
AnimNodeResource* embedded_outputs =
|
|
|
|
embedded_blend_tree_resource->GetGraphOutputNode();
|
|
|
|
embedded_outputs->m_socket_accessor->RegisterInput<AnimData>(
|
|
|
|
"AnimOutput",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Embedded: inputs
|
|
|
|
AnimNodeResource* embedded_inputs =
|
|
|
|
embedded_blend_tree_resource->GetGraphInputNode();
|
|
|
|
embedded_inputs->m_socket_accessor->RegisterOutput<AnimData>(
|
|
|
|
"AnimInput",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Embedded: SpeedScale node
|
|
|
|
embedded_blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("SpeedScale"));
|
2024-04-01 12:33:23 +02:00
|
|
|
embedded_speed_scale_index =
|
|
|
|
embedded_blend_tree_resource->m_nodes.size() - 1;
|
2024-03-25 21:10:27 +01:00
|
|
|
AnimNodeResource* embedded_speed_scale_resource =
|
2024-04-01 12:33:23 +02:00
|
|
|
embedded_blend_tree_resource->m_nodes[embedded_speed_scale_index];
|
|
|
|
embedded_speed_scale_resource->m_socket_accessor->SetInputValue(
|
|
|
|
"SpeedScale",
|
|
|
|
0.1f);
|
2024-03-25 21:10:27 +01:00
|
|
|
|
|
|
|
// Embedded: setup connections
|
|
|
|
embedded_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_inputs,
|
|
|
|
"AnimInput",
|
|
|
|
embedded_speed_scale_resource,
|
|
|
|
"Input");
|
|
|
|
embedded_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_speed_scale_resource,
|
|
|
|
"Output",
|
|
|
|
embedded_outputs,
|
|
|
|
"AnimOutput");
|
|
|
|
|
|
|
|
// Parent: setup connections
|
|
|
|
REQUIRE(parent_blend_tree_resource->ConnectSockets(
|
2024-04-01 12:33:23 +02:00
|
|
|
walk_node_resource,
|
2024-03-25 21:10:27 +01:00
|
|
|
"Output",
|
|
|
|
embedded_graph,
|
|
|
|
"AnimInput"));
|
|
|
|
REQUIRE(parent_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_graph,
|
|
|
|
"AnimOutput",
|
|
|
|
parent_blend_tree_outputs,
|
|
|
|
"Output"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-04-01 17:59:25 +02:00
|
|
|
//
|
|
|
|
// Used for tests with a BlendTree within a BlendTree
|
|
|
|
//
|
|
|
|
// +-----------Parent BlendTree-------------+
|
|
|
|
// | |
|
|
|
|
// | +-----Embd Btree---+ |
|
|
|
|
// | AnmSmpl--+-------\ | |
|
|
|
|
// | | Blend2---+--Out
|
|
|
|
// | | AnmS-/ | |
|
|
|
|
// | |------------------+ |
|
|
|
|
// | |
|
|
|
|
// +----------------------------------------+
|
|
|
|
//
|
|
|
|
class EmbeddedTreeBlend2GraphResource {
|
|
|
|
protected:
|
|
|
|
AnimGraphResource parent_graph_resource;
|
|
|
|
BlendTreeResource* parent_blend_tree_resource = nullptr;
|
|
|
|
|
|
|
|
AnimGraphResource* embedded_graph = nullptr;
|
|
|
|
BlendTreeResource* embedded_blend_tree_resource = nullptr;
|
|
|
|
|
|
|
|
size_t walk_node_index = -1;
|
|
|
|
AnimNodeResource* walk_node_resource = nullptr;
|
|
|
|
|
|
|
|
size_t embedded_blend_tree_node_index = -1;
|
|
|
|
size_t embedded_blend2_node_index = -1;
|
|
|
|
size_t embedded_run_node_index = -1;
|
|
|
|
AnimNodeResource* embedded_blend2_node_resource = nullptr;
|
|
|
|
AnimNodeResource* embedded_run_node_resource = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
EmbeddedTreeBlend2GraphResource() {
|
|
|
|
parent_graph_resource.m_name = "ParentBlendTree";
|
|
|
|
parent_graph_resource.m_graph_type_name = "BlendTree";
|
|
|
|
parent_graph_resource.m_node_type_name = "BlendTree";
|
|
|
|
|
|
|
|
parent_blend_tree_resource = &parent_graph_resource.m_blend_tree_resource;
|
|
|
|
parent_blend_tree_resource->Reset();
|
|
|
|
parent_blend_tree_resource->InitGraphConnectors();
|
|
|
|
|
|
|
|
// Setup parent outputs
|
|
|
|
AnimNodeResource* parent_blend_tree_outputs =
|
|
|
|
parent_blend_tree_resource->GetGraphOutputNode();
|
|
|
|
parent_blend_tree_outputs->m_socket_accessor->RegisterInput<AnimData>(
|
|
|
|
"Output",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Setup parent inputs
|
|
|
|
AnimNodeResource* parent_blend_tree_inputs =
|
|
|
|
parent_blend_tree_resource->GetGraphInputNode();
|
|
|
|
parent_blend_tree_inputs->m_socket_accessor->RegisterOutput<float>(
|
|
|
|
"EmbeddedBlend2Weight",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Parent AnimSampler
|
|
|
|
parent_blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("AnimSampler"));
|
|
|
|
walk_node_index = parent_blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
|
|
|
|
walk_node_resource = parent_blend_tree_resource->m_nodes[walk_node_index];
|
|
|
|
walk_node_resource->m_name = "WalkAnim";
|
|
|
|
walk_node_resource->m_socket_accessor->SetPropertyValue(
|
|
|
|
"Filename",
|
|
|
|
std::string("media/Walking-loop.ozz"));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Embedded Tree
|
|
|
|
//
|
|
|
|
parent_blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("BlendTree"));
|
|
|
|
embedded_blend_tree_node_index =
|
|
|
|
parent_blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
embedded_graph = dynamic_cast<AnimGraphResource*>(
|
|
|
|
parent_blend_tree_resource->m_nodes.back());
|
|
|
|
embedded_graph->m_name = "EmbeddedTreeBlend2GraphResource";
|
|
|
|
embedded_graph->m_node_type_name = "BlendTree";
|
|
|
|
embedded_graph->m_graph_type_name = "BlendTree";
|
|
|
|
embedded_blend_tree_resource = &embedded_graph->m_blend_tree_resource;
|
|
|
|
|
|
|
|
// Embedded: outputs
|
|
|
|
AnimNodeResource* embedded_outputs =
|
|
|
|
embedded_blend_tree_resource->GetGraphOutputNode();
|
|
|
|
embedded_outputs->m_socket_accessor->RegisterInput<AnimData>(
|
|
|
|
"AnimOutput",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Embedded: inputs
|
|
|
|
AnimNodeResource* embedded_inputs =
|
|
|
|
embedded_blend_tree_resource->GetGraphInputNode();
|
|
|
|
embedded_inputs->m_socket_accessor->RegisterOutput<AnimData>(
|
|
|
|
"AnimInput",
|
|
|
|
nullptr);
|
|
|
|
embedded_inputs->m_socket_accessor->RegisterOutput<float>(
|
|
|
|
"BlendWeight",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Embedded nodes
|
|
|
|
embedded_blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("Blend2"));
|
|
|
|
embedded_blend2_node_index =
|
|
|
|
embedded_blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
|
|
|
|
embedded_blend_tree_resource->m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("AnimSampler"));
|
|
|
|
embedded_run_node_index = embedded_blend_tree_resource->m_nodes.size() - 1;
|
|
|
|
|
|
|
|
// Configure node resources
|
2024-04-05 00:43:41 +02:00
|
|
|
embedded_blend2_node_resource =
|
2024-04-01 17:59:25 +02:00
|
|
|
embedded_blend_tree_resource->m_nodes[embedded_blend2_node_index];
|
|
|
|
embedded_blend2_node_resource->m_socket_accessor->SetInputValue(
|
|
|
|
"Weight",
|
|
|
|
0.1f);
|
|
|
|
|
|
|
|
embedded_run_node_resource =
|
|
|
|
embedded_blend_tree_resource->m_nodes[embedded_run_node_index];
|
|
|
|
embedded_run_node_resource->m_name = "RunAnim";
|
|
|
|
embedded_run_node_resource->m_socket_accessor->SetPropertyValue(
|
|
|
|
"Filename",
|
|
|
|
std::string("media/RunningSlow-loop.ozz"));
|
|
|
|
|
|
|
|
// Embedded: setup connections
|
|
|
|
REQUIRE(embedded_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_inputs,
|
|
|
|
"AnimInput",
|
|
|
|
embedded_blend2_node_resource,
|
|
|
|
"Input0"));
|
|
|
|
REQUIRE(embedded_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_run_node_resource,
|
|
|
|
"Output",
|
|
|
|
embedded_blend2_node_resource,
|
|
|
|
"Input1"));
|
|
|
|
REQUIRE(embedded_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_blend2_node_resource,
|
|
|
|
"Output",
|
|
|
|
embedded_blend_tree_resource->GetGraphOutputNode(),
|
|
|
|
"AnimOutput"));
|
|
|
|
REQUIRE(embedded_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_inputs,
|
|
|
|
"BlendWeight",
|
|
|
|
embedded_blend2_node_resource,
|
|
|
|
"Weight"));
|
|
|
|
|
|
|
|
// Parent: setup connections
|
|
|
|
REQUIRE(parent_blend_tree_resource->ConnectSockets(
|
|
|
|
walk_node_resource,
|
|
|
|
"Output",
|
|
|
|
embedded_graph,
|
|
|
|
"AnimInput"));
|
|
|
|
REQUIRE(parent_blend_tree_resource->ConnectSockets(
|
|
|
|
embedded_graph,
|
|
|
|
"AnimOutput",
|
|
|
|
parent_blend_tree_outputs,
|
|
|
|
"Output"));
|
|
|
|
REQUIRE(parent_blend_tree_resource->ConnectSockets(
|
|
|
|
parent_blend_tree_inputs,
|
|
|
|
"EmbeddedBlend2Weight",
|
|
|
|
embedded_graph,
|
|
|
|
"BlendWeight"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-02 16:26:24 +02:00
|
|
|
bool load_skeleton(ozz::animation::Skeleton& skeleton, const char* filename) {
|
2022-04-11 16:46:09 +02:00
|
|
|
assert(filename);
|
|
|
|
ozz::io::File file(filename, "rb");
|
|
|
|
if (!file.opened()) {
|
|
|
|
ozz::log::Err() << "Failed to open skeleton file " << filename << "."
|
|
|
|
<< std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ozz::io::IArchive archive(&file);
|
|
|
|
if (!archive.TestTag<ozz::animation::Skeleton>()) {
|
|
|
|
ozz::log::Err() << "Failed to load skeleton instance from file " << filename
|
|
|
|
<< "." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once the tag is validated, reading cannot fail.
|
|
|
|
archive >> skeleton;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
TEST_CASE_METHOD(
|
|
|
|
SimpleAnimSamplerGraphResource,
|
|
|
|
"SimpleAnimSamplerGraphResource saving and loading results in same "
|
|
|
|
"resource",
|
|
|
|
"[SimpleAnimSamplerGraphResource]") {
|
|
|
|
graph_resource.SaveToFile("TestGraphAnimSamplerBlendTree.json");
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
AnimGraphResource graph_resource_loaded;
|
|
|
|
graph_resource_loaded.LoadFromFile("TestGraphAnimSamplerBlendTree.json");
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
graph_resource.m_graph_type_name
|
|
|
|
== graph_resource_loaded.m_graph_type_name);
|
|
|
|
REQUIRE(graph_resource.m_name == graph_resource_loaded.m_name);
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
BlendTreeResource* blend_tree_resource_loaded =
|
|
|
|
&graph_resource_loaded.m_blend_tree_resource;
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
blend_tree_resource->m_nodes.size()
|
|
|
|
== blend_tree_resource_loaded->m_nodes.size());
|
|
|
|
for (size_t i = 0; i < blend_tree_resource->m_nodes.size(); i++) {
|
|
|
|
const AnimNodeResource* node = blend_tree_resource->m_nodes[i];
|
|
|
|
const AnimNodeResource* node_loaded =
|
|
|
|
blend_tree_resource_loaded->m_nodes[i];
|
|
|
|
|
|
|
|
REQUIRE(node->m_name == node_loaded->m_name);
|
|
|
|
REQUIRE(node->m_node_type_name == node_loaded->m_node_type_name);
|
|
|
|
}
|
2024-03-17 22:06:27 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
blend_tree_resource->m_connections.size()
|
|
|
|
== blend_tree_resource_loaded->m_connections.size());
|
|
|
|
for (size_t i = 0; i < blend_tree_resource->m_connections.size(); i++) {
|
|
|
|
const BlendTreeConnectionResource& connection =
|
|
|
|
blend_tree_resource->m_connections[i];
|
|
|
|
const BlendTreeConnectionResource& connection_loaded =
|
|
|
|
blend_tree_resource_loaded->m_connections[i];
|
|
|
|
|
|
|
|
REQUIRE(
|
|
|
|
connection.source_node_index == connection_loaded.source_node_index);
|
|
|
|
REQUIRE(
|
|
|
|
connection.source_socket_name == connection_loaded.source_socket_name);
|
|
|
|
REQUIRE(
|
|
|
|
connection.target_node_index == connection_loaded.target_node_index);
|
|
|
|
REQUIRE(
|
|
|
|
connection.target_socket_name == connection_loaded.target_socket_name);
|
|
|
|
}
|
|
|
|
}
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
TEST_CASE_METHOD(
|
|
|
|
SimpleAnimSamplerGraphResource,
|
|
|
|
"SimpleAnimSamplerGraphResource emulated evaluation",
|
|
|
|
"[SimpleAnimSamplerGraphResource]") {
|
2024-03-17 22:06:27 +01:00
|
|
|
AnimGraphBlendTree anim_graph_blend_tree;
|
2024-03-25 21:10:27 +01:00
|
|
|
graph_resource.CreateBlendTreeInstance(anim_graph_blend_tree);
|
2023-04-01 14:16:20 +02:00
|
|
|
AnimGraphContext graph_context;
|
|
|
|
|
|
|
|
ozz::animation::Skeleton skeleton;
|
2023-04-21 12:39:09 +02:00
|
|
|
REQUIRE(load_skeleton(skeleton, "media/skeleton.ozz"));
|
2023-04-01 14:16:20 +02:00
|
|
|
graph_context.m_skeleton = &skeleton;
|
|
|
|
|
2024-03-17 22:06:27 +01:00
|
|
|
REQUIRE(anim_graph_blend_tree.Init(graph_context));
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-17 22:06:27 +01:00
|
|
|
REQUIRE(anim_graph_blend_tree.m_nodes.size() == 3);
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
anim_graph_blend_tree.m_nodes[0]->m_node_type_name == "BlendTreeSockets");
|
|
|
|
REQUIRE(
|
|
|
|
anim_graph_blend_tree.m_nodes[1]->m_node_type_name == "BlendTreeSockets");
|
2024-03-17 22:06:27 +01:00
|
|
|
REQUIRE(anim_graph_blend_tree.m_nodes[2]->m_node_type_name == "AnimSampler");
|
2023-04-01 14:16:20 +02:00
|
|
|
|
|
|
|
// connections within the graph
|
|
|
|
AnimSamplerNode* anim_sampler_walk =
|
2024-03-17 22:06:27 +01:00
|
|
|
dynamic_cast<AnimSamplerNode*>(anim_graph_blend_tree.m_nodes[2]);
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-04-01 12:33:23 +02:00
|
|
|
BlendTreeSocketNode* graph_output_node =
|
|
|
|
dynamic_cast<BlendTreeSocketNode*>(anim_graph_blend_tree.m_nodes[0]);
|
2023-04-01 14:16:20 +02:00
|
|
|
|
|
|
|
// check node input dependencies
|
2024-03-25 21:10:27 +01:00
|
|
|
size_t anim_sampler_index =
|
|
|
|
anim_graph_blend_tree.GetAnimNodeIndex(anim_sampler_walk);
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
anim_graph_blend_tree.m_node_output_connections[anim_sampler_index].size()
|
|
|
|
== 1);
|
2023-04-01 14:16:20 +02:00
|
|
|
CHECK(
|
2024-03-25 21:10:27 +01:00
|
|
|
anim_graph_blend_tree.m_node_output_connections[anim_sampler_index][0]
|
|
|
|
.m_target_node
|
2023-04-01 14:16:20 +02:00
|
|
|
== graph_output_node);
|
|
|
|
|
|
|
|
// Ensure animation sampler nodes use the correct files
|
2023-04-21 12:39:09 +02:00
|
|
|
REQUIRE(anim_sampler_walk->m_filename == "media/Walking-loop.ozz");
|
2023-04-01 14:16:20 +02:00
|
|
|
REQUIRE(anim_sampler_walk->m_animation != nullptr);
|
|
|
|
|
|
|
|
// Ensure that outputs are properly propagated.
|
|
|
|
AnimData output;
|
|
|
|
output.m_local_matrices.resize(skeleton.num_soa_joints());
|
2024-03-17 22:06:27 +01:00
|
|
|
anim_graph_blend_tree.SetOutput("GraphOutput", &output);
|
2023-04-01 14:16:20 +02:00
|
|
|
REQUIRE(anim_sampler_walk->o_output == &output);
|
|
|
|
|
|
|
|
WHEN("Emulating Graph Evaluation") {
|
2024-03-17 22:06:27 +01:00
|
|
|
CHECK(anim_graph_blend_tree.m_anim_data_allocator.size() == 0);
|
2023-04-01 14:16:20 +02:00
|
|
|
anim_sampler_walk->Evaluate(graph_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
graph_context.freeAnimations();
|
|
|
|
}
|
|
|
|
|
2024-03-17 22:06:27 +01:00
|
|
|
//
|
|
|
|
// Checks that node const inputs are properly set.
|
|
|
|
//
|
2023-04-02 16:26:24 +02:00
|
|
|
TEST_CASE("AnimSamplerSpeedScaleGraph", "[AnimGraphResource]") {
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphResource graph_resource;
|
2023-04-02 16:26:24 +02:00
|
|
|
graph_resource.m_name = "AnimSamplerSpeedScaleGraph";
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_resource.m_graph_type_name = "BlendTree";
|
2024-03-20 22:33:31 +01:00
|
|
|
|
|
|
|
BlendTreeResource& blend_tree_resource = graph_resource.m_blend_tree_resource;
|
|
|
|
blend_tree_resource.Reset();
|
|
|
|
blend_tree_resource.InitGraphConnectors();
|
2023-04-02 16:26:24 +02:00
|
|
|
|
|
|
|
// Prepare graph inputs and outputs
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.m_nodes.push_back(AnimNodeResourceFactory("AnimSampler"));
|
|
|
|
size_t walk_node_index = blend_tree_resource.m_nodes.size() - 1;
|
2023-04-02 16:26:24 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.m_nodes.push_back(AnimNodeResourceFactory("SpeedScale"));
|
|
|
|
size_t speed_scale_node_index = blend_tree_resource.m_nodes.size() - 1;
|
2023-04-02 16:26:24 +02:00
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
AnimNodeResource* walk_node = blend_tree_resource.m_nodes[walk_node_index];
|
|
|
|
walk_node->m_name = "WalkAnim";
|
|
|
|
walk_node->m_socket_accessor->SetPropertyValue(
|
2023-04-02 16:26:24 +02:00
|
|
|
"Filename",
|
2023-04-21 12:39:09 +02:00
|
|
|
std::string("media/Walking-loop.ozz"));
|
2023-04-02 16:26:24 +02:00
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
AnimNodeResource* speed_scale_node =
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.m_nodes[speed_scale_node_index];
|
2024-03-24 21:50:22 +01:00
|
|
|
speed_scale_node->m_name = "SpeedScale";
|
2023-04-02 16:26:24 +02:00
|
|
|
float speed_scale_value = 1.35f;
|
2024-03-24 21:50:22 +01:00
|
|
|
speed_scale_node->m_socket_accessor->SetInputValue(
|
2023-04-02 16:26:24 +02:00
|
|
|
"SpeedScale",
|
|
|
|
speed_scale_value);
|
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
AnimNodeResource* graph_node = blend_tree_resource.GetGraphOutputNode();
|
2024-03-25 21:10:27 +01:00
|
|
|
graph_node->m_socket_accessor->RegisterInput<AnimData>(
|
|
|
|
"GraphOutput",
|
|
|
|
nullptr);
|
2023-04-02 16:26:24 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
blend_tree_resource
|
|
|
|
.ConnectSockets(walk_node, "Output", speed_scale_node, "Input");
|
2023-04-02 16:26:24 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.ConnectSockets(
|
2023-04-02 16:26:24 +02:00
|
|
|
speed_scale_node,
|
|
|
|
"Output",
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.GetGraphOutputNode(),
|
2023-04-02 16:26:24 +02:00
|
|
|
"GraphOutput");
|
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
graph_resource.SaveToFile(
|
|
|
|
"TestGraphAnimSamplerSpeedScaleGraph.animgraph.json");
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphResource graph_resource_loaded;
|
|
|
|
graph_resource_loaded.LoadFromFile(
|
2024-03-24 21:50:22 +01:00
|
|
|
"TestGraphAnimSamplerSpeedScaleGraph.animgraph.json");
|
2023-04-02 16:26:24 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
BlendTreeResource& blend_tree_resource_loaded =
|
|
|
|
graph_resource_loaded.m_blend_tree_resource;
|
2024-03-20 22:33:31 +01:00
|
|
|
|
2023-04-02 16:26:24 +02:00
|
|
|
Socket* speed_scale_resource_loaded_input =
|
2024-03-25 21:10:27 +01:00
|
|
|
blend_tree_resource_loaded.m_nodes[speed_scale_node_index]
|
|
|
|
->m_socket_accessor->GetInputSocket("SpeedScale");
|
2023-04-02 16:26:24 +02:00
|
|
|
REQUIRE(speed_scale_resource_loaded_input != nullptr);
|
|
|
|
|
|
|
|
REQUIRE_THAT(
|
|
|
|
speed_scale_resource_loaded_input->m_value.float_value,
|
|
|
|
Catch::Matchers::WithinAbs(speed_scale_value, 0.1));
|
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphBlendTree blend_tree;
|
|
|
|
graph_resource_loaded.CreateBlendTreeInstance(blend_tree);
|
2023-04-02 16:26:24 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE_THAT(
|
|
|
|
*dynamic_cast<SpeedScaleNode*>(blend_tree.m_nodes[speed_scale_node_index])
|
|
|
|
->i_speed_scale,
|
|
|
|
Catch::Matchers::WithinAbs(speed_scale_value, 0.1));
|
2023-04-02 16:26:24 +02:00
|
|
|
}
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
TEST_CASE_METHOD(
|
|
|
|
Blend2GraphResource,
|
|
|
|
"Blend2GraphResource saving and loading results in same resource",
|
|
|
|
"[Blend2GraphResource]") {
|
|
|
|
graph_resource.SaveToFile("TestGraphBlend2Graph.animgraph.json");
|
2024-03-20 22:33:31 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
AnimGraphResource graph_resource_loaded;
|
|
|
|
graph_resource_loaded.LoadFromFile("TestGraphBlend2Graph.animgraph.json");
|
2024-03-20 22:33:31 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
graph_resource.m_graph_type_name
|
|
|
|
== graph_resource_loaded.m_graph_type_name);
|
|
|
|
REQUIRE(graph_resource.m_name == graph_resource_loaded.m_name);
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
BlendTreeResource* blend_tree_resource_loaded =
|
|
|
|
&graph_resource_loaded.m_blend_tree_resource;
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
blend_tree_resource->m_nodes.size()
|
|
|
|
== blend_tree_resource_loaded->m_nodes.size());
|
|
|
|
for (size_t i = 0; i < blend_tree_resource->m_nodes.size(); i++) {
|
|
|
|
const AnimNodeResource* node = blend_tree_resource->m_nodes[i];
|
|
|
|
const AnimNodeResource* node_loaded =
|
|
|
|
blend_tree_resource_loaded->m_nodes[i];
|
|
|
|
|
|
|
|
REQUIRE(node->m_name == node_loaded->m_name);
|
|
|
|
REQUIRE(node->m_node_type_name == node_loaded->m_node_type_name);
|
|
|
|
}
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
blend_tree_resource->m_connections.size()
|
|
|
|
== blend_tree_resource_loaded->m_connections.size());
|
|
|
|
for (size_t i = 0; i < blend_tree_resource->m_connections.size(); i++) {
|
|
|
|
const BlendTreeConnectionResource& connection =
|
|
|
|
blend_tree_resource->m_connections[i];
|
|
|
|
const BlendTreeConnectionResource& connection_loaded =
|
|
|
|
blend_tree_resource_loaded->m_connections[i];
|
|
|
|
|
|
|
|
REQUIRE(
|
|
|
|
connection.source_node_index == connection_loaded.source_node_index);
|
|
|
|
REQUIRE(
|
|
|
|
connection.source_socket_name == connection_loaded.source_socket_name);
|
|
|
|
REQUIRE(
|
|
|
|
connection.target_node_index == connection_loaded.target_node_index);
|
|
|
|
REQUIRE(
|
|
|
|
connection.target_socket_name == connection_loaded.target_socket_name);
|
|
|
|
}
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
// Check that the constant weight of the Blend2 node was properly applied when
|
|
|
|
// loading the resource.
|
|
|
|
const NodeDescriptor<Blend2Node>* blend2_node_descriptor_loaded =
|
|
|
|
dynamic_cast<NodeDescriptor<Blend2Node>*>(
|
|
|
|
blend_tree_resource_loaded->m_nodes[blend_node_index]
|
|
|
|
->m_socket_accessor);
|
2024-03-20 22:33:31 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE_THAT(
|
|
|
|
blend_node->m_socket_accessor->GetInputValue<float>("Weight"),
|
|
|
|
Catch::Matchers::WithinAbs(
|
|
|
|
blend2_node_descriptor_loaded->GetInputValue<float>("Weight"),
|
|
|
|
0.01));
|
|
|
|
}
|
2022-04-11 16:46:09 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
TEST_CASE_METHOD(
|
|
|
|
Blend2GraphResource,
|
|
|
|
"Blend2GraphResource graph unsynced evaluation",
|
|
|
|
"[Blend2GraphResource]") {
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphBlendTree blend_tree_graph;
|
2024-03-25 21:10:27 +01:00
|
|
|
graph_resource.CreateBlendTreeInstance(blend_tree_graph);
|
2022-04-11 16:46:09 +02:00
|
|
|
AnimGraphContext graph_context;
|
|
|
|
|
|
|
|
ozz::animation::Skeleton skeleton;
|
2023-04-21 12:39:09 +02:00
|
|
|
REQUIRE(load_skeleton(skeleton, "media/skeleton.ozz"));
|
2022-04-11 16:46:09 +02:00
|
|
|
graph_context.m_skeleton = &skeleton;
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_graph.Init(graph_context));
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_graph.m_nodes.size() == 5);
|
2024-03-24 21:50:22 +01:00
|
|
|
REQUIRE(blend_tree_graph.m_nodes[0]->m_node_type_name == "BlendTreeSockets");
|
|
|
|
REQUIRE(blend_tree_graph.m_nodes[1]->m_node_type_name == "BlendTreeSockets");
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_graph.m_nodes[2]->m_node_type_name == "AnimSampler");
|
|
|
|
REQUIRE(blend_tree_graph.m_nodes[3]->m_node_type_name == "AnimSampler");
|
|
|
|
REQUIRE(blend_tree_graph.m_nodes[4]->m_node_type_name == "Blend2");
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2022-02-12 11:46:50 +01:00
|
|
|
// connections within the graph
|
2022-04-01 13:19:54 +02:00
|
|
|
AnimSamplerNode* anim_sampler_walk =
|
2024-03-20 22:33:31 +01:00
|
|
|
dynamic_cast<AnimSamplerNode*>(blend_tree_graph.m_nodes[2]);
|
2022-04-01 13:19:54 +02:00
|
|
|
AnimSamplerNode* anim_sampler_run =
|
2024-03-20 22:33:31 +01:00
|
|
|
dynamic_cast<AnimSamplerNode*>(blend_tree_graph.m_nodes[3]);
|
2024-03-25 21:10:27 +01:00
|
|
|
Blend2Node* blend2_instance =
|
|
|
|
dynamic_cast<Blend2Node*>(blend_tree_graph.m_nodes[4]);
|
2022-02-12 11:46:50 +01:00
|
|
|
|
|
|
|
// check node input dependencies
|
2024-03-25 21:10:27 +01:00
|
|
|
size_t anim_sampler_index0 =
|
|
|
|
blend_tree_graph.GetAnimNodeIndex(anim_sampler_walk);
|
|
|
|
size_t anim_sampler_index1 =
|
|
|
|
blend_tree_graph.GetAnimNodeIndex(anim_sampler_run);
|
2024-03-20 22:33:31 +01:00
|
|
|
size_t blend_index = blend_tree_graph.GetAnimNodeIndex(blend2_instance);
|
2022-02-11 16:51:18 +01:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_graph.m_node_input_connections[blend_index].size() == 2);
|
2022-04-03 21:05:11 +02:00
|
|
|
CHECK(
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_graph.m_node_input_connections[blend_index][0].m_source_node
|
2022-04-03 21:05:11 +02:00
|
|
|
== anim_sampler_walk);
|
|
|
|
CHECK(
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_graph.m_node_input_connections[blend_index][1].m_source_node
|
2022-04-03 21:05:11 +02:00
|
|
|
== anim_sampler_run);
|
2022-04-01 13:19:54 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(
|
2024-03-25 21:10:27 +01:00
|
|
|
blend_tree_graph.m_node_output_connections[anim_sampler_index0].size()
|
|
|
|
== 1);
|
2022-04-03 21:05:11 +02:00
|
|
|
CHECK(
|
2024-03-25 21:10:27 +01:00
|
|
|
blend_tree_graph.m_node_output_connections[anim_sampler_index0][0]
|
|
|
|
.m_target_node
|
2022-04-03 21:05:11 +02:00
|
|
|
== blend2_instance);
|
2022-04-01 13:19:54 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(
|
2024-03-25 21:10:27 +01:00
|
|
|
blend_tree_graph.m_node_output_connections[anim_sampler_index1].size()
|
|
|
|
== 1);
|
2022-04-03 21:05:11 +02:00
|
|
|
CHECK(
|
2024-03-25 21:10:27 +01:00
|
|
|
blend_tree_graph.m_node_output_connections[anim_sampler_index1][0]
|
|
|
|
.m_target_node
|
2022-04-03 21:05:11 +02:00
|
|
|
== blend2_instance);
|
2022-04-01 13:19:54 +02:00
|
|
|
|
2022-04-11 16:46:09 +02:00
|
|
|
// Ensure animation sampler nodes use the correct files
|
2023-04-21 12:39:09 +02:00
|
|
|
REQUIRE(anim_sampler_walk->m_filename == "media/Walking-loop.ozz");
|
2022-04-11 16:46:09 +02:00
|
|
|
REQUIRE(anim_sampler_walk->m_animation != nullptr);
|
|
|
|
|
2023-04-21 12:39:09 +02:00
|
|
|
REQUIRE(anim_sampler_run->m_filename == "media/Running0-loop.ozz");
|
2022-04-11 16:46:09 +02:00
|
|
|
REQUIRE(anim_sampler_run->m_animation != nullptr);
|
|
|
|
|
|
|
|
WHEN("Emulating Graph Evaluation") {
|
2024-03-20 22:33:31 +01:00
|
|
|
CHECK(blend_tree_graph.m_anim_data_allocator.size() == 0);
|
2022-04-11 16:46:09 +02:00
|
|
|
CHECK(blend2_instance->i_input0 == anim_sampler_walk->o_output);
|
|
|
|
CHECK(blend2_instance->i_input1 == anim_sampler_run->o_output);
|
2022-04-13 15:47:43 +02:00
|
|
|
|
2024-04-01 21:18:26 +02:00
|
|
|
AnimData* graph_output = static_cast<AnimData*>(
|
|
|
|
blend_tree_graph.GetOutputPtr<AnimData>("GraphOutput"));
|
2022-04-14 18:03:36 +02:00
|
|
|
|
2023-04-02 16:26:24 +02:00
|
|
|
CHECK(
|
|
|
|
graph_output->m_local_matrices.size()
|
|
|
|
== graph_context.m_skeleton->num_soa_joints());
|
2022-04-14 18:03:36 +02:00
|
|
|
|
2024-04-01 21:18:26 +02:00
|
|
|
CHECK(blend2_instance->o_output == graph_output);
|
2022-04-11 16:46:09 +02:00
|
|
|
}
|
2022-04-13 15:47:43 +02:00
|
|
|
|
|
|
|
graph_context.freeAnimations();
|
2022-02-11 16:51:18 +01:00
|
|
|
}
|
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
//
|
|
|
|
// Graph:
|
|
|
|
// Outputs:
|
|
|
|
// - GraphFloatOutput (float)
|
|
|
|
// - GraphVec3Output (Vec3)
|
|
|
|
//
|
|
|
|
// Inputs:
|
|
|
|
// - GraphFloatInput (float)
|
|
|
|
//
|
|
|
|
// Nodes:
|
|
|
|
// - MathFloatToVec3Node
|
|
|
|
//
|
|
|
|
// Connectivity:
|
|
|
|
// GraphFloatInput -+----------------------> GraphFloatOutput
|
|
|
|
// \-> MathFloatToVec3 --> GraphVec3Output
|
|
|
|
//
|
|
|
|
//
|
2022-04-03 21:05:11 +02:00
|
|
|
TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphResource graph_resource_origin;
|
2022-02-14 22:37:19 +01:00
|
|
|
graph_resource_origin.m_name = "TestInputOutputGraph";
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_resource_origin.m_graph_type_name = "BlendTree";
|
2024-03-20 22:33:31 +01:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
BlendTreeResource& blend_tree_resource =
|
|
|
|
graph_resource_origin.m_blend_tree_resource;
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.Reset();
|
|
|
|
blend_tree_resource.InitGraphConnectors();
|
2022-02-14 22:37:19 +01:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
// Prepare graph inputs and outputs
|
2024-03-25 21:10:27 +01:00
|
|
|
blend_tree_resource.m_nodes.push_back(
|
|
|
|
AnimNodeResourceFactory("MathFloatToVec3Node"));
|
2024-03-20 22:33:31 +01:00
|
|
|
size_t float_to_vec3_node_index = blend_tree_resource.m_nodes.size() - 1;
|
2022-04-03 21:05:11 +02:00
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
AnimNodeResource* graph_output_node =
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.GetGraphOutputNode();
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_output_node->m_socket_accessor->RegisterInput<float>(
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphFloatOutput",
|
2022-02-14 22:37:19 +01:00
|
|
|
nullptr);
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_output_node->m_socket_accessor->RegisterInput<Vec3>(
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphVec3Output",
|
2022-02-14 22:37:19 +01:00
|
|
|
nullptr);
|
2022-04-03 21:05:11 +02:00
|
|
|
|
2024-04-01 21:18:26 +02:00
|
|
|
AnimNodeResource* graph_input_node_resource =
|
|
|
|
blend_tree_resource.GetGraphInputNode();
|
|
|
|
graph_input_node_resource->m_socket_accessor->RegisterOutput<float>(
|
2022-02-14 22:37:19 +01:00
|
|
|
"GraphFloatInput",
|
|
|
|
nullptr);
|
2022-04-03 21:05:11 +02:00
|
|
|
|
|
|
|
// Prepare graph inputs and outputs
|
2024-04-01 21:18:26 +02:00
|
|
|
AnimNodeResource* float_to_vec3_node_resource =
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.m_nodes[float_to_vec3_node_index];
|
2022-04-03 21:05:11 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2024-04-01 21:18:26 +02:00
|
|
|
graph_input_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphFloatInput",
|
|
|
|
graph_output_node,
|
|
|
|
"GraphFloatOutput"));
|
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2024-04-01 21:18:26 +02:00
|
|
|
graph_input_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphFloatInput",
|
2024-04-01 21:18:26 +02:00
|
|
|
float_to_vec3_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"Input0"));
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2024-04-01 21:18:26 +02:00
|
|
|
graph_input_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphFloatInput",
|
2024-04-01 21:18:26 +02:00
|
|
|
float_to_vec3_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"Input1"));
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2024-04-01 21:18:26 +02:00
|
|
|
graph_input_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphFloatInput",
|
2024-04-01 21:18:26 +02:00
|
|
|
float_to_vec3_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"Input2"));
|
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2024-04-01 21:18:26 +02:00
|
|
|
float_to_vec3_node_resource,
|
2022-04-03 21:05:11 +02:00
|
|
|
"Output",
|
|
|
|
graph_output_node,
|
|
|
|
"GraphVec3Output"));
|
|
|
|
|
2022-02-14 22:37:19 +01:00
|
|
|
WHEN("Saving and loading graph resource") {
|
2024-03-24 21:50:22 +01:00
|
|
|
const char* filename = "TestGraphResourceSaveLoadGraphInputs.json";
|
2024-03-20 22:33:31 +01:00
|
|
|
graph_resource_origin.SaveToFile(filename);
|
2022-02-14 22:37:19 +01:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphResource graph_resource_loaded;
|
|
|
|
graph_resource_loaded.LoadFromFile(filename);
|
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
BlendTreeResource& graph_blend_tree_loaded =
|
|
|
|
graph_resource_loaded.m_blend_tree_resource;
|
2022-02-14 22:37:19 +01:00
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
const AnimNodeResource* graph_loaded_output_node =
|
2024-03-20 22:33:31 +01:00
|
|
|
graph_blend_tree_loaded.m_nodes[0];
|
2024-03-24 21:50:22 +01:00
|
|
|
const AnimNodeResource* graph_loaded_input_node =
|
2024-03-20 22:33:31 +01:00
|
|
|
graph_blend_tree_loaded.m_nodes[1];
|
2022-02-14 22:37:19 +01:00
|
|
|
|
|
|
|
THEN("Graph inputs and outputs must be in loaded resource as well.") {
|
|
|
|
REQUIRE(
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_output_node->m_socket_accessor->m_inputs.size()
|
|
|
|
== graph_loaded_output_node->m_socket_accessor->m_inputs.size());
|
2022-02-14 22:37:19 +01:00
|
|
|
|
|
|
|
REQUIRE(
|
2024-04-01 21:18:26 +02:00
|
|
|
graph_input_node_resource->m_socket_accessor->m_outputs.size()
|
2024-03-24 21:50:22 +01:00
|
|
|
== graph_loaded_input_node->m_socket_accessor->m_outputs.size());
|
2022-02-14 22:37:19 +01:00
|
|
|
|
|
|
|
REQUIRE(
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_loaded_input_node->m_socket_accessor->GetOutputSocket(
|
2022-02-14 22:37:19 +01:00
|
|
|
"GraphFloatInput")
|
|
|
|
!= nullptr);
|
|
|
|
|
|
|
|
REQUIRE(
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_loaded_output_node->m_socket_accessor->GetInputSocket(
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphFloatOutput")
|
2022-02-14 22:37:19 +01:00
|
|
|
!= nullptr);
|
|
|
|
REQUIRE(
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_loaded_output_node->m_socket_accessor->GetInputSocket(
|
2022-04-03 21:05:11 +02:00
|
|
|
"GraphVec3Output")
|
2022-02-14 22:37:19 +01:00
|
|
|
!= nullptr);
|
|
|
|
|
2022-04-03 21:05:11 +02:00
|
|
|
WHEN("Instantiating an AnimGraph") {
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphBlendTree blend_tree_node;
|
|
|
|
graph_resource_loaded.CreateBlendTreeInstance(blend_tree_node);
|
2022-03-25 12:05:56 +01:00
|
|
|
|
2023-04-01 14:16:20 +02:00
|
|
|
float graph_float_input = 123.456f;
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_node.SetInput("GraphFloatInput", &graph_float_input);
|
2022-04-03 21:05:11 +02:00
|
|
|
|
2024-04-01 21:18:26 +02:00
|
|
|
MathFloatToVec3Node* float_to_vec3_node =
|
|
|
|
dynamic_cast<MathFloatToVec3Node*>(
|
|
|
|
blend_tree_node.m_nodes[float_to_vec3_node_index]);
|
|
|
|
|
|
|
|
CHECK(float_to_vec3_node->i_input0 == &graph_float_input);
|
|
|
|
CHECK(float_to_vec3_node->i_input1 == &graph_float_input);
|
|
|
|
CHECK(float_to_vec3_node->i_input2 == &graph_float_input);
|
|
|
|
|
2022-04-11 11:40:53 +02:00
|
|
|
AND_WHEN("Evaluating Graph") {
|
2022-04-13 15:47:43 +02:00
|
|
|
AnimGraphContext context;
|
2024-03-20 22:33:31 +01:00
|
|
|
context.m_graph = nullptr;
|
2022-04-11 16:46:09 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_node.Init(context);
|
2023-04-01 14:16:20 +02:00
|
|
|
|
|
|
|
// GraphFloatOutput is directly connected to GraphFloatInput therefore
|
|
|
|
// we need to get the pointer here.
|
2024-03-25 21:10:27 +01:00
|
|
|
float* graph_float_ptr =
|
|
|
|
blend_tree_node.GetOutputPtr<float>("GraphFloatOutput");
|
2023-04-01 14:16:20 +02:00
|
|
|
Vec3 graph_vec3_output;
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_node.SetOutput("GraphVec3Output", &graph_vec3_output);
|
2023-04-01 14:16:20 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_node.UpdateTime(0.f, 0.f);
|
|
|
|
blend_tree_node.Evaluate(context);
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
THEN("output vector components equal the graph input values") {
|
2023-04-01 14:16:20 +02:00
|
|
|
CHECK(graph_float_ptr == &graph_float_input);
|
|
|
|
CHECK(graph_vec3_output.v[0] == graph_float_input);
|
|
|
|
CHECK(graph_vec3_output.v[1] == graph_float_input);
|
|
|
|
CHECK(graph_vec3_output.v[2] == graph_float_input);
|
2022-04-11 11:40:53 +02:00
|
|
|
}
|
2022-04-13 15:47:43 +02:00
|
|
|
|
|
|
|
context.freeAnimations();
|
2022-04-11 11:40:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-01 21:18:26 +02:00
|
|
|
//
|
|
|
|
// Graph:
|
|
|
|
// Input: float GraphFloatInputSingle
|
|
|
|
// Output: float GraphFloat0Output
|
|
|
|
// float GraphFloat1Output
|
|
|
|
// float GraphFloat1Output
|
|
|
|
// Nodes: 2x Add Node
|
|
|
|
// Connections:
|
|
|
|
// - Direct GraphFloatInputSingle to GraphFQloat0Output
|
|
|
|
// - Remaining wires such that
|
|
|
|
// GraphFloat1Output -> GraphFLoatInputSingle * 2
|
|
|
|
// GraphFloat1Output -> GraphFLoatInputSingle * 3
|
|
|
|
//
|
2022-04-11 11:40:53 +02:00
|
|
|
TEST_CASE("SimpleMathEvaluations", "[AnimGraphResource]") {
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphResource graph_resource_origin;
|
|
|
|
graph_resource_origin.m_name = "TestSimpleMathGraph";
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_resource_origin.m_graph_type_name = "BlendTree";
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
BlendTreeResource& blend_tree_resource =
|
|
|
|
graph_resource_origin.m_blend_tree_resource;
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.Reset();
|
|
|
|
blend_tree_resource.InitGraphConnectors();
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
// Prepare graph inputs and outputs
|
|
|
|
blend_tree_resource.m_nodes.push_back(AnimNodeResourceFactory("MathAddNode"));
|
|
|
|
size_t math_add0_node_index = blend_tree_resource.m_nodes.size() - 1;
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.m_nodes.push_back(AnimNodeResourceFactory("MathAddNode"));
|
|
|
|
size_t math_add1_node_index = blend_tree_resource.m_nodes.size() - 1;
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
AnimNodeResource* graph_output_node =
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.GetGraphOutputNode();
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_output_node->m_socket_accessor->RegisterInput<float>(
|
2022-04-11 11:40:53 +02:00
|
|
|
"GraphFloat0Output",
|
|
|
|
nullptr);
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_output_node->m_socket_accessor->RegisterInput<float>(
|
2022-04-11 11:40:53 +02:00
|
|
|
"GraphFloat1Output",
|
|
|
|
nullptr);
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_output_node->m_socket_accessor->RegisterInput<float>(
|
2022-04-11 11:40:53 +02:00
|
|
|
"GraphFloat2Output",
|
|
|
|
nullptr);
|
|
|
|
|
2024-03-25 21:10:27 +01:00
|
|
|
AnimNodeResource* graph_input_node = blend_tree_resource.GetGraphInputNode();
|
2024-03-24 21:50:22 +01:00
|
|
|
graph_input_node->m_socket_accessor->RegisterOutput<float>(
|
2022-04-11 11:40:53 +02:00
|
|
|
"GraphFloatInput",
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
// Prepare graph inputs and outputs
|
2024-03-24 21:50:22 +01:00
|
|
|
AnimNodeResource* math_add0_node =
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.m_nodes[math_add0_node_index];
|
2024-03-24 21:50:22 +01:00
|
|
|
AnimNodeResource* math_add1_node =
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree_resource.m_nodes[math_add1_node_index];
|
2022-04-11 11:40:53 +02:00
|
|
|
|
|
|
|
// direct output
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2022-04-11 11:40:53 +02:00
|
|
|
graph_input_node,
|
|
|
|
"GraphFloatInput",
|
|
|
|
graph_output_node,
|
|
|
|
"GraphFloat0Output"));
|
|
|
|
|
|
|
|
// add0 node
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2022-04-11 11:40:53 +02:00
|
|
|
graph_input_node,
|
|
|
|
"GraphFloatInput",
|
|
|
|
math_add0_node,
|
|
|
|
"Input0"));
|
2022-04-03 21:05:11 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2022-04-11 11:40:53 +02:00
|
|
|
graph_input_node,
|
|
|
|
"GraphFloatInput",
|
|
|
|
math_add0_node,
|
|
|
|
"Input1"));
|
2022-02-14 22:37:19 +01:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2022-04-11 11:40:53 +02:00
|
|
|
math_add0_node,
|
|
|
|
"Output",
|
|
|
|
graph_output_node,
|
|
|
|
"GraphFloat1Output"));
|
|
|
|
|
|
|
|
// add1 node
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2022-04-11 11:40:53 +02:00
|
|
|
math_add0_node,
|
|
|
|
"Output",
|
|
|
|
math_add1_node,
|
|
|
|
"Input0"));
|
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2022-04-11 11:40:53 +02:00
|
|
|
graph_input_node,
|
|
|
|
"GraphFloatInput",
|
|
|
|
math_add1_node,
|
|
|
|
"Input1"));
|
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
REQUIRE(blend_tree_resource.ConnectSockets(
|
2022-04-11 11:40:53 +02:00
|
|
|
math_add1_node,
|
|
|
|
"Output",
|
|
|
|
graph_output_node,
|
|
|
|
"GraphFloat2Output"));
|
|
|
|
|
|
|
|
WHEN("Saving and loading graph resource") {
|
2024-03-24 21:50:22 +01:00
|
|
|
const char* filename = "TestGraphResourceSaveLoadGraphInputs.json";
|
2024-03-20 22:33:31 +01:00
|
|
|
graph_resource_origin.SaveToFile(filename);
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphResource graph_resource_loaded;
|
|
|
|
graph_resource_loaded.LoadFromFile(filename);
|
2022-04-11 11:40:53 +02:00
|
|
|
|
|
|
|
WHEN("Instantiating an AnimGraph") {
|
2024-03-20 22:33:31 +01:00
|
|
|
AnimGraphBlendTree blend_tree;
|
|
|
|
graph_resource_loaded.CreateBlendTreeInstance(blend_tree);
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2023-04-01 14:16:20 +02:00
|
|
|
float graph_float_input = 123.456f;
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree.SetInput("GraphFloatInput", &graph_float_input);
|
2022-04-11 11:40:53 +02:00
|
|
|
|
|
|
|
AND_WHEN("Evaluating Graph") {
|
2022-04-13 15:47:43 +02:00
|
|
|
AnimGraphContext context;
|
2024-03-20 22:33:31 +01:00
|
|
|
context.m_graph = nullptr;
|
2022-04-11 16:46:09 +02:00
|
|
|
|
2024-04-01 21:18:26 +02:00
|
|
|
float float1_output = -1.f;
|
|
|
|
float float2_output = -1.f;
|
|
|
|
|
2023-04-01 14:16:20 +02:00
|
|
|
// float0 output is directly connected to the graph input, therefore
|
|
|
|
// we have to get a ptr to the input data here.
|
2024-03-25 21:10:27 +01:00
|
|
|
float* float0_output_ptr =
|
|
|
|
blend_tree.GetOutputPtr<float>("GraphFloat0Output");
|
2022-04-03 21:05:11 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree.SetOutput("GraphFloat1Output", &float1_output);
|
|
|
|
blend_tree.SetOutput("GraphFloat2Output", &float2_output);
|
2022-04-11 11:40:53 +02:00
|
|
|
|
2024-03-20 22:33:31 +01:00
|
|
|
blend_tree.UpdateTime(0.f, 0.f);
|
|
|
|
blend_tree.Evaluate(context);
|
2022-04-11 11:40:53 +02:00
|
|
|
|
|
|
|
THEN("output vector components equal the graph input vaulues") {
|
2024-04-01 21:18:26 +02:00
|
|
|
CHECK(float0_output_ptr == &graph_float_input);
|
2023-04-01 14:16:20 +02:00
|
|
|
CHECK(float1_output == Approx(graph_float_input * 2.f));
|
2023-04-02 16:26:24 +02:00
|
|
|
REQUIRE_THAT(
|
|
|
|
float2_output,
|
|
|
|
Catch::Matchers::WithinAbs(graph_float_input * 3.f, 10));
|
2022-04-11 11:40:53 +02:00
|
|
|
}
|
2022-04-13 15:47:43 +02:00
|
|
|
|
|
|
|
context.freeAnimations();
|
2022-04-03 21:05:11 +02:00
|
|
|
}
|
2022-02-14 22:37:19 +01:00
|
|
|
}
|
|
|
|
}
|
2024-03-24 21:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tests whether BlendTree within a BlendTree can be saved and loaded
|
|
|
|
//
|
|
|
|
// +-----------Parent BlendTree-------------+
|
|
|
|
// | |
|
|
|
|
// | +-----Embd Btree---+ |
|
|
|
|
// | AnmSmpl--+-\ | |
|
|
|
|
// | | \-SpdScale------+--Out |
|
|
|
|
// | |------------------+ |
|
|
|
|
// | |
|
|
|
|
// +----------------------------------------+
|
|
|
|
//
|
2024-03-25 21:10:27 +01:00
|
|
|
TEST_CASE_METHOD(
|
|
|
|
EmbeddedBlendTreeGraphResource,
|
|
|
|
"EmbeddedBlendTreeGraphResource saving and loading results in same "
|
|
|
|
"resource",
|
|
|
|
"[EmbeddedBlendTreeGraphResource]") {
|
|
|
|
parent_graph_resource.SaveToFile("TestGraphEmbeddedBlendTree.json");
|
2024-03-24 21:50:22 +01:00
|
|
|
|
|
|
|
AnimGraphResource parent_graph_resource_loaded;
|
2024-03-25 21:10:27 +01:00
|
|
|
parent_graph_resource_loaded.LoadFromFile("TestGraphEmbeddedBlendTree.json");
|
2024-03-24 21:50:22 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Check the loaded parent graph
|
|
|
|
//
|
|
|
|
CHECK(parent_graph_resource.m_name == parent_graph_resource_loaded.m_name);
|
2024-03-25 21:10:27 +01:00
|
|
|
CHECK(
|
|
|
|
parent_graph_resource.m_graph_type_name
|
|
|
|
== parent_graph_resource_loaded.m_graph_type_name);
|
|
|
|
CHECK(
|
|
|
|
parent_graph_resource.m_node_type_name
|
2024-03-24 21:50:22 +01:00
|
|
|
== parent_graph_resource_loaded.m_node_type_name);
|
2024-03-25 21:10:27 +01:00
|
|
|
|
|
|
|
const BlendTreeResource& parent_blend_tree_resource_loaded =
|
|
|
|
parent_graph_resource_loaded.m_blend_tree_resource;
|
|
|
|
|
|
|
|
CHECK(
|
|
|
|
parent_blend_tree_resource->m_nodes.size()
|
|
|
|
== parent_blend_tree_resource_loaded.m_nodes.size());
|
|
|
|
for (size_t i = 0; i < parent_blend_tree_resource->m_nodes.size(); i++) {
|
2024-04-01 12:33:23 +02:00
|
|
|
const AnimNodeResource* parent_node =
|
|
|
|
parent_blend_tree_resource->m_nodes[i];
|
2024-03-25 21:10:27 +01:00
|
|
|
const AnimNodeResource* parent_node_loaded =
|
|
|
|
parent_blend_tree_resource_loaded.m_nodes[i];
|
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
CHECK(parent_node->m_name == parent_node_loaded->m_name);
|
2024-03-25 21:10:27 +01:00
|
|
|
CHECK(
|
|
|
|
parent_node->m_node_type_name == parent_node_loaded->m_node_type_name);
|
2024-03-24 21:50:22 +01:00
|
|
|
}
|
2024-03-25 21:10:27 +01:00
|
|
|
|
|
|
|
CHECK(
|
|
|
|
parent_blend_tree_resource->m_connections.size()
|
|
|
|
== parent_blend_tree_resource_loaded.m_connections.size());
|
2024-04-01 12:33:23 +02:00
|
|
|
for (size_t i = 0; i < parent_blend_tree_resource->m_connections.size();
|
|
|
|
i++) {
|
2024-03-25 21:10:27 +01:00
|
|
|
const BlendTreeConnectionResource& parent_connection =
|
|
|
|
parent_blend_tree_resource->m_connections[i];
|
|
|
|
const BlendTreeConnectionResource& parent_connection_loaded =
|
|
|
|
parent_blend_tree_resource_loaded.m_connections[i];
|
|
|
|
|
|
|
|
CHECK(
|
|
|
|
parent_connection.source_node_index
|
|
|
|
== parent_connection_loaded.source_node_index);
|
|
|
|
CHECK(
|
|
|
|
parent_connection.source_socket_name
|
|
|
|
== parent_connection_loaded.source_socket_name);
|
|
|
|
CHECK(
|
|
|
|
parent_connection.target_node_index
|
|
|
|
== parent_connection_loaded.target_node_index);
|
|
|
|
CHECK(
|
|
|
|
parent_connection.target_socket_name
|
|
|
|
== parent_connection_loaded.target_socket_name);
|
2024-03-24 21:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check the loaded embedded graph
|
|
|
|
//
|
2024-03-25 21:10:27 +01:00
|
|
|
REQUIRE(
|
|
|
|
parent_blend_tree_resource_loaded.m_nodes[3]->m_node_type_name
|
|
|
|
== "BlendTree");
|
|
|
|
|
|
|
|
const AnimGraphResource* embedded_graph_loaded =
|
|
|
|
dynamic_cast<AnimGraphResource*>(
|
|
|
|
parent_blend_tree_resource_loaded.m_nodes[3]);
|
|
|
|
const BlendTreeResource& embedded_blend_tree_resource_loaded =
|
|
|
|
embedded_graph_loaded->m_blend_tree_resource;
|
|
|
|
|
|
|
|
CHECK(
|
|
|
|
embedded_blend_tree_resource->m_nodes.size()
|
|
|
|
== embedded_blend_tree_resource_loaded.m_nodes.size());
|
|
|
|
CHECK(
|
|
|
|
embedded_blend_tree_resource->m_connections.size()
|
|
|
|
== embedded_blend_tree_resource_loaded.m_connections.size());
|
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
for (size_t i = 0; i < embedded_blend_tree_resource->m_nodes.size(); i++) {
|
2024-03-25 21:10:27 +01:00
|
|
|
const AnimNodeResource* parent_node =
|
|
|
|
embedded_blend_tree_resource->m_nodes[i];
|
|
|
|
const AnimNodeResource* parent_node_loaded =
|
|
|
|
embedded_blend_tree_resource_loaded.m_nodes[i];
|
|
|
|
|
2024-03-24 21:50:22 +01:00
|
|
|
CHECK(parent_node->m_name == parent_node_loaded->m_name);
|
2024-03-25 21:10:27 +01:00
|
|
|
CHECK(
|
|
|
|
parent_node->m_node_type_name == parent_node_loaded->m_node_type_name);
|
2024-03-24 21:50:22 +01:00
|
|
|
}
|
2024-03-25 21:10:27 +01:00
|
|
|
|
|
|
|
CHECK(
|
|
|
|
embedded_blend_tree_resource->m_connections.size()
|
|
|
|
== embedded_blend_tree_resource_loaded.m_connections.size());
|
|
|
|
for (size_t i = 0; i < embedded_blend_tree_resource->m_connections.size();
|
|
|
|
i++) {
|
|
|
|
const BlendTreeConnectionResource& embedded_connection =
|
|
|
|
embedded_blend_tree_resource->m_connections[i];
|
|
|
|
const BlendTreeConnectionResource& embedded_connection_loaded =
|
|
|
|
embedded_blend_tree_resource_loaded.m_connections[i];
|
|
|
|
|
|
|
|
CHECK(
|
|
|
|
embedded_connection.source_node_index
|
|
|
|
== embedded_connection_loaded.source_node_index);
|
|
|
|
CHECK(
|
|
|
|
embedded_connection.source_socket_name
|
|
|
|
== embedded_connection_loaded.source_socket_name);
|
|
|
|
CHECK(
|
|
|
|
embedded_connection.target_node_index
|
|
|
|
== embedded_connection_loaded.target_node_index);
|
|
|
|
CHECK(
|
|
|
|
embedded_connection.target_socket_name
|
|
|
|
== embedded_connection_loaded.target_socket_name);
|
2024-03-24 21:50:22 +01:00
|
|
|
}
|
2024-03-25 22:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(
|
|
|
|
EmbeddedBlendTreeGraphResource,
|
|
|
|
"EmbeddedBlendTreeGraphResource instantiation",
|
|
|
|
"[EmbeddedBlendTreeGraphResource]") {
|
|
|
|
AnimGraphBlendTree blend_tree;
|
|
|
|
|
|
|
|
parent_graph_resource.CreateBlendTreeInstance(blend_tree);
|
|
|
|
AnimGraphContext graph_context;
|
|
|
|
|
|
|
|
ozz::animation::Skeleton skeleton;
|
|
|
|
REQUIRE(load_skeleton(skeleton, "media/skeleton.ozz"));
|
|
|
|
graph_context.m_skeleton = &skeleton;
|
|
|
|
|
|
|
|
blend_tree.Init(graph_context);
|
2024-04-01 12:33:23 +02:00
|
|
|
|
|
|
|
const AnimSamplerNode* walk_node =
|
|
|
|
dynamic_cast<AnimSamplerNode*>(blend_tree.m_nodes[walk_node_index]);
|
|
|
|
const AnimGraphBlendTree* embedded_blend_tree_node =
|
|
|
|
dynamic_cast<AnimGraphBlendTree*>(
|
|
|
|
blend_tree.m_nodes[embedded_blend_tree_node_index]);
|
|
|
|
const SpeedScaleNode* speed_scale_node = dynamic_cast<SpeedScaleNode*>(
|
2024-04-01 17:59:25 +02:00
|
|
|
embedded_blend_tree_node->m_nodes[embedded_speed_scale_index]);
|
2024-04-01 12:33:23 +02:00
|
|
|
|
|
|
|
blend_tree.StartUpdateTick();
|
|
|
|
blend_tree.MarkActiveInputs(std::vector<AnimGraphConnection>());
|
|
|
|
REQUIRE(embedded_blend_tree_node->m_state == AnimNodeEvalState::Activated);
|
|
|
|
REQUIRE(speed_scale_node->m_state == AnimNodeEvalState::Activated);
|
|
|
|
REQUIRE(walk_node->m_state == AnimNodeEvalState::Activated);
|
|
|
|
|
|
|
|
float time_last = 0.f;
|
|
|
|
float dt = 0.1f;
|
|
|
|
blend_tree.UpdateTime(time_last, time_last + dt);
|
|
|
|
CHECK(embedded_blend_tree_node->m_state == AnimNodeEvalState::TimeUpdated);
|
|
|
|
CHECK(speed_scale_node->m_state == AnimNodeEvalState::TimeUpdated);
|
|
|
|
CHECK(walk_node->m_state == AnimNodeEvalState::TimeUpdated);
|
|
|
|
|
|
|
|
CHECK_THAT(
|
|
|
|
walk_node->m_time_last,
|
|
|
|
Catch::Matchers::WithinAbs(time_last, 0.001));
|
|
|
|
CHECK_THAT(
|
|
|
|
walk_node->m_time_now,
|
|
|
|
Catch::Matchers::WithinAbs(
|
|
|
|
time_last + dt * (*speed_scale_node->i_speed_scale),
|
|
|
|
0.001));
|
|
|
|
|
2024-03-25 22:26:29 +01:00
|
|
|
blend_tree.Evaluate(graph_context);
|
|
|
|
|
2024-04-01 12:33:23 +02:00
|
|
|
WHEN("Updating the time a second time") {
|
|
|
|
// Perform another update
|
|
|
|
time_last = time_last + dt;
|
|
|
|
dt = 0.3f;
|
|
|
|
blend_tree.StartUpdateTick();
|
|
|
|
blend_tree.MarkActiveInputs(std::vector<AnimGraphConnection>());
|
|
|
|
blend_tree.UpdateTime(time_last, time_last + dt);
|
|
|
|
CHECK(embedded_blend_tree_node->m_state == AnimNodeEvalState::TimeUpdated);
|
|
|
|
CHECK(speed_scale_node->m_state == AnimNodeEvalState::TimeUpdated);
|
|
|
|
CHECK(walk_node->m_state == AnimNodeEvalState::TimeUpdated);
|
|
|
|
|
|
|
|
CHECK_THAT(
|
|
|
|
walk_node->m_time_last,
|
|
|
|
Catch::Matchers::WithinAbs(
|
|
|
|
time_last * (*speed_scale_node->i_speed_scale),
|
|
|
|
0.001));
|
|
|
|
CHECK_THAT(
|
|
|
|
walk_node->m_time_now,
|
|
|
|
Catch::Matchers::WithinAbs(
|
|
|
|
(time_last + dt) * (*speed_scale_node->i_speed_scale),
|
|
|
|
0.001));
|
|
|
|
}
|
|
|
|
|
2024-04-01 17:59:25 +02:00
|
|
|
graph_context.freeAnimations();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here we check two things:
|
|
|
|
// 1. That nodes of the parent get properly activated by an embedded node.
|
|
|
|
// 2. That output sockets of nodes in the parent graph can properly be
|
|
|
|
// connected to inputs of an embedded node.
|
|
|
|
TEST_CASE_METHOD(
|
|
|
|
EmbeddedTreeBlend2GraphResource,
|
|
|
|
"EmbeddedTreeBlend2GraphResource instantiation",
|
|
|
|
"[EmbeddedTreeBlend2GraphResource]") {
|
|
|
|
AnimGraphBlendTree blend_tree;
|
|
|
|
|
|
|
|
parent_graph_resource.CreateBlendTreeInstance(blend_tree);
|
|
|
|
AnimGraphContext graph_context;
|
|
|
|
|
|
|
|
ozz::animation::Skeleton skeleton;
|
|
|
|
REQUIRE(load_skeleton(skeleton, "media/skeleton.ozz"));
|
|
|
|
graph_context.m_skeleton = &skeleton;
|
|
|
|
|
|
|
|
blend_tree.Init(graph_context);
|
|
|
|
const AnimSamplerNode* walk_node =
|
|
|
|
dynamic_cast<AnimSamplerNode*>(blend_tree.m_nodes[walk_node_index]);
|
|
|
|
AnimGraphBlendTree* embedded_blend_tree_node =
|
|
|
|
dynamic_cast<AnimGraphBlendTree*>(
|
|
|
|
blend_tree.m_nodes[embedded_blend_tree_node_index]);
|
|
|
|
const Blend2Node* embedded_blend2_node = dynamic_cast<Blend2Node*>(
|
|
|
|
embedded_blend_tree_node->m_nodes[embedded_blend2_node_index]);
|
|
|
|
const AnimSamplerNode* embedded_run_node = dynamic_cast<AnimSamplerNode*>(
|
|
|
|
embedded_blend_tree_node->m_nodes[embedded_run_node_index]);
|
|
|
|
|
|
|
|
REQUIRE(walk_node != nullptr);
|
|
|
|
REQUIRE(embedded_blend2_node != nullptr);
|
|
|
|
REQUIRE(embedded_run_node != nullptr);
|
|
|
|
|
|
|
|
WHEN("Setting blend2 weight within EmbeddedBlendTree") {
|
|
|
|
float embedded_blend2_weight = 0.2f;
|
|
|
|
embedded_blend_tree_node->SetInput<float>(
|
|
|
|
"BlendWeight",
|
|
|
|
&embedded_blend2_weight);
|
|
|
|
CHECK_THAT(
|
|
|
|
*embedded_blend2_node->i_blend_weight,
|
|
|
|
Catch::Matchers::WithinAbs(embedded_blend2_weight, 0.001));
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Setting blend2 weight on the parent BlendTree") {
|
|
|
|
float parent_blend2_weight = 0.4f;
|
|
|
|
blend_tree.SetInput<float>("EmbeddedBlend2Weight", &parent_blend2_weight);
|
|
|
|
|
|
|
|
THEN(
|
|
|
|
"the embedded blend2 weights points to the address specified in the "
|
|
|
|
"parent tree.") {
|
|
|
|
CHECK(embedded_blend2_node->i_blend_weight == &parent_blend2_weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Setting the blend weight to 0 and marking inputs as active") {
|
|
|
|
parent_blend2_weight = 0.f;
|
|
|
|
blend_tree.StartUpdateTick();
|
|
|
|
blend_tree.MarkActiveInputs(std::vector<AnimGraphConnection>());
|
|
|
|
THEN(
|
|
|
|
"parent AnimSampler is active and embedded AnimSampler is inactive") {
|
|
|
|
CHECK(walk_node->m_state == AnimNodeEvalState::Activated);
|
|
|
|
CHECK(embedded_run_node->m_state == AnimNodeEvalState::Deactivated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Setting the blend weight to 1 and marking inputs as active") {
|
|
|
|
parent_blend2_weight = 1.f;
|
|
|
|
blend_tree.StartUpdateTick();
|
|
|
|
blend_tree.MarkActiveInputs(std::vector<AnimGraphConnection>());
|
|
|
|
THEN(
|
|
|
|
"parent AnimSampler is inactive and embedded AnimSampler is active") {
|
|
|
|
CHECK(walk_node->m_state == AnimNodeEvalState::Deactivated);
|
|
|
|
CHECK(embedded_run_node->m_state == AnimNodeEvalState::Activated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Setting the blend weight to 0.3 and marking inputs as active") {
|
|
|
|
parent_blend2_weight = 0.3f;
|
|
|
|
blend_tree.StartUpdateTick();
|
|
|
|
blend_tree.MarkActiveInputs(std::vector<AnimGraphConnection>());
|
|
|
|
THEN("both parent AnimSampler and embedded AnimSampler are active") {
|
|
|
|
CHECK(walk_node->m_state == AnimNodeEvalState::Activated);
|
|
|
|
CHECK(embedded_run_node->m_state == AnimNodeEvalState::Activated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-25 22:26:29 +01:00
|
|
|
graph_context.freeAnimations();
|
2024-03-20 22:33:31 +01:00
|
|
|
}
|