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 55 additions and 14 deletions
Showing only changes of commit 57a8e385e4 - Show all commits

View File

@ -60,6 +60,7 @@ enum class AssetType : AssetTypeMeta
AUDIO_BANK,
ANIM_CONTAINER,
ANIM_CLIP,
ANIM_CONTROLLER,
MAX_COUNT
};
constexpr size_t TYPE_COUNT{ static_cast<size_t>(AssetType::MAX_COUNT) };
@ -82,6 +83,7 @@ constexpr std::string_view SCENE_FOLDER{ "/Scenes/" };
constexpr std::string_view PREFAB_FOLDER{ "/Prefabs/" };
constexpr std::string_view MATERIAL_FOLDER{ "/Materials/" };
constexpr std::string_view ANIM_CLIP_FOLDER{ "/Animations/" };
constexpr std::string_view ANIM_CONTROLLER_FOLDER{ "/Animation Controllers/" };
// ASSET EXTENSIONS
@ -99,6 +101,7 @@ constexpr std::string_view MATERIAL_EXTENSION {".shmat"};
constexpr std::string_view TEXTURE_EXTENSION {".shtex"};
constexpr std::string_view MODEL_EXTENSION{ ".shmodel" };
constexpr std::string_view ANIM_CONTAINER_EXTENSION{ ".shanimcontainer" };
constexpr std::string_view ANIM_CONTROLLER_EXTENSION{ ".shanimcontroller" };
constexpr std::string_view FILLER_EXTENSION{"dummy"};
constexpr std::string_view EXTENSIONS[] = {
@ -115,6 +118,7 @@ constexpr std::string_view EXTENSIONS[] = {
FONT_EXTENSION,
AUDIO_BANK_EXTENSION,
ANIM_CONTAINER_EXTENSION,
ANIM_CONTROLLER_EXTENSION,
FILLER_EXTENSION
};

View File

@ -640,23 +640,29 @@ namespace SHADE
if (ImGui::CollapsingHeader(componentType.get_name().data()))
{
DrawContextMenu(component);
/* Animation Rig */
Handle<SHRig> const& rig = component->GetRig();
const auto RIG_NAME = rig ? SHResourceManager::GetAssetName<SHRig>(rig).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Rig", RIG_NAME, [component]()
{
Handle<SHRig> const& rig = component->GetRig();
return SHResourceManager::GetAssetID<SHRig>(rig).value_or(0);
},
[component](AssetID const& id)
{
if (SHAssetManager::GetType(id) != AssetType::MODEL)
SHEditorWidgets::DragDropReadOnlyField<AssetID>
(
"Rig", RIG_NAME, [component]()
{
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!")
return;
}
component->SetRig(SHResourceManager::LoadOrGet<SHRig>(id));
SHResourceManager::FinaliseChanges();
}, SHDragDrop::DRAG_RESOURCE);
Handle<SHRig> const& rig = component->GetRig();
return SHResourceManager::GetAssetID<SHRig>(rig).value_or(0);
},
[component](AssetID const& id)
{
if (SHAssetManager::GetType(id) != AssetType::MODEL)
{
SHLOG_WARNING("Attempted to assign non mesh rig asset to Animator Rig property!")
return;
}
component->SetRig(SHResourceManager::LoadOrGet<SHRig>(id));
SHResourceManager::FinaliseChanges();
},
SHDragDrop::DRAG_RESOURCE
);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHRig> const& rig = component->GetRig())
@ -665,6 +671,37 @@ namespace SHADE
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
/* Animation Controller */
Handle<SHAnimationController> animController = component->GetAnimationController();
const auto AC_NAME = animController ? SHResourceManager::GetAssetName<SHAnimationController>(animController).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>
(
"Animation Controller", AC_NAME, [component]()
{
Handle<SHAnimationController> ac = component->GetAnimationController();
return SHResourceManager::GetAssetID<SHAnimationController>(ac).value_or(0);
},
[component](AssetID const& id)
{
if (SHAssetManager::GetType(id) != AssetType::ANIM_CONTROLLER)
{
SHLOG_WARNING("Attempted to assign non animation controller asset to Animator Animation Controller property!")
return;
}
component->SetAnimationController(SHResourceManager::LoadOrGet<SHAnimationController>(id));
SHResourceManager::FinaliseChanges();
},
SHDragDrop::DRAG_RESOURCE
);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHAnimationController> ac = component->GetAnimationController())
{
AssetID assetID = SHResourceManager::GetAssetID<SHAnimationController>(ac).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
}
else
{