[OpenSCAD] Working with imported STLs

Jamie Bainbridge jamie.bainbridge at gmail.com
Mon Apr 16 06:50:52 EDT 2018


On 16 April 2018 at 10:58, kerog <kerog777 at gmail.com> wrote:
> I recently tried to bring in an STL with an import command and then slice it
> up using difference commands in order to get something that I could make a
> multicolor part.  I know I've done something like this in the past and had
> it work, but even though I was able to quick render OK (F5) a full render
> seemed to ignore the differencing that I had done.  Is there some sort of
> restriction on using difference() on imported objects?

The way I understand it, OpenSCAD doesn't work this way.

When you design parts with code using CSG then export them to a
manifold mesh, the triangles which make up the mesh are generated at
export time. Everything is (hopefully) a valid manifold shape.

However, when you import an STL you're bringing in a manifold mesh
which is a fixed object. OpenSCAD doesn't see the STL as a CSG object
which it can modify.

Then you erase parts of the STL or tack bits on. When the mesh is
generated at export time, your CSG objects have their triangles
created plus the STL (or what's left of it) is defined as a separate
shape to the SCAD CSG objects.

For example, if you a hole in an STL file, you've essentially just
erased a bunch of vertices and faces, so the part is not a manifold
mesh anymore, plus OpenSCAD has added the "shell" of the hole as a
separate mesh. It looks okay to the eye but as far as the software is
concerned it's not okay at all.

You can run STLs made this way through NetFabb Online Service with a
reasonable degree of success: https://service.netfabb.com/

However, I find it better to use Riham's STL-to-SCAD converter:
http://jsfiddle.net/Riham/yzvGD/

This converts the triangles of an STL mesh into an OpenSCAD polyhedron
which IS then seen as a CSG object just like any other cube() or
cylinder() or sphere().

Now you can cut parts out of that polyhedron or add parts to it and,
providing you code your difference()s and union()s correctly, OpenSCAD
can generate a valid manifold mesh on export.

STLs with high triangle counts will result in complex polyhedrons
which will make your PC chug. Consider reducing the triangle count
(known as "decimating") if it doesn't affect your part quality or
dimensions too much. You can do this with MeshLab which is also Free
Software: https://www.shapeways.com/tutorials/polygon_reduction_with_meshlab

Jamie



More information about the Discuss mailing list