Ultimaker / CuraEngine

Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
https://ultimaker.com/en/products/cura-software
GNU Affero General Public License v3.0
1.66k stars 874 forks source link

Fluid Motion Smoothing Fails to Smooth in Some Cases #1982

Open mfish38 opened 7 months ago

mfish38 commented 7 months ago

Application Version Cura 5.5.0

Platform Cura 5.5.0

Qt Cura 5.5.0

PyQt Cura 5.5.0

Display Driver AMD Adrenalin Edition 23.11.1

Steps to Reproduce

  1. Turn on fluid motion with shift distance of 0.1, small distance of 0.05, and angle of 15.
  2. Slice a benchy.
  3. Print using a Klipper based printer.

Actual Results There are still non-fluid motion segments remaining at the start of the bow curves that result in blobbing on the print. When I slice it there is one on layer 116 on the front right, identifiable by the gradient shading discontinuity:

image

Expected results

The current fluid motion smoothing will not process segments if the smooth distance is too large, leaving non-fluid segments. And if the smooth distance is set smaller so that the points are processed, then not all points are shifted enough as the shift amount is scaled by the smooth distance. This makes it practically impossible to set a smooth distance that will remove all non-fluid motions.

I believe the segment should be collapsed to single point, a different method of scaling the distance points are shifted, or some additional parameter added to handle this case.

Reading the smoothing source code the comment here indicates that if the outer segments are less than the shift distance the segment should be deleted: https://github.com/Ultimaker/CuraEngine/blob/0c3e9d0c492d15068f8afe9aa2743e5e068e7cbd/include/utils/actions/smooth.h#L79-L80

However, testing shows that the deletion of such line segments is never done. It looks like it should be done here but it is not: https://github.com/Ultimaker/CuraEngine/blob/0c3e9d0c492d15068f8afe9aa2743e5e068e7cbd/include/utils/actions/smooth.h#L97-L103

Additional Information Using a different G-Code viewer shows the segment in question and the coordinates around it (note that this g code was produced by Cura): Capture

Note the super small line segment veering at almost a 45 degree angle towards the outside of the wall.

Here is a transcription of the a, b, c, d points from the g code that would be used by the smoothing algorithm:

a = Point(123.275, 97.555) b = Point(122.311, 97.139) c = Point(122.306, 97.122) d = Point(121.33, 96.757)

mfish38 commented 7 months ago

My guess is that this has the potential to occur whenever shift distance is greater than 1/3 of the maximum resolution slicer setting. At a minimum, perhaps adding fluid_motion_shift_distance = min(<max resolution> / 3.0 - epsilon, fluid_motion_shift_distance) would prevent large shift distances from unexpectedly resulting in suddenly having unsmoothed segments.

Then perhaps some setting or toggle to optionally collapse segments that fail the 3x shift distance check to a point instead of limiting the shift distance.