sample stl files for 3d printing



[applause] hi there, how are you doing? thank you so much for coming. so, i am here to talk aboutusing python to generate designs for 3d printers and laser cutters,but first i want to talk about myself and introduce myself. that's my email addressand my github repository. so, i work at a start-upin boston called ginkgo bioworks. we apply techniquesfrom synthetic biology


and genetic engineeringto build custom organisms for our customers. we build thousandsof custom strains, and to do this at scale,we rely heavily on python to help us design, track,and analyze our engineered samples. and if you're interestedabout ginkgo, you can learn more about usat ginkgobioworks.com. we are hiring. in my spare time,i like to explore


a lot of different hobbies,and that includes things like photography and gardeningand cycling and cooking, electronics and making art. and for each one of my hobbies,i've at least written like a handful of python scriptsto facilitate it one way or another. so here's a quick example: in my backyard,i have a davis weather station. this transmits weather datawirelessly to a raspberry pi in my house, and i haveanother raspberry pi in my basement


that monitors this dataand controls a set of relays that switch on sprinklersto water the garden. so python for me, it's notjust a programming language. it's one of the primary means i useto express myself creatively. but as powerful as python is,programming by its very nature is not a physical medium. frederick p. brooks wroteone of my favorite quotes about computer programmingin his book "the mythical man-month." (reading quote)


and the world is filled with theseamazing but nebulous castles but we can't really appreciate themwithout the aid of a computer. you can't share your codelike you would a painting, or a sculpture,or a well-cooked meal. and, you know, to be honest,i realize that this is not true. like, we use software to manipulateour physical world every day. our computers producesound and light and they churn outprinted documents. there are many waysthat you can write code


to affect the physical world. and that's the coreof what i want to talk about. but first, a little history. before there were computers,people had to make things by hand. the period betweenthe late 19th century and the middle of the 20th centurywas collectively known as the machine age. and during this time,we perfected the art of building partsat an industrial scale using a process calledsubtractive manufacturing.


this includes techniques such as:milling, turning, boring, broaching, sawing,reaming, tapping. the general idea was to shapebulk stock into some kind of part by removing materialwith incredible precision. but after the 1950s,the world entered the atomic age and ushered inthe digital computer. and during the 1940s and 50s,existing tools like mills and lathes were connectedto electric motors that were controlledby punch tape.


this was the first step towardsautomation of these machine tools. and as computers evolvedin sophistication, it spawned a new fieldof fabrication called computer numerical control,also known as cnc. so today, computer-controlledautomation is ubiquitous throughout all areasof manufacturing. not only has the computer hardwareand software programming evolved to such a pointof sophistication, but there are new manufacturing toolsand processes that had never existed


just a few decades prior. this includes things likeplasma cutters and water jets and 5-axis milling machines,lithography, and two of my personal favorites:laser cutters and 3d printers. so, we're going to examine each oneof these technologies individually, and then we're going to discusshow we can use python to generate designsfor these tools. so first, laser cutters. laser cutters are devicesthat utilize high-powered lasers


to etch or cut a varietyof different materials. most commercially availablelaser cutters are capable of cutting and etchingpaper or wood, plastic, leather, fabric,up to a certain thickness. and the laser tube itselfis static to the device, typically mounted towardsthe back of the machine. carefully positioned mirrorsbounce the laser light to the laser head,and the laser head itself is composed of mirrors and lensesthat focus the laser beam


onto the target material. stepper motors then movethe laser head in the x and y plane parallel to the work material,thus allowing the laser to trace out the contours of a given design. laser cutters are incredibly preciseand they're capable of producing just really complex and intricatedetail in your design. digital design for laser cuttersthough, typically start as vector graphics. this is, you know, design programslike adobe illustrator and inkscape


are vector illustrator packages. this is in contrast to programslike the gimp or photoshop which are raster or bitmaporiented graphics packages. vector graphics make it easyfor the software controlling the motion of the laser cutter to translateyour graphics into motion. the process of creatinglaser cut designs is relatively straightforward. after you think aboutwhat your design should look like, you need to pick the materialthat you want to use and the size.


generally speaking,if you're cutting with a laser cutter,thinner is better than thicker. your design should then be sizedaccording to the constraints of the materialyou're cutting out. but with vector graphicsyou can scale your designs without losing any fidelityof your design. most laser cutter softwarethen requires you to indicate which parts of your designare meant to be cut versus which should be etched.


