Skip to content

Commit

Permalink
[FEATURE] Make first layer and top flow ratio adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Jun 27, 2024
1 parent 964cd33 commit 185281f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ static std::vector<std::string> s_Preset_print_options {
"dont_support_bridges", "thick_bridges", "notes", "complete_objects", "extruder_clearance_radius",
"extruder_clearance_height", "gcode_comments", "gcode_label_objects", "output_filename_format", "post_process", "gcode_substitutions", "perimeter_extruder",
"infill_extruder", "solid_infill_extruder", "support_material_extruder", "support_material_interface_extruder",
"ooze_prevention", "standby_temperature_delta", "interface_shells", "extrusion_width", "first_layer_extrusion_width",
"ooze_prevention", "standby_temperature_delta", "interface_shells", "extrusion_width", "first_layer_extrusion_width",
"perimeter_extrusion_width", "external_perimeter_extrusion_width", "infill_extrusion_width", "solid_infill_extrusion_width",
"top_infill_extrusion_width", "support_material_extrusion_width", "infill_overlap", "infill_anchor", "infill_anchor_max", "bridge_flow_ratio",
"elefant_foot_compensation", "xy_size_compensation", "resolution", "gcode_resolution", "arc_fitting",
Expand Down Expand Up @@ -539,6 +539,8 @@ static std::vector<std::string> s_Preset_print_options {
"infill_reverse",
"internal_perimeters_reverse",

"first_layer_flow_ratio",
"top_layer_flow_ratio",
};

static std::vector<std::string> s_Preset_filament_options {
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
osteps.emplace_back(posSupportMaterial);
} else if (
opt_key == "first_layer_extrusion_width"
|| opt_key == "first_layer_flow_ratio"
|| opt_key == "top_layer_flow_ratio"
|| opt_key == "min_layer_height"
|| opt_key == "max_layer_height"
|| opt_key == "gcode_resolution") {
Expand Down
20 changes: 20 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,26 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(false));

def = this->add("first_layer_flow_ratio", coFloat);
def->label = L("First layer flow ratio");
def->category = L("Advanced");
def->tooltip = L("This factor affects the amount of plastic for first layer. "
"You can decrease it slightly (e.g. 0.85) to prevent rough first layer and sticking to the nozzle, "
"or increase a bit to improve sticking to unflat bed (though it's better to have autoleveling or flat bed).");
def->min = 0.5;
def->max = 1.5;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(1));

def = this->add("top_layer_flow_ratio", coFloat);
def->label = L("Top layer flow ratio");
def->category = L("Advanced");
def->tooltip = L("This factor affects the amount of plastic for top layer. Play with this parameter to get smooth surface.");
def->min = 0.5;
def->max = 1.5;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(1));

