Changed std::string to std::fs::path for MeshWriter & MeshLoader
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user