Split keyframes on animation editor into their constituents

This commit is contained in:
Kah Wei 2023-01-16 16:12:46 +08:00
parent 52913562e7
commit 26f84fb8d6
3 changed files with 70 additions and 12 deletions

View File

@ -13,10 +13,6 @@ of DigiPen Institute of Technology is prohibited.
#include "SHpch.h" #include "SHpch.h"
// Primary Header // Primary Header
#include "SHAnimationEditor.h" #include "SHAnimationEditor.h"
// External Dependencies
#include <imgui.h>
#include "Editor/IconsMaterialDesign.h"
#include "Editor/SHEditorUI.h"
namespace SHADE namespace SHADE
{ {
@ -165,17 +161,19 @@ namespace SHADE
{ {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text(channel.Name.c_str()); const bool SHOW_ALL = ImGui::CollapsingHeader(channel.Name.c_str(), ImGuiTreeNodeFlags_DefaultOpen);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
// Draw all the keyframes if (SHOW_ALL)
const auto START_POS = ImGui::GetCursorPos();
for (const auto& keyframe : channel.PositionKeyFrames)
{ {
ImGui::SetCursorPos(ImVec2(START_POS.x + keyframe.FrameIndex * DIST_PER_FRAME, START_POS.y)); drawChannelKeyFrames("Position", channel.PositionKeyFrames);
SHEditorUI::OffsetText(ICON_MD_RADIO_BUTTON_CHECKED, 6.0f); // Hardcoded offset to align icon since ImGui can't calculate icon with properly drawChannelKeyFrames("Rotation", channel.RotationKeyFrames);
drawChannelKeyFrames("Scale", channel.ScaleKeyFrames);
}
else
{
// TODO: Show flattened view
} }
ImGui::SetCursorPos(START_POS);
} }
ImGui::EndTable(); ImGui::EndTable();

View File

@ -36,9 +36,22 @@ namespace SHADE
void Update() override; void Update() override;
private: private:
/*---------------------------------------------------------------------------------*/
/* Static Constants */
/*---------------------------------------------------------------------------------*/
static constexpr float DIST_PER_FRAME = 18.0f;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Data Members */ /* Data Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHAnimationClip clip; SHAnimationClip clip;
/*---------------------------------------------------------------------------------*/
/* Helper Functions */
/*---------------------------------------------------------------------------------*/
template<typename T>
void drawChannelKeyFrames(const std::string& name, const std::vector<SHAnimationKeyFrame<T>>& keyframes);
}; };
} }
#include "SHAnimationEditor.hpp"

View File

@ -0,0 +1,47 @@
/************************************************************************************//*!
\file SHAnimationEditor.hpp
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Jan 16, 2023
\brief Contains the definition of the SHAnimationEditor function templates.
Copyright (C) 2023 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// Primary Include
#include "SHAnimationEditor.h"
// Project Include
#include "Editor/SHEditorUI.h"
// External Dependencies
#include <imgui.h>
#include "Editor/IconsMaterialDesign.h"
namespace SHADE
{
template<typename T>
void SHAnimationEditor::drawChannelKeyFrames(const std::string& name, const std::vector<SHAnimationKeyFrame<T>>& keyframes)
{
// Ignore if keyframes list is empty
if (keyframes.empty())
return;
// Title
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Indent();
ImGui::Text(name.c_str());
ImGui::Unindent();
ImGui::TableNextColumn();
// Draw all the keyframes
const auto START_POS = ImGui::GetCursorPos();
for (const auto& keyframe : keyframes)
{
ImGui::SetCursorPos(ImVec2(START_POS.x + keyframe.FrameIndex * DIST_PER_FRAME, START_POS.y));
SHEditorUI::OffsetText(ICON_MD_RADIO_BUTTON_CHECKED, 6.0f); // Hardcoded offset to align icon since ImGui can't calculate icon with properly
}
ImGui::SetCursorPos(START_POS);
}
}