1 / 8

The .obj Model Format

The .obj model format is a text-based format developed by Alias Wavefront. This format allows for easy reading of vertices and faces from a file and displaying them. Each line in the file specifies the data type and is followed by the accompanying data. This example demonstrates the structure of a cube model.

somersj
Download Presentation

The .obj Model Format

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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.

  3. 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

  4. 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 vdefine 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 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 • 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

  5. Example 2 6 • # Example • 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 • 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 5 1 X 4 8 3 7 Z Y

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

  7. 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

  8. 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 OpenGL commands (see GL_POLYGON)

More Related