Slicing and G Code: The Bridge Between 3D Model and 3D Printer
There’s still one more step before your 3D printer can cast the zero-to-everything magic: Slicing the 3D model.
To elaborate on the concept of Slicing, let’s first have a brief look at the rough process of 3D printing.
As you can see, obtaining the 3D model is just the end of Step ①. For your 3D printer to start printing, you need to import the 3D model into the slicing software (hereafter slicer) and send the slicing outcome — G Code — to the 3D printer.
So far, you might have wondered a lot: Why is slicing necessary? How does it work? And what is G Code exactly? Keep reading, and answers are on the way!
What is Slicing
Essentially, slicing is a translating process.
The 3D printing model we obtained in Step ① is a three-dimensional graphic file (such as the STL file). Such files contain geometric information, which is composed of triangular faces used to represent the contour shape of the object.
However, your 3D printer is a mechanical device, of which the operation requires instruction information on How To Do, rather than geometric information describing What It Is. Therefore, a problem arises: the 3D printer cannot read and understand the geometric information in the model file, and the model file itself does not store instruction information. In this way, there is an information gap between the 3D printing model and the 3D printer.
Slicing is the bridge over this gap.
The role it plays is to “translate” the geometric information in the 3D model file into instruction information that can be read and understood by the 3D printer. In addition to the original geometric data, you can also add more auxiliary information (such as adjusting the temperature of the heated bed or nozzle, adding supports, etc.) through the slicer, so that the 3D printer can better build the model.
We can compare this slicing process to cooking to better explain their relationship.
With only a picture of a dish (3D model file), no matter how skilled a chef (3D printer) is, it is almost impossible to perfectly restore the taste of the dish in the picture. But if you make a corresponding recipe (generating G Code by slicing), describe in detail all the ingredients, the amount of each, the cooking sequence of this dish, and the special technique for each cooking step, the problem will be solved.
In addition, if you have some knowledge of the computer numerical control, the relationship among 3D printing models, slicing software, and G Code can also be compared with reference to that among Computer Aided Design (CAD), Computer Aided Manufacturing (CAM), and Computer Numerical Control (CNC).
How Slicing Works
After roughly explaining the role of slicing, we can take the example of Cura, one of the most powerful slicers, to briefly introduce the working mechanism behind slicing (otherwise known as the Engine), and several key concepts involved.
CuraEngine mainly goes through the following five steps when slicing a 3D model file.
Optimizing the 3D model
When you import the 3D model into Cura, it will be optimized according to Cura’s OptimizedModel.
As mentioned above, the geometric information of the 3D model file is actually a description of the shape and position of the triangles that make up the model. Therefore, the optimization of CuraEngine is to analyze, establish, and store the relationship between these triangular faces, which is officially called the vertex-face relation. Put more clearly, it analyzes which triangles are adjacent.
For example, suppose you are required to memorize a set of numbers: 8, 10, 12, 20, 25, 30. You can choose to simply memorize it, or you can memorize it based on their relationship: 8, 10, and 12 are respectively four times, five times, and six times as much as 2; 20, 25, and 30 are respectively four times, five times, and six times as much as 5.
It’s easier to memorize, right? Cura thinks so.
Optimizing the model and establishing the adjacent relation among the triangular facets are the key prerequisites for Cura to quickly slice models and build Layerparts.
Slicing 3D model into 2D layers
The main task of CuraEngine in this step is to cross-cut the 3D model into 2D planes (imagine how you slice the cheese).
Combined with the mechanical structure of the 3D printer, it can be understood as the 3D model is cut layer by layer with a certain Z axis height (layer height) by a 2D plane formed by the X axis and the Y axis. When the 2D plane intersects with the triangular faces that make up the 3D model, the corresponding intersecting lines will be obtained.
The target of slicing is to get 2D graphics on 2D planes for the printer to print layer by layer. However, the cross-cutting result is just a bunch of lines. How do we know which lines form a closed 2D graphic?
Here comes the adjacent relation of the triangular faces established in Optimizing the Model.
If two triangular faces (like A and B) are adjacent and both of them intersect with the same X-Y plane, the intersecting lines (like the red line and the blue line) generated must also be adjacent, which means they can form a closed 2D graphic with other adjacent lines.
Therefore, CuraEngine can quickly identify separate closed 2D graphics. At this point, the 3D model is sliced into 2D layers, and each layer consists of one or more closed 2D graphics.
In the last step, we’ve got closed 2D graphics on 2D layers. However, the number of graphics in each layer is not necessarily the same. Separate 2D graphics on a single layer are called LayerParts, which is an essential concept in CuraEngine.
Quoting an official example of CuraEngine, If you slice a table with four legs, Layer ② has four LayerParts, while Layer ① has only one LayerPart.
In this step, CuraEngine defines separate closed 2D graphics as different LayerParts. In this way, the G Code will be complied in units of LayerPart, removing the redundant information outside the Layerparts as much as possible to improve the printing efficiency.
After building LayerParts, CuraEngine marks areas of the LayerPart as Insets, Up/Down Skins Areas, or Sparse Infill Areas and plans respective printing modes.
For the same LayerPart, the outer line area will be marked as Insets, and the area inside the line will be marked as Up/Down Skins Areas or Sparse Infill Areas. As for the specific parameters (such as outline thickness, infill density, pattern, etc.), you can set them separately in Cura. It should be noted that this step is only to mark different areas and plan corresponding printing modes, but not actual paths. When the G code is compiled in the next step, specific printing paths will be generated in different areas.
Generating the G Code
In this step, CuraEngine will collect the geometry and parameter information involved in all the previous steps, and then compile it into G Code to guide the 3D printer to print out the target model.
As shown below, Cura’s official document lists some important bits during this process:
1. PathOrderOptimizer: As the name implies, the nozzle will select the nearest LayerPart to print when it moves to enhance efficiency.
2. Infill: Print in the form of lines.
3. Comb: To avoid stringing, the nozzle will try not to move without printing if there’s another path to go.
4. GCodeExport: The G Code generating process is divided into two steps. First, collect and summarize all the path information of each layer; second, compile and generate the G Code.
How to Read G Code
As the outcome of slicing, G Code instructs 3D printers to print. Because of its nature as a special programming language, G Code can be as readable as Java or Python. As long as you grasp the basic syntax, it’s not difficult to judge the meaning of different G commands.
G Code can be divided into two types: G-code and M-code.
G-code (General code) focuses on geometric information, mainly describing instructions like guiding the 3D printer on moving. Seen from the naming, it is obvious that the G-code is the core of G Code (sounds like a tongue-twister).
M-code (Miscellaneous code) is a non-geometric command used to specify non-geometric parameters such as the heated bed temperature or the fan activation status.
The number immediately following the letter G or M indicates different actions. For example, G0 instructs the printing module to move quickly, and G28 instructs the printing module back to the home position.
The remaining parameters generally consist of one or more alphanumeric combinations. Letters usually indicate the object that performs the action, while numbers indicate specific parameters of the action. For instance, the G0 X5 Y20 command instructs the printing module to quickly move to the position where the coordinate is (5, 20) by the movement of the X axis and Y axis. However, not every G command has specific parameters. For example, M84 simply means to disable the motor, in which case no other parameters need to be added later.
For the meanings of more letters, please refer to the explanation on Wikipedia.
It’s worth noting that 3D printers with different core firmware may have different understandings of the same G command, and therefore perform different actions. For this situation, there are three solutions for reference:
- Try to choose the exclusive slicer for your 3D printer if any. For example, Snapmaker Luban is a tailor-made slicer for Snapmaker 3D printers, which will generate the most suitable G commands according to the firmware type of the Snapmaker 3D printer.
- If you have to use other slicers, try to find your printer model in the printer settings of the slicer. For example, you can select Snapmaker on the printer list of Cura.
- If your printer is not on the list, you can add/create a new printer setting in the slicer and select the correct firmware type. For example, the core firmware used by the Snapmaker 3D printer is Marlin.
Based on the reputation, practicality, and price, we recommend six slicers as follows. Whether you are a professional or a newcomer, they are the first choice for most of your slicing needs.
Common Parameters and Tips
As known among Makers, no matter how perfect the 3D model file is, there will always be various unexpected problems in the actual printing process. In most cases, nevertheless, these problems can be alleviated or solved by adjusting specific parameters in the slicer. Next, let’s talk about some commonly used slicing parameters and related tips.
The layer height refers to the vertical distance between layers when slicing. The lower the layer height, the longer the printing time, and the better model details can be printed out. Generally, we want the details, but the choice depends on specific scenarios. If the model does not contain many details or is of practical use, the layer height can be increased appropriately to save time and the filament.
Outer Wall Thickness
The thicker the outer wall, the stronger the outer skin of the model, and vice versa. It should be noted that the wall thickness is best set as a multiple of the nozzle diameter. Otherwise, the printing may be compromised.
When the 3D printing module travels, the melted filament in the nozzle will ooze downwards due to the gravity, resulting in strings on the print. What you need to solve this problem is Retraction.
After setting suitable retraction parameters, whenever the 3D printing module travels, the filament will be retracted for a certain distance, thus offsetting the oozing distance. However, if you set inappropriate parameters, it will cause insufficient extruding when the printer continues to print or cause the filament clogging in the nozzle. Therefore, you’d better constantly adjust the settings according to the actual situation to avoid strings without generating other problems.
Infill density is generally expressed in the form of a percentage. If it is set as 100%, the target area will be completely filled. However, because the extrusion volume is sometimes unstable, setting an infill density of 100% is likely to cause the model to deform. 15%-30% is enough for most printing cases, which is both economical and time-saving.
When the model has overhangs, the support comes on stage. The role of support is to serve as a printing base for the overhanging part. As mentioned earlier, the 3D printer prints layer by layer. Except for the initial layer, each layer is built on the basis of the layer below. If the overhang angle equals or exceeds 90°, nothing under the first layer of the overhang can support its printing. When the overhang angle exceeds 45°, printing problems will easily occur if no support is added. In Snapmaker Luban, in addition to the support position, you can also set the support structure (linear, grid, etc.), density, Z distance, and other support parameters.
Initial Layer Adhesion
As the saying goes, well begun is half done. Similar to building houses, a solid and reliable initial layer is crucial for 3D printing. If the adhesion of the initial layer is not so good, it might cause layer shifting or warping. Considering its importance, most slicers support setting separate parameters for the initial layer, such as printing speed, travel speed, layer height, etc.
There is no perfect parameter setting for every maker or every model. Understand the meaning of these parameters and flexibly adjust them in different scenarios to get the best prints——that’s what makes us proud of being Maker.
We hope this article could be more or less useful for you.
Snapmaker Academy will bring you more exciting topics in the future, so stay tuned!
If you are interested in other topics of 3D printing, feel free to contact us at firstname.lastname@example.org, or leave your message in the community.
Note: The 3D Printing mentioned in this article refers in particular to Fused Filament Fabrication (FFF) 3D Printing.
Snapmaker recommends the software to you in no particular order and for resource-sharing purposes only.
Snapmaker does not in any way endorse, control, or assume responsibility for the content, views hosted on, and services provided by these software.