/cobj

Minimal C Alias Wavefront OBJ loader

Primary LanguageCMIT LicenseMIT

cobj

Single-header OBJ (Alias Wavefront) loader written in C

cobj.h

features

  • no dependencies
  • custom memory allocator functions
  • three modes of allocation:
  • exact amount (2 passes reader)
  • double-the-size array type
  • callback (no allocation)
  • material library (optional and shareable), see struct cobjMtl
  • negative indices
  • polygons > 3 vertices
  • 16/32 bits for indices
  • can read/parse fast and efficiently +100Mb obj files

todo

  • make three allocation modes available by flag
  • Option to Expand vertices+uv+normals for glDrawElements/glDrawArrays format
  • Option to compute normals when no presents
  • Binary version serialization. defines to include parsing/binary code.
  • Export to DX/GL .h binary data to embed into data segment
  • Smoothing groups and other OBJ elements not supported so far
  • Support for half float?
  • Stripize?

some screenshots

Models are from http://graphics.cs.williams.edu/data/meshes.xml

buddha.obj

File size: 90Mb
Mem footprint: 39Mb (2 pass mode)
Triangles: 1,087,474
Vertices: 549,333
Load time: 2.3s (1 pass mode)

dragon.obj

File size: 70Mb
Mem footprint: 31Mb (2 pass mode)
Triangles: 871,306
Vertices: 438,929
Load time: 1.9s (1 pass mode)

rungholt.obj

File size: 262Mb
Mem footprint: 270Mb! (2 pass mode)
Triangles: 6,704,264
Vertices: 12,308,528
Load time: 5.2s (1 pass mode)