Skip to content

Commit

Permalink
Change direction for perimeter extrusion at odd layers for overhangs.
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jul 12, 2018
1 parent 592588a commit 87245ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion xs/src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,8 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
}

// extrude all loops ccw
bool was_clockwise = loop.make_counter_clockwise();
//no! this was decided in perimeter_generator
bool was_clockwise = false;// loop.make_counter_clockwise();

SeamPosition seam_position = m_config.seam_position;
if (loop.loop_role() == elrSkirt)
Expand Down
17 changes: 10 additions & 7 deletions xs/src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ void PerimeterGenerator::process()
// We can add more perimeters if there are uncovered overhangs
// improvement for future: find a way to add perimeters only where it's needed.
// It's hard to do, so here is a simple version.
bool may_add_more_perimeters = false;
if (this->config->extra_perimeters && i > loop_number && !last.empty()
bool has_overhang = false;
if (this->config->extra_perimeters /*&& i > loop_number*/ && !last.empty()
&& this->lower_slices != NULL && !this->lower_slices->expolygons.empty()){
//split the polygons with bottom/notbottom
ExPolygons unsupported = diff_ex(last, this->lower_slices->expolygons, true);
Expand Down Expand Up @@ -199,7 +199,7 @@ void PerimeterGenerator::process()
}
if (!unsupported.empty()) {
//add fake perimeters here
may_add_more_perimeters = true;
has_overhang = true;
}
}
}
Expand Down Expand Up @@ -279,7 +279,7 @@ void PerimeterGenerator::process()
last.clear();
break;
} else if (i > loop_number) {
if (may_add_more_perimeters) {
if (has_overhang) {
loop_number++;
contours.emplace_back();
holes.emplace_back();
Expand All @@ -290,11 +290,11 @@ void PerimeterGenerator::process()
}

for (const ExPolygon &expolygon : next_onion) {
contours[i].emplace_back(PerimeterGeneratorLoop(expolygon.contour, i, true));
contours[i].emplace_back(PerimeterGeneratorLoop(expolygon.contour, i, true, has_overhang));
if (! expolygon.holes.empty()) {
holes[i].reserve(holes[i].size() + expolygon.holes.size());
for (const Polygon &hole : expolygon.holes)
holes[i].emplace_back(PerimeterGeneratorLoop(hole, i, false));
holes[i].emplace_back(PerimeterGeneratorLoop(hole, i, false, has_overhang));
}
}
last = std::move(next_onion);
Expand Down Expand Up @@ -536,7 +536,10 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_loops(

ExtrusionEntityCollection children = this->_traverse_loops(loop.children, thin_walls);
if (loop.is_contour) {
eloop.make_counter_clockwise();
if (loop.is_overhang && this->layer_id % 2 == 1)

This comment has been minimized.

Copy link
@vovodroid

vovodroid Dec 30, 2023

@supermerill

Hi, actually using term "odd layer" is wrong from user point of view. Though in code expression layer_id % 2 == 1 is used, layer numeration in GUI starts from 1, i.e. layer_id+1. Thus reversing happens on even layers, starting from layer 2.

This comment has been minimized.

Copy link
@supermerill

supermerill Jan 16, 2024

Owner

You're right, I'll change the text to 'even layer'.
Because I don't think it's a good idea to mess with the first layer.

eloop.make_clockwise();
else
eloop.make_counter_clockwise();
entities.append(children.entities);
entities.append(eloop);
} else {
Expand Down
11 changes: 8 additions & 3 deletions xs/src/libslic3r/PerimeterGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ class PerimeterGeneratorLoop {
// Is it a contour or a hole?
// Contours are CCW oriented, holes are CW oriented.
bool is_contour;
//overhang may need to be reversed
bool is_overhang;
// Depth in the hierarchy. External perimeter has depth = 0. An external perimeter could be both a contour and a hole.
unsigned short depth;
// Children contour, may be both CCW and CW oriented (outer contours or holes).
std::vector<PerimeterGeneratorLoop> children;

PerimeterGeneratorLoop(Polygon polygon, unsigned short depth, bool is_contour) :
polygon(polygon), is_contour(is_contour), depth(depth) {}


PerimeterGeneratorLoop(Polygon polygon, unsigned short depth, bool is_contour) :
polygon(polygon), is_contour(is_contour), depth(depth), is_overhang(false) {}
PerimeterGeneratorLoop(Polygon polygon, unsigned short depth, bool is_contour, bool is_overhang) :
polygon(polygon), is_contour(is_contour), depth(depth), is_overhang(is_overhang) {}
// External perimeter. It may be CCW or CW oriented (outer contour or hole contour).
bool is_external() const { return this->depth == 0; }
// An island, which may have holes, but it does not have another internal island.
Expand Down

0 comments on commit 87245ae

Please sign in to comment.