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
12 changed files with 38 additions and 37 deletions
Showing only changes of commit ba22638520 - Show all commits

View File

@ -181,7 +181,7 @@ namespace Sandbox
// Link up SHDebugDraw
SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>());
auto clip = SHResourceManager::LoadOrGet<SHAnimationClip>(77816045);
auto clip = SHResourceManager::LoadOrGet<SHAnimationData>(77816045);
auto rig = SHResourceManager::LoadOrGet<SHRig>(77816045);
int i = 0;
}

View File

@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited.
// Project Includes
#include "SH_API.h"
#include "Resource/SHHandle.h"
#include "SHAnimationClip.h"
#include "SHAnimationData.h"
namespace SHADE
{
@ -100,7 +100,7 @@ namespace SHADE
/// </summary>
struct Node
{
Handle<SHAnimationClip> Clip;
Handle<SHAnimationData> Clip;
std::vector<Transition> Transitions;
};

View File

@ -1,9 +1,9 @@
/************************************************************************************//*!
\file SHAnimationClip.cpp
\file SHAnimationData.cpp
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 20, 2022
\brief Contains the function definitions of the SHAnimationClip class.
\brief Contains the function definitions of the SHAnimationData class.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
@ -12,14 +12,14 @@ of DigiPen Institute of Technology is prohibited.
// Pre-compiled Header
#include "SHpch.h"
// Primary Header
#include "SHAnimationClip.h"
#include "SHAnimationData.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------------*/
SHAnimationClip::SHAnimationClip(const SHAnimAsset& asset)
SHAnimationData::SHAnimationData(const SHAnimAsset& asset)
: ticksPerSecond { static_cast<int>(asset.ticksPerSecond) }
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
{

View File

@ -1,9 +1,9 @@
/************************************************************************************//*!
\file SHAnimationClip.h
\file SHAnimationData.h
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Dec 12, 2022
\brief Contains the definition of the SHAnimationClip struct and related types.
\brief Contains the definition of the SHAnimationData struct and related types.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
@ -35,7 +35,7 @@ namespace SHADE
/// Represents a animation clip of a 3D animation that is made for a specific model
/// rig.
/// </summary>
class SH_API SHAnimationClip
class SH_API SHAnimationData
{
public:
/*---------------------------------------------------------------------------------*/
@ -60,7 +60,7 @@ namespace SHADE
/// Constructs an SHAnimation Clip from a specified SHAnimAsset.
/// </summary>
/// <param name="asset">Animation asset to load.</param>
explicit SHAnimationClip(const SHAnimAsset& asset);
explicit SHAnimationData(const SHAnimAsset& asset);
/*---------------------------------------------------------------------------------*/
/* Getter Functions */

View File

@ -15,6 +15,7 @@ of DigiPen Institute of Technology is prohibited.
#include "SH_API.h"
#include "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h"
#include "Resource/SHResourceLibrary.h"
namespace SHADE
{

View File

@ -19,7 +19,7 @@ of DigiPen Institute of Technology is prohibited.
// Project Includes
#include "SHRig.h"
#include "Math/SHMatrix.h"
#include "SHAnimationClip.h"
#include "SHAnimationData.h"
#include "Graphics/SHVkUtil.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "ECS_Base/Managers/SHSystemManager.h"
@ -37,14 +37,14 @@ namespace SHADE
playOnce = false;
}
void SHAnimatorComponent::Play(Handle<SHAnimationClip> clip)
void SHAnimatorComponent::Play(Handle<SHAnimationData> clip)
{
currClip = clip;
currPlaybackTime = 0.0f;
Play();
}
void SHAnimatorComponent::PlayOneShot(Handle<SHAnimationClip> clip)
void SHAnimatorComponent::PlayOneShot(Handle<SHAnimationData> clip)
{
Play(clip);
playOnce = true;
@ -86,7 +86,7 @@ namespace SHADE
}
}
void SHAnimatorComponent::SetClip(Handle<SHAnimationClip> newClip)
void SHAnimatorComponent::SetClip(Handle<SHAnimationData> newClip)
{
// No change
if (currClip == newClip)

View File

@ -22,7 +22,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Math/SHMatrix.h"
#include "Math/Vector/SHVec3.h"
#include "Math/SHQuaternion.h"
#include "SHAnimationClip.h"
#include "SHAnimationData.h"
namespace SHADE
{
@ -31,7 +31,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/
class SHRig;
struct SHRigNode;
class SHAnimationClip;
class SHAnimationData;
class SHVkBuffer;
/*-----------------------------------------------------------------------------------*/
@ -55,12 +55,12 @@ namespace SHADE
/// Plays the specified animation clip from the start.
/// </summary>
/// <param name="clip">Animation clip to play.</param>
void Play(Handle<SHAnimationClip> clip);
void Play(Handle<SHAnimationData> clip);
/// <summary>
/// Plays the specified animation clip from the start one time only.
/// </summary>
/// <param name="clip">Animation clip to play.</param>
void PlayOneShot(Handle<SHAnimationClip> clip);
void PlayOneShot(Handle<SHAnimationData> clip);
/// <summary>
/// Plays the currently loaded animation clip from the start.
/// </summary>
@ -88,7 +88,7 @@ namespace SHADE
/// If the clip is the same as the current clip, nothing happens.
/// </summary>
/// <param name="newClip">Clip to use.</param>
void SetClip(Handle<SHAnimationClip> newClip);
void SetClip(Handle<SHAnimationData> newClip);
/*---------------------------------------------------------------------------------*/
/* Getter Functions */
@ -108,7 +108,7 @@ namespace SHADE
/// Retrieve the currently set animation clip.
/// </summary>
/// <returns>Handle to the currently set animation clip.</returns>
Handle<SHAnimationClip> GetCurrentClip() const noexcept { return currClip; }
Handle<SHAnimationData> GetCurrentClip() const noexcept { return currClip; }
/// <summary>
/// Checks if an animation is currently playing.
/// </summary>
@ -131,7 +131,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
// Resources
Handle<SHRig> rig;
Handle<SHAnimationClip> currClip;
Handle<SHAnimationData> currClip;
// Playback Tracking
float currPlaybackTime = 0.0f;
bool isPlaying = true;
@ -141,7 +141,7 @@ namespace SHADE
// Buffer
std::vector<SHMatrix> boneMatrices;
// Caches
std::unordered_map<std::string, const SHAnimationClip::Channel*> channelMap;
std::unordered_map<std::string, const SHAnimationData::Channel*> channelMap;
/*---------------------------------------------------------------------------------*/
/* Helper Functions */

View File

@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited.
// Project Includes
#include "SHRig.h"
#include "Math/SHMatrix.h"
#include "SHAnimationClip.h"
#include "SHAnimationData.h"
#include "Graphics/SHVkUtil.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "ECS_Base/Managers/SHSystemManager.h"

View File

@ -644,13 +644,13 @@ namespace SHADE
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
Handle<SHAnimationClip> const& clip = component->GetCurrentClip();
const auto CLIP_NAME = clip ? SHResourceManager::GetAssetName<SHAnimationClip>(clip).value_or("") : "";
Handle<SHAnimationData> const& clip = component->GetCurrentClip();
const auto CLIP_NAME = clip ? SHResourceManager::GetAssetName<SHAnimationData>(clip).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Clip", CLIP_NAME,
[component]()
{
Handle<SHAnimationClip> const& clip = component->GetCurrentClip();
return SHResourceManager::GetAssetID<SHAnimationClip>(clip).value_or(0);
Handle<SHAnimationData> const& clip = component->GetCurrentClip();
return SHResourceManager::GetAssetID<SHAnimationData>(clip).value_or(0);
},
[component](AssetID const& id)
{
@ -659,13 +659,13 @@ namespace SHADE
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!")
return;
}
component->SetClip(SHResourceManager::LoadOrGet<SHAnimationClip>(id));
component->SetClip(SHResourceManager::LoadOrGet<SHAnimationData>(id));
}, SHDragDrop::DRAG_RESOURCE);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHAnimationClip> const& clip = component->GetCurrentClip())
if (Handle<SHAnimationData> const& clip = component->GetCurrentClip())
{
AssetID assetID = SHResourceManager::GetAssetID<SHAnimationClip>(clip).value_or(0);
AssetID assetID = SHResourceManager::GetAssetID<SHAnimationData>(clip).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}

