3D printing: your friend the Slicer

Modeling your shape is only the first step of 3D printing. You need to process the resulting mesh with a slicer program that will cut your solid into thin slice and decide how to print them. The output of a slicer program is a G-code file that contain the instructions to move the printer and extrude the filament. They are multiple slicers programs available but I will only mention three that were evaluated by Reprap magazine (in no particular order):

  • Cura and Slic3r are very effective open source packages
  • KISSlicer is a commercial product, but the free version let you print single object with most of the options available.

As you can discover in the Reprap magazine, there is no one solution to the slicing problem. It’s an optimization task and each program is solving the paths differently. Each of these package offers different options to reduce problems like strings / seams on the edges and increase overall printing quality.

slicerJob

In the previous picture you can see how KISSlicer is splitting this “gear”. The path colors on the right represent the type of extrusion the printer will do. Like you want to have a lower speed and more precision for the output shell, but for the inner shells, the printer can go faster.

As I was looking at the subject I found these vase pictures from 3DPrinterGear user on KISSlicer forum where you can see that depending on the printing mode, you can end-up with a very visible seam on one side, or more like a “chicken-pox” effect  when the slicer starts each profile at a different point each time.

seamOnVase

The ‘obvious’ solution was to extrude the plastic in one path, think of it as a spiral and avoid completely the issue. I found later that Cura slicer has an option called “Joris mode” to exactly do that for single wall objects. That seems like an interesting challenge to take and see how hard it would be to build a slicer and generate some G-code to print a continuous extrusion profile. As this is only considering the outer shell profiles it’s a nice subset to experiment and develop algorithm for. So let’s dig in the slicer, algorithm!

Note: all the graph on this post are generated using Matlab. The code is available at the end of the post. The gear shape is coming from this thing on Thingiverse made by Emmett.

Slicer Step 1: Find Intersecting triangles

The first step once the tessellation is read is to find for each Z plan the section of the geometry.

gearSlice

The geometry of a STL file is a tessellation of triangles in space. So the brute force method to do it is to test if each triangle is intersecting the current plan. This is obviously not optimal and we have to weed out most of the candidates otherwise we’ll spend ages processing the file.

Let’s simplify the problem and display it in 2 dimensions (only X and Z), now for each triangle we can find the lower Z vertex and the higher Z vertex. Example in triangle A the lower is at Z=2 and the higher Z=13. Then we have to sort all the minimum and the maximum in 2 lists of increasing Z values.2dSlice

Now we can have a tool to figure out which triangles are in any Z plans in 2 steps by doing:

</code>
for currentZ = 0:N
    1/ Add any triangle from the bottom list
       with bottomZ value smaller or equal than currentZ
    2/ Remove any triangle from the top list
       with topZ value smaller than currentZ
<code> 

So for example if the plan you want to test is Z = 8.5 you will have:

  1. Add in list triangles : [C A D B]
  2. Remove from list triangle C

=> the answer is only triangle [A D B] have to be tested for the section.

For a real implementation you would keep the list from one Z plane to the next and the location in the list were your stopped the search because triangle that are already under will never be used again. Also to keep the R/W low it’s probably more efficient to use a linked list in C.

Slicer Step 2 : projection of Intersecting triangle on current plan

For each of the intersecting triangle we have to check how many vertex are already in the plan as no extra computation are required in this case.

vertexInPlan

For every remaining segment of the triangle with vertex on both side, the “segment to plan” intersection is easy to compute:

segmentProjection

And here are example of the result for the gear section. The left picture is the bottom plan of the object so all the faces are in the plan and displayed as triangles of various colors. The right picture is a plane over were all the intersecting faces are represented as segment.

sliceResult

That’s all for today, the graph are generated using this Matlab package, and all code are copyrighted, only usable for non-commercial purpose and provided as is with no guaranty of any sort! The package includes a Matlab STL reader that can open TXT and binary files.

[<<Prev. – STL Matlab Writer]    [3D Printer articles]   [TBD – Next>>]

Advertisements

4 thoughts on “3D printing: your friend the Slicer

  1. roxio

    Hi
    I interested 3d printer so i study your matlab code.
    But i can’t understand code
    how i show bottom face?
    Your blog show faces and color triangle
    How can i show this picture?

    Reply
    1. damienideas Post author

      Good day Roxio,
      if you look inside the main file (startSlicer.m), there is a loop where all the triangles are intersected with the current slice plan. When the triangle is inside the plan, its intersection is the triangle itself.
      Once all the intersection have been computed, they are displayed as point/line or triangle by this piece of code:
      %display all the intersections

      for idxObj = 1: numel(currIntersect)
      switch size(currIntersect{idxObj}, 1)

      case 3
      fill(currIntersect{idxObj}(:,1), currIntersect{idxObj}(:,2), rand(1,3));
      end
      end

      The triangle are displayed with “Fill” function.

      But remember that to see any triangle, the faces have to be in the XY plan (normal to Z) and the slice Z has to be the same as the face.

      Hope this will help you, Cheers

      Reply
      1. roxio

        Oh thanks reply
        I have a more question
        This program result is usually show cutting plan edge
        But i need face….
        So i think how can i convert code
        like cura or slic3r.
        this programs used slicer and make gcode
        Only slicing result is like this matlab code
        But use 3d printer result is full filled component
        How can is it?
        Do you nkow?
        I think gcode have a key but ican’t understand now..
        Sorry my rough english…..

        Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s