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,29 +30,22 @@ void AnimSamplerNode::Evaluate(ozz::vector<ozz::math::SoaTransform>* local_matri
} }
} }
void AnimSamplerNode::DrawDebugUi() { void AnimSamplerNode::DrawDebugUi() {
std::string node_name = "AnimSamplerNode: " + m_name; const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh;
if (ImGui::TreeNode(node_name.c_str())) { int anim_count = skinned_mesh->m_animation_names.size();
const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh; const char* items[255] = {0};
int anim_count = skinned_mesh->m_animation_names.size(); int item_current = 0;
const char* items[255] = {0}; for (int i = 0; i < anim_count; i++) {
int item_current = 0; items[i] = skinned_mesh->m_animation_names[i].c_str();
for (int i = 0; i < anim_count; i++) { if (skinned_mesh->m_animations[i] == m_animation) {
items[i] = skinned_mesh->m_animation_names[i].c_str(); item_current = i;
if (skinned_mesh->m_animations[i] == m_animation) {
item_current = i;
}
} }
if (ImGui::Combo("Animation", &item_current, items, anim_count)) {
m_animation = skinned_mesh->m_animations[item_current];
}
ImGui::Checkbox("Override", &m_override_ratio);
ImGui::SameLine();
ImGui::SliderFloat("Ratio", &m_anim_ratio, 0.f, 1.f);
ImGui::TreePop();
} }
if (ImGui::Combo("Animation", &item_current, items, anim_count)) {
m_animation = skinned_mesh->m_animations[item_current];
}
ImGui::Checkbox("Override", &m_override_ratio);
ImGui::SameLine();
ImGui::SliderFloat("Ratio", &m_anim_ratio, 0.f, 1.f);
} }

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; ImGui::SliderFloat("Weight", &m_weight, 0.f, 1.f);
if (ImGui::TreeNode(node_name.c_str())) { ImGui::Checkbox("Sync Inputs", &m_sync_inputs);
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::Checkbox("Sync Inputs", &m_sync_inputs);
ImGui::TreePop();
}
} }

View File

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

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::Text("Name"); ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Text("Synced"); ImGui::NextColumn(); ImGui::Text("Synced");
ImGui::Text("Duration"); ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Text("Time"); 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(
selected = i; node->m_name.c_str(),
bool hovered = ImGui::IsItemHovered(); selected == i,
ImGui::NextColumn(); ImGuiSelectableFlags_SpanAllColumns))
selected = i;
bool hovered = ImGui::IsItemHovered();
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::PopID(); ImGui::NextColumn();
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::PopID(); ImGui::NextColumn();
} ImGui::PopID();
ImGui::Columns(1);
ImGui::Separator();
ImGui::TreePop();
} }
ImGui::Columns(1);
ImGui::Separator();
ImGui::End(); ImGui::End();
} }