Three.js: Feature Request: GCode Exporter

Created on 22 Nov 2019  路  5Comments  路  Source: mrdoob/three.js

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

Enhancement

Most helpful comment

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

All 5 comments

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.

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.

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.

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.

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

Was this page helpful?
0 / 5 - 0 ratings