Animation WIP merge #321

Merged
XiaoQiDigipen merged 76 commits from SP3-17-animation-system into main 2023-01-30 17:35:57 +08:00
6 changed files with 296 additions and 0 deletions
Showing only changes of commit 2a6db58cd9 - Show all commits

View File

@ -0,0 +1,20 @@
/************************************************************************************//*!
\file SHAnimationSystem.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 SHAnimationSystem 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 Include
#include "SHAnimationSystem.h"
namespace SHADE
{
}

View File

@ -0,0 +1,32 @@
/************************************************************************************//*!
\file SHAnimationSystem.h
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 20, 2022
\brief Contains the definition of the SHAnimationSystem class 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 "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SH_API SHAnimationSystem : public SHSystem
{
};
}

View File

@ -0,0 +1,28 @@
/************************************************************************************//*!
\file SHAnimatorComponent.cpp
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 20, 2022
\brief Contains the definition of functions of the SHRenderable Component 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 Include
#include "SHAnimatorComponent.h"
namespace SHADE
{
}
RTTR_REGISTRATION
{
using namespace SHADE;
using namespace rttr;
registration::class_<SHAnimatorComponent>("Animator Component");
}

View File

@ -0,0 +1,36 @@
/************************************************************************************//*!
\file SHAnimatorComponent.h
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 20, 2022
\brief Contains the definition of the SHAnimationSystem class 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
// External Dependencies
#include <rttr/registration>
// Project Includes
#include "ECS_Base/Components/SHComponent.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SH_API SHAnimatorComponent final : public SHComponent
{
private:
/*-------------------------------------------------------------------------------*/
/* Data Members */
/*-------------------------------------------------------------------------------*/
RTTR_ENABLE()
};
}

View File

@ -0,0 +1,89 @@
/************************************************************************************//*!
\file SHRig.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 SHRig 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 "SHRig.h"
// STL Includes
#include <stack>
// Project Headers
#include "Assets/Asset Types/Models/SHRigAsset.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------------*/
SHRig::SHRig(const SHRigAsset& asset)
{
// Don't bother if empty
if (asset.root == nullptr)
return;
// Do a recursive depth first traversal to populate the rig
rootNode = recurseCreateNode(asset, asset.root);
}
/*-----------------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------------*/
const std::string& SHRig::GetName(Handle<Node> node) const noexcept
{
static const std::string EMPTY_STRING = "";
if (nodeNames.contains(node))
return nodeNames.at(node);
return EMPTY_STRING;
}
Handle<SHRig::Node> SHRig::GetNode(const std::string& name) const noexcept
{
if (nodesByName.contains(name))
return nodesByName.at(name);
return {};
}
/*-----------------------------------------------------------------------------------*/
/* Helper Functions */
/*-----------------------------------------------------------------------------------*/
Handle<SHRig::Node> SHRig::recurseCreateNode(const SHRigAsset& asset, const RigNode* sourceNode)
{
// Construct the node
auto newNode = nodeStore.Create();
// Fill the node with data
const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef);
newNode->Transform = NODE_DATA.transform;
// Populate maps
if (!NODE_DATA.name.empty())
{
nodeNames.emplace(newNode, NODE_DATA.name);
nodesByName.emplace(NODE_DATA.name, newNode);
}
// Fill child nodes
for (const auto& child : sourceNode->children)
{
// Ignore nulls
if (child == nullptr)
continue;
// Recursively create children
newNode->Children.emplace_back(recurseCreateNode(asset, child));
}
return newNode;
}
}

View File

@ -0,0 +1,91 @@
/************************************************************************************//*!
\file SHRig.h
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 20, 2022
\brief Contains the definition of the SHRig 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
// STL Includes
#include <string>
#include <vector>
#include <unordered_map>
// Project Includes
#include "Math/SHMatrix.h"
#include "Resource/SHHandle.h"
#include "Resource/SHResourceLibrary.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
struct SHRigAsset;
struct RigNode;
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SHRig
{
/*---------------------------------------------------------------------------------*/
/* Type Definitions */
/*---------------------------------------------------------------------------------*/
struct Node
{
SHMatrix Transform;
std::vector<Handle<Node>> Children;
};
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
/// <summary>
///
/// </summary>
/// <param name="asset"></param>
explicit SHRig(const SHRigAsset& asset);
/*---------------------------------------------------------------------------------*/
/* Usage Functions */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Retrieves the name of a node.
/// </summary>
/// <param name="node">Node to get the name of.</param>
/// <returns>
/// Name of the node. If it does not have a name or is invalid, an empty string will
/// be provided.
/// </returns>
const std::string& GetName(Handle<Node> node) const noexcept;
/// <summary>
/// Retrieves a node via name.
/// </summary>
/// <param name="name">Name of the node to retrieve.</param>
/// <returns>
/// Node with the specified name. If it does not have a name or is invalid, an empty
/// handle will be provided.
/// </returns>
Handle<Node> GetNode(const std::string& name) const noexcept;
private:
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
Handle<Node> rootNode;
std::unordered_map<Handle<Node>, std::string> nodeNames;
std::unordered_map<std::string, Handle<Node>> nodesByName;
SHResourceLibrary<Node> nodeStore;
/*---------------------------------------------------------------------------------*/
/* Helper Functions */
/*---------------------------------------------------------------------------------*/
Handle<Node> recurseCreateNode(const SHRigAsset& asset, const RigNode* sourceNode);
};
}