this can be achievedwith a color of the line, for example, red for cutor blue for etch. and then when you're readyto execute your cut, you position your materialon the laser bed, and you focus the laser beam,and you upload your design file. every laser cutter, to be honest,is a little different, so the specifics ofhow that actually gets done is dictated by the companythat makes that specific cutter. so, you can upload your designsas pdf or eps,


but i personally prefer svg. svg files are xml documentsand a closely-related cousin to html. html and svg sharea lot of attribute names for various tags, like width,height, style, and border. they share style syntax as well,and later revisions of svg actually supportcascading style sheets. this is a simple exampleof an svg document. you can see the two tags:rec for rectangle, and circ for circle.


the rectangle tagtakes an xy position to define its top-left cornerand a width and height value to define its size. the circle, on the other hand,requires an x and y coordinate to define its center,and another value for its radius. and each of these objectstake parameters that define how the shape is stroked and filled,that is, with what color. but as you can see, you can getrelatively complex designs with just a few lines of codewith an svg.


my personal favoritefeature of svg are paths. a path is simply a listof connected line segments that are used to buildcomplex polygons. a path segment can bea straight line or a curve splinewith control points. within the svg document,the path is defined by a string of characters. it's broken up intosingle letter commands like m for moveor l for line,


and then two or more numbersthat represent the coordinate of that command. you can do a lotwith just circles and squares, but paths allow you to buildincredibly complex shapes. and in this example,i just rattled off a few random pointsto make this squiggly line. so, for this talk i wrotea python program to generate a laser-cuttablecube or box that uses finger joints. even though this designoriginates in 2d space,


when you put it togetherlike a puzzle it producesa three-dimensional shape. the program itself isa few hundred lines of code so we won't be ableto discuss it in its entirety, but you can go check outmy github repository after this talk,and look at the code, and look at the various optionsthat allow you to change its design. i brought a bunch of examplesas well, and so if you come find me, i can show them to you.


and i'm gonna auction these offlater at the pyladies auction. so, this is whatone of the generated designs looks like that is sent verbatimto the laser cutting control software. you can seethat the layout of the design packs the faces closely togetherto minimize the overall waste of the material. and you can see that it's notthe same face over and over again. there are slight differencesbetween each of the individual faces. and that's to helpthe puzzle-like way


that it fits together. and so this is the resultof what you get when you cutthat design on wood. you can see the scorch markscaused by small flare-ups as the material briefly ignitesfrom the laser. as a bonus the board has thisnice, refreshing burnt wood smell. since the cube fits togetherlike a puzzle, the edges of each facemust interlock. i think of these edges as beingeither positive or negative,


dependent upon whetherthey have a outer edge to them or an inner edge to them. and i've color coded themto distinguish this feature. so in this case, red is positiveand green is negative. so, as we kind of dial in,we can just think about a single edge on a single face,and consider the code that we would need to writein order to generate it. the width of the materialdictates the height of each individual finger,and the length of the edge


combined with the number of fingersthat you want in your design dictates the overall widthof the finger itself. and so from theseconfigurable parameters, we can write a functionto draw a single edge. and this iswhat that code looks like. this function takesthe size of a cube face as a tuple, the number of fingers in an edge,the width of a single finger, and the thickness of the material, and it calculatesvarious geometrical offsets.


first, we use the size of the facein order to find its center. along with the number of fingersin the finger width, we use the center position thento calculate where our first point in the edge line should occur. we then build two listsof positional offsets, one for the finger width,and the other for the finger depth. and we iterate through each pointalong the edge, calculating the offsets for each. the code exploits the factthat every other point


moves forward through the edge,and every second point raises the edgeand every fourth point lowers it. so we use a modulus operatorto replay those offsets as we build the edge profile. and here is an exampleof how you would call that previous function. since the previous functionwas a generator that returns a list of positions, the caller takes those pointsand translates them into a string


that is formatted as an svg path. you can note thatthe first command is an m command because we want to moveto that position. and then it's followedby l commands to actually draw those connected line segments. and that's the resultof what we've drawn. this is obviously only a small pieceof the overall box generator, but it's central to the design. the code is object-orientedand relatively easy to follow.


you can configure and customize itin many different ways, such as the size of the box,the thickness of the material, and the designson the box faces themselves. so for example,since the box generator itself has a base class that definesa geometric rules for each face, you can inherit from this classand hook into it's rendering method. in this example, i've addeda fermat's spiral. this is a simple mathematical functionthat generates a pattern that is reminiscent of the patternof seeds you would find


