Added marking of nodes active/inactive.

This commit is contained in:
Martin Felis
2022-02-20 15:57:19 +01:00
parent 618f6b613e
commit b01acc2a88
3 changed files with 89 additions and 8 deletions
+14 -1
View File
@@ -389,7 +389,20 @@ void AnimGraph::UpdateOrderedNodes() {
void AnimGraph::MarkActiveNodes() {
m_frame_counter++;
// TODO: start from output and trigger updating of the frame counter.
int first_node_index = getAnimNodeIndex(m_ordered_nodes[0]);
m_ordered_nodes[0]->m_frame_counter = m_frame_counter;
m_ordered_nodes[0]->UpdateActiveInputFrameCounters(m_node_inputs[first_node_index]);
for (size_t i = 1, n = m_ordered_nodes.size(); i < n; i++) {
AnimNode* node = m_ordered_nodes[i];
if (CheckIsNodeActive(node)) {
int node_index = getAnimNodeIndex(node);
node->UpdateActiveInputFrameCounters(m_node_inputs[node_index]);
} else {
// Avoid active frame counter overrun.
node->m_frame_counter = m_frame_counter - 1;
}
}
}
void* AnimGraph::GetOutput(const std::string& name) const {
+23 -4
View File
@@ -319,6 +319,26 @@ struct Blend2Node : public AnimNode {
AnimData* m_output = nullptr;
float m_blend_weight = 0.f;
bool m_sync_blend = false;
virtual void UpdateActiveInputFrameCounters (const std::vector<AnimNodeInput>& inputs) override {
for (size_t i = 0, n = inputs.size(); i < n; i++) {
AnimNode* input_node = inputs[i].m_node;
if (input_node == nullptr) {
continue;
}
if (inputs[i].m_input_name == "Input0" && m_blend_weight < 0.999) {
input_node->m_frame_counter = m_frame_counter;
continue;
}
if (inputs[i].m_input_name == "Input1" && m_blend_weight > 0.001) {
input_node->m_frame_counter = m_frame_counter;
continue;
}
}
}
};
template <>
@@ -532,14 +552,13 @@ struct AnimGraph {
void UpdateOrderedNodes();
void MarkActiveNodes();
bool CheckNodeActive(int node_index) {
assert(node_index < m_nodes.size());
return m_nodes[node_index]->m_frame_counter == m_frame_counter;
bool CheckIsNodeActive(AnimNode* node) {
return node->m_frame_counter == m_frame_counter;
}
void UpdateTime(float dt);
void Evaluate();
int m_frame_counter;
int m_frame_counter = 0;
AnimData m_local_transforms;
std::vector<AnimNode*> m_nodes;