<p>Well, there is no 1:1 correspondence the pixel might be in many locations at once.</p>
<p>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.</p>
<p>Only like i said what do you do with overlap?</p>

CC BY-SA 4.0
2021-08-04T17:44:07.990Z
2021-08-04T17:44:07.990Z
joojaa
<p>I have a mesh stored in .obj format with a texture image in .png format. For any &quot;defined&quot; 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 &quot;defined&quot; pixels, I mean the texture pixels that correspond to points on the surface of the mesh, not the texture pixels between the texture patches.</p>
<p>The .obj file format is as follows:</p>
<pre><code>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 ...
...
</code></pre>

<texture><mesh><uv-mapping><mapping>
How to map texture pixels to the corresponding 3D positions?
chaohuang
# How to map texture pixels to the corresponding 3D positions?

(Asked by: username_0 on 2021-08-03)

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 ...
...

```

**Tags:** texture, mesh, uv-mapping, mapping


---

## 1 answers

### Answer by username_1 on 2021-08-04. Score: 2

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?


---