View File

@ -28,7 +28,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
#include "Assets/Asset Types/SHMaterialAsset.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
#include "Animation/SHAnimationClip.h"
#include "Animation/SHAnimationData.h"
#include "Animation/SHRig.h"
namespace SHADE
@ -53,7 +53,7 @@ namespace SHADE
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };
template<> struct SHResourceLoader<SHMaterial> { using AssetType = SHMaterialSpec; };
template<> struct SHResourceLoader<SHFont> { using AssetType = SHFontAsset; };
template<> struct SHResourceLoader<SHAnimationClip> { using AssetType = SHModelAsset; };
template<> struct SHResourceLoader<SHAnimationData> { using AssetType = SHModelAsset; };
template<> struct SHResourceLoader<SHRig> { using AssetType = SHModelAsset; };
/// <summary>

View File

@ -41,7 +41,7 @@ namespace SHADE
!std::is_same_v<ResourceType, SHMaterialSpec> &&
!std::is_same_v<ResourceType, SHFont> &&
!std::is_same_v<ResourceType, SHMaterial> &&
!std::is_same_v<ResourceType, SHAnimationClip> &&
!std::is_same_v<ResourceType, SHAnimationData> &&
!std::is_same_v<ResourceType, SHRig>
)
{
@ -355,7 +355,7 @@ namespace SHADE
loadedAssetData.emplace_back(assetId);
return resourceHub.Create<ResourceType>(assetData.rig, rigNodeStore);
}
else if constexpr (std::is_same_v<ResourceType, SHAnimationClip>)
else if constexpr (std::is_same_v<ResourceType, SHAnimationData>)
{
loadedAssetData.emplace_back(assetId);
return resourceHub.Create<ResourceType>(*assetData.anims[0]);

View File

@ -400,7 +400,7 @@ namespace YAML
{
YAML::Node node;
node[RIG_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHRig>(rhs.GetRig()).value_or(0);
node[CLIP_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHAnimationClip>(rhs.GetCurrentClip()).value_or(0);
node[CLIP_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHAnimationData>(rhs.GetCurrentClip()).value_or(0);
return node;
}
static bool decode(YAML::Node const& node, SHAnimatorComponent& rhs)
@ -411,7 +411,7 @@ namespace YAML
}
if (node[CLIP_YAML_TAG.data()].IsDefined())
{
rhs.SetClip(SHResourceManager::LoadOrGet<SHAnimationClip>(node[CLIP_YAML_TAG.data()].as<AssetID>()));
rhs.SetClip(SHResourceManager::LoadOrGet<SHAnimationData>(node[CLIP_YAML_TAG.data()].as<AssetID>()));
}
return true;
}