Wavefront OBJ reader for building CGAL::Polyhedron_3

CGAL provides high quality generic half-edge data structure for representing polyhedral surfaces as well as many algorithms for mesh processing. However, CGAL doesn’t have any in-build support for building a polyhedron from Wavefront OBJ or PLY file. The following code is a basic OBJ file loader which reads vertex coordinates and faces (can be polygons) from OBJ file. Note that it doesn’t read vertex normals, face normals, or texture coordinates. Code is well commented and should be fairly obvious.

importOBJ() Function

Using importOBJ()

Downloads

ImportOBJ.h
TestImportOBJ.cpp


One Comment
  • Andrei Serebro Reply

    Thank you very much for sharing this useful stuff!
    There is a small typo in the code above, though. It should be

    “`if(!_file)“`

    rather than

    “`if(_file)“`

Write a comment, your thoughts are welcome: