Implemented Animation Clip asset and animation controller #410
|
@ -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,39 +147,56 @@ namespace SHADE
|
||||||
prompt->isOpen = true;
|
prompt->isOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render all clips
|
// Render all animation clips
|
||||||
for (auto animClip : childAnimClips)
|
if (SHEditorUI::CollapsingHeader("Existing Animation Clips"))
|
||||||
{
|
{
|
||||||
bool changed = false;
|
ImGui::Indent();
|
||||||
std::optional<std::string> animClipName = SHResourceManager::GetAssetName<SHAnimationClip>(animClip);
|
for (auto animClip : childAnimClips)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
auto assetId = SHResourceManager::GetAssetID(animClip);
|
bool changed = false;
|
||||||
if (assetId.has_value())
|
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());
|
// Update runtime asset
|
||||||
animAsset->firstIndex = firstIndex;
|
*animClip = SHAnimationClip(currRawAnim, firstIndex, endIndex);
|
||||||
animAsset->lastIndex = endIndex;
|
|
||||||
SHAssetManager::SaveAsset(assetId.value());
|
// 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();
|
ImGui::End();
|
||||||
|
@ -202,6 +220,10 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
childAnimClips = getChildAnimClips(assetId);
|
childAnimClips = getChildAnimClips(assetId);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
childAnimClips.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -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>)
|
||||||
|
|
Loading…
Reference in New Issue