Perl Slicer (well the start of one anyway)
thingiverse
I was browsing a discussion board one day (sorry, forgot which one) that was talking about slicers and how they could slice a model. Then I thought, interesting, I could probably write some code to slice through a model. It doesn't sound that hard! So yeah, that's what started it. Of course, I'm an average perl programmer, so don't expect much but I figured it might be fun to try. So, I first wrote code to import a binary STL (it still doesn't do ASCII STL yet). That part gets all of the triangles into a big array. You can see the STL format here: https://en.wikipedia.org/wiki/STL_(file_format) It then iterates through z planes from bottom up by some layer height. Then it looks at each triangle. If all of its sides are on the current z plane, it just draws the triangle on the current plane buffer. If one triangle point is above the current z and the other two below, it figures out where each of the two triangle sides intersects the plane by rise over run and proportion of the one z point to the plane to figure the proportion of x distance to go and y distance to go to find the intersection point. Once it gets the two intersection points of the two lines passing through the plane, it draws a line between those two points. Once it does that for all triangles that pass through the current z height plane, that gives the outline slice of the model at that z height. Then, for now, the program just prints out that z height planes as a layer text to the output file to show that we have at least gotten this far with the program. USAGE: slicer.pl input_file.stl output_file.txt I included an STL model because it gives you something to try and because Thingiverse won't let me publish a program without including some model. I hope to get around to: 1. Filling in the outline on the plane so that it's solid blob. 2. Following the perimeter of the blob to get the outer shell vector -> output that gcode. 3. Maybe do more than one perimeter -> output that gcode. 4. Do some grid infill of the rest infill that's left -> output that gcode. 5. Have some sort of config file to make it easier for the settings. At that point, with some header and footer gcode it might be a working slicer that can output gcode! Neato. Not sure if I'll follow through that far or not, or even use it as my daily slicer. It's really more of an exercise and the fun of discovery and so far my goal of "slicing" a model (but yeah it's not outputting gcode yet) was accomplished so I thought I'd share for if anyone was curious about it. If you need to install Perl, Strawberry Perl is what I use - it's free: http://strawberryperl.com/ Further out ambitious goals (it would be neat if...): 1. Have it handle multiple colors. 2. Have it add wipe towers. 3. Have it handle variable layer heights. 4. Have it auto-generate support. 5. Grow up and be a real boy. If you like it, give it a "like", and please remember to give me credit if you're using it. And if you're feeling generous give me some sort of tip to support my Diet Dr Pepper habit. Thanks be to my Savior Jesus for the fun I've had so far!
With this file you will be able to print Perl Slicer (well the start of one anyway) with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Perl Slicer (well the start of one anyway).