Merge pull request #207 from SHADE-DP/SP3-13-Assets-Manager

Fixed and Updated internal asset creation pipeline for editor (Textures)

Accounted for texture compilation within editor
Fixed bug with rebuilding of asset collection and asset directory
Added checks for already registered assets and sub assets
This commit is contained in:
XiaoQiDigipen 2022-11-15 01:50:13 +08:00 committed by GitHub
commit 638e95473c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 24 deletions

View File

@ -161,21 +161,39 @@ namespace SHADE
newPath += PREFAB_FOLDER; newPath += PREFAB_FOLDER;
newPath += name; newPath += name;
newPath += PREFAB_EXTENSION; newPath += PREFAB_EXTENSION;
data = new SHPrefabAsset(); {
auto prefab = new SHPrefabAsset();
prefab->name = name;
data = prefab;
}
break; break;
case AssetType::SCENE: case AssetType::SCENE:
newPath += SCENE_FOLDER; newPath += SCENE_FOLDER;
newPath += name; newPath += name;
newPath += SCENE_EXTENSION; newPath += SCENE_EXTENSION;
data = new SHSceneAsset();
{
auto scene = new SHSceneAsset();
scene->name = name;
data = scene;
}
break; break;
case AssetType::MATERIAL: case AssetType::MATERIAL:
newPath += MATERIAL_FOLDER; newPath += MATERIAL_FOLDER;
newPath += name; newPath += name;
newPath += MATERIAL_EXTENSION; newPath += MATERIAL_EXTENSION;
data = new SHMaterialAsset();
{
auto material = new SHMaterialAsset();
material->name = name;
data = material;
}
break; break;
default: default:
@ -192,7 +210,7 @@ namespace SHADE
false false
}; };
assetCollection.insert({ auto result = assetCollection.emplace(
id, id,
SHAsset( SHAsset(
name, name,
@ -201,10 +219,13 @@ namespace SHADE
newPath, newPath,
false false
) )
}); );
assetData.emplace(id, data); assetData.emplace(id, data);
SHAssetMetaHandler::WriteMetaData(asset);
SaveAsset(id);
return id; return id;
} }
@ -361,6 +382,21 @@ namespace SHADE
modelPath += MODEL_EXTENSION; modelPath += MODEL_EXTENSION;
newPath = modelPath; newPath = modelPath;
} }
else if (ext == DDS_EXTENSION.data())
{
auto pathGen = SHTextureCompiler::CompileTextureAsset(path);
if (!pathGen.has_value())
{
SHLOG_ERROR("Texture Compilation Failed for: {}", path.string());
return;
}
newPath = pathGen.value();
}
else
{
SHLOG_WARNING("File Type compilation not yet Implemented: {}", path.string());
return;
}
if (genMeta) if (genMeta)
{ {
@ -376,7 +412,7 @@ namespace SHADE
void SHAssetManager::RefreshDirectory() noexcept void SHAssetManager::RefreshDirectory() noexcept
{ {
SHFileSystem::DestroyDirectory(folderRoot); SHFileSystem::DestroyDirectory(folderRoot);
assetCollection.clear(); //assetCollection.clear();
BuildAssetCollection(); BuildAssetCollection();
} }
@ -507,7 +543,7 @@ namespace SHADE
{ {
SHAsset newAsset{ SHAsset newAsset{
path.stem().string(), path.stem().string(),
GenerateAssetID(AssetType::SHADER_BUILT_IN), GenerateAssetID(AssetType::TEXTURE),
AssetType::SHADER_BUILT_IN, AssetType::SHADER_BUILT_IN,
path, path,
false false
@ -614,6 +650,12 @@ namespace SHADE
for (auto i{ 0 }; i < asset.subAssets.size(); ++i) for (auto i{ 0 }; i < asset.subAssets.size(); ++i)
{ {
auto const id = asset.subAssets[i]->id; auto const id = asset.subAssets[i]->id;
if (assetCollection.contains(id))
{
continue;
}
assetCollection[id] = *asset.subAssets[i]; assetCollection[id] = *asset.subAssets[i];
delete asset.subAssets[i]; delete asset.subAssets[i];
asset.subAssets[i] = &assetCollection[id]; asset.subAssets[i] = &assetCollection[id];

View File

@ -138,6 +138,7 @@ namespace SHADE
metaFile.close(); metaFile.close();
meta.path = path.parent_path().string() + "/" + path.stem().string(); meta.path = path.parent_path().string() + "/" + path.stem().string();
meta.path.make_preferred();
return meta; return meta;
} }

View File

@ -151,8 +151,11 @@ namespace SHADE
bool found{ false }; bool found{ false };
for (auto const& asset : assets) for (auto const& asset : assets)
{
if (!assetCollection.contains(asset.id))
{ {
assetCollection.emplace(asset.id, asset); assetCollection.emplace(asset.id, asset);
}
if (file.name == asset.name) if (file.name == asset.name)
{ {
AssetPath path{ file.path }; AssetPath path{ file.path };
@ -170,22 +173,6 @@ namespace SHADE
toGenerate.push_back(&file); toGenerate.push_back(&file);
} }
} }
//for (auto const& asset : assets)
//{
// assetCollection.emplace(asset.id, asset);
// for(auto& file : folder->files)
// {
// if (file.name == asset.name)
// {
// AssetPath path{ file.path };
// if (SHAssetMetaHandler::GetTypeFromExtension(path.extension().string()) == asset.type)
// {
// file.assetMeta = &assetCollection[asset.id];
// break;
// }
// }
// }
//}
for (auto i {0}; i < folder->files.size(); ++i) for (auto i {0}; i < folder->files.size(); ++i)
{ {