diff --git a/cpp/open3d/io/TriangleMeshIO.h b/cpp/open3d/io/TriangleMeshIO.h index 3ee4cb0f492..32ec2aa751a 100644 --- a/cpp/open3d/io/TriangleMeshIO.h +++ b/cpp/open3d/io/TriangleMeshIO.h @@ -31,6 +31,7 @@ struct ReadTriangleMeshOptions { /// `aiProcessPreset_TargetRealtime_Fast, /// aiProcess_RemoveRedundantMaterials, aiProcess_OptimizeMeshes, /// aiProcess_PreTransformVertices`. + /// https://github.com/assimp/assimp/blob/master/include/assimp/postprocess.h /// /// Note that identical vertices will always be joined regardless of whether /// post-processing is enabled or not, which changes the number of vertices diff --git a/cpp/open3d/io/file_format/FileASSIMP.cpp b/cpp/open3d/io/file_format/FileASSIMP.cpp index 92a2fda8077..15bc3ffd26a 100644 --- a/cpp/open3d/io/file_format/FileASSIMP.cpp +++ b/cpp/open3d/io/file_format/FileASSIMP.cpp @@ -36,13 +36,16 @@ FileGeometry ReadFileGeometryTypeFBX(const std::string& path) { return FileGeometry(CONTAINS_TRIANGLES | CONTAINS_POINTS); } +// Ref: +// https://github.com/assimp/assimp/blob/master/include/assimp/postprocess.h const unsigned int kPostProcessFlags_compulsory = - aiProcess_JoinIdenticalVertices; + aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | + aiProcess_PreTransformVertices; const unsigned int kPostProcessFlags_fast = - aiProcessPreset_TargetRealtime_Fast | - aiProcess_RemoveRedundantMaterials | aiProcess_OptimizeMeshes | - aiProcess_PreTransformVertices; + kPostProcessFlags_compulsory | aiProcess_GenNormals | + aiProcess_Triangulate | aiProcess_GenUVCoords | + aiProcess_RemoveRedundantMaterials | aiProcess_OptimizeMeshes; struct TextureImages { std::shared_ptr albedo; @@ -65,7 +68,7 @@ void LoadTextures(const std::string& filename, std::string base_path = utility::filesystem::GetFileParentDirectory(filename); - auto texture_loader = [&base_path, &scene, &mat]( + auto texture_loader = [&base_path, &scene, &mat, &filename]( aiTextureType type, std::shared_ptr& img) { if (mat->GetTextureCount(type) > 0) { @@ -94,7 +97,10 @@ void LoadTextures(const std::string& filename, } } else { utility::LogWarning( - "This format of image is not supported."); + "Unsupported texture format for texture {} for " + "file {}: Only jpg and " + "png textures are supported.", + path.C_Str(), filename); } } // Else, build the path to it. @@ -170,7 +176,8 @@ bool ReadTriangleMeshUsingASSIMP( const auto* scene = importer.ReadFile(filename.c_str(), post_process_flags); if (!scene) { - utility::LogWarning("Unable to load file {} with ASSIMP", filename); + utility::LogWarning("Unable to load file {} with ASSIMP: {}", filename, + importer.GetErrorString()); return false; } @@ -326,7 +333,8 @@ bool ReadModelUsingAssimp(const std::string& filename, const auto* scene = importer.ReadFile(filename.c_str(), kPostProcessFlags_fast); if (!scene) { - utility::LogWarning("Unable to load file {} with ASSIMP", filename); + utility::LogWarning("Unable to load file {} with ASSIMP: {}", filename, + importer.GetErrorString()); return false; } diff --git a/cpp/open3d/t/io/file_format/FileASSIMP.cpp b/cpp/open3d/t/io/file_format/FileASSIMP.cpp index 514d59fca1b..da23953fe79 100644 --- a/cpp/open3d/t/io/file_format/FileASSIMP.cpp +++ b/cpp/open3d/t/io/file_format/FileASSIMP.cpp @@ -35,14 +35,16 @@ namespace t { namespace io { // Split all polygons with more than 3 edges into triangles. +// Ref: +// https://github.com/assimp/assimp/blob/master/include/assimp/postprocess.h const unsigned int kPostProcessFlags_compulsory = aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | - aiProcess_SortByPType; + aiProcess_SortByPType | aiProcess_PreTransformVertices; const unsigned int kPostProcessFlags_fast = - aiProcessPreset_TargetRealtime_Fast | - aiProcess_RemoveRedundantMaterials | aiProcess_OptimizeMeshes | - aiProcess_PreTransformVertices; + kPostProcessFlags_compulsory | aiProcess_GenNormals | + aiProcess_GenUVCoords | aiProcess_RemoveRedundantMaterials | + aiProcess_OptimizeMeshes; bool ReadTriangleMeshUsingASSIMP( const std::string& filename, @@ -58,7 +60,8 @@ bool ReadTriangleMeshUsingASSIMP( const auto* scene = importer.ReadFile(filename.c_str(), post_process_flags); if (!scene) { - utility::LogWarning("Unable to load file {} with ASSIMP", filename); + utility::LogWarning("Unable to load file {} with ASSIMP: {}", filename, + importer.GetErrorString()); return false; } @@ -219,7 +222,7 @@ bool WriteTriangleMeshUsingASSIMP(const std::string& filename, // Sanity checks... if (write_ascii) { utility::LogWarning( - "TriangleMesh can't be saved in ASCII fromat as .glb"); + "TriangleMesh can't be saved in ASCII format as .glb"); return false; } if (compressed) { @@ -470,7 +473,9 @@ bool WriteTriangleMeshUsingASSIMP(const std::string& filename, // Export if (exporter.Export(ai_scene.get(), "glb2", filename.c_str()) == AI_FAILURE) { - utility::LogWarning("Got error: {}", exporter.GetErrorString()); + utility::LogWarning( + "Got error: ({}) while writing TriangleMesh to file {}.", + exporter.GetErrorString(), filename); return false; }