From c659caebb93cdbc86074dac2bfbaa538793a6873 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 12 Nov 2021 22:12:25 +0100 Subject: [PATCH] Added code to evaluate node ordering for spanning tree of blend tree. --- CMakeLists.txt | 6 +++--- src/AnimNode.h | 2 ++ src/{ => AnimNodes}/AnimSamplerNode.cc | 3 ++- src/{ => AnimNodes}/AnimSamplerNode.h | 7 ++++++- src/{ => AnimNodes}/BlendNode.cc | 4 ++-- src/{ => AnimNodes}/BlendNode.h | 8 +++++++- src/{ => AnimNodes}/SpeedScaleNode.cc | 0 src/{ => AnimNodes}/SpeedScaleNode.h | 7 ++++++- src/AnimationController.cc | 18 +++++++++++++++--- src/AnimationController.h | 1 + 10 files changed, 44 insertions(+), 12 deletions(-) rename src/{ => AnimNodes}/AnimSamplerNode.cc (98%) rename src/{ => AnimNodes}/AnimSamplerNode.h (86%) rename src/{ => AnimNodes}/BlendNode.cc (98%) rename src/{ => AnimNodes}/BlendNode.h (75%) rename src/{ => AnimNodes}/SpeedScaleNode.cc (100%) rename src/{ => AnimNodes}/SpeedScaleNode.h (78%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1d67c1..f246bf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,9 +47,9 @@ target_sources(AnimTestbed PRIVATE src/SkinnedMesh.cc src/SkinnedMesh.h src/AnimNode.cc - src/AnimSamplerNode.cc - src/SpeedScaleNode.cc - src/BlendNode.cc + src/AnimNodes/AnimSamplerNode.cc + src/AnimNodes/SpeedScaleNode.cc + src/AnimNodes/BlendNode.cc src/AnimationController.cc 3rdparty/glfw/deps/glad_gl.c 3rdparty/imgui/imgui.cpp diff --git a/src/AnimNode.h b/src/AnimNode.h index 14ac761..283fda0 100644 --- a/src/AnimNode.h +++ b/src/AnimNode.h @@ -28,6 +28,8 @@ struct AnimNode { virtual void Evaluate(ozz::vector* local_matrices) = 0; + virtual void CollectNodeOrdering (std::vector& anim_nodes) = 0; + virtual void DrawDebugUi() {}; }; diff --git a/src/AnimSamplerNode.cc b/src/AnimNodes/AnimSamplerNode.cc similarity index 98% rename from src/AnimSamplerNode.cc rename to src/AnimNodes/AnimSamplerNode.cc index 13b4f54..97b4ea9 100644 --- a/src/AnimSamplerNode.cc +++ b/src/AnimNodes/AnimSamplerNode.cc @@ -3,10 +3,11 @@ // #include "AnimSamplerNode.h" -#include "SkinnedMesh.h" #include +#include "../SkinnedMesh.h" + void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation) { m_animation = animation; diff --git a/src/AnimSamplerNode.h b/src/AnimNodes/AnimSamplerNode.h similarity index 86% rename from src/AnimSamplerNode.h rename to src/AnimNodes/AnimSamplerNode.h index 39b948e..5746cb7 100644 --- a/src/AnimSamplerNode.h +++ b/src/AnimNodes/AnimSamplerNode.h @@ -5,7 +5,7 @@ #ifndef ANIMTESTBED_ANIMSAMPLERNODE_H #define ANIMTESTBED_ANIMSAMPLERNODE_H -#include "AnimNode.h" +#include "../AnimNode.h" struct AnimSamplerNode : public AnimNode { AnimSamplerNode(AnimationController* animation_controller) @@ -33,6 +33,11 @@ struct AnimSamplerNode : public AnimNode { virtual void Evaluate( ozz::vector* local_matrices) override; + virtual void CollectNodeOrdering( + std::vector& anim_nodes) override { + anim_nodes.push_back(this); + }; + virtual void DrawDebugUi(); }; diff --git a/src/BlendNode.cc b/src/AnimNodes/BlendNode.cc similarity index 98% rename from src/BlendNode.cc rename to src/AnimNodes/BlendNode.cc index f7f70f3..4e4a6e3 100644 --- a/src/BlendNode.cc +++ b/src/AnimNodes/BlendNode.cc @@ -4,10 +4,10 @@ #include "BlendNode.h" +#include #include -#include "SkinnedMesh.h" -#include +#include "../SkinnedMesh.h" BlendNode::BlendNode(AnimationController* animation_controller) : AnimNode(animation_controller), diff --git a/src/BlendNode.h b/src/AnimNodes/BlendNode.h similarity index 75% rename from src/BlendNode.h rename to src/AnimNodes/BlendNode.h index 64b53c2..dff4bf5 100644 --- a/src/BlendNode.h +++ b/src/AnimNodes/BlendNode.h @@ -5,7 +5,7 @@ #ifndef ANIMTESTBED_BLENDNODE_H #define ANIMTESTBED_BLENDNODE_H -#include "AnimNode.h" +#include "../AnimNode.h" struct BlendNode : public AnimNode { BlendNode(AnimationController* animation_controller); @@ -30,6 +30,12 @@ struct BlendNode : public AnimNode { virtual void Evaluate( ozz::vector* local_matrices) override; + virtual void CollectNodeOrdering (std::vector& anim_nodes) override { + anim_nodes.push_back(this); + m_input_A->CollectNodeOrdering(anim_nodes); + m_input_B->CollectNodeOrdering(anim_nodes); + } + virtual void DrawDebugUi(); }; diff --git a/src/SpeedScaleNode.cc b/src/AnimNodes/SpeedScaleNode.cc similarity index 100% rename from src/SpeedScaleNode.cc rename to src/AnimNodes/SpeedScaleNode.cc diff --git a/src/SpeedScaleNode.h b/src/AnimNodes/SpeedScaleNode.h similarity index 78% rename from src/SpeedScaleNode.h rename to src/AnimNodes/SpeedScaleNode.h index f5c0a05..6d614d6 100644 --- a/src/SpeedScaleNode.h +++ b/src/AnimNodes/SpeedScaleNode.h @@ -5,7 +5,7 @@ #ifndef ANIMTESTBED_SPEEDSCALENODE_H #define ANIMTESTBED_SPEEDSCALENODE_H -#include "AnimNode.h" +#include "../AnimNode.h" struct SpeedScaleNode : public AnimNode { SpeedScaleNode(AnimationController* animation_controller): AnimNode (animation_controller), m_time_scale(1.f) {} @@ -26,6 +26,11 @@ struct SpeedScaleNode : public AnimNode { m_input_node->Evaluate(local_matrices); }; + virtual void CollectNodeOrdering (std::vector& anim_nodes) override { + anim_nodes.push_back(this); + m_input_node->CollectNodeOrdering(anim_nodes); + } + virtual void DrawDebugUi() override; }; diff --git a/src/AnimationController.cc b/src/AnimationController.cc index 412f07f..baa819d 100644 --- a/src/AnimationController.cc +++ b/src/AnimationController.cc @@ -9,10 +9,10 @@ #include #include -#include "AnimSamplerNode.h" -#include "BlendNode.h" +#include "AnimNodes/AnimSamplerNode.h" +#include "AnimNodes/BlendNode.h" +#include "AnimNodes/SpeedScaleNode.h" #include "SkinnedMesh.h" -#include "SpeedScaleNode.h" AnimationController::AnimationController(SkinnedMesh* skinned_mesh) : m_current_time(0.f), m_skinned_mesh(skinned_mesh) { @@ -49,6 +49,10 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh) m_anim_nodes.push_back(blend_node); m_output_node = blend_node; + + m_output_node->CollectNodeOrdering(m_ordered_nodes); + + std::cout << "Have " << m_ordered_nodes.size() << " nodes in blend tree." << std::endl; m_output_node->Reset(); } @@ -99,5 +103,13 @@ void AnimationController::DrawDebugUi() { ImGui::TreePop(); } + if (m_output_node && ImGui::TreeNode("Nodes")) { + for (int i = 0; i < m_ordered_nodes.size(); i++) { + ImGui::Text(m_ordered_nodes[i]->m_name.c_str()); + } + + ImGui::TreePop(); + } + ImGui::End(); } \ No newline at end of file diff --git a/src/AnimationController.h b/src/AnimationController.h index 672fa79..c57008c 100644 --- a/src/AnimationController.h +++ b/src/AnimationController.h @@ -44,6 +44,7 @@ struct AnimationController { AnimNode* m_output_node; std::vector m_anim_nodes; + std::vector m_ordered_nodes; }; #endif //ANIMTESTBED_ANIMATIONCONTROLLER_H