Jump to content

Wavefront .obj file

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Dila (talk | contribs) at 15:36, 3 December 2009 (Added Sketchup to a list of software packages that support this format.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

OBJ (or .OBJ) is a geometry definition file format first developed by Wavefront Technologies for its Advanced Visualizer animation package. The file format is open and has been adopted by other 3D graphics application vendors. For the most part it is a universally accepted format.

The OBJ file format is a simple data-format that represents 3D geometry alone — namely, the position of each vertex, the UV position of each texture coordinate vertex, normals, and the faces that make each polygon defined as a list of vertices, texture vertices, and normals.

A typical OBJ file looks like this:

# this is a comment
# List of Vertices, with (x,y,z) coordinates.
v 0.123 0.234 0.345 
v ... 
...

#Texture coordinates, in (u,v) coordinates.
vt 0.500 -1.352
vt ...
...

#Normals in (x,y,z) form; normals might not be unit. 
vn 0.707 0.000 0.707
vn ...
..

#Each face is given by a set of three indices each to the vertex/texture/normal
#coordinate array that precedes this.
#Hence f 1/1/1 2/2/2 3/3/3 is a triangle having texture coordinates and 
#normals for those 3 vertices,
#and having for the vertex 1 (1/1/1) the vertex 1 from the "v" list, texture coordinate 1 from 
#the "vt" list, and the normal 1 from the "vn" list; then for the 2nd vertex: 
#the vertex 2 from the "v" list, texture coordinate 2 from 
#the "vt" list, and the normal 2 from the "vn" list; for the 3rd vertex: 
#vertex 3 from the "v" list, texture coordinate 3 from 
#the "vt" list, and the normal 3 from the "vn" list
#NOTE: The list of vertices, etc. is one-based-indexing (meaning the first vertex in the file is v1).

f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3
f ...
...

# when there are named polygon groups or materials groups the following 
# tags appear in the face section,
g [group name]
usemtl [material name]
# the latter matches the named material definitions in the external .mtl file.
# Each tag applies to all faces following, until another tag of the same type 
# appears (therefor, the texture coordinate can be left out, since it is 
# defined for all faces following, until another tag of the same type 
# appears).
f v1//vn1 v2//vn2 v3//vn3 
...

...

An OBJ file also supports smoothing parameters to allow for curved objects, and also the possibility to name groups of polygons. It also supports materials by referring to an external MTL material file.

OBJ files, due to their list structure, are able to reference vertices, normals, etc either by their absolute (1-indexed) list position, or relatively by using negative indices and counting backwards. However, not all software supports the latter approach, and conversely some software inherently writes only the latter form (due to the convenience of appending elements without needing to recalculate vertex offsets, etc), leading to occasional incompatibilities.

Software that supports OBJ

See also