on the face of a sunflower. and this is the code that is usedin order to generate that. rather than going through thisin detail, i just want to highlight this idea that you can come up withinteresting artifacts like that and embed it in part of --in your overall larger design. it's very easy to do,once you figure out kind of the base of your object,to add these kinds of artifacts that give your design more flavor. and this is the resultant imagethat is generated from that.


so, svg makes it really easyto layer in new elements and add to the designwithout requiring you to change the overall structureof the svg document itself. coupled with python,it's the perfect technology to expressyour laser-cuttable designs. whoops. alright. so, 3d printers. 3d printers are devicesthat can build three-dimensional objects.


they range in priceand sophistication, but the most common3d printers available are known asfused deposition models. these work by breaking downthree-dimensional objects into 2d slices that, when stackedone on top of the other, will reconstruct the geometryof the three-dimensional object. fdm printers, specifically,work by extruding plastics at really high temperatures. but unlike laser cutters,3d printers work in three axes


instead of two. the x and y axes are utilizedby the printhead to deposit the materialin a desired shape, and the z axis is then usedto advance the model to the nexttwo-dimensional slice. this is a high-leveldesign pipeline for 3d printers. most 3d printing softwareconsumes stl files and producewhat is known as gcode files. but stl files are not easyto generate by hand


since they actually representthe three-dimensional object in a triangle mesh form. personally, i don't think aboutmy three-dimensional designs as a mesh of triangles. i like to think about themas solid objects. about five years agomy girlfriend and i purchased our first 3d printer,and we were so excited about it that we were obsessed aboutall the things that we were going to designand make on it.


but i was immediately frustratedwith the standard tools out there that people typically usedto design cad models for printing. you know, i'd spend hoursin programs like sketchup building up a complex designonly to realize i needed to change somethingcore to the model. most of the design toolsdo not make it easy for you to make these kindsof drastic changes. it's kind of like paintinga family portrait and realizingyou left out your brother.


so, there are more sophisticated3d modelers out there, including somethat are parametric. but most are expensiveor only run in windows or are difficult to learn,or typically all three. so i looked around to finda programmatic solution that i would findmore comfortable and that's how i discoveredsomething called openscad. openscad utilizesconstructive solid geometry. the idea is to build your objectsfrom two-dimensional


and three-dimensional primitivessuch as cubes, cylinders, and spheres. you position these objectsin space and then you define boolean operationsbetween them. the most commonboolean operation is union, to join two or more solidstogether as one. and then there is difference,which is used to subtract one or more solids from another. so for example, let's just takea drinking glass. we can construct itwith just two cylinders.


the first cylinder -- sorry, the top got cut offbut we'll see the code later. the first cylinder describesthe outside surface and the second describesthe empty volume inside. using openscad, we would definethe first cylinder with a second cylinder inside. the inside cylinderwould then be offset in the z axis, or the up axis,and would have a smaller radius than the outer cylinder.


we would then subtractthat inner cylinder from the outer cylinderto create that empty envelope. in order for this to work,we have to make sure that it leaves the floor of the glassbut creates the mouth as well, and that's why we do the offset. so this is whatyour two cylinders would look like. and you can seein the third line of code, there's a translate operation.


and that is what movesthat inner cylinder up to create the floor of the glassand the mouth of the glass. right now i have thisas a union of two objects to highlight the fact that thesetwo cylinders are inset, but by changing that top unionto a difference, we then create the empty volumethat we're aiming for. openscad does all of the hard,complicated math to calculate the meshfor these objects, freeing us up to think abouthow to construct our models


with just primitive shapes. i think it's impressiveto consider what we can build with just four lines of code. but the scripting languagefor openscad is relatively simple in and of itself,and doesn't really provide a lot of the featuresthat we know and love from python. but with the simplicityof openscad in our favor, we can easily then generateopenscad from python. so, for a more complicated example,we're going to consider a flower pot.


flower pots are similarto drinking glasses, but they also havea few distinct features. first, most flower potsare wider at the top and smaller at the bottom. although we think about the shapeas a cone, it's often described as a cylinder in openscadbecause you can define a cylinder with two different radiusesfor each end. second, they usually havea hole at the bottom to facilitate drainage.


and finally, they often providea lipped collar at the top to make it easy to holdand move the pot around. so now that we have a feelfor openscad syntax, let's talk abouthow we can generate this design from python. there are a few differentpython libraries that allow you to build openscadsyntax from python, including a library that i've writtencalled python scad. most of these librarieswork in very similar ways,


