1

I'm trying to find the uv coordinates of a neighboring vertices of a target vertex in a 3D textured mesh (please see the attached figure).

I'm trying to find the uv coordinates of neighboring vertices of a target vertex in a 3D textured mesh (please see the attached figure). I tried this :

#---- load mesh with texture 
import trimesh
from PIL import Image

im = Image.open("/home/cow_mesh_views/texture/cow_texture.png")
im_arr=np.array(im)
mesh = trimesh.load('/home/cow_mesh_views/cow.obj',process=False,                   
   maintain_order=False)
tex = trimesh.visual.TextureVisuals(image=im)   
mesh.visual.texture = tex   

#construct a non oriented graph
graph = mesh.vertex_adjacency_graph

#specify a target vertex and get their directed neighboring vertices
target = 0 #target vertex
neighbors= list(graph.neighbors(target)) # [764, 767, 812, 813, 1158, 1165]

#color the neighboring vertices so we can visualize them
colors=[[255,255,0],[0,255,0],[0,0,255],[255,0,255],[0,255,255],[0,0,0]]  #some colors
mesh_colored=mesh.copy()
mesh_colored.visual=mesh.visual.to_color()

index=0
for i in list(graph.neighbors(target)):
    mesh_colored.visual.vertex_colors[i][0]=colors[col][0]
    mesh_colored.visual.vertex_colors[i][1]=colors[col][1]
    mesh_colored.visual.vertex_colors[i][2]=colors[col][2]
    index = index+1

#color the target vertex in red
mesh_colored.visual.vertex_colors[target][0]=255
mesh_colored.visual.vertex_colors[target][1]=0
mesh_colored.visual.vertex_colors[target][2]=0

mesh.show() #to obtain the attached figure

#display the uv coordinates of the neighboring vertices and target vertex
list_uv=[]
list_uv.append(mesh.visual.uv[target])
for i in list(graph.neighbors(0)):
    list_uv_neig.append(mesh.visual.uv[i])

print(list_uv_neig)
'''
[TrackedArray([0.126415, 0.872706])  #uv coordinates of the target vertex 0
 TrackedArray([0.85437 , 0.658994]), #uv coordianted of the first neighbor 764
 TrackedArray([0.858253, 0.665619]), #uv coordianted of the first neighbor 767
 TrackedArray([0.158518, 0.885909]), #uv coordianted of the first neighbor 812
 TrackedArray([0.853611, 0.668611]), #uv coordianted of the first neighbor 813
 TrackedArray([0.131   , 0.896051]), #uv coordianted of the first neighbor 1158
 TrackedArray([0.108088, 0.902447])] #uv coordianted of the first neighbor 1165
 '''

We can remark that the target vertex 0 has very distant uv coordinates compared to neighbors 764 767 813, but somehow similar to neighbors 812 1158 and 1165. I expected to have closes uv coordinates since the vertices are close in the 3D mesh !

When I check in the 3D file .obj file for the faces inclung vertex 0 (1 in the .obj file), I found this (face, vertex/texture_coordinates_id vertex/texture_coordinates_id) :

 f 1/2787 765/39 768/42
 f 768/42 814/96 1/2787
 f 813/98 1/2787 814/96
 f 1/2868 813/521 1159/522
 f 1159/522 1166/531 1/2868 
 f 765/532 1/2868 1166/531

We can remark that the vertex 1 (0 in Trimesh library) is associated to two texture_coordinates_ids : 2787 and 2868. When I check in the .obj file for the uv coordinates associated to theses ids, I find respectively : [0.85403 0.66365] and [0.126415 0.872706]. This might explain why I don't find the close uv coordinated of the vertices.

So my question is : how to get uniform uv coordinates for close vertices belonging to the same neighborhood so as their are close in order to reflect this close vertices ?

Thank you for your help

Figure

paul
  • 9
  • 2

0 Answers0