mikedh / trimesh

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

Loading Objaverse GLB files with textures #2304

Open preddy5 opened 1 month ago

preddy5 commented 1 month ago

Hi @mikedh, Thank you for maintaining this amazing repository. Geometric processing research wouldn't be what it is today without trimesh.

I've downloaded a GLB scene from the Objaverse dataset on Sketchfab (link). However, I'm struggling to load the file with trimesh while preserving the textures. When I converted the GLB scene to an OBJ file using this online converter, I was able to load it successfully, but this process isn't scalable for the entire Objaverse dataset.

I also tried loading the GLB file in Blender and exporting it as an OBJ. Although the exported file contained the geometry, it didn’t include the texture information (even though the texture appears when rendering or UV editing in Blender).

I would really appreciate any guidance you could provide on how to load the GLB file as a trimesh mesh object while retaining the textures, so I can fully utilize trimesh functionalities. Thank you so much for your time and help!

Code:

mesh = trimesh.load(file_path, process=False, force='mesh')
if hasattr(mesh.visual, 'material') and mesh.visual.material.image is not None:
    print("Mesh has a texture")
    print(f"Texture size: {mesh.visual.material.image.size}")
else:
    print("Mesh does not have a texture")

returns "Mesh does not have a texture"

Regards, Pradyumna.

lionlai1989 commented 4 weeks ago

I faced a similar issue when exporting a mesh with textures to a GLB file. "trimesh" sometimes creates a GLB with textures but sometimes doesn't.

The problem, in my case, was related to missing dependencies required by "trimesh", which can be solved by:

pip install "trimesh[easy]"

Hope this works for you!