tinyobjloader

repository·release·Indexed 26 days ago

https://github.com/tinyobjloader/tinyobjloader

A lightweight loader for Wavefront .obj and .mtl files. It provides a single-header C++11 implementation, a pure C11 implementation for freestanding environments, and Python bindings. Features include an Object Oriented API via tinyobj::ObjReader, a multi-threaded optimized parser (LoadObjOpt), and an experimental streaming parser for incremental data processing. Supports optional SIMD, zstd/gzip compression, and robust triangulation via mapbox/earcut.

Tokens
4.7K
Snippets
19
Records
30
Agent score
86%

What's inside tinyobjloader

  1. Overview of experimental .obj loaders

    release

    The experimental/ directory contains two specialized versions of the .obj loader:

    1. Multi-threaded optimized parser: Located in tinyobj_loader_opt.h. Designed for high-performance parsing using multiple threads.
    2. Streaming experimental parser: Located in stream/stream_obj_loader.h. Designed for streaming data processing.
  2. Overview of tinyobjloader implementations

    release

    tinyobjloader provides two independent implementations for loading Wavefront .obj and .mtl files:

    1. C++11 Implementation: A single-header loader (tiny_obj_loader.h) that requires only the C++ STL. It is designed for ease of integration into C++ projects.
    2. C11 Implementation: A pure C11 loader (tiny_obj_c.{c,h}) bundled with the tobj_tess tessellation library. This version is secure, portable, freestanding-capable (no libc dependency in the core), and supports optional multithreading, SIMD, and mmap. It also supports points (p) and free-form geometry (curv, curv2, surf).
  3. Compile the fuzzing target

    release

    The fuzz target is compiled alongside the main project when the LIB_FUZZING_ENGINE environment variable is defined during the CMake configuration step. For clang, use -fsanitize=fuzzer.

    export LIB_FUZZING_ENGINE=-fsanitize=fuzzer
    mkdir build && cd build
    cmake .. -DBUILD_SHARED_LIBS=OFF
    make -j $(nproc)
  4. Use the Experimental Stream OBJ Parser

    release

    The experimental stream parser is designed to parse Wavefront .obj files from a std::istream without loading the entire file into memory. This reduces peak input buffering and allows applications to consume mesh data (like faces) incrementally.

    The parser is implemented in two layers:

    1. StreamHandler: A callback-style incremental parser interface for low-level event handling.
    2. LoadObjStreamExperimental(...): A convenience wrapper that automatically builds tinyobj::attrib_t, tinyobj::shape_t, and tinyobj::material_t structures.

    It also supports an ordered multithreaded chunk mode that reads bounded batches of lines and parses them in parallel while replaying events in the original order.

  5. Install tinyobjloader

    release

    To install, copy the tiny_obj_loader.h header file into your project. You must define TINYOBJLOADER_IMPLEMENTATION exactly once in one of your .cc files to generate the implementation.

    #define TINYOBJLOADER_IMPLEMENTATION
    #include "tiny_obj_loader.h"
  6. Set up fuzzing for tinyobjloader

    release

    To perform fuzzing tests on the ParseFromString API, you need clang with fuzzer support (at least version 8.0).

    On Ubuntu 18.04, install the necessary packages using:

    sudo apt install clang++-8
    sudo apt install libfuzzer-8-dev

    If clang++ is not already pointing to version 8, you can configure update-alternatives:

    sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 10
    sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 10