Pixels to 3D Objects?
It started off as a simple project to convert some much loved 8-Bit characters to 3D objects that could be printed on a 3D printer.
I’d fire up my favourite CAD Program ViaCAD12 Pro and start creating simple cubes for each of the sprites. Export to STL (Standard Tessellation Language), Slice in Cura and print to one of my FDM Printers. My resin printers are out of service at the moment since my operation, and I’m unable to get to them.
I’d been wanting to find a project to use the couple of rolls of Glow in the Dark Filament from Geeetech and this was perfect.
Knocking out the CAD models was easy enough and not very time consuming, printing took up to 8 hours depending on the size model. I shared these with some FB Groups, with some positive feedback.
Of course, more complex models like “The Priest” from Jet Set Willy would be prone to making modelling mistakes, and I did! Realising only after the initial print.
There has to be an easier way? I needed something to convert PNG Images to 3D Objects quickly and easily. I found a couple of on-line tools, one charged the other looked a bit ropey, so I thought, damn it, I’ll write my own… The PNG2OBJ Project was born.
I chose Python for maximum portability across multiple architectures, making the code Open Source which can be found here: https://github.com/muckypaws/PNG2OBJ
This will take a PNG image and convert any pixels to a 3D cube. It currently has limitations, assuming that Black is the background colour, and any non-black pixel (Non-Zero) is taken as a pixel present. This approach works well for 80’s retro games I was working on, but won’t work so well on multi-colour images (yet).
The program is simple to use, at the command line issue :-
./python3 PNG2OBJ filename or ./PNG2OBJ filename for linux users.
It only works with PNG Files, and don’t provide the “.PNG” extension of the filename. As a result two files will be created. FILENAME.TXT and FILENAME.OBJ
Filename.TXT is used for debugging purposes and shows in ASCII what the program saw.
Filename.OBJ is the Wavefront 3D Object File that can be used in Blender, zBrush, CAD Programs, pretty much anything that reads standard OBJ Files.
The first iteration of the program worked as expected, though larger images would slow ViaCAD down for reasons unknown. Blender and zBrush coped perfectly well.
Although the program did it’s job and created a 3D Obj file, the challenge was hatched pattern pixels as you can see in the Zub character. Printing them meant that a properly calibrated printer would result in lots of small cubes that didn’t adhere together. To work around this I added a parameter to the code :-
JOINTS_REQUIRED = True
What this does is detect a hash pattern and add a support connecting block between the cubes, which will print and add strength to the models. It’s not perfect but will create what’s needed to print the model with a degree of stability.
Not bad for a Newbie Python Coder. The code could do with improvement, allowing for detection and separation of different coloured pixels to make layered 3D Models, command line parameters and more, and who knows, maybe the community will improve on it, or I will as the need arises.
Here’s some of the work I’ve created, which I hope to sell to raise much needed funds for the local hospice that were amazing with my Late Wife End of Life Care.
Let me know what you think in the comments below.
Make a one-time donation
Want to make a donation to help keep this site up and running? Why not buy me a coffee using the button below.
Or enter a custom amount
Your contribution is appreciated.Donate