Changed std::string to std::fs::path for MeshWriter & MeshLoader

This commit is contained in:
Vladyslav Baranovskyi
2025-02-11 20:29:04 +02:00
parent 08229c3be6
commit f5b3ac5190
4 changed files with 36 additions and 34 deletions

View File

@@ -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<aiScene> 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<aiScene> 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!");