Added support for loading SHRig and SHAnimationClip into SHResourceManager and modified SHAnimationClip to support proper keyframe data

This commit is contained in:
Kah Wei 2023-01-09 17:51:54 +08:00
parent a58c3e86a5
commit 7bf0c26052
4 changed files with 55 additions and 10 deletions

View File

@ -20,10 +20,37 @@ namespace SHADE
/* Constructors */
/*-----------------------------------------------------------------------------------*/
SHAnimationClip::SHAnimationClip(const SHAnimAsset& asset)
: ticksPerSecond { asset.ticksPerSecond }
, totalTime { asset.duration }
{
// Populate keyframes
for (const auto& channel : asset.nodeChannels)
{
// Create a channel
Channel newChannel;
newChannel.Name = channel.name;
newChannel.PositionKeyFrames.reserve(channel.positionKeys.size());
newChannel.RotationKeyFrames.reserve(channel.rotationKeys.size());
newChannel.ScaleKeyFrames.reserve(channel.scaleKeys.size());
// Populate Keyframes
for (const auto& posKey : channel.positionKeys)
{
newChannel.PositionKeyFrames.emplace_back(SHAnimationKeyFrame<SHVec3>{ static_cast<int>(posKey.time), posKey.value});
}
for (const auto& rotKey : channel.rotationKeys)
{
newChannel.RotationKeyFrames.emplace_back(SHAnimationKeyFrame<SHQuaternion>{ static_cast<int>(rotKey.time), rotKey.value});
}
for (const auto& scaleKey : channel.scaleKeys)
{
newChannel.ScaleKeyFrames.emplace_back(SHAnimationKeyFrame<SHVec3>{ static_cast<int>(scaleKey.time), scaleKey.value});
}
// Insert the channel
channels.emplace_back(std::move(newChannel));
}
}
/*-----------------------------------------------------------------------------------*/
/* Usage Functions */

View File

@ -23,15 +23,13 @@ namespace SHADE
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
/// <summary>
/// Defines a single key frame in an animation.
/// Defines a single key frame in an animation for a specific type of data.
/// </summary>
template<typename T>
struct SHAnimationKeyFrame
{
float TimeStamp;
SHVec3 Position;
SHQuaternion Orientation;
SHVec3 Scale;
SHMatrix TransformationMatrix;
int FrameIndex;
T Data;
};
/// <summary>
@ -50,18 +48,25 @@ namespace SHADE
struct Channel
{
std::string Name;
std::vector<SHAnimationKeyFrame> KeyFrames;
std::vector<SHAnimationKeyFrame<SHVec3>> PositionKeyFrames;
std::vector<SHAnimationKeyFrame<SHQuaternion>> RotationKeyFrames;
std::vector<SHAnimationKeyFrame<SHVec3>> ScaleKeyFrames;
};
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Constructs an SHAnimation Clip from a specified SHAnimAsset.
/// </summary>
/// <param name="asset">Animation asset to load.</param>
explicit SHAnimationClip(const SHAnimAsset& asset);
/*---------------------------------------------------------------------------------*/
/* Getter Functions */
/*---------------------------------------------------------------------------------*/
const std::vector<Channel>& GetChannels() const noexcept { return channels; }
int GetTicksPerSecond() const noexcept { return ticksPerSecond; }
float GetTotalTime() const noexcept { return totalTime; }
private:
@ -69,6 +74,7 @@ namespace SHADE
/* Data Members */
/*---------------------------------------------------------------------------------*/
std::vector<Channel> channels;
int ticksPerSecond;
float totalTime;
/*---------------------------------------------------------------------------------*/

View File

@ -27,6 +27,8 @@ 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/SHRig.h"
namespace SHADE
{
@ -49,6 +51,8 @@ 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 = SHAnimAsset; };
template<> struct SHResourceLoader<SHRig> { using AssetType = SHRigAsset; };
/// <summary>
/// Static class responsible for loading and caching runtime resources from their

View File

@ -40,7 +40,9 @@ namespace SHADE
!std::is_same_v<ResourceType, SHVkShaderModule> &&
!std::is_same_v<ResourceType, SHMaterialSpec> &&
!std::is_same_v<ResourceType, SHFont> &&
!std::is_same_v<ResourceType, SHMaterial>
!std::is_same_v<ResourceType, SHMaterial> &&
!std::is_same_v<ResourceType, SHAnimationClip> &&
!std::is_same_v<ResourceType, SHRig>
)
{
static_assert(true, "Unsupported Resource Type specified for SHResourceManager.");
@ -345,5 +347,11 @@ namespace SHADE
return gfxSystem->AddFont(assetData);
}
// Animation Clip and Rig
else
{
loadedAssetData.emplace_back(assetId);
return resourceHub.Create<ResourceType>(assetData);
}
}
}