Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mesh] TriangleMesh's "+=" operator appends UVs regardless of the presence of existing features #6728

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Fix regression in printing cuda tensor from PR #6444 🐛
- Add Python pathlib support for file IO (PR #6619)
- Fix log error message for `probability` argument validation in `PointCloud::SegmentPlane` (PR #6622)
- `TriangleMesh`'s `+=` operator appends UVs regardless of the presence of existing features (PR #6728)

## 0.13

Expand Down
16 changes: 6 additions & 10 deletions cpp/open3d/geometry/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ TriangleMesh &TriangleMesh::Rotate(const Eigen::Matrix3d &R,

TriangleMesh &TriangleMesh::operator+=(const TriangleMesh &mesh) {
if (mesh.IsEmpty()) return (*this);
bool add_textures = HasTriangleUvs() && HasTextures() &&
HasTriangleMaterialIds() && mesh.HasTriangleUvs() &&
mesh.HasTextures() && mesh.HasTriangleMaterialIds();
size_t old_vert_num = vertices_.size();
MeshBase::operator+=(mesh);
size_t old_tri_num = triangles_.size();
Expand All @@ -77,30 +74,29 @@ TriangleMesh &TriangleMesh::operator+=(const TriangleMesh &mesh) {
if (HasAdjacencyList()) {
ComputeAdjacencyList();
}
if (add_textures) {
if (mesh.HasTriangleUvs()) {
size_t old_tri_uv_num = triangle_uvs_.size();
triangle_uvs_.resize(old_tri_uv_num + mesh.triangle_uvs_.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this does not have any UV coordinates then triangle_uvs_.size() will be different from the total number of triangles in the resulting mesh. This would break with the assumption that triangle_uvs_.size() == 3*number of triangles

for (size_t i = 0; i < mesh.triangle_uvs_.size(); i++) {
triangle_uvs_[old_tri_uv_num + i] = mesh.triangle_uvs_[i];
}

}
if (mesh.HasTextures()) {
size_t old_tex_num = textures_.size();
textures_.resize(old_tex_num + mesh.textures_.size());
for (size_t i = 0; i < mesh.textures_.size(); i++) {
textures_[old_tex_num + i] = mesh.textures_[i];
}

}
if (mesh.HasTriangleMaterialIds()) {
size_t old_tex_num = textures_.size();
size_t old_mat_id_num = triangle_material_ids_.size();
triangle_material_ids_.resize(old_mat_id_num +
mesh.triangle_material_ids_.size());
for (size_t i = 0; i < mesh.triangle_material_ids_.size(); i++) {
triangle_material_ids_[old_mat_id_num + i] =
mesh.triangle_material_ids_[i] + (int)old_tex_num;
}
} else {
triangle_uvs_.clear();
textures_.clear();
triangle_material_ids_.clear();
}
return (*this);
}
Expand Down