Implemented Animation Clip asset and animation controller #410
|
@ -14,7 +14,6 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// Project Includes
|
||||
#include "SH_API.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "Assets/Asset Types/Models/SHAnimationAsset.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
|
|
|
@ -14,6 +14,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "SHAnimationController.h"
|
||||
#include "SHAnimationSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "SHAnimationClip.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -18,13 +18,17 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// Project Includes
|
||||
#include "SH_API.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "SHAnimationClip.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHAnimationClip;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Object that controls the animation that is played by an animator through the use
|
||||
/// of an internal state machine.
|
||||
|
@ -36,7 +40,7 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
class Node;
|
||||
struct Node;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definition */
|
||||
|
@ -45,7 +49,7 @@ namespace SHADE
|
|||
/// Describes a parameter for the AnimationController that can be used to control
|
||||
/// the flow of animations.
|
||||
/// </summary>
|
||||
struct AnimParam
|
||||
struct SH_API AnimParam
|
||||
{
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Type Definition */
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace SHADE
|
|||
static_assert(std::is_same_v<T, bool> || std::is_same_v<T, float> || std::is_same_v<T, int>, "Only works with bool, float or ints.");
|
||||
|
||||
// Invalid param
|
||||
if (!parameters.contains(paramName))
|
||||
if (parameters.find(paramName) == parameters.end())
|
||||
return;
|
||||
|
||||
// Set the value
|
||||
|
@ -86,7 +86,7 @@ namespace SHADE
|
|||
static_assert(std::is_same_v<T, bool> || std::is_same_v<T, float> || std::is_same_v<T, int>, "Only works with bool, float or ints.");
|
||||
|
||||
// Invalid param
|
||||
if (!parameters.contains(paramName))
|
||||
if (parameters.find(paramName) == parameters.end())
|
||||
return {};
|
||||
|
||||
// Check if the type matches
|
||||
|
@ -108,9 +108,10 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Return the correct value
|
||||
if (instData.Params.contains(paramName))
|
||||
auto paramIter = instData.Params.find(paramName);
|
||||
if (paramIter != instData.Params.end())
|
||||
{
|
||||
return instData.Params[paramName];
|
||||
return paramIter->second.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -85,6 +85,12 @@ namespace SHADE
|
|||
|
||||
void SHAnimatorComponent::PlayFromStart()
|
||||
{
|
||||
if (!currClip)
|
||||
{
|
||||
SHLOG_WARNING("[SHAnimatorComponent] Attempted to restart a clip but there is no existing clip. Ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
isPlaying = true;
|
||||
currPlaybackTime = 0.0f;
|
||||
}
|
||||
|
@ -96,6 +102,12 @@ namespace SHADE
|
|||
|
||||
void SHAnimatorComponent::Stop()
|
||||
{
|
||||
if (!currClip)
|
||||
{
|
||||
SHLOG_WARNING("[SHAnimatorComponent] Attempted to stop a clip but there is no existing clip. Ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
isPlaying = false;
|
||||
currPlaybackTime = 0.0f;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ namespace SHADE
|
|||
class SHRig;
|
||||
struct SHRigNode;
|
||||
class SHAnimationClip;
|
||||
class SHVkBuffer;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
|
@ -65,7 +64,8 @@ namespace SHADE
|
|||
/// <param name="clip">Animation clip to play.</param>
|
||||
void PlayOneShot(Handle<SHAnimationClip> clip);
|
||||
/// <summary>
|
||||
/// Plays the currently loaded animation clip from the start.
|
||||
/// Plays the currently loaded animation clip from the start. Note that this only
|
||||
/// works when using manual playback mode.
|
||||
/// </summary>
|
||||
void PlayFromStart();
|
||||
/// <summary>
|
||||
|
@ -73,7 +73,9 @@ namespace SHADE
|
|||
/// </summary>
|
||||
void Pause();
|
||||
/// <summary>
|
||||
/// Stops the animation and resets the play time back to 0.
|
||||
/// Stops the animation and resets the play time back to 0. Note that this only
|
||||
/// works when using manual playback mode. This is not supported when using an
|
||||
/// Animation Controller.
|
||||
/// </summary>
|
||||
void Stop();
|
||||
|
||||
|
@ -100,6 +102,10 @@ namespace SHADE
|
|||
/// </summary>
|
||||
/// <param name="newRig">Animation controller to use.</param>
|
||||
void SetAnimationController(Handle<SHAnimationController> ac);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Parameter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Sets the parameter of the for the string. Does nothing if an invalid param name
|
||||
/// is provided. Type of the parameter is not checked. Also does nothing if no
|
||||
|
@ -128,7 +134,6 @@ namespace SHADE
|
|||
/// Sets the flag for a trigger parameter. Does nothing if an invalid param name is
|
||||
/// provided or if the param name refers to a parameter that is not a trigger.
|
||||
/// </summary>
|
||||
/// <param name="instData">Data of the instance to .</param>
|
||||
/// <param name="paramName">Name of the parameter.</param>
|
||||
void SetTrigger(const std::string& paramName);
|
||||
|
||||
|
@ -156,6 +161,10 @@ namespace SHADE
|
|||
/// </summary>
|
||||
/// <returns>Handle to the current Animation Controller node.</returns>
|
||||
Handle<SHAnimationController::Node> GetCurrentNode() const noexcept { return animInstanceData.CurrentNode; }
|
||||
/// <summary>
|
||||
/// Retrieves the currently set animation controller.
|
||||
/// </summary>
|
||||
/// <returnsHandle to the currently set animtion controller.</returns>
|
||||
Handle<SHAnimationController> GetAnimationController() const noexcept { return animController; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -16,9 +16,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "SHRig.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "SHRawAnimation.h"
|
||||
#include "Graphics/SHVkUtil.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "SHAnimationController.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -29,9 +27,9 @@ namespace SHADE
|
|||
std::optional<T> SHAnimatorComponent::GetParameter(const std::string& paramName)
|
||||
{
|
||||
if (!animController)
|
||||
return;
|
||||
return {};
|
||||
|
||||
return animController->GetParameter(paramName);
|
||||
return animController->GetParameter<T>(animInstanceData, paramName);
|
||||
}
|
||||
template<typename T>
|
||||
void SHAnimatorComponent::SetParameter(const std::string& paramName, T value)
|
||||
|
@ -39,7 +37,7 @@ namespace SHADE
|
|||
if (!animController)
|
||||
return;
|
||||
|
||||
return animController->SetParameter(paramName, value);
|
||||
return animController->SetParameter(animInstanceData, paramName, value);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -10,8 +10,10 @@
|
|||
*****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Math/SHMath.h"
|
||||
#include "Assets/Asset Types/SHAssetData.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/Vector/SHVec4.h"
|
||||
#include "Math/SHQuaternion.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ namespace SHADE
|
|||
// Generate new asset
|
||||
const AssetID NEW_ASSET_ID = SHAssetManager::CreateNewAsset(AssetType::ANIM_CLIP, newAssetName);
|
||||
auto animClip = SHAssetManager::GetData<SHAnimClipAsset>(NEW_ASSET_ID);
|
||||
animClip->animRawDataAssetId = SHResourceManager::GetAssetID<SHRawAnimation>(rawAnimation).value_or(INVALID_ASSET_ID);
|
||||
animClip->firstIndex = firstIndex;
|
||||
animClip->lastIndex = lastIndex;
|
||||
SHAssetManager::SaveAsset(NEW_ASSET_ID);
|
||||
|
|
|
@ -370,7 +370,7 @@ namespace SHADE
|
|||
loadedAssetData.emplace_back(assetId);
|
||||
return resourceHub.Create<ResourceType>
|
||||
(
|
||||
LoadOrGet<SHRawAnimation>(assetData.animRawDataAssetId),
|
||||
LoadOrGet<SHRawAnimation>(assetId), // TODO: Wrong, we need to grab the parent asset's ID
|
||||
assetData.firstIndex,
|
||||
assetData.lastIndex
|
||||
);
|
||||
|
|
|
@ -44,6 +44,21 @@ namespace SHADE
|
|||
return SHResourceManager::LoadOrGet<SHFont>(assetId);
|
||||
}
|
||||
|
||||
Handle<SHAnimationClip> SHResourceManagerInterface::LoadOrGetAnimationClip(AssetID assetId)
|
||||
{
|
||||
return SHResourceManager::LoadOrGet<SHAnimationClip>(assetId);
|
||||
}
|
||||
|
||||
Handle<SHAnimationController> SHResourceManagerInterface::LoadOrGetAnimationController(AssetID assetId)
|
||||
{
|
||||
return SHResourceManager::LoadOrGet<SHAnimationController>(assetId);
|
||||
}
|
||||
|
||||
Handle<SHRig> SHResourceManagerInterface::LoadOrGetRig(AssetID assetId)
|
||||
{
|
||||
return SHResourceManager::LoadOrGet<SHRig>(assetId);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -29,6 +29,9 @@ namespace SHADE
|
|||
struct SHMaterialSpec;
|
||||
class SHMaterial;
|
||||
class SHFont;
|
||||
class SHAnimationClip;
|
||||
class SHRig;
|
||||
class SHAnimationController;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
|
@ -80,6 +83,24 @@ namespace SHADE
|
|||
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||
/// <returns>Handle to the resource to retrieve.</returns>
|
||||
static Handle<SHFont> LoadOrGetFont(AssetID assetId);
|
||||
/// <summary>
|
||||
/// Wrapper for SHResourceManager::LoadOrGet<SHAnimationClip>().
|
||||
/// </summary>
|
||||
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||
/// <returns>Handle to the resource to retrieve.</returns>
|
||||
static Handle<SHAnimationClip> LoadOrGetAnimationClip(AssetID assetId);
|
||||
/// <summary>
|
||||
/// Wrapper for SHResourceManager::LoadOrGet<SHAnimationController>().
|
||||
/// </summary>
|
||||
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||
/// <returns>Handle to the resource to retrieve.</returns>
|
||||
static Handle<SHAnimationController> LoadOrGetAnimationController(AssetID assetId);
|
||||
/// <summary>
|
||||
/// Wrapper for SHResourceManager::LoadOrGet<SHRig>().
|
||||
/// </summary>
|
||||
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||
/// <returns>Handle to the resource to retrieve.</returns>
|
||||
static Handle<SHRig> LoadOrGetRig(AssetID assetId);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/************************************************************************************//*!
|
||||
\file AnimationClipAsset.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the implementation of the functions of the managed
|
||||
AnimationClip class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2023 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.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "AnimationClipAsset.hxx"
|
||||
// External Dependencies
|
||||
#include "Resource/SHResourceManagerInterface.h"
|
||||
// Project Headers
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHAnimationClip> AnimationClipAsset::NativeObject::get()
|
||||
try
|
||||
{
|
||||
return SHResourceManagerInterface::LoadOrGetAnimationClip(asset.NativeAssetID);
|
||||
}
|
||||
catch (const BadHandleCastException&)
|
||||
{
|
||||
return Handle<SHAnimationClip>();
|
||||
}
|
||||
AssetID AnimationClipAsset::NativeAssetID::get()
|
||||
{
|
||||
return asset.NativeAssetID;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationClipAsset::AnimationClipAsset(AssetID AnimationClipId)
|
||||
: asset{ AnimationClipId }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationClipAsset::operator bool(AnimationClipAsset asset)
|
||||
{
|
||||
return asset.asset;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Conversion Operators */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationClipAsset::operator Asset(AnimationClipAsset nativeAsset)
|
||||
{
|
||||
return nativeAsset.asset;
|
||||
}
|
||||
|
||||
AnimationClipAsset::operator AnimationClipAsset(Asset asset)
|
||||
{
|
||||
return AnimationClipAsset(asset.NativeAssetID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/************************************************************************************//*!
|
||||
\file AnimationClipAsset.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the definition of the managed AnimationClipAsset class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2023 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 "Resource/SHHandle.h"
|
||||
#include "Animation/SHAnimationClip.h"
|
||||
// Project Includes
|
||||
#include "NativeAsset.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the native Animation Clip object that specifies a range of
|
||||
/// animation frames that can be specified to an Animator component to play an
|
||||
/// animation.
|
||||
/// </summary>
|
||||
public value struct AnimationClipAsset
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Copy of the Handle to the native object.
|
||||
/// </summary>
|
||||
property Handle<SHAnimationClip> NativeObject
|
||||
{
|
||||
Handle<SHAnimationClip> get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The raw asset ID of the asset.
|
||||
/// </summary>
|
||||
property AssetID NativeAssetID
|
||||
{
|
||||
AssetID get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the AnimationClip.
|
||||
/// </summary>
|
||||
/// <param name="AnimationClipId">AssetID to the AnimationClip asset.</param>
|
||||
AnimationClipAsset(AssetID AnimationClipId);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Implicit conversion operator to enable checking if a AnimationClip is valid.
|
||||
/// </summary>
|
||||
/// <param name="gameObj">Asset to check.</param>
|
||||
/// <returns>True if the Asset is valid.</returns>
|
||||
static operator bool(AnimationClipAsset asset);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Conversion Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Conversion operator to enable casting from a AnimationClip to an Asset.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector3 to convert from.</param>
|
||||
static explicit operator Asset(AnimationClipAsset nativeAsset);
|
||||
/// <summary>
|
||||
/// Conversion operator to enable casting from a Asset to a AnimationClip.
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
static explicit operator AnimationClipAsset(Asset asset);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
Asset asset;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/************************************************************************************//*!
|
||||
\file AnimationController.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the implementation of the functions of the managed
|
||||
AnimationController class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2023 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.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "AnimationControllerAsset.hxx"
|
||||
// External Dependencies
|
||||
#include "Resource/SHResourceManagerInterface.h"
|
||||
// Project Headers
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHAnimationController> AnimationControllerAsset::NativeObject::get()
|
||||
try
|
||||
{
|
||||
return SHResourceManagerInterface::LoadOrGetAnimationController(asset.NativeAssetID);
|
||||
}
|
||||
catch (const BadHandleCastException&)
|
||||
{
|
||||
return Handle<SHAnimationController>();
|
||||
}
|
||||
AssetID AnimationControllerAsset::NativeAssetID::get()
|
||||
{
|
||||
return asset.NativeAssetID;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationControllerAsset::AnimationControllerAsset(AssetID AnimationControllerId)
|
||||
: asset{ AnimationControllerId }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationControllerAsset::operator bool(AnimationControllerAsset asset)
|
||||
{
|
||||
return asset.asset;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Conversion Operators */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationControllerAsset::operator Asset(AnimationControllerAsset nativeAsset)
|
||||
{
|
||||
return nativeAsset.asset;
|
||||
}
|
||||
|
||||
AnimationControllerAsset::operator AnimationControllerAsset(Asset asset)
|
||||
{
|
||||
return AnimationControllerAsset(asset.NativeAssetID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/************************************************************************************//*!
|
||||
\file AnimationControllerAsset.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the definition of the managed AnimationController class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
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 "Resource/SHHandle.h"
|
||||
#include "Animation/SHAnimationController.h"
|
||||
// Project Includes
|
||||
#include "NativeAsset.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the native AnimationController object containing the
|
||||
/// state machine for controlling what AnimationClips that an Animator should play.
|
||||
/// </summary>
|
||||
public value struct AnimationControllerAsset
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Copy of the Handle to the native object.
|
||||
/// </summary>
|
||||
property Handle<SHAnimationController> NativeObject
|
||||
{
|
||||
Handle<SHAnimationController> get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The raw asset ID of the asset.
|
||||
/// </summary>
|
||||
property AssetID NativeAssetID
|
||||
{
|
||||
AssetID get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the AnimationController.
|
||||
/// </summary>
|
||||
/// <param name="AnimationControllerId">AssetID to the AnimationController asset.</param>
|
||||
AnimationControllerAsset(AssetID AnimationControllerId);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Implicit conversion operator to enable checking if a AnimationController is valid.
|
||||
/// </summary>
|
||||
/// <param name="gameObj">Asset to check.</param>
|
||||
/// <returns>True if the Asset is valid.</returns>
|
||||
static operator bool(AnimationControllerAsset asset);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Conversion Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Conversion operator to enable casting from a AnimationController to an Asset.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector3 to convert from.</param>
|
||||
static explicit operator Asset(AnimationControllerAsset nativeAsset);
|
||||
/// <summary>
|
||||
/// Conversion operator to enable casting from a Asset to a AnimationController.
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
static explicit operator AnimationControllerAsset(Asset asset);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
Asset asset;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/************************************************************************************//*!
|
||||
\file AnimationRigAsset.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the implementation of the functions of the managed
|
||||
AnimationRig class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2023 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.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "AnimationRigAsset.hxx"
|
||||
// External Dependencies
|
||||
#include "Resource/SHResourceManagerInterface.h"
|
||||
// Project Headers
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHRig> AnimationRigAsset::NativeObject::get()
|
||||
try
|
||||
{
|
||||
return SHResourceManagerInterface::LoadOrGetRig(asset.NativeAssetID);
|
||||
}
|
||||
catch (const BadHandleCastException&)
|
||||
{
|
||||
return Handle<SHRig>();
|
||||
}
|
||||
AssetID AnimationRigAsset::NativeAssetID::get()
|
||||
{
|
||||
return asset.NativeAssetID;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationRigAsset::AnimationRigAsset(AssetID AnimationRigId)
|
||||
: asset{ AnimationRigId }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationRigAsset::operator bool(AnimationRigAsset asset)
|
||||
{
|
||||
return asset.asset;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Conversion Operators */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationRigAsset::operator Asset(AnimationRigAsset nativeAsset)
|
||||
{
|
||||
return nativeAsset.asset;
|
||||
}
|
||||
|
||||
AnimationRigAsset::operator AnimationRigAsset(Asset asset)
|
||||
{
|
||||
return AnimationRigAsset(asset.NativeAssetID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/************************************************************************************//*!
|
||||
\file AnimationRigAsset.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the definition of the managed AnimationRigAsset class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2023 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 "Resource/SHHandle.h"
|
||||
#include "Animation/SHRig.h"
|
||||
// Project Includes
|
||||
#include "NativeAsset.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the native Animation Rig object that specifies how an
|
||||
/// Animation Clip affects the model that this Rig is attached to.
|
||||
/// </summary>
|
||||
public value struct AnimationRigAsset
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Copy of the Handle to the native object.
|
||||
/// </summary>
|
||||
property Handle<SHRig> NativeObject
|
||||
{
|
||||
Handle<SHRig> get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The raw asset ID of the asset.
|
||||
/// </summary>
|
||||
property AssetID NativeAssetID
|
||||
{
|
||||
AssetID get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the AnimationRig.
|
||||
/// </summary>
|
||||
/// <param name="AnimationRigId">AssetID to the AnimationRig asset.</param>
|
||||
AnimationRigAsset(AssetID AnimationRigId);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Implicit conversion operator to enable checking if a AnimationRig is valid.
|
||||
/// </summary>
|
||||
/// <param name="gameObj">Asset to check.</param>
|
||||
/// <returns>True if the Asset is valid.</returns>
|
||||
static operator bool(AnimationRigAsset asset);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Conversion Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Conversion operator to enable casting from a AnimationRig to an Asset.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector3 to convert from.</param>
|
||||
static explicit operator Asset(AnimationRigAsset nativeAsset);
|
||||
/// <summary>
|
||||
/// Conversion operator to enable casting from a Asset to a AnimationRig.
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
static explicit operator AnimationRigAsset(Asset asset);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
Asset asset;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
/************************************************************************************//*!
|
||||
\file Animator.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the definition of the functions of the managed Animator class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2023 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.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Animator.hxx"
|
||||
#include "Assets/NativeAsset.hxx"
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Animator::Animator(Entity entity)
|
||||
: Component(entity)
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AnimationControllerAsset Animator::AnimationController::get()
|
||||
{
|
||||
auto controller = GetNativeComponent()->GetAnimationController();
|
||||
return controller ? AnimationControllerAsset(controller) : AnimationControllerAsset();
|
||||
}
|
||||
void Animator::AnimationController::set(AnimationControllerAsset value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
GetNativeComponent()->SetAnimationController(Handle<SHAnimationController>());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNativeComponent()->SetAnimationController(value.NativeObject);
|
||||
}
|
||||
}
|
||||
AnimationRigAsset Animator::Rig::get()
|
||||
{
|
||||
auto rig = GetNativeComponent()->GetRig();
|
||||
return rig ? AnimationRigAsset(rig) : AnimationRigAsset();
|
||||
}
|
||||
void Animator::Rig::set(AnimationRigAsset value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
GetNativeComponent()->SetRig(Handle<SHRig>());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNativeComponent()->SetRig(Handle<SHRig>(value.NativeObject));
|
||||
}
|
||||
}
|
||||
System::String^ Animator::CurrentNodeName::get()
|
||||
{
|
||||
const auto CURR_NODE = GetNativeComponent()->GetCurrentNode();
|
||||
if (CURR_NODE)
|
||||
return Convert::ToCLI(CURR_NODE->Name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void Animator::Play()
|
||||
{
|
||||
GetNativeComponent()->Play();
|
||||
}
|
||||
|
||||
void Animator::Play(AnimationClipAsset clip)
|
||||
{
|
||||
GetNativeComponent()->Play(clip.NativeObject);
|
||||
}
|
||||
|
||||
void Animator::PlayOneShot(AnimationClipAsset clip)
|
||||
{
|
||||
GetNativeComponent()->PlayOneShot(clip.NativeObject);
|
||||
}
|
||||
|
||||
void Animator::PlayFromStart()
|
||||
{
|
||||
GetNativeComponent()->Play();
|
||||
}
|
||||
|
||||
void Animator::Pause()
|
||||
{
|
||||
GetNativeComponent()->Pause();
|
||||
}
|
||||
|
||||
void Animator::Stop()
|
||||
{
|
||||
GetNativeComponent()->Stop();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Parameter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
void Animator::SetParameter(System::String^ paramName, T value)
|
||||
{
|
||||
if (T::typeid == int::typeid)
|
||||
{
|
||||
GetNativeComponent()->SetParameter<int>(Convert::ToNative(paramName), static_cast<int>(value));
|
||||
}
|
||||
else if (T::typeid == float::typeid)
|
||||
{
|
||||
GetNativeComponent()->SetParameter<float>(Convert::ToNative(paramName), static_cast<float>(value));
|
||||
}
|
||||
else if (T::typeid == bool::typeid)
|
||||
{
|
||||
GetNativeComponent()->SetParameter<bool>(Convert::ToNative(paramName), static_cast<bool>(value));
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::SetTrigger(System::String^ paramName)
|
||||
{
|
||||
GetNativeComponent()->SetTrigger(Convert::ToNative(paramName));
|
||||
}
|
||||
|
||||
System::Nullable<int> Animator::GetIntParameter(System::String^ paramName)
|
||||
{
|
||||
auto val = GetNativeComponent()->GetParameter<int>(Convert::ToNative(paramName));
|
||||
if (val.has_value())
|
||||
return System::Nullable<int>(val.value());
|
||||
return {};
|
||||
}
|
||||
|
||||
System::Nullable<float> Animator::GetFloatParameter(System::String^ paramName)
|
||||
{
|
||||
auto val = GetNativeComponent()->GetParameter<float>(Convert::ToNative(paramName));
|
||||
if (val.has_value())
|
||||
return System::Nullable<float>(val.value());
|
||||
return {};
|
||||
}
|
||||
|
||||
System::Nullable<bool> Animator::GetBoolParameter(System::String^ paramName)
|
||||
{
|
||||
auto val = GetNativeComponent()->GetParameter<bool>(Convert::ToNative(paramName));
|
||||
if (val.has_value())
|
||||
return System::Nullable<bool>(val.value());
|
||||
return {};
|
||||
}
|
||||
|
||||
System::Nullable<bool> Animator::GetTriggerState(System::String^ paramName)
|
||||
{
|
||||
return GetBoolParameter(paramName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
/************************************************************************************//*!
|
||||
\file Animator.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Mar 8, 2023
|
||||
\brief Contains the definition of the managed Animator class with the
|
||||
declaration of functions for working with it.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2023 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 "Components/Component.hxx"
|
||||
// External Dependencies
|
||||
#include "Animation/SHAnimatorComponent.h"
|
||||
// Project Includes
|
||||
#include "Assets/AnimationClipAsset.hxx"
|
||||
#include "Assets/AnimationControllerAsset.hxx"
|
||||
#include "Assets/AnimationRigAsset.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// CLR version of the SHADE Engine's SHAnimatorComponent.
|
||||
/// </summary>
|
||||
public ref class Animator : public Component<SHAnimatorComponent>
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructs a Animator Component that represents a native Animator
|
||||
/// component tied to the specified Entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">Entity that this Component will be tied to.</param>
|
||||
Animator(Entity entity);
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Animation Controller used to controller the animation of this Animator.
|
||||
/// </summary>
|
||||
property AnimationControllerAsset AnimationController
|
||||
{
|
||||
AnimationControllerAsset get();
|
||||
void set(AnimationControllerAsset value);
|
||||
}
|
||||
/// <summary>
|
||||
/// The shared Material used to render this Animator and other Animators
|
||||
/// using the same base Material.
|
||||
/// </summary>
|
||||
property AnimationRigAsset Rig
|
||||
{
|
||||
AnimationRigAsset get();
|
||||
void set(AnimationRigAsset value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Name of the current node if there is an animation controller attached. If
|
||||
/// there is none, null is returned.
|
||||
/// </summary>
|
||||
property System::String^ CurrentNodeName
|
||||
{
|
||||
System::String^ get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Plays the currently loaded animation from the last time.
|
||||
/// </summary>
|
||||
void Play();
|
||||
/// <summary>
|
||||
/// Plays the specified animation clip from the start. This will unset any
|
||||
/// SHAnimationControllers that have been set.
|
||||
/// </summary>
|
||||
/// <param name="clip">Animation clip to play.</param>
|
||||
void Play(AnimationClipAsset clip);
|
||||
/// <summary>
|
||||
/// Plays the specified animation clip from the start one time only. This will unset
|
||||
/// any SHAnimationControllers that have been set.
|
||||
/// </summary>
|
||||
/// <param name="clip">Animation clip to play.</param>
|
||||
void PlayOneShot(AnimationClipAsset clip);
|
||||
/// <summary>
|
||||
/// Plays the currently loaded animation clip from the start. Note that this only
|
||||
/// works when using manual playback mode.
|
||||
/// </summary>
|
||||
void PlayFromStart();
|
||||
/// <summary>
|
||||
/// Pauses the animation at the current time.
|
||||
/// </summary>
|
||||
void Pause();
|
||||
/// <summary>
|
||||
/// Stops the animation and resets the play time back to 0. Note that this only
|
||||
/// works when using manual playback mode. This is not supported when using an
|
||||
/// Animation Controller.
|
||||
/// </summary>
|
||||
void Stop();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Parameter Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Sets the parameter of the for the string. Does nothing if an invalid param name
|
||||
/// is provided. Type of the parameter is not checked. Also does nothing if no
|
||||
/// animation controller is specified.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of parameter. Only bool, int, floats are supported.
|
||||
/// </typeparam>
|
||||
/// <param name="paramName">Name of the parameter.</param>
|
||||
/// <param name="value">Value to set the parameter to.</param>
|
||||
generic<typename T>
|
||||
void SetParameter(System::String^ paramName, T value);
|
||||
/// <summary>
|
||||
/// Sets the flag for a trigger parameter. Does nothing if an invalid param name is
|
||||
/// provided or if the param name refers to a parameter that is not a trigger.
|
||||
/// </summary>
|
||||
/// <param name="paramName">Name of the parameter.</param>
|
||||
void SetTrigger(System::String^ paramName);
|
||||
/// <summary>
|
||||
/// Gets the parameter of the for the named parameter of type int. Types are
|
||||
/// checked and will not return a value if there is nothing. Returns nothing if
|
||||
/// there is no animation controller specified either.
|
||||
/// </summary>
|
||||
/// <param name="paramName">Name of the parameter.</param>
|
||||
/// <returns>The value of the parameter or nothing if invalid.</returns>
|
||||
System::Nullable<int> GetIntParameter(System::String^ paramName);
|
||||
/// <summary>
|
||||
/// Gets the parameter of the for the named parameter of type float. Types are
|
||||
/// checked and will not return a value if there is nothing. Returns nothing if
|
||||
/// there is no animation controller specified either.
|
||||
/// </summary>
|
||||
/// <param name="paramName">Name of the parameter.</param>
|
||||
/// <returns>The value of the parameter or nothing if invalid.</returns>
|
||||
System::Nullable<float> GetFloatParameter(System::String^ paramName);
|
||||
/// <summary>
|
||||
/// Gets the parameter of the for the named parameter of type bool. Types are
|
||||
/// checked and will not return a value if there is nothing. Returns nothing if
|
||||
/// there is no animation controller specified either.
|
||||
/// </summary>
|
||||
/// <param name="paramName">Name of the parameter.</param>
|
||||
/// <returns>The value of the parameter or nothing if invalid.</returns>
|
||||
System::Nullable<bool> GetBoolParameter(System::String^ paramName);
|
||||
/// <summary>
|
||||
/// Checks if the trigger flag for the named trigger parameter is set. Types are
|
||||
/// checked and will not return a value if there is nothing. Returns nothing if
|
||||
/// there is no animation controller specified either.
|
||||
/// </summary>
|
||||
/// <param name="paramName">Name of the parameter.</param>
|
||||
/// <returns>True if the trigger is set.</returns>
|
||||
System::Nullable<bool> GetTriggerState(System::String^ paramName);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue