mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
2.99k stars 577 forks source link

Discrepancy in Importing .obj Mesh with Vertex Texture #2252

Open astonishingwolf opened 3 months ago

astonishingwolf commented 3 months ago

Hi,

First of all, thank you for creating such an awesome project. Recently, I noticed an unusual behavior in the trimesh loading function for .obj files. When I import an SMPL object with texture coordinates, it returns 7576 vertices instead of the expected 6890 vertices (as verified from the .obj file).

Upon closer inspection, I found that in obj.py, before returning the vertices (in the case of a textured .obj), the function applies a mask to them before return which results in duplication. The mask is based on the unique vertex texture coordinates. So if the same vertex has two different uv coordinates in separate texture faces it appends them to separate rows causing the number of vertex to increase before returning. I am unsure whether this is an intended feature or a bug that needs fixing.

gt732 commented 3 weeks ago

@astonishingwolf Did you find a way around this? Its driving me crazy, I'm trying to apply a texture to the smpl obj model but I keep getting errors for discrepancy between the loaded smpl obj and SMPL vertices generated by VIBE/PARE.

astonishingwolf commented 2 weeks ago

Hey @gt732 Umm no there seems to be some bug in the import obj script of trimesh. I went with an in-house implementation of a dataloader from one of my peers. It works fine for importing vertices, faces, normals, and texture. You can use this https://github.com/AstitvaSri/ZeroBS_OBJ_IO/blob/main/zerobs_io.py Ignore the name :) Let me know in case if you need any other help.