6.6 KiB
Slicing System
Summary
MatterControl integrates the MatterSlice slicing engine to convert 3D models into G-code instructions for printing. The system maps printer settings to slicer parameters, handles multi-extruder configurations, and supports features like rafts, supports, and custom start/end G-code.
Technical Description
Architecture Overview
PrinterConfig.Settings
│
▼
EngineMappingsMatterSlice (IObjectSlicer)
│
├── Settings Mapping (Exports dictionary)
│
▼
MatterSlice Engine
│
▼
G-code Output File
Slicer Static Class
The Slicer static class provides helper methods:
Key Methods:
| Method | Purpose |
|---|---|
SliceItem() |
Entry point for slicing objects |
GetExtrudersUsed() |
Determine which extruders are needed |
GetSolidsForExtruder() |
Filter objects by extruder assignment |
GetAllHoles() |
Find hole/negative objects |
T1OrGreaterUsed() |
Check if multi-extruder print |
Configuration:
RunInProcess- Run slicer in-process (debug) vs subprocess
EngineMappingsMatterSlice
Implements IObjectSlicer interface to translate MatterControl settings to MatterSlice parameters:
Export Mapping:
Exports = new Dictionary<string, ExportField>()
{
[SettingsKey.layer_height] = new ExportField("layerThickness"),
[SettingsKey.perimeters] = new ExportField("numberOfPerimeters"),
[SettingsKey.fill_density] = new ExportField("infillPercent", transformer),
// ...
};
Mapping Categories:
| Category | Sample Settings |
|---|---|
| Layer | layer_height, first_layer_height |
| Perimeters | perimeters, external_perimeter_speed |
| Infill | fill_density, infill_type, fill_angle |
| Speed | travel_speed, perimeter_speed, infill_speed |
| Retraction | retract_length, retract_speed, retract_lift |
| Support | support_material_spacing, support_air_gap |
| Raft/Brim | create_raft, raft_air_gap, skirts |
| Fan | min_fan_speed, max_fan_speed, bridge_fan_speed |
| Extruder | filament_diameter, nozzle_diameter, extrusion_multiplier |
Export Field Transformers
Some settings require transformation:
// Percentage to decimal conversion
[SettingsKey.fill_density] = new ExportField(
"infillPercent",
(value, settings) => {
if (double.TryParse(value, out double infillRatio))
return $"{infillRatio * 100}";
return "0";
})
// Start G-code processing
[SettingsKey.start_gcode] = new ExportField(
"startCode",
(value, settings) => StartGCodeGenerator.BuildStartGCode(settings, value))
Multi-Extruder Support
Extruder assignment based on MaterialIndex:
var itemsThisExtruder = meshItemsOnBuildPlate.Where((item) => {
var material = item.WorldMaterialIndex();
return material == extruderIndex
|| (extruderIndex == 0 && material >= extruderCount);
});
Extruder-Specific Settings:
support_material_extrudersupport_material_interface_extruderraft_extruderbrim_extruder
Print Output Types
Objects can have different output behaviors:
| Type | Description |
|---|---|
Default |
Normal solid printing |
Solid |
Explicitly solid |
Support |
Support material |
Hole |
Negative/subtraction |
Fuzzy |
Fuzzy skin effect |
Slicing Process
- Collect Printable Items: Filter scene for printable objects
- Determine Extruders: Calculate which extruders are needed
- Map Settings: Convert settings to slicer parameters
- Run Slicer: Execute MatterSlice engine
- Progress Reporting: Update UI with slice progress
- Output G-code: Write to file
MatterSlice Integration
MatterSlice is included as a submodule:
Submodules/MatterSlice/MatterSlice.csprojSubmodules/MatterSlice/MatterSliceLib/MatterSliceLib.csproj
Key Settings Files:
StaticData/SliceSettings/Layouts.txt- UI layout definitions- Settings JSON files in printer profiles
Slicer Settings UI
Settings are organized via SliceSettingsWidget:
SliceSettingsWidget
├── Category tabs (General, Infill, Support, etc.)
├── Settings rows (SliceSettingsRow)
└── Preset selector (PresetSelectorWidget)
Design Rationale
Integrated Slicer: Bundling MatterSlice provides:
- Seamless user experience
- Direct control over slicing behavior
- No external dependencies to manage
- Consistent cross-platform behavior
Export Field Pattern: The mapping dictionary allows:
- Declarative settings mapping
- Custom transformers where needed
- Easy addition of new settings
- Clear documentation of mappings
Extruder Detection: Pre-calculating used extruders enables:
- Appropriate temperature settings
- Correct tool change G-code
- Optimized print preparation
Reference
Core Classes
| Class | Location | Description |
|---|---|---|
Slicer |
SlicerConfiguration/Slicer.cs | Static slicer helpers |
EngineMappingsMatterSlice |
SlicerConfiguration/EngineMappingsMatterSlice.cs | Settings mapping |
ExportField |
MatterControl.Printing/ExportField.cs | Field definition |
SliceSettingsWidget |
SlicerConfiguration/SliceSettingsWidget.cs | Settings UI |
UI Components
| Class | Location | Description |
|---|---|---|
SliceSettingsRow |
SlicerConfiguration/SliceSettingsRow.cs | Individual setting row |
PresetSelectorWidget |
SlicerConfiguration/PresetSelectorWidget.cs | Preset dropdown |
SettingsRow |
SlicerConfiguration/SettingsRow.cs | Base row widget |
Key Enums
| Enum | Values |
|---|---|
PrintOutputTypes |
Default, Solid, Support, Hole, Fuzzy |
InfillType |
Grid, Triangles, Gyroid, Lines, etc. |
SeamPlacement |
Random, Nearest, Aligned |
SupportType |
None, Lines, Grid, FromBed, Everywhere |
Settings Keys (Sample)
| Key | Description |
|---|---|
layer_height |
Layer thickness |
perimeters |
Number of perimeter shells |
fill_density |
Infill percentage |
support_material |
Enable supports |
create_raft |
Create print raft |
retract_length |
Retraction distance |
travel_speed |
Non-printing move speed |