Added functions for setting animation parameters
This commit is contained in:
parent
4144fe0d4a
commit
e285d5e6b2
|
@ -192,6 +192,20 @@ namespace SHADE
|
||||||
parameters.erase(name);
|
parameters.erase(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHAnimationController::SetTrigger(InstanceData& instData, const std::string& paramName)
|
||||||
|
{
|
||||||
|
// Invalid param
|
||||||
|
if (!parameters.contains(paramName))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Not a trigger
|
||||||
|
if (parameters[paramName] != AnimParam::Type::Trigger)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Set the flag
|
||||||
|
instData.Params[paramName].Value = true;
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -14,6 +14,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// STL Includes
|
// STL Includes
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
|
@ -191,7 +192,37 @@ namespace SHADE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of the parameter.</param>
|
/// <param name="name">Name of the parameter.</param>
|
||||||
void RemoveParameter(const std::string& name);
|
void RemoveParameter(const std::string& name);
|
||||||
void SetStartingNode(Handle<Node> node);
|
/// <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.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">
|
||||||
|
/// Type of parameter. Only bool, int, floats are supported.
|
||||||
|
/// </typeparam>
|
||||||
|
/// <param name="instData">Data of the instance to update.</param>
|
||||||
|
/// <param name="paramName">Name of the parameter.</param>
|
||||||
|
/// <param name="value">Value to set the parameter to.</param>
|
||||||
|
template<typename T>
|
||||||
|
void SetParameter(InstanceData& instData, const std::string& paramName, T value);
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the parameter of the for the string. Types are checked and will not return
|
||||||
|
/// a value if there is nothing.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">
|
||||||
|
/// Type of parameter. Only bool, int, floats are supported.
|
||||||
|
/// </typeparam>
|
||||||
|
/// <param name="instData">Data of the instance to update.</param>
|
||||||
|
/// <param name="paramName">Name of the parameter.</param>
|
||||||
|
/// <returns>The value of the parameter or nothing if invalid.</returns>
|
||||||
|
template<typename T>
|
||||||
|
std::optional<T> GetParameter(InstanceData& instData, const std::string& paramName);
|
||||||
|
/// <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="instData">Data of the instance to update.</param>
|
||||||
|
/// <param name="paramName">Name of the parameter.</param>
|
||||||
|
void SetTrigger(InstanceData& instData, const std::string& paramName);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Getters */
|
/* Getters */
|
||||||
|
|
|
@ -66,4 +66,55 @@ namespace SHADE
|
||||||
// Neither of the existing cases
|
// Neither of the existing cases
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void SHAnimationController::SetParameter(InstanceData& instData, const std::string& paramName, T value)
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Set the value
|
||||||
|
instData.Params[paramName].Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::optional<T> SHAnimationController::GetParameter(InstanceData& instData, const std::string& paramName)
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// Check if the type matches
|
||||||
|
const auto TYPE = parameters[paramName];
|
||||||
|
if constexpr (std::is_same_v<T, bool>)
|
||||||
|
{
|
||||||
|
if (TYPE != AnimParam::Type::Bool && TYPE != AnimParam::Type::Trigger)
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_same_v<T, float>)
|
||||||
|
{
|
||||||
|
if (parameters[paramName] != AnimParam::Type::Float)
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_same_v<T, int>)
|
||||||
|
{
|
||||||
|
if (parameters[paramName] != AnimParam::Type::Int)
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the correct value
|
||||||
|
if (instData.Params.contains(paramName))
|
||||||
|
{
|
||||||
|
return instData.Params[paramName];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return T(); // Default constructed value
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -199,6 +199,14 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHAnimatorComponent::SetTrigger(const std::string& paramName)
|
||||||
|
{
|
||||||
|
if (!animController)
|
||||||
|
return;
|
||||||
|
|
||||||
|
return animController->SetTrigger(animInstanceData, paramName);
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Helper Functions - Loading */
|
/* Helper Functions - Loading */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -95,7 +95,42 @@ namespace SHADE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newRig">Rig to use.</param>
|
/// <param name="newRig">Rig to use.</param>
|
||||||
void SetRig(Handle<SHRig> newRig);
|
void SetRig(Handle<SHRig> newRig);
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the animation controller to use for this animator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newRig">Animation controller to use.</param>
|
||||||
void SetAnimationController(Handle<SHAnimationController> ac);
|
void SetAnimationController(Handle<SHAnimationController> ac);
|
||||||
|
/// <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>
|
||||||
|
template<typename T>
|
||||||
|
void SetParameter(const std::string& paramName, T value);
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the parameter of the for the string. Types are checked and will not return
|
||||||
|
/// a value if there is nothing. Returns nothing if there is no animation controller
|
||||||
|
/// specified either.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">
|
||||||
|
/// Type of parameter. Only bool, int, floats are supported.
|
||||||
|
/// </typeparam>
|
||||||
|
/// <param name="paramName">Name of the parameter.</param>
|
||||||
|
/// <returns>The value of the parameter or nothing if invalid.</returns>
|
||||||
|
template<typename T>
|
||||||
|
std::optional<T> GetParameter(const std::string& paramName);
|
||||||
|
/// <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="instData">Data of the instance to .</param>
|
||||||
|
/// <param name="paramName">Name of the parameter.</param>
|
||||||
|
void SetTrigger(const std::string& paramName);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Getter Functions */
|
/* Getter Functions */
|
||||||
|
|
|
@ -22,6 +22,26 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Setter Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
template<typename T>
|
||||||
|
std::optional<T> SHAnimatorComponent::GetParameter(const std::string& paramName)
|
||||||
|
{
|
||||||
|
if (!animController)
|
||||||
|
return;
|
||||||
|
|
||||||
|
return animController->GetParameter(paramName);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
void SHAnimatorComponent::SetParameter(const std::string& paramName, T value)
|
||||||
|
{
|
||||||
|
if (!animController)
|
||||||
|
return;
|
||||||
|
|
||||||
|
return animController->SetParameter(paramName, value);
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in New Issue