From a837652833d681ff2bb41c1cabe907378de3aad3 Mon Sep 17 00:00:00 2001 From: fa1k3 <268878418+fa1k3@users.noreply.github.com> Date: Mon, 2 Nov 2026 07:34:32 +0100 Subject: [PATCH] Apply the Z shrinkage compensation once to the belt height (#16490) On a belt printer the slicing height comes from the box of the mesh under trafo_centered(), which already carries the shrinkage compensation, and SlicingParameters::create_from_config() scaled it by the Z compensation again. With a Z shrinkage above 100 % the top of the part was not sliced. The belt build height check now also compares the compensated height when the object is too tall, so an object that only fits after the compensation is no longer refused. Co-authored-by: SoftFever --- src/libslic3r/Print.cpp | 2 +- src/libslic3r/PrintObject.cpp | 9 ++++--- tests/fff_print/test_print.cpp | 46 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 956b022bb5..4852aa51ba 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2434,7 +2434,7 @@ StringObjectException Print::validate(std::vector *warnin print_object.model_object(), "" }; - } else if (effective_max_z > this->config().printable_height + EPSILON) { + } else if (compensated_max_z > this->config().printable_height + EPSILON) { return StringObjectException{ last_layer_below_max ? Slic3r::format(_u8L("While the object %1% itself fits the build volume, its last layer exceeds the maximum build volume height."), print_object.model_object()->name) + diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 634d2ed291..2d6d200ef1 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -4467,6 +4467,7 @@ void PrintObject::update_slicing_parameters() coordf_t object_height = this->model_object()->max_z(); BeltTransformPipeline::BeltFloorParams belt_floor; const auto &pcfg = this->print()->config(); + const Vec3d shrinkage_compensation = this->print()->shrinkage_compensation(); if (pcfg.belt_printer.value) { // The box of the mesh in the frame it is sliced in: XY centred and Z as // placed on the bed (trafo_centered()). raw_bounding_box() has the @@ -4479,12 +4480,14 @@ void PrintObject::update_slicing_parameters() for (const ModelVolume *v : this->model_object()->volumes) if (v->is_model_part()) bb.merge(v->mesh().transformed_bounding_box(trafo * v->get_matrix())); - auto hr = BeltTransformPipeline::compute_belt_height_and_floor(pcfg, bb, object_height); - object_height = hr.object_height; + // trafo() already carries the shrinkage compensation, so the belt height is + // compensated, while create_from_config() expects object_height without it. + auto hr = BeltTransformPipeline::compute_belt_height_and_floor(pcfg, bb, object_height * shrinkage_compensation.z()); + object_height = hr.object_height / shrinkage_compensation.z(); belt_floor = hr.floor_params; } m_slicing_params = SlicingParameters::create_from_config(pcfg, m_config, object_height, - this->object_extruders(), this->print()->shrinkage_compensation()); + this->object_extruders(), shrinkage_compensation); // Populate belt floor parameters into slicing params for support clipping. m_slicing_params.belt_floor_shear_factor = belt_floor.shear_factor; m_slicing_params.belt_floor_from_axis = belt_floor.from_axis; diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index e87a698720..b4b97f560b 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -2312,3 +2312,49 @@ TEST_CASE("Objects on extruders with different layer height limits can share a p INFO(error.string); CHECK(error.string.empty()); } + +TEST_CASE("Belt printers apply the Z shrinkage compensation to the slicing height once", "[Print][belt][Regression]") +{ + // A 20 mm cube printed with a filament that shrinks to xy % / z % is sliced like an uncompensated box + // 20 * 100 / xy wide and 20 * 100 / z tall. The span of the layers is compared, as the belt Z offset + // depends on where the object is centred. + const auto [xy, z, angle] = GENERATE(table({ { 100., 95., 45. }, { 100., 105., 45. }, { 90., 95., 45. }, { 100., 105., 0. } })); + const auto sliced_height = [](const TriangleMesh &mesh, double xy, double z, double angle) { + DynamicPrintConfig config = belt_test_config(); + config.set_deserialize_strict({ { "filament_shrink", xy }, { "filament_shrinkage_compensation_z", z }, { "belt_slice_rotation_angle", angle } }); + Print print; + init_and_process_print({ mesh }, print, config); + const PrintObject &object = *print.objects().front(); + return std::make_pair(object.slicing_parameters().object_print_z_max, + object.layers().back()->print_z - object.layers().front()->print_z); + }; + + const auto [compensated_max_z, compensated_span] = sliced_height(cube(20.), xy, z, angle); + const auto [expected_max_z, expected_span] = sliced_height(make_cube(20. * 100. / xy, 20. * 100. / xy, 20. * 100. / z), 100., 100., angle); + CHECK_THAT(compensated_max_z, Catch::Matchers::WithinAbs(expected_max_z, EPSILON)); + CHECK_THAT(compensated_span, Catch::Matchers::WithinAbs(expected_span, 0.2 * 100. / z)); +} + +TEST_CASE("The belt build height check uses the compensated height", "[Print][belt][validate][Regression]") +{ + // printable_height is 100 mm. Z shrinkage 105 % prints 101 mm at about 96.2 mm, which fits, and 106 mm at + // about 101 mm, which does not; with 95 % a 97 mm object only becomes too tall through the compensation. + const auto [z, height, expected] = GENERATE(table({ + { 105., 101., "" }, + { 105., 106., "exceeds the maximum build volume height." }, + { 95., 92., "" }, + { 95., 97., "because of material shrinkage compensation" }, + })); + DynamicPrintConfig config = belt_test_config(); + config.set_deserialize_strict({ { "printable_height", 100. }, { "filament_shrinkage_compensation_z", z } }); + + Print print; + Model model; + init_print({ make_cube(20., 20., height) }, print, model, config); + const std::string error = print.validate().string; + INFO(error); + if (expected.empty()) + CHECK(error.empty()); + else + CHECK(error.find(expected) != std::string::npos); +}