Wavefront OBJ Files

The Wavefront OBJ file format is a common format for storing and sharing 3D graphics data. Like the PPM image format that you implemented way back in Chapter 2, Drawing on a Canvas, the OBJ format is plain text, which means you can view, edit, and even create these files in any text editor, though it’s much easier to model something in a 3D modeling tool and then export it to OBJ.

The OBJ format consists of statements, each of which occupies a single line. Each statement is prefaced with a command, followed by a space-delimited list of arguments. For example, the following OBJ file defines three vertices (v), and a triangle (f, for “face”) that references those vertices.

 v 1.5 2 1.3
 v 1.4 -1.2 0.12
 v -0.1 0 -1.3
 

Get The Ray Tracer Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.