improved inner seam shifting to follow the loop correctly

This commit is contained in:
PavelMikus 2022-08-23 17:11:40 +02:00
parent c3e0ff6eda
commit 70555b85d6

View File

@ -1629,26 +1629,31 @@ void SeamPlacer::place_seam(const Layer *layer, ExtrusionLoop &loop, bool extern
//lastly, for internal perimeters, do the shifting if needed //lastly, for internal perimeters, do the shifting if needed
if (po->config().shifted_inner_seams) { if (po->config().shifted_inner_seams) {
//shifting auto get_next_loop_point = [loop](ExtrusionLoop::ClosestPathPoint current) {
//fix depth, it is sometimes strongly underestimated current.segment_idx+=1;
depth = std::max(loop.paths[projected_point.path_idx].width, (depth + 0.3f*loop.paths[projected_point.path_idx].width) * 1.2f); if (current.segment_idx >= loop.paths[current.path_idx].polyline.points.size()) {
Vec2f current_pos = unscale(seam_point).cast<float>(); current.path_idx = next_idx_modulo(current.path_idx, loop.paths.size());
Vec2f next_pos = unscale(loop.paths[projected_point.path_idx].polyline.points[projected_point.segment_idx + 1]).cast<float>(); current.segment_idx = 0;
Vec2f dir_to_next = (next_pos - current_pos).normalized();
if (dir_to_next.squaredNorm() < EPSILON) {
projected_point.segment_idx = projected_point.segment_idx + 1;
if (projected_point.segment_idx >= loop.paths[projected_point.path_idx].polyline.points.size() - 1) {
projected_point.path_idx = next_idx_modulo(projected_point.path_idx, loop.paths.size());
projected_point.segment_idx = 0;
} }
projected_point.segment_idx = next_idx_modulo(projected_point.segment_idx, current.foot_pt = loop.paths[current.path_idx].polyline.points[current.segment_idx];
loop.paths[projected_point.path_idx].size()); return current;
};
//fix depth, it is sometimes strongly underestimated
depth = std::max(loop.paths[projected_point.path_idx].width, depth);
next_pos = unscale(loop.paths[projected_point.path_idx].polyline.points[projected_point.segment_idx]).cast<float>(); while (depth > 0.0f) {
dir_to_next = (next_pos - current_pos).normalized(); auto next_point = get_next_loop_point(projected_point);
Vec2f a = unscale(projected_point.foot_pt).cast<float>();
Vec2f b = unscale(next_point.foot_pt).cast<float>();
float dist = (a - b).norm();
if (dist > depth) {
Vec2f final_pos = a + (b - a) * depth / dist;
next_point.foot_pt = Point::new_scale(final_pos.x(), final_pos.y());
}
depth -= dist;
projected_point = next_point;
} }
Vec2f shifted_pos = current_pos + depth * dir_to_next; seam_point = projected_point.foot_pt;
seam_point = Point::new_scale(shifted_pos.x(), shifted_pos.y());
} }
} }