Search code examples
openscad

How to modify imported .stl files in OpenSCAD?


Is there anyway to go about importing STL files into OpenSCAD with the ability to modify them?

For instance, the following code demonstrates what I have tried thus far:

difference() {
    import("spherical_puzzle_base.stl");
    translate([0, 0, -RADIUS/2]) {
        cube([RADIUS*2, RADIUS*2, RADIUS], center=true);
    }
}

When I do this I can either hit F5 to render the STL file only which doesn't include the intersection. Or I can hit F6 to compile and render, but it creates a very messed up rendering, no where near manifold or even close to what I would expect for that matter. Is there a solution to this problem using OpenSCAD? Thanks!

(I am attempting to do it this way to save long rendering times, especially while I am testing various design possibilities)


Solution

  • I was not sure, whether modifications of stl-models by boolean operations are possible. Boolean operations in openscad are part of csg-modelling. With csg only 'primitive solids' as 'cube', 'sphere', 'cylinder' or 'polyhedron' can be combined.

    To verify in openscad 2014.01.29 i tried this:

    translate([10,10,0]) polyhedron( points=[ [10,10,0],[10,-10,0],[-10,-10,0],[-10,10,0,[0,0,10]],
    triangles=[ [0,1,4],[1,2,4],[2,3,4],[3,0,4],[1,0,3],[2,1,3]]
    );

    export as 'polyhedron.stl' and then:

    difference() {
        import("polyhedron.stl"); 
        translate([5,5,0]) cube([10,10,10]); 
    }
    

    i got the correct result (with other, more complex stl too) and i could export them to valid stl-files. Only on screen in openscad some faces seemed to be transparent or damaged. So i think, openscad treats stl-files in boolean operations as 'polyhedron' and you can modify your stl in your way.