Splitted animation and data node inputs.

AnimGraphEditor
Martin Felis 2022-02-22 22:34:13 +01:00
parent af5d27db85
commit ef74f39cf4
3 changed files with 56 additions and 33 deletions

View File

@ -358,8 +358,8 @@ void AnimGraph::UpdateOrderedNodes() {
m_eval_ordered_nodes.clear(); m_eval_ordered_nodes.clear();
while (node_index_stack.size() > 0) { while (node_index_stack.size() > 0) {
std::vector<AnimNodeInput>& node_inputs = 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(); node_index_stack.pop_back();
for (size_t i = 0, n = node_inputs.size(); i < n; i++) { for (size_t i = 0, n = node_inputs.size(); i < n; i++) {
@ -392,9 +392,19 @@ void AnimGraph::MarkActiveNodes() {
m_nodes[i]->m_state = AnimNodeEvalState::Deactivated; m_nodes[i]->m_state = AnimNodeEvalState::Deactivated;
} }
const std::vector<AnimNodeInput> graph_output_inputs = m_node_inputs[0]; const std::vector<NodeInput> graph_output_anim_inputs = m_node_anim_inputs[0];
for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) { for (size_t i = 0, n = graph_output_anim_inputs.size(); i < n; i++) {
AnimNode* node = m_eval_ordered_nodes[i]; const NodeInput& graph_input = graph_output_anim_inputs[i];
AnimNode* node = graph_input.m_node;
if (node != nullptr) {
node->m_state = AnimNodeEvalState::Activated;
}
}
const std::vector<NodeInput> graph_output_data_inputs = m_node_data_inputs[0];
for (size_t i = 0, n = graph_output_data_inputs.size(); i < n; i++) {
const NodeInput& graph_input = graph_output_data_inputs[i];
AnimNode* node = graph_input.m_node;
if (node != nullptr) { if (node != nullptr) {
node->m_state = AnimNodeEvalState::Activated; node->m_state = AnimNodeEvalState::Activated;
} }
@ -404,13 +414,20 @@ void AnimGraph::MarkActiveNodes() {
AnimNode* node = m_eval_ordered_nodes[i]; AnimNode* node = m_eval_ordered_nodes[i];
if (CheckIsNodeActive(node)) { if (CheckIsNodeActive(node)) {
int node_index = getAnimNodeIndex(node); int node_index = getAnimNodeIndex(node);
node->MarkActiveInputs(m_node_inputs[node_index]); node->MarkActiveInputs(m_node_anim_inputs[node_index]);
for (size_t j = 0, nj = m_node_data_inputs[node_index].size(); j < nj; j++) {
const NodeInput& data_input = m_node_data_inputs[node_index][j];
if (data_input.m_node != nullptr) {
data_input.m_node->m_state = AnimNodeEvalState::Activated;
}
}
} }
} }
} }
void AnimGraph::UpdateTime(float dt) { void AnimGraph::UpdateTime(float dt) {
const std::vector<AnimNodeInput> graph_output_inputs = m_node_inputs[0]; 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++) { for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) {
AnimNode* node = m_eval_ordered_nodes[i]; AnimNode* node = m_eval_ordered_nodes[i];
if (node != nullptr) { if (node != nullptr) {
@ -425,15 +442,15 @@ void AnimGraph::UpdateTime(float dt) {
} }
int node_index = getAnimNodeIndex(node); int node_index = getAnimNodeIndex(node);
const std::vector<AnimNodeInput> node_inputs = m_node_inputs[node_index]; const std::vector<NodeInput> node_anim_inputs =
m_node_anim_inputs[node_index];
float node_time_now = node->m_time_now; float node_time_now = node->m_time_now;
float node_time_last = node->m_time_last; float node_time_last = node->m_time_last;
for (size_t i = 0, n = node_inputs.size(); i < n; i++) { for (size_t i = 0, n = node_anim_inputs.size(); i < n; i++) {
AnimNode* input_node = node_inputs[i].m_node; AnimNode* input_node = node_anim_inputs[i].m_node;
if (input_node != nullptr if (input_node != nullptr
&& input_node->m_state == AnimNodeEvalState::Activated && input_node->m_state == AnimNodeEvalState::Activated) {
&& node_inputs[i].m_type == SocketType::SocketTypeAnimation) {
input_node->UpdateTime(node_time_last, node_time_now); input_node->UpdateTime(node_time_last, node_time_now);
} }
} }

View File

@ -82,9 +82,8 @@ struct AnimNodeResource {
}; };
struct AnimNodeInput { struct NodeInput {
AnimNode* m_node; AnimNode* m_node;
SocketType m_type = SocketType::SocketTypeUndefined;
std::string m_input_name; std::string m_input_name;
}; };
@ -100,7 +99,7 @@ enum class AnimNodeEvalState {
struct AnimNode { struct AnimNode {
virtual ~AnimNode(){}; virtual ~AnimNode(){};
virtual void MarkActiveInputs(const std::vector<AnimNodeInput>& inputs) { virtual void MarkActiveInputs(const std::vector<NodeInput>& inputs) {
for (size_t i = 0, n = inputs.size(); i < n; i++) { for (size_t i = 0, n = inputs.size(); i < n; i++) {
AnimNode* input_node = inputs[i].m_node; AnimNode* input_node = inputs[i].m_node;
if (input_node != nullptr) { if (input_node != nullptr) {
@ -337,7 +336,7 @@ struct Blend2Node : public AnimNode {
bool m_sync_blend = false; bool m_sync_blend = false;
virtual void MarkActiveInputs(const std::vector<AnimNodeInput>& inputs) override { virtual void MarkActiveInputs(const std::vector<NodeInput>& inputs) override {
for (size_t i = 0, n = inputs.size(); i < n; i++) { for (size_t i = 0, n = inputs.size(); i < n; i++) {
AnimNode* input_node = inputs[i].m_node; AnimNode* input_node = inputs[i].m_node;
if (input_node == nullptr) { if (input_node == nullptr) {
@ -356,7 +355,7 @@ struct Blend2Node : public AnimNode {
} }
} }
virtual void UpdateTime(float dt, std::vector<AnimNodeInput>& inputs) { virtual void UpdateTime(float dt, std::vector<NodeInput>& inputs) {
if (!m_sync_blend) { if (!m_sync_blend) {
m_time_now = m_time_now + dt; m_time_now = m_time_now + dt;
} }
@ -612,7 +611,8 @@ struct AnimGraph {
std::vector<AnimNode*> m_nodes; std::vector<AnimNode*> m_nodes;
std::vector<AnimNode*> m_eval_ordered_nodes; std::vector<AnimNode*> m_eval_ordered_nodes;
std::vector<std::vector<AnimNodeInput> > m_node_inputs; std::vector<std::vector<NodeInput> > m_node_anim_inputs;
std::vector<std::vector<NodeInput> > m_node_data_inputs;
NodeSocketAccessorBase* m_socket_accessor; NodeSocketAccessorBase* m_socket_accessor;
char* m_input_buffer = nullptr; char* m_input_buffer = nullptr;
char* m_output_buffer = nullptr; char* m_output_buffer = nullptr;
@ -636,9 +636,9 @@ struct AnimGraph {
size_t node_index, size_t node_index,
const std::string& input_name) { const std::string& input_name) {
assert(node_index < m_nodes.size()); assert(node_index < m_nodes.size());
assert(node_index < m_node_inputs.size()); assert(node_index < m_node_anim_inputs.size());
std::vector<AnimNodeInput>& 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++) { for (size_t i = 0, n = node_inputs.size(); i < n; i++) {
if (node_inputs[i].m_input_name == input_name) { if (node_inputs[i].m_input_name == input_name) {
return node_inputs[i].m_node; return node_inputs[i].m_node;
@ -681,19 +681,26 @@ struct AnimGraph {
result.m_nodes.push_back(node); result.m_nodes.push_back(node);
assert(node_resource.m_socket_accessor != nullptr); assert(node_resource.m_socket_accessor != nullptr);
result.m_node_inputs.push_back(std::vector<AnimNodeInput>()); result.m_node_anim_inputs.push_back(std::vector<NodeInput>());
std::vector<AnimNodeInput>& node_inputs = result.m_node_inputs.back(); result.m_node_data_inputs.push_back(std::vector<NodeInput>());
std::vector<NodeInput>& node_anim_inputs = result.m_node_anim_inputs.back();
std::vector<NodeInput>& node_data_inputs = result.m_node_data_inputs.back();
for (int j = 0, n = node_resource.m_socket_accessor->m_inputs.size(); for (int j = 0, n = node_resource.m_socket_accessor->m_inputs.size();
j < n; j < n;
j++) { j++) {
const Socket& input_socket = const Socket& input_socket =
node_resource.m_socket_accessor->m_inputs[j]; node_resource.m_socket_accessor->m_inputs[j];
AnimNodeInput input;
NodeInput input;
input.m_node = nullptr; input.m_node = nullptr;
input.m_type = input_socket.m_type;
input.m_input_name = input_socket.m_name; 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);
} else {
node_data_inputs.push_back(input);
}
} }
} }
@ -821,8 +828,8 @@ struct AnimGraph {
size_t target_node_index = result.getAnimNodeIndex(target_node); size_t target_node_index = result.getAnimNodeIndex(target_node);
std::vector<AnimNodeInput>& node_inputs = std::vector<NodeInput>& node_inputs =
result.m_node_inputs[target_node_index]; result.m_node_anim_inputs[target_node_index];
for (int j = 0, n = node_inputs.size(); j < n; j++) { for (int j = 0, n = node_inputs.size(); j < n; j++) {
if (node_inputs[j].m_input_name == target_socket->m_name) { if (node_inputs[j].m_input_name == target_socket->m_name) {
node_inputs[j].m_node = source_node; node_inputs[j].m_node = source_node;

View File

@ -94,12 +94,11 @@ TEST_CASE("BasicGraph", "[AnimGraphResource]") {
size_t anim_sampler_index1 = graph.getAnimNodeIndex(anim_sampler_instance1); size_t anim_sampler_index1 = graph.getAnimNodeIndex(anim_sampler_instance1);
size_t blend_index = graph.getAnimNodeIndex(blend2_instance); size_t blend_index = graph.getAnimNodeIndex(blend2_instance);
CHECK(graph.m_node_inputs[anim_sampler_index0].size() == 0); CHECK(graph.m_node_anim_inputs[anim_sampler_index0].size() == 0);
CHECK(graph.m_node_inputs[anim_sampler_index1].size() == 0); CHECK(graph.m_node_anim_inputs[anim_sampler_index1].size() == 0);
CHECK(graph.m_node_inputs[blend_index].size() == 3); CHECK(graph.m_node_anim_inputs[blend_index].size() == 2);
CHECK(graph.m_node_inputs[blend_index][0].m_node == anim_sampler_instance0); CHECK(graph.m_node_anim_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_anim_inputs[blend_index][1].m_node == anim_sampler_instance1);
CHECK(graph.m_node_inputs[blend_index][2].m_node == nullptr);
} }
TEST_CASE("InputAttributeConversion", "[AnimGraphResource]") { TEST_CASE("InputAttributeConversion", "[AnimGraphResource]") {