def = this->add("bridge_speed", coFloat);
def->label = L("Bridges");
def->category = L("Speed");
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionFloat, bridge_angle))
((ConfigOptionInt, bottom_solid_layers))
((ConfigOptionFloat, bottom_solid_min_thickness))
((ConfigOptionFloat, first_layer_flow_ratio))
((ConfigOptionFloat, top_layer_flow_ratio))
((ConfigOptionFloat, bridge_flow_ratio))
((ConfigOptionPercent, bridge_density))
((ConfigOptionFloat, bridge_speed))
Expand Down
10 changes: 8 additions & 2 deletions src/libslic3r/PrintObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ bool PrintObject::invalidate_state_by_config_options(
|| opt_key == "extra_perimeters"
|| opt_key == "extra_perimeters_on_overhangs"
|| opt_key == "first_layer_extrusion_width"
|| opt_key == "first_layer_flow_ratio"
|| opt_key == "top_layer_flow_ratio"
|| opt_key == "perimeter_extrusion_width"
|| opt_key == "infill_overlap"
|| opt_key == "external_perimeters_first"
Expand Down Expand Up @@ -822,7 +824,9 @@ bool PrintObject::invalidate_state_by_config_options(
|| opt_key == "raft_first_layer_expansion"
|| opt_key == "dont_support_bridges"
|| opt_key == "first_layer_extrusion_width"
|| opt_key == "infill_reverse") {
|| opt_key == "infill_reverse"
|| opt_key == "first_layer_flow_ratio"
|| opt_key == "top_layer_flow_ratio") {
steps.emplace_back(posSupportMaterial);
} else if (opt_key == "bottom_solid_layers") {
steps.emplace_back(posPrepareInfill);
Expand Down Expand Up @@ -855,7 +859,9 @@ bool PrintObject::invalidate_state_by_config_options(
|| opt_key == "infill_anchor"
|| opt_key == "infill_anchor_max"
|| opt_key == "top_infill_extrusion_width"
|| opt_key == "first_layer_extrusion_width") {
|| opt_key == "first_layer_extrusion_width"
|| opt_key == "first_layer_flow_ratio"
|| opt_key == "top_layer_flow_ratio") {
steps.emplace_back(posInfill);
} else if (opt_key == "fill_pattern") {
steps.emplace_back(posPrepareInfill);
Expand Down
7 changes: 5 additions & 2 deletions src/libslic3r/PrintRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ Flow PrintRegion::flow(const PrintObject &object, FlowRole role, double layer_he
{
const PrintConfig &print_config = object.print()->config();
ConfigOptionFloatOrPercent config_width;
float flow_ratio = 1;
// Get extrusion width from configuration.
// (might be an absolute value, or a percent value, or zero for auto)
if (first_layer && print_config.first_layer_extrusion_width.value > 0) {
if (first_layer) {
config_width = print_config.first_layer_extrusion_width;
flow_ratio = m_config.first_layer_flow_ratio.value;
} else if (role == frExternalPerimeter) {
config_width = m_config.external_perimeter_extrusion_width;
} else if (role == frPerimeter) {
Expand All @@ -42,6 +44,7 @@ Flow PrintRegion::flow(const PrintObject &object, FlowRole role, double layer_he
config_width = m_config.solid_infill_extrusion_width;
} else if (role == frTopSolidInfill) {
config_width = m_config.top_infill_extrusion_width;
flow_ratio = m_config.top_layer_flow_ratio.value;
} else {
throw Slic3r::InvalidArgument("Unknown role");
}
Expand All @@ -52,7 +55,7 @@ Flow PrintRegion::flow(const PrintObject &object, FlowRole role, double layer_he
// Get the configured nozzle_diameter for the extruder associated to the flow role requested.
// Here this->extruder(role) - 1 may underflow to MAX_INT, but then the get_at() will follback to zero'th element, so everything is all right.
auto nozzle_diameter = float(print_config.nozzle_diameter.get_at(this->extruder(role) - 1));
return Flow::new_from_config_width(role, config_width, nozzle_diameter, float(layer_height));
return Flow::new_from_config_width(role, config_width, nozzle_diameter, float(layer_height * flow_ratio));
}

coordf_t PrintRegion::nozzle_dmr_avg(const PrintConfig &print_config) const
Expand Down
4 changes: 3 additions & 1 deletion src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,10 +1775,12 @@ void TabPrint::build()

optgroup = page->new_optgroup(L("Overlap"));
optgroup->append_single_option_line("infill_overlap");
optgroup->append_single_option_line("bridge_density");

optgroup = page->new_optgroup(L("Flow"));
optgroup->append_single_option_line("bridge_flow_ratio");
optgroup->append_single_option_line("bridge_density");
optgroup->append_single_option_line("first_layer_flow_ratio");
optgroup->append_single_option_line("top_layer_flow_ratio");

optgroup = page->new_optgroup(L("Slicing"));
optgroup->append_single_option_line("slice_closing_radius");
Expand Down

0 comments on commit 185281f

Please sign in to comment.