Animation WIP merge #321

Merged
XiaoQiDigipen merged 76 commits from SP3-17-animation-system into main 2023-01-30 17:35:57 +08:00
4 changed files with 55 additions and 10 deletions
Showing only changes of commit 7bf0c26052 - Show all commits

View File

@ -20,11 +20,38 @@ 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
{
@ -43,12 +45,14 @@ namespace SHADE
/// </summary>
template<typename T = void>
struct SHResourceLoader { using AssetType = void; };
template<> struct SHResourceLoader<SHMesh> { using AssetType = SHMeshAsset; };
template<> struct SHResourceLoader<SHMesh> { using AssetType = SHMeshAsset; };
template<> struct SHResourceLoader<SHTexture> { using AssetType = SHTextureAsset; };
template<> struct SHResourceLoader<SHVkShaderModule> { using AssetType = SHShaderAsset; };
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);
}
}
}