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.65k stars 514 forks source link

exporting non-STL formats causes slicing issues #1262

Open tsdexter opened 1 year ago

tsdexter commented 1 year ago

Is there a way to download an STL with multiple parts? I'm using the mentioned model below as part of a multi part model with parts that fit exactly together (ie: the word is cutout of a box but also placed exactly back inside as a separate model for easy colouring in the slicer), when I download as an STL and import it's all one solid object with no word or separate parts.

This is causing me to have to use 3MF as file format, which does separate parts well, however, it presents the issue below:

Expected Behavior

Exporting an STL or a 3MF should export a file that slices the same

Actual Behavior

STL slices good, but 3MF or AMF have some weird features and cannot be printed. The geometry looks the same in all 3 files, ie:

image

However, once I sliced it the 3MF and AMF have some weird features that make them unprintable:

image

Notice:

Steps to Reproduce the Problem

  1. Use the model https://gist.github.com/tsdexter/add64749db71add39908f6640fef20c3
  2. Export STL/AMF
  3. Import and slice

Specifications

tsdexter commented 1 year ago

note: if I exported the name and the box with the name cutout separately as 2 STLs and then import them into BambuStudio slicer at the same time and select 'yes' to "do you want to load these files as 1 object with multiple parts" they import well and I can easily colour just the name, however, this means I have to export twice, once with each part commented out. Ideally there is someway to easily export it (via CLI) once and get multiple files.

z3dev commented 1 year ago

@tsdexter You are correct. STL does not support the concept of parts, just one mesh.

You can use DXF, 3MF, or X3D to exports parts. Of course, you design should return an array of parts from main(). Most people assign colors to each part in order to see the parts in slicers.

We can probably help out if you can provide the exported 3MF file.

tsdexter commented 1 year ago

@z3dev thanks for the quick reply.

Here are all the exported formats: https://drive.google.com/file/d/1p2cjMt2xzQUMMU-qf7eIRQ2bsf2_WSLT/view?usp=sharing

tsdexter commented 1 year ago

@z3dev it appears to be an issue with non-manifold edges... the 3mf has roughly 10x as many non-manifold edges as the stl does, see: https://github.com/bambulab/BambuStudio/issues/1955#issuecomment-1605828993

Also noticed that Cura slices the 3mf fine but Bambu/Prusa do not, I think this is because Cura "fixes" the model, whereas bambu/prusa do not (at least not on mac yet)... any ideas about the non-manifold edges?

As well, I've added a PR to get around this issue for me, for now. It adds multipart -> multiple files to the CLI export see https://github.com/jscad/OpenJSCAD.org/pull/1263

z3dev commented 1 year ago

@z3dev it appears to be an issue with non-manifold edges... the 3mf has roughly 10x as many non-manifold edges as the stl does.

That would be strange as both exports start with snap & triangulation.

Do you mind adding one more format; JSON? This will export the exact shape of the geometries being created. I'd like to see the results of the design.

tsdexter commented 1 year ago

@z3dev json should be in the zip file on the google drive link, also here: https://gist.github.com/tsdexter/add64749db71add39908f6640fef20c3

tsdexter commented 1 year ago

@z3dev I don't know a tonne about the math/mechanics of generating the underlying model but I've colorized all the polygons to visualize it a little better, it looks like it's making faces with many vertices rather than triangles, which I think explains all the non-manifold edges... is this normal or should it be making triangle faces/polygons to avoid non-manifold?

I'm getting the shape by extruding a path2
image image

tsdexter commented 1 year ago

actually, it looks like it triangulated the polygons during export, so perhaps that's irrelevant?

z3dev commented 8 months ago

@tsdexter i took a longer look at this, starting with the JSON file which was uploaded. The JSON format should export the 3D model as represented internally in JSCAD. I was able to export both as STL and 3MF.

I opened the STL in Meshlab (probably the best mesh application), and examined the STL. Meshlab did not find any issues with non-manifold vertices or faces. That's a good sign.

Then I opened the 3MF in PrusaSlicer (It's probably my favorite). PrusaSlicer (and Prusa) recommend 3MF for all multi-color 3D models, and I test with this often. PrusaSlicer didn't have any issues with the 3MF, and sliced the model perfectly.

So... what to look at now? If you can provide the JSCAD code, or maybe the starting SVG then I could investigate further.