jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.63k stars 512 forks source link

OpenJSCAD exports incorrectly-formed STL #40

Closed swsnider closed 7 years ago

swsnider commented 10 years ago

When I export STL from the program (using the openjscad.org site)

function main() {
   return difference(
         cube({size: 3, center: true}),
         cylinder({r:1, h:3, center: true}).rotateX(90)
      ).translate([0,0,1.5]).scale(10);
}

I get an mesh that looks like this:

bad_example

Note that the face with the hole has a bunch of triangles that do not share two vertexes with each neighboring triangle, in violation of the page at http://www.ennex.com/~fabbers/StL.asp, which is the most authoritative page I can find on the STL format.

If I use tinkercad.com to create the equivalent object, I get a mesh that looks like

good_example

which correctly ensures that each neighboring triangle shares two vertexes.

Normally, I'd consider this a nit-pick, but my slicer I'm developing is choking on the input that violates the STL format because I'm using an optimization that's only possible with well-formed files.

swsnider commented 10 years ago

With the program

translate([0,0,1.5]) scale(10) difference(){
         cube(size=3, center=true);
         rotate(a=90, v=[1,0,0]) cylinder(r=1, h=3.5, center=true, $fn=20);
      }

openscad generates a mesh that looks like this

good_example_scad

so this seems to be a diversion from that behavior as well.

z3dev commented 9 years ago

It would be a nice rosey world if all software packages interacted together and create perfectly formatted files. I still haven't found a 3D design tool that creates perfectly formatted STL files, and therefore always "clean" all STL files, especially before slicing for 3D printers.

FYI, I ran the "incorrect" STL file through Netfabb (https://netfabb.azurewebsites.net). I think that you would be surprised at the results.

I don't think that OpenJSCAD should create perfect STL files, as the internals are quite different. Something that can be "read" as STL is sufficient. My favorite application for reading various formats is Meshlab.

swsnider commented 9 years ago

This is different than not being 'perfectly formatted'. If you read my bug above, you'll note that the output STL describes a different shape than the user instructed it to create. This is a bug, not an issue of formatting. It's great (truly!) that people have created STL fixup tools, but that doesn't mean this isn't a bug.

z3dev commented 9 years ago

So, just to be clear. You are saying that the STL file is NOT "well-formed", i.e. the output is not following the rules of STL. And that OpenJSCAD.org is not formatting the output correctly. i.e. there are triangles that do not share two vertexes with neighboring triangles. There's a related issue about STL as well, #9 . Can you take a look at that as well? FYI, the STL file output is created as part of the CSG.js library, which as all export functions defined in format.js.

swsnider commented 9 years ago

What I'm saying is that the STL file describes a shape with slits along two of the cube's faces. This could also be viewed as a problem where there exist triangles that do not share two vertices with neighboring triangles.

This is not a normals issue, although that may also be wrong with this file. This is purely a bug report about an incorrect shape being output.

z3dev commented 8 years ago

Pull request #107 contains some changes to CSG.js and openjscad.js. I ran some tests and all issues with T-junctions were resolved after making those changes.

If you need this fixed then please make the changes manually.

z3dev commented 7 years ago

This issue was moved to jscad/io#16