From a39230ce42033c83d202b71b1808fd489c558d06 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Sat, 24 Sep 2022 16:07:51 +0800 Subject: [PATCH] More setting up for testing of gltf loading --- .../src/Assets/Libraries/SHMeshLoader.cpp | 9 +++--- SHADE_Engine/src/Assets/SHAssetManager.cpp | 28 +++++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp index c48cc2a5..6f50d4dc 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp @@ -25,10 +25,11 @@ namespace SHADE (void)scene; SHMeshAsset result - { - .compiled = false, - .changed = false - }; + { + .compiled { false}, + .changed { false }, + .meshName { mesh.mName.C_Str() } + }; for (size_t i{0}; i < mesh.mNumVertices; ++i) { diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 239a2e72..b5d701db 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -31,15 +31,19 @@ namespace SHADE /**************************************************************************** * \brief Static function to generate asset ID. ****************************************************************************/ - AssetID SHAssetManager::GenerateAssetID() noexcept + AssetID SHAssetManager::GenerateAssetID(AssetType type) noexcept { std::default_random_engine randEngine{ static_cast(std::chrono::system_clock::now().time_since_epoch().count()) }; std::mt19937 idGen{ randEngine() }; - AssetID result{ idGen() }; + AssetID result{ static_cast(type) << 24}; + AssetID unique{ idGen() & ((1 << 24) - 1) }; + + result |= unique; + while (result == 0) { - result = idGen(); + result = GenerateAssetID(type); } return result; } @@ -95,7 +99,7 @@ namespace SHADE ****************************************************************************/ AssetID SHAssetManager::CreateNewAsset(AssetType type, AssetName name) noexcept { - AssetID id{ GenerateAssetID() }; + AssetID id{ GenerateAssetID(type) }; SHAsset meta; meta.id = id; meta.type = type; @@ -204,6 +208,8 @@ namespace SHADE .location {0} } ); + + SHLOG_INFO("Loaded meshes\n"); } /**************************************************************************** @@ -228,8 +234,8 @@ namespace SHADE SHAsset SHAssetManager::RegisterAssetNew(AssetPath const& asset) noexcept { SHAsset meta; - meta.id = GenerateAssetID(); meta.type = SHAssetMetaHandler::GetTypeFromExtension(asset.extension().string()); + meta.id = GenerateAssetID(meta.type); assetCollection.push_back(meta); @@ -260,7 +266,17 @@ namespace SHADE SHDDSLoader::LoadImageAsset(imagePaths, images); //TODO Recognise new meshes as asset as well and write mesh into binary - //TODO + //TODO + + for (auto const& mesh : meshes) + { + meshCollection.emplace(GenerateAssetID(AssetType::MESH), mesh); + } + + for (auto const& image : images) + { + ddsCollection.emplace(GenerateAssetID(AssetType::DDS), image); + } } /****************************************************************************