# a mesh is a collection of vertices, edges, and faces that define the shape of a 3D object. In this case, we are using a torus mesh from open3D.mesh = o3d.geometry.TriangleMesh.create_torus()# the vertices of the mesh are the points in 3D space that define the shape of the torus. We can access them as a numpy array for easier manipulation.verts = np.asarray(mesh.vertices)# Distance from the center of the torus in the XY planedistance_xy = np.sqrt(verts[:, 0]**2+ verts[:, 1]**2)# the u_angle is the angle around the central hole of the torus, and the v_angle is the angle around the tube of the torus. We can compute them using the arctan2 function, which gives us the angle in radians between the positive x-axis and the point (x,y). u_angle = np.arctan2(verts[:, 1], verts[:, 0])v_angle = np.arctan2(verts[:, 2], distance_xy - R)
Troubleshooting
Getting UV-coordinates right is hard. The UV-coordinates are the coordinates of the texture image that correspond to each vertex of the 3D model. If the UV-coordinates are wrong, the texture will be distorted or not appear at all. This is what it looks like when they are off:
Or this one where the V coordinate is linearly increasing
Below we have the UV-coordinates almost right, but the seam is blurry. This is a ‘seam crosser’ problem. The UV-coordinates are in [0,1]x[0,1] so on the torus 0.9 is actually close to 0.1, but the texture mapping doesn’t know that, so it stretches the texture across the seam. This can be fixed by snapping the UV-coordinates to 0 or 1 when they are close to the seam, but this can cause other problems if not done carefully.