Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1.  
  2. ofMesh & ofApp::generateIndices(ofMesh & mesh, int width, int height) {
  3. int steps = 1;
  4. vector<glm::vec3> &vertices = mesh.getVertices();
  5.  
  6. for (int i = 0; i < width - steps; i += steps) {
  7. for (int j = 0; j < height - steps; j += steps) {
  8. auto topLeft = width * j + i;
  9. auto topRight = topLeft + steps;
  10. auto bottomLeft = topLeft + width * steps;
  11. auto bottomRight = bottomLeft + steps;
  12.  
  13. const ofVec3f & vTL = vertices[topLeft];
  14. const ofVec3f & vTR = vertices[topRight];
  15. const ofVec3f & vBL = vertices[bottomLeft];
  16. const ofVec3f & vBR = vertices[bottomRight];
  17.  
  18. //upper left triangle
  19. if (vTL.z > 0 && vTR.z > 0 && vBL.z > 0
  20. && abs(vTL.z - vTR.z) < opts.facesMaxLength
  21. && abs(vTL.z - vBL.z) < opts.facesMaxLength) {
  22. const ofIndexType indices[3] = { topLeft, bottomLeft, topRight };
  23. mesh.addIndices(indices, 3);
  24. }
  25.  
  26. //bottom right triangle
  27. if (vBR.z > 0 && vTR.z > 0 && vBL.z > 0
  28. && abs(vBR.z - vTR.z) < opts.facesMaxLength
  29. && abs(vBR.z - vBL.z) < opts.facesMaxLength) {
  30. const ofIndexType indices[3] = { topRight, bottomRight, bottomLeft };
  31. mesh.addIndices(indices, 3);
  32. }
  33. }
  34. }
  35.  
  36. return mesh;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement