Hey! This thing is still a Work in Progress. Files, instructions, and other stuff might change!


by joshuaf Jan 22, 2016
Download All Files

Thing Apps Enabled

Please Login to Comment

For somebody looking to use this to create an editable version of an STL file, it may require more work (more than just the command).

I converted an stl file to increase the size of some of the holes, and after a long time finally realized the issue that the scad file's faces are reversed (they need to be defined in clockwise direction, where this defined them counter clockwise). I later gave up (as it was a very complex shape with too many triangles to manually reverse all of them) and used other software.

Basically each face is a triangle, each point is a reference to an x,y,z coordinate defined at the start of the file. For an example now take a triangle where 1 is bottom left, 2 is top center and 3 is bottom right - if we define them as [1, 2, 3] it is correct, same [2, 3, 1] and [3, 1, 2]; but the following is incorrect (reversed face) [3, 2, 1], [2, 1, 3] and [1, 3, 2].

If you are using a not very complex file, it may be easy to just edit it manually (basically changing any 2 of the 3 references around) to get correctly orientated faces.

Still thank you for helping and making it easier to edit stl files.

I've updated the stl2scad.py file with the fix. After researching various explanations of the STL file format, I've concluded that the vertices should always be read (from an STL file) in counter-clockwise order, when viewed from the outside. That is the opposite of how they were being handled.
The STL file may also include a normal to indicate the direction, but it is intended to be redundant to the counter-clockwise rule, so unnecessary to check for these purposes.

I've researched this further and confirmed that the file I referenced does have the same problem. It is only visible when you use the View - Thrown Together option in OpenSCAD. Outward faces should be the brownish-yellow color. If you see pink faces on the outside, the vertices are in the wrong order.
Also, the STL file should have enough information to determine the proper order, by using the specified normal.
I wrote up my findings here: https://github.com/joshuaflanagan/stl2scad/issues/2
I'll post an update when I get a fix.

Thanks for the feedback. It sounds like you may be describing the same issue that was mentioned on the original thing: http://www.thingiverse.com/thing:64709/#comment-543787

It sounds like sometimes all of the faces get reversed. I could add an option to the software that will reverse them all for you. I'm wondering if there is something in the STL file that indicates the order, but I'm not picking up on it. Will need to research further. Ideally, the software would automatically determine the correct direction. But do you think a simple flag (-R) that reverses the faces direction would solve your problem?

Do you have an example of a problem STL you can provide? I ran stl2scad on the iPhone case in the thing I mentioned in my last post, and it rendered just fine in OpenSCAD. I'm assuming a symptom of the problem is that the model will not render in OpenSCAD.
If you can provide a "problem" stl file and tell me the behavior you are observing, and what you expect to see instead, I can try and work on a fix.

A flag like that can be a temporary solution (until someone somehow figures out how to get the correct order from the stl file).

Curious can this convert scad to stl?

This is the purpose of OpenSCAD ;o)