Skip to content

Commit

Permalink
Make sure Tensors are contiguous before memcpy from them
Browse files Browse the repository at this point in the history
  • Loading branch information
errissa committed Oct 18, 2023
1 parent 2aea50b commit f9937f8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cpp/open3d/t/io/file_format/FileASSIMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,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 @@ -277,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 @@ -303,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

0 comments on commit f9937f8

Please sign in to comment.