Skip to content
Merged
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions cpp/open3d/t/io/file_format/FileASSIMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ bool WriteTriangleMeshUsingASSIMP(const std::string& filename,
".glb");
return false;
}
// Check for unsupported features
if (mesh.HasTriangleNormals()) {
utility::LogWarning(
"Exporting triangle normals is not supported. Please convert "
"to vertex normals or export to a format that supports it.");
}
if (mesh.HasTriangleColors()) {
utility::LogWarning(
"Exporting triangle colors is not supported. Please convert to "
"vertex colors or export to a format that supporst it.");
}

Assimp::Exporter exporter;
auto ai_scene = std::unique_ptr<aiScene>(new aiScene);
Expand All @@ -243,8 +254,9 @@ bool WriteTriangleMeshUsingASSIMP(const std::string& filename,
ai_mesh->mName.Set("Object1");
ai_mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
// Guaranteed to have both vertex positions and triangle indices
auto vertices = mesh.GetVertexPositions();
auto indices = mesh.GetTriangleIndices().To(core::Dtype::UInt32);
auto vertices = mesh.GetVertexPositions().Contiguous();
auto indices =
mesh.GetTriangleIndices().Contiguous().To(core::Dtype::UInt32);
ai_mesh->mNumVertices = vertices.GetShape(0);
ai_mesh->mVertices = new aiVector3D[ai_mesh->mNumVertices];
memcpy(&ai_mesh->mVertices->x, vertices.GetDataPtr(),
Expand All @@ -266,15 +278,15 @@ bool WriteTriangleMeshUsingASSIMP(const std::string& filename,
}

if (write_vertex_normals && mesh.HasVertexNormals()) {
auto normals = mesh.GetVertexNormals();
auto normals = mesh.GetVertexNormals().Contiguous();
auto m_normals = normals.GetShape(0);
ai_mesh->mNormals = new aiVector3D[m_normals];
memcpy(&ai_mesh->mNormals->x, normals.GetDataPtr(),
sizeof(float) * m_normals * 3);
}

if (write_vertex_colors && mesh.HasVertexColors()) {
auto colors = mesh.GetVertexColors();
auto colors = mesh.GetVertexColors().Contiguous();
auto m_colors = colors.GetShape(0);
ai_mesh->mColors[0] = new aiColor4D[m_colors];
if (colors.GetShape(1) == 4) {
Expand All @@ -292,7 +304,7 @@ bool WriteTriangleMeshUsingASSIMP(const std::string& filename,
}

if (write_triangle_uvs && mesh.HasTriangleAttr("texture_uvs")) {
auto triangle_uvs = mesh.GetTriangleAttr("texture_uvs");
auto triangle_uvs = mesh.GetTriangleAttr("texture_uvs").Contiguous();
auto vertex_uvs = core::Tensor::Empty({ai_mesh->mNumVertices, 2},
core::Dtype::Float32);
auto n_uvs = ai_mesh->mNumVertices;
Expand Down