I have a mesh stored in .obj format with a texture image in .png format. For any "defined" pixel in the texture image, I'd like to compute the corresponding 3D coordinates when the texture image is mapped to the 3D mesh. For "defined" pixels, I mean the texture pixels that correspond to points on the surface of the mesh, not the texture pixels between the texture patches.

The .obj file format is as follows:

v 0.123 0.234 0.345 1.0
v ...
vt 0.500 1
vt ...
vn 0.707 0.000 0.707
vn ...
f 1/1 2/2 3/3
f ...

1 Answer 1


Well, there is no 1:1 correspondence the pixel might be in many locations at once.

What your asking is relatively easy. Just iterate through each triangle (f). Then get the texture coordinate of each triangle corner (second index in f tells you which vt to look up ). The texture coordinates are in fractions of image so 0.5 0.5 is in middle of image. You need to convert this triangle to a list of pixels. Then for each pixel read the barycentric coordinate, and from barycentric coordinate look up 3D location from vertices (first index of f and v for position in space). done.

Only like i said what do you do with overlap?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.