writeOBJ.cpp 592 B

12345678910111213141516171819202122232425
  1. #include "writeOBJ.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cstdio>
  5. IGL_INLINE bool igl::writeOBJ(const std::string str, const Eigen::MatrixXd& V, const Eigen::MatrixXi& F)
  6. {
  7. std::ofstream s(str.c_str());
  8. if(!s.is_open())
  9. {
  10. fprintf(stderr,"IOError: writeOBJ() could not open %s\n",str.c_str());
  11. return false;
  12. }
  13. for(int i=0;i<V.rows();++i)
  14. s << "v " << V(i,0) << " " << V(i,1) << " " << V(i,2) << std::endl;
  15. for(int i=0;i<F.rows();++i)
  16. s << "f " << F(i,0)+1 << " " << F(i,1)+1 << " " << F(i,2)+1 << std::endl;
  17. s.close();
  18. return true;
  19. }