Root/cad/test1/README

1Comparison of Free scripted 3D CAD systems, part 1
2==================================================
3
4Werner Almesberger <werner@almesberger.net>
5
6This is a brief evaluation of the scripted 3D CAD systems OpenSCAD
7and Cadmium, comparing the workflow, resource consumption, and the
8quality of the results.
9
10
11Introduction
12============
13
14This file and the sources of the models can be found in
15http://projects.qi-hardware.com/index.php/p/wernermisc/source/tree/master/cad/test1/
16
17Later experiments showed that small changes to the model can lead to
18quite different results. The continuation is at
19http://projects.qi-hardware.com/index.php/p/wernermisc/source/tree/master/cad/test2/
20
21
22Objectives
23----------
24
25This test aims to determine the general suitability of currently
26available Free scripted 3D CAD system for the construction of
27real-life objects.
28
29Aspects considered were the ease or difficulty of model development,
30the clarity of the modeling language, resource consumption during
31rendering, and the quality of the resulting mesh.
32
33A second objective was to evaluate the suitability of CSG as the only
34means for constructing models suitable for large-scale industrial
35production.
36
37
38Object description
39------------------
40
41The object to model is a simple button/key cap shape. The shape
42consists of a top part shaped as a 10 x 15 mm rectangle with rounded
43corners and at height of 1.5 mm. The top part rests on a base that's
440.5 mm thin and has a border of 1 mm on each side.
45
46The corners of the rectangle are rounded with a radius of 2 mm. All
47other external edges are rounded (chamfered) with a radius of 0.2 mm.
48The edge where top and base meet is filleted with a radius of 0.4 mm.
49
50Note that a real button would typically have an internal cavity,
51possibly some depression or other structure on its top, and on the
52bottom side a pusher in the middle and possibly other support
53elements.
54
55Also, if the design was to be used for injection molding, sidewalls
56would be slightly tilted.
57
58The rounding of the bottom plate is not strictly necessary and was
59added for visual appearance.
60
61
62Candidate 1: OpenSCAD
63---------------------
64
65OpenSCAD [1] uses its own language, somewhat similar to POV-Ray's, to
66describe 3D objects. It has an IDE with a quick preview capability
67using OpenCSG [2].
68
69High-quality rendering, e.g., to STL, is done with CGAL [3] and can
70also be run non-interactively.
71
72OpenSCAD and OpenCSG are licensed under the GNU GPL v2. Parts of CGAL
73are licensed under the GNU LGPL v2.1 while others are licensed under
74the incompatible QPL. See [4] for details.
75
76The version tested was the openscad 2011.06-1+lucid1 Ubuntu package.
77
78
79OpenSCAD front-ends
80-------------------
81
82There also a number of Python-based scripted front-ends for OpenSCAD,
83namely OpenSCADpy [5], PyOpenSCAD [6], and pySCAD [7].
84
85Furthermore, there is Mecha [8, 9] for Haskell.
86
87Cadmium (see below) appears to be on par or better in terms of syntax
88clarity and tidiness than the OpenSCAD Python bindings. Therefore,
89only pure OpenSCAD was considered for this comparison.
90
91
92Candidate 2: Cadmium
93--------------------
94
95Cadmium [10] is similar in concept to OpenSCAD, but uses Python
96instead of a homegrown language. Open CASCADE [11] (via pythonOCC
97[12]) provides the 3D operations here.
98
99The respective licenses are GNU AGPL v3 for Cadmium, GNU LGPL v3 for
100pythonOCC, and a homegrown "LGPL-like" license [13] for Open CASCADE.
101
102The Cadmium version tested was Sun Jul 10 16:04:07 2011 +0530 commit
103d4ff63b150ee060a8179a74e369b5df3d0a4a3fc, with pythonOCC 0.5.
104
105
106Results and observations
107========================
108
109Model development was efficient with both systems, with most of the
110difficulties coming from the task of making the model, not from
111inadequacies of the tools.
112
113Both systems also also produced correct-looking meshes.
114
115Notable differences exist in the time the rendering takes, where
116rough previews with OpenSCAD are instantaneous and proper rendering
117takes minutes, while Cadmium has no preview and the rendering takes
118hours.
119
120On the other hand, some small anomalies could be found in the mesh
121generated by OpenSCAD while the Cadmium's mesh looks perfect.
122
123
124Model development
125-----------------
126
127Both systems offer the same basic CSG primitives and operations,
128which made the model development per se straightforward and the
129porting from one system to the other effortless.
130
131The very quick preview of OpenSCAD is immensely helpful during
132development. The usefulness of the preview is diminished by
133differences only being shown as unions of the solids involved, with
134color indicating their role. It was thus often necessary to isolate
135and simplify elements before the resulting shape could be guessed, or
136to render with slower CGAL.
137
138Given the slow rendering process, debugging non-trivial designs with
139Cadmium is currently quite time-consuming.
140
141Development of the basic model (without chamfers and fillets) was
142first done with Cadmium. I then switched to OpenSCAD to develop the
143more advanced features, and finally ported them back to the Cadmium
144model.
145
146Designing the model elements for filleting and chamfering was
147somewhat awkward with only CSG and - without understanding the
148entire construction process - it may not be easy to see what the
149resulting code does.
150
151
152Modeling language
153-----------------
154
155The limited programming language of OpenSCAD proved to be more than
156adequate for this simple design. To ease comparison and to reduce the
157porting effort, the Cadmium model has the same code structure as the
158OpenSCAD model.
159
160It should be noted that some redundancy could be avoided in Cadmium
161if all the "rbox_*" functions were placed in a common class whose
162objects could then remember the box's geometry for reuse with the
163fillet and chamfer functions/methods.
164
165One nuisance with OpenSCAD is that mistyped variable names merely
166generate a warning but let rendering proceed - often with confusing
167results.
168
169One difficulty encountered when making the Cadmium model was that
170there appears to be no null value for the "union" operation, which
171means functions that generate all their objects in a loop have to
172special-case the first element, making them look a bit awkward (e.g.,
173rbox_chamfer_top_corners). It should be easy to remedy this
174shortcoming.
175
176The Python language also introduces complications to Cadmium that
177OpenSCAD can avoid, such as the Python parser's limited ability to
178detect continuation lines, requiring continuations to be marked with
179a backslash, and the need to pay attention to the mixing of
180floating-point and integer numbers when using divisions.
181
182Cadmium's ability to use short operators instead of blocks generally
183yielded only marginally more compact code, since many operations
184ended up being longer than one line anyway. In fact, the code
185structure often looks a bit tidier in OpenSCAD.
186
187The placement of transformations before creation of the object in
188OpenSCAD e.g.,
189translate(...) rotate(...) cylinder(...);
190is slightly less intuitive than the reverse order Cadmium uses, e.g.,
191Cylinder(...).rotate(...).translate(...)
192
193Furthermore, if each step is placed on a separate line, Cadmium's
194syntax puts the object in a more prominent position than the list of
195translations.
196
197
198Bugs
199----
200
201OpenSCAD got stuck allocating excessive amounts of memory when trying
202to preview with OpenCSG from the IDE.
203
204Cadmium fails at line 113 of button.py if the "noise" parameter
205introduced to work around this bug is absent or set to zero.
206
207The mesh generated by Open SCAD appears to have some small anomalies,
208see section "Resulting mesh".
209
210
211Execution
212---------
213
214On a lightly loaded Intel Q6600, the "high quality" rendering time
215was as follows:
216
217        real user sys
218OpenSCAD 1m25.491s 1m24.990s 0m00.410s
219Cadmium 81m44.408s 81m41.110s 0m01.540s
220
221This is consistent with the time the rendering of earlier stages of
222the design took: OpenSCAD with CGAL was always much faster than
223Cadmium with Open CASCADE.
224
225I didn't attempt to systematically search for costly operations, but
226observed that the crossed cubes/boxes forming the core of the rounded
227box took considerably longer than a run with one of them removed.
228
229
230Resulting mesh
231--------------
232
233The rendering results are available at
234http://downloads.qi-hardware.com/people/werner/cad/test1/
235
236The STL files are scad.stl.bz2 and cadmium.stl.bz2 for OpenSCAD and
237Cadmium, respectively. scad.png and cadmium.png show screenshots of
238the meshes rendered with MeshLab 1.2.2, with double side lighting and
239"flat" rendering.
240
241The two meshes are of similar size, as reported by MeshLab:
242
243        Vertices Faces
244OpenSCAD 3351 7798
245Cadmium 3183 8362
246
247Note that the OpenSCAD model uses a slightly larger number of circle
248segments (explicitly set with $fn) than the Cadmium model (which just
249uses whatever is the default behaviour).
250
251At earlier stages of the design, the Cadmium mesh was found to be
252significantly larger then the OpenSCAD mesh.
253
254Both meshes look clean and at a first glance show now major
255distortions (*).
256
257(*) Note that the model already takes care of avoiding situations
258    where the subtraction of volumes could leave behind solids with
259    the thickness of a rounding error.
260
261When viewed with MeshLab 1.2.2, with smooth rendering and
262"Fancy Lighting", some faces appear to be inverted. These faces are
263shown in red in
264http://downloads.qi-hardware.com/people/werner/cad/test1/scad-reversed.png
265
266A peek at the inside of the OpenSCAD-generated mesh reveals internal
267structures left over from the construction process, as shown on
268http://downloads.qi-hardware.com/people/werner/cad/test1/scad-inside.png
269
270No anomalies could be found in the mesh generated by Cadmium.
271
272
273Conclusion
274==========
275
276In the conclusions, I first consider the relative performance of the
277two CAD system and then reflect on the whether the CSG-only workflow
278as such proved to be satisfactory.
279
280
281OpenSCAD vs. Cadmium
282--------------------
283
284Both systems succeeded in handling the task. OpenSCAD impressed with
285fast response allowing highly interactive development, while Cadmium
286---------------------------------------------------------------------
287soon gets very slow. It is not clear whether this slowness is a
288general shortcoming of Cadmium or whether it is a consequence of poor
289choices made when making the model.
290
291The mesh generated by OpenSCAD shows some anomalies, but it's not
292clear whether they would affect further processing steps, e.g.,
293conversion to toolpaths.
294
295In terms of resource consumption and stability, even this relatively
296simple model exhausted both systems, with OpenSCAD exhibiting
297stability issues and Cadmium requiring excessive processing time.
298
299Both modeling languages can be used in very similar ways and were
300pleasant to use. Python-based Cadmium may be more suitable for tasks
301requiring structured building blocks.
302
303
304The CSG-only workflow
305---------------------
306
307With both systems, translating the mental models of the various
308components into correct instructions was difficult where more
309abstract operations were involved, requiring some amount of trial and
310error.
311
312Also, the resulting code does not easily reveal its purpose and
313textual comments are an unsatisfactory means of illustrating
314geometrical properties. (As an example, consider the above section
315"Object description".)
316
317A workflow that includes distinct steps with a visual representation
318of intermediate results, e.g., instead of CSG, using extrusion with
319shapes and paths generated by some 2D CAD system, may be less
320demanding.
321
322Also, while generating the basic shape was very easy, most of the
323work went into the addition of fillets and chamfers. Neither of the
324two systems provides operations to automate such tasks.
325
326
327The story continues
328-------------------
329
330Later experiments showed that small changes to the model can lead to
331quite different and generally better results. The continuation of
332this evaluation is at
333http://projects.qi-hardware.com/index.php/p/wernermisc/source/tree/master/cad/test2/
334
335
336References
337==========
338
339[1] http://www.openscad.org/
340[2] http://www.opencsg.org/
341[3] http://www.cgal.org/
342[4] http://www.cgal.org/license.html
343[5] https://github.com/hmeyer/openscadpy
344[6] https://github.com/etjones/MCAD/tree/master/PyOpenScad
345[7] https://github.com/kevinmehall/pyscad
346[8] http://hackage.haskell.org/package/mecha/
347[9] https://github.com/tomahawkins/mecha/blob/master/Language/Mecha/Examples/CSG.hs
348[10] http://jayesh3.github.com/cadmium/
349[11] http://www.opencascade.org/
350[12] http://www.pythonocc.org/
351[13] http://www.opencascade.org/getocc/license/
352
353---------------------------------------------------------------------
354

Archive Download this file

Branches:
master



interactive