In this post we will explain what it means to run
OpenSCAD .scad scripts with AngelCAD and why it can be a good idea. Using this feature requires
AngelCAD V1.5 or newer.
One criticism against OpenSCAD is that it can be very slow and requires a lot of memory to run its .scad scripts. Since the .scad scripts are widely used, it would be a good idea if there was a way to run them faster. That is where AngelCAD comes in. The reason why OpenSCAD is slow and memory hungry is because it is based on the
CGAL library. AngelCAD on the other hand is using
xcsg which is based on
Carve, so it has the potential to be much faster.
How does running .scad scripts work in AngelCAD?NOTE: OpenSCAD must be installed on the same computer as AngelCAD to use this feature, because OpenSCAD is used for parsing the .scad script into an easier to handle .csg file. This process is however very fast since it does not involve CGAL.From a user point of view, running .scad scripts in AngelCAD is just as easy as in OpenSCAD, only faster. Drop an .scad script into the AngelCAD editor and press the build button, and the resulting STL or other 3d file format is produced in no time. Behind the scenes, several things will then happen:
First, AngelCAD calls on OpenSCAD to convert the .scad script into a .scg file (fully automatic):
$ openscad myfile.scad --o myfile.csg Second, the .csg file is automatically scanned by AngelCAD to see if it contains OpenSCAD
import statements referring to STL or OFF files. If it does, these statements are replaced by suitable OpenSCAD
polyhedron statements. If the import refers to an STL, AngelCADs
polyfix is used to automatically compute the polyhedron. The result is a cleaned up .csg file that also OpenSCAD can read.
Third, the cleaned up .csg file is passed to AngelCADs
xcsg application. Normally, xcsg requires the
.xcsg file format, but version 1.5 has been enhanced to also accept OpenSCADs .csg files. The result is a 3d STL or other format file.
$ xcsg --stl myfile.csgThis may sound more complicated than running OpenSCAD, but in reality it is just as simple and faster from a user's point of view. All steps are fully automatic and it is much, much faster than running OpenSCAD itself, especially if the model is of some size. This is because the xcsg/carve boolean engine is quite lightweight, it uses native numerical representation and unlike OpenSCAD it is able to employ multi-threading, which means it can use more than one computer core at the same time.
The attached screenshots show AngelCAD running OpenSCAD's
example12.scad. This example imports an STL file, so all the steps explained above are being carried out.
Mesh resolutionOpenSCAD has parameters like $fn and $fa to control mesh resolution, but these are not used by AngelCAD/xcsg. Instead, the resolution is controlled by the
secant tolerance. This is also true for .scad scripts when run via AngelCAD. As can be seen from the first screenshot below, the command line argument
sec_tol=0.01 (alternatively specified as the longer equivalent
secant_tolerance=0.01) can be used to control the resulting mesh resolution. For this reason, running the same script through OpenSCAD may result in a slightly different result.
LimitationsThe support for OpenSCAD modelling features is relatively complete, but not 100%. The following is a list of .scad language features that are not supported
- import(file='somefile.dxf'): DXF or SVG file import is not supported. Import of STL and OFF is supported. Edit: DXF support is s available in V1.5-06
- text(): text command is not supported. Edit: text() support is available in V1.5-06
- surface(file='surface.dat'): surface command is not supported
- resize(newsize=[30,60,10]): resize command is not supported
- polygon without holes is supported, but a polygon with internal holes is not