In the VBO examples presented so far, vertex data was either generated randomly or was specified by hand
In practice, however, 3D models are typically created in a 3D modeling software, such as Blender, 3DS Mas, Maya, Cinema 4D, etc.
A relatively simple and popular file format for the exchange of 3D models is the Wavefront OBJ format
The OBJ file format is supported by almost all 3D graphics programs
Wavefront OBJ format
The OBJ format consists of a text file with lists of 3D positions, texture coordinates, normal and vertex indices
A vertex position is specified by “v” followed by 3 float values:
v 0.6 -2.5 0.1
A vertex texture coordinate is specified by “vt” followed by 2 float values:
vt 0.5 0.75
A vertex normal is specified by “vn” followed by 3 float values:
vn 0.0 -1.0 0.0
A quadrilateral (or short “quad”) is specified by a “f” (face) followed by 4 vertex descriptions, each consisting of 3 indices:
f v/vt/vn v/vt/vn v/vt/vn v/vt/vn
where the respective first index refers to the list of vertices, the second one to the list of texture coordinates, and the third one to the list of normals
A triangle can be defined by 3 vertex descriptions
f v/vt/vn v/vt/vn v/vt/vn
For a vertex description not all indices need to be specified, it is also possible to have
only positions:
f v v v
only positions and texture coordinates:
f v/vt v/vt v/vt
only positions and normal:
f v/ /vn v/ /vn v/ /vn
Example: Wavefront OBJ file
ObjToVbo
For the examples shown in this lecture, it is not necessary that they contain their own parser for the OBJ format
Instead, in the following, we use the tool ObjToVbo, which converts an OBJ file into an array of floats. The array can then be written to a text or binary file
Such a float array can be read with high speed and with little programming effort and can be passed directly to a VBO in OpenGL.
Changing the parameter includedPerVertexData[ ] allows to adjust the composition of the generated float array so that it fits to the required format of the VBOs (details in the source code)
Example for the Usage of ObjToVbo
In this example, an OBJ file is converted to a float array that contains the following data structure per vertex:
댓글