Compare commits

..

No commits in common. "73e7a6087534cc950892b6f2ae4425c6630abce8" and "306a2cb4d8a5f353339bf8665ed571477f9e32b5" have entirely different histories.

4 changed files with 142 additions and 179 deletions

View File

@ -7,7 +7,7 @@
#include "AnimGraphResource.h"
#include "imnodes.h"
using namespace AniGraph;
using namespace AnimGraphCode;
ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) {
switch (socket_type) {

View File

@ -8,7 +8,7 @@
#include "3rdparty/json/json.hpp"
namespace AniGraph {
namespace AnimGraphCode {
using json = nlohmann::json;
@ -351,7 +351,7 @@ bool AnimGraphResource::loadFromFile(const char* filename) {
return true;
}
void AnimGraph::updateOrderedNodes() {
void AnimGraph::UpdateOrderedNodes() {
std::vector<int> node_index_stack;
node_index_stack.push_back(0);
@ -359,7 +359,7 @@ void AnimGraph::updateOrderedNodes() {
while (node_index_stack.size() > 0) {
std::vector<NodeInput>& node_inputs =
m_node_inputs[node_index_stack.back()];
m_node_anim_inputs[node_index_stack.back()];
node_index_stack.pop_back();
for (size_t i = 0, n = node_inputs.size(); i < n; i++) {
@ -368,7 +368,7 @@ void AnimGraph::updateOrderedNodes() {
continue;
}
int input_node_index = input_node->m_index;
int input_node_index = getAnimNodeIndex(input_node);
bool is_node_processed = false;
for (size_t j = 0, m = m_eval_ordered_nodes.size(); j < m; j++) {
if (m_eval_ordered_nodes[j] == input_node) {
@ -387,7 +387,7 @@ void AnimGraph::updateOrderedNodes() {
}
}
void AnimGraph::markActiveNodes() {
void AnimGraph::MarkActiveNodes() {
for (size_t i = 0, n = m_nodes.size(); i < n; i++) {
m_nodes[i]->m_state = AnimNodeEvalState::Deactivated;
}
@ -403,9 +403,9 @@ void AnimGraph::markActiveNodes() {
for (size_t i = 0, n = m_eval_ordered_nodes.size(); i < n; i++) {
AnimNode* node = m_eval_ordered_nodes[i];
if (checkIsNodeActive(node)) {
int node_index = node->m_index;
node->MarkActiveInputs(m_node_inputs[node_index]);
if (CheckIsNodeActive(node)) {
int node_index = getAnimNodeIndex(node);
node->MarkActiveInputs(m_node_anim_inputs[node_index]);
// Non-animation data inputs are always active.
for (size_t j = 0, nj = m_node_inputs[node_index].size(); j < nj; j++) {
@ -418,20 +418,8 @@ void AnimGraph::markActiveNodes() {
}
}
void AnimGraph::evalSyncTracks() {
for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) {
AnimNode* node = m_eval_ordered_nodes[i];
int node_index = node->m_index;
if (node->m_state == AnimNodeEvalState::Deactivated) {
continue;
}
node->CalcSyncTrack(m_node_inputs[node_index]);
}
}
void AnimGraph::updateTime(float dt) {
const std::vector<NodeInput> graph_output_inputs = m_node_inputs[0];
void AnimGraph::UpdateTime(float dt) {
const std::vector<NodeInput> graph_output_inputs = m_node_anim_inputs[0];
for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) {
AnimNode* node = m_eval_ordered_nodes[i];
if (node != nullptr) {
@ -445,18 +433,15 @@ void AnimGraph::updateTime(float dt) {
continue;
}
int node_index = node->m_index;
const std::vector<NodeInput> node_inputs =
m_node_inputs[node_index];
int node_index = getAnimNodeIndex(node);
const std::vector<NodeInput> node_anim_inputs =
m_node_anim_inputs[node_index];
float node_time_now = node->m_time_now;
float node_time_last = node->m_time_last;
for (size_t i = 0, n = node_inputs.size(); i < n; i++) {
AnimNode* input_node = node_inputs[i].m_node;
// Only propagate time updates via animation sockets.
for (size_t i = 0, n = node_anim_inputs.size(); i < n; i++) {
AnimNode* input_node = node_anim_inputs[i].m_node;
if (input_node != nullptr
&& node_inputs[i].m_type == SocketType::SocketTypeAnimation
&& input_node->m_state == AnimNodeEvalState::Activated) {
input_node->UpdateTime(node_time_last, node_time_now);
}
@ -464,18 +449,7 @@ void AnimGraph::updateTime(float dt) {
}
}
void AnimGraph::evaluate() {
for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) {
AnimNode* node = m_eval_ordered_nodes[i];
if (node->m_state == AnimNodeEvalState::Deactivated) {
continue;
}
node->Evaluate();
}
}
void* AnimGraph::getOutput(const std::string& name) const {
void* AnimGraph::GetOutput(const std::string& name) const {
Socket* socket = m_socket_accessor->FindInputSocket(name);
if (socket == nullptr) {
return nullptr;
@ -484,7 +458,7 @@ void* AnimGraph::getOutput(const std::string& name) const {
return socket->m_value.ptr;
}
void* AnimGraph::getInput(const std::string& name) const {
void* AnimGraph::GetInput(const std::string& name) const {
Socket* socket = m_socket_accessor->FindOutputSocket(name);
if (socket == nullptr) {
return nullptr;
@ -493,4 +467,4 @@ void* AnimGraph::getInput(const std::string& name) const {
return *(socket->m_value.ptr_ptr);
}
} // namespace AniGraph
} // namespace AnimGraphCode

View File

@ -14,11 +14,19 @@
#include "SyncTrack.h"
namespace AniGraph {
namespace AnimGraphCode {
//
// Data types
//
enum class SocketType {
SocketTypeUndefined,
SocketTypeBool,
SocketTypeAnimation,
SocketTypeFloat,
SocketTypeVec3,
SocketTypeQuat,
SocketTypeString
};
enum SocketFlags { SocketFlagAffectsTime = 1 };
struct AnimData {
float m_bone_transforms[16];
@ -47,18 +55,7 @@ SplitOutputAttributeId(int attribute_id, int* node_id, int* output_index) {
*output_index = (attribute_id >> 23) - 1;
}
enum class SocketType {
SocketTypeUndefined,
SocketTypeBool,
SocketTypeAnimation,
SocketTypeFloat,
SocketTypeVec3,
SocketTypeQuat,
SocketTypeString
};
enum SocketFlags { SocketFlagAffectsTime = 1 };
struct AnimNodeResource;
struct Socket {
std::string m_name;
@ -80,6 +77,7 @@ struct AnimNodeResource {
std::string m_type_name;
AnimNode* m_anim_node = nullptr;
NodeSocketAccessorBase* m_socket_accessor = nullptr;
float m_position[2] = {0.f, 0.f};
};
@ -100,14 +98,6 @@ enum class AnimNodeEvalState {
};
struct AnimNode {
std::string m_name;
std::string m_node_type_name;
float m_time_now = 0.f;
float m_time_last = 0.f;
size_t m_index = -1;
AnimNodeEvalState m_state = AnimNodeEvalState::Undefined;
SyncTrack m_sync_track;
virtual ~AnimNode(){};
virtual void MarkActiveInputs(const std::vector<NodeInput>& inputs) {
@ -119,33 +109,22 @@ struct AnimNode {
}
}
virtual void CalcSyncTrack(const std::vector<NodeInput>& inputs) {
for (size_t i = 0, n = inputs.size(); i < n; i++) {
AnimNode* input_node = inputs[i].m_node;
if (input_node != nullptr
&& inputs[i].m_type == SocketType::SocketTypeAnimation
&& input_node->m_state != AnimNodeEvalState::Deactivated) {
m_sync_track = input_node->m_sync_track;
return;
}
}
}
virtual void UpdateTime(float time_last, float time_now) {
m_time_last = time_last;
m_time_now = time_now;
m_state = AnimNodeEvalState::TimeUpdated;
}
virtual void Evaluate() {};
std::string m_name;
std::string m_node_type_name;
float m_time_now = 0.f;
float m_time_last = 0.f;
AnimNodeEvalState m_state = AnimNodeEvalState::Undefined;
SyncTrack m_sync_track;
};
struct NodeSocketAccessorBase {
std::vector<Socket> m_properties;
std::vector<Socket> m_inputs;
std::vector<Socket> m_outputs;
NodeSocketAccessorBase() {}
virtual ~NodeSocketAccessorBase() {}
@ -325,6 +304,10 @@ struct NodeSocketAccessorBase {
size_t GetOutputIndex(const std::string& name) {
return GetSocketIndex(m_outputs, name);
}
std::vector<Socket> m_properties;
std::vector<Socket> m_inputs;
std::vector<Socket> m_outputs;
};
template <typename T>
@ -339,9 +322,6 @@ struct NodeRegistry {
AnimNode* node);
};
//
// BlendTreeNode
//
struct BlendTreeNode : public AnimNode {};
template <>
@ -349,9 +329,6 @@ struct NodeSocketAccessor<BlendTreeNode> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {}
};
//
// Blend2Node
//
struct Blend2Node : public AnimNode {
AnimData m_input0;
AnimData m_input1;
@ -359,6 +336,7 @@ struct Blend2Node : public AnimNode {
float m_blend_weight = 0.f;
bool m_sync_blend = false;
virtual void MarkActiveInputs(const std::vector<NodeInput>& inputs) override {
for (size_t i = 0, n = inputs.size(); i < n; i++) {
AnimNode* input_node = inputs[i].m_node;
@ -428,9 +406,6 @@ struct NodeSocketAccessor<Blend2Node> : public NodeSocketAccessorBase {
}
};
//
// SpeedScaleNode
//
struct SpeedScaleNode : public AnimNode {
AnimData m_input;
AnimData* m_output = nullptr;
@ -457,9 +432,6 @@ struct NodeSocketAccessor<SpeedScaleNode> : public NodeSocketAccessorBase {
}
};
//
// AnimSamplerNode
//
struct AnimSamplerNode : public AnimNode {
AnimData* m_output = nullptr;
std::string m_filename;
@ -475,9 +447,6 @@ struct NodeSocketAccessor<AnimSamplerNode> : public NodeSocketAccessorBase {
}
};
//
// AnimGraphResource
//
struct AnimGraphConnection {
int m_source_node_index;
int m_source_socket_index;
@ -506,6 +475,7 @@ struct AnimGraphResource {
bool loadFromFile(const char* filename);
AnimNodeResource& getGraphOutputNode() { return m_nodes[0]; }
AnimNodeResource& getGraphInputNode() { return m_nodes[1]; }
size_t addNode(AnimNodeResource node_resource) {
@ -611,22 +581,7 @@ static inline AnimNodeResource AnimNodeResourceFactory(
return result;
}
//
// AnimGraph (Runtime)
//
struct AnimGraph {
AnimData m_local_transforms;
std::vector<AnimNode*> m_nodes;
std::vector<AnimNode*> m_eval_ordered_nodes;
std::vector<std::vector<NodeInput> > m_node_inputs;
NodeSocketAccessorBase* m_socket_accessor;
char* m_input_buffer = nullptr;
char* m_output_buffer = nullptr;
std::vector<Socket>& getGraphOutputs() { return m_socket_accessor->m_inputs; }
std::vector<Socket>& getGraphInputs() { return m_socket_accessor->m_outputs; }
~AnimGraph() {
delete[] m_input_buffer;
delete[] m_output_buffer;
@ -638,15 +593,14 @@ struct AnimGraph {
delete m_socket_accessor;
}
void updateOrderedNodes();
void markActiveNodes();
bool checkIsNodeActive(AnimNode* node) {
void UpdateOrderedNodes();
void MarkActiveNodes();
bool CheckIsNodeActive(AnimNode* node) {
return node->m_state != AnimNodeEvalState::Deactivated;
}
void evalSyncTracks();
void updateTime(float dt);
void evaluate();
void reset() {
void UpdateTime(float dt);
void Evaluate();
void Reset() {
for (size_t i = 0, n = m_nodes.size(); i < n; i++) {
m_nodes[i]->m_time_now = 0.f;
m_nodes[i]->m_time_last = 0.f;
@ -654,9 +608,21 @@ struct AnimGraph {
}
}
AnimData m_local_transforms;
void* getOutput(const std::string& name) const;
void* getInput(const std::string& name) const;
std::vector<AnimNode*> m_nodes;
std::vector<AnimNode*> m_eval_ordered_nodes;
std::vector<std::vector<NodeInput> > m_node_inputs;
std::vector<std::vector<NodeInput> > m_node_anim_inputs;
NodeSocketAccessorBase* m_socket_accessor;
char* m_input_buffer = nullptr;
char* m_output_buffer = nullptr;
std::vector<Socket>& GetGraphOutputs() { return m_socket_accessor->m_inputs; }
std::vector<Socket>& GetGraphInputs() { return m_socket_accessor->m_outputs; }
void* GetOutput(const std::string& name) const;
void* GetInput(const std::string& name) const;
int getNodeEvalOrderIndex(const AnimNode* node) {
for (size_t i = 0, n = m_eval_ordered_nodes.size(); i < n; i++) {
@ -671,9 +637,9 @@ struct AnimGraph {
size_t node_index,
const std::string& input_name) {
assert(node_index < m_nodes.size());
assert(node_index < m_node_inputs.size());
assert(node_index < m_node_anim_inputs.size());
std::vector<NodeInput>& node_inputs = m_node_inputs[node_index];
std::vector<NodeInput>& node_inputs = m_node_anim_inputs[node_index];
for (size_t i = 0, n = node_inputs.size(); i < n; i++) {
if (node_inputs[i].m_input_name == input_name) {
return node_inputs[i].m_node;
@ -693,6 +659,17 @@ struct AnimGraph {
return nullptr;
}
size_t getAnimNodeIndex(AnimNode* node) {
for (size_t i = 0, n = m_nodes.size(); i < n; i++) {
if (m_nodes[i] == node) {
return i;
}
}
std::cerr << "Could not find node " << node << "." << std::endl;
return -1;
}
static AnimGraph createFromResource(const AnimGraphResource& resource) {
AnimGraph result;
@ -702,12 +679,13 @@ struct AnimGraph {
AnimNode* node = AnimNodeFactory(node_resource.m_type_name.c_str());
node->m_name = node_resource.m_name;
node->m_node_type_name = node_resource.m_type_name;
node->m_index = i;
result.m_nodes.push_back(node);
assert(node_resource.m_socket_accessor != nullptr);
result.m_node_inputs.push_back(std::vector<NodeInput>());
std::vector<NodeInput>& node_inputs = result.m_node_inputs.back();
result.m_node_anim_inputs.push_back(std::vector<NodeInput>());
std::vector<NodeInput>& node_anim_inputs = result.m_node_anim_inputs.back();
for (int j = 0, n = node_resource.m_socket_accessor->m_inputs.size();
j < n;
@ -721,6 +699,10 @@ struct AnimGraph {
input.m_input_name = input_socket.m_name;
node_inputs.push_back(input);
if (input_socket.m_type == SocketType::SocketTypeAnimation) {
node_anim_inputs.push_back(input);
}
}
}
@ -734,7 +716,7 @@ struct AnimGraph {
// inputs
int input_block_size = 0;
std::vector<Socket>& graph_inputs = result.getGraphInputs();
std::vector<Socket>& graph_inputs = result.GetGraphInputs();
for (int i = 0; i < graph_inputs.size(); i++) {
input_block_size += sizeof(void*);
}
@ -752,7 +734,7 @@ struct AnimGraph {
// outputs
int output_block_size = 0;
std::vector<Socket>& graph_outputs = result.getGraphOutputs();
std::vector<Socket>& graph_outputs = result.GetGraphOutputs();
for (int i = 0; i < graph_outputs.size(); i++) {
output_block_size += graph_outputs[i].m_type_size;
}
@ -846,7 +828,7 @@ struct AnimGraph {
(*source_socket->m_value.ptr_ptr) = target_socket->m_value.ptr;
size_t target_node_index = target_node->m_index;
size_t target_node_index = result.getAnimNodeIndex(target_node);
std::vector<NodeInput>& node_inputs =
result.m_node_inputs[target_node_index];
@ -856,6 +838,14 @@ struct AnimGraph {
}
}
std::vector<NodeInput>& node_anim_inputs =
result.m_node_anim_inputs[target_node_index];
for (int j = 0, n = node_anim_inputs.size(); j < n; j++) {
if (node_anim_inputs[j].m_input_name == target_socket->m_name) {
node_anim_inputs[j].m_node = source_node;
}
}
if (target_node_accessor != result.m_socket_accessor) {
delete target_node_accessor;
}
@ -865,13 +855,13 @@ struct AnimGraph {
}
}
result.updateOrderedNodes();
result.reset();
result.UpdateOrderedNodes();
result.Reset();
return result;
}
};
} // namespace AniGraph
} // namespace AnimGraphCode
#endif //ANIMTESTBED_ANIMGRAPHRESOURCE_H

View File

@ -5,7 +5,7 @@
#include "AnimGraphResource.h"
#include "catch.hpp"
using namespace AniGraph;
using namespace AnimGraphCode;
TEST_CASE("BasicGraph", "[AnimGraphResource]") {
AnimGraphResource graph_resource;
@ -87,19 +87,18 @@ TEST_CASE("BasicGraph", "[AnimGraphResource]") {
CHECK(graph.m_socket_accessor->FindInputSocket("GraphOutput"));
CHECK(
reinterpret_cast<char*>(blend2_instance->m_output)
== graph.getOutput("GraphOutput"));
== graph.GetOutput("GraphOutput"));
// check node input dependencies
size_t anim_sampler_index0 = anim_sampler_instance0->m_index;
size_t anim_sampler_index1 = anim_sampler_instance1->m_index;
size_t blend_index = blend2_instance->m_index;
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() == 3);
CHECK(graph.m_node_inputs[blend_index][0].m_node == anim_sampler_instance0);
CHECK(graph.m_node_inputs[blend_index][1].m_node == anim_sampler_instance1);
CHECK(graph.m_node_inputs[blend_index][2].m_node == nullptr);
CHECK(graph.m_node_anim_inputs[anim_sampler_index0].size() == 0);
CHECK(graph.m_node_anim_inputs[anim_sampler_index1].size() == 0);
CHECK(graph.m_node_anim_inputs[blend_index].size() == 2);
CHECK(graph.m_node_anim_inputs[blend_index][0].m_node == anim_sampler_instance0);
CHECK(graph.m_node_anim_inputs[blend_index][1].m_node == anim_sampler_instance1);
}
TEST_CASE("InputAttributeConversion", "[AnimGraphResource]") {
@ -194,14 +193,14 @@ TEST_CASE("ResourceSaveLoadGraphInputs", "[AnimGraphResource]") {
AnimGraph anim_graph =
AnimGraph::createFromResource(graph_resource_loaded);
REQUIRE(
anim_graph.getOutput("GraphOutput") == anim_graph.m_output_buffer);
anim_graph.GetOutput("GraphOutput") == anim_graph.m_output_buffer);
REQUIRE(
anim_graph.getOutput("SomeFloatOutput")
anim_graph.GetOutput("SomeFloatOutput")
== anim_graph.m_output_buffer + sizeof(AnimData));
REQUIRE(anim_graph.getInput("GraphAnimInput") == nullptr);
REQUIRE(anim_graph.getInput("GraphFloatInput") == nullptr);
REQUIRE(anim_graph.getInput("GraphBoolInput") == nullptr);
REQUIRE(anim_graph.GetInput("GraphAnimInput") == nullptr);
REQUIRE(anim_graph.GetInput("GraphFloatInput") == nullptr);
REQUIRE(anim_graph.GetInput("GraphBoolInput") == nullptr);
}
}
@ -217,15 +216,15 @@ TEST_CASE("ResourceSaveLoadGraphInputs", "[AnimGraphResource]") {
AnimGraph anim_graph = AnimGraph::createFromResource(graph_resource_origin);
void* graph_anim_input_ptr = anim_graph.getInput("GraphAnimInput");
void* graph_output_ptr = anim_graph.getOutput("GraphOutput");
void* graph_anim_input_ptr = anim_graph.GetInput("GraphAnimInput");
void* graph_output_ptr = anim_graph.GetOutput("GraphOutput");
REQUIRE(graph_anim_input_ptr == graph_output_ptr);
REQUIRE(graph_output_ptr == anim_graph.m_output_buffer);
REQUIRE(
anim_graph.getInput("GraphAnimInput")
== anim_graph.getOutput("GraphOutput"));
anim_graph.GetInput("GraphAnimInput")
== anim_graph.GetOutput("GraphOutput"));
}
}
@ -267,12 +266,12 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
AnimGraph anim_graph = AnimGraph::createFromResource(graph_resource);
THEN("Writing to the input pointer changes the value of the output.") {
float* float_input_ptr = (float*)anim_graph.getInput("GraphFloatInput");
float* float_input_ptr = (float*)anim_graph.GetInput("GraphFloatInput");
REQUIRE(float_input_ptr != nullptr);
*float_input_ptr = 23.123f;
float* float_output_ptr =
(float*)anim_graph.getOutput("GraphFloatOutput");
(float*)anim_graph.GetOutput("GraphFloatOutput");
REQUIRE(float_output_ptr != nullptr);
CHECK(*float_output_ptr == Approx(23.123f));
}
@ -298,7 +297,7 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
REQUIRE(
*anim_graph.m_socket_accessor->m_outputs[0].m_value.ptr_ptr
== &blend2_node->m_blend_weight);
float* float_input_ptr = (float*)anim_graph.getInput("GraphFloatInput");
float* float_input_ptr = (float*)anim_graph.GetInput("GraphFloatInput");
REQUIRE(float_input_ptr == &blend2_node->m_blend_weight);
}
@ -331,21 +330,21 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
dynamic_cast<Blend2Node*>(anim_graph.m_nodes[blend2_node_index]);
AnimData* graph_input0 =
(AnimData*)anim_graph.getInput("GraphAnimInput0");
(AnimData*)anim_graph.GetInput("GraphAnimInput0");
REQUIRE(graph_input0 == &blend2_node->m_input0);
REQUIRE(
anim_graph.m_nodes[1]
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input0"));
AnimData* graph_input1 =
(AnimData*)anim_graph.getInput("GraphAnimInput1");
(AnimData*)anim_graph.GetInput("GraphAnimInput1");
REQUIRE(graph_input1 == &blend2_node->m_input1);
REQUIRE(
anim_graph.m_nodes[1]
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input1"));
AnimData* graph_output =
(AnimData*)anim_graph.getOutput("GraphAnimOutput");
(AnimData*)anim_graph.GetOutput("GraphAnimOutput");
REQUIRE(graph_output == blend2_node->m_output);
REQUIRE(
anim_graph.m_nodes[blend2_node_index]
@ -418,14 +417,14 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
// check connectivity
//
AnimData* graph_input0 =
(AnimData*)anim_graph.getInput("GraphAnimInput0");
(AnimData*)anim_graph.GetInput("GraphAnimInput0");
REQUIRE(graph_input0 == &blend2_node->m_input0);
REQUIRE(
anim_graph.m_nodes[1]
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input0"));
AnimData* graph_input1 =
(AnimData*)anim_graph.getInput("GraphAnimInput1");
(AnimData*)anim_graph.GetInput("GraphAnimInput1");
REQUIRE(graph_input1 == nullptr);
REQUIRE(sampler_node->m_output == &speed_scale_node->m_input);
@ -439,7 +438,7 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input1"));
AnimData* graph_output =
(AnimData*)anim_graph.getOutput("GraphAnimOutput");
(AnimData*)anim_graph.GetOutput("GraphAnimOutput");
REQUIRE(graph_output == blend2_node->m_output);
REQUIRE(
anim_graph.m_nodes[blend2_node_index]
@ -462,7 +461,7 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
WHEN("Instantiating graph") {
AnimGraph anim_graph = AnimGraph::createFromResource(graph_resource);
float* blend_weight_input =
reinterpret_cast<float*>(anim_graph.getInput("GraphFloatInput"));
reinterpret_cast<float*>(anim_graph.GetInput("GraphFloatInput"));
Blend2Node* blend2_node =
dynamic_cast<Blend2Node*>(anim_graph.m_nodes[blend2_node_index]);
@ -473,43 +472,43 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
WHEN("Setting weight to 0. and marking nodes active.") {
*blend_weight_input = 0.;
anim_graph.markActiveNodes();
anim_graph.MarkActiveNodes();
THEN("Speed scale and sampler node are inactive") {
REQUIRE(anim_graph.checkIsNodeActive(speed_scale_node) == false);
REQUIRE(anim_graph.checkIsNodeActive(sampler_node) == false);
REQUIRE(anim_graph.CheckIsNodeActive(speed_scale_node) == false);
REQUIRE(anim_graph.CheckIsNodeActive(sampler_node) == false);
}
}
WHEN("Setting weight to 0. and marking nodes active") {
*blend_weight_input = 0.1;
anim_graph.markActiveNodes();
anim_graph.MarkActiveNodes();
THEN("Speed scale and sampler nodes are active") {
REQUIRE(anim_graph.checkIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.checkIsNodeActive(sampler_node) == true);
REQUIRE(anim_graph.CheckIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.CheckIsNodeActive(sampler_node) == true);
}
}
WHEN("Setting weight to 1. and marking nodes active") {
*blend_weight_input = 1.0;
anim_graph.markActiveNodes();
anim_graph.MarkActiveNodes();
THEN("Speed scale and sampler nodes are active") {
REQUIRE(anim_graph.checkIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.checkIsNodeActive(sampler_node) == true);
REQUIRE(anim_graph.CheckIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.CheckIsNodeActive(sampler_node) == true);
}
}
WHEN("Updating time with dt = 0.3f and speed scale = 1.0f") {
float* speed_scale_input =
reinterpret_cast<float*>(anim_graph.getInput("SpeedScaleInput"));
reinterpret_cast<float*>(anim_graph.GetInput("SpeedScaleInput"));
*blend_weight_input = 0.1;
*speed_scale_input = 1.0f;
anim_graph.markActiveNodes();
anim_graph.updateTime(0.3f);
anim_graph.MarkActiveNodes();
anim_graph.UpdateTime(0.3f);
THEN ("Anim sampler node time now must be 0.3f") {
REQUIRE(sampler_node->m_time_now == Approx(0.3f));
@ -518,13 +517,13 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
WHEN("Updating time with dt = 0.3f and speed scale = 1.3f") {
float* speed_scale_input =
reinterpret_cast<float*>(anim_graph.getInput("SpeedScaleInput"));
reinterpret_cast<float*>(anim_graph.GetInput("SpeedScaleInput"));
*blend_weight_input = 0.1;
*speed_scale_input = 1.3f;
anim_graph.markActiveNodes();
anim_graph.updateTime(0.3f);
anim_graph.MarkActiveNodes();
anim_graph.UpdateTime(0.3f);
THEN ("Anim sampler node time now must be 0.39f") {
REQUIRE(sampler_node->m_time_now == Approx(0.39f));