Let Cancel stop a texture bake while it simplifies

Once the budget is met the progress fraction stops moving, and a cancel was only checked when it
moved, so Cancel did nothing until the flat-face merging finished. It is now also checked every 16k
steps.
This commit is contained in:
SoftFever committed 2026-09-30 19:31:54 +08:00
1 parent 7c0a3ab916
commit 36ebe0cde5
2 files changed
+32 -9

No files matched your search

@@ -2032,3 +2032,25 @@ TEST_CASE("A budget met only by flattening curvature removes detail", "[TextureD
CHECK(res.geometry.triangle_count() <= 100);
CHECK(res.target_cost_detail);
}
TEST_CASE("Cancelling while flat faces are harvested past the budget stops the decimation", "[TextureDisplacement]")
{
// 12 * 4^6 = 49152 triangles: the budget is met almost at once, and the harvest after it runs to
// a dozen triangles over several times the two polling intervals a cancel takes to be seen.
const TextureBake::TriSoup cube = TextureBake::to_soup(subdivide_mesh_uniform(its_make_cube(20., 20., 20.), 0.f, 6));
const size_t target = cube.triangle_count() - 1000;
const size_t full = TextureBake::decimate(cube, target, true, 0.005).geometry.triangle_count();
// The Cancel button pressed once the bar is full: every call after the first to report 1.0 cancels.
bool full_seen = false;
const auto cancel_when_full = [&full_seen](double f) {
if (full_seen)
return false;
full_seen = f >= 1.0;
return true;
};
const size_t canceled = TextureBake::decimate(cube, target, true, 0.005, {}, cancel_when_full).geometry.triangle_count();
CHECK(full_seen);
CHECK(canceled <= target);
CHECK(canceled > full);
}