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/SHEditorUI.h"
#include "Assets/SHAssetManager.h"
#include "Editor/SHEditorWidgets.hpp"
namespace SHADE
{
@ -133,7 +134,7 @@ namespace SHADE
drawMenuBar();
// 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>();
prompt->Init(currRawAnim, [this](AssetID createdAssetId)
@ -146,39 +147,56 @@ namespace SHADE
prompt->isOpen = true;
}
// Render all clips
for (auto animClip : childAnimClips)
// Render all animation clips
if (SHEditorUI::CollapsingHeader("Existing Animation Clips"))
{
bool changed = false;
std::optional<std::string> animClipName = SHResourceManager::GetAssetName<SHAnimationClip>(animClip);
int firstIndex = animClip->GetStartFrameIndex();
int endIndex = animClip->GetEndFrameIndex();
ImGui::Text(animClipName.has_value() ? animClipName.value().c_str() : "");
ImGui::SameLine();
SHEditorUI::PushID(0);
changed |= SHEditorUI::InputInt("", firstIndex);
SHEditorUI::PopID();
ImGui::SameLine();
ImGui::Text(" - ");
ImGui::SameLine();
SHEditorUI::PushID(1);
changed |= SHEditorUI::InputInt("", endIndex);
SHEditorUI::PopID();
// If there's a change we need to commit changes
if (changed)
ImGui::Indent();
for (auto animClip : childAnimClips)
{
auto assetId = SHResourceManager::GetAssetID(animClip);
if (assetId.has_value())
bool changed = false;
std::optional<std::string> animClipName = SHResourceManager::GetAssetName<SHAnimationClip>(animClip);
int firstIndex = animClip->GetStartFrameIndex();
int endIndex = animClip->GetEndFrameIndex();
ImGui::Separator();
ImGui::Text(animClipName.has_value() ? animClipName.value().c_str() : "");
changed |= SHEditorWidgets::SliderInt
(
"Start", 0, currRawAnim->GetTotalFrames(),
[&]() { return firstIndex; },
[&](int i) { firstIndex = i; }
);
changed |= SHEditorWidgets::SliderInt
(
"End", 0, currRawAnim->GetTotalFrames(),
[&]() { return endIndex; },
[&](int i) { endIndex = i; }
);
// If there's a change we need to commit changes
if (changed && firstIndex < endIndex)
{
auto animAsset = SHAssetManager::GetData<SHAnimClipAsset>(assetId.value());
animAsset->firstIndex = firstIndex;
animAsset->lastIndex = endIndex;
SHAssetManager::SaveAsset(assetId.value());
// Update runtime asset
*animClip = SHAnimationClip(currRawAnim, firstIndex, endIndex);
// Update serialized asset
auto assetId = SHResourceManager::GetAssetID(animClip);
if (assetId.has_value())
{
auto animAsset = SHAssetManager::GetData<SHAnimClipAsset>(assetId.value());
animAsset->firstIndex = firstIndex;
animAsset->lastIndex = endIndex;
SHAssetManager::SaveAsset(assetId.value());
}
}
}
// Extra separator if there is more than one
if (!childAnimClips.empty())
ImGui::Separator();
ImGui::Unindent();
}
}
ImGui::End();
@ -202,6 +220,10 @@ namespace SHADE
{
childAnimClips = getChildAnimClips(assetId);
}
else
{
childAnimClips.clear();
}
}
/*-----------------------------------------------------------------------------------*/

View File

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