diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 28d2ea324e..01a3f9f43f 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -907,7 +907,7 @@ StringObjectException Print::sequential_print_clearance_valid(const Print &print // Place of the instance in print.model()'s object and instance lists. Copies of one object get // one PrintObject per distinct transformation, so print.objects() does not list them in order. std::pair model_position; - double height; // top above the bed, raft included (object_top below) + double height; // top above the bed, raft included (PrintObject::print_z_max) // Whether the instance reaches above extruder_clearance_height_to_rod, and the Y extent of it // the rod can hit while a later instance prints (see above_rod_y_range). bool has_above_rod = false; @@ -928,17 +928,9 @@ StringObjectException Print::sequential_print_clearance_valid(const Print &print } const bool skirt_reaches_rod = print.has_infinite_skirt() || (print.config().skirt_loops > 0 && print.config().skirt_height * max_layer_height > rod_height); - // Top of an instance above the bed, scaled. object_print_z_max includes the raft and the Z shrinkage - // compensation, like the printable-height check in validate(). On a belt printer it is the height in the - // tilted slicing frame, so there the model's own top is used, as that check does; a raft is refused there. - const bool belt_printer = print.config().belt_printer.value; - auto object_top = [belt_printer](const PrintInstance &instance) -> double { - return belt_printer ? instance.print_object->max_z() - : scale_(instance.print_object->slicing_parameters().object_print_z_max); - }; - auto above_rod_y_range = [rod_height, &object_top](const PrintInstance &instance, coord_t &min_y, coord_t &max_y) -> bool { + auto above_rod_y_range = [rod_height](const PrintInstance &instance, coord_t &min_y, coord_t &max_y) -> bool { // Skip the mesh walk for the common case of an object whose top, raft included, doesn't reach the rod. - if (object_top(instance) <= scale_(rod_height)) + if (instance.print_object->print_z_max() <= scale_(rod_height)) return false; // Mesh Z this far below the rod prints above it once the raft lifts the object. const double rod_z = rod_height - instance.print_object->slicing_parameters().object_print_z_min; @@ -1074,7 +1066,7 @@ StringObjectException Print::sequential_print_clearance_valid(const Print &print } } struct print_instance_info print_info {&instance, convex_hull.bounding_box(), convex_hull}; - print_info.height = object_top(instance); + print_info.height = instance.print_object->print_z_max(); print_info.model_position = model_position_of(print.model(), instance.model_instance); print_info.has_above_rod = above_rod_y_range(instance, print_info.rod_min_y, print_info.rod_max_y); const BoundingBox footprint = print_info.bounding_box.inflated(-scale_(0.5 * print.config().extruder_clearance_radius.value + object_skirt_offset)); @@ -1534,7 +1526,7 @@ StringObjectException Print::compacted_wipe_tower_clearance_valid(const Print &p Polygons offenders; bool body_tier_used = false; for (const PrintObject *object : print.objects()) { - const double object_top = unscaled(object->max_z()); + const double object_top = unscaled(object->print_z_max()); for (const PrintInstance &instance : object->instances()) { const Polygon inst_hull = compacted_tower_print_instance_hull(*object, instance); if (inst_hull.points.empty()) @@ -1648,7 +1640,7 @@ void Print::validate_compacted_wipe_tower_clearance() const return; for (const PrintObject *object : m_objects) { - const double object_top = unscaled(object->max_z()); + const double object_top = unscaled(object->print_z_max()); for (const PrintInstance &instance : object->instances()) { const Polygon inst_hull = compacted_tower_print_instance_hull(*object, instance); if (inst_hull.points.empty()) diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 38627daeea..be4fe4df33 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -405,6 +405,10 @@ public: // The height is snug. coord_t height() const { return m_size.z(); } double max_z() const { return m_max_z; } + // Top of the printed object above the bed, scaled: object_print_z_max of the slicing parameters, so the + // raft and the Z shrinkage compensation count, as in the printable-height check of Print::validate(). + // On a belt printer that is the height in the tilted slicing frame, so the model's own top is used there. + double print_z_max() const; // Centering offset of the sliced mesh from the scaled and rotated mesh of the model. const Point& center_offset() const { return m_center_offset; } const AdaptiveInfillField* adaptive_infill_field(AdaptiveInfillMode mode) const { return m_adaptive_infill_fields[size_t(mode)].get(); } @@ -1398,7 +1402,7 @@ public: static int get_compatible_filament_type(const std::set& types); bool is_all_objects_are_short() const { - return std::all_of(this->objects().begin(), this->objects().end(), [&](PrintObject* obj) { return obj->height() < scale_(this->config().nozzle_height.value); }); + return std::all_of(this->objects().begin(), this->objects().end(), [&](PrintObject* obj) { return obj->print_z_max() < scale_(this->config().nozzle_height.value); }); } // Post-slicing config-slot resolvers: map a (filament, layer) pair to the index of its diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 81001c06cb..40bdb6a2d2 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -4478,6 +4478,11 @@ void PrintObject::generate_support_preview() profiler.duration2 = (ts3 - ts2).total_milliseconds(); } +double PrintObject::print_z_max() const +{ + return this->print()->config().belt_printer.value ? m_max_z : scale_(m_slicing_params.object_print_z_max); +} + void PrintObject::update_slicing_parameters() { // Orca: updated function call for XYZ shrinkage compensation diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index cb5f27c0b6..d7a064ad88 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -1888,6 +1888,43 @@ TEST_CASE("Sequential printing counts a raft toward the height checked against t CHECK(error.find("too tall") != std::string::npos); } +TEST_CASE("Sequential printing counts a raft toward whether an object is short", "[Print]") +{ + // Objects below nozzle_height only need to clear the nozzle cone, so they may stand close together, + // and their skirt is kept at its full distance. A raft lifts a 2 mm slab past the 2.5 mm nozzle_height, + // so the slabs need the toolhead radius between them and the skirt offset of a tall object. + const bool raft = GENERATE(false, true); + std::vector meshes; + for (size_t i = 0; i < 2; ++i) { + TriangleMesh slab = make_cube(20, 20, 2); + slab.translate(float(80 + 30 * i), 80.f, 0.f); // 10 mm apart, within the 40 mm toolhead radius + meshes.push_back(std::move(slab)); + } + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.set_deserialize_strict({ + { "print_sequence", "by object" }, + { "nozzle_height", 2.5 }, + { "extruder_clearance_radius", 40 }, + { "skirt_loops", 1 }, + { "skirt_type", "perobject" }, + { "raft_layers", raft ? 3 : 0 }, + { "layer_change_gcode", "G92 E0\n" } // validate() relative-E reset + }); + Print print; + Model model; + Test::init_print(std::move(meshes), print, model, config, nullptr, /*arrange=*/false); + REQUIRE((2. + print.objects().front()->slicing_parameters().object_print_z_min > 2.5) == raft); + + CHECK(print.is_all_objects_are_short() == ! raft); + CHECK((std::get<0>(print.object_skirt_offset()) > 0.f) == ! raft); + const std::string error = print.validate().string; + INFO(error); + if (raft) + CHECK(error.find("too close to others") != std::string::npos); + else + CHECK(error.empty()); +} + TEST_CASE("Sequential printing measures objects on a belt printer by the model's top", "[Print][belt]") { // On a belt printer object_print_z_max is the height in the tilted slicing frame: at 45 degrees a 30 mm @@ -3217,6 +3254,39 @@ TEST_CASE("No sparse layers still refuses an object that rises past the lid clea REQUIRE_THROWS_WITH(print.process(), Catch::Matchers::ContainsSubstring("No sparse layers")); } +// Only the layers below an object's top count toward its rise above the compacted tower, and a raft lifts that +// top. The 20 mm cube shares the tower's Y band and may rise 20 mm above it. The tower starts on the first layer +// above 19.6 mm, where the taller object's second part changes filament, and keeps pace from there, so without a +// raft the cube rises 19.6 mm at most. The raft lifts the cube's top with every layer, and it is refused. +TEST_CASE("No sparse layers counts a raft toward an object's rise above the compacted tower", "[Print][PrimeTower]") +{ + const bool raft = GENERATE(false, true); + Model model; + add_object(model, make_cube(20., 20., 20.), 20., 140.); + ModelObject *tall = add_object(model, make_cube(20., 20., 19.6), 60., 20.); + TriangleMesh upper = make_cube(20., 20., 20.4); + upper.translate(0.f, 0.f, 19.6f); + tall->add_volume(std::move(upper))->config.set_key_value("extruder", new ConfigOptionInt(2)); + Print print; + print.apply(model, prime_tower_config({ + { "wipe_tower_no_sparse_layers", 1 }, + { "wipe_tower_x", 120 }, // with its rib wall the tower is over 40 mm across + { "wipe_tower_y", 140 }, + { "extruder_clearance_height_to_lid", 30 }, // the taller cube, away from the rod's band, rises as much + { "extruder_clearance_height_to_rod", 20 }, + { "raft_layers", raft ? 3 : 0 }, + })); + REQUIRE((print.objects().front()->slicing_parameters().object_print_z_min > 0.4) == raft); + + const std::string error = print.validate().string; + INFO(error); + CHECK(error.empty()); + if (raft) + REQUIRE_THROWS_WITH(print.process(), Catch::Matchers::ContainsSubstring("No sparse layers")); + else + REQUIRE_NOTHROW(print.process()); +} + // Within the toolhead radius of the tower the head body limits an object to nozzle_height, however tall the tower // grows, so validate() refuses it before slicing. TEST_CASE("No sparse layers refuses before slicing an object that rises within the toolhead radius of the tower", "[Print][PrimeTower]") @@ -3231,6 +3301,31 @@ TEST_CASE("No sparse layers refuses before slicing an object that rises within t CHECK_THAT(print.validate().string, Catch::Matchers::ContainsSubstring("No sparse layers")); } +// The head body passes over an object that stays below nozzle_height however close to the tower it stands. A +// raft lifts a 2 mm slab past the 2.5 mm nozzle_height, so the same slab within the toolhead radius is refused +// before slicing once it stands on one. +TEST_CASE("No sparse layers counts a raft toward whether an object near the tower is short", "[Print][PrimeTower]") +{ + const bool raft = GENERATE(false, true); + Model model; + add_object(model, make_cube(10., 10., 2.), 140., 140.); // 10 mm from the tower in X and in Y + add_object(model, make_cube(20., 20., 10.), 20., 20.)->config.set_key_value("extruder", new ConfigOptionInt(2)); + Print print; + print.apply(model, prime_tower_config({ + { "wipe_tower_no_sparse_layers", 1 }, + { "nozzle_height", 2.5 }, + { "raft_layers", raft ? 3 : 0 }, + })); + REQUIRE((2. + print.objects().front()->slicing_parameters().object_print_z_min > 2.5) == raft); + + const std::string error = print.validate().string; + INFO(error); + if (raft) + CHECK(error.find("No sparse layers") != std::string::npos); + else + CHECK(error.empty()); +} + TEST_CASE("An object takes the layer height limits of the extruder of its own filament", "[Print]") { CHECK_THAT(slicing_parameters_on_filament(1).max_layer_height, Catch::Matchers::WithinAbs(0.32, EPSILON));