-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[Mesh] TriangleMesh's "+=" operator appends UVs regardless of the presence of existing features #6728
Changes from all commits
59f0572
d70fa31
f4a02dd
023465b
551a91d
babe594
468e9b6
222ffcb
59bd56a
8a49642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,9 +52,12 @@ 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(); | ||
bool is_empty = IsEmpty(); | ||
bool add_triangle_uvs = | ||
mesh.HasTriangleUvs() && (HasTriangleUvs() || is_empty); | ||
bool add_textures_and_material_ids = | ||
mesh.HasTextures() && mesh.HasTriangleMaterialIds() && | ||
((HasTextures() && HasTriangleMaterialIds()) || is_empty); | ||
size_t old_vert_num = vertices_.size(); | ||
MeshBase::operator+=(mesh); | ||
size_t old_tri_num = triangles_.size(); | ||
|
@@ -77,19 +80,21 @@ TriangleMesh &TriangleMesh::operator+=(const TriangleMesh &mesh) { | |
if (HasAdjacencyList()) { | ||
ComputeAdjacencyList(); | ||
} | ||
if (add_textures) { | ||
if (add_triangle_uvs) { | ||
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]; | ||
} | ||
|
||
} else { | ||
triangle_uvs_.clear(); | ||
} | ||
if (add_textures_and_material_ids) { | ||
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]; | ||
} | ||
|
||
size_t old_mat_id_num = triangle_material_ids_.size(); | ||
triangle_material_ids_.resize(old_mat_id_num + | ||
mesh.triangle_material_ids_.size()); | ||
|
@@ -98,7 +103,6 @@ TriangleMesh &TriangleMesh::operator+=(const TriangleMesh &mesh) { | |
mesh.triangle_material_ids_[i] + (int)old_tex_num; | ||
} | ||
} else { | ||
triangle_uvs_.clear(); | ||
textures_.clear(); | ||
triangle_material_ids_.clear(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to keep this portion - Also, textures and triangle_material_ids go together, so we should have a single @cdbharath this PR may break other mesh functions if there is a bug -- please do the following tests and make sure there are no errors. Check for the case where:
With these 3 meshes, perform this check:
|
||
|
There was a problem hiding this comment.
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 thentriangle_uvs_.size()
will be different from the total number of triangles in the resulting mesh. This would break with the assumption thattriangle_uvs_.size() == 3*number of triangles