Skip to content

Commit

Permalink
Save per-vertex color
Browse files Browse the repository at this point in the history
  • Loading branch information
errissa committed Oct 2, 2023
1 parent 9cb2935 commit 351482f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cpp/open3d/t/io/file_format/FileASSIMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ bool WriteTriangleMeshUsingASSIMP(
memcpy(&ai_mesh->mNormals->x, normals.GetDataPtr(), sizeof(float)*m_normals*3);
}

// Add colors if present...
if (mesh.HasVertexColors()) {
auto colors = mesh.GetVertexColors();
auto m_colors = colors.GetShape(0);
utility::LogWarning("Adding {} colors...", m_colors);
ai_mesh->mColors[0] = new aiColor4D[m_colors];
if (colors.GetShape(1) == 4) {
memcpy(&ai_mesh->mColors[0][0].r, colors.GetDataPtr(), sizeof(float)*m_colors*3);
} else { // must be 3 components
auto color_ptr = reinterpret_cast<float*>(colors.GetDataPtr());
for (unsigned int i = 0; i < m_colors; ++i) {
ai_mesh->mColors[0][i].r = *color_ptr++;
ai_mesh->mColors[0][i].g = *color_ptr++;
ai_mesh->mColors[0][i].b = *color_ptr++;
ai_mesh->mColors[0][i].a = 1.0f;
}
}
}

// Add UVs if present...
if (mesh.HasTriangleAttr("texture_uvs")) {
auto triangle_uvs = mesh.GetTriangleAttr("texture_uvs");
Expand Down

0 comments on commit 351482f

Please sign in to comment.