diff --git a/SHADE_Engine/src/Animation/SHAnimationClip.h b/SHADE_Engine/src/Animation/SHAnimationClip.h
index 9b93a7a3..9de621d0 100644
--- a/SHADE_Engine/src/Animation/SHAnimationClip.h
+++ b/SHADE_Engine/src/Animation/SHAnimationClip.h
@@ -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
diff --git a/SHADE_Engine/src/Animation/SHAnimationController.cpp b/SHADE_Engine/src/Animation/SHAnimationController.cpp
index 2347ca6e..9b7b6de2 100644
--- a/SHADE_Engine/src/Animation/SHAnimationController.cpp
+++ b/SHADE_Engine/src/Animation/SHAnimationController.cpp
@@ -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
{
diff --git a/SHADE_Engine/src/Animation/SHAnimationController.h b/SHADE_Engine/src/Animation/SHAnimationController.h
index e593bc63..56bf6f45 100644
--- a/SHADE_Engine/src/Animation/SHAnimationController.h
+++ b/SHADE_Engine/src/Animation/SHAnimationController.h
@@ -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 */
+ /*-----------------------------------------------------------------------------------*/
///
/// 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.
///
- struct AnimParam
+ struct SH_API AnimParam
{
/*-------------------------------------------------------------------------------*/
/* Type Definition */
diff --git a/SHADE_Engine/src/Animation/SHAnimationController.hpp b/SHADE_Engine/src/Animation/SHAnimationController.hpp
index 98fa35e6..7b86f125 100644
--- a/SHADE_Engine/src/Animation/SHAnimationController.hpp
+++ b/SHADE_Engine/src/Animation/SHAnimationController.hpp
@@ -73,7 +73,7 @@ namespace SHADE
static_assert(std::is_same_v || std::is_same_v || std::is_same_v, "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 || std::is_same_v || std::is_same_v, "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
{
diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp
index 71ae4e03..36f8e501 100644
--- a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp
+++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp
@@ -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;
}
diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.h b/SHADE_Engine/src/Animation/SHAnimatorComponent.h
index 8beef34c..ef67d35e 100644
--- a/SHADE_Engine/src/Animation/SHAnimatorComponent.h
+++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.h
@@ -33,7 +33,6 @@ namespace SHADE
class SHRig;
struct SHRigNode;
class SHAnimationClip;
- class SHVkBuffer;
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
@@ -65,7 +64,8 @@ namespace SHADE
/// Animation clip to play.
void PlayOneShot(Handle clip);
///
- /// 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.
///
void PlayFromStart();
///
@@ -73,7 +73,9 @@ namespace SHADE
///
void Pause();
///
- /// 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.
///
void Stop();
@@ -100,6 +102,10 @@ namespace SHADE
///
/// Animation controller to use.
void SetAnimationController(Handle ac);
+
+ /*---------------------------------------------------------------------------------*/
+ /* Parameter Functions */
+ /*---------------------------------------------------------------------------------*/
///
/// 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.
///
- /// Data of the instance to .
/// Name of the parameter.
void SetTrigger(const std::string& paramName);
@@ -156,6 +161,10 @@ namespace SHADE
///
/// Handle to the current Animation Controller node.
Handle GetCurrentNode() const noexcept { return animInstanceData.CurrentNode; }
+ ///
+ /// Retrieves the currently set animation controller.
+ ///
+ ///
Handle GetAnimationController() const noexcept { return animController; }
private:
diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp b/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp
index ec64bc6e..0e51f2c3 100644
--- a/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp
+++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp
@@ -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 SHAnimatorComponent::GetParameter(const std::string& paramName)
{
if (!animController)
- return;
+ return {};
- return animController->GetParameter(paramName);
+ return animController->GetParameter(animInstanceData, paramName);
}
template
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);
}
/*-----------------------------------------------------------------------------------*/
diff --git a/SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h b/SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h
index 6e98c661..b57664e8 100644
--- a/SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h
+++ b/SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h
@@ -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
diff --git a/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp
index b795b1fa..1c9dc61d 100644
--- a/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp
+++ b/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp
@@ -78,7 +78,6 @@ namespace SHADE
// Generate new asset
const AssetID NEW_ASSET_ID = SHAssetManager::CreateNewAsset(AssetType::ANIM_CLIP, newAssetName);
auto animClip = SHAssetManager::GetData(NEW_ASSET_ID);
- animClip->animRawDataAssetId = SHResourceManager::GetAssetID(rawAnimation).value_or(INVALID_ASSET_ID);
animClip->firstIndex = firstIndex;
animClip->lastIndex = lastIndex;
SHAssetManager::SaveAsset(NEW_ASSET_ID);
diff --git a/SHADE_Engine/src/Resource/SHResourceManager.hpp b/SHADE_Engine/src/Resource/SHResourceManager.hpp
index cdda1ad7..a405b298 100644
--- a/SHADE_Engine/src/Resource/SHResourceManager.hpp
+++ b/SHADE_Engine/src/Resource/SHResourceManager.hpp
@@ -370,7 +370,7 @@ namespace SHADE
loadedAssetData.emplace_back(assetId);
return resourceHub.Create
(
- LoadOrGet(assetData.animRawDataAssetId),
+ LoadOrGet(assetId), // TODO: Wrong, we need to grab the parent asset's ID
assetData.firstIndex,
assetData.lastIndex
);
diff --git a/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp b/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp
index d89a7b16..8feef560 100644
--- a/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp
+++ b/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp
@@ -44,6 +44,21 @@ namespace SHADE
return SHResourceManager::LoadOrGet(assetId);
}
+ Handle SHResourceManagerInterface::LoadOrGetAnimationClip(AssetID assetId)
+ {
+ return SHResourceManager::LoadOrGet(assetId);
+ }
+
+ Handle SHResourceManagerInterface::LoadOrGetAnimationController(AssetID assetId)
+ {
+ return SHResourceManager::LoadOrGet(assetId);
+ }
+
+ Handle SHResourceManagerInterface::LoadOrGetRig(AssetID assetId)
+ {
+ return SHResourceManager::LoadOrGet(assetId);
+ }
+
/*-----------------------------------------------------------------------------------*/
/* Query Functions */
/*-----------------------------------------------------------------------------------*/
diff --git a/SHADE_Engine/src/Resource/SHResourceManagerInterface.h b/SHADE_Engine/src/Resource/SHResourceManagerInterface.h
index 359bd7c8..a09f3463 100644
--- a/SHADE_Engine/src/Resource/SHResourceManagerInterface.h
+++ b/SHADE_Engine/src/Resource/SHResourceManagerInterface.h
@@ -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
/// Asset ID of the resource to load.
/// Handle to the resource to retrieve.
static Handle LoadOrGetFont(AssetID assetId);
+ ///
+ /// Wrapper for SHResourceManager::LoadOrGet().
+ ///
+ /// Asset ID of the resource to load.
+ /// Handle to the resource to retrieve.
+ static Handle LoadOrGetAnimationClip(AssetID assetId);
+ ///
+ /// Wrapper for SHResourceManager::LoadOrGet().
+ ///
+ /// Asset ID of the resource to load.
+ /// Handle to the resource to retrieve.
+ static Handle LoadOrGetAnimationController(AssetID assetId);
+ ///
+ /// Wrapper for SHResourceManager::LoadOrGet().
+ ///
+ /// Asset ID of the resource to load.
+ /// Handle to the resource to retrieve.
+ static Handle LoadOrGetRig(AssetID assetId);
/*---------------------------------------------------------------------------------*/
/* Query Functions */
diff --git a/SHADE_Managed/src/Assets/AnimationClipAsset.cxx b/SHADE_Managed/src/Assets/AnimationClipAsset.cxx
new file mode 100644
index 00000000..603d3983
--- /dev/null
+++ b/SHADE_Managed/src/Assets/AnimationClipAsset.cxx
@@ -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 AnimationClipAsset::NativeObject::get()
+ try
+ {
+ return SHResourceManagerInterface::LoadOrGetAnimationClip(asset.NativeAssetID);
+ }
+ catch (const BadHandleCastException&)
+ {
+ return Handle();
+ }
+ 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);
+ }
+}
diff --git a/SHADE_Managed/src/Assets/AnimationClipAsset.hxx b/SHADE_Managed/src/Assets/AnimationClipAsset.hxx
new file mode 100644
index 00000000..5a8c7845
--- /dev/null
+++ b/SHADE_Managed/src/Assets/AnimationClipAsset.hxx
@@ -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
+{
+ ///
+ /// 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.
+ ///
+ public value struct AnimationClipAsset
+ {
+ internal:
+ /*-----------------------------------------------------------------------------*/
+ /* Properties */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Copy of the Handle to the native object.
+ ///
+ property Handle NativeObject
+ {
+ Handle get();
+ }
+ ///
+ /// The raw asset ID of the asset.
+ ///
+ property AssetID NativeAssetID
+ {
+ AssetID get();
+ }
+
+ /*-----------------------------------------------------------------------------*/
+ /* Constructors/Destructor */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Constructor for the AnimationClip.
+ ///
+ /// AssetID to the AnimationClip asset.
+ AnimationClipAsset(AssetID AnimationClipId);
+
+ /*-----------------------------------------------------------------------------*/
+ /* Operator Overloads */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Implicit conversion operator to enable checking if a AnimationClip is valid.
+ ///
+ /// Asset to check.
+ /// True if the Asset is valid.
+ static operator bool(AnimationClipAsset asset);
+
+ /*-----------------------------------------------------------------------------*/
+ /* Conversion Operators */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Conversion operator to enable casting from a AnimationClip to an Asset.
+ ///
+ /// Vector3 to convert from.
+ static explicit operator Asset(AnimationClipAsset nativeAsset);
+ ///
+ /// Conversion operator to enable casting from a Asset to a AnimationClip.
+ ///
+ ///
+ static explicit operator AnimationClipAsset(Asset asset);
+
+ protected:
+ /*-----------------------------------------------------------------------------*/
+ /* Data Members */
+ /*-----------------------------------------------------------------------------*/
+ Asset asset;
+ };
+}
diff --git a/SHADE_Managed/src/Assets/AnimationControllerAsset.cxx b/SHADE_Managed/src/Assets/AnimationControllerAsset.cxx
new file mode 100644
index 00000000..044f94d2
--- /dev/null
+++ b/SHADE_Managed/src/Assets/AnimationControllerAsset.cxx
@@ -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 AnimationControllerAsset::NativeObject::get()
+ try
+ {
+ return SHResourceManagerInterface::LoadOrGetAnimationController(asset.NativeAssetID);
+ }
+ catch (const BadHandleCastException&)
+ {
+ return Handle();
+ }
+ 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);
+ }
+}
diff --git a/SHADE_Managed/src/Assets/AnimationControllerAsset.hxx b/SHADE_Managed/src/Assets/AnimationControllerAsset.hxx
new file mode 100644
index 00000000..1be74fb9
--- /dev/null
+++ b/SHADE_Managed/src/Assets/AnimationControllerAsset.hxx
@@ -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
+{
+ ///
+ /// Managed counterpart of the native AnimationController object containing the
+ /// state machine for controlling what AnimationClips that an Animator should play.
+ ///
+ public value struct AnimationControllerAsset
+ {
+ internal:
+ /*-----------------------------------------------------------------------------*/
+ /* Properties */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Copy of the Handle to the native object.
+ ///
+ property Handle NativeObject
+ {
+ Handle get();
+ }
+ ///
+ /// The raw asset ID of the asset.
+ ///
+ property AssetID NativeAssetID
+ {
+ AssetID get();
+ }
+
+ /*-----------------------------------------------------------------------------*/
+ /* Constructors/Destructor */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Constructor for the AnimationController.
+ ///
+ /// AssetID to the AnimationController asset.
+ AnimationControllerAsset(AssetID AnimationControllerId);
+
+ /*-----------------------------------------------------------------------------*/
+ /* Operator Overloads */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Implicit conversion operator to enable checking if a AnimationController is valid.
+ ///
+ /// Asset to check.
+ /// True if the Asset is valid.
+ static operator bool(AnimationControllerAsset asset);
+
+ /*-----------------------------------------------------------------------------*/
+ /* Conversion Operators */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Conversion operator to enable casting from a AnimationController to an Asset.
+ ///
+ /// Vector3 to convert from.
+ static explicit operator Asset(AnimationControllerAsset nativeAsset);
+ ///
+ /// Conversion operator to enable casting from a Asset to a AnimationController.
+ ///
+ ///
+ static explicit operator AnimationControllerAsset(Asset asset);
+
+ protected:
+ /*-----------------------------------------------------------------------------*/
+ /* Data Members */
+ /*-----------------------------------------------------------------------------*/
+ Asset asset;
+ };
+}
diff --git a/SHADE_Managed/src/Assets/AnimationRigAsset.cxx b/SHADE_Managed/src/Assets/AnimationRigAsset.cxx
new file mode 100644
index 00000000..154c6aee
--- /dev/null
+++ b/SHADE_Managed/src/Assets/AnimationRigAsset.cxx
@@ -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 AnimationRigAsset::NativeObject::get()
+ try
+ {
+ return SHResourceManagerInterface::LoadOrGetRig(asset.NativeAssetID);
+ }
+ catch (const BadHandleCastException&)
+ {
+ return Handle();
+ }
+ 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);
+ }
+}
diff --git a/SHADE_Managed/src/Assets/AnimationRigAsset.hxx b/SHADE_Managed/src/Assets/AnimationRigAsset.hxx
new file mode 100644
index 00000000..be43b7f0
--- /dev/null
+++ b/SHADE_Managed/src/Assets/AnimationRigAsset.hxx
@@ -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
+{
+ ///
+ /// Managed counterpart of the native Animation Rig object that specifies how an
+ /// Animation Clip affects the model that this Rig is attached to.
+ ///
+ public value struct AnimationRigAsset
+ {
+ internal:
+ /*-----------------------------------------------------------------------------*/
+ /* Properties */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Copy of the Handle to the native object.
+ ///
+ property Handle NativeObject
+ {
+ Handle get();
+ }
+ ///
+ /// The raw asset ID of the asset.
+ ///
+ property AssetID NativeAssetID
+ {
+ AssetID get();
+ }
+
+ /*-----------------------------------------------------------------------------*/
+ /* Constructors/Destructor */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Constructor for the AnimationRig.
+ ///
+ /// AssetID to the AnimationRig asset.
+ AnimationRigAsset(AssetID AnimationRigId);
+
+ /*-----------------------------------------------------------------------------*/
+ /* Operator Overloads */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Implicit conversion operator to enable checking if a AnimationRig is valid.
+ ///
+ /// Asset to check.
+ /// True if the Asset is valid.
+ static operator bool(AnimationRigAsset asset);
+
+ /*-----------------------------------------------------------------------------*/
+ /* Conversion Operators */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Conversion operator to enable casting from a AnimationRig to an Asset.
+ ///
+ /// Vector3 to convert from.
+ static explicit operator Asset(AnimationRigAsset nativeAsset);
+ ///
+ /// Conversion operator to enable casting from a Asset to a AnimationRig.
+ ///
+ ///
+ static explicit operator AnimationRigAsset(Asset asset);
+
+ protected:
+ /*-----------------------------------------------------------------------------*/
+ /* Data Members */
+ /*-----------------------------------------------------------------------------*/
+ Asset asset;
+ };
+}
diff --git a/SHADE_Managed/src/Components/Animator.cxx b/SHADE_Managed/src/Components/Animator.cxx
new file mode 100644
index 00000000..364ce046
--- /dev/null
+++ b/SHADE_Managed/src/Components/Animator.cxx
@@ -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());
+ }
+ 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());
+ }
+ else
+ {
+ GetNativeComponent()->SetRig(Handle(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
+ void Animator::SetParameter(System::String^ paramName, T value)
+ {
+ if (T::typeid == int::typeid)
+ {
+ GetNativeComponent()->SetParameter(Convert::ToNative(paramName), static_cast(value));
+ }
+ else if (T::typeid == float::typeid)
+ {
+ GetNativeComponent()->SetParameter(Convert::ToNative(paramName), static_cast(value));
+ }
+ else if (T::typeid == bool::typeid)
+ {
+ GetNativeComponent()->SetParameter(Convert::ToNative(paramName), static_cast(value));
+ }
+ }
+
+ void Animator::SetTrigger(System::String^ paramName)
+ {
+ GetNativeComponent()->SetTrigger(Convert::ToNative(paramName));
+ }
+
+ System::Nullable Animator::GetIntParameter(System::String^ paramName)
+ {
+ auto val = GetNativeComponent()->GetParameter(Convert::ToNative(paramName));
+ if (val.has_value())
+ return System::Nullable(val.value());
+ return {};
+ }
+
+ System::Nullable Animator::GetFloatParameter(System::String^ paramName)
+ {
+ auto val = GetNativeComponent()->GetParameter(Convert::ToNative(paramName));
+ if (val.has_value())
+ return System::Nullable(val.value());
+ return {};
+ }
+
+ System::Nullable Animator::GetBoolParameter(System::String^ paramName)
+ {
+ auto val = GetNativeComponent()->GetParameter(Convert::ToNative(paramName));
+ if (val.has_value())
+ return System::Nullable(val.value());
+ return {};
+ }
+
+ System::Nullable Animator::GetTriggerState(System::String^ paramName)
+ {
+ return GetBoolParameter(paramName);
+ }
+}
diff --git a/SHADE_Managed/src/Components/Animator.hxx b/SHADE_Managed/src/Components/Animator.hxx
new file mode 100644
index 00000000..7100c54b
--- /dev/null
+++ b/SHADE_Managed/src/Components/Animator.hxx
@@ -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
+{
+ ///
+ /// CLR version of the SHADE Engine's SHAnimatorComponent.
+ ///
+ public ref class Animator : public Component
+ {
+ internal:
+ /*-----------------------------------------------------------------------------*/
+ /* Constructors */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Constructs a Animator Component that represents a native Animator
+ /// component tied to the specified Entity.
+ ///
+ /// Entity that this Component will be tied to.
+ Animator(Entity entity);
+
+ public:
+ /*-----------------------------------------------------------------------------*/
+ /* Properties */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Animation Controller used to controller the animation of this Animator.
+ ///
+ property AnimationControllerAsset AnimationController
+ {
+ AnimationControllerAsset get();
+ void set(AnimationControllerAsset value);
+ }
+ ///
+ /// The shared Material used to render this Animator and other Animators
+ /// using the same base Material.
+ ///
+ property AnimationRigAsset Rig
+ {
+ AnimationRigAsset get();
+ void set(AnimationRigAsset value);
+ }
+ ///
+ /// Name of the current node if there is an animation controller attached. If
+ /// there is none, null is returned.
+ ///
+ property System::String^ CurrentNodeName
+ {
+ System::String^ get();
+ }
+
+ /*-----------------------------------------------------------------------------*/
+ /* Usage Functions */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Plays the currently loaded animation from the last time.
+ ///
+ void Play();
+ ///
+ /// Plays the specified animation clip from the start. This will unset any
+ /// SHAnimationControllers that have been set.
+ ///
+ /// Animation clip to play.
+ void Play(AnimationClipAsset clip);
+ ///
+ /// Plays the specified animation clip from the start one time only. This will unset
+ /// any SHAnimationControllers that have been set.
+ ///
+ /// Animation clip to play.
+ void PlayOneShot(AnimationClipAsset clip);
+ ///
+ /// Plays the currently loaded animation clip from the start. Note that this only
+ /// works when using manual playback mode.
+ ///
+ void PlayFromStart();
+ ///
+ /// Pauses the animation at the current time.
+ ///
+ void Pause();
+ ///
+ /// 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.
+ ///
+ void Stop();
+
+ /*-----------------------------------------------------------------------------*/
+ /* Parameter Functions */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// 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.
+ ///
+ ///
+ /// Type of parameter. Only bool, int, floats are supported.
+ ///
+ /// Name of the parameter.
+ /// Value to set the parameter to.
+ generic
+ void SetParameter(System::String^ paramName, T value);
+ ///
+ /// 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.
+ ///
+ /// Name of the parameter.
+ void SetTrigger(System::String^ paramName);
+ ///
+ /// 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.
+ ///
+ /// Name of the parameter.
+ /// The value of the parameter or nothing if invalid.
+ System::Nullable GetIntParameter(System::String^ paramName);
+ ///
+ /// 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.
+ ///
+ /// Name of the parameter.
+ /// The value of the parameter or nothing if invalid.
+ System::Nullable GetFloatParameter(System::String^ paramName);
+ ///
+ /// 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.
+ ///
+ /// Name of the parameter.
+ /// The value of the parameter or nothing if invalid.
+ System::Nullable GetBoolParameter(System::String^ paramName);
+ ///
+ /// 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.
+ ///
+ /// Name of the parameter.
+ /// True if the trigger is set.
+ System::Nullable GetTriggerState(System::String^ paramName);
+ };
+}
+