Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cura 9790 reconfigure gradual infill #1771

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
40 changes: 25 additions & 15 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,22 +1622,29 @@ bool FffGcodeWriter::processMultiLayerInfill(const SliceDataStorage& storage, La
{
return false;
}
const coord_t infill_line_distance = mesh.settings.get<coord_t>("infill_line_distance");
const auto infill_line_distance = mesh.settings.get<coord_t>("infill_line_distance");
if (infill_line_distance <= 0)
{
return false;
}
coord_t max_resolution = mesh.settings.get<coord_t>("meshfix_maximum_resolution");
coord_t max_deviation = mesh.settings.get<coord_t>("meshfix_maximum_deviation");
AngleDegrees infill_angle = 45; // Original default. This will get updated to an element from mesh->infill_angles.
if (! mesh.infill_angles.empty())
const auto max_infill_steps = mesh.settings.get<size_t>("gradual_infill_steps");
constexpr auto getInfillAngle = [](const SliceMeshStorage& mesh, const LayerPlan& gcode_layer) -> AngleDegrees
{
const size_t combined_infill_layers = std::max(uint64_t(1), round_divide(mesh.settings.get<coord_t>("infill_sparse_thickness"), std::max(mesh.settings.get<coord_t>("layer_height"), coord_t(1))));
infill_angle = mesh.infill_angles.at((gcode_layer.getLayerNr() / combined_infill_layers) % mesh.infill_angles.size());
}
AngleDegrees infill_angle { 45. }; // Original default. This will get updated to an element from mesh->infill_angles.
if (! mesh.infill_angles.empty())
{
const auto combined_infill_layers = std::max(1UL, round_divide(mesh.settings.get<coord_t>("infill_sparse_thickness"), std::max(mesh.settings.get<coord_t>("layer_height"), 1LL)));
infill_angle = mesh.infill_angles.at((gcode_layer.getLayerNr() / combined_infill_layers) % mesh.infill_angles.size());
}
return infill_angle;
};
const AngleDegrees infill_angle = getInfillAngle(mesh, gcode_layer);

const Point3 mesh_middle = mesh.bounding_box.getMiddle();
const Point infill_origin(mesh_middle.x + mesh.settings.get<coord_t>("infill_offset_x"), mesh_middle.y + mesh.settings.get<coord_t>("infill_offset_y"));

