diff --git a/openVulkanoCpp/Scene/Export/MeshWriter.cpp b/openVulkanoCpp/Scene/Export/MeshWriter.cpp index 7cab2ec..7b3d708 100644 --- a/openVulkanoCpp/Scene/Export/MeshWriter.cpp +++ b/openVulkanoCpp/Scene/Export/MeshWriter.cpp @@ -102,27 +102,27 @@ namespace namespace OpenVulkano::Scene { - void MeshWriter::WriteAsOBJ(Geometry* geometry, const std::string& filePath) + void MeshWriter::WriteAsOBJ(Geometry* geometry, const std::filesystem::path& filePath) { std::ofstream file(filePath); if (!file.is_open()) [[unlikely]] - throw std::runtime_error("Failed to open file '" + filePath + "' for writing!"); + throw std::runtime_error("Failed to open file '" + filePath.string() + "' for writing!"); WriteObjContents(geometry, "", file); file.close(); } - void MeshWriter::WriteAsUSD(Geometry* geometry, const std::string& filePath) + void MeshWriter::WriteAsUSD(Geometry* geometry, const std::filesystem::path& filePath) { std::ofstream file(filePath); if (!file.is_open()) [[unlikely]] - throw std::runtime_error("Failed to open file '" + filePath + "' for writing!"); + throw std::runtime_error("Failed to open file '" + filePath.string() + "' for writing!"); WriteUsdContents(file, geometry); file.close(); } - void MeshWriter::WriteObjAsZip(Geometry* geometry, const std::string& texturePath, const std::string& zipPath) + void MeshWriter::WriteObjAsZip(Geometry* geometry, const std::filesystem::path& texturePath, const std::filesystem::path& zipPath) { OpenVulkano::ArchiveWriter zipWriter(zipPath.c_str()); @@ -146,7 +146,7 @@ namespace OpenVulkano::Scene } } - void MeshWriter::WriteAsUSDZ(Geometry* geometry, const std::string& texturePath, const std::string& usdzPath) + void MeshWriter::WriteAsUSDZ(Geometry* geometry, const std::filesystem::path& texturePath, const std::filesystem::path& usdzPath) { OpenVulkano::ZipWriter zipWriter(usdzPath, true); @@ -166,7 +166,7 @@ namespace OpenVulkano::Scene } } - void MeshWriter::WriteAsSTL(Geometry* geometry, const std::string& filePath, bool binary) + void MeshWriter::WriteAsSTL(Geometry* geometry, const std::filesystem::path& filePath, bool binary) { #if __has_include("assimp/Exporter.hpp") std::unique_ptr scene(new aiScene()); @@ -178,7 +178,7 @@ namespace OpenVulkano::Scene Assimp::Exporter exporter; const char* formatId = binary ? "stlb" : "stl"; - aiReturn result = exporter.Export(scene.get(), formatId, filePath); + aiReturn result = exporter.Export(scene.get(), formatId, filePath.string().c_str()); scene->mRootNode = nullptr; scene->mMeshes = nullptr; @@ -190,14 +190,14 @@ namespace OpenVulkano::Scene if (result != aiReturn_SUCCESS) { - throw std::runtime_error("Unable to write STL file to " + filePath + ": " + exporter.GetErrorString()); + throw std::runtime_error("Unable to write STL file to " + filePath.string() + ": " + exporter.GetErrorString()); } #else throw std::runtime_error("Unable to export to STL: Assimp is not available!"); #endif } - void MeshWriter::WriteAsFBX(Geometry* geometry, const std::string& texturePath, const std::string& fbxPath) + void MeshWriter::WriteAsFBX(Geometry* geometry, const std::filesystem::path& texturePath, const std::filesystem::path& fbxPath) { #if __has_include("assimp/Exporter.hpp") std::unique_ptr scene(new aiScene()); @@ -209,12 +209,12 @@ namespace OpenVulkano::Scene if (!texturePath.empty()) { - aiString externalPath(texturePath); + aiString externalPath(texturePath.string().c_str()); scene->mMaterials[0]->AddProperty(&externalPath, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0)); } Assimp::Exporter exporter; - aiReturn result = exporter.Export(scene.get(), "fbx", fbxPath); + aiReturn result = exporter.Export(scene.get(), "fbx", fbxPath.string().c_str()); scene->mRootNode = nullptr; scene->mMeshes = nullptr; @@ -226,7 +226,7 @@ namespace OpenVulkano::Scene if (result != aiReturn_SUCCESS) { - throw std::runtime_error("Unable to write a fbx file to " + fbxPath + ": " + exporter.GetErrorString()); + throw std::runtime_error("Unable to write a fbx file to " + fbxPath.string() + ": " + exporter.GetErrorString()); } #else throw std::runtime_error("Unable to convert the scene to FBX: Assimp is not available!"); diff --git a/openVulkanoCpp/Scene/Export/MeshWriter.hpp b/openVulkanoCpp/Scene/Export/MeshWriter.hpp index 388ecb9..047d8da 100644 --- a/openVulkanoCpp/Scene/Export/MeshWriter.hpp +++ b/openVulkanoCpp/Scene/Export/MeshWriter.hpp @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace OpenVulkano::Scene { @@ -14,11 +14,11 @@ namespace OpenVulkano::Scene class MeshWriter { public: - [[deprecated]] static void WriteAsOBJ(Geometry* geometry, const std::string& filePath); - [[deprecated]] static void WriteAsUSD(Geometry* geometry, const std::string& filePath); - [[deprecated]] static void WriteObjAsZip(Geometry* geometry, const std::string& texturePath, const std::string& zipPath); - [[deprecated]] static void WriteAsUSDZ(Geometry* geometry, const std::string& texturePath, const std::string& usdzPath); - [[deprecated]] static void WriteAsFBX(Geometry* geometry, const std::string& texturePath, const std::string& fbxPath); - [[deprecated]] static void WriteAsSTL(Geometry* geometry, const std::string& filePath, bool binary); + static void WriteAsOBJ(Geometry* geometry, const std::filesystem::path& filePath); + static void WriteAsUSD(Geometry* geometry, const std::filesystem::path& filePath); + static void WriteObjAsZip(Geometry* geometry, const std::filesystem::path& texturePath, const std::filesystem::path& zipPath); + static void WriteAsUSDZ(Geometry* geometry, const std::filesystem::path& texturePath, const std::filesystem::path& usdzPath); + static void WriteAsFBX(Geometry* geometry, const std::filesystem::path& texturePath, const std::filesystem::path& fbxPath); + static void WriteAsSTL(Geometry* geometry, const std::filesystem::path& filePath, bool binary); }; } \ No newline at end of file diff --git a/openVulkanoCpp/Scene/MeshLoader.cpp b/openVulkanoCpp/Scene/MeshLoader.cpp index e86b62c..6aaa218 100644 --- a/openVulkanoCpp/Scene/MeshLoader.cpp +++ b/openVulkanoCpp/Scene/MeshLoader.cpp @@ -36,7 +36,7 @@ namespace namespace OpenVulkano::Scene { - void MeshLoader::ParseAssimpFile(Geometry *geometry, const std::string& file) + void MeshLoader::ParseAssimpFile(Geometry *geometry, const std::filesystem::path& file) { #ifdef ASSIMP_AVAILABLE Assimp::Importer importer; @@ -45,10 +45,10 @@ namespace OpenVulkano::Scene aiProcess_ImproveCacheLocality | aiProcess_RemoveRedundantMaterials | aiProcess_GenUVCoords | aiProcess_TransformUVCoords | aiProcess_ConvertToLeftHanded | aiProcess_PreTransformVertices | aiProcess_OptimizeGraph; - const aiScene* scene = importer.ReadFile(file, flags); - if (!scene) throw std::runtime_error("Failed to load file \"" + file + "\" Error: " + importer.GetErrorString()); - if (!scene->HasMeshes()) throw std::runtime_error("File \"" + file + "\" does not have any meshes"); - if (scene->mNumMeshes > 1) Logger::DATA->warn("File {0} contains more than one mesh. Only first one will be loaded", file); + const aiScene* scene = importer.ReadFile(file.string().c_str(), flags); + if (!scene) throw std::runtime_error("Failed to load file \"" + file.string() + "\" Error: " + importer.GetErrorString()); + if (!scene->HasMeshes()) throw std::runtime_error("File \"" + file.string() + "\" does not have any meshes"); + if (scene->mNumMeshes > 1) Logger::DATA->warn("File {0} contains more than one mesh. Only first one will be loaded", file.string()); aiMesh *mesh = scene->mMeshes[0]; geometry->aabb.Reset(); @@ -91,15 +91,15 @@ namespace OpenVulkano::Scene #endif } - void MeshLoader::ParseUSDFile(Geometry *geometry, const std::string& file) + void MeshLoader::ParseUSDFile(Geometry *geometry, const std::filesystem::path& file) { tinyusdz::Stage stage; std::string warning, err; - auto result = tinyusdz::LoadUSDFromFile(file, &stage, &warning, &err); + auto result = tinyusdz::LoadUSDFromFile(file.string().c_str(), &stage, &warning, &err); if (!result) { - throw std::runtime_error("Failed to load USD file: " + file); + throw std::runtime_error("Failed to load USD file: " + file.string()); } for (auto &prim : stage.root_prims()) @@ -148,14 +148,15 @@ namespace OpenVulkano::Scene } } } - throw std::runtime_error("No mesh found inside a xform in USD file: " + file); + throw std::runtime_error("No mesh found inside a xform in USD file: " + file.string()); } - Geometry* MeshLoader::LoadFromFile(const std::string& file) + Geometry* MeshLoader::LoadFromFile(const std::filesystem::path& file) { Geometry* geometry = new Geometry(); - if (ends_with(file, ".usd") || ends_with(file, ".usda") || ends_with(file, ".usdc") || ends_with(file, ".usdz")) + std::string fileStr = file.string(); + if (ends_with(fileStr, ".usd") || ends_with(fileStr, ".usda") || ends_with(fileStr, ".usdc") || ends_with(fileStr, ".usdz")) { ParseUSDFile(geometry, file); } diff --git a/openVulkanoCpp/Scene/MeshLoader.hpp b/openVulkanoCpp/Scene/MeshLoader.hpp index 767b0ff..86c45e6 100644 --- a/openVulkanoCpp/Scene/MeshLoader.hpp +++ b/openVulkanoCpp/Scene/MeshLoader.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include namespace OpenVulkano::Scene @@ -13,9 +14,9 @@ namespace OpenVulkano::Scene class Geometry; class MeshLoader { - [[deprecated]] static void ParseAssimpFile(Geometry *geometry, const std::string& file); - [[deprecated]] static void ParseUSDFile(Geometry *geometry, const std::string& file); + static void ParseAssimpFile(Geometry *geometry, const std::filesystem::path& file); + static void ParseUSDFile(Geometry *geometry, const std::filesystem::path& file); public: - [[deprecated]] static Geometry* LoadFromFile(const std::string& file); + static Geometry* LoadFromFile(const std::filesystem::path& file); }; } \ No newline at end of file