Make Your Own 3D model of your QR code for Bitcoin (or any alt currency) with no 3D experience required

If you don’t care about how this was made, the motivation, or design and would just like a way to 3D model your QR code, please skip down to the bottom Any 3D model you generate (as an STL file) will be able to be easily converted to the appropriate file type for 3D printing or for milling down with a C&C machine.

Motivation and background

Having recently gotten into Bitcoin, I was reading more and more articles about shops starting to accept it. A lot of these had people with QR codes on a piece of paper saying “We now accept bitcoin.” This is/was awesome, yet I thought it looked a little ghetto. I thought to myself, wouldn’t it be cool if they had a QR code hanging on the wall that people could scan from a couple feet away, or like a metal piece attached to the register that people could scan with their phones. Around the same time, I saw this neat article on Hackaday where a guy made a 3D replica in metal of his Bitcoin QR code and thought that was pretty cool. Having recently gotten into 3D modeling myself, I was wondering if I could do the same thing as a sort of a practice model. It turns out that some of the nicer programs like Solidworks and maybe Autocad can extrude 3D models from images, but it’s not very easy and not everyone wants to throw out hundreds or thousands of dollars to buy them either. My target audience when I first started with this application was small business owners who wanted something a little different to display they accepted bitcoin, or for the random hobbyist that would throw up one of their QR codes in their cubicle or home office or what have you. The average person doesn’t know 3D modeling, and I didn’t think they should have to.

How it Works

The code itself would make CS major cringe as it was kludged together without much forethought, so don’t judge me. Also, I hardly commented it, but its fairly straightforward. Maybe i’ll make it pretty one day, but I mainly wanted to throw it out there for others.

There are a various number of file types out there that are used for 3D modeling. Looking around, STL files seemed to be pretty common, and most applications, such as Makerware, which is used with one of the cheapest 3D printers around, can take an STL file and slice it for printing.

STL file format

An STL (STereloLithography) file is nothing more than a collection of vertexes, which form hundreds of triangles, which form polygons. The file itself is pretty straightforward, so building one in my application was fairly easy. I generate a binary STL file (which has the one catch that it is little endian), with the following format (from wikipedia):

80 Byte Header: Largely ignored, so I just generated 80 bytes of 0s

32 bit integer : The total number of triangles. Each time my drawTriangle function is called, it increments a running count of the total number of faces. During the initial pass through, I think I write a 0 or something here. Once I have drawn all the faces, I come back and write the correct value

for each triangle

Three 32 bit floats representing the triangle’s normal

Three 32 bit floats representing the triangle’s first vertex

Three 32 bit floats representing the triangle’s second vertex

Three 32 bit floats representing the triangle’s third vertex

2 byte unsigned short integer, the “attribute byte count’, which apparently most software doesn’t understand unless it’s 0

end

Application flow

Very basic

The application loads a png image (of the qr code) and loops through each pixel one by one. If the color value is black (RGB 255,255,255), I mark it with a one in the draw array.

Iteration 1: For every 1 value in the drawArray, I just drew a cube (using a collection of 12 triangles, 2 for each face of a six sided cube). While this technically looked correct, Makerware wouldn’t perform the export correctly because the “slicing” process didn’t like the shared faces. This first implementation didn’t look at it’s neighbor, so two black pixels right next to each other would draw the exact same face.

Iteration 2: For every 1 value in the drawArray, the current pixel looks at its neighbor to the North -East -South -West. If the neighbor value was also a 1, the application does not draw that face. Iteration 2 would slice correctly, but the files were much larger than necessary. This was because even though two pixels in a row could “share” two triangles to make their face, they would actually make them individually (see badly drawn MS paint picture below).

Iteration 3 (final): Performs in the exact same manner as Iteration 2, except after the application finds a 1 value for a pixel, it checks its neighbor, its neighbor’s neighbor, and so on until it finds a 0. It then draws two triangles to make up the face for the entire stretch of ‘1’ value pixels. See bad MS paint drawing

