2
$\begingroup$

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, 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]?

$\endgroup$

1 Answer 1

4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – trisct
    Commented Dec 3, 2020 at 6:07
  • 1
    $\begingroup$ @trisct normalized yes. Values outside just repeat the texture useful for tiling etc. $\endgroup$
    – joojaa
    Commented Dec 3, 2020 at 6:23

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.