Implemented Animation Clip asset and animation controller #410

Merged
XiaoQiDigipen merged 66 commits from SP3-22-AnimationController into main 2023-03-09 16:19:40 +08:00
2 changed files with 53 additions and 29 deletions
Showing only changes of commit 41784d4c04 - Show all commits

View File

@ -25,6 +25,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Editor/EditorWindow/SHEditorWindowManager.h" #include "Editor/EditorWindow/SHEditorWindowManager.h"
#include "Editor/SHEditorUI.h" #include "Editor/SHEditorUI.h"
#include "Assets/SHAssetManager.h" #include "Assets/SHAssetManager.h"
#include "Editor/SHEditorWidgets.hpp"
namespace SHADE namespace SHADE
{ {
@ -133,7 +134,7 @@ namespace SHADE
drawMenuBar(); drawMenuBar();
// Button to add a new clip // Button to add a new clip
if (ImGui::Button(std::format("{} Add", ICON_MD_ADD).data())) if (ImGui::Button(std::format("{} Create Animation Clip", ICON_MD_ADD).data()))
{ {
auto prompt = SHEditorWindowManager::GetPopupWindow<SHAnimClipCreatePrompt>(); auto prompt = SHEditorWindowManager::GetPopupWindow<SHAnimClipCreatePrompt>();
prompt->Init(currRawAnim, [this](AssetID createdAssetId) prompt->Init(currRawAnim, [this](AssetID createdAssetId)
@ -146,7 +147,10 @@ namespace SHADE
prompt->isOpen = true; prompt->isOpen = true;
} }
// Render all clips // Render all animation clips
if (SHEditorUI::CollapsingHeader("Existing Animation Clips"))
{
ImGui::Indent();
for (auto animClip : childAnimClips) for (auto animClip : childAnimClips)
{ {
bool changed = false; bool changed = false;
@ -155,21 +159,28 @@ namespace SHADE
int firstIndex = animClip->GetStartFrameIndex(); int firstIndex = animClip->GetStartFrameIndex();
int endIndex = animClip->GetEndFrameIndex(); int endIndex = animClip->GetEndFrameIndex();
ImGui::Separator();
ImGui::Text(animClipName.has_value() ? animClipName.value().c_str() : ""); ImGui::Text(animClipName.has_value() ? animClipName.value().c_str() : "");
ImGui::SameLine(); changed |= SHEditorWidgets::SliderInt
SHEditorUI::PushID(0); (
changed |= SHEditorUI::InputInt("", firstIndex); "Start", 0, currRawAnim->GetTotalFrames(),
SHEditorUI::PopID(); [&]() { return firstIndex; },
ImGui::SameLine(); [&](int i) { firstIndex = i; }
ImGui::Text(" - "); );
ImGui::SameLine(); changed |= SHEditorWidgets::SliderInt
SHEditorUI::PushID(1); (
changed |= SHEditorUI::InputInt("", endIndex); "End", 0, currRawAnim->GetTotalFrames(),
SHEditorUI::PopID(); [&]() { return endIndex; },
[&](int i) { endIndex = i; }
);
// If there's a change we need to commit changes // If there's a change we need to commit changes
if (changed) if (changed && firstIndex < endIndex)
{ {
// Update runtime asset
*animClip = SHAnimationClip(currRawAnim, firstIndex, endIndex);
// Update serialized asset
auto assetId = SHResourceManager::GetAssetID(animClip); auto assetId = SHResourceManager::GetAssetID(animClip);
if (assetId.has_value()) if (assetId.has_value())
{ {
@ -180,6 +191,13 @@ namespace SHADE
} }
} }
} }
// Extra separator if there is more than one
if (!childAnimClips.empty())
ImGui::Separator();
ImGui::Unindent();
}
} }
ImGui::End(); ImGui::End();
} }
@ -202,6 +220,10 @@ namespace SHADE
{ {
childAnimClips = getChildAnimClips(assetId); childAnimClips = getChildAnimClips(assetId);
} }
else
{
childAnimClips.clear();
}
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -361,6 +361,8 @@ namespace SHADE
else if constexpr (std::is_same_v<ResourceType, SHRawAnimation>) else if constexpr (std::is_same_v<ResourceType, SHRawAnimation>)
{ {
loadedAssetData.emplace_back(assetId); loadedAssetData.emplace_back(assetId);
if (assetData.anims.empty())
return {};
return resourceHub.Create<ResourceType>(*assetData.anims[0]); return resourceHub.Create<ResourceType>(*assetData.anims[0]);
} }
else if constexpr (std::is_same_v<ResourceType, SHAnimationClip>) else if constexpr (std::is_same_v<ResourceType, SHAnimationClip>)