liveBook · Manning

Wavefront OBJ

As explained in Digital Twins in Action

OBJ is a text-based geometry file format for representing three-dimensional models, including vertices, texture coordinates, normals, and polygonal faces.

Wavefront OBJ (.obj) is a human-readable, text-based format for defining 3D geometry. It can describe a polygon mesh with vertices, faces, and normals. Because the geometry is readable as text, a small model can be written in an editor, though larger models are typically exported from modeling software. section 7.1

Listing 7.1 Definition of a 3D cube in OBJ file format
# Vertices
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

# Face normals
vn  0.0  0.0  1.0  # Front face normal
vn  1.0  0.0  0.0  # Right face normal
vn  0.0  0.0 -1.0  # Back face normal
vn -1.0  0.0  0.0  # Left face normal
vn  0.0  1.0  0.0  # Top face normal
vn  0.0 -1.0  0.0  # Bottom face normal

# Faces (format: vertex//normal)
f 1//1 2//1 3//1 4//1  # Front face
f 2//2 6//2 7//2 3//2  # Right face
f 6//3 5//3 8//3 7//3  # Back face
f 5//4 1//4 4//4 8//4  # Left face
f 4//5 3//5 7//5 8//5  # Top face
f 5//6 6//6 2//6 1//6  # Bottom face

The cube listing makes the file structure concrete: `v` lines give vertex coordinates, `vn` lines give normals, and `f` lines assemble faces using vertex and normal references. section 7.1

An exported OBJ model can be inspected in an OBJ viewer or loaded into a web page with Three.js. For web delivery, account for loading time: the browser must download the whole OBJ file before rendering any polygon, then convert its text geometry for the GPU. Larger files can therefore take longer to appear. section 7.2.1

How Digital Twins in Action covers it

How deep it goes
Works through vertex, normal, and face records in a cube; stops short of a complete OBJ format specification.
Examples
Uses a hand-written cube OBJ and an exported home model viewed in a browser.
What it assumes
Introduces vertices, faces, and normals before showing OBJ records; assumes no prior familiarity with OBJ syntax.
What you can do after
Build it from scratch as a small text-defined mesh, or apply it via Three.js to display an exported model.
How it connects
Connects polygon meshes and normals to Blender exports, Three.js rendering, and browser loading performance.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Digital Twins in Action. The section links point to the parts of the book it draws on.