wrapping openscad definitionswith python classes. for my demo,i'll be using my library but you can accomplishthe same thing with any of the otheralternative libraries out there. so, most of my scad objectsthat i write in python start out like this, with a seriesof parametric variables that help define the physicalconstraints of the object. i try to write a few top-levelvariables that are designed to be flexible, and then computeother variable values


based on those initial values. in this example,many of the variables for the flower pot are derivedfrom the flowerpot's overall height. this makes it easy to changethe overall size of the flower pot without having to changeeach individual variable. you can also see that i have --as an example, i have ratios in therethat define, for example, the top radiusversus the bottom radius. you know, i went around measuringflower pots around my house


and found that it wastypically about a .6 ratio. and along with thingslike the thickness or the wall thicknessof the pot itself, because we have tocalculate our offsets in order to do the subtraction. so this is all the codethat is required to then produce that pot. it's, to be honest, much simplerthan the cube for the laser cutter. it's pretty boring, actually.


we start from the outsideand add other cylinders to carve out the spaces we need. it's built entirelywith the cylinder primitive along with unionsand translations. really the only hard partis imagining your model and then breaking it downinto primitive solids. once you've done this,building the design and code is incredibly straightforward. so, this is my printer at homebuilding a 2.5 inch flower pot


which is right here. it took about two hours to print,but one thing you'll notice is that it's printingan outer wall that's actually notpart of the design. this wall is generatedby the printer software and is known asa support material. the lip of the flowerpotoverhangs in space and without that support material,the printer wouldn't be able to successfully printthat overhang.


but you can just tear it offonce the print is done. and there's the finished result. so, now i'm going to talk abouttwo projects i have done with laser cuttersand 3d printers that are more complicated,and the code is available for these projects. but it's to kind ofwhet your appetite of, beyond these simple exampleswhat else can you do with it? so to start off first ismy snowflake generator.


this project, my girlfriendand i started about four years ago. we were trying to figure outwhat to make our friends and family for the holidays. and rachel foundthis amazing paper that describes a physical modelto simulate the growth of snowflakes. we translated the mathfrom this paper into python code and proceeded to makepersonalized snowflakes for everyone on our gift list. the model worksat the mesoscopic level,


which is to say it modelsa collection of molecules, specifically water moleculesas an undefined unit. and it starts off firstby constructing a hexagonal grid. the grid is then populatedwith a homogeneous field of water molecules. and these water moleculescan move from one neighboring cell to another and can switchbetween three defined states: vapor, boundary, or frozen. the boundary state is often usedto describe water that is neither


vaporous or frozen, but caughtin between those two states. the initial fieldof water molecules are set to a vaporous state,except for the cell in the middle, which is initializedas a frozen state. and then, from there,the simulation runs and the snowflakebegins to form. the model takes eightdifferent parameters which dictate the behaviorof these individual steps in the algorithm.


so each cell doesthese individual calculations for its own state. it first figures out howthe vapor of the cell should move. and then it figures outif some of it should freeze to the boundary vapor. and a portion of the frozenboundary cells then attach to the body of the snowflake. and then a certain portionof them melt off. and finally, as a parameterfor noise, which i think


is really beautiful, it addsjust a little bit of randomness to the overall simulation. and what you end up are notperfectly symmetrical snowflakes, but snowflakes with slight defectswith respect to their individual arms. so, from a grid perspective,as the simulation progresses, the snowflake crystal beginsto grow out from its initial seed, so you can seethe frozen state in the middle, and then the boundary seedsaround it. and the program works likea cellular automata simulation.


each cell inspects its neighborsand calculates its changes based on the parameters but because there's hundredsof thousands of cells, the simulation iscomputationally intensive, taking hours to run. in order to generatethe hundred snowflakes we made as a gift, actually, we generated allof our snowflakes in the cloud. [laughter]


so, the result of this simulationis a complex bitmap. but instead of capturingred green blue intensities on a cartesian grid,this bitmap stores the density of the frozen water moleculeswithin a hexagonal grid. when the snowflake reachesa certain predetermined size, the simulation stopsand the program proceeds to translate that snowflakeinto svg files. two svg filesare produced and merged. the first svg file isa representation


of the densest bandsof frozen water molecules in the snowflake. that is where the most commonabundance of water that froze, and there are these bandsof density that you can see. and the second svgactually defines the outline of the snowflake, and these two files are mergedinto a single svg and then sentto the laser cutter. so, i have a kind of a cool videothat just describes


