Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: GCode Exporter #17981

Closed
LetsPrint3D opened this issue Nov 22, 2019 · 14 comments
Closed

Feature Request: GCode Exporter #17981

LetsPrint3D opened this issue Nov 22, 2019 · 14 comments
Milestone

Comments

@LetsPrint3D
Copy link

LetsPrint3D commented Nov 22, 2019

ThreeJS is widely used across a range of web based tools for 3D Printing, CNC, etc. and utilizes the STLLoader / GCodeLoader and STLExporter for a variety of operations.

However, GCode is the necessary file type that 3D Printers actually read, where an exporter would drastically enhance the potential capabilities of these tools. Ultimately allowing for 3D model conversions from a number of other file types, although most commonly from an STL import -> GCODE export.

For a more detailed explanation of G-Code commands...
http://marlinfw.org/docs/gcode/G000-G001.html
https://reprap.org/wiki/G-code

As a whole, the primary command is "G1" which is simply used to move between coordinates. I have attached a sample G-Code file of a cube for reference.
cube.zip

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 22, 2019

Isn't using using 3MF more future-proof? According to this article:

At the moment, your CAD software usually works with other formats than .stl for a variety of reasons. Most construction software can actually output .stl files though. Your printing software takes the .stl files and slices them, in most cases to G-code format; these sliced files which can have numerous endings, such as .mpt, .mpf .nc and others. The .3mf format will put an end to the variety of files needed for the whole process of construction, modification and manufacturing of 3D models, according to the consortium.

@LetsPrint3D
Copy link
Author

LetsPrint3D commented Nov 23, 2019

3MF will likely become more widely adopted in the next couple of years, but it's barely a consideration for the average person right now. The most popular 3D Model file sharing sites like Thingiverse and MyMiniFactory have hundreds of thousands of freely available designs, almost all posted as STL files.

You download the STL file you want to print, plug it in the slicer software and it spits out a GCODE file your 3D Printer can use.

Over time I could see the format change and be replaced by something like 3MF, but we're a long way out from that still. Certain software (ex: Cura) and sites (ex: PrusaPrinters) have recently added support, but the actual usage of this hasn't really caught much attention.

@mrdoob
Copy link
Owner

mrdoob commented Nov 24, 2019

So basically you're asking us to write a slicer in js, right?
Doesn't sound super easy, but maybe someone would like to give it a go.

@LetsPrint3D
Copy link
Author

LetsPrint3D commented Nov 25, 2019

As there is already a G-Code Loader for ThreeJS, I was under the impression it would be relatively straight forward to make an exporter as well. I'm sure that is a naive way to look at it, but was hopeful.

I have very limited experience working in 3D space, can only comment in regards to G-Code itself. In a nutshell though, it basically picks a starting vertex at the base of the mesh and moves around the X/Y axis, writing each individual point to file with the "G91 X0.0 Y0.0" move command. When it gets back to the start point, it raises the Z axis by whatever increment is specified (layer height) with "G91 Z0.0" for example, and then repeats until completed.

The only complexities I can really see would be Start/End scripts. Basically a set of various commands inserted in the head/foot of the file that run before and after the print. I would imagine just taking a parameter array of startCommands and endCommands would be sufficient.

@mrdoob
Copy link
Owner

mrdoob commented Nov 25, 2019

Sounds like you are halfway there then. Would you like to give it a go using the loader as reference?

@jgphilpott
Copy link

@LetsPrint3D has there been any progress on this since 2019? I'm also very interested in this feature and willing to help out if possible!

@mrdoob
Copy link
Owner

mrdoob commented Aug 29, 2022

We now have three-mesh-bvh which should make things much easier:

https://gkjohnson.github.io/three-mesh-bvh/example/bundle/clippedEdges.html

@jgphilpott
Copy link

Okay thanks @mrdoob I will take a closer look at it over the weekend. It still feels like an enormous task to generate machine usable Gcode from this but I will press onward.

Currently im exporting my scene to an STL or OBJ file and then slicing it with software like Cura or GoSlice. But I want to be able to do it all in the browser for a more seamless user experience. Considering the size of the 3D printing industry im surprised how hard it is proving to find a decent slicing library for the browser.

@mrdoob
Copy link
Owner

mrdoob commented Aug 30, 2022

/cc @gkjohnson

@gkjohnson
Copy link
Collaborator

I know nothing of the GCode format but from the loader example it looks like it's just a series of nozzle movements for each 3d printed layer of the object. As @mrdoob mentioned the three-mesh-bvh example can be used to very quickly derive the series of outline edges for each layer and then they can be sorted into coherent sets of connected lines for each layer.

The hard part, though, seems like optimizing the line order for speed, safely generating the paths to move the printhead between points to start / stop printing, and generating an internal structure for hollow models so they don't collapse or are at least solid. For that last point three-mesh-bvh can be used to determine the inside and outside of the model quickly (see the voxelization example) which may help. It would be worth looking into how some existing tools generate the structures for this.

@yomboprime may have some more insight here since they've worked on generating 3d print files previously, as well.

@yomboprime
Copy link
Collaborator

@gkjohnson You're right, a GCode slicer (FDM technology) is way more complex than a resin print slicer (which is what I did on that tweet). There are a lot of parameters involved in generating GCode. Just take a look at the configuration menus of Prusa Slicer or Cura Slicer. For many years new complex algorithms have been developed, like new infill patterns and the recent Arachne technique. They're way beyond my capabilities.

@jgphilpott
Copy link

Okay @mrdoob i've taken a closer look at this and three-mesh-bvh definitely looks like an essential tool for anyone wanting to develop Gcode slicing software in JS. I'm also interested in three-bvh-csg since the tool im working on already uses csg, @gkjohnson thanks for these!

@yomboprime your MinceSlicer is essentially what i'm looking for except with FDM support and without the GUI. I have an Ender 5 Pro and I want to be able to export directly from my three.js scene to a Gcode that I can use on it. Thus eliminating the need for intermediary file formats like STL and OBJ as well as other slicing software like Cura.

It's definitely possible, if you start with very simple objects like a small cube or cylinder. Then gradually scale up the complexity and number of settings you can support, but undoubtedly an enormous task with many unforeseen challenges!

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 23, 2024

Closing. A GCode exporter is too specific for this repository. This should be maintained in a separate one and then an external example can be added like with IFCLoader.

@Mugen87 Mugen87 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
@Mugen87 Mugen87 added this to the r170 milestone Oct 23, 2024
@jgphilpott
Copy link

FYI, for anyone who comes across this thread. I am working on this issue here, but im not very far along yet. Between work, family and my other projects it's hard to find the time but ill keep working on it and im also very willing to contribute to another project that's further along. Im focusing on FDM cuz thats what I have but it would be awsome to have a universal slicer that's three.js compatible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants