Pages

Wednesday, October 19, 2011

Say goodbye to unsightly STL triangle misery! Forever!


I downloaded Rupert Rawnsley's OpenSCAD Horizontal Spool Holder from Thingiverse and  printed it on one of my Prusa Mendels.  Nothing unusual about that.

Except that at no point in the making-chain from Thingiverse to the finished printed object was an STL file used to do the calculations.  The spool holder was printed directly from OpenSCAD's CSG representation.

Printing directly from CSG is much more robust than using the flakey (literally) STL file format.  A CSG file can be wrong - we can all make mistakes - but, unlike STL, it always represents an unambiguous solid.

It should also be faster.  I'll do some timings and post them later.  Finally, it should allow us easily to do fancy things like filling solids with scalar and vector fields representing build parameters, so you can have an object that is flexible (and/or green) at one end and rigid (and/or blue) at the other.

I built a simple CSG modeller into the RepRap Java Host Software.  I added a parser that directly reads the CSG generated by OpenSCAD into it.  (The software still uses the STL too, but just as a bunch of triangles for display on the screen; STL takes no part in the build process.)  At the moment the supported OpenSCAD primitives are cubes, cylinders (including frustums and cones), and spheres. I will add extruded polygons, extruded imported DXFs, polyhedra, and imported STL files later (in that order, which is also the order of difficulty of doing them...). Note that the final one of those will implicitly (there's a mathematical joke there somewhere) allow any STL file to be converted to CSG.

Just like the CSG processor at the heart of OpenSCAD, the software is essentially a re-implementation of my old friend John Woodwark's DORA CSG modeller (Divided Object Ray-tracing Algorithm) from the early 1980s (see here).

For instructions on how to use all this, follow this link...

Stop Press: 

Marius has just upgraded OpenSCAD to make things even easier.  The OpenSCAD Github master now has:

$ openscad examples/example001.scad -o out.csg

..or Design->Export as CSG

18 comments:

  1. If only OpenSCAD would *export* it's CSG-solid into *any* of the common file formats used for this.

    ReplyDelete
  2. Well. The parser for the "Display CSG" thing that OpenSCAD does do is very simple. Point me to a format, and I might see if I can write it, then read it.

    ReplyDelete
  3. Great! And did the output printed object look any better? especially the outer radius?

    ReplyDelete
  4. Adrian - the IGES documentation, one of the two most commonly used CAD exchange formats (STEP/IGES), can be found at http://ts.nist.gov/standards/iges/

    Best!

    ReplyDelete
  5. Marcus: Do you have any concrete suggestions for common file formats used for CSG representation? It would be interesting to add to the list of things to look into.

    ReplyDelete
  6. Yes - I know about IGES and STEP; but I have never found an example of their being used for direct CSG representation (as opposed to doing CSG combinations of a load of B-Rep nonsense). They should have it in there somewhere, though. If you can point me to a STEP file (preferably) that shows a complete CSG representation of something simple (say a cylinder subtracted from a cuboid), I'd be most grateful...

    ReplyDelete
  7. @RichRap - in this case the output was identical, because in this case the OpenSCAD STL file was solid. But the amount of code being executed to do the work is - I estimate - about 30% of the complexity, and with far fewer infelicitous approximations and heuristics.

    ReplyDelete
  8. Timings - it's only about 5% faster. I had expected more, but there you go...

    ReplyDelete
  9. Excellent! Saw this in the checkin comments the other day - glad to see it out!

    ReplyDelete
  10. Svlis man. Use svlis.

    Direct slicing baby!

    ReplyDelete
  11. would someone be so kind to explain to me how to Design->Export as CSG when the version on Openscad that I have has not option for exporting a csg file. I'm a newbie at this 3D software, I apologize if this is a stupid question.

    ReplyDelete
  12. The version I downloaded was openscad-2011.06.win32-installer.exe
    for windows, as I found downloading and installing the other programs a bit confusing.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Wow - I find the idea of running an STL through the final process meassively appealing. That's a really significant branch of processing - akin to NURBS and car show rooms perhaps?

    ReplyDelete
  15. First, there's a nice replacement for good old STL already standardized and it's called AMF (http://amff.wikispaces.com/). Secondly, the intended inclusion of "imported STL" in CSG format will not solve the problem of "unsightly triangle misery" unless a sophisticated reverse engineering procedure will be able to convert STL surfaces into solids defined in CSG or B-rep.

    ReplyDelete
  16. Adrian I am not sure if any of these help with STEP files and CSG representation but see

    http://www.cmiss.org/cmgui/wiki/sphtorrectcylstep/view

    Also
    http://wheger.tripod.com/step/

    ReplyDelete
  17. Er, above link is incorrect. It should be: http://amf.wikispaces.com/

    ReplyDelete
  18. It's good point to avoid stl, but what do you think about this?
    if all of us will develop and support some union format, this can optimize even more (not using the polygons approx, use the exact geomerty for slicer)
    https://github.com/openscad/openscad/issues/1650

    ReplyDelete