CSE 40166 / 60166 - Computer Graphics

|    Home  |   Syllabus  |   Assignments  |   Schedule  |   Resources   |

.obj File Format

Sample *.obj file:
#
# example .obj file
#

mtllib cube.mtl

v -1.0 -1.0 -1.0
v -1.0 1.0 -1.0
v 1.0 1.0 -1.0
v 1.0 -1.0 -1.0
v 1.0 -1.0 -1.0
v 1.0 1.0 -1.0
v -1.0 1.0 -1.0
v -1.0 -1.0 -1.0
# 8 vertices

vt 0.0 0.0
vt 0.0 1.0
vt 1.0 1.0
vt 1.0 0.0
# 4 vertex tex coords

vn 0.0 0.0 1.0
vn 0.0 0.0 -1.0
vn -1.0 0.0 0.0
vn 1.0 0.0 0.0
vn 0.0 1.0 0.0
vn 0.0 -1.0 0.0
# 6 vertex normals

s 1
usemtl cube_mtl
f 4/4/1 3/3/1 2/2/1 1/1/1
f 8/4/2 7/3/2 6/2/2 5/1/2
f 1/4/3 2/3/3 7/2/3 8/1/3
f 5/4/4 6/3/4 3/2/4 4/1/4
f 3/4/5 6/3/5 7/2/5 2/1/5
f 5/4/6 4/3/6 1/2/6 8/1/6
# 8 faces
Explaination of each line:
  • # comments
           comments
  • mtllib materialFile.mtl
           Specify the material file to use for material definitions
  • v vertex_x vertex_y vertex_z
           Specify a vertex and its coordinates in XYZ-space
  • vt texCoord_u texCoord_v
           Specify a texture coordinate and its coordinates in UV-space
  • vn vertexNormal_x vertexNormal_y vertexNormal_z
           Specify a vertex normal and its direction in XYZ-space
  • s 1 or off
           Specify smooth shading (1) or flat shading (off)
  • f vertexIndex/texCoordIndex/vertexNormalIndex ...
           Specify a polygon face made up of N vertices with a given texture coordinate and vertex normal. If only two values are given with one slash, then they are interpretted as (vertex/texCoord). If two values are given with two slashes, then they are interpretted as (vertex//vertexNormal). If only a single value is given, then it is just a vertex.
For more information, visit Wikipedia or paulbourke.net.