const auto max_resolution = mesh.settings.get<coord_t>("meshfix_maximum_resolution");
const auto max_deviation = mesh.settings.get<coord_t>("meshfix_maximum_deviation");
// Print the thicker infill lines first. (double or more layer thickness, infill combined with previous layers)
bool added_something = false;
for (unsigned int combine_idx = 1; combine_idx < part.infill_area_per_combine_per_density[0].size(); combine_idx++)
Expand All @@ -1652,8 +1659,8 @@ bool FffGcodeWriter::processMultiLayerInfill(const SliceDataStorage& storage, La
std::vector<VariableWidthLines> infill_paths = part.infill_wall_toolpaths;
for (size_t density_idx = part.infill_area_per_combine_per_density.size() - 1; (int)density_idx >= 0; density_idx--)
{ // combine different density infill areas (for gradual infill)
size_t density_factor = 2 << density_idx; // == pow(2, density_idx + 1)
coord_t infill_line_distance_here = infill_line_distance * density_factor; // the highest density infill combines with the next to create a grid with density_factor 1
const int density_factor = density_idx + 1 - max_infill_steps;
coord_t infill_line_distance_here = infill_line_distance * pow(2, density_factor); // the highest density infill combines with the next to create a grid with density_factor 1
coord_t infill_shift = infill_line_distance_here / 2;
if (density_idx == part.infill_area_per_combine_per_density.size() - 1 || infill_pattern == EFillMethod::CROSS || infill_pattern == EFillMethod::CROSS_3D)
{
Expand Down Expand Up @@ -1766,6 +1773,7 @@ bool FffGcodeWriter::processSingleLayerInfill(const SliceDataStorage& storage,
const auto infill_multiplier = mesh.settings.get<size_t>("infill_multiplier");
const auto wall_line_count = mesh.settings.get<size_t>("infill_wall_line_count");
const size_t last_idx = part.infill_area_per_combine_per_density.size() - 1;
const size_t max_infill_steps = mesh.settings.get<bool>("gradual_infill") ? mesh.settings.get<size_t>("gradual_infill_steps") : 0;
const auto max_resolution = mesh.settings.get<coord_t>("meshfix_maximum_resolution");
const auto max_deviation = mesh.settings.get<coord_t>("meshfix_maximum_deviation");
AngleDegrees infill_angle = 45; // Original default. This will get updated to an element from mesh->infill_angles.
Expand Down Expand Up @@ -1813,8 +1821,9 @@ bool FffGcodeWriter::processSingleLayerInfill(const SliceDataStorage& storage,
Polygons infill_polygons_here;

// the highest density infill combines with the next to create a grid with density_factor 1
int infill_line_distance_here = infill_line_distance << (density_idx + 1);
int infill_shift = infill_line_distance_here / 2;
const int density_factor = density_idx + 1 - max_infill_steps;
coord_t infill_line_distance_here = infill_line_distance * pow(2, density_factor);
coord_t infill_shift = infill_line_distance_here / 2;

/* infill shift explanation: [>]=shift ["]=line_dist

Expand Down Expand Up @@ -2853,6 +2862,7 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
const ExtruderTrain& infill_extruder = Application::getInstance().current_slice->scene.extruders[extruder_nr];

coord_t default_support_line_distance = infill_extruder.settings.get<coord_t>("support_line_distance");
const size_t max_infill_steps = infill_extruder.settings.get<bool>("gradual_support_infill") ? infill_extruder.settings.get<size_t>("gradual_support_infill_steps") : 0;

// To improve adhesion for the "support initial layer" the first layer might have different properties
if (gcode_layer.getLayerNr() == 0)
Expand Down Expand Up @@ -2961,9 +2971,9 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
continue;
}

const unsigned int density_factor = 2 << density_idx; // == pow(2, density_idx + 1)
int support_line_distance_here = default_support_line_distance * density_factor; // the highest density infill combines with the next to create a grid with density_factor 1
const int support_shift = support_line_distance_here / 2;
const int density_factor = density_idx + 1 - max_infill_steps;
coord_t support_line_distance_here = default_support_line_distance * pow(2, density_factor); // the highest density infill combines with the next to create a grid with density_factor 1
coord_t support_shift = support_line_distance_here / 2;
if (density_idx == max_density_idx || support_pattern == EFillMethod::CROSS || support_pattern == EFillMethod::CROSS_3D)
{
support_line_distance_here /= 2;
Expand Down
2 changes: 1 addition & 1 deletion src/skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void SkinInfillAreaComputation::generateGradualInfill(SliceMeshStorage& mesh)
// make gradual_infill_step_height divisible by layer_skip_count
float n_skip_steps_per_gradual_step = std::max(1.0f, std::ceil(gradual_infill_step_layer_count / layer_skip_count)); // only decrease layer_skip_count to make it a divisor of gradual_infill_step_layer_count
layer_skip_count = gradual_infill_step_layer_count / n_skip_steps_per_gradual_step;
const size_t max_infill_steps = mesh.settings.get<size_t>("gradual_infill_steps");
const size_t max_infill_steps = mesh.settings.get<bool>("gradual_infill") ? mesh.settings.get<size_t>("gradual_infill_steps") : 0;

const LayerIndex min_layer = mesh.settings.get<size_t>("initial_bottom_layers");
const LayerIndex max_layer = mesh.layers.size() - 1 - mesh.settings.get<size_t>("top_layers");
Expand Down
2 changes: 1 addition & 1 deletion src/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void AreaSupport::generateGradualSupport(SliceDataStorage& storage)
const size_t total_layer_count = storage.print_layer_count;
const ExtruderTrain& infill_extruder = mesh_group_settings.get<ExtruderTrain&>("support_infill_extruder_nr");
const coord_t gradual_support_step_height = infill_extruder.settings.get<coord_t>("gradual_support_infill_step_height");
const size_t max_density_steps = infill_extruder.settings.get<size_t>("gradual_support_infill_steps");
const size_t max_density_steps = infill_extruder.settings.get<bool>("gradual_support_infill") ? infill_extruder.settings.get<size_t>("gradual_support_infill_steps") : 0;

const coord_t wall_count = infill_extruder.settings.get<size_t>("support_wall_count");
const coord_t wall_width = infill_extruder.settings.get<coord_t>("support_line_width");
Expand Down