readOBJ.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // IGL Lib - Simple C++ mesh library
  3. //
  4. // Copyright 2011, Daniele Panozzo. All rights reserved.
  5. // History:
  6. // return type changed from void to bool Alec 18 Sept 2011
  7. // added pure vector of vectors version that has much more support Alec 31 Oct
  8. // 2011
  9. #ifndef IGL_READOBJ_H
  10. #define IGL_READOBJ_H
  11. #include "igl_inline.h"
  12. #include <Eigen/Core>
  13. #include <string>
  14. #include <vector>
  15. namespace igl
  16. {
  17. // Read a mesh from an ascii obj file, filling in vertex positions, normals
  18. // and texture coordinates. Mesh may have faces of any number of degree
  19. //
  20. // Templates:
  21. // Scalar type for positions and vectors (will be read as double and cast
  22. // to Scalar)
  23. // Index type for indices (will be read as int and cast to Index)
  24. // Inputs:
  25. // str path to .obj file
  26. // Outputs:
  27. // V double matrix of vertex positions #V by 3
  28. // F #F list of face indices into vertex positions
  29. // TC double matrix of texture coordinats #TC by 2
  30. // FTC #F list of face indices into vertex texture coordinates
  31. // N double matrix of corner normals #N by 3
  32. // FN #F list of face indices into vertex normals
  33. // Returns true on success, false on errors
  34. template <typename Scalar, typename Index>
  35. IGL_INLINE bool readOBJ(
  36. const std::string obj_file_name,
  37. std::vector<std::vector<Scalar > > & V,
  38. std::vector<std::vector<Scalar > > & TC,
  39. std::vector<std::vector<Scalar > > & N,
  40. std::vector<std::vector<Index > > & F,
  41. std::vector<std::vector<Index > > & FTC,
  42. std::vector<std::vector<Index > > & FN);
  43. //! Read a mesh from an ascii obj file
  44. // Inputs:
  45. // str path to .obj file
  46. // Outputs:
  47. // V eigen double matrix #V by 3
  48. // F eigen int matrix #F by 3
  49. //
  50. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  51. // crash or give garbage on anything else.
  52. //
  53. // KNOWN BUG: This only knows how to face lines without normal or texture
  54. // indices. It will probably crash or give garbage on anything else.
  55. IGL_INLINE bool readOBJ(const std::string str, Eigen::MatrixXd& V, Eigen::MatrixXi& F);
  56. }
  57. #ifdef IGL_HEADER_ONLY
  58. # include "readOBJ.cpp"
  59. #endif
  60. #endif