Removed even more unused files.

RefactorUnifiedBlendTreeStateMachineHandling
Martin Felis 2024-04-05 00:18:07 +02:00
parent 3444f8a625
commit 8694a11416
9 changed files with 50 additions and 82 deletions

View File

@ -39,17 +39,13 @@ set(ThirdPartyIncludeDeps
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/sokol> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/sokol>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/vectorial/include> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/vectorial/include>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
) )
# Shared code by main executable and tests # Shared code by main executable and tests
add_library(AnimTestbedCode OBJECT add_library(AnimTestbedCode OBJECT
src/SyncTrack.cc src/SyncTrack.cc
src/SyncTrack.h src/SyncTrack.h
src/ozzutils.cc src/ozzutils.cc
# src/AnimGraph/AnimGraphBlendTreeResource.cc
# src/AnimGraph/AnimGraphBlendTreeResource.h
src/AnimGraph/AnimGraph.cc
src/AnimGraph/AnimGraph.h
src/AnimGraph/AnimGraphNodes.cc src/AnimGraph/AnimGraphNodes.cc
src/AnimGraph/AnimGraphNodes.h src/AnimGraph/AnimGraphNodes.h
src/AnimGraph/AnimGraphData.cc src/AnimGraph/AnimGraphData.cc
@ -112,7 +108,7 @@ target_sources(AnimTestbed PRIVATE
3rdparty/imgui-node-editor/imgui_extra_math.inl 3rdparty/imgui-node-editor/imgui_extra_math.inl
3rdparty/imgui-node-editor/crude_json.cpp 3rdparty/imgui-node-editor/crude_json.cpp
3rdparty/imgui-node-editor/crude_json.h 3rdparty/imgui-node-editor/crude_json.h
) )
target_link_libraries(AnimTestbed AnimTestbedCode glfw ozz_base ozz_geometry ozz_animation ${OPENGL_LIBRARIES}) target_link_libraries(AnimTestbed AnimTestbedCode glfw ozz_base ozz_geometry ozz_animation ${OPENGL_LIBRARIES})
@ -124,7 +120,7 @@ set(ozz_offline_test_objs
3rdparty/ozz-animation/src/animation/offline/raw_skeleton.cc 3rdparty/ozz-animation/src/animation/offline/raw_skeleton.cc
3rdparty/ozz-animation/src/animation/offline/animation_builder.cc 3rdparty/ozz-animation/src/animation/offline/animation_builder.cc
3rdparty/ozz-animation/src/animation/offline/raw_animation.cc 3rdparty/ozz-animation/src/animation/offline/raw_animation.cc
) )
target_sources(runtests PRIVATE target_sources(runtests PRIVATE
tests/AnimGraphResourceTests.cc tests/AnimGraphResourceTests.cc
@ -133,7 +129,7 @@ target_sources(runtests PRIVATE
tests/SyncTrackTests.cc tests/SyncTrackTests.cc
tests/main.cc tests/main.cc
${ozz_offline_test_objs} ${ozz_offline_test_objs}
) )
target_include_directories( target_include_directories(
runtests runtests

View File

@ -1,3 +0,0 @@
//
// Created by martin on 25.03.22.
//

View File

@ -1,38 +0,0 @@
//
// Created by martin on 25.03.22.
//
#ifndef ANIMTESTBED_ANIMGRAPH_H
#define ANIMTESTBED_ANIMGRAPH_H
#include "AnimNode.h"
#include "AnimGraphData.h"
//
// AnimGraph (Runtime)
//
struct AnimGraph {
~AnimGraph() {}
bool Init(AnimGraphContext& context) {
return m_root_node->Init(context);
}
void UpdateTime(float dt) {
m_time_last = m_time_now;
m_time_now = m_time_now + dt;
m_root_node->UpdateTime(m_time_last, m_time_now);
}
void Evaluate(AnimGraphContext& context) {
}
AnimNode* m_root_node = nullptr;
float m_time_now = 0.f;
float m_time_last = 0.f;
Vec3 m_root_bone_translation = {};
Quat m_root_bone_rotation = {};
};
#endif // ANIMTESTBED_ANIMGRAPH_H

View File

@ -1,3 +1,5 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "misc-no-recursion"
// //
// Created by martin on 17.03.24. // Created by martin on 17.03.24.
// //
@ -5,7 +7,6 @@
#include "AnimGraphBlendTree.h" #include "AnimGraphBlendTree.h"
#include <algorithm> #include <algorithm>
#include <cstring>
bool AnimGraphBlendTree::Init(AnimGraphContext& context) { bool AnimGraphBlendTree::Init(AnimGraphContext& context) {
for (size_t i = 2; i < m_nodes.size(); i++) { for (size_t i = 2; i < m_nodes.size(); i++) {
@ -64,9 +65,9 @@ void AnimGraphBlendTree::UpdateOrderedNodesRecursive(int node_index) {
void AnimGraphBlendTree::MarkActiveInputs( void AnimGraphBlendTree::MarkActiveInputs(
const std::vector<AnimGraphConnection>& input_connections) { const std::vector<AnimGraphConnection>& input_connections) {
for (size_t i = 0, n = m_nodes.size(); i < n; i++) { for (AnimNode* node : m_nodes) {
if (m_nodes[i]->m_tick_number != m_tick_number) { if (node->m_tick_number != m_tick_number) {
m_nodes[i]->m_state = AnimNodeEvalState::Deactivated; node->m_state = AnimNodeEvalState::Deactivated;
} }
} }
@ -104,7 +105,7 @@ void AnimGraphBlendTree::MarkActiveInputs(
void AnimGraphBlendTree::CalcSyncTrack( void AnimGraphBlendTree::CalcSyncTrack(
const std::vector<AnimGraphConnection>& input_connections) { const std::vector<AnimGraphConnection>& input_connections) {
for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) { for (int i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) {
AnimNode* node = m_eval_ordered_nodes[i]; AnimNode* node = m_eval_ordered_nodes[i];
if (node->m_state == AnimNodeEvalState::Deactivated) { if (node->m_state == AnimNodeEvalState::Deactivated) {
continue; continue;
@ -119,8 +120,8 @@ void AnimGraphBlendTree::UpdateTime(float time_last, float time_now) {
const std::vector<AnimGraphConnection>& graph_output_inputs = const std::vector<AnimGraphConnection>& graph_output_inputs =
m_node_input_connections[0]; m_node_input_connections[0];
for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) { for (const AnimGraphConnection& graph_output_input : graph_output_inputs) {
AnimNode* node = graph_output_inputs[i].m_source_node; AnimNode* node = graph_output_input.m_source_node;
if (node != nullptr && node->m_state != AnimNodeEvalState::TimeUpdated) { if (node != nullptr && node->m_state != AnimNodeEvalState::TimeUpdated) {
node->UpdateTime(time_last, time_now); node->UpdateTime(time_last, time_now);
} }
@ -158,15 +159,18 @@ void AnimGraphBlendTree::PropagateTimeToNodeInputs(const AnimNode* node) {
const std::vector<AnimGraphConnection>& node_input_connections = const std::vector<AnimGraphConnection>& node_input_connections =
m_node_input_connections[node_index]; m_node_input_connections[node_index];
for (size_t i = 0, n = node_input_connections.size(); i < n; i++) { for (const AnimGraphConnection& node_input_connection :
AnimNode* input_node = node_input_connections[i].m_source_node; node_input_connections) {
AnimNode* input_node = node_input_connection.m_source_node;
// Only propagate time updates via animation sockets. // Only propagate time updates via animation sockets.
if (input_node != nullptr if (input_node != nullptr
&& node_input_connections[i].m_socket.m_type && node_input_connection.m_socket.m_type
== SocketType::SocketTypeAnimation == SocketType::SocketTypeAnimation
&& input_node->m_state == AnimNodeEvalState::Activated) { && input_node->m_state == AnimNodeEvalState::Activated) {
input_node->UpdateTime(node_time_last, node_time_now); input_node->UpdateTime(node_time_last, node_time_now);
} }
} }
} }
#pragma clang diagnostic pop

View File

@ -189,8 +189,8 @@ struct AnimGraphBlendTree : public AnimNode {
return nullptr; return nullptr;
} }
size_t GetAnimNodeIndex(const AnimNode* node) const { int GetAnimNodeIndex(const AnimNode* node) const {
for (size_t i = 0; i < m_nodes.size(); i++) { for (int i = 0; i < m_nodes.size(); i++) {
if (m_nodes[i] == node) { if (m_nodes[i] == node) {
return i; return i;
} }

View File

@ -5,8 +5,6 @@
#ifndef ANIMTESTBED_ANIMGRAPHEDITOR_H #ifndef ANIMTESTBED_ANIMGRAPHEDITOR_H
#define ANIMTESTBED_ANIMGRAPHEDITOR_H #define ANIMTESTBED_ANIMGRAPHEDITOR_H
#include "AnimGraph.h"
namespace ax::NodeEditor { namespace ax::NodeEditor {
struct EditorContext; struct EditorContext;
} // namespace ax::NodeEditor } // namespace ax::NodeEditor

View File

@ -1,3 +1,5 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "misc-no-recursion"
// //
// Created by martin on 17.03.24. // Created by martin on 17.03.24.
// //
@ -664,7 +666,6 @@ void AnimGraphResource::CreateBlendTreeConnectionInstances(
embedded_graph_activation_connection.m_target_socket_name = embedded_graph_activation_connection.m_target_socket_name =
target_socket->m_name; target_socket->m_name;
// TODO: what to set the pointer to?!?
embedded_graph_activation_connection.m_socket = *target_socket; embedded_graph_activation_connection.m_socket = *target_socket;
instance.m_node_input_connections[connection.target_node_index].push_back( instance.m_node_input_connections[connection.target_node_index].push_back(
@ -866,4 +867,5 @@ bool AnimGraphResource::LoadStateMachineResourceFromJson(
assert(false && "Not yet implemented"); assert(false && "Not yet implemented");
return false; return false;
} }
#pragma clang diagnostic pop

View File

@ -5,10 +5,8 @@
#ifndef ANIMTESTBED_ANIMGRAPHRESOURCE_H #ifndef ANIMTESTBED_ANIMGRAPHRESOURCE_H
#define ANIMTESTBED_ANIMGRAPHRESOURCE_H #define ANIMTESTBED_ANIMGRAPHRESOURCE_H
#include "AnimGraph.h"
#include "AnimGraphNodes.h"
#include "3rdparty/json/json.hpp" #include "3rdparty/json/json.hpp"
#include "AnimGraphNodes.h"
struct AnimGraphBlendTree; struct AnimGraphBlendTree;
struct AnimGraphStateMachine; struct AnimGraphStateMachine;
@ -23,7 +21,8 @@ struct AnimNodeResource {
float m_position[2] = {0.f, 0.f}; float m_position[2] = {0.f, 0.f};
}; };
static inline AnimNodeResource* AnimNodeResourceFactory(const std::string& node_type_name); static inline AnimNodeResource* AnimNodeResourceFactory(
const std::string& node_type_name);
struct BlendTreeConnectionResource { struct BlendTreeConnectionResource {
size_t source_node_index = -1; size_t source_node_index = -1;
@ -36,8 +35,7 @@ struct BlendTreeResource {
std::vector<AnimNodeResource*> m_nodes; std::vector<AnimNodeResource*> m_nodes;
std::vector<BlendTreeConnectionResource> m_connections; std::vector<BlendTreeConnectionResource> m_connections;
~BlendTreeResource() { CleanupNodes(); ~BlendTreeResource() { CleanupNodes(); }
}
void Reset() { void Reset() {
CleanupNodes(); CleanupNodes();
@ -62,8 +60,12 @@ struct BlendTreeResource {
m_nodes[1]->m_name = "Inputs"; m_nodes[1]->m_name = "Inputs";
} }
[[nodiscard]] AnimNodeResource* GetGraphOutputNode() const { return m_nodes[0]; } [[nodiscard]] AnimNodeResource* GetGraphOutputNode() const {
[[nodiscard]] AnimNodeResource* GetGraphInputNode() const { return m_nodes[1]; } return m_nodes[0];
}
[[nodiscard]] AnimNodeResource* GetGraphInputNode() const {
return m_nodes[1];
}
size_t GetNodeIndex(const AnimNodeResource* node_resource) const { size_t GetNodeIndex(const AnimNodeResource* node_resource) const {
for (size_t i = 0, n = m_nodes.size(); i < n; i++) { for (size_t i = 0, n = m_nodes.size(); i < n; i++) {
@ -75,7 +77,7 @@ struct BlendTreeResource {
return -1; return -1;
} }
bool ConnectSockets ( bool ConnectSockets(
const AnimNodeResource* source_node, const AnimNodeResource* source_node,
const std::string& source_socket_name, const std::string& source_socket_name,
const AnimNodeResource* target_node, const AnimNodeResource* target_node,
@ -86,13 +88,17 @@ struct BlendTreeResource {
std::vector<Socket*> result; std::vector<Socket*> result;
for (size_t i = 0; i < m_nodes.size(); i++) { for (size_t i = 0; i < m_nodes.size(); i++) {
for (size_t j = 0, num_inputs = instance_node_descriptors[i]->m_inputs.size(); for (size_t j = 0,
num_inputs = instance_node_descriptors[i]->m_inputs.size();
j < num_inputs; j < num_inputs;
j++) { j++) {
Socket& input = instance_node_descriptors[i]->m_inputs[j]; Socket& input = instance_node_descriptors[i]->m_inputs[j];
if (*input.m_reference.ptr_ptr == nullptr) { if (*input.m_reference.ptr_ptr == nullptr) {
memcpy(&input.m_value, &m_nodes[i]->m_socket_accessor->m_inputs[j].m_value, sizeof(Socket::SocketValue)); memcpy(
&input.m_value,
&m_nodes[i]->m_socket_accessor->m_inputs[j].m_value,
sizeof(Socket::SocketValue));
result.push_back(&input); result.push_back(&input);
} }
} }
@ -104,12 +110,14 @@ struct BlendTreeResource {
size_t GetNodeIndexForOutputSocket(const std::string& socket_name) const { size_t GetNodeIndexForOutputSocket(const std::string& socket_name) const {
for (size_t i = 0; i < m_connections.size(); i++) { for (size_t i = 0; i < m_connections.size(); i++) {
const BlendTreeConnectionResource& connection = m_connections[i]; const BlendTreeConnectionResource& connection = m_connections[i];
if (connection.target_node_index == 0 && connection.target_socket_name == socket_name) { if (connection.target_node_index == 0
&& connection.target_socket_name == socket_name) {
return connection.source_node_index; return connection.source_node_index;
} }
} }
std::cerr << "Error: could not find a node connected to output '" << socket_name << "'." << std::endl; std::cerr << "Error: could not find a node connected to output '"
<< socket_name << "'." << std::endl;
return -1; return -1;
} }
@ -117,12 +125,14 @@ struct BlendTreeResource {
size_t GetNodeIndexForInputSocket(const std::string& socket_name) const { size_t GetNodeIndexForInputSocket(const std::string& socket_name) const {
for (size_t i = 0; i < m_connections.size(); i++) { for (size_t i = 0; i < m_connections.size(); i++) {
const BlendTreeConnectionResource& connection = m_connections[i]; const BlendTreeConnectionResource& connection = m_connections[i];
if (connection.source_node_index == 1 && connection.source_socket_name == socket_name) { if (connection.source_node_index == 1
&& connection.source_socket_name == socket_name) {
return connection.target_node_index; return connection.target_node_index;
} }
} }
std::cerr << "Error: could not find a node connected to input '" << socket_name << "'." << std::endl; std::cerr << "Error: could not find a node connected to input '"
<< socket_name << "'." << std::endl;
return -1; return -1;
} }
@ -140,7 +150,7 @@ struct StateMachineResource {
std::vector<StateMachineTransitionResources> m_transitions; std::vector<StateMachineTransitionResources> m_transitions;
}; };
struct AnimGraphResource: AnimNodeResource { struct AnimGraphResource : AnimNodeResource {
std::string m_graph_type_name; std::string m_graph_type_name;
BlendTreeResource m_blend_tree_resource; BlendTreeResource m_blend_tree_resource;

View File

@ -2,7 +2,6 @@
// Created by martin on 04.02.22. // Created by martin on 04.02.22.
// //
#include "AnimGraph/AnimGraph.h"
#include "AnimGraph/AnimGraphBlendTree.h" #include "AnimGraph/AnimGraphBlendTree.h"
#include "AnimGraph/AnimGraphEditor.h" #include "AnimGraph/AnimGraphEditor.h"
#include "AnimGraph/AnimGraphNodes.h" #include "AnimGraph/AnimGraphNodes.h"