From 4028cd2a1b7d7eb33c8e2be38b84069fd633abd1 Mon Sep 17 00:00:00 2001 From: remi durand Date: Tue, 15 Jun 2021 00:06:59 +0200 Subject: [PATCH] add first_layer_size_compensation_layers rewrote from bitblaster (Roberto Mozzicato) pr see prusa3d/PrusaSlicer#6569 --- resources/ui_layout/print.ui | 3 +++ src/libslic3r/Preset.cpp | 1 + src/libslic3r/PrintConfig.cpp | 14 ++++++++++++++ src/libslic3r/PrintConfig.hpp | 2 ++ src/libslic3r/PrintObject.cpp | 11 ++++++++--- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/resources/ui_layout/print.ui b/resources/ui_layout/print.ui index b430e7bd3..ac2b23796 100644 --- a/resources/ui_layout/print.ui +++ b/resources/ui_layout/print.ui @@ -92,7 +92,10 @@ group:Modifying slices line:XY compensation setting:width$6:xy_size_compensation setting:width$6:xy_inner_size_compensation + end_line + line:XY First layer compensation setting:width$6:first_layer_size_compensation + setting:width$6:first_layer_size_compensation_layers end_line line:Vertical Hole shrinking compensation setting:width$6:hole_size_compensation diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 7433980dc..90d2d5b3d 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -562,6 +562,7 @@ const std::vector& Preset::print_options() "first_layer_flow_ratio", "clip_multipart_objects", "enforce_full_fill_volume", "external_infill_margin", "bridged_infill_margin", "first_layer_size_compensation", + "first_layer_size_compensation_layers", "xy_size_compensation", "xy_inner_size_compensation", "hole_size_compensation", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 00ec13c21..fd05cdd98 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1704,6 +1704,19 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(0)); + def = this->add("first_layer_size_compensation_layers", coInt); + def->label = L("height in layers"); + def->full_label = L("XY First layer compensation height in layers"); + def->category = OptionCategory::slicing; + def->tooltip = L("The number of layers on which the elephant foot compensation will be active. " + "The first layer will be shrunk by the elephant foot compensation value, then " + "the next layers will be gradually shrunk less, up to the layer indicated by this value."); + def->sidetext = L("layers"); + def->min = 1; + def->max = 30; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionInt(1)); + def = this->add("fill_smooth_width", coFloatOrPercent); def->label = L("Width"); def->full_label = L("Ironing width"); @@ -5517,6 +5530,7 @@ void PrintConfigDef::to_prusa(t_config_option_key& opt_key, std::string& value, "start_gcode_manual", "perimeter_round_corners", "travel_speed_z", +"first_layer_size_compensation_layers", }; //looks if it's to be removed, or have to be transformed if (to_remove_keys.find(opt_key) != to_remove_keys.end()) { diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 10a7ec623..e4b8cb6b3 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -623,6 +623,7 @@ public: ConfigOptionFloatOrPercent first_layer_height; ConfigOptionFloatOrPercent first_layer_extrusion_width; ConfigOptionFloat first_layer_size_compensation; + ConfigOptionInt first_layer_size_compensation_layers; ConfigOptionFloat hole_size_compensation; ConfigOptionFloat hole_size_threshold; ConfigOptionBool infill_only_where_needed; @@ -693,6 +694,7 @@ protected: OPT_PTR(first_layer_height); OPT_PTR(first_layer_extrusion_width); OPT_PTR(first_layer_size_compensation); + OPT_PTR(first_layer_size_compensation_layers); OPT_PTR(infill_only_where_needed); OPT_PTR(interface_shells); OPT_PTR(layer_height); diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 6acaf5e86..426f91425 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -707,6 +707,7 @@ namespace Slic3r { || opt_key == "slice_closing_radius" || opt_key == "clip_multipart_objects" || opt_key == "first_layer_size_compensation" + || opt_key == "first_layer_size_compensation_layers" || opt_key == "elephant_foot_min_width" || opt_key == "support_material_contact_distance_type" || opt_key == "support_material_contact_distance_top" @@ -2491,9 +2492,13 @@ namespace Slic3r { float hole_delta = inner_delta + float(scale_(m_config.hole_size_compensation.value)); //FIXME only apply the compensation if no raft is enabled. float first_layer_compensation = 0.f; - if (layer_id == 0 && m_config.raft_layers == 0 && m_config.first_layer_size_compensation.value != 0) { + int first_layers = m_config.first_layer_size_compensation_layers.value; + if (layer_id < first_layers && m_config.raft_layers == 0 && m_config.first_layer_size_compensation.value != 0) { // Only enable Elephant foot compensation if printing directly on the print bed. first_layer_compensation = float(scale_(m_config.first_layer_size_compensation.value)); + // reduce first_layer_compensation for every layer over the first one. + first_layer_compensation = (first_layers - layer_id + 1) * first_layer_compensation / float(first_layers); + // simplify compensations if possible if (first_layer_compensation > 0) { outter_delta += first_layer_compensation; inner_delta += first_layer_compensation; @@ -2528,7 +2533,7 @@ namespace Slic3r { expolygons = _shrink_contour_holes(std::max(0.f, outter_delta), std::max(0.f, inner_delta), std::max(0.f, hole_delta), expolygons); } // Apply the elephant foot compensation. - if (layer_id == 0 && first_layer_compensation != 0.f) { + if (layer_id < first_layers && first_layer_compensation != 0.f) { expolygons = union_ex(Slic3r::elephant_foot_compensation(expolygons, layerm->flow(frExternalPerimeter), unscale(-first_layer_compensation))); } @@ -2582,7 +2587,7 @@ namespace Slic3r { // Apply the negative XY compensation. (the ones that is <0) ExPolygons trimming; static const float eps = float(scale_(m_config.slice_closing_radius.value) * 1.5); - if (layer_id == 0 && first_layer_compensation < 0.f) { + if (layer_id < first_layers && first_layer_compensation < 0.f) { ExPolygons expolygons_first_layer = offset_ex(layer->merged(eps), -eps); trimming = Slic3r::elephant_foot_compensation(expolygons_first_layer, layer->regions().front()->flow(frExternalPerimeter), unscale(-first_layer_compensation));