gcode-preview icon indicating copy to clipboard operation
gcode-preview copied to clipboard

Add STL export button

Open remcoder opened this issue 1 year ago • 6 comments

Based on an idea by @merlin-dev-33:

What: The idea is to be able to export the currently viewed model as a 3d object. So from gcode to STL for instance.

Why: The reason is to use the tube rendering to create a new version of the model. One application would be to first slice a model with exaggerated layer line height/width, import it into gcode-preview, export the generated mesh consisting of tubes, and the slice and print on a regelar printer with normal sized nozzle.

How: There is an STL Exporter included in Threejs. It requires access to the Scene or the Mesh that is to be exported. The Scene is already exposed by the lib but the 3DObject that represents the loaded model isn't exposed explicitly so we need to traverse the Scene or expose the model explicitly.

V3: Since we have an alpha for the new v3 version ready let's build this on top of that. No new dev work should be done on v2.

remcoder avatar Nov 09 '24 13:11 remcoder

I did a first test and managed to export the scene as an STL: model_binary.stl.zip

Some observations:

  • the file size is increased. original STL: 11MB, export 26MB. (Both binary)
  • the exported model can be imported in a slicer and sliced 🎉
  • the slicer complained about 100k+ non-manifold edges
  • there was a purge line that was generated in the original slice. This should be disabled to prevent issues.
  • I had trouble laying the exported stl flat in the slicer.. Could be due to the purge line or the non-manifold edges. I'll need to take look at this.

All in all a first successful result!

I'll need to do some more tests with some changes

  • original slice with a higher layer height
  • no more purge line

And I wonder if the 'non-manifold edges' situation will cause issues. This is happens because the gcode preview doesn't create a closed mesh. The tubes are open at the start and end. It didn't seem to matter when slicing the exported stl but we have to pay attention to this.

remcoder avatar Nov 11 '24 13:11 remcoder

I did a second test with these changes:

Initial slice:

  • layer height 1mm (previous was 0.2)
  • layer width 1.1mm (previous was 0.45 I think)
  • removed the purge line

Processing

  • Then loaded into gcode preview,
  • adjusted the line width in code,
  • exported it as STL
  • and loaded it up in the slicer again.

Observations:

  • the model can now be laid flat (prob due to removing the purge line) 🎉
  • gcode preview (V2) doesn't read the layer width from the gcode file so this needs to be adjusted
  • the lines aren't round tubes but rather have a diamond profile.
  • the lines have gaps when viewed from the side
image

The weird thing is that the gaps are not visible in the gcode preview. So I'm going to look at this next.

remcoder avatar Nov 11 '24 15:11 remcoder

Conclusion, I willl a add an export button to the demo but for the feature to be usable the gaps need to be fixed too.

remcoder avatar Nov 11 '24 15:11 remcoder

Some progress: #253 was fixed, meaning that I can go forward with this.

remcoder avatar Dec 12 '24 21:12 remcoder

Some progress: here's a demo (not THE demo but a simple example) that has an export button.

To make this work completely, a variable layer height and line width will need to be supported. We should add those to the main demo.

remcoder avatar Dec 17 '24 16:12 remcoder

Another thing that will make these export print better is to increase the tube segments, to make the tubes more round. Right now the cross section is a diamond (4 vertices). Increasing this to 6 or 8 or even just rotating them 45 degrees will make the rendered 'print lines' have less overhangs.

remcoder avatar Dec 17 '24 20:12 remcoder