Added serialization of AnimatorComponent

This commit is contained in:
Kah Wei 2023-01-29 20:35:18 +08:00
parent 2d1987e14b
commit 4a00312f57
4 changed files with 37 additions and 1 deletions

View File

@ -152,6 +152,7 @@ namespace Sandbox
SHComponentManager::CreateComponentSparseSet<SHColliderComponent>(); SHComponentManager::CreateComponentSparseSet<SHColliderComponent>();
SHComponentManager::CreateComponentSparseSet<SHTransformComponent>(); SHComponentManager::CreateComponentSparseSet<SHTransformComponent>();
SHComponentManager::CreateComponentSparseSet<SHRenderable>(); SHComponentManager::CreateComponentSparseSet<SHRenderable>();
SHComponentManager::CreateComponentSparseSet<SHAnimatorComponent>();
//SHComponentManager::CreateComponentSparseSet<SHCameraComponent>(); //SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
SHAssetManager::Load(); SHAssetManager::Load();

View File

@ -443,7 +443,7 @@ namespace SHADE
boneMatrixData.insert(boneMatrixData.end(), extraMatricesToAdd, SHMatrix::Identity); boneMatrixData.insert(boneMatrixData.end(), extraMatricesToAdd, SHMatrix::Identity);
} }
// We don't have to account for missing animators or reset indices as the renderable list are not updated at this point // TODO: Recompute boneindexdata if a new animator was added
} }
// Update GPU Buffers // Update GPU Buffers

View File

@ -210,6 +210,7 @@ namespace SHADE
AddComponentToComponentNode<SHButtonComponent>(components, eid); AddComponentToComponentNode<SHButtonComponent>(components, eid);
AddComponentToComponentNode<SHTextRenderableComponent>(components, eid); AddComponentToComponentNode<SHTextRenderableComponent>(components, eid);
AddComponentToComponentNode<SHAnimatorComponent>(components, eid);
node[ComponentsNode] = components; node[ComponentsNode] = components;
@ -266,6 +267,7 @@ namespace SHADE
AddComponentID<SHCanvasComponent>(componentIDList, componentsNode); AddComponentID<SHCanvasComponent>(componentIDList, componentsNode);
AddComponentID<SHButtonComponent>(componentIDList, componentsNode); AddComponentID<SHButtonComponent>(componentIDList, componentsNode);
AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode); AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode);
AddComponentID<SHAnimatorComponent>(componentIDList, componentsNode);
return componentIDList; return componentIDList;
} }
@ -348,5 +350,6 @@ namespace SHADE
SHSerializationHelper::InitializeComponentFromNode<SHButtonComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHButtonComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHTextRenderableComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHTextRenderableComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHAnimatorComponent>(componentsNode, eid);
} }
} }

View File

@ -15,6 +15,7 @@
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h" #include "Graphics/MiddleEnd/TextRendering/SHFont.h"
#include "Physics/Collision/SHCollisionTagMatrix.h" #include "Physics/Collision/SHCollisionTagMatrix.h"
#include "Animation/SHAnimatorComponent.h"
namespace YAML namespace YAML
{ {
@ -29,6 +30,8 @@ namespace YAML
struct HasYAMLConv<SHRenderable> : std::true_type {}; struct HasYAMLConv<SHRenderable> : std::true_type {};
template<> template<>
struct HasYAMLConv<SHTextRenderableComponent> : std::true_type {}; struct HasYAMLConv<SHTextRenderableComponent> : std::true_type {};
template<>
struct HasYAMLConv<SHAnimatorComponent> : std::true_type {};
template<> template<>
struct convert<SHVec4> struct convert<SHVec4>
@ -386,4 +389,33 @@ namespace YAML
return true; return true;
} }
}; };
template<>
struct convert<SHAnimatorComponent>
{
static constexpr std::string_view RIG_YAML_TAG = "Rig";
static constexpr std::string_view CLIP_YAML_TAG = "Clip";
static YAML::Node encode(SHAnimatorComponent const& rhs)
{
YAML::Node node;
node[RIG_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHRig>(rhs.GetRig()).value_or(0);
node[CLIP_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHAnimationClip>(rhs.GetCurrentClip()).value_or(0);
return node;
}
static bool decode(YAML::Node const& node, SHAnimatorComponent& rhs)
{
if (node[RIG_YAML_TAG.data()].IsDefined())
{
rhs.SetRig(SHResourceManager::LoadOrGet<SHRig>(node[RIG_YAML_TAG.data()].as<AssetID>()));
}
if (node[CLIP_YAML_TAG.data()].IsDefined())
{
rhs.SetClip(SHResourceManager::LoadOrGet<SHAnimationClip>(node[CLIP_YAML_TAG.data()].as<AssetID>()));
}
return true;
}
};
} }