The obj Model Format Jason Goffeney 3142006 Model

The. obj Model Format Jason Goffeney 3/14/2006

Model Format • The. obj model format was developed by Alias Wavefront. • It is in text and about a simple as you can get. • For assignment 3 you will need to read vertices and faces from the file and display them.

Model Format • Each line in the file begins with a character string to specify its type and is followed by the data accompanying it. # - the line is a comment v - a vertex followed by x, y and z float coordinate info f - a face followed by integer indices of vertices starting with 1

Example • Here is a small example of a cube model. – The first line starts with a comment symbol # so it is discarded – The lines beginning with v define the x, y and z position of each vertex – The lines beginning with f are followed by the vertices it is composed of. These each represent the side of a cube so they have 4 vertices. # Example v 1. 0 v 1. 0 -1. 0 v -1. 0 f 1 3 4 2 f 5 7 8 6 f 1 5 6 2 f 3 7 8 4 f 1 5 7 3 f 2 6 8 4

Example 2 6 5 1 X 4 8 3 7 Z Y # Example v 1. 0 v 1. 0 -1. 0 v -1. 0 f 1 3 4 2 f 5 7 8 6 f 1 5 6 2 f 3 7 8 4 f 1 5 7 3 f 2 6 8 4

Other Data Types • There are two other data types that may be held in a. obj file. – vn float defines the normal of the vertex at the equivalent index (the first vn matches the first v) – vt float defines a texture coordinate for the vertex at the equivalent index (the first vt matches the first v)

Managing the Data • A model class should mirror the structure of the file – A vertex is composed of 3 floats – A face is composed of a list of integers – A model is a list of vertices and a list of faces

The Model Class • Some ideas for implementing a model class – A constructor that takes the file path as a parameter – An interior method to open the file, read each line and fill the appropriate data structures – A method to render the model by drawing each polygon using Open. GL commands (see GL_POLYGON)
- Slides: 8