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/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,7 +147,10 @@ namespace SHADE
|
|||
prompt->isOpen = true;
|
||||
}
|
||||
|
||||
// Render all clips
|
||||
// Render all animation clips
|
||||
if (SHEditorUI::CollapsingHeader("Existing Animation Clips"))
|
||||
{
|
||||
ImGui::Indent();
|
||||
for (auto animClip : childAnimClips)
|
||||
{
|
||||
bool changed = false;
|
||||
|
@ -155,21 +159,28 @@ namespace SHADE
|
|||
int firstIndex = animClip->GetStartFrameIndex();
|
||||
int endIndex = animClip->GetEndFrameIndex();
|
||||
|
||||
ImGui::Separator();
|
||||
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();
|
||||
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)
|
||||
if (changed && firstIndex < endIndex)
|
||||
{
|
||||
// Update runtime asset
|
||||
*animClip = SHAnimationClip(currRawAnim, firstIndex, endIndex);
|
||||
|
||||
// Update serialized asset
|
||||
auto assetId = SHResourceManager::GetAssetID(animClip);
|
||||
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();
|
||||
}
|
||||
|
@ -202,6 +220,10 @@ namespace SHADE
|
|||
{
|
||||
childAnimClips = getChildAnimClips(assetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
childAnimClips.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -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>)
|
||||
|
|
Loading…
Reference in New Issue