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 3 commits into
base: main
Choose a base branch
from

Conversation

cdbharath
Copy link

@cdbharath cdbharath commented Mar 27, 2024

Allows appending of UV coordinates, textures and material IDs with += operator overload in TriangleMesh class irrespective of the presence of these attributes in the existing mesh (mesh on LHS to += operator)

Type

Motivation and Context

The += operator overload of TriangleMesh class does not append UV coordinates, textures and material IDs when the existing mesh (mesh on LHS to += operator) already contains any of these attributes. There is no reason to limit += for UVs to TriangleMesh with the attributes already assigned as it currently happens here.

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

The current change doesn't check if the presence of UV coordinates, textures and material IDs in the existing mesh and appends only based on their availability in the incoming mesh.

I am attaching a screenshot that shows the addition of UV coordinates based on += operator. The test code is as follows

    auto box = geometry::TriangleMesh::CreateBox(1.0, 1.0, 1.0, true, true);    
    auto sphere = geometry::TriangleMesh::CreateSphere(1.0, 6, true);   
    rendering::MaterialRecord material;
    material.albedo_img = texture_image;
    material.name = "material";
            
    auto scene = std::make_shared<geometry::TriangleMesh>();
        
    // Append new meshes using +=
    *scene += *box;
    *scene += *sphere;
            
    gui::Application::GetInstance().Initialize(argc, argv);
    auto vis1 = std::make_shared<visualizer::O3DVisualizer>("Textures", 1024, 768);
    vis1->AddGeometry("scene", scene, &material);
    vis1->ResetCameraToDefault();
    gui::Application::GetInstance().AddWindow(vis1);
    gui::Application::GetInstance().Run();

The following is the resulting mesh with its texture UVs.
Screenshot from 2024-03-27 15-41-48

Copy link

update-docs bot commented Mar 27, 2024

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@cdbharath cdbharath changed the title [Mesh] TriangleMesh's "+=" operator applies regardless of the presenc… [Mesh] TriangleMesh's "+=" operator applies regardless of the presence of existing features Mar 27, 2024
@cdbharath cdbharath changed the title [Mesh] TriangleMesh's "+=" operator applies regardless of the presence of existing features [Mesh] TriangleMesh's "+=" operator appends UVs regardless of the presence of existing features Mar 28, 2024
Copy link
Contributor

@benjaminum benjaminum left a comment

Choose a reason for hiding this comment

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

@cdbharath Thanks for your PR, please have a look at the comment

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants