From 023465bfe6fd51000f5c560c391683d1079ea621 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 11 Jun 2024 15:19:32 +0200 Subject: [PATCH] add special case for += operator with empty mesh --- cpp/open3d/geometry/TriangleMesh.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpp/open3d/geometry/TriangleMesh.cpp b/cpp/open3d/geometry/TriangleMesh.cpp index b199edff4de..90c393b5ea3 100644 --- a/cpp/open3d/geometry/TriangleMesh.cpp +++ b/cpp/open3d/geometry/TriangleMesh.cpp @@ -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(); @@ -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 +