diff --git a/CMakeLists.txt b/CMakeLists.txt index d2f6800d..846e5df1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ if (WIN32) list(APPEND CMAKE_PREFIX_PATH $ENV{SYSROOT}/cmake $ENV{SYSROOT}/lib/cmake - $ENV{SYSROOT}/lib/cmake/assimp $ENV{SYSROOT}/lib/cmake/assimp-5.0 $ENV{SYSROOT}/lib/cmake/Catch2 $ENV{SYSROOT}/lib/cmake/meshoptimizer diff --git a/Examples/ExampleEnv02/Sponza.cpp b/Examples/ExampleEnv02/Sponza.cpp index 5dfed298..2d70e5e7 100644 --- a/Examples/ExampleEnv02/Sponza.cpp +++ b/Examples/ExampleEnv02/Sponza.cpp @@ -56,8 +56,8 @@ class Sponza : public stratus::Application { // Disable culling for this model since there are some weird parts that seem to be reversed //stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/glTF-Sample-Models/2.0/Sponza/glTF/Sponza.gltf", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_CCW); - stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/Sponza2022/scene.gltf", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_CCW); - stratus::Async e2 = stratus::ResourceManager::Instance()->LoadModel("../Resources/local/Sponza2022/NewSponza_Curtains_glTF.gltf", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_CCW); + stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/Sponza2022/scene.gltf", stratus::ColorSpace::SRGB, true, stratus::RenderFaceCulling::CULLING_CCW); + stratus::Async e2 = stratus::ResourceManager::Instance()->LoadModel("../Resources/local/Sponza2022/NewSponza_Curtains_glTF.gltf", stratus::ColorSpace::SRGB, true, stratus::RenderFaceCulling::CULLING_CCW); requested.push_back(e); requested.push_back(e2); diff --git a/Examples/ExampleEnv03/Interrogation.cpp b/Examples/ExampleEnv03/Interrogation.cpp index 18893a63..a8c464df 100644 --- a/Examples/ExampleEnv03/Interrogation.cpp +++ b/Examples/ExampleEnv03/Interrogation.cpp @@ -60,7 +60,7 @@ class Interrogation : public stratus::Application { //Input()->AddInputHandler(controller); // Disable culling for this model since there are some weird parts that seem to be reversed - stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/local/InterrogationRoom/scene.gltf", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_NONE); + stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/local/InterrogationRoom/scene.gltf", stratus::ColorSpace::SRGB, false, stratus::RenderFaceCulling::CULLING_NONE); e.AddCallback([this](stratus::Async e) { interrogationRoom = e.GetPtr(); auto transform = stratus::GetComponent(interrogationRoom); diff --git a/Examples/ExampleEnv04/SanMiguel.cpp b/Examples/ExampleEnv04/SanMiguel.cpp index 52d953ee..e866af3f 100644 --- a/Examples/ExampleEnv04/SanMiguel.cpp +++ b/Examples/ExampleEnv04/SanMiguel.cpp @@ -63,7 +63,7 @@ class SanMiguel : public stratus::Application { //Input()->AddInputHandler(controller); // Disable culling for this model since there are some weird parts that seem to be reversed - stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/San_Miguel/san-miguel-low-poly.obj", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_CCW); + stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/San_Miguel/san-miguel-low-poly.obj", stratus::ColorSpace::SRGB, true, stratus::RenderFaceCulling::CULLING_CCW); e.AddCallback([this](stratus::Async e) { sanMiguel = e.GetPtr(); auto transform = stratus::GetComponent(sanMiguel); diff --git a/Examples/ExampleEnv05/Bistro.cpp b/Examples/ExampleEnv05/Bistro.cpp index b1776fdf..2839621f 100644 --- a/Examples/ExampleEnv05/Bistro.cpp +++ b/Examples/ExampleEnv05/Bistro.cpp @@ -416,7 +416,7 @@ class Bistro : public stratus::Application { // Disable culling for this model since there are some weird parts that seem to be reversed //stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/Bistro_v5_2/BistroExterior.fbx", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_CCW); - stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/BistroGltf/Bistro.gltf", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_CCW); + stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/BistroGltf/Bistro.gltf", stratus::ColorSpace::SRGB, true, stratus::RenderFaceCulling::CULLING_CCW); e.AddCallback([this](stratus::Async e) { bistro = e.GetPtr(); auto transform = stratus::GetComponent(bistro); diff --git a/Examples/ExampleEnv06/Bathroom.cpp b/Examples/ExampleEnv06/Bathroom.cpp index d99b964a..974b58b5 100644 --- a/Examples/ExampleEnv06/Bathroom.cpp +++ b/Examples/ExampleEnv06/Bathroom.cpp @@ -68,7 +68,7 @@ class Bathroom : public stratus::Application { //Input()->AddInputHandler(controller); // Disable culling for this model since there are some weird parts that seem to be reversed - stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/Bathroom/scene.gltf", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_NONE); + stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/Bathroom/scene.gltf", stratus::ColorSpace::SRGB, true, stratus::RenderFaceCulling::CULLING_NONE); e.AddCallback([this](stratus::Async e) { bathroom = e.GetPtr(); auto transform = stratus::GetComponent(bathroom); diff --git a/Examples/ExampleEnv07/Warehouse.cpp b/Examples/ExampleEnv07/Warehouse.cpp index c18469a6..6c1f42b0 100644 --- a/Examples/ExampleEnv07/Warehouse.cpp +++ b/Examples/ExampleEnv07/Warehouse.cpp @@ -68,7 +68,7 @@ class Warehouse : public stratus::Application { //Input()->AddInputHandler(controller); // Disable culling for this model since there are some weird parts that seem to be reversed - stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/Warehouse/scene.gltf", stratus::ColorSpace::SRGB, stratus::RenderFaceCulling::CULLING_NONE); + stratus::Async e = stratus::ResourceManager::Instance()->LoadModel("../Resources/Warehouse/scene.gltf", stratus::ColorSpace::SRGB, true, stratus::RenderFaceCulling::CULLING_NONE); e.AddCallback([this](stratus::Async e) { warehouse = e.GetPtr(); auto transform = stratus::GetComponent(warehouse); diff --git a/Source/Engine/StratusResourceManager.cpp b/Source/Engine/StratusResourceManager.cpp index 4df56cbe..4fb9f67e 100644 --- a/Source/Engine/StratusResourceManager.cpp +++ b/Source/Engine/StratusResourceManager.cpp @@ -137,7 +137,7 @@ namespace stratus { } } - Async ResourceManager::LoadModel(const std::string& name, const ColorSpace& cspace, RenderFaceCulling defaultCullMode) { + Async ResourceManager::LoadModel(const std::string& name, const ColorSpace& cspace, const bool optimizeGraph, RenderFaceCulling defaultCullMode) { { auto sl = _LockRead(); if (_loadedModels.find(name) != _loadedModels.end()) { @@ -148,8 +148,8 @@ namespace stratus { auto ul = _LockWrite(); TaskSystem * tasks = TaskSystem::Instance(); - Async e = tasks->ScheduleTask([this, name, defaultCullMode, cspace]() { - return _LoadModel(name, cspace, defaultCullMode); + Async e = tasks->ScheduleTask([this, name, defaultCullMode, optimizeGraph, cspace]() { + return _LoadModel(name, cspace, optimizeGraph, defaultCullMode); }); _loadedModels.insert(std::make_pair(name, e)); @@ -440,33 +440,37 @@ namespace stratus { } } - EntityPtr ResourceManager::_LoadModel(const std::string& name, const ColorSpace& cspace, RenderFaceCulling defaultCullMode) { + EntityPtr ResourceManager::_LoadModel(const std::string& name, const ColorSpace& cspace, const bool optimizeGraph, RenderFaceCulling defaultCullMode) { STRATUS_LOG << "Attempting to load model: " << name << std::endl; Assimp::Importer importer; //importer.SetPropertyInteger(AI_CONFIG_PP_SLM_VERTEX_LIMIT, 16000); importer.SetPropertyInteger(AI_CONFIG_PP_SLM_TRIANGLE_LIMIT, 4000); + + unsigned int pflags = aiProcess_Triangulate | + aiProcess_JoinIdenticalVertices | + aiProcess_SortByPType | + aiProcess_GenNormals | + //aiProcess_GenSmoothNormals | + aiProcess_FlipUVs | + aiProcess_GenUVCoords | + aiProcess_CalcTangentSpace | + aiProcess_SplitLargeMeshes | + aiProcess_ImproveCacheLocality | + aiProcess_OptimizeMeshes | + //aiProcess_OptimizeGraph | + //aiProcess_FixInfacingNormals | + aiProcess_FindDegenerates | + aiProcess_FindInvalidData | + aiProcess_FindInstances; + + if (optimizeGraph) { + pflags |= aiProcess_OptimizeGraph; + } + //const aiScene *scene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_GenNormals | aiProcess_GenUVCoords); //const aiScene *scene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_OptimizeMeshes); - const aiScene *scene = importer.ReadFile(name, aiProcess_Triangulate | - aiProcess_JoinIdenticalVertices | - aiProcess_SortByPType | - aiProcess_GenNormals | - //aiProcess_GenSmoothNormals | - aiProcess_FlipUVs | - aiProcess_GenUVCoords | - aiProcess_CalcTangentSpace | - aiProcess_SplitLargeMeshes | - aiProcess_ImproveCacheLocality | - aiProcess_OptimizeMeshes | - //aiProcess_OptimizeGraph | - //aiProcess_FixInfacingNormals | - aiProcess_FindDegenerates | - aiProcess_FindInvalidData | - aiProcess_FindInstances - //aiProcess_PreTransformVertices - // aiProcess_FlipWindingOrder - ); + const aiScene *scene = importer.ReadFile(name, pflags); auto material = MaterialManager::Instance()->CreateMaterial(name); diff --git a/Source/Engine/StratusResourceManager.h b/Source/Engine/StratusResourceManager.h index 30b58b7a..d0c4cc2f 100644 --- a/Source/Engine/StratusResourceManager.h +++ b/Source/Engine/StratusResourceManager.h @@ -39,7 +39,7 @@ namespace stratus { virtual ~ResourceManager(); - Async LoadModel(const std::string&, const ColorSpace&, RenderFaceCulling defaultCullMode = RenderFaceCulling::CULLING_CCW); + Async LoadModel(const std::string&, const ColorSpace&, const bool optimizeGraph, RenderFaceCulling defaultCullMode = RenderFaceCulling::CULLING_CCW); TextureHandle LoadTexture(const std::string&, const ColorSpace&); // prefix is used to select all faces with one string. It ends up expanding to: // prefix + "right." + fileExt @@ -68,7 +68,7 @@ namespace stratus { private: std::unique_lock _LockWrite() const { return std::unique_lock(_mutex); } std::shared_lock _LockRead() const { return std::shared_lock(_mutex); } - EntityPtr _LoadModel(const std::string&, const ColorSpace&, RenderFaceCulling); + EntityPtr _LoadModel(const std::string&, const ColorSpace&, const bool optimizeGraph, RenderFaceCulling); // Despite accepting multiple files, it assumes they all have the same format (e.g. for cube texture) TextureHandle _LoadTextureImpl(const std::vector&, const ColorSpace&,