Implemented Animation Clip asset and animation controller #410

Merged
XiaoQiDigipen merged 66 commits from SP3-22-AnimationController into main 2023-03-09 16:19:40 +08:00
2 changed files with 83 additions and 15 deletions
Showing only changes of commit eae6f6399b - Show all commits

View File

@ -1,7 +1,7 @@
#include "SHpch.h"
#include "SHBinaryLoader.h"
#include "Assets/Asset Types/SHAnimClipAsset.h"
#include "Assets/Asset Types/SHAnimClipContainerAsset.h"
#include <fstream>
@ -19,15 +19,9 @@ namespace SHADE
auto const extension = path.extension().string();
SHAssetData* result{nullptr};
if (extension == ANIM_CLIP_EXTENSION)
if (extension == ANIM_CONTAINER_EXTENSION)
{
const auto data = new SHAnimClipAsset();
file.read(
reinterpret_cast<char*>(&data->animRawDataAssetId),
sizeof(uint32_t) * 3
);
data->name = path.stem().string();
result = data;
LoadAnimClipContainer(file, result, path);
}
file.close();
@ -47,15 +41,84 @@ namespace SHADE
auto const extension = path.extension().string();
if (extension == ANIM_CLIP_EXTENSION)
if (extension == ANIM_CONTAINER_EXTENSION)
{
auto animClip = dynamic_cast<SHAnimClipAsset const*>(data);
file.write(
reinterpret_cast<char const*>(&animClip->animRawDataAssetId),
sizeof(uint32_t) * 3
);
WriteAnimClipContainer(file, data, path);
}
file.close();
}
void SHBinaryLoader::WriteAnimClipContainer(std::ofstream& file, SHAssetData const* data, AssetPath path)
{
auto const& anim = *dynamic_cast<SHAnimClipContainerAsset const*>(data);
file.write(
reinterpret_cast<char const*>(&anim.animRawDataAssetId),
sizeof(uint32_t)
);
uint32_t const size {static_cast<uint32_t>(anim.clips.size())};
file.write(
reinterpret_cast<char const*>(&size),
sizeof(uint32_t)
);
for (auto const& clip : anim.clips)
{
uint32_t charCount {static_cast<uint32_t>(clip.name.size())};
file.write(
reinterpret_cast<char const*>(&charCount),
sizeof(uint32_t)
);
file.write(
clip.name.data(),
charCount
);
file.write(
reinterpret_cast<char const*>(&clip.firstIndex),
sizeof(uint32_t) * 2
);
}
}
void SHBinaryLoader::LoadAnimClipContainer(std::ifstream& file, SHAssetData* result, AssetPath path)
{
auto const data = new SHAnimClipContainerAsset();
file.read(
reinterpret_cast<char*>(&data->animRawDataAssetId),
sizeof(uint32_t)
);
uint32_t size;
file.read(
reinterpret_cast<char*>(&size),
sizeof(uint32_t)
);
for (auto i{0}; i < size; ++i)
{
auto& clip {data->clips.emplace_back()};
uint32_t charCount;
file.read(
reinterpret_cast<char*>(&charCount),
sizeof(uint32_t)
);
clip.name.resize(charCount);
file.read(
clip.name.data(),
charCount
);
file.read(
reinterpret_cast<char*>(&clip.firstIndex),
sizeof(uint32_t) * 2
);
}
}
}

View File

@ -8,5 +8,10 @@ namespace SHADE
{
SHAssetData* Load(AssetPath path) override;
void Write(SHAssetData const* data, AssetPath path) override;
private:
//Individual functions to write files
void WriteAnimClipContainer(std::ofstream& file,SHAssetData const* data, AssetPath path);
void LoadAnimClipContainer(std::ifstream& file,SHAssetData* result, AssetPath path);
};
}