cut_mesh(): new parameter to optionally not triangulate the caps.

This commit is contained in:
Vojtech Bubnik 2021-05-19 13:52:47 +02:00
parent 66cf7ea9d3
commit e952aded78
2 changed files with 33 additions and 28 deletions

View file

@ -1179,6 +1179,7 @@ std::vector<ExPolygons> slice_mesh_ex(
return layers; return layers;
} }
// Remove duplicates of slice_vertices, optionally triangulate the cut.
static void triangulate_slice( static void triangulate_slice(
indexed_triangle_set &its, indexed_triangle_set &its,
IntersectionLines &lines, IntersectionLines &lines,
@ -1186,7 +1187,8 @@ static void triangulate_slice(
// Vertices of the original (unsliced) mesh. Newly added vertices are those on the slice. // Vertices of the original (unsliced) mesh. Newly added vertices are those on the slice.
int num_original_vertices, int num_original_vertices,
// Z height of the slice. // Z height of the slice.
float z) float z,
bool triangulate)
{ {
sort_remove_duplicates(slice_vertices); sort_remove_duplicates(slice_vertices);
@ -1230,6 +1232,7 @@ static void triangulate_slice(
f(i) = map_duplicate_vertex[f(i) - num_original_vertices]; f(i) = map_duplicate_vertex[f(i) - num_original_vertices];
} }
if (triangulate) {
size_t idx_vertex_new_first = its.vertices.size(); size_t idx_vertex_new_first = its.vertices.size();
Pointf3s triangles = triangulate_expolygons_3d(make_expolygons_simple(lines), z, true); Pointf3s triangles = triangulate_expolygons_3d(make_expolygons_simple(lines), z, true);
for (size_t i = 0; i < triangles.size(); ) { for (size_t i = 0; i < triangles.size(); ) {
@ -1258,6 +1261,7 @@ static void triangulate_slice(
if (facet(0) != facet(1) && facet(0) != facet(2) && facet(1) != facet(2)) if (facet(0) != facet(1) && facet(0) != facet(2) && facet(1) != facet(2))
its.indices.emplace_back(facet); its.indices.emplace_back(facet);
} }
}
// Remove vertices, which are not referenced by any face. // Remove vertices, which are not referenced by any face.
its_compactify_vertices(its); its_compactify_vertices(its);
@ -1266,7 +1270,7 @@ static void triangulate_slice(
// its_remove_degenerate_faces(its); // its_remove_degenerate_faces(its);
} }
void cut_mesh(const indexed_triangle_set &mesh, float z, indexed_triangle_set *upper, indexed_triangle_set *lower) void cut_mesh(const indexed_triangle_set &mesh, float z, indexed_triangle_set *upper, indexed_triangle_set *lower, bool triangulate_caps)
{ {
assert(upper || lower); assert(upper || lower);
if (upper == nullptr && lower == nullptr) if (upper == nullptr && lower == nullptr)
@ -1413,10 +1417,10 @@ void cut_mesh(const indexed_triangle_set &mesh, float z, indexed_triangle_set *u
} }
if (upper != nullptr) if (upper != nullptr)
triangulate_slice(*upper, upper_lines, upper_slice_vertices, int(mesh.vertices.size()), z); triangulate_slice(*upper, upper_lines, upper_slice_vertices, int(mesh.vertices.size()), z, triangulate_caps);
if (lower != nullptr) if (lower != nullptr)
triangulate_slice(*lower, lower_lines, lower_slice_vertices, int(mesh.vertices.size()), z); triangulate_slice(*lower, lower_lines, lower_slice_vertices, int(mesh.vertices.size()), z, triangulate_caps);
} }
} }

View file

@ -76,7 +76,8 @@ void cut_mesh(
const indexed_triangle_set &mesh, const indexed_triangle_set &mesh,
float z, float z,
indexed_triangle_set *upper, indexed_triangle_set *upper,
indexed_triangle_set *lower); indexed_triangle_set *lower,
bool triangulate_caps = true);
} }