Skip to content

Commit

Permalink
Seam: use scarf joint to minimize seam visiblity (#3839)
Browse files Browse the repository at this point in the history
* Remember z of previous layer

* Support travel to middle of the layer z

* Support sloped extrusion

* Implement sloped seam

* Reduce extra movements

* Don't clip loop if sloped seam is enabled

* Fix wipe

* Ensure `slope_max_segment_length`

* Add options

* Limit slope length to perimeter length

* Fix slope segmentation

* Rename the option to scarf joint seam

* Don't modify the slope option when turning on spiral vase

* Add a few suggestions when turnning on scarf joint

* Add option to add scarf joint to inner walls

* Apply seam gap at the end of the slope

* Add option to explicitly use the entire loop as scarf length

* Fix layer number

* Increase default scarf length to 20mm

* Better way of storing the global scarf state

* Better vase mode layer height recognition

* Move id should exclude seams

* Fix slope height with independent support layer height

* Fix linux build

* Allow controlling the scarf with modifier

* Scarf start height default to 0

* Allow enable scarf seam on contour only

* Fix type error

* Move the creation of sloped loop into ExtrusionEntity.cpp

* Fix error "vector too long"

* Detect seams properly

* The correct way of calculating the rate limit

* The correct way of calculating the rate limit

(cherry picked from commit 05961f7)

* Add pressure equalizer in print by object mode

* Remove the settings recommendation as it varies a lot depends on printer & filament

* Add a beta suffix

---------

Co-authored-by: SoftFever <softfeverever@gmail.com>
  • Loading branch information
Noisyfox and SoftFever committed Mar 2, 2024
1 parent ab1b0e0 commit 924a2b4
Show file tree
Hide file tree
Showing 16 changed files with 533 additions and 54 deletions.
109 changes: 109 additions & 0 deletions src/libslic3r/ExtrusionEntity.cpp
Expand Up @@ -340,6 +340,115 @@ double ExtrusionLoop::min_mm3_per_mm() const
return min_mm3_per_mm;
}

ExtrusionLoopSloped::ExtrusionLoopSloped(ExtrusionPaths& original_paths,
double seam_gap,
double slope_min_length,
double slope_max_segment_length,
double start_slope_ratio,
ExtrusionLoopRole role)
: ExtrusionLoop(role)
{
// create slopes
const auto add_slop = [this, slope_max_segment_length, seam_gap](const ExtrusionPath& path, const Polyline& poly,
double ratio_begin, double ratio_end) {
if (poly.empty()) {
return;
}

// Ensure `slope_max_segment_length`
Polyline detailed_poly;
{
detailed_poly.append(poly.first_point());

// Recursively split the line into half until no longer than `slope_max_segment_length`
const std::function<void(const Line&)> handle_line = [slope_max_segment_length, &detailed_poly, &handle_line](const Line& line) {
if (line.length() <= slope_max_segment_length) {
detailed_poly.append(line.b);
} else {
// Then process left half
handle_line({line.a, line.midpoint()});
// Then process right half
handle_line({line.midpoint(), line.b});
}
};

for (const auto& l : poly.lines()) {
handle_line(l);
}
}

starts.emplace_back(detailed_poly, path, ExtrusionPathSloped::Slope{ratio_begin, ratio_begin},
ExtrusionPathSloped::Slope{ratio_end, ratio_end});

if (is_approx(ratio_end, 1.) && seam_gap > 0) {
// Remove the segments that has no extrusion
const auto seg_length = detailed_poly.length();
if (seg_length > seam_gap) {
// Split the segment and remove the last `seam_gap` bit
const Polyline orig = detailed_poly;
Polyline tmp;
orig.split_at_length(seg_length - seam_gap, &detailed_poly, &tmp);

ratio_end = lerp(ratio_begin, ratio_end, (seg_length - seam_gap) / seg_length);
assert(1. - ratio_end > EPSILON);
} else {
// Remove the entire segment
detailed_poly.clear();
}
}
if (!detailed_poly.empty()) {
ends.emplace_back(detailed_poly, path, ExtrusionPathSloped::Slope{1., 1. - ratio_begin},
ExtrusionPathSloped::Slope{1., 1. - ratio_end});
}
};

double remaining_length = slope_min_length;

ExtrusionPaths::iterator path = original_paths.begin();
double start_ratio = start_slope_ratio;
for (; path != original_paths.end() && remaining_length > 0; ++path) {
const double path_len = unscale_(path->length());
if (path_len > remaining_length) {
// Split current path into slope and non-slope part
Polyline slope_path;
Polyline flat_path;
path->polyline.split_at_length(scale_(remaining_length), &slope_path, &flat_path);

add_slop(*path, slope_path, start_ratio, 1);
start_ratio = 1;

paths.emplace_back(std::move(flat_path), *path);
remaining_length = 0;
} else {
remaining_length -= path_len;
const double end_ratio = lerp(1.0, start_slope_ratio, remaining_length / slope_min_length);
add_slop(*path, path->polyline, start_ratio, end_ratio);
start_ratio = end_ratio;
}
}
assert(remaining_length <= 0);
assert(start_ratio == 1.);

// Put remaining flat paths
paths.insert(paths.end(), path, original_paths.end());
}

