Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Type
Motivation and Context
When loading a textured mesh with Assimp or TinyOBJ the materials are loaded in order, and a material index is provided for each triangle. However these materials are stored in an unordered map. A common occurrence is loaded a textured mesh along with a default material. The texture might be loaded as index 1 which can be seen in the TriangleMesh::triangle_material_ids_. By instead loading to a vector, the order is maintained.
This change breaks any access to the TriangleMesh::materials_ parameter. Though no instances of this access occur within the Open3d C++ library, it is exposed publicly in the Python API. Instead of a dictionary, the user would get a list of pairs.
Checklist:
python util/check_style.py --apply
to apply Open3D code styleto my code.
updated accordingly.
results (e.g. screenshots or numbers) here.
Description
This change is