xyz-tools / gcode-preview

A simple GCode parser & previewer lib with 3D printing in mind. Written in Typescript.
https://gcode-preview.web.app/
MIT License
160 stars 31 forks source link

Add STL export button #249

Open remcoder opened 4 days ago

remcoder commented 4 days ago

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 commented 2 days ago

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

Some observations:

All in all a first successful result!

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

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 commented 2 days ago

I did a second test with these changes:

Initial slice:

Processing

Observations:

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 commented 2 days ago

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.