SP3-103 SP3-104 Testing set up for loading gltf and dds

This commit is contained in:
Xiao Qi 2022-09-24 13:37:12 +08:00
parent a8a2e90c26
commit a907c7c575
2 changed files with 56 additions and 37 deletions

View File

@ -29,7 +29,7 @@ namespace SHADE
std::unordered_map<AssetID, SHDDSAsset> SHAssetManager::ddsCollection;
/****************************************************************************
* \brief Static function to generate resource ID.
* \brief Static function to generate asset ID.
****************************************************************************/
AssetID SHAssetManager::GenerateAssetID() noexcept
{
@ -45,7 +45,7 @@ namespace SHADE
}
/****************************************************************************
* \brief Deallocate all memory used by resource data
* \brief Deallocate all memory used by asset data
****************************************************************************/
void SHAssetManager::Unload() noexcept
{
@ -76,7 +76,7 @@ namespace SHADE
}
/****************************************************************************
* \brief Get record of all resources currently loaded with name and id.
* \brief Get record of all assets currently loaded with name and id.
*
* \return const& to unordered_map<AssetName, AssetID>
****************************************************************************/
@ -86,12 +86,12 @@ namespace SHADE
}
/****************************************************************************
* \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM
* \brief Create record for new asset. CAN ONLY CREATE FOR CUSTOM
* ASSETS CREATED BY THE ENGINE.
*
* \param type of resource
* \param name of resource
* \return resource id generated for new asset
* \param type of asset
* \param name of asset
* \return asset id generated for new asset
****************************************************************************/
AssetID SHAssetManager::CreateNewAsset(AssetType type, AssetName name) noexcept
{
@ -117,10 +117,10 @@ namespace SHADE
}
/****************************************************************************
* \brief Import new resource from outside editor window.
* \brief Import new asset from outside editor window.
*
* \param path - c style string to full path
* \return resource if generated for new
* \return asset if generated for new
****************************************************************************/
AssetID SHAssetManager::ImportNewAsset(char const* p) noexcept
{
@ -145,24 +145,24 @@ namespace SHADE
}
/****************************************************************************
* \brief Search through resources folder for new unregistered assets.
* \brief Search through assets folder for new unregistered assets.
* Takes in no params and returns nothing. Only updates internally.
****************************************************************************/
void SHAssetManager::RefreshAllAssets() noexcept
{
std::vector<AssetPath> metaFiles;
std::vector<AssetPath> resourceFiles;
std::vector<AssetPath> AssetFiles;
//SHFileSystem::LoadAllFiles(metaFiles, resourceFiles);
//std::vector<AssetPath> resourceFilesVerified;
std::vector<AssetPath> resourceFilesNew;
//SHFileSystem::LoadAllFiles(metaFiles, AssetFiles);
//std::vector<AssetPath> AssetFilesVerified;
std::vector<AssetPath> AssetFilesNew;
for (auto const& resource : resourceFiles)
for (auto const& asset : AssetFiles)
{
bool found = false;
for (auto it {metaFiles.begin()}; it != metaFiles.end(); ++it)
{
std::string fileExtCheck{ resource.filename().string() };
std::string fileExtCheck{ asset.filename().string() };
fileExtCheck += META_EXTENSION;
if (it->filename().string() == fileExtCheck)
{
@ -172,17 +172,17 @@ namespace SHADE
}
}
if (!found && IsRecognised(resource.extension().string().c_str()))
if (!found && IsRecognised(asset.extension().string().c_str()))
{
resourceFilesNew.push_back(resource);
AssetFilesNew.push_back(asset);
}
}
std::vector<SHAsset> newLoad;
newLoad.reserve(resourceFilesNew.size());
newLoad.reserve(AssetFilesNew.size());
//TODO: Handle if meta does not match all resources (if meta exist and asset doesnt, vice versa)
for (auto const& file : resourceFilesNew)
//TODO: Handle if meta does not match all assets (if meta exist and asset doesnt, vice versa)
for (auto const& file : AssetFilesNew)
{
newLoad.push_back(RegisterAssetNew(file));
}
@ -191,11 +191,26 @@ namespace SHADE
}
void SHAssetManager::LoadDataTemp(std::string p) noexcept
{
AssetPath path{ p };
LoadGLTF(
{
.name {path.filename().string()},
.id {0},
.type {AssetType::MESH},
.path {path},
.location {0}
}
);
}
/****************************************************************************
* \param Path for meta data file
* \param Path for resource file
* \param Path for asset file
* \brief Links meta data to resource in registries. Meta data should
* \brief Links meta data to asset in registries. Meta data should
* already exist
****************************************************************************/
void SHAssetManager::RegisterAsset(AssetPath const& metaPath, AssetPath const& path) noexcept
@ -206,15 +221,15 @@ namespace SHADE
}
/****************************************************************************
* \param Path for resource file
* \param Path for asset file
* \brief Creates new meta data for new resource.
* \brief Creates new meta data for new asset.
****************************************************************************/
SHAsset SHAssetManager::RegisterAssetNew(AssetPath const& resource) noexcept
SHAsset SHAssetManager::RegisterAssetNew(AssetPath const& asset) noexcept
{
SHAsset meta;
meta.id = GenerateAssetID();
meta.type = SHAssetMetaHandler::GetTypeFromExtension(resource.extension().string());
meta.type = SHAssetMetaHandler::GetTypeFromExtension(asset.extension().string());
assetCollection.push_back(meta);
@ -249,7 +264,7 @@ namespace SHADE
}
/****************************************************************************
* \brief Load all resources that are in the folder
* \brief Load all assets that are in the folder
****************************************************************************/
void SHAssetManager::Load() noexcept
{
@ -258,7 +273,7 @@ namespace SHADE
}
/****************************************************************************
* \brief Load resource data into memory
* \brief Load asset data into memory
****************************************************************************/
void SHAssetManager::LoadAllData() noexcept
{
@ -273,20 +288,21 @@ namespace SHADE
}
/****************************************************************************
* \brief Retrieve all resource files and meta files from filesystem
* \brief Retrieve all asset files and meta files from filesystem
****************************************************************************/
void SHAssetManager::RetrieveAssets() noexcept
{
std::vector<AssetPath> metaFiles;
std::vector<AssetPath> resourceFiles;
std::vector<AssetPath> AssetFiles;
//TODO: Write new function for file manager to loop through all files
//SHFileSystem::LoadAllFiles(metaFiles, resourceFiles);
SHFileSystem::StartupFillDirectories(ASSET_ROOT);
FolderPointer rootFolder = SHFileSystem::GetRoot();
for (auto const& meta : metaFiles)
{
for (std::vector<AssetPath>::const_iterator it{ resourceFiles.cbegin() };
it != resourceFiles.cend();
for (std::vector<AssetPath>::const_iterator it{ AssetFiles.cbegin() };
it != AssetFiles.cend();
++it)
{
// Asset exists for meta file
@ -295,14 +311,14 @@ namespace SHADE
if (meta.filename().string() == fileExtCheck)
{
RegisterAsset(meta, *it);
resourceFiles.erase(it);
AssetFiles.erase(it);
break;
}
}
}
//TODO: Handle if meta does not match all resources (if meta exist and asset doesnt, vice versa)
for (auto const& file : resourceFiles)
//TODO: Handle if meta does not match all assets (if meta exist and asset doesnt, vice versa)
for (auto const& file : AssetFiles)
{
if (IsRecognised(file.extension().string().c_str()))
{

View File

@ -76,6 +76,9 @@ namespace SHADE
static void RefreshAllAssets() noexcept;
// -------------------------------------------------------------------------/
//TODO: TEMPORARY FOR TESTING GLTF & DDS
static void LoadDataTemp(std::string path) noexcept;
private:
/****************************************************************************
* \brief Load resource data into memory