mirror of
https://github.com/thisistherk/fast_obj.git
synced 2025-04-06 22:15:01 +00:00
Fast C OBJ parser
Some .obj files have extra whitespace after usemtl and other statements; this may interfere with parsing, for example by adding a space to the material name which can result in inability to find it in .mtl file. For consistency, we replace all uses of is_end_of_name with skip_name that handles this by leaving trailing whitespace alone. It will be skipped in the parsing flow when we skip the newline, which is similar to the behavior of trailing whitespace after numeric data (which parse_float/int leave alone). |
||
---|---|---|
test | ||
.gitignore | ||
CMakeLists.txt | ||
fast_obj.c | ||
fast_obj.h | ||
LICENSE | ||
README.md |
fast_obj
Because the world needs another OBJ loader. Single header library, should compile without warnings in both C89 or C++. Much faster (5-10x) than other libraries tested.
To use:
fastObjMesh* mesh = fast_obj_read("path/to/objfile.obj");
...do stuff with mesh...
fast_obj_destroy(mesh);
Note that valid indices in the fastObjMesh::indices
array start from 1
. A dummy position, normal and
texture coordinate are added to the corresponding fastObjMesh
arrays at element 0
and then an index
of 0
is used to indicate that attribute is not present at the vertex. This means that users can avoid
the need to test for non-present data if required as the vertices will still reference a valid entry in
the mesh arrays.
A simple test app is provided to compare speed against tinyobjloader and check output matches.