Hello there,
I am trying to design a virtual 3d printer.
The problem is i don’t know how to convert Gcode commands to commands for the nozzle and make an animation with the part being printing layer by layer i fast forward of course.
According to this moment i am experimenting on this 3d printer slicer for unity(see the photo).
This project takes an STL file and converts that to a Gcode, so the part of the slicer is partially solved.
A Gcode Viewer for unity what i need.Do you have any suggestions on how to approach that?
Uh, gcode does not store geometry. It stores printer nozzle movements and printing commands.
So you’d need to find a gcode parser. Or write one.(it is a text format, so not too difficult)
CURA, for example, just renders 3d lines for ALL nozzle movements. You could do the same, but it absolutely will not produce a normal 3d model.
Ahh, didn’t know.
Not sure if there are any made already
Assuming that 3D printers work approximately to a grid, I would guess that you could:
- Find a voxel rendering or voxel mesh generation library.
- Create a voxel grid which matches the size and resolution of the printer.
- Use the recorded nozzle movements to fill in that grid.
I assume it’ll be a really dense grid, so you might need a fairly well optimised voxel library.
Depending on your use case, a “point cloud” may also be effective.
A 3d printer is going to have sub-millimeter precision and a field size in ballpark of 20x20x20 cm. So you’re looking at a voxel cube with edge length of 2k voxels.
Having said that, it IS possible to fit something like that into ram on a modern computer (8 gigabytes), but polygonizing it is definitely going to be fun. One other interesting thing is that modern slicers do not slice things as solids. Interior of anything is going to be filled with something like gyroid. ( https://en.wikipedia.org/wiki/Gyroid ), and if you’d try to polygonize that head on, all this stuff will be generating faces.
So, I’d r ecommend to stick with cura approach, which looks like this:
You could probably give it appearance of a solid by rendering it with something like screen-space metaball shader.
Righto. I imagined that voxel libraries would cover that stuff - sparse volume or RLE compression, and efficient surface meshing - but I guess not?