VR GCode Viewer

One of the common steps that anyone familiar with 3D printing has experienced is that of slicing the model they wish to print – that is, running it through a slicing program that will convert the geometry of the model into a series of toolpath motions for the 3D printer to enact.

A preview of a rook model sliced in Simplify3D.

It’s at this stage of the process that you can see exactly how the printed object is going to be constructed. You can see where and how the extruded plastic will be deposited, and it’s at this stage that it’s a good idea to check over the sliced output and make sure there’s nothing unreasonable in there – nothing that the printer would struggle to do.

However, there are a few things that are missing that I thought would be interesting to play with.

Firstly, there’s no real sense of scale – you’re just looking at a flat model on your computer monitor, and it’s sometimes tricky to get a feeling for the size of the different features of a model.

Secondly, while the outside of the model is easy to inspect, the inside is less so – you can get a top-down cross sectional view, but that’s not always sufficient for looking at exactly how everything will behave.

Since I’d been playing around with a lot of Virtual Reality stuff recently, mostly with the HTC Vive but also a little with the Oculus Rift, and had tried my hand at a little VR development – I thought maybe I could do something fun here.

So, I put together an application using Unreal Engine 4 that allows the user to open sliced .gcode files, and preview them in virtual reality. I put together the initial demo video below.

In the video, I open the model of the rook that I sliced in the earlier image using Simplify3D. The model is virtually constructed, one piece of plastic at a time – much in the same way a 3D printer would construct the physical model, actually – until the whole model is instantiated and held in memory. I’m then able to move around the model, scale it, look inside, and explore it from a first-person perspective.

Because each and every bit of plastic is represented, this is quite a graphically intensive program to run. With the model of the small rook, I was seeing acceptable performance – with larger models, I ran into trouble quickly. I spent some time optimising the performance – game engines and rendering are not my forte, but I was able to make some small improvements. I also added in some extra features I thought would improve the experience. This resulted in an updated version, shown below.

In the updated program, I added a menu that allows the user to select the model to be previewed (previously, it took the first file found in the program directory). I optimised the drawing behaviour of the plastic and overhauled the code that constructed the virtual model. This resulted in a nice boost to performance – it’s still very heavily bound by GPU power and memory, but I was able to push it further than I could previously, and opened some much larger files.

This castle is an order of magnitude more complex than the rook I sliced earlier.

I also added the ability to preview not only the extruded plastic, but also the travel moves the print head makes. This can be useful when you want to get an understanding of exactly what is going on within a sliced model.

The blue lines represent travel-only moves. The red represent moves where plastic is extruded.

At this stage, I had a fairly usable application for previewing sliced models in Virtual Reality. I tidied up what I had, made a compiled version for people to download, and wrote up some basic documentation – and have it all hosted on GitHub, here. Anyone who is interested can download it and give it a shot!

Leave a Reply

Your email address will not be published. Required fields are marked *