Added Tests for MathAdd Node
parent
e7314e3477
commit
bf0c7a7daa
|
@ -223,6 +223,8 @@ void AnimGraph::evaluate() {
|
||||||
|
|
||||||
finishNodeEval(node->m_index);
|
finishNodeEval(node->m_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evalOutputNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket* AnimGraph::getInputSocket(const std::string& name) {
|
Socket* AnimGraph::getInputSocket(const std::string& name) {
|
||||||
|
|
|
@ -150,8 +150,8 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
||||||
graph_resource_origin.clear();
|
graph_resource_origin.clear();
|
||||||
graph_resource_origin.m_name = "TestInputOutputGraph";
|
graph_resource_origin.m_name = "TestInputOutputGraph";
|
||||||
|
|
||||||
size_t float_to_vec3_node_index =
|
size_t float_to_vec3_node_index = graph_resource_origin.addNode(
|
||||||
graph_resource_origin.addNode(AnimNodeResourceFactory("MathFloatToVec3Node"));
|
AnimNodeResourceFactory("MathFloatToVec3Node"));
|
||||||
|
|
||||||
AnimNodeResource& graph_output_node =
|
AnimNodeResource& graph_output_node =
|
||||||
graph_resource_origin.getGraphOutputNode();
|
graph_resource_origin.getGraphOutputNode();
|
||||||
|
@ -200,7 +200,6 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
||||||
graph_output_node,
|
graph_output_node,
|
||||||
"GraphVec3Output"));
|
"GraphVec3Output"));
|
||||||
|
|
||||||
|
|
||||||
WHEN("Saving and loading graph resource") {
|
WHEN("Saving and loading graph resource") {
|
||||||
const char* filename = "ResourceSaveLoadGraphInputs.json";
|
const char* filename = "ResourceSaveLoadGraphInputs.json";
|
||||||
graph_resource_origin.saveToFile(filename);
|
graph_resource_origin.saveToFile(filename);
|
||||||
|
@ -240,22 +239,28 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
||||||
AnimGraph anim_graph = graph_resource_loaded.createInstance();
|
AnimGraph anim_graph = graph_resource_loaded.createInstance();
|
||||||
|
|
||||||
REQUIRE(anim_graph.getInputSocket("GraphFloatInput") != nullptr);
|
REQUIRE(anim_graph.getInputSocket("GraphFloatInput") != nullptr);
|
||||||
REQUIRE(anim_graph.getInputPtr("GraphFloatInput") == anim_graph.m_input_buffer);
|
REQUIRE(
|
||||||
|
anim_graph.getInputPtr("GraphFloatInput")
|
||||||
|
== anim_graph.m_input_buffer);
|
||||||
|
|
||||||
float* graph_float_input = nullptr;
|
float* graph_float_input = nullptr;
|
||||||
graph_float_input = static_cast<float*>(anim_graph.getInputPtr("GraphFloatInput"));
|
graph_float_input =
|
||||||
|
static_cast<float*>(anim_graph.getInputPtr("GraphFloatInput"));
|
||||||
|
|
||||||
*graph_float_input = 123.456f;
|
*graph_float_input = 123.456f;
|
||||||
|
|
||||||
|
AND_WHEN("Evaluating Graph") {
|
||||||
anim_graph.updateTime(0.f);
|
anim_graph.updateTime(0.f);
|
||||||
anim_graph.evaluate();
|
anim_graph.evaluate();
|
||||||
|
|
||||||
anim_graph.evalOutputNode();
|
Socket* float_output_socket =
|
||||||
|
anim_graph.getOutputSocket("GraphFloatOutput");
|
||||||
Socket* float_output_socket = anim_graph.getOutputSocket("GraphFloatOutput");
|
Socket* vec3_output_socket =
|
||||||
Socket* vec3_output_socket = anim_graph.getOutputSocket("GraphVec3Output");
|
anim_graph.getOutputSocket("GraphVec3Output");
|
||||||
Vec3& vec3_output = *static_cast<Vec3*>(vec3_output_socket->m_value.ptr);
|
Vec3& vec3_output =
|
||||||
|
*static_cast<Vec3*>(vec3_output_socket->m_value.ptr);
|
||||||
|
|
||||||
|
THEN("output vector components equal the graph input vaulues") {
|
||||||
CHECK(vec3_output[0] == *graph_float_input);
|
CHECK(vec3_output[0] == *graph_float_input);
|
||||||
CHECK(vec3_output[1] == *graph_float_input);
|
CHECK(vec3_output[1] == *graph_float_input);
|
||||||
CHECK(vec3_output[2] == *graph_float_input);
|
CHECK(vec3_output[2] == *graph_float_input);
|
||||||
|
@ -263,6 +268,145 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("SimpleMathEvaluations", "[AnimGraphResource]") {
|
||||||
|
AnimGraphResource graph_resource_origin;
|
||||||
|
|
||||||
|
graph_resource_origin.clear();
|
||||||
|
graph_resource_origin.m_name = "TestInputOutputGraph";
|
||||||
|
|
||||||
|
size_t math_add0_node_index =
|
||||||
|
graph_resource_origin.addNode(AnimNodeResourceFactory("MathAddNode"));
|
||||||
|
|
||||||
|
size_t math_add1_node_index =
|
||||||
|
graph_resource_origin.addNode(AnimNodeResourceFactory("MathAddNode"));
|
||||||
|
|
||||||
|
AnimNodeResource& graph_output_node =
|
||||||
|
graph_resource_origin.getGraphOutputNode();
|
||||||
|
|
||||||
|
graph_output_node.m_socket_accessor->RegisterInput<float>(
|
||||||
|
"GraphFloat0Output",
|
||||||
|
nullptr);
|
||||||
|
graph_output_node.m_socket_accessor->RegisterInput<float>(
|
||||||
|
"GraphFloat1Output",
|
||||||
|
nullptr);
|
||||||
|
graph_output_node.m_socket_accessor->RegisterInput<float>(
|
||||||
|
"GraphFloat2Output",
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
AnimNodeResource& graph_input_node =
|
||||||
|
graph_resource_origin.getGraphInputNode();
|
||||||
|
graph_input_node.m_socket_accessor->RegisterOutput<float>(
|
||||||
|
"GraphFloatInput",
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
// Prepare graph inputs and outputs
|
||||||
|
AnimNodeResource& math_add0_node =
|
||||||
|
graph_resource_origin.m_nodes[math_add0_node_index];
|
||||||
|
AnimNodeResource& math_add1_node =
|
||||||
|
graph_resource_origin.m_nodes[math_add1_node_index];
|
||||||
|
|
||||||
|
// direct output
|
||||||
|
REQUIRE(graph_resource_origin.connectSockets(
|
||||||
|
graph_input_node,
|
||||||
|
"GraphFloatInput",
|
||||||
|
graph_output_node,
|
||||||
|
"GraphFloat0Output"));
|
||||||
|
|
||||||
|
// add0 node
|
||||||
|
REQUIRE(graph_resource_origin.connectSockets(
|
||||||
|
graph_input_node,
|
||||||
|
"GraphFloatInput",
|
||||||
|
math_add0_node,
|
||||||
|
"Input0"));
|
||||||
|
|
||||||
|
REQUIRE(graph_resource_origin.connectSockets(
|
||||||
|
graph_input_node,
|
||||||
|
"GraphFloatInput",
|
||||||
|
math_add0_node,
|
||||||
|
"Input1"));
|
||||||
|
|
||||||
|
REQUIRE(graph_resource_origin.connectSockets(
|
||||||
|
math_add0_node,
|
||||||
|
"Output",
|
||||||
|
graph_output_node,
|
||||||
|
"GraphFloat1Output"));
|
||||||
|
|
||||||
|
// add1 node
|
||||||
|
REQUIRE(graph_resource_origin.connectSockets(
|
||||||
|
math_add0_node,
|
||||||
|
"Output",
|
||||||
|
math_add1_node,
|
||||||
|
"Input0"));
|
||||||
|
|
||||||
|
REQUIRE(graph_resource_origin.connectSockets(
|
||||||
|
graph_input_node,
|
||||||
|
"GraphFloatInput",
|
||||||
|
math_add1_node,
|
||||||
|
"Input1"));
|
||||||
|
|
||||||
|
REQUIRE(graph_resource_origin.connectSockets(
|
||||||
|
math_add1_node,
|
||||||
|
"Output",
|
||||||
|
graph_output_node,
|
||||||
|
"GraphFloat2Output"));
|
||||||
|
|
||||||
|
WHEN("Saving and loading graph resource") {
|
||||||
|
const char* filename = "ResourceSaveLoadGraphInputs.json";
|
||||||
|
graph_resource_origin.saveToFile(filename);
|
||||||
|
|
||||||
|
AnimGraphResource graph_resource_loaded;
|
||||||
|
graph_resource_loaded.loadFromFile(filename);
|
||||||
|
|
||||||
|
const AnimNodeResource& graph_loaded_output_node =
|
||||||
|
graph_resource_loaded.m_nodes[0];
|
||||||
|
const AnimNodeResource& graph_loaded_input_node =
|
||||||
|
graph_resource_loaded.m_nodes[1];
|
||||||
|
|
||||||
|
WHEN("Instantiating an AnimGraph") {
|
||||||
|
AnimGraph anim_graph = graph_resource_loaded.createInstance();
|
||||||
|
|
||||||
|
REQUIRE(anim_graph.getInputSocket("GraphFloatInput") != nullptr);
|
||||||
|
REQUIRE(
|
||||||
|
anim_graph.getInputPtr("GraphFloatInput")
|
||||||
|
== anim_graph.m_input_buffer);
|
||||||
|
|
||||||
|
float* graph_float_input = nullptr;
|
||||||
|
graph_float_input =
|
||||||
|
static_cast<float*>(anim_graph.getInputPtr("GraphFloatInput"));
|
||||||
|
|
||||||
|
*graph_float_input = 123.456f;
|
||||||
|
|
||||||
|
AND_WHEN("Evaluating Graph") {
|
||||||
|
anim_graph.updateTime(0.f);
|
||||||
|
anim_graph.evaluate();
|
||||||
|
|
||||||
|
Socket* float0_output_socket =
|
||||||
|
anim_graph.getOutputSocket("GraphFloat0Output");
|
||||||
|
Socket* float1_output_socket =
|
||||||
|
anim_graph.getOutputSocket("GraphFloat1Output");
|
||||||
|
Socket* float2_output_socket =
|
||||||
|
anim_graph.getOutputSocket("GraphFloat2Output");
|
||||||
|
|
||||||
|
REQUIRE(float0_output_socket != nullptr);
|
||||||
|
REQUIRE(float1_output_socket != nullptr);
|
||||||
|
REQUIRE(float2_output_socket != nullptr);
|
||||||
|
|
||||||
|
float& float0_output = *static_cast<float*>(float0_output_socket->m_value.ptr);
|
||||||
|
float& float1_output = *static_cast<float*>(float1_output_socket->m_value.ptr);
|
||||||
|
float& float2_output = *static_cast<float*>(float2_output_socket->m_value.ptr);
|
||||||
|
|
||||||
|
THEN("output vector components equal the graph input vaulues") {
|
||||||
|
CHECK(float0_output == Approx(*graph_float_input));
|
||||||
|
CHECK(float1_output == Approx(*graph_float_input * 2.));
|
||||||
|
CHECK(float2_output == Approx(*graph_float_input * 3.));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue