Implemented Animation Clip asset and animation controller #410
|
@ -11,18 +11,18 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
*//*************************************************************************************/
|
*//*************************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
#include "SHAssetData.h"
|
#include "SHAssetData.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
struct SH_API SHAnimClipAsset : SHAssetData
|
struct SH_API SHAnimClipAsset : SHAssetData
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
AssetID animRawDataAssetId;
|
AssetID animRawDataAssetId;
|
||||||
int firstIndex;
|
uint32_t firstIndex;
|
||||||
int lastIndex;
|
uint32_t lastIndex;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHBinaryLoader.h"
|
||||||
|
|
||||||
|
#include "Assets/Asset Types/SHAnimClipAsset.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
SHAssetData* SHBinaryLoader::Load(AssetPath path)
|
||||||
|
{
|
||||||
|
std::ifstream file{ path, std::ios::in | std::ios::binary };
|
||||||
|
if (!file.is_open())
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("[Binary Loader] Unable to open file for reading: {}", path.string());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const extension = path.extension().string();
|
||||||
|
SHAssetData* result{nullptr};
|
||||||
|
|
||||||
|
if (extension == ANIM_CLIP_EXTENSION)
|
||||||
|
{
|
||||||
|
const auto data = new SHAnimClipAsset();
|
||||||
|
file.read(
|
||||||
|
reinterpret_cast<char*>(&data->animRawDataAssetId),
|
||||||
|
sizeof(uint32_t) * 3
|
||||||
|
);
|
||||||
|
data->name = path.stem().string();
|
||||||
|
result = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBinaryLoader::Write(SHAssetData const* data, AssetPath path)
|
||||||
|
{
|
||||||
|
std::ofstream file{ path, std::ios::out | std::ios::binary };
|
||||||
|
|
||||||
|
if (!file.is_open())
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("[Binary Loader] Unable to open file for writing: {}", path.string());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const extension = path.extension().string();
|
||||||
|
|
||||||
|
if (extension == ANIM_CLIP_EXTENSION)
|
||||||
|
{
|
||||||
|
auto animClip = dynamic_cast<SHAnimClipAsset const*>(data);
|
||||||
|
file.write(
|
||||||
|
reinterpret_cast<char const*>(&animClip->animRawDataAssetId),
|
||||||
|
sizeof(uint32_t) * 3
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "SHAssetLoader.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
struct SHBinaryLoader : SHAssetLoader
|
||||||
|
{
|
||||||
|
SHAssetData* Load(AssetPath path) override;
|
||||||
|
void Write(SHAssetData const* data, AssetPath path) override;
|
||||||
|
};
|
||||||
|
}
|
|
@ -26,32 +26,32 @@ namespace SHADE
|
||||||
|
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string());
|
SHLOG_ERROR("[Text Loader] Unable to open text file for reading: {}", path.string());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
||||||
stream << file.rdbuf();
|
stream << file.rdbuf();
|
||||||
|
|
||||||
std::string content = stream.str();
|
std::string content = stream.str();
|
||||||
|
|
||||||
|
auto const extension = path.extension().string();
|
||||||
SHAssetData* result;
|
SHAssetData* result;
|
||||||
|
|
||||||
if (path.extension().string() == SCENE_EXTENSION)
|
if (extension == SCENE_EXTENSION)
|
||||||
{
|
{
|
||||||
auto data = new SHSceneAsset();
|
auto data = new SHSceneAsset();
|
||||||
data->name = path.stem().string();
|
data->name = path.stem().string();
|
||||||
data->data = std::move(content);
|
data->data = std::move(content);
|
||||||
result = data;
|
result = data;
|
||||||
}
|
}
|
||||||
else if (path.extension().string() == PREFAB_EXTENSION)
|
else if (extension == PREFAB_EXTENSION)
|
||||||
{
|
{
|
||||||
auto data = new SHPrefabAsset();
|
auto data = new SHPrefabAsset();
|
||||||
data->name = path.stem().string();
|
data->name = path.stem().string();
|
||||||
data->data = std::move(content);
|
data->data = std::move(content);
|
||||||
result = data;
|
result = data;
|
||||||
}
|
}
|
||||||
else if (path.extension().string() == MATERIAL_EXTENSION)
|
else if (extension == MATERIAL_EXTENSION)
|
||||||
{
|
{
|
||||||
auto data = new SHMaterialAsset();
|
auto data = new SHMaterialAsset();
|
||||||
data->name = path.stem().string();
|
data->name = path.stem().string();
|
||||||
|
@ -70,21 +70,23 @@ namespace SHADE
|
||||||
|
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string());
|
SHLOG_ERROR("[Text Loader] Unable to open text file for writing: {}", path.string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.extension().string() == SCENE_EXTENSION)
|
auto const extension = path.extension().string();
|
||||||
|
|
||||||
|
if (extension == SCENE_EXTENSION)
|
||||||
{
|
{
|
||||||
auto scene = dynamic_cast<SHSceneAsset const*>(data);
|
auto scene = dynamic_cast<SHSceneAsset const*>(data);
|
||||||
file << scene->data;
|
file << scene->data;
|
||||||
}
|
}
|
||||||
else if (path.extension().string() == PREFAB_EXTENSION)
|
else if (extension == PREFAB_EXTENSION)
|
||||||
{
|
{
|
||||||
auto prefab = dynamic_cast<SHPrefabAsset const*>(data);
|
auto prefab = dynamic_cast<SHPrefabAsset const*>(data);
|
||||||
file << prefab->data;
|
file << prefab->data;
|
||||||
}
|
}
|
||||||
else if (path.extension().string() == MATERIAL_EXTENSION)
|
else if (extension == MATERIAL_EXTENSION)
|
||||||
{
|
{
|
||||||
auto material = dynamic_cast<SHMaterialAsset const*>(data);
|
auto material = dynamic_cast<SHMaterialAsset const*>(data);
|
||||||
file << material->data;
|
file << material->data;
|
||||||
|
|
|
@ -11,10 +11,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "SHAssetLoader.h"
|
#include "SHAssetLoader.h"
|
||||||
|
|
||||||
#include "Assets/Asset Types/SHPrefabAsset.h"
|
|
||||||
#include "Assets/Asset Types/SHSceneAsset.h"
|
|
||||||
#include "Assets/Asset Types/SHMaterialAsset.h"
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
struct SHTextBasedLoader : SHAssetLoader
|
struct SHTextBasedLoader : SHAssetLoader
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
* or disclosure of this file or its contents without the prior
|
* or disclosure of this file or its contents without the prior
|
||||||
* written consent of Digipen Institute of Technology is prohibited
|
* written consent of Digipen Institute of Technology is prohibited
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
// ReSharper disable All
|
||||||
#ifndef SH_ASSET_MACROS_H
|
#ifndef SH_ASSET_MACROS_H
|
||||||
#define SH_ASSET_MACROS_H
|
#define SH_ASSET_MACROS_H
|
||||||
|
|
||||||
|
@ -28,12 +29,12 @@ enum FMOD_SPEAKERMODE : int;
|
||||||
|
|
||||||
// Typedefs
|
// Typedefs
|
||||||
typedef uint32_t AssetID;
|
typedef uint32_t AssetID;
|
||||||
typedef std::string AssetName;
|
using AssetName = std::string;
|
||||||
typedef std::filesystem::path AssetPath;
|
typedef std::filesystem::path AssetPath;
|
||||||
typedef unsigned char* AssetData;
|
typedef unsigned char* AssetData;
|
||||||
typedef std::string AssetMetaVersion;
|
typedef std::string AssetMetaVersion;
|
||||||
typedef std::string AssetExtension;
|
typedef std::string AssetExtension;
|
||||||
typedef size_t AssetTypeMeta;
|
typedef size_t AssetTypeMeta;
|
||||||
|
|
||||||
typedef FMOD::Sound* SHSound;
|
typedef FMOD::Sound* SHSound;
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ enum class AssetType : AssetTypeMeta
|
||||||
MESH,
|
MESH,
|
||||||
SCRIPT,
|
SCRIPT,
|
||||||
FONT,
|
FONT,
|
||||||
|
ANIM_CLIP,
|
||||||
MAX_COUNT
|
MAX_COUNT
|
||||||
};
|
};
|
||||||
constexpr size_t TYPE_COUNT{ static_cast<size_t>(AssetType::MAX_COUNT) };
|
constexpr size_t TYPE_COUNT{ static_cast<size_t>(AssetType::MAX_COUNT) };
|
||||||
|
@ -77,6 +79,7 @@ constexpr std::string_view FONT_COMPILER_EXE{ "FontCompiler.exe" };
|
||||||
constexpr std::string_view SCENE_FOLDER{ "/Scenes/" };
|
constexpr std::string_view SCENE_FOLDER{ "/Scenes/" };
|
||||||
constexpr std::string_view PREFAB_FOLDER{ "/Prefabs/" };
|
constexpr std::string_view PREFAB_FOLDER{ "/Prefabs/" };
|
||||||
constexpr std::string_view MATERIAL_FOLDER{ "/Materials/" };
|
constexpr std::string_view MATERIAL_FOLDER{ "/Materials/" };
|
||||||
|
constexpr std::string_view ANIM_CLIP_FOLDER{ "/Animation Clips/" };
|
||||||
|
|
||||||
|
|
||||||
// ASSET EXTENSIONS
|
// ASSET EXTENSIONS
|
||||||
|
@ -92,6 +95,7 @@ constexpr std::string_view PREFAB_EXTENSION {".shprefab"};
|
||||||
constexpr std::string_view MATERIAL_EXTENSION {".shmat"};
|
constexpr std::string_view MATERIAL_EXTENSION {".shmat"};
|
||||||
constexpr std::string_view TEXTURE_EXTENSION {".shtex"};
|
constexpr std::string_view TEXTURE_EXTENSION {".shtex"};
|
||||||
constexpr std::string_view MODEL_EXTENSION{ ".shmodel" };
|
constexpr std::string_view MODEL_EXTENSION{ ".shmodel" };
|
||||||
|
constexpr std::string_view ANIM_CLIP_EXTENSION{ ".shanimclip" };
|
||||||
|
|
||||||
constexpr std::string_view EXTENSIONS[] = {
|
constexpr std::string_view EXTENSIONS[] = {
|
||||||
AUDIO_EXTENSION,
|
AUDIO_EXTENSION,
|
||||||
|
@ -106,6 +110,7 @@ constexpr std::string_view EXTENSIONS[] = {
|
||||||
SCRIPT_EXTENSION,
|
SCRIPT_EXTENSION,
|
||||||
FONT_EXTENSION,
|
FONT_EXTENSION,
|
||||||
AUDIO_WAV_EXTENSION,
|
AUDIO_WAV_EXTENSION,
|
||||||
|
ANIM_CLIP_EXTENSION
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr size_t EXTENSIONS_COUNT{ 11 };
|
constexpr size_t EXTENSIONS_COUNT{ 11 };
|
||||||
|
|
|
@ -21,8 +21,13 @@
|
||||||
#include "Libraries/Loaders/SHShaderSourceLoader.h"
|
#include "Libraries/Loaders/SHShaderSourceLoader.h"
|
||||||
#include "Libraries/Loaders/SHTextBasedLoader.h"
|
#include "Libraries/Loaders/SHTextBasedLoader.h"
|
||||||
#include "Libraries/Loaders/SHFontLoader.h"
|
#include "Libraries/Loaders/SHFontLoader.h"
|
||||||
|
#include "Libraries/Loaders/SHBinaryLoader.h"
|
||||||
|
|
||||||
|
#include "Asset Types/SHPrefabAsset.h"
|
||||||
|
#include "Asset Types/SHMaterialAsset.h"
|
||||||
|
#include "Asset Types/SHSceneAsset.h"
|
||||||
|
#include "Asset Types/SHAnimClipAsset.h"
|
||||||
|
|
||||||
//#include "Libraries/Compilers/SHMeshCompiler.h"
|
|
||||||
#include "Libraries/Compilers/SHTextureCompiler.h"
|
#include "Libraries/Compilers/SHTextureCompiler.h"
|
||||||
#include "Libraries/Compilers/SHShaderSourceCompiler.h"
|
#include "Libraries/Compilers/SHShaderSourceCompiler.h"
|
||||||
|
|
||||||
|
@ -233,6 +238,19 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case AssetType::ANIM_CLIP:
|
||||||
|
newPath += ANIM_CLIP_FOLDER;
|
||||||
|
newPath += name;
|
||||||
|
newPath += ANIM_CLIP_EXTENSION;
|
||||||
|
|
||||||
|
{
|
||||||
|
auto animClip = new SHAnimClipAsset();
|
||||||
|
animClip->name = name;
|
||||||
|
data = animClip;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SHLOG_ERROR("[Asset Manager] Asset type of {} not an internal asset type, cannot be created", name);
|
SHLOG_ERROR("[Asset Manager] Asset type of {} not an internal asset type, cannot be created", name);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -274,7 +292,8 @@ namespace SHADE
|
||||||
if (
|
if (
|
||||||
asset.type == AssetType::SCENE ||
|
asset.type == AssetType::SCENE ||
|
||||||
asset.type == AssetType::PREFAB ||
|
asset.type == AssetType::PREFAB ||
|
||||||
asset.type == AssetType::MATERIAL
|
asset.type == AssetType::MATERIAL ||
|
||||||
|
asset.type == AssetType::ANIM_CLIP
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (assetData.contains(id))
|
if (assetData.contains(id))
|
||||||
|
@ -528,6 +547,7 @@ namespace SHADE
|
||||||
loaders[static_cast<size_t>(AssetType::MESH)] = nullptr;
|
loaders[static_cast<size_t>(AssetType::MESH)] = nullptr;
|
||||||
loaders[static_cast<size_t>(AssetType::SCRIPT)] = nullptr;
|
loaders[static_cast<size_t>(AssetType::SCRIPT)] = nullptr;
|
||||||
loaders[static_cast<size_t>(AssetType::FONT)] = dynamic_cast<SHAssetLoader*>(new SHFontLoader());
|
loaders[static_cast<size_t>(AssetType::FONT)] = dynamic_cast<SHAssetLoader*>(new SHFontLoader());
|
||||||
|
loaders[static_cast<size_t>(AssetType::ANIM_CLIP)] = dynamic_cast<SHAssetLoader*>(new SHBinaryLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue