Implemented node like debug gui for anim nodes.

AnimGraphEditor
Martin Felis 2021-11-16 21:17:52 +01:00
parent 1cfba1c388
commit 5e6e81b60b
4 changed files with 73 additions and 91 deletions

View File

@ -18,9 +18,8 @@ void AnimSamplerNode::SetAnimation(ozz::animation::Animation* animation) {
m_sampling_cache.Resize(num_joints); m_sampling_cache.Resize(num_joints);
} }
void AnimSamplerNode::Evaluate(
ozz::vector<ozz::math::SoaTransform>* local_matrices) {
void AnimSamplerNode::Evaluate(ozz::vector<ozz::math::SoaTransform>* local_matrices) {
ozz::animation::SamplingJob sampling_job; ozz::animation::SamplingJob sampling_job;
sampling_job.animation = m_animation; sampling_job.animation = m_animation;
sampling_job.cache = &m_sampling_cache; sampling_job.cache = &m_sampling_cache;
@ -31,11 +30,7 @@ void AnimSamplerNode::Evaluate(ozz::vector<ozz::math::SoaTransform>* local_matri
} }
} }
void AnimSamplerNode::DrawDebugUi() { void AnimSamplerNode::DrawDebugUi() {
std::string node_name = "AnimSamplerNode: " + m_name;
if (ImGui::TreeNode(node_name.c_str())) {
const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh; const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh;
int anim_count = skinned_mesh->m_animation_names.size(); int anim_count = skinned_mesh->m_animation_names.size();
const char* items[255] = {0}; const char* items[255] = {0};
@ -53,7 +48,4 @@ void AnimSamplerNode::DrawDebugUi() {
ImGui::Checkbox("Override", &m_override_ratio); ImGui::Checkbox("Override", &m_override_ratio);
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("Ratio", &m_anim_ratio, 0.f, 1.f); ImGui::SliderFloat("Ratio", &m_anim_ratio, 0.f, 1.f);
ImGui::TreePop();
}
} }

View File

@ -49,14 +49,6 @@ void BlendNode::Evaluate(ozz::vector<ozz::math::SoaTransform>* local_matrices) {
} }
void BlendNode::DrawDebugUi() { void BlendNode::DrawDebugUi() {
std::string node_name = "BlendNode: " + m_name;
if (ImGui::TreeNode(node_name.c_str())) {
ImGui::Text("Input A:");
m_input_A->DrawDebugUi();
ImGui::Text("Input B:");
m_input_B->DrawDebugUi();
ImGui::SliderFloat("Weight", &m_weight, 0.f, 1.f); ImGui::SliderFloat("Weight", &m_weight, 0.f, 1.f);
ImGui::Checkbox("Sync Inputs", &m_sync_inputs); ImGui::Checkbox("Sync Inputs", &m_sync_inputs);
ImGui::TreePop();
}
} }

View File

