<p>OBJ files typically contain vertex positions, texture coordinates (also known as UVs), and normals, as well as face data. There are other kinds of things they can contain but those are the most common (see <a href="http://paulbourke.net/dataformats/obj/" rel="nofollow noreferrer">here</a> for a fuller specification).</p>
<p>Vertex positions are specified with the <code>v</code> command, texture coordinates with <code>vt</code>, and normals with <code>vn</code>. The faces then reference those values by index using something like <code>f 1/2/3 4/5/6 7/8/9</code>, where each grouping of values represents a vertex on the face, and the numbers separated by slashes are the position/texture/normal indices.</p>
<p>The texture coordinates are the part that tell you what point in the texture image (jpg) goes with that vertex. If you've downloaded or exported a model that has a texture mapping, you should be able to see those <code>vt</code> commands in the obj file.</p>
<p>If a model doesn't have texture coordinates, though, then it most likely needs the help of a human 3D modeler. It is not easy to create usable texture coordinates for a model automatically (this is a big research topic). 3D modeling applications have various tools to help the modeler set up a texture layout, but it still usually needs some hand-tweaking to work well.</p>

CC BY-SA 4.0
2020-12-03T06:07:51.143Z
Thank you very much! But I still wonder what exactly do the values following the `vt` command mean? For example, in the updated question, the line `vt 0.000000 1.000000 0.000000` refers to which point in the image? Are the coordinates of the pixels in a image normalized to be in [0,1]? I think I've also seen `vt` coordinates to be outside [0,1], what do those mean?
trisct
CC BY-SA 4.0
2020-12-03T06:23:51.130Z
@trisct normalized yes. Values outside just repeat the texture useful for tiling etc.
joojaa
CC BY-SA 4.0
2020-12-02T22:11:02.063Z
2020-12-02T22:20:18.703Z
2020-12-02T22:20:18.703Z
Nathan Reed
<p>I am a new learner in 3d graphics. So forgive me if I seem to ask something very basic. I am confused how obj files are textured. So far I have seen:</p>
<ul>
<li>obj + jpg</li>
<li>obj + mtl + jpg</li>
</ul>
<p>When I look online, most say that they are textured by UV mapping. But when I look into the files, I find no specification of the UV mappings, i.e. how to map a pixel in the jpg file to a vertex (or maybe face?) in the obj file? I suppose there is some rule that is used by default. But I really need to know what it is.</p>
<p>Any reference, such as official documents, blogs, textbooks, online learning materials would be of great help. Thanks!</p>
<hr />
<p><strong>Update</strong>
I came across an example <a href="https://www.fileformat.info/format/wavefrontobj/egff.htm" rel="nofollow noreferrer">here</a>, called &quot;texture mapped square&quot;</p>
<pre><code># A 2 x 2 square mapped with a 1 x 1 square
# texture stretched to fit the square exactly.
mtllib master.mtl
v  0.000000 2.000000 0.000000
v  0.000000 0.000000 0.000000
v  2.000000 0.000000 0.000000
v  2.000000 2.000000 0.000000
vt 0.000000 1.000000 0.000000
vt 0.000000 0.000000 0.000000
vt 1.000000 0.000000 0.000000
vt 1.000000 1.000000 0.000000
# 4 vertices
usemtl wood
# The first number is the point,
# then the slash,
# and the second is the texture point
f 1/1 2/2 3/3 4/4
# 1 element
</code></pre>
<p>I assume that the coordinates following <code>vt</code> commands are the UV coordinates of the corresponding pixels in the texture image. Exactly what do the values mean? Are they normalized coordinates, that is, is the image normalized to have a coordinate system [0,1]x[0,1]?</p>

<3d><texture><3dtexture>
How are obj files textured?
trisct
# How are obj files textured?

(Asked by: username_0 on 2020-12-02)

I am a new learner in 3d graphics. So forgive me if I seem to ask something very basic. I am confused how obj files are textured. So far I have seen:

* obj + jpg
* obj + mtl + jpg

When I look online, most say that they are textured by UV mapping. But when I look into the files, I find no specification of the UV mappings, i.e. how to map a pixel in the jpg file to a vertex (or maybe face?) in the obj file? I suppose there is some rule that is used by default. But I really need to know what it is.

Any reference, such as official documents, blogs, textbooks, online learning materials would be of great help. Thanks!

---

**Update**
I came across an example [here](https://www.fileformat.info/format/wavefrontobj/egff.htm), called "texture mapped square"

```
# A 2 x 2 square mapped with a 1 x 1 square
# texture stretched to fit the square exactly.
mtllib master.mtl
v  0.000000 2.000000 0.000000
v  0.000000 0.000000 0.000000
v  2.000000 0.000000 0.000000
v  2.000000 2.000000 0.000000
vt 0.000000 1.000000 0.000000
vt 0.000000 0.000000 0.000000
vt 1.000000 0.000000 0.000000
vt 1.000000 1.000000 0.000000
# 4 vertices
usemtl wood
# The first number is the point,
# then the slash,
# and the second is the texture point
f 1/1 2/2 3/3 4/4
# 1 element

```

I assume that the coordinates following `vt` commands are the UV coordinates of the corresponding pixels in the texture image. Exactly what do the values mean? Are they normalized coordinates, that is, is the image normalized to have a coordinate system [0,1]x[0,1]?

**Tags:** 3d, texture, 3dtexture


---

## 1 answers

### Answer by username_1 on 2020-12-02. Score: 4 | Accepted answer

OBJ files typically contain vertex positions, texture coordinates (also known as UVs), and normals, as well as face data. There are other kinds of things they can contain but those are the most common (see [here](http://paulbourke.net/dataformats/obj/) for a fuller specification).

Vertex positions are specified with the `v` command, texture coordinates with `vt`, and normals with `vn`. The faces then reference those values by index using something like `f 1/2/3 4/5/6 7/8/9`, where each grouping of values represents a vertex on the face, and the numbers separated by slashes are the position/texture/normal indices.

The texture coordinates are the part that tell you what point in the texture image (jpg) goes with that vertex. If you've downloaded or exported a model that has a texture mapping, you should be able to see those `vt` commands in the obj file.

If a model doesn't have texture coordinates, though, then it most likely needs the help of a human 3D modeler. It is not easy to create usable texture coordinates for a model automatically (this is a big research topic). 3D modeling applications have various tools to help the modeler set up a texture layout, but it still usually needs some hand-tweaking to work well.

> **Comments:**
> **username_0**: Thank you very much! But I still wonder what exactly do the values following the `vt` command mean? For example, in the updated question, the line `vt 0.000000 1.000000 0.000000` refers to which point in the image? Are the coordinates of the pixels in a image normalized to be in [0,1]? I think I've also seen `vt` coordinates to be outside [0,1], what do those mean?  
> **username_2**: @username_0 normalized yes. Values outside just repeat the texture useful for tiling etc.  

---

