Wednesday, September 25, 2019

Removing the background & converting a JPEG or PNG to SVG

Disclaimer: this isn't a strictly 3D printing post. Blender will consume SVG files, and with some effort can MAKE svg files...but I needed some SVG files for a project, so I will go over how it works for me.

For my current project, I need to remove the background of a photo, then turn the subject into a SVG file - all so I can use a laser cutter to etch animals onto slate coasters. 



I'll be using Illustrator...CS3. I was a student once, and the Indesign/Photoshop/Illustrator package was $300 as a one-time purchase. I'm not using this for commercial purposes (if I end up needing to do commercial purposes, I might come back and show how to do this in Inkscape). I'm sure the habits are very similar.

I start with a 10 cm x 10 cm square as the document size - the size of the coaster I'll be etching with a laser. (This can also be useful for someone using a Cricut - my girlfriend got one last week.)

Next, under File>Place, I put my image file on my document - this also creates the first layer. The image is ideally too big - scaling down keeps details, while scaling it up will lose them. Regardless, select a corner with your right mouse button, hold down shift (so the image will scale on its X/Y at the same rate)...and then scale your picture to fit in the box. If you used a PNG, you're fine. If you used a JPEG, go to Object>Rasterize and click okay in the dialog box. (If you don't rasterize your JPEG you will not see "Live Trace" later.)

Rasterized Baby Leopard scaled down to fit in the 10 cm x 10 cm frame (Layer 1)
You have the photo within the box - let's take a step back and do some other prep work. Under Window>Layers - you'll want that visible. Under View>Show Transparency Grid, you want the background to be transparent - checkered instead of pure white. Also under View>Smart Guides, I like turning those off for this kind of project. (Feel free to turn them back on later - you can decide for yourself what you like.)
View Menu for adding Show Transparency Grid & turning off Smart Grid

As a good practice, create a new layer and select it - this is where you'll do your tracing. Both your foreground and background should be a white box with a red line through it...this means any fill you have will be transparent. (If you don't do this step, you'll see your picture being covered up as you trace.)

Transparent fill
With the pen tool, start right-clicking along the border of your image. You can make curves with a curve tool, but...more learning. When I hit an area that needs more of a curve, I'll just place more vertices. Once you get back around to the start, click from your first spot, and it will automatically make it complete. (If you had Smart Guides from earlier turned on, it would try to suggest certain angles for the next vertex.)

The red vertices are pretty small, so I often zoom in for close details

With that done, drag that part of the layer 2 on top of that the original layer. Under Select>All, it should highlight both the image and the border you just drew. Object>Clipping Mask should cut out the background!

The clipping can be more exact, but the conversion to SVG will change the detail level too.
Now comes a more basic "turn this into an svg" - you can always save an Illustrator file as an SVG. But I needed a black with transparency object. With the selection tool (not pen tool), double right-click on the new image. You want a "Live Trace" button to show up in the top bar, and for some reasonable-but-not-known-to-me, it takes two double-clicks. Press "Live Trace". Boom - white and black...but not transparent. There's a button in the bar that opens up tracing options, and you'll want to check the "Ignore White" checkbox. (You'll notice now that it's just transparent and black now.) I would also recommend experimenting with different amounts of Threshold, instead of sitting at 128. The higher the number, the more black. Min. Area is going to give you a higher detail at a smaller number.

Trace Dialog Box

And that's it. Save as a SVG, and you're done! Wish you good luck translating this into your vector-based experiences.

Thursday, September 12, 2019

Remixing a d20 countdown dice holder in Blender - BoltFactory plugin

I figured I would share some of the remix process of my latest project.

The final result - whoops, where is my d12?
You can find the final results here on Thingiverse. The original version was done by the user kittka on Thingiverse, a little larger and using magnets.

My original remix that I didn't share, was scaled down and using different magnets. Sadly, the thin magnets I normally use for my projects did not hold the d20 together, as it jostled around in the gaming bag. Remix #2, I used more powerful magnets in the base where the d20 had more room.

As this wasn't a major remix, I didn't bother posting it. There were still minor issues - knocking the d20 at just the wrong angle, it would spill all of the dice out. I considered replacing one set of magnets with a post and hole, so you'd have to pull it apart vertically...but it was in a design backlog.

Enter the Puppy


My friend hosting D&D has a pup that likes to chew. Alfred climbed into my bag, pulled out my d20, and chewed on the lid...breaking off part of the top. Fortunately, none of the magnets were swallowed, no PETG was eaten, but I now needed a new d20.
Post-Alfred


Enter the BoltFactory plugin


Blender 2.8 has a bunch of plugins, most of which I had played with in the earlier versions. I had not experimented very much making bolts in the past. I did make a screw thread once using arrays, but...it was work. Boltfactory is stock, just needing to be turned on. Edit>Preferences>Add-ons, then type in "bolt".


Once that's turned on, you can shift-A to create a mesh, and select "Bolt" at the bottom, which gives you this handy bolt creation menu.


I used the default bolt generated. To get the corresponding nut, just change the Model: BOLT to Model: NUT.


I scaled them both up at the same ratio, to fit to the die. From there, I made a wide-but-not-tall cube to boolean-intersect a thread section from the bottom of the bolt (slightly bigger than the nut part I was cutting out), and a boolean-intersect from the nut. I printed a prototype, to see if my .24 mm layer height and .5mm nozzle would provide good enough tolerances for the scaled-up threads. Success!
Orange nut, purple bolt, with a longer orange test bolt
Scaling up the nut/bolt gave me a really "chunky" thread. Easy to print, as well as not needing a lot of turning to open. (Turned out to be about 108 degrees of turning.) Enough to have a tight seal, but not enough to make it too much effort.

The Real Work


It gets tedious and ugly after this. I dissolved all of the vertices that held the magnets, and made smooth edges to merge with future bolt/nut sections. There were three design issues to overcome, and in my first time doing this, I didn't come up with a clean system.

  1. The top needs to be flush with the base, plane to plane (bottom of the top, to the top of the base)
  2. The number faces on the top need to match the "spin" of the bolt into the nut
  3. The number faces on the top need to be flush with the number faces on the base
The first one was awkward — the top and base needed to be rotated the exact amount. I probably should have just reimported the original, but I continued my original remix. They needed to be the same z-plane coordinates on each facing plane. I checked the z-coordinates of the vertices, and rotated on x/y axis to balance opposite sides. After that was flat, I merged the bolt and nuts (skipping some finer details here). 

I printed the d20 bottom, as the nut part wasn't going to change. Printed a top, testing the "right amount" of bolt.

The second design issue should have been more manageable in Blender, but I didn't trust virtual tolerances. To match up the faces, I would rotate everything BUT the screw portion. It's easiest if you dissolve the unnecessary edges on the bottom of the top - otherwise the spin might get some of your edges cutting into other edges. Again, printed a couple more to get the alignment of faces correct.

The third design issue, I noticed that the top wasn't completely aligned with the bottom, on the x/y axis. I could run my fingernail up the face from #6 into #5, but it would catch...and there was one millimeter-ish gap on the #2 to #10. A couple of printed tops later, it matched.
Closed