Simplify flat faces even when a bake fits its budget

Nothing removed the even mesh over a texture's flat parts unless the
budget was lowered until simplification had to run. Collapses stay under
a thirty-second of the resolution: on the test map 387584 -> 369876
triangles, with the print unchanged (0.02% of the extrusion).

An earlier attempt was reverted for a 21% heavier result. That was the
colour despeckle switching itself off, not the collapsing: it keyed off
the face parent map, which any collapse empties.
This commit is contained in:
ExPikaPaka
2026-09-23 12:19:58 +02:00
parent 0a543644ef
commit 1b029ff8fa
3 changed files with 28 additions and 10 deletions
+9 -1
View File
@@ -2178,6 +2178,12 @@ indexed_triangle_set build_texture_displacement_v2(const indexed_triangle_set
BOOST_LOG_TRIVIAL(info) << "TextureBake resolution: " << settings.refine_length << " mm"
<< (auto_edge ? " (auto)" : "") << ", budget " << settings.max_triangles / 1000 << " k"
<< (auto_budget ? " (auto)" : "");
// How far a flat-face harvest may move the surface, tied to the resolution: what a bake refined to
// 1.4 mm edges can merge flat is not what one refined to 0.1 mm may touch. A thirty-second of the
// edge is well under a layer either way - at the default resolution it sheds about 5% of the
// triangles on a relief that covers the whole surface, and far more of one with flat ground in it -
// and the floor keeps a very fine resolution from spending the pass for nothing.
settings.harvest_tol = std::clamp(settings.refine_length / 32.0, 0.005, 0.05);
settings.preserve_untextured = true;
// Always on: relief driven under the plate is unprintable whichever pipeline produced it, so this
// is no longer a choice the user has to make. Only geometry that ends up below the model's own
@@ -2335,7 +2341,9 @@ indexed_triangle_set build_texture_displacement_v2(const indexed_triangle_set
// noise. A simplified mesh is neither: its triangles are as large as the colour regions
// themselves and already end on the colour boundaries, so a majority vote among three
// neighbours would repaint whole features. Bake mode (no simplification) keeps it.
const bool simplified = result.face_parent_id.empty();
// Not "did a collapse run": a flat-face harvest leaves the mesh as fine as it was, and
// reading it as simplified switched the despeckle off for every bake that harvested.
const bool simplified = result.simplified;
despeckle_triangle_colors(out, palette, simplified ? 0 : color->despeckle_passes);
merge_small_color_regions(out, palette, color->min_color_region_mm2);
for (size_t i = 0; i < out.indices.size(); ++i) {