diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 5a486776c..087d3fe3c 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -434,17 +434,34 @@ void PrintObject::generate_support_material() std::unique_ptr PrintObject::prepare_adaptive_infill_data() { - const ConfigOptionPercent* opt_fill_density = this->print()->full_print_config().option("fill_density"); - const ConfigOptionFloatOrPercent* opt_infill_extrusion_width = this->print()->full_print_config().option("infill_extrusion_width"); + float fill_density = 0; + float infill_extrusion_width = 0; - if(opt_fill_density == nullptr || opt_infill_extrusion_width == nullptr || opt_fill_density->value <= 0 || opt_infill_extrusion_width->value <= 0) + // Compute the average of above parameters over all layers + for (size_t layer_idx = 0; layer_idx < this->m_layers.size(); ++layer_idx) + { + for (size_t region_id = 0; region_id < this->m_layers[layer_idx]->m_regions.size(); ++region_id) + { + LayerRegion *layerm = this->m_layers[layer_idx]->m_regions[region_id]; + + // Check if region_id is used for this layer + if(!layerm->fill_surfaces.surfaces.empty()) { + const PrintRegionConfig ®ion_config = layerm->region()->config(); + + fill_density += region_config.fill_density; + infill_extrusion_width += region_config.infill_extrusion_width; + } + } + } + + fill_density /= this->m_layers.size(); + infill_extrusion_width /= this->m_layers.size(); + + if(fill_density <= 0 || infill_extrusion_width <= 0) { return std::unique_ptr{}; } - float fill_density = opt_fill_density->value; - float infill_extrusion_width = opt_infill_extrusion_width->value; - coordf_t line_spacing = infill_extrusion_width / ((fill_density / 100.0f) * 0.333333333f); TriangleMesh mesh = this->model_object()->raw_mesh();