Skip to content

Commit

Permalink
add special case for += operator with empty mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminum committed Jun 11, 2024
1 parent f4a02dd commit 023465b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cpp/open3d/geometry/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ TriangleMesh &TriangleMesh::Rotate(const Eigen::Matrix3d &R,

TriangleMesh &TriangleMesh::operator+=(const TriangleMesh &mesh) {
if (mesh.IsEmpty()) return (*this);
bool is_empty = IsEmpty();
size_t old_vert_num = vertices_.size();
MeshBase::operator+=(mesh);
size_t old_tri_num = triangles_.size();
Expand All @@ -74,21 +75,22 @@ TriangleMesh &TriangleMesh::operator+=(const TriangleMesh &mesh) {
if (HasAdjacencyList()) {
ComputeAdjacencyList();
}
if (mesh.HasTriangleUvs()) {
if (mesh.HasTriangleUvs() && (HasTriangleUvs() || is_empty)) {
size_t old_tri_uv_num = triangle_uvs_.size();
triangle_uvs_.resize(old_tri_uv_num + mesh.triangle_uvs_.size());
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()) {
if (mesh.HasTextures() && (HasTextures() || is_empty)) {
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()) {
if (mesh.HasTriangleMaterialIds() &&
(HasTriangleMaterialIds() || is_empty)) {
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 +
Expand Down

0 comments on commit 023465b

Please sign in to comment.