diff --git a/Assets/Cube.003.shmesh b/Assets/Cube.003.shmesh new file mode 100644 index 00000000..54cfb867 Binary files /dev/null and b/Assets/Cube.003.shmesh differ diff --git a/Assets/Cube.012.shmesh b/Assets/Cube.012.shmesh new file mode 100644 index 00000000..bc26a4e8 Binary files /dev/null and b/Assets/Cube.012.shmesh differ diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 0412028e..0584d39b 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -81,7 +81,8 @@ namespace Sandbox SHADE::SHSystemManager::RegisterRoutine(); //TODO: REMOVE AFTER PRESENTATION - SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf"); + //SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf"); + SHADE::SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh"); //SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds"); SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds"); //TODO: REMOVE AFTER PRESENTATION diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index 7c7ad1e0..6daa3645 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -42,7 +42,7 @@ namespace Sandbox std::vector> handles; for (auto const& mesh : meshes) { - if (mesh.meshName == "Cube.012") + if (mesh.header.meshName == "Cube.012") { handles.push_back(graphicsSystem->AddMesh( mesh.header.vertexCount, diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp index 6d4b6fcb..12b2517e 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp @@ -18,7 +18,11 @@ void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept { - std::ofstream file{path, std::ios::out | std::ios::binary}; + std::string newPath{ path.string() }; + newPath = newPath.substr(0, newPath.find_last_of('/') + 1); + newPath += asset.header.meshName + MESH_EXTENSION; + + std::ofstream file{ newPath, std::ios::out | std::ios::binary | std::ios::trunc }; if (!file.is_open()) { SHLOG_ERROR("Unable to open file for writing mesh file: {}", path.string()); @@ -34,17 +38,6 @@ void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPat sizeof(uint32_t) ); - uint32_t charCount{static_cast(asset.header.meshName.size())}; - file.write( - reinterpret_cast(&charCount), - sizeof(uint32_t) - ); - - file.write( - asset.header.meshName.c_str(), - asset.header.meshName.size() - ); - auto const vertexVec3Byte {sizeof(SHVec3) * asset.header.vertexCount}; auto const vertexVec2Byte {sizeof(SHVec2) * asset.header.vertexCount}; @@ -70,7 +63,7 @@ void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPat file.write( reinterpret_cast(asset.indices.data()), - sizeof(uint32_t) + sizeof(uint32_t) * asset.header.indexCount ); file.close(); diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp index a1a8b29c..b77d429d 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp @@ -19,7 +19,7 @@ namespace SHADE { Assimp::Importer SHMeshLoader::aiImporter; - void SHMeshLoader::ProcessNode(aiNode const& node, aiScene const& scene, std::vector& meshes) + void SHMeshLoader::ProcessNode(aiNode const& node, aiScene const& scene, std::vector& meshes) noexcept { for (size_t i {0}; i < node.mNumMeshes; ++i) { @@ -33,7 +33,7 @@ namespace SHADE } } - SHMeshAsset SHMeshLoader::ProcessMesh(aiMesh const& mesh, aiScene const& scene) + SHMeshAsset SHMeshLoader::ProcessMesh(aiMesh const& mesh, aiScene const& scene) noexcept { (void)scene; @@ -43,8 +43,6 @@ namespace SHADE .changed { false } }; - result.header.meshName = mesh.mName.C_Str(); - for (size_t i{0}; i < mesh.mNumVertices; ++i) { // Vertex position @@ -95,6 +93,7 @@ namespace SHADE result.header.vertexCount = result.vertexPosition.size(); result.header.indexCount = result.indices.size(); + result.header.meshName = mesh.mName.C_Str(); return result; } @@ -143,16 +142,21 @@ namespace SHADE SHLOG_ERROR("Unable to open SHMesh File: {}", path.string()); } - uint32_t vertCount, indexCount, charCount; + std::string name{ path.filename().string() }; + name = name.substr(0, name.find_last_of('.')); + + file.seekg(0); + + uint32_t vertCount, indexCount; std::vector vertPos, vertTan, vertNorm; std::vector texCoord; std::vector indices; - std::string name; + file.read(reinterpret_cast(&vertCount), sizeof(uint32_t)); + file.read(reinterpret_cast(&indexCount), sizeof(uint32_t)); - file >> vertCount; - file >> indexCount; - file >> charCount; + auto const vertexVec3Byte{ sizeof(SHVec3) * vertCount }; + auto const vertexVec2Byte{ sizeof(SHVec2) * vertCount }; vertPos.resize(vertCount); vertTan.resize(vertCount); @@ -160,43 +164,43 @@ namespace SHADE texCoord.resize(vertCount); indices.resize(indexCount); - name.reserve(charCount); - for (auto i{0}; i < charCount; ++i) - { - file >> name[i]; - } + file.read(reinterpret_cast(vertPos.data()), vertexVec3Byte); + file.read(reinterpret_cast(vertTan.data()), vertexVec3Byte); + file.read(reinterpret_cast(vertNorm.data()), vertexVec3Byte); + file.read(reinterpret_cast(texCoord.data()), vertexVec2Byte); + file.read(reinterpret_cast(indices.data()), sizeof(uint32_t) * indexCount); - for (auto i{ 0 }; i < vertCount; ++i) - { - file >> vertPos[i].x; - file >> vertPos[i].y; - file >> vertPos[i].z; - } - - for (auto i{ 0 }; i < vertCount; ++i) - { - file >> vertTan[i].x; - file >> vertTan[i].y; - file >> vertTan[i].z; - } + //for (auto i{ 0 }; i < vertCount; ++i) + //{ + // file >> vertPos[i].x; + // file >> vertPos[i].y; + // file >> vertPos[i].z; + //} + // + //for (auto i{ 0 }; i < vertCount; ++i) + //{ + // file >> vertTan[i].x; + // file >> vertTan[i].y; + // file >> vertTan[i].z; + //} - for (auto i{ 0 }; i < vertCount; ++i) - { - file >> vertNorm[i].x; - file >> vertNorm[i].y; - file >> vertNorm[i].z; - } + //for (auto i{ 0 }; i < vertCount; ++i) + //{ + // file >> vertNorm[i].x; + // file >> vertNorm[i].y; + // file >> vertNorm[i].z; + //} - for (auto i{ 0 }; i < vertCount; ++i) - { - file >> texCoord[i].x; - file >> texCoord[i].y; - } + //for (auto i{ 0 }; i < vertCount; ++i) + //{ + // file >> texCoord[i].x; + // file >> texCoord[i].y; + //} - for (auto i{ 0 }; i < indexCount; ++i) - { - file >> indices[i]; - } + //for (auto i{ 0 }; i < indexCount; ++i) + //{ + // file >> indices[i]; + //} mesh.compiled = true; mesh.changed = false; @@ -214,7 +218,7 @@ namespace SHADE file.close(); } - void SHMeshLoader::LoadMesh(std::vector& meshes, AssetPath path) + void SHMeshLoader::LoadMesh(std::vector& meshes, AssetPath path) noexcept { if (path.extension().string() == GLTF_EXTENSION) { diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 6c617c04..dde3b0e2 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -17,6 +17,8 @@ #include "Libraries/SHMeshLoader.h" #include "Libraries/SHTextureLoader.h" +#include "Libraries/SHMeshCompiler.h" + namespace SHADE { FMOD::System* SHAssetManager::audioSystem; @@ -200,7 +202,8 @@ namespace SHADE AssetPath path{ p }; if (path.extension().string() == FBX_EXTENSION - || path.extension().string() == GLTF_EXTENSION) + || path.extension().string() == GLTF_EXTENSION + || path.extension().string() == MESH_EXTENSION) { LoadGLTF( { @@ -301,6 +304,11 @@ namespace SHADE for (auto const& mesh : meshes) { meshCollection.emplace(GenerateAssetID(AssetType::MESH), mesh); + + if (!mesh.compiled) + { + SHMeshCompiler::CompileMeshBinary(mesh, asset.path); + } } }