0

It has been several weeks that I am looking for a way to have one UV coordinates (tuple) associated to one vertex while loading a textured 3D mesh (.obj file + .png + .mtl) with Trimesh library. Here is how I am loading :

im = Image.open("/home/anass/Téléchargements/cow_mesh_views/texture/cow_texture.png")
im_arr=np.array(im)
mesh = trimesh.load('cow.obj',process=False,maintain_order=True)
tex = trimesh.visual.TextureVisuals(image=im)   
mesh.visual.texture = tex    
graph = mesh.vertex_adjacency_graph
#mesh.show()   
print(list(graph.neighbors(0))) #print direct neighboring vertices of vertex 0

The problem is the UV coordinates of some vertices. Indeed, there are some vertices in the .obj file that have 2 different tuples of UV coordinates depending on the face they are belonging. For example, vertex 764 is a neighbor of vertex 0. However, their UV coordinates according to trimesh are totally different :

 print(mesh.visual.uv[0]) #prints TrackedArray([0.126415, 0.872706])
 print(mesh.visual.uv[764] #prints TrackedArray([0.85437 , 0.658994])

I excepted Trimesh returns me TrackedArray([0.85403 , 0.66365]) since theses latters likely similar to the ones of vertex 764. And when I check the .obj, I find indeed that vertex 0 has 2 different UV coordinates according to two different faces.

My question is how can I manage the loading of the 3D textured mesh in order to have one UV coordinates per vertex ?? I tried an option saying to load the mesh with the option "process=True", however when doing this, I do no longer have the exact number of neighbors for each vertex (for example without this option, Trimesh returns 6 neighbors of vertex 0. However, when setting "process=True", it returns only 4 neighboring vertices).

Any help please?

Community
  • 1
  • 1
James
  • 9
  • 5

0 Answers0