diff --git a/openVulkanoCpp/Scene/Export/MeshWriter.cpp b/openVulkanoCpp/Scene/Export/MeshWriter.cpp index 7b3d708..d7c0601 100644 --- a/openVulkanoCpp/Scene/Export/MeshWriter.cpp +++ b/openVulkanoCpp/Scene/Export/MeshWriter.cpp @@ -6,6 +6,7 @@ #include "MeshWriter.hpp" #include "Base/Utils.hpp" +#include "Extensions/FmtFormatter.hpp" #include "IO/MemMappedFile.hpp" #include "Scene/Geometry.hpp" #include "Scene/Vertex.hpp" @@ -107,7 +108,7 @@ namespace OpenVulkano::Scene std::ofstream file(filePath); if (!file.is_open()) [[unlikely]] - throw std::runtime_error("Failed to open file '" + filePath.string() + "' for writing!"); + throw std::runtime_error(fmt::format("Failed to open file '{}' for writing!", filePath)); WriteObjContents(geometry, "", file); file.close(); @@ -117,7 +118,7 @@ namespace OpenVulkano::Scene { std::ofstream file(filePath); if (!file.is_open()) [[unlikely]] - throw std::runtime_error("Failed to open file '" + filePath.string() + "' for writing!"); + throw std::runtime_error(fmt::format("Failed to open file '{}' for writing!", filePath)); WriteUsdContents(file, geometry); file.close(); } @@ -190,7 +191,7 @@ namespace OpenVulkano::Scene if (result != aiReturn_SUCCESS) { - throw std::runtime_error("Unable to write STL file to " + filePath.string() + ": " + exporter.GetErrorString()); + throw std::runtime_error(fmt::format("Unable to write STL file to {}: {}", filePath, exporter.GetErrorString())); } #else throw std::runtime_error("Unable to export to STL: Assimp is not available!"); @@ -226,7 +227,7 @@ namespace OpenVulkano::Scene if (result != aiReturn_SUCCESS) { - throw std::runtime_error("Unable to write a fbx file to " + fbxPath.string() + ": " + exporter.GetErrorString()); + throw std::runtime_error(fmt::format("Unable to write a fbx file to {}: {}", fbxPath, exporter.GetErrorString())); } #else throw std::runtime_error("Unable to convert the scene to FBX: Assimp is not available!"); diff --git a/openVulkanoCpp/Scene/MeshLoader.cpp b/openVulkanoCpp/Scene/MeshLoader.cpp index 6aaa218..ae234bb 100644 --- a/openVulkanoCpp/Scene/MeshLoader.cpp +++ b/openVulkanoCpp/Scene/MeshLoader.cpp @@ -7,6 +7,7 @@ #include "MeshLoader.hpp" #include "Scene/Geometry.hpp" #include "Base/Logger.hpp" +#include "Extensions/FmtFormatter.hpp" #if __has_include("assimp/Importer.hpp") #include #include @@ -26,14 +27,6 @@ #include "value-pprint.hh" #include "value-types.hh" -namespace -{ - static bool ends_with(std::string_view str, std::string_view suffix) - { - return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; - } -} - namespace OpenVulkano::Scene { void MeshLoader::ParseAssimpFile(Geometry *geometry, const std::filesystem::path& file) @@ -46,8 +39,8 @@ namespace OpenVulkano::Scene aiProcess_ConvertToLeftHanded | aiProcess_PreTransformVertices | aiProcess_OptimizeGraph; 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) throw std::runtime_error(fmt::format("Failed to load file \"{}\" Error: {}", file, importer.GetErrorString())); + if (!scene->HasMeshes()) throw std::runtime_error(fmt::format("File \"{}\" does not have any meshes", file)); 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]; @@ -99,7 +92,7 @@ namespace OpenVulkano::Scene auto result = tinyusdz::LoadUSDFromFile(file.string().c_str(), &stage, &warning, &err); if (!result) { - throw std::runtime_error("Failed to load USD file: " + file.string()); + throw std::runtime_error(fmt::format("Failed to load USD file: {}", file)); } for (auto &prim : stage.root_prims()) @@ -148,15 +141,15 @@ namespace OpenVulkano::Scene } } } - throw std::runtime_error("No mesh found inside a xform in USD file: " + file.string()); + throw std::runtime_error(fmt::format("No mesh found inside a xform in USD file: {}", file)); } Geometry* MeshLoader::LoadFromFile(const std::filesystem::path& file) { Geometry* geometry = new Geometry(); - std::string fileStr = file.string(); - if (ends_with(fileStr, ".usd") || ends_with(fileStr, ".usda") || ends_with(fileStr, ".usdc") || ends_with(fileStr, ".usdz")) + const std::filesystem::path ext = file.extension(); + if (ext == ".usd" || ext == ".usda" || ext == ".usdc" || ext == ".usdz") { ParseUSDFile(geometry, file); }