Implemented Animation Clip asset and animation controller #410
|
@ -0,0 +1,65 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHRawAnimation.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 SHRawAnimation class.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
// Pre-compiled Header
|
||||||
|
#include "SHpch.h"
|
||||||
|
// Primary Header
|
||||||
|
#include "SHRawAnimation.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
SHRawAnimation::SHRawAnimation(const SHAnimAsset& asset)
|
||||||
|
: ticksPerSecond { static_cast<int>(asset.ticksPerSecond) }
|
||||||
|
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
|
||||||
|
{
|
||||||
|
// Populate keyframes
|
||||||
|
for (const auto& channel : asset.nodeChannels)
|
||||||
|
{
|
||||||
|
// Create a channel
|
||||||
|
Channel newChannel;
|
||||||
|
newChannel.Name = std::string(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});
|
||||||
|
}
|
||||||
|
|
||||||
|
newChannel.MaxFrames = std::max({ newChannel.PositionKeyFrames.size(), newChannel.RotationKeyFrames.size(), newChannel.ScaleKeyFrames.size() });
|
||||||
|
|
||||||
|
// Insert the channel
|
||||||
|
channels.emplace_back(std::move(newChannel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHAnimationClip.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.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Project Includes
|
||||||
|
#include "SH_API.h"
|
||||||
|
#include "Math/SHMatrix.h"
|
||||||
|
#include "Assets/Asset Types/Models/SHAnimationAsset.h"
|
||||||
|
#include "Resource/SHHandle.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Forward Declarations */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
class SHRawAnimation;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a snippet of 3D animation that is stored in a SHRawAnimation object.
|
||||||
|
/// </summary>
|
||||||
|
class SH_API SHAnimationClip
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Getter Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
inline Handle<SHRawAnimation> GetRawAnimation() const noexcept { return rawAnim; }
|
||||||
|
inline float GetTotalTime() const noexcept { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Handle<SHRawAnimation> rawAnim;
|
||||||
|
int startFrameIndex; // First Frame
|
||||||
|
int endFrameIndex; // Last Frame (inclusive)
|
||||||
|
float totalTime; // Time to take from first to last frame
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
#include "SHRawAnimation.h"
|
#include "SHAnimationClip.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -100,7 +100,7 @@ namespace SHADE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
struct Node
|
struct Node
|
||||||
{
|
{
|
||||||
Handle<SHRawAnimation> Clip;
|
Handle<SHAnimationClip> Clip;
|
||||||
std::vector<Transition> Transitions;
|
std::vector<Transition> Transitions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "SHRig.h"
|
#include "SHRig.h"
|
||||||
#include "Math/SHMatrix.h"
|
#include "Math/SHMatrix.h"
|
||||||
#include "SHRawAnimation.h"
|
#include "SHAnimationClip.h"
|
||||||
#include "Graphics/SHVkUtil.h"
|
#include "Graphics/SHVkUtil.h"
|
||||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
|
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
|
||||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
@ -37,14 +37,14 @@ namespace SHADE
|
||||||
playOnce = false;
|
playOnce = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAnimatorComponent::Play(Handle<SHRawAnimation> clip)
|
void SHAnimatorComponent::Play(Handle<SHAnimationClip> clip)
|
||||||
{
|
{
|
||||||
currClip = clip;
|
currClip = clip;
|
||||||
currPlaybackTime = 0.0f;
|
currPlaybackTime = 0.0f;
|
||||||
Play();
|
Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAnimatorComponent::PlayOneShot(Handle<SHRawAnimation> clip)
|
void SHAnimatorComponent::PlayOneShot(Handle<SHAnimationClip> clip)
|
||||||
{
|
{
|
||||||
Play(clip);
|
Play(clip);
|
||||||
playOnce = true;
|
playOnce = true;
|
||||||
|
@ -86,7 +86,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAnimatorComponent::SetClip(Handle<SHRawAnimation> newClip)
|
void SHAnimatorComponent::SetClip(Handle<SHAnimationClip> newClip)
|
||||||
{
|
{
|
||||||
// No change
|
// No change
|
||||||
if (currClip == newClip)
|
if (currClip == newClip)
|
||||||
|
@ -124,9 +124,14 @@ namespace SHADE
|
||||||
if (!currClip || !isPlaying || !rig || !rig->GetRootNode())
|
if (!currClip || !isPlaying || !rig || !rig->GetRootNode())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Get animation data
|
||||||
|
auto animData = currClip->GetRawAnimation();
|
||||||
|
if (!animData)
|
||||||
|
return;
|
||||||
|
|
||||||
// Update time on the playback
|
// Update time on the playback
|
||||||
currPlaybackTime += dt;
|
currPlaybackTime += dt;
|
||||||
if (currPlaybackTime > currClip->GetTotalTime())
|
if (currPlaybackTime > animData->GetTotalTime())
|
||||||
{
|
{
|
||||||
if (playOnce)
|
if (playOnce)
|
||||||
{
|
{
|
||||||
|
@ -135,7 +140,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currPlaybackTime = currPlaybackTime - currClip->GetTotalTime();
|
currPlaybackTime = currPlaybackTime - animData->GetTotalTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
class SHRig;
|
class SHRig;
|
||||||
struct SHRigNode;
|
struct SHRigNode;
|
||||||
class SHRawAnimation;
|
class SHAnimationClip;
|
||||||
class SHVkBuffer;
|
class SHVkBuffer;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -55,12 +55,12 @@ namespace SHADE
|
||||||
/// Plays the specified animation clip from the start.
|
/// Plays the specified animation clip from the start.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clip">Animation clip to play.</param>
|
/// <param name="clip">Animation clip to play.</param>
|
||||||
void Play(Handle<SHRawAnimation> clip);
|
void Play(Handle<SHAnimationClip> clip);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Plays the specified animation clip from the start one time only.
|
/// Plays the specified animation clip from the start one time only.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clip">Animation clip to play.</param>
|
/// <param name="clip">Animation clip to play.</param>
|
||||||
void PlayOneShot(Handle<SHRawAnimation> clip);
|
void PlayOneShot(Handle<SHAnimationClip> clip);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Plays the currently loaded animation clip from the start.
|
/// Plays the currently loaded animation clip from the start.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -88,7 +88,7 @@ namespace SHADE
|
||||||
/// If the clip is the same as the current clip, nothing happens.
|
/// If the clip is the same as the current clip, nothing happens.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newClip">Clip to use.</param>
|
/// <param name="newClip">Clip to use.</param>
|
||||||
void SetClip(Handle<SHRawAnimation> newClip);
|
void SetClip(Handle<SHAnimationClip> newClip);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Getter Functions */
|
/* Getter Functions */
|
||||||
|
@ -108,7 +108,7 @@ namespace SHADE
|
||||||
/// Retrieve the currently set animation clip.
|
/// Retrieve the currently set animation clip.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Handle to the currently set animation clip.</returns>
|
/// <returns>Handle to the currently set animation clip.</returns>
|
||||||
Handle<SHRawAnimation> GetCurrentClip() const noexcept { return currClip; }
|
Handle<SHAnimationClip> GetCurrentClip() const noexcept { return currClip; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if an animation is currently playing.
|
/// Checks if an animation is currently playing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -131,7 +131,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
// Resources
|
// Resources
|
||||||
Handle<SHRig> rig;
|
Handle<SHRig> rig;
|
||||||
Handle<SHRawAnimation> currClip;
|
Handle<SHAnimationClip> currClip;
|
||||||
// Playback Tracking
|
// Playback Tracking
|
||||||
float currPlaybackTime = 0.0f;
|
float currPlaybackTime = 0.0f;
|
||||||
bool isPlaying = true;
|
bool isPlaying = true;
|
||||||
|
|
|
@ -32,8 +32,7 @@ namespace SHADE
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a animation clip of a 3D animation that is made for a specific model
|
/// Represents the raw 3D animation data for a rigged 3D model.
|
||||||
/// rig.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class SH_API SHRawAnimation
|
class SH_API SHRawAnimation
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue