Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ofMesh & ofApp::generateIndices(ofMesh & mesh, int width, int height) {
- int steps = 1;
- vector<glm::vec3> &vertices = mesh.getVertices();
- for (int i = 0; i < width - steps; i += steps) {
- for (int j = 0; j < height - steps; j += steps) {
- auto topLeft = width * j + i;
- auto topRight = topLeft + steps;
- auto bottomLeft = topLeft + width * steps;
- auto bottomRight = bottomLeft + steps;
- const ofVec3f & vTL = vertices[topLeft];
- const ofVec3f & vTR = vertices[topRight];
- const ofVec3f & vBL = vertices[bottomLeft];
- const ofVec3f & vBR = vertices[bottomRight];
- //upper left triangle
- if (vTL.z > 0 && vTR.z > 0 && vBL.z > 0
- && abs(vTL.z - vTR.z) < opts.facesMaxLength
- && abs(vTL.z - vBL.z) < opts.facesMaxLength) {
- const ofIndexType indices[3] = { topLeft, bottomLeft, topRight };
- mesh.addIndices(indices, 3);
- }
- //bottom right triangle
- if (vBR.z > 0 && vTR.z > 0 && vBL.z > 0
- && abs(vBR.z - vTR.z) < opts.facesMaxLength
- && abs(vBR.z - vBL.z) < opts.facesMaxLength) {
- const ofIndexType indices[3] = { topRight, bottomRight, bottomLeft };
- mesh.addIndices(indices, 3);
- }
- }
- }
- return mesh;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement