Initial graph evaluations, added Float to Vec3 Node, minor editor tweaks.
This commit is contained in:
+90
-16
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "AnimGraph.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
void AnimGraph::updateOrderedNodes() {
|
||||
m_eval_ordered_nodes.clear();
|
||||
updateOrderedNodesRecursive(0);
|
||||
@@ -14,11 +16,19 @@ void AnimGraph::updateOrderedNodesRecursive(int node_index) {
|
||||
const std::vector<AnimGraphConnection> node_input_connections =
|
||||
m_node_input_connections[node_index];
|
||||
for (size_t i = 0, n = node_input_connections.size(); i < n; i++) {
|
||||
int input_node_index = getAnimNodeIndex(node_input_connections[i].m_source_node);
|
||||
int input_node_index =
|
||||
getAnimNodeIndex(node_input_connections[i].m_source_node);
|
||||
|
||||
if (input_node_index == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
updateOrderedNodesRecursive(input_node_index);
|
||||
}
|
||||
|
||||
m_eval_ordered_nodes.push_back(node);
|
||||
if (node_index != 0) {
|
||||
m_eval_ordered_nodes.push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimGraph::markActiveNodes() {
|
||||
@@ -26,7 +36,8 @@ void AnimGraph::markActiveNodes() {
|
||||
m_nodes[i]->m_state = AnimNodeEvalState::Deactivated;
|
||||
}
|
||||
|
||||
const std::vector<AnimGraphConnection>& graph_output_inputs = m_node_input_connections[0];
|
||||
const std::vector<AnimGraphConnection>& graph_output_inputs =
|
||||
m_node_input_connections[0];
|
||||
for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) {
|
||||
const AnimGraphConnection& graph_input = graph_output_inputs[i];
|
||||
AnimNode* node = graph_input.m_source_node;
|
||||
@@ -42,10 +53,14 @@ void AnimGraph::markActiveNodes() {
|
||||
node->MarkActiveInputs(m_node_input_connections[node_index]);
|
||||
|
||||
// Non-animation data inputs are always active.
|
||||
for (size_t j = 0, nj = m_node_input_connections[node_index].size(); j < nj; j++) {
|
||||
const AnimGraphConnection& input = m_node_input_connections[node_index][j];
|
||||
for (size_t j = 0, nj = m_node_input_connections[node_index].size();
|
||||
j < nj;
|
||||
j++) {
|
||||
const AnimGraphConnection& input =
|
||||
m_node_input_connections[node_index][j];
|
||||
if (input.m_source_node != nullptr
|
||||
&& input.m_target_socket.m_type != SocketType::SocketTypeAnimation) {
|
||||
&& input.m_target_socket.m_type
|
||||
!= SocketType::SocketTypeAnimation) {
|
||||
input.m_source_node->m_state = AnimNodeEvalState::Activated;
|
||||
}
|
||||
}
|
||||
@@ -102,6 +117,42 @@ void AnimGraph::finishNodeEval(size_t node_index) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AnimGraph::evalInputNode() {
|
||||
for (size_t i = 0, n = m_node_output_connections[1].size(); i < n; i++) {
|
||||
AnimGraphConnection& graph_input_connection =
|
||||
m_node_output_connections[1][i];
|
||||
|
||||
if (graph_input_connection.m_source_socket.m_type
|
||||
!= SocketType::SocketTypeAnimation) {
|
||||
memcpy(
|
||||
*graph_input_connection.m_target_socket.m_value.ptr_ptr,
|
||||
graph_input_connection.m_source_socket.m_value.ptr,
|
||||
sizeof(void*));
|
||||
printf("bla");
|
||||
} else {
|
||||
// TODO: how to deal with anim data outputs?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimGraph::evalOutputNode() {
|
||||
for (size_t i = 0, n = m_node_input_connections[0].size(); i < n; i++) {
|
||||
AnimGraphConnection& graph_output_connection =
|
||||
m_node_input_connections[0][i];
|
||||
|
||||
if (graph_output_connection.m_source_socket.m_type
|
||||
!= SocketType::SocketTypeAnimation) {
|
||||
memcpy(
|
||||
graph_output_connection.m_target_socket.m_value.ptr,
|
||||
graph_output_connection.m_source_socket.m_value.ptr,
|
||||
graph_output_connection.m_target_socket.m_type_size);
|
||||
} else {
|
||||
// TODO: how to deal with anim data outputs?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimGraph::evalSyncTracks() {
|
||||
for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) {
|
||||
AnimNode* node = m_eval_ordered_nodes[i];
|
||||
@@ -115,22 +166,24 @@ void AnimGraph::evalSyncTracks() {
|
||||
}
|
||||
|
||||
void AnimGraph::updateTime(float dt) {
|
||||
const std::vector<AnimGraphConnection> graph_output_inputs = m_node_input_connections[0];
|
||||
const std::vector<AnimGraphConnection> graph_output_inputs =
|
||||
m_node_input_connections[0];
|
||||
for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) {
|
||||
AnimNode* node = m_eval_ordered_nodes[i];
|
||||
AnimNode* node = graph_output_inputs[i].m_source_node;
|
||||
if (node != nullptr) {
|
||||
node->UpdateTime(node->m_time_now, node->m_time_now + dt);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0, n = m_eval_ordered_nodes.size(); i < n; i++) {
|
||||
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::TimeUpdated) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int node_index = node->m_index;
|
||||
const std::vector<AnimGraphConnection> node_input_connections = m_node_input_connections[node_index];
|
||||
const std::vector<AnimGraphConnection> node_input_connections =
|
||||
m_node_input_connections[node_index];
|
||||
float node_time_now = node->m_time_now;
|
||||
float node_time_last = node->m_time_last;
|
||||
|
||||
@@ -139,7 +192,8 @@ void AnimGraph::updateTime(float dt) {
|
||||
|
||||
// Only propagate time updates via animation sockets.
|
||||
if (input_node != nullptr
|
||||
&& node_input_connections[i].m_target_socket.m_type == SocketType::SocketTypeAnimation
|
||||
&& node_input_connections[i].m_target_socket.m_type
|
||||
== SocketType::SocketTypeAnimation
|
||||
&& input_node->m_state == AnimNodeEvalState::Activated) {
|
||||
input_node->UpdateTime(node_time_last, node_time_now);
|
||||
}
|
||||
@@ -156,7 +210,7 @@ void AnimGraph::evaluate() {
|
||||
eval_stack[i] = &eval_buffers[i];
|
||||
}
|
||||
|
||||
for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) {
|
||||
for (int i = 0, n = m_eval_ordered_nodes.size(); i < n; i++) {
|
||||
AnimNode* node = m_eval_ordered_nodes[i];
|
||||
|
||||
if (node->m_state == AnimNodeEvalState::Deactivated) {
|
||||
@@ -172,11 +226,10 @@ void AnimGraph::evaluate() {
|
||||
}
|
||||
|
||||
Socket* AnimGraph::getInputSocket(const std::string& name) {
|
||||
Socket* socket = nullptr;
|
||||
for (size_t i = 0, n = m_node_output_connections[1].size(); i < n; i++) {
|
||||
AnimGraphConnection& connection = m_node_output_connections[1][i];
|
||||
if (connection.m_target_socket.m_name == name) {
|
||||
return &connection.m_target_socket;
|
||||
if (connection.m_source_socket.m_name == name) {
|
||||
return &connection.m_source_socket;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +237,6 @@ Socket* AnimGraph::getInputSocket(const std::string& name) {
|
||||
}
|
||||
|
||||
Socket* AnimGraph::getOutputSocket(const std::string& name) {
|
||||
Socket* socket = nullptr;
|
||||
for (size_t i = 0, n = m_node_input_connections[0].size(); i < n; i++) {
|
||||
AnimGraphConnection& connection = m_node_input_connections[0][i];
|
||||
if (connection.m_target_socket.m_name == name) {
|
||||
@@ -192,5 +244,27 @@ Socket* AnimGraph::getOutputSocket(const std::string& name) {
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Socket* AnimGraph::getInputSocket(const std::string& name) const {
|
||||
for (size_t i = 0, n = m_node_output_connections[1].size(); i < n; i++) {
|
||||
const AnimGraphConnection& connection = m_node_output_connections[1][i];
|
||||
if (connection.m_source_socket.m_name == name) {
|
||||
return &connection.m_source_socket;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Socket* AnimGraph::getOutputSocket(const std::string& name) const {
|
||||
for (size_t i = 0, n = m_node_input_connections[0].size(); i < n; i++) {
|
||||
const AnimGraphConnection& connection = m_node_input_connections[0][i];
|
||||
if (connection.m_target_socket.m_name == name) {
|
||||
return &connection.m_target_socket;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user