Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. allVertices.clear();
  2. allVertexNormals.clear();
  3. allIndices.clear();
  4. std::ifstream file_(path);
  5. std::string line;
  6. if (file_.is_open()) {
  7. while (!file_.eof()) {
  8. std::getline(file_, line);
  9.  
  10. std::string header = line.substr(0, line.find_first_of(" ",0));
  11.  
  12. if (!header.compare("#")) continue;
  13.  
  14. if (!header.compare("v")) {
  15. glm::vec3 vertex;
  16. std::stringstream ss (line.substr(2));
  17. ss >> vertex.x >> vertex.y >> vertex.z;
  18. allVertices.push_back(vertex);
  19. }
  20. if (!header.compare("vn")) {
  21. glm::vec3 normal;
  22. std::stringstream ss(line.substr(3));
  23. ss >> normal.x >> normal.y >> normal.z;
  24. allVertexNormals.push_back(normal);
  25. }
  26. if (!header.compare("f")) {
  27. std::stringstream ss(line.substr(2));
  28. int i;
  29.  
  30. while (ss >> i) {
  31. allIndices.push_back(i);
  32. //skip all space and /
  33. while(ss.peek() == ' ' || ss.peek() == '/'){
  34. ss.ignore();
  35. }
  36. }
  37. }
  38. }
  39. }
  40. else {
  41. std::cout << "Fail to open" << std::endl;
  42. return false;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement