Implemented Animation Clip asset and animation controller #410
|
@ -17,6 +17,52 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* AnimParam Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
SHAnimationController::AnimParam::AnimParam(Type type)
|
||||||
|
: ParamType { type }
|
||||||
|
{
|
||||||
|
switch (ParamType)
|
||||||
|
{
|
||||||
|
case Type::Bool:
|
||||||
|
Value = false;
|
||||||
|
break;
|
||||||
|
case Type::Float:
|
||||||
|
Value = 0.0f;
|
||||||
|
break;
|
||||||
|
case Type::Int:
|
||||||
|
Value = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Transition - Usage Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
bool SHAnimationController::Transition::EvaluateCondition(const AnimParam& testParam) const noexcept
|
||||||
|
{
|
||||||
|
// Don't match, instant fail
|
||||||
|
if (testParam.ParamType != Param.ParamType)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Evaluate them accordingly
|
||||||
|
switch (Param.ParamType)
|
||||||
|
{
|
||||||
|
case AnimParam::Type::Bool:
|
||||||
|
case AnimParam::Type::Trigger:
|
||||||
|
return evaluateCondition(std::get<bool>(testParam.Value));
|
||||||
|
case AnimParam::Type::Float:
|
||||||
|
return evaluateCondition(std::get<float>(testParam.Value));
|
||||||
|
break;
|
||||||
|
case AnimParam::Type::Int:
|
||||||
|
return evaluateCondition(std::get<int>(testParam.Value));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Lifecycle Functions */
|
/* Lifecycle Functions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -38,7 +84,33 @@ namespace SHADE
|
||||||
// Go to next state
|
// Go to next state
|
||||||
for (const auto& transition : instData.CurrentNode->Transitions)
|
for (const auto& transition : instData.CurrentNode->Transitions)
|
||||||
{
|
{
|
||||||
// TODO
|
// Check for no condition special case
|
||||||
|
if (transition.Condition == Transition::ConditionType::None)
|
||||||
|
{
|
||||||
|
changeNode(instData, transition.Target);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check if we have the parameter
|
||||||
|
if (!instData.Params.contains(transition.ParamName))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// If evaluation success, we transition
|
||||||
|
AnimParam& param = instData.Params[transition.ParamName];
|
||||||
|
if (transition.EvaluateCondition(param))
|
||||||
|
{
|
||||||
|
changeNode(instData, transition.Target);
|
||||||
|
|
||||||
|
// If trigger, we need to unset it
|
||||||
|
if (param.ParamType == AnimParam::Type::Trigger)
|
||||||
|
{
|
||||||
|
param.Value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,22 +155,11 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* AnimParam Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
SHAnimationController::AnimParam::AnimParam(Type type)
|
void SHAnimationController::changeNode(InstanceData& instData, Handle<Node> newNode)
|
||||||
: ParamType { type }
|
|
||||||
{
|
{
|
||||||
switch (ParamType)
|
instData.CurrentNode = newNode;
|
||||||
{
|
instData.ClipPlaybackTime = 0.0f;
|
||||||
case Type::Bool:
|
|
||||||
Value = false;
|
|
||||||
break;
|
|
||||||
case Type::Float:
|
|
||||||
Value = 0.0f;
|
|
||||||
break;
|
|
||||||
case Type::Int:
|
|
||||||
Value = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace SHADE
|
||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
Bool,
|
Bool,
|
||||||
Trigger,
|
Trigger, // Variant of bool that can only be set to true and will be unset when consumed.
|
||||||
Float,
|
Float,
|
||||||
Int
|
Int
|
||||||
};
|
};
|
||||||
|
@ -69,7 +69,7 @@ namespace SHADE
|
||||||
/// on the specified type.
|
/// on the specified type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">Type of AnimParam.</param>
|
/// <param name="type">Type of AnimParam.</param>
|
||||||
explicit AnimParam(Type type);
|
explicit AnimParam(Type type = Type::Int);
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
|
@ -104,8 +104,26 @@ namespace SHADE
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*-------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------*/
|
||||||
ConditionType Condition;
|
ConditionType Condition;
|
||||||
AnimParam::ValueType Threshold;
|
AnimParam Param;
|
||||||
|
std::string ParamName;
|
||||||
Handle<Node> Target;
|
Handle<Node> Target;
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*-------------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Checks the condition of this Transition against an animation paramter.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="testParam">Parameter to test with.</param>
|
||||||
|
/// <returns>Whether the condition passed.</returns>
|
||||||
|
bool EvaluateCondition(const AnimParam& testParam) const noexcept;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*-------------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*-------------------------------------------------------------------------------*/
|
||||||
|
template<typename T>
|
||||||
|
bool evaluateCondition(T value) const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -167,5 +185,12 @@ namespace SHADE
|
||||||
Handle<Node> startNode;
|
Handle<Node> startNode;
|
||||||
std::vector<Handle<Node>> nodes;
|
std::vector<Handle<Node>> nodes;
|
||||||
std::unordered_map<std::string, AnimParam::Type> parameters;
|
std::unordered_map<std::string, AnimParam::Type> parameters;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void changeNode(InstanceData& instData, Handle<Node> newNode);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "SHAnimationController.hpp"
|
|
@ -0,0 +1,67 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHAnimationController.hpp
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Mar 1, 2023
|
||||||
|
\brief Contains the definition of template functions SHAnimationController.
|
||||||
|
|
||||||
|
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
|
||||||
|
#include "SHAnimationController.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
bool SHAnimationController::Transition::evaluateCondition(T value) const noexcept
|
||||||
|
{
|
||||||
|
// Early failure if invalid data
|
||||||
|
if (!std::holds_alternative<T>(Param.Value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Get the value
|
||||||
|
const T PARAM_VAL = std::get<T>(Param.Value);
|
||||||
|
|
||||||
|
// Handle condition type
|
||||||
|
switch (Condition)
|
||||||
|
{
|
||||||
|
case SHAnimationController::Transition::ConditionType::None:
|
||||||
|
return true;
|
||||||
|
case SHAnimationController::Transition::ConditionType::Equals:
|
||||||
|
if constexpr (std::is_floating_point_v<T>)
|
||||||
|
{
|
||||||
|
static constexpr T EPSILON = static_cast<T>(0.001);
|
||||||
|
return std::abs(std::abs(value) - std::abs(PARAM_VAL)) < EPSILON;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return value == PARAM_VAL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SHAnimationController::Transition::ConditionType::NotEquals:
|
||||||
|
if constexpr (std::is_floating_point_v<T>)
|
||||||
|
{
|
||||||
|
static constexpr T EPSILON = static_cast<T>(0.001);
|
||||||
|
return std::abs(std::abs(value) - std::abs(PARAM_VAL)) > EPSILON;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return value != PARAM_VAL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SHAnimationController::Transition::ConditionType::LessThan:
|
||||||
|
return PARAM_VAL < value;
|
||||||
|
case SHAnimationController::Transition::ConditionType::LessThanOrEqual:
|
||||||
|
return PARAM_VAL <= value;
|
||||||
|
case SHAnimationController::Transition::ConditionType::GreaterThan:
|
||||||
|
return PARAM_VAL > value;
|
||||||
|
case SHAnimationController::Transition::ConditionType::GreaterThanOrEqual:
|
||||||
|
return PARAM_VAL >= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neither of the existing cases
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -71,7 +71,7 @@ namespace SHADE
|
||||||
//! of the texture library would mean the recreation of the desc set that also
|
//! of the texture library would mean the recreation of the desc set that also
|
||||||
//! involves the generic data, which is bad bad bad. Solution is to separate the
|
//! involves the generic data, which is bad bad bad. Solution is to separate the
|
||||||
//! 2 desc sets.
|
//! 2 desc sets.
|
||||||
static constexpr uint32_t DEFAULT_MAX_TEXTURES = 2000;
|
static constexpr uint32_t DEFAULT_MAX_TEXTURES = 1000;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Usage Functions */
|
/* Usage Functions */
|
||||||
|
|
Loading…
Reference in New Issue