@ -7,8 +7,6 @@
#include <imgui.h> #include <imgui.h>
void SpeedScaleNode::DrawDebugUi() { void SpeedScaleNode::DrawDebugUi() {
std::string node_name = "SpeedScaleNode: " + m_name;
if (ImGui::TreeNode(node_name.c_str())) {
bool is_negative = m_time_scale < 0.f; bool is_negative = m_time_scale < 0.f;
if (ImGui::Checkbox("Reverse Time", &is_negative)) { if (ImGui::Checkbox("Reverse Time", &is_negative)) {
m_time_scale = m_time_scale * -1.f; m_time_scale = m_time_scale * -1.f;
@ -19,9 +17,4 @@ void SpeedScaleNode::DrawDebugUi() {
ImGui::SliderFloat("Time Scale", &m_time_scale, 0.01f, 5.f); ImGui::SliderFloat("Time Scale", &m_time_scale, 0.01f, 5.f);
// and back to the original negative or positive sign // and back to the original negative or positive sign
m_time_scale = m_time_scale * (is_negative ? -1.f : 1.f); m_time_scale = m_time_scale * (is_negative ? -1.f : 1.f);
m_input_node->DrawDebugUi();
ImGui::TreePop();
}
} }

View File

@ -61,8 +61,6 @@ AnimationController::AnimationController(SkinnedMesh* skinned_mesh)
m_output_node->Reset(); m_output_node->Reset();
} }
AnimationController::~AnimationController() { AnimationController::~AnimationController() {
while (m_anim_nodes.size() > 0) { while (m_anim_nodes.size() > 0) {
delete m_anim_nodes[m_anim_nodes.size() - 1]; delete m_anim_nodes[m_anim_nodes.size() - 1];
@ -97,9 +95,7 @@ void AnimationController::UpdateOrderedNodes() {
} }
} }
void AnimationController::UpdateBlendLogic() { void AnimationController::UpdateBlendLogic() {}
}
void AnimationController::UpdateTime(float dt) { void AnimationController::UpdateTime(float dt) {
if (m_output_node == nullptr) { if (m_output_node == nullptr) {
@ -121,8 +117,6 @@ void AnimationController::UpdateTime(float dt) {
m_output_node->UpdateTime(dt); m_output_node->UpdateTime(dt);
} }
void AnimationController::Evaluate() { void AnimationController::Evaluate() {
if (m_output_node == nullptr) { if (m_output_node == nullptr) {
return; return;
@ -137,8 +131,6 @@ void AnimationController::Evaluate() {
ltm_job.Run(); ltm_job.Run();
}; };
void AnimationController::DrawDebugUi() { void AnimationController::DrawDebugUi() {
ImGui::SetNextWindowSize(ImVec2(500, 300), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(500, 300), ImGuiCond_FirstUseEver);
ImGui::Begin("AnimationController"); ImGui::Begin("AnimationController");
@ -147,46 +139,59 @@ void AnimationController::DrawDebugUi() {
ResetAnims(); ResetAnims();
} }
if (m_output_node && ImGui::TreeNode("Output")) { ImVec2 node_size(200, 100);
m_output_node->DrawDebugUi(); for (int i = 0; i < m_ordered_nodes.size(); i++) {
AnimNode* node = m_ordered_nodes[i];
ImGui::TreePop(); ImGui::SetNextWindowSize(node_size, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos(
ImVec2((m_ordered_nodes.size() - 1 - i) * node_size.x - i * 10, 300),
ImGuiCond_FirstUseEver);
ImGui::Begin(node->m_name.c_str());
node->DrawDebugUi();
ImGui::End();
} }
if (m_output_node && ImGui::TreeNode("Nodes")) { ImGui::Columns(4, "Node States"); // 4-ways, with border
ImGui::Columns(4, "NodeOverview"); // 4-ways, with border
ImGui::Separator(); ImGui::Separator();
ImGui::Text("Name"); ImGui::NextColumn(); ImGui::Text("Name");
ImGui::Text("Synced"); ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Text("Duration"); ImGui::NextColumn(); ImGui::Text("Synced");
ImGui::Text("Time"); ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Text("Duration");
ImGui::NextColumn();
ImGui::Text("Time");
ImGui::NextColumn();
ImGui::Separator(); ImGui::Separator();
static int selected = -1; static int selected = -1;
for (int i = 0; i < m_ordered_nodes.size(); i++) { for (int i = 0; i < m_ordered_nodes.size(); i++) {
AnimNode* node = m_ordered_nodes[i]; AnimNode* node = m_ordered_nodes[i];
if (ImGui::Selectable(node->m_name.c_str(), selected == i, ImGuiSelectableFlags_SpanAllColumns)) if (ImGui::Selectable(
node->m_name.c_str(),
selected == i,
ImGuiSelectableFlags_SpanAllColumns))
selected = i; selected = i;
bool hovered = ImGui::IsItemHovered(); bool hovered = ImGui::IsItemHovered();
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Text(node->m_is_time_synced ? "X" : "-"); ImGui::NextColumn(); ImGui::Text(node->m_is_time_synced ? "X" : "-");
ImGui::NextColumn();
ImGui::PushID((void*)&node->m_anim_duration); ImGui::PushID((void*)&node->m_anim_duration);
ImGui::Text("%2.3f", node->m_anim_duration); ImGui::NextColumn(); ImGui::Text("%2.3f", node->m_anim_duration);
ImGui::NextColumn();
ImGui::PopID(); ImGui::PopID();
ImGui::PushID((void*)&node->m_current_time); ImGui::PushID((void*)&node->m_current_time);
ImGui::Text("%2.3f", node->m_current_time); ImGui::NextColumn(); ImGui::Text("%2.3f", node->m_current_time);
ImGui::NextColumn();
ImGui::PopID(); ImGui::PopID();
} }
ImGui::Columns(1); ImGui::Columns(1);
ImGui::Separator(); ImGui::Separator();
ImGui::TreePop();
}
ImGui::End(); ImGui::End();
} }