← All school projects

finished2025

OBJ parser and tokenizer

C++ parser for Wavefront OBJ files (vertices, texture coordinates, normals, faces) and a tokenizer that splits text into nested segments

C++ · CMake · Parsing · Wavefront OBJ · 3D · Solo

GitHub ↗

A parser for Wavefront OBJ 3D models and a generic tokenizer, written during the GTech 3 "Parser" module.

Context

Theory week from November 3 to 7, 2025: text parsing, binary parsing, .obj parsing, then an introduction to the FBX SDK and OpenGL. The repository keeps the module's name ("Parser FBX"); the code covers the tokenizer and the OBJ parser. The course slides and the provided projects (basicgl, bmp, parser) sit in Doc/.

What I did

The tokenizer and its test program, then the OBJ parser: data structures, line-by-line reading, the four face formats, index conversion, test files, CMake and README. Individual work.

Links

OBJ parser

Supported lines:

CommandContent
v x y z [w]Vertex (w defaults to 1.0)
vt u v [w]Texture coordinate (w defaults to 0.0)
vn x y zNormal
f ...Face: v, v/vt, v//vn or v/vt/vn, triangles, quads and polygons
o nameObject name
#Comment

File indices (1-based) are converted to 0-based; a missing index is -1. vp, s, g, usemtl and mtllib lines are skipped. An error returns false and a message with the line number (getLastError()).

ObjData
  ├── vertices   : std::vector<Vertex>
  ├── texCoords  : std::vector<TexCoord>
  ├── normals    : std::vector<Normal>
  ├── faces      : std::vector<Face>  (FaceVertex: vIndex, vtIndex, vnIndex)
  └── objectName

Tokenizer

  • tokenize: splits text into tokens (:, (, ), {, }, /, \, ", , and strings).
  • segmentize: groups tokens into nested segments (parentheses, braces, quotes) with a stack.

Tests

  • cube.obj: 8 vertices, 4 texture coordinates, 6 normals, 12 triangles.
  • test-formats.obj: one face of each format, plus a quad.
  • test.sh builds the parser and runs it on both files.

Stack

TechRole
C++17Language
CMake / Visual StudioBuild (two executables: TestObjParser, TestTokenizer)