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

For TriangleMesh triangle_material_ids_ do not relate to the materials_ #5924

Closed
3 tasks done
dbs4261 opened this issue Feb 17, 2023 · 2 comments · Fixed by #5938
Closed
3 tasks done

For TriangleMesh triangle_material_ids_ do not relate to the materials_ #5924

dbs4261 opened this issue Feb 17, 2023 · 2 comments · Fixed by #5938
Labels
bug Not a build issue, this is likely a bug.

Comments

@dbs4261
Copy link
Contributor

dbs4261 commented Feb 17, 2023

Checklist

Describe the issue

The triangle_material_ids_ vector contain indices for which texture should be applied. However because materials are stored in an unordered_map, the indices cannot be used to access the corresponding material. It would be better to store a vector<pair<string, Material>> that way it is indexable, but materials could still be accessed by name using find with a lambda comparing names.

Steps to reproduce the bug

`class TriangleMesh {
    ...
    std::unordered_map<std::string, Material> materials_;
    /// List of material ids.
    std::vector<int> triangle_material_ids_;
    /// Textures of the image.
    std::vector<Image> textures_;
}`
By examining the values with a debugger, the triangle_material_ids_ match up with the textures_ but there is no mechanism for accessing the material associated with it.

Error message

No response

Expected behavior

No response

Open3D, Python and System information

- Operating system: Ubuntu 22.04
- Python version: Python 3.11
- Open3D version: bbae9e31fefac1c2fe04759d30b81c30d927dbeb
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: build from source
- Compiler version (if built from source): gcc 11.3

Additional information

No response

@dbs4261 dbs4261 added the bug Not a build issue, this is likely a bug. label Feb 17, 2023
dbs4261 added a commit to dbs4261/Open3D that referenced this issue Feb 20, 2023
Changed TriangleMesh::materials_ to be a std::vector<std::pair<std::string, Material>> so that the order of materials when loading a mesh is respected.
Using the unordered map caused issues when a Default Material and a texture were loaded and the texture would end up as the second material in the iterator.
Now TriangleMesh::triangle_material_ids_ will indicate what material index should be used.
A warning is given when passing a TriangleMesh to the visualizer and more than one material index is found, and the minimum value found in TriangleMesh::triangle_material_ids_ is used.
If no triangle_material_ids_ exist then the first material in the order they are loaded will be used.
dbs4261 added a commit to dbs4261/Open3D that referenced this issue Feb 20, 2023
Changed TriangleMesh::materials_ to be a std::vector<std::pair<std::string, Material>> so that the order of materials when loading a mesh is respected.
Using the unordered map caused issues when a Default Material and a texture were loaded and the texture would end up as the second material in the iterator.
Now TriangleMesh::triangle_material_ids_ will indicate what material index should be used.
A warning is given when passing a TriangleMesh to the visualizer and more than one material index is found, and the minimum value found in TriangleMesh::triangle_material_ids_ is used.
If no triangle_material_ids_ exist then the first material in the order they are loaded will be used.
@dbs4261 dbs4261 mentioned this issue Feb 20, 2023
9 tasks
dbs4261 added a commit to dbs4261/Open3D that referenced this issue Feb 20, 2023
dbs4261 added a commit to dbs4261/Open3D that referenced this issue Apr 20, 2023
Changed TriangleMesh::materials_ to be a std::vector<std::pair<std::string, Material>> so that the order of materials when loading a mesh is respected.
Using the unordered map caused issues when a Default Material and a texture were loaded and the texture would end up as the second material in the iterator.
Now TriangleMesh::triangle_material_ids_ will indicate what material index should be used.
A warning is given when passing a TriangleMesh to the visualizer and more than one material index is found, and the minimum value found in TriangleMesh::triangle_material_ids_ is used.
If no triangle_material_ids_ exist then the first material in the order they are loaded will be used.
dbs4261 added a commit to dbs4261/Open3D that referenced this issue Apr 20, 2023
@johnthagen
Copy link
Contributor

For the Python 3.11 support part, track

errissa pushed a commit that referenced this issue Oct 14, 2023
* Fix for Issue #5924:
Changed TriangleMesh::materials_ to be a std::vector<std::pair<std::string, Material>> so that the order of materials when loading a mesh is respected.
Using the unordered map caused issues when a Default Material and a texture were loaded and the texture would end up as the second material in the iterator.
Now TriangleMesh::triangle_material_ids_ will indicate what material index should be used.
A warning is given when passing a TriangleMesh to the visualizer and more than one material index is found, and the minimum value found in TriangleMesh::triangle_material_ids_ is used.
If no triangle_material_ids_ exist then the first material in the order they are loaded will be used.

* Updated CHANGELOG.md with info about fixing Issue #5924

* Updates to work with changes to the translation of tensor mesh materials

---------
@errissa
Copy link
Collaborator

errissa commented Oct 14, 2023

@dbs4261 Thank for both reporting this issue and for the PR to fix it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not a build issue, this is likely a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants