Nonplanar SlicerΒΆ
All development for the nonplanar slicing functionality has been in the Scene package of the slicer.
The functionality is implemented in the NLMatrix4x3DDecorator. This decorator is attached to each model that is loaded to be processed by the slicer. It references methods in the NLMatrix4x3D class. By having a decorator, state information can be maintained between the preprocessing and postprocessing of the model.
The preprocessing is handled in transformMeshData. This method takes in a sceneNode that represents the mesh to be sliced. From this, it extracts the mesh data and world transformation. First, it checks if the nonplanar mode changed to update the matrix of transformations. Then, if nonplanar slicing is disabled nothing occurs and the mesh data is returned. Otherwise, the surface transformations to use are obtained from the settings. The mesh is then transformed to align with the world coordinates, and the vertices are subdivided if they do not contain sufficient detail. Finally, the transformation is applied to every vertice and normal in the mesh before inverting the transformations to adjust location and returning the mesh data. This method is called from StartSliceJob before sending the mesh to the backend, CuraEngine.
The postprocessing is not handled until the GCodeWriter starts writing chunks of g-code commands to a file on the disk. This means the previewed g-code will be for the transformed model rather than the original. Since the lines are processed in chunks rather than one at a time or a whole file, the inversion process maintains a state between chunks but also iterates through each line. The process consists of first interpolating each g-code command into several smaller commands such that each command is for less than a predetermined amount of travel. Then, the inverse transformation is found for each g-code command to map the position to the nonplanar slice in the original part. Lastly, some cleanup, such as changing the extrusion amount to match the different distance travelled is completed. The transformed and interpolated g-code commands are the ones written to the file. Any command that is not G0 or G1 is passed through unchanged.