std::vector<const ExtrusionPath*> ExtrusionLoopSloped::get_all_paths() const {
std::vector<const ExtrusionPath*> r;
r.reserve(starts.size() + paths.size() + ends.size());
for (const auto& p : starts) {
r.push_back(&p);
}
for (const auto& p : paths) {
r.push_back(&p);
}
for (const auto& p : ends) {
r.push_back(&p);
}

return r;
}


std::string ExtrusionEntity::role_to_string(ExtrusionRole role)
{
Expand Down
52 changes: 52 additions & 0 deletions src/libslic3r/ExtrusionEntity.hpp
Expand Up @@ -301,6 +301,42 @@ class ExtrusionPath : public ExtrusionEntity
bool m_no_extrusion = false;
};

class ExtrusionPathSloped : public ExtrusionPath
{
public:
struct Slope
{
double z_ratio{1.};
double e_ratio{1.};
};

Slope slope_begin;
Slope slope_end;

ExtrusionPathSloped(const ExtrusionPath& rhs, const Slope& begin, const Slope& end)
: ExtrusionPath(rhs), slope_begin(begin), slope_end(end)
{}
ExtrusionPathSloped(ExtrusionPath&& rhs, const Slope& begin, const Slope& end)
: ExtrusionPath(std::move(rhs)), slope_begin(begin), slope_end(end)
{}
ExtrusionPathSloped(const Polyline& polyline, const ExtrusionPath& rhs, const Slope& begin, const Slope& end)
: ExtrusionPath(polyline, rhs), slope_begin(begin), slope_end(end)
{}
ExtrusionPathSloped(Polyline&& polyline, const ExtrusionPath& rhs, const Slope& begin, const Slope& end)
: ExtrusionPath(std::move(polyline), rhs), slope_begin(begin), slope_end(end)
{}

Slope interpolate(const double ratio) const
{
return {
lerp(slope_begin.z_ratio, slope_end.z_ratio, ratio),
lerp(slope_begin.e_ratio, slope_end.e_ratio, ratio),
};
}

bool is_flat() const { return is_approx(slope_begin.z_ratio, slope_end.z_ratio); }
};

class ExtrusionPathOriented : public ExtrusionPath
{
public:
Expand Down Expand Up @@ -459,6 +495,22 @@ class ExtrusionLoop : public ExtrusionEntity
ExtrusionLoopRole m_loop_role;
};

class ExtrusionLoopSloped : public ExtrusionLoop
{
public:
std::vector<ExtrusionPathSloped> starts;
std::vector<ExtrusionPathSloped> ends;

ExtrusionLoopSloped(ExtrusionPaths& original_paths,
double seam_gap,
double slope_min_length,
double slope_max_segment_length,
double start_slope_ratio,
ExtrusionLoopRole role = elrDefault);

[[nodiscard]] std::vector<const ExtrusionPath*> get_all_paths() const;
};

inline void extrusion_paths_append(ExtrusionPaths &dst, Polylines &polylines, ExtrusionRole role, double mm3_per_mm, float width, float height)
{
dst.reserve(dst.size() + polylines.size());
Expand Down

0 comments on commit 924a2b4

Please sign in to comment.