Skip to content

Commit

Permalink
FIX: Solve cracked layers of tree support under adaptive slicing
Browse files Browse the repository at this point in the history
fix bug of empty layers when meeting similar large layer height of tree support

TODO: hybrid(auto) still has dangling layers at the botttom.

Github#826

Change-Id: I6d5dfa9a610403e51ea82c1d86444f8645dc3210
(cherry picked from commit ea38988f0b5ba22c5b7c3b212d510f649dd23301)
  • Loading branch information
MusangKingBambulab authored and lanewei120 committed Dec 17, 2022
1 parent 18f794e commit 6096de0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/libslic3r/TreeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define NO_INDEX (std::numeric_limits<unsigned int>::max())

// #define SUPPORT_TREE_DEBUG_TO_SVG

namespace Slic3r
{
#define unscale_(val) ((val) * SCALING_FACTOR)
Expand Down Expand Up @@ -1398,16 +1399,13 @@ void TreeSupport::generate_toolpaths()

const size_t wall_count = object_config.tree_support_wall_count.value;
const bool with_infill = object_config.support_base_pattern != smpNone && object_config.support_base_pattern != smpDefault;
auto m_support_material_flow = support_material_flow(m_object, float(m_slicing_params.layer_height));

// coconut: use same intensity settings as SupportMaterial.cpp
auto m_support_material_interface_flow = support_material_interface_flow(m_object, float(m_slicing_params.layer_height));
coordf_t interface_spacing = object_config.support_interface_spacing.value + m_support_material_interface_flow.spacing();
coordf_t bottom_interface_spacing = object_config.support_bottom_interface_spacing.value + m_support_material_interface_flow.spacing();
coordf_t interface_density = std::min(1., m_support_material_interface_flow.spacing() / interface_spacing);
coordf_t bottom_interface_density = std::min(1., m_support_material_interface_flow.spacing() / bottom_interface_spacing);
coordf_t support_spacing = object_config.support_base_pattern_spacing.value + m_support_material_flow.spacing();
coordf_t support_density = std::min(1., m_support_material_flow.spacing() / support_spacing);

const coordf_t branch_radius = object_config.tree_support_branch_diameter.value / 2;
const coordf_t branch_radius_scaled = scale_(branch_radius);
Expand Down Expand Up @@ -1517,6 +1515,9 @@ void TreeSupport::generate_toolpaths()

TreeSupportLayer* ts_layer = m_object->get_tree_support_layer(layer_id);
Flow support_flow(support_extrusion_width, ts_layer->height, nozzle_diameter);
coordf_t support_spacing = object_config.support_base_pattern_spacing.value + support_flow.spacing();
coordf_t support_density = std::min(1., support_flow.spacing() / support_spacing);

ts_layer->support_fills.no_sort = false;

for (auto& area_group : ts_layer->area_groups) {
Expand Down Expand Up @@ -1568,12 +1569,11 @@ void TreeSupport::generate_toolpaths()
}
else {
// base_areas
filler_support->spacing = m_support_material_flow.spacing();
Flow flow = (layer_id == 0 && m_raft_layers == 0) ? m_object->print()->brim_flow() :
(m_support_params.base_fill_pattern == ipRectilinear && (layer_id % num_layers_to_change_infill_direction == 0) ? support_transition_flow(m_object) : support_flow);
if (area_group.dist_to_top < 10 / layer_height) {
// extra 2 walls for the top tips
make_perimeter_and_inner_brim(ts_layer->support_fills.entities, *m_object->print(), poly, wall_count + 2, flow, false);
filler_support->spacing = support_flow.spacing();
Flow flow = (layer_id == 0 && m_raft_layers == 0) ? m_object->print()->brim_flow() : support_flow;
if (area_group.dist_to_top < 10 / layer_height && !with_infill) {
// at least 2 walls for the top tips
make_perimeter_and_inner_brim(ts_layer->support_fills.entities, *m_object->print(), poly, std::max(wall_count, size_t(2)), flow, false);
} else {
if (with_infill && layer_id > 0 && m_support_params.base_fill_pattern != ipLightning) {
filler_support->angle = Geometry::deg2rad(object_config.support_angle.value);
Expand Down Expand Up @@ -3029,7 +3029,9 @@ std::vector<std::pair<coordf_t, coordf_t>> TreeSupport::plan_layer_heights(std::
coordf_t dist = extr2z - extr1z;

// Insert intermediate layers.
size_t n_layers_extra = size_t(ceil(dist / m_slicing_params.max_suport_layer_height));
size_t n_layers_extra = size_t(ceil(dist / (m_slicing_params.max_suport_layer_height + EPSILON)));
int actual_internel_layers = extr2_layer_nr - extr1_layer_nr - 1;
int extr_layers_left = extr2_layer_nr - extr1_layer_nr - n_layers_extra - 1;
if (n_layers_extra < 1)
continue;

Expand All @@ -3038,8 +3040,7 @@ std::vector<std::pair<coordf_t, coordf_t>> TreeSupport::plan_layer_heights(std::
assert(step >= layer_height - EPSILON);
for (int layer_nr = extr1_layer_nr + 1; layer_nr < extr2_layer_nr; layer_nr++) {
// if (curr_layer_nodes.empty()) continue;

if (std::abs(print_z - m_object->get_layer(layer_nr)->print_z) < step / 2 + EPSILON) {
if (std::abs(print_z - m_object->get_layer(layer_nr)->print_z) < step / 2 + EPSILON || extr_layers_left < 1) {
layer_heights[layer_nr].first = print_z;
layer_heights[layer_nr].second = step;
print_z += step;
Expand All @@ -3048,6 +3049,7 @@ std::vector<std::pair<coordf_t, coordf_t>> TreeSupport::plan_layer_heights(std::
// can't clear curr_layer_nodes, or the model will have empty layers
layer_heights[layer_nr].first = 0.0;
layer_heights[layer_nr].second = 0.0;
extr_layers_left--;
}
}
}
Expand Down

0 comments on commit 6096de0

Please sign in to comment.