Animation WIP merge #321
|
@ -9,12 +9,28 @@ 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
|
||||
// Precompiled Header
|
||||
#include "SHpch.h"
|
||||
// Primary Include
|
||||
#include "SHAnimationSystem.h"
|
||||
// Project Includes
|
||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
#include "SHAnimatorComponent.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* System Routine Functions - UpdateRoutine */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHAnimationSystem::UpdateRoutine::UpdateRoutine()
|
||||
: SHSystemRoutine("Animation System Update", false)
|
||||
{}
|
||||
void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept
|
||||
{
|
||||
auto& animators = SHComponentManager::GetDense<SHAnimatorComponent>();
|
||||
for (auto& animator : animators)
|
||||
{
|
||||
animator.Update(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,24 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// System that is responsible for updating all animations.
|
||||
/// </summary>
|
||||
class SH_API SHAnimationSystem : public SHSystem
|
||||
{
|
||||
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Responsible for updating the playback of all animator components and computing
|
||||
/// the required bone matrices.
|
||||
/// </summary>
|
||||
class SH_API UpdateRoutine final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
UpdateRoutine();
|
||||
void Execute(double dt) noexcept override final;
|
||||
};
|
||||
};
|
||||
}
|
|
@ -9,7 +9,7 @@ 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
|
||||
// Precompiled Header
|
||||
#include "SHpch.h"
|
||||
// Primary Include
|
||||
#include "SHAnimatorComponent.h"
|
||||
|
@ -19,7 +19,13 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Update Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHAnimatorComponent::Update(float dt)
|
||||
{
|
||||
// Set everything to identity
|
||||
}
|
||||
}
|
||||
|
||||
RTTR_REGISTRATION
|
||||
|
|
|
@ -37,10 +37,29 @@ namespace SHADE
|
|||
class SH_API SHAnimatorComponent final : public SHComponent
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*void Play();
|
||||
void PlayFromStart();
|
||||
void Pause();
|
||||
void Stop();*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
const std::vector<SHMatrix>& GetBoneMatrices() const noexcept { return boneMatrices; }
|
||||
bool IsPlaying() const { return isPlaying; }
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Update Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Updates the current state of the animation if one is specified based on the
|
||||
/// current animation clip and frames. This will update the bone matrices.
|
||||
/// </summary>
|
||||
/// <param name="dt">Time passed since the last frame.</param>
|
||||
void Update(float dt);
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -49,6 +68,7 @@ namespace SHADE
|
|||
Handle<SHRig> rig;
|
||||
std::vector<SHMatrix> boneMatrices;
|
||||
float currPlaybackTime = 0.0f;
|
||||
bool isPlaying = false;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* RTTR */
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace SHADE
|
|||
return;
|
||||
|
||||
// Do a recursive depth first traversal to populate the rig
|
||||
nodeCount = 0;
|
||||
rootNode = recurseCreateNode(asset, asset.root);
|
||||
}
|
||||
|
||||
|
@ -54,6 +55,11 @@ namespace SHADE
|
|||
return {};
|
||||
}
|
||||
|
||||
int SHRig::GetNodeCount() const noexcept
|
||||
{
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -61,6 +67,7 @@ namespace SHADE
|
|||
{
|
||||
// Construct the node
|
||||
auto newNode = nodeStore.Create();
|
||||
++nodeCount;
|
||||
|
||||
// Fill the node with data
|
||||
const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef);
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace SHADE
|
|||
explicit SHRig(const SHRigAsset& asset);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Retrieves the name of a node.
|
||||
|
@ -73,6 +73,11 @@ namespace SHADE
|
|||
/// handle will be provided.
|
||||
/// </returns>
|
||||
Handle<Node> GetNode(const std::string& name) const noexcept;
|
||||
/// <summary>
|
||||
/// Returns the number of nodes in the rig. This matches the number of bone matrices
|
||||
/// needed.
|
||||
/// </summary>
|
||||
int GetNodeCount() const noexcept;
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -81,6 +86,7 @@ namespace SHADE
|
|||
Handle<Node> rootNode;
|
||||
std::unordered_map<Handle<Node>, std::string> nodeNames;
|
||||
std::unordered_map<std::string, Handle<Node>> nodesByName;
|
||||
int nodeCount = 0;
|
||||
SHResourceLibrary<Node> nodeStore;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Reference in New Issue