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

Bug: Trimesh introduced non manifold edges and fills big hole when loading mesh #2326

Open
nepfaff opened this issue Nov 21, 2024 · 4 comments

Comments

@nepfaff
Copy link
Contributor

nepfaff commented Nov 21, 2024

I have this mesh:
image

I load it with trimesh and save it again using the following code:

mesh = trimesh.load(mesh_path, skip_materials=True, force="mesh", process=False)
mesh.export("out.obj")

Trimesh then produces this mesh:
image

Note that the mesh has the big hole filled in and contains non manifold edges. This corresponds to the trimesh visualization with mesh.show() and thus must have something to do with the way that the mesh is loaded.

Trimesh version: trimesh-4.5.2

@mikedh
Copy link
Owner

mikedh commented Nov 21, 2024

Hey, it looks like what's happening here is that file has a ton of n-gon's that have to be triangulated, which trimesh does as a triangle fan:

usemtl Material
f 14/1/1 7/2/1 3/3/1 1/4/1 40/5/1 33/6/1 37/7/1 36/8/1 34/9/1 35/10/1 39/11/1 32/12/1 38/1\
3/1 29/14/1 30/15/1 28/16/1 31/17/1 26/18/1 27/19/1 25/20/1
f 40/5/1 1/4/1 5/21/1 7/2/1 14/1/1 12/22/1 15/23/1 11/24/1 9/25/1 10/26/1 16/27/1 13/28/1 \
24/29/1 19/30/1 18/31/1 17/32/1 23/33/1 20/34/1 22/35/1 21/36/1
f 4/37/2 3/3/2 7/38/2 8/39/2

It looks like three.js behaves the same as trimesh. Meshlab also appears to use the identical triangulation algorithm as trimesh. What viewer/generator are these meshes being created in? Do they load in meshlab or blender?

@nepfaff
Copy link
Contributor Author

nepfaff commented Nov 21, 2024

I see. That makes sense then. Thank you for the quick reply! No Bug but a mesh issue in this case 😊

The mesh was generated using Blender, and the visualization is from Meshlab. I'm guessing this means that these use some way of detecting this issue and handling it differently?

This is the Blender visualization:
image

@mikedh
Copy link
Owner

mikedh commented Nov 21, 2024

Oh yeah in the meshlab source:

This function is intended as a trivial fallback when glutessellator is not available.
it assumes just ONE outline

We could call trimesh.creation.triangulate_polygon on this loop too, however it's quite a bit more work since we'd have to fit the plane, transform the vertices into 2D, triangulate, transform back to 3D, rather than just looking at the topology like the fan tessellation.

@nepfaff
Copy link
Contributor Author

nepfaff commented Nov 25, 2024

That is interesting. Thank you for looking into Meshlab's code.

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

No branches or pull requests

2 participants