void updateDeletedVoxelNeighbors(int x, int y, int z, std::vector<Triangle>& v, T empty) { int offset[6][3] = { { 0, -1, 0 }, { 0, 1, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 0, -1 } }; for(int i = 0; i < 6; ++i) { int xx = x + offset[i][0]; int yy = y + offset[i][1]; int zz = z + offset[i][2]; if(validPos(xx, yy, zz) && get(xx, yy, zz) != 0 && shouldGeneratePoly(xx, yy, zz, Cube::oppositeFace(i), empty)) { TriangleRun* run = &triangle_run[index(xx, yy, zz)]; while(run->next) { run = run->next; } TriangleRun* new_run = new TriangleRun; new_run->start = v.size(); new_run->end = (int)v.size() - 1; Cube c; c.x_size = grid_dx; c.y_size = grid_dy; c.z_size = grid_dz; c.setPos(glm::vec3(xx * grid_dx, yy * grid_dy, zz * grid_dz)); Quad q; Triangle a, b; c.getFace(Cube::oppositeFace(i)).triangulate(a, b); v.push_back(a); v.push_back(b); new_run->end += 2; run->next = new_run; } } }
std::vector<Triangle> triangulate(T empty) { T* ptr = data; std::vector<Triangle> t; for(int z = 0; z < z_size; ++z) { for(int y = 0; y < y_size; ++y) { for(int x = 0; x < x_size; ++x) { if(*ptr != empty) { int pos = ptr - data; triangle_run[pos].start = t.size(); triangle_run[pos].end = (int)t.size() - 1; for(int i = 0; i < 6; ++i) { Cube c; c.x_size = grid_dx; c.y_size = grid_dy; c.z_size = grid_dz; c.setPos(glm::vec3(x * grid_dx, y * grid_dy, z * grid_dz)); if(shouldGeneratePoly(x, y, z, i, empty)) { Quad q; Triangle a, b; c.getFace(i).triangulate(a, b); t.push_back(a); t.push_back(b); triangle_run[pos].end += 2; } } } ++ptr; } } } return t; }