this whole process. one thing that really astounds meabout this model is that it can generate justan amazing variety of different kinds of snowflakes. and very much with eachnot looking like the last. so this is -- i ran the simulationsaving an image of the snowflake at every step, so this shows youthe overall growth of it. you can see the black auraaround it, and that's actually the depleted vaporthat it's sucking into the body


of the snowflake, while the gray areais still vaporous water. and here we are etchingand cutting one of the snowflakes. so, you can see right herethe laser cutter is in an etching mode, where it isjust pulsing the laser and just ablating the surfaceof the plastic off to make a depressionin the plastic but then not actually cut it. and then once it's done,it does the cutting step,


which allows usto remove the snowflake. and again, i have broughtexamples of these guys, so if you want to, come takea peek at them after the talk. alright, so the other examplethat i want to show you is somethingthat i called rockit. so, this is a model rocketconstruction kit. you know, this is kind ofthe first project i did with openscad and python,and i wanted to make something functional, right?


i wanted to be able to printsomething off my printer and have itactually do something. and so i made this model rocketgenerator that can design and print a rangeof different rockets and rocket types. so if you're not familiarwith model rocketry, you should know that there area range of different engine sizes. and these engines are madeof solid propellant packed into a cardboard tube.


the sizes of these enginesvary in length and diameter, requiring different-sizedengine holders to start a design. when you start a design,you first select an engine and then rockit will calculatea bunch of different parameters for the rocketbased on that engine size. another neat feature of rockitis that it uses these coupling sleevesthat allow you to snap together the rocket like legos. i mean, you can literally justprint this off your printer,


snap it togetherand then launch it. but i recommend using glue because it will probablycome apart in flight. and you can even print the basewith that coupling sleeve and that will allow youto make multistage rockets. rockit makes it very easyto change different aspects of your design. for example, you can swap indifferent kinds of nose cones, or you can add or remove fins,or one of my favorite features


is to tilt the fins so that whenthe rocket is launched, it rifles up into the sky. but what i think isreally fantastic about this is that you can print twovery similar rocket designs with a slight tweak between themand they'll be very -- it's a very reproducible process. so you can empirically evaluatehow you have changed the performance of your design. so, my friend adamvideotaped this one launch,


and it's unfortunatelythe only video footage i have, and it's a prettydisastrous launch. but it does work. i believe this isone of the ones that had spiral, so it spiraled up into the air. but the weight ratioto the engine size was not calibrated, and so it also thenpromptly took a nosedive. but that's the best part --


i mean, these rockets, to be honest,they're not the most robust thing. i mean, it's plastic,and plastic doesn't like heat, and so you're likely to melt them,but i say who cares? just go home and printsome more, you know? you'll definitely at leastget a few flights out of it. but yeah, i just -- what i thinkis just so neat about this is that you can print somethingoff your printer and stuff a rocket engine in itand it will fly. anyway,you may be asking yourself,


how do i get accessto these tools? so i realize that not everybodyhas these at their disposal. and in boston, where i'm from,there are a number of local maker spacesthat provide access to 3d printers and laser cutters. some public librarieshave also booted up their own maker spacesto provide access to these tools. and if you can't findanything local, you can always use popularinternet-based service providers


such as ponoko or shapeways. for example, i got allof my materials cut at ponoko before i came to this talk. but the whole fieldis really rapidly changing and new toolsare coming out every year. and as these tools advance,the total cost of ownership comes down in price. these are the relevant github urlsfor all the various software that i've written.


the top one isa mirror of this talk. but you can also findmy snowflake generator, the rocket generator, and the python scadlibrary there. and that's it,thank you very much. (moderator)so, a few minutes for questions. if you have any,come to the microphones please. (audience member)i'm curious as to why you didn't printyour pot upside down.


(giles hall)that's a great question. the reason is that, um -- the -- the flatnessof the bottom of the pot would then be the overhangas opposed to the lip. to be honest, it's probablysix of one, half-dozen of the other. but you would imaginethat it would have to print a scaffoldinginto the center of the pot, and i find that to dig outsupport material is harder


than just being able to rip it,


sample stl files for 3d printing

sample stl files for 3d printing,so that's why i chosethat orientation. (audience member)thanks. (moderator)so if there are no more questions, let's thank the speaker again.


sample stl files for 3d printing Rating: 4.5 Diposkan Oleh: PaduWaras