Skip to content

Commit

Permalink
too many polygons exported in the gcode file
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Dec 23, 2023
1 parent 123f4a3 commit af95a40
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,9 +1451,20 @@ void GCode::_do_export(Print& print_mod, GCodeOutputStream &file, ThumbnailsGene
if (print.config().gcode_flavor.value == gcfKlipper) {
Polygon poly = print_object->model_object()->convex_hull_2d(
print_instance.model_instance->get_matrix());
poly.douglas_peucker(0.1);
Polygon poly_old = poly;
coord_t simplify_size = scale_t(0.1);
// simplify as long as there is too many points
while (poly.size() > 20 && simplify_size < 100) {
poly_old = poly;
poly.douglas_peucker(simplify_size);
simplify_size *= 2;
}
//if gone too far, get the previous one.
if (poly.size() < 10) {
poly = poly_old;
}

const boost::format format_point("[%f,%f]");
const boost::format format_point("[%.2f,%.2f]");
std::string s_poly;
for (const Point& point : poly.points)
s_poly += (boost::format(format_point) % unscaled(point.x()) % unscaled(point.y())).str() + ",";
Expand Down

0 comments on commit af95a40

Please sign in to comment.