Added code to evaluate node ordering for spanning tree of blend tree.

AnimGraphEditor
Martin Felis 2021-11-12 22:12:25 +01:00
parent 1f858d68c0
commit c659caebb9
10 changed files with 44 additions and 12 deletions

View File

@ -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

View File

@ -28,6 +28,8 @@ struct AnimNode {
virtual void Evaluate(ozz::vector<ozz::math::SoaTransform>* local_matrices) = 0;
virtual void CollectNodeOrdering (std::vector<AnimNode*>& anim_nodes) = 0;
virtual void DrawDebugUi() {};
};

View File

@ -3,10 +3,11 @@
//
#include "AnimSamplerNode.h"
#include "SkinnedMesh.h"
#include <imgui.h>
#include "../SkinnedMesh.h"
void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation) {
m_animation = animation;

View File

@ -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<ozz::math::SoaTransform>* local_matrices) override;
virtual void CollectNodeOrdering(
std::vector<AnimNode*>& anim_nodes) override {
anim_nodes.push_back(this);
};
virtual void DrawDebugUi();
};

View File

@ -4,10 +4,10 @@
#include "BlendNode.h"
#include <imgui.h>
#include <ozz/animation/runtime/blending_job.h>
#include "SkinnedMesh.h"
#include <imgui.h>
#include "../SkinnedMesh.h"
BlendNode::BlendNode(AnimationController* animation_controller)
: AnimNode(animation_controller),

View File

@ -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<ozz::math::SoaTransform>* local_matrices) override;
virtual void CollectNodeOrdering (std::vector<AnimNode*>& anim_nodes) override {
anim_nodes.push_back(this);
m_input_A->CollectNodeOrdering(anim_nodes);
m_input_B->CollectNodeOrdering(anim_nodes);
}
virtual void DrawDebugUi();
};

View File

@ -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<AnimNode*>& anim_nodes) override {
anim_nodes.push_back(this);
m_input_node->CollectNodeOrdering(anim_nodes);
}
virtual void DrawDebugUi() override;
};

View File

@ -9,10 +9,10 @@
#include <ozz/animation/runtime/local_to_model_job.h>
#include <ozz/animation/runtime/sampling_job.h>
#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();
}

View File

@ -44,6 +44,7 @@ struct AnimationController {
AnimNode* m_output_node;
std::vector<AnimNode*> m_anim_nodes;
std::vector<AnimNode*> m_ordered_nodes;
};
#endif //ANIMTESTBED_ANIMATIONCONTROLLER_H