ImplicitCAD: Programmatic CAD Built with 3D Printing in Mind


Cornerstone of many useful things: This Prusa i3 part was modeled in OpenSCAD.

Programmatic CAD, in particular the OpenSCAD language and IDE, has accompanied the maker movement for a while now. After its introduction in 2009, it quickly found its way into the 3D printing toolbox of many makers and eventually became what could be called an Industry Standard among open hardware labs, makerspaces and tinkerers. The Prusa i3, one of the most popular DIY 3D printers, was designed in OpenSCAD, and even Makerbot, the company that sold 100.000 3D printers, uses the language for its “Customizer” – an online tool that allows users to customize 3D printable models with minimal effort.

OpenSCAD is indeed a wonderful tool, and we have been using it a lot. We have become used to its quirks and accepted working with polygon mesh approximations of the models we are trying to design. We have made our peace with excessive rendering times, scripting workarounds and the pain of creating fillets, and we have learned to keep our aesthetic expectations low. We are happy with the fact that there is a way to programmatically create and share virtually any object, but sometimes we wish there was a better way in the open source world. Hint: there is.

Inspired by OpenSCAD, ImplicitCAD was originally started by Christopher Olah in early 2012, aiming to create a solid programmatic CAD tool to create complex models for 3D printing. It borrows the OpenSCAD language for modeling but has its own 3D geometry engine. At the core, the engine relies on continuous mathematical descriptions of 3D geometries rather than polygon mesh approximations. The finished model can then be translated into a mesh-based format such as STL, rendered into an image via raytracing, or turned into G-code directly. In many cases, this happens much faster and more efficiently in ImplicitCAD than in OpenSCAD. Also, ImplicitCAD offers a bit more flexibility in programming – and rounded CSG operations. ImplicitCAD is written entirely in Haskell and, despite having a common modeling language, shares no common code with OpenSCAD.

Getting Started

ImplicitCAD doesn’t come in a precompiled binary with an IDE on board. There are ambitions to create a web based editor, but currently, it is not functional. I recommend you to use MeshLab for previewing your models along with your favorite text editor.

The installation and build instructions for Linux, Mac and Windows are easy to follow and should be sufficient to get you started. To get the most recent development version 0.0.6, you will need to create your own build from the ImplicitCAD source.

Hello World

With ImplicitCAD installed on your system, you can start modeling. Just create an empty text file named ‘helloworld.escad’ on your Desktop and open it in your favorite editor. Type:

Mesh output quality at default rendering resolution.
sphere(r=10);

Then open a terminal and render your model by typing:

$ extopenscad ~/Desktop/helloworld.escad

Mac users may try this:

$ ~/.cabal/bin/extopenscad ~/Desktop/helloworld.escad

This will create a ‘helloworld.stl’ on your desktop. Open the file in mesh lab. Wow, a rough sphere.

ImplicitCAD automatically sets the rendering resolution to a reasonable value (and shows this in its terminal output), but you can specify a rendering resolution by defining $res in your model file. Smaller values result in a higher rendering quality:

$res=0.5;
sphere(r=10);

Render this and have a look at the STL again. The quality should be much better now.

Where It Shines

Rounded CSG transformations

ImplicitCAD can perform rounded unions. This creates smooth transitions between fused objects.

Passing the ‘r’ parameter to the ‘union()’ module smooths out the transition between arbitrary geometries.
$res=0.5;
sphere_size=10;
fillet_radius=2;
union(r=fillet_radius)
{
  translate([-0.8*sphere_size,0,0])
    sphere(sphere_size);
  translate([0.8*sphere_size,0,0])
    sphere(sphere_size);
}

Rounded differences work just as well:

OpenSCAD’s ‘minkowski()’ module also allows convex smoothing – too bad it is such a handbrake. ImplicitCAD does this on the fly.
$res=0.5;
cube_size=10;
fillet_radius=2;

difference(r=fillet_radius){
  cube(cube_size,center=true);
  cylinder(r=cube_size/4, h=2*cube_size, center=true);
}

Threads

Unfortunately, lots of CSG work is necessary to get a proper thread out of OpenSCAD. ImplicitCAD however, supports translation in the rotate_extrude module, making threads easier and faster:

An M16 thread in ImplicitCAD.
$res=0.05;
inner_diameter=13.55;
outer_diameter=16;
pitch=2;
turns=5;

union()
{
  cylinder(r=inner_diameter/2,h=(turns+1)*pitch);
  rotate_extrude(a=turns*360,translate=[0,turns*pitch],r=1)
    polygon([
      (inner_diameter/2-pitch,pitch),
      (inner_diameter/2,pitch),
      (outer_diameter/2,pitch/2),
      (inner_diameter/2,0),
      (inner_diameter/2-pitch,0)
    ]);
}

Functions

Many modules in ImplicitCAD accept functions as parameters. This example sets the extrusion height to a function of x and y:

$res=0.05;
linear_extrude(height(x,y)=15+5*cos(x/4)+5*cos(x/2)+5*cos(y/4)+5*cos(y/2))
 circle(r=10);

What It Does

These are just a few examples, you can find more on the project’s website. Besides rounded ‘union()’, ‘difference()’ and ‘intersection()’ transformations, ImplicitCAD also offers rounded primitives such as the ‘cube()’. Some modules accept functions instead of only parameters, which allows creating curved surfaces more efficiently. For more detail, have a look at the API documentation. Unlike OpenSCAD, which relies on the single threaded OpenCSG, ImplicitCAD’s geometry engine renders highly parallelized on multiple cores. Besides STL files, ImplicitCAD exports raytraced PNG images, DXF files and G-Code for laser cutters.

What It Doesn’t

There are still tons of things ImplicitCAD can’t do. It misses a dedicated text module, although text may still be rendered by using polygons. Thanks to the other rounding tools, I can certainly live without ‘minkowski()’, but I really miss the ‘hull()’ module. At the moment, user defined modules can’t process child modules, and the 2D subsystem lacks an ‘offset’ operation. Multiple objects must be combined using ‘union()’ before rendering, and ImplicitCAD apparantly doesn’t do this implicitly.

Potential For 3D Printing

ImplicitCAD extends your 3D printing toolbox by another great tool for modeling parts. However, in 3D printing, we currently rely on a toolchain that first creates mesh approximations of models, and then creates another, even worse approximation of the first one when generating toolpaths, usually G-code. ImplicitCAD has been built with 3D printing in mind and already includes some rough G-Code export functionality. Generating G-Code for 3D printing directly from the model, bypassing the mesh generation, may allow for a faster and more accurate slicing process in the future.

Past And Future Of ImplicitCAD

The development progress has been a bit unsteady, but ImplitCAD’s codebase has always been clean, concise and readable. After Christopher dropped the project and moved on to machine learning, the development idled for a while until Julia Longtin took over as the new maintainer. She now uses ImplicitCAD as a teaching tool for her 3D printing and microcontroller classes at HacDC. The original features are pretty much untouched, but Julia has successfully increased the precision and speed of the geometry engine. She is also trying to fix the browser based editor, which will lower the entry barrier to using ImplicitCAD. By adding comments throughout the code, she aims to make the code more readable for new contributors. Right now, the project is in a “rebuilding year”, and we may have good chances to see it gain new momentum in 2016.

Thanks to [Jasper1984] for the ImplicitCAD script for the open hardware logo used in this posts featured image.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *