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

Update the GLTF writer to support writing textured models #6101

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

dbs4261
Copy link
Contributor

@dbs4261 dbs4261 commented Apr 21, 2023

The GLTF exporter does not currently support textured meshes. This is because Open3d's per triangle UV coordinates makes the task non-trivial. This change set adds that feature.
Note: this depends on #5938 which changes how textures are stored in an open3d::geometry::TriangleMesh

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes #
  • New feature (non-breaking change which adds functionality). Resolves #
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

The current GLTF exporter does not support textured meshes. This PR adds an exporter for TriangleMeshModels. Currently there is only a reader. It does not add support to the existing writer.

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

Code was added to create TriangleMeshModels from a TriangleMesh. This isn't a simple conversion because TriangleMesh's support multiple materials, assigned on a per triangle basis. However TriangleMeshModels are supposed to only have one material per mesh. There is a similar issue for the export of the meshes. TriangleMesh's store texture coordinates on a per triangle basis. This is to support seams where the same vertex has different texture coordinates. However GLTF requires texture coordinates to be stored on a per vertex basis. So this PR adds a function to convert a mesh to have per-vertex texture coordinates. Currently this function is in a detail namespace but could be moved to a public API.


This change is Reviewable

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.
…Mesh as well as for exporting a TriangleMeshModel to GLTF
@errissa errissa self-requested a review April 21, 2023 19:33
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