I still have the problem that I’m only scanning one direction (horizontally or vertically), so there are extra triangles generated on the tops only of the cubes when you have long chains of black pixels in the x & y direction, kinda like the following picture. I really don’t know how to put it into words, but if you actually look at the code, you will probably see it. This doesn’t actually create a problem in the model itself and everything slices correctly, but the file is still a little bigger than necessary. Still, we are dealing with relatively small QR code images and I haven’t had a problem with it so far.



How it use it and what it looks like:

Download either the executable JAR file here, or the source files from here and here. Make sure your Java is up to date (at the time of writing its java7u51) because the applications uses some newer things like FileChannels. Make sure you have QRcode of your bitcoin, dogecoin, litecoin, whatevercoin address saved as a PNGimage. (I think the default for most of the online and offline wallets). If not, open the image in Paint or whatever, do a save as, and save it as a PNG.

If you have never heard of JAR files, running java programs, etc. – Don’t worry, it’s really not that hard. Just follow these few steps. Comment below or do some general Googling if you have questions

1. Download and install java – http://java.com/getjava

2. Add Java to your system path. You may be able to skip this step if it is done automatically for you. If you have to, simply Google “Adding java to my Windows ____ path” or something along those lines. Plenty of tutorials and youtube videos out there

3. Download the qrgenerator.jar file above. Put both the JAR file and the QR code PNG image in the same directory(folder)

4. Open command prompt or terminal. If you are on windows. you can go Start Menu->All programs->Accessories-> Command Prompt

5. In command prompt, navigate to the directory you have your JAR file and QR code picture. Do this by typing cd directory name

For example, if I put both files in my documents folder, it would be: cd C:\Users\bigslugga\Documents

6. Follow the instructions below

Running the file with java -jar qrGenerator.jar will display the list of required options. At the very least it will require an input file name (the png of your qr code) and an output file name of your choosing, with a .stl extension. An example command is:

java -jar qrGenerator.jar QRcode.png qrModel.stl

This will generate the STL file named qrModel.stl, which is the 3D representation of your QR code.

By default, the running the application generates your QR code on a background platform that looks like this (you have to scale the Z direction independently to make the QR code that pronounced):

If you want to build your own platform (I made one with the bitcoin logo), and just need the QR drawing, you can use

java -jar qrGenerator.jar QRcode.png qrModel.stl -P

to get a model like:

And on my custom platform:

All of these are in Makerware, which I have no affiliation with but it’s free and easy to see your models with. You can scale the QR code in the Z direction if you want it taller or shorter too.

With an STL file you can pretty much do whatever you want. If you know a shop that lets you print 3D print stuff, or a shop that will mill you down a design, you can bring it to them on a cd or flash drive. There are tons of free applications that will convert your STL model file into GCode or whatever language for a CNC machine. Almost all 3d modeling programs out there will also accept STL files if you want to model your own, or know someone who will model for you, your own background plate.

I made an actual 3D print to make sure everything looked right. I printed it out a little smaller (to use less plastic). Also, if the black part looks a little ghetto, it’s because I only had one color plastic I was working with and had to sharpie the raised QR code and bitcoin logo myself. In actual practice, I’d print it out with black plastic on some contrasting background. However, it works just fine when Ii scanned it with QR droid to get my address 1HdFsjNZgVMkutQ9uEsKfbsebeyqkkUyPw ( what up product placement!)

Going further

Feel free to take this code, modify it, play with it, make it better. Please message me (via reddit as Bigslugga) or comment if you make some cool edits or make it more efficient for people, and I’ll try to post it up. If you don’t like to mess with code but have a neat idea, feel free to tell me or others and hopefully one of us will be able to get around to it.

Good luck and happy modeling!

-Jasen

Downloads:

Executable:

qrGenerator.jar

Source:

STLmaker.java

STLDrawer.java