King’s Gambit [1] is a little project I’ve been working for the better part of a week and a half. It’s a parametric 3D model chess set in OpenSCAD that’s printable on a 3D printer.
A Programmer’s Modeling Tool
OpenSCAD is described as a programmer’s solid 3D modeling tool. You can write scripts using constructive model geometry (CSG) to construct 3D models. CSG is simply where you take primitive shapes like spheres, cubes, and cylinders and perform operations with them like union, intersection, and difference to produce objects of appreciable complexity.
To get started in OpenSCAD is pretty simple, as it’s not a hard language to learn. Just a cursory reading through the user manual and googling for some tutorials will make it easy to get started. However, there are some little gotchas. [2][3]
The biggest advantage OpenSCAD for me is that it makes 3D modeling accessible to programmers. It lets me leverage the existing programming tools that I know, such as vim and git to be productive. Instead of being faced with a dizzying array of buttons in an interface like most CAD software, OpenSCAD uses 3 simple primitive shapes, and 3 major CSG operations for me to build upon. In addition, OpenSCAD makes it easy to make parametric models, where the dimensions of the model aren’t hard coded and can be adjusted according to a user’s needs.
However, there are ways in which it can improve. There are certain operations that can be used to produce rounded corners, such as the Minkowski sum, but it’s too slow to be useful for that. [4]
As for the language itself, there are some common language features that are missing, such as blocks as first class objects, object properties, pattern matching, etc. Therefore, I found it difficult to create abstractions that I’d like, or to encapsulate variables cleanly for parametric modeling. I’ll write more about this in detail in a later post, as I gain more experience. Perhaps there are other ways to do things that I’m not yet aware of.
Inspired by the Staunton Design
King’s Gambit is inspired by the original Staunton chess set, the most recognizable chess pieces in the world. However, it is a little different, as I designed all the pieces myself from scratch. Given that this is the first time I’ve designed any 3D solid model, I’d say that it turned out pretty well.
Most of the pieces were pretty easy to design, and I spent most of my time refactoring and doing geometric math, rather than scratching my head about why it’s not rendering correctly. It’s said that any programming language worth learning will make you think a little differently. I found it to be a little bit of an adjustment to picture in my mind how to combine different primitives in order to get the desired shape.
The bishop’s mitre is a sphere unioned with a cone with a rectangular volume subtracted from it to create the slot. You simply union another sphere for the dollop on top.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
module bishop_head(head_ratio, neck_radius) { translate([0, 0, neck_radius]) difference() { // the bishop head with a dollop on top union() { teardrop(head_ratio, neck_radius) translate([0, 0, -neck_radius / 3]) sphere(neck_radius / 3); } // the bishop slot rotate(a = -45, v=[0, 1, 0]) translate([neck_radius / 4, -neck_radius, 0]) cube([neck_radius * 2, neck_radius * 2, neck_radius / 4]); } }
|
The rook’s turret is a cylinder with a bullet (which itself is a cylinder unioned with a sphere) subtracted out of the top to get the valley. Then using a for loop, we can subtract out rectangular volumes at every 60 degrees to get the recognizable ramparts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
module rook_battlement(height, radius) { neck_radius = radius; battlement_radius = 1.4 * radius; inner_battlement_radius = 0.6 * battlement_radius; cylinder(0.2 * height, neck_radius, battlement_radius); translate([0, 0, 0.2 * height]) { difference() { // the battlement cylinder(0.8 * height, battlement_radius, battlement_radius); // cut out the loopholes for (i = [0:5]) { rotate(a = [0, 0, i * 360 / 6]) translate([-1.5, 0, 0.5 * height]) cube([3, 10, 4]); } // cut out circular space at top translate([0, 0, 0.5 * height]) { cylinder(height, inner_battlement_radius, inner_battlement_radius); sphere(inner_battlement_radius); } } } }
|
I found the knight to be the hardest to design, as it had the most organic shape out of all the pieces, so it’s not easily constructed from primitives. I ended up making two profiles in Inkscape and exported them as DXF files to be imported into OpenSCAD. I then extruded the 2D profiles and intersected them. at an angle. They didn’t quite have the desired effect, but it’s serviceable for the time being.
One thing I had to watch out for were overhangs. 3D printers have a tougher time with models with overhangs without support material, so instead of sharp grooves, I tended to have sloping saucers, and torus rings for decor.
I have a library of parts that I refactored out of the chess pieces to make them more reusable, if people wanted to make different versions or variations of the pieces. I will spend more time to pull them out into a library if necessary, but for the time being, they’re going to be part of King’s Gambit.
Fork it!
Though there’s a 1849 British design patent on the Staunton design, it looks like it has long expired. With a quick search on the internets, it seems like it’s generally accepted amongst chess set makers to not copyright derivatives of the Staunton design. I intend to release King’s Gambit under some sort of copyleft license, but as of this moment, I’m not sure whether it should be under creative commons or LGPL, since creative commons is not well-applied to software. Being in OpenSCAD, it’s definitely software, and yet, it describes an object.
I encourage you to fork it and make improvements upon it. I’ve printed some of the pieces out, but not all of them yet, so there may be some bugs that need fixing. In addition, though I tried to make all the pieces as parametric as I can, I know I might have hard coded some of the pieces along the way. So if you find that you can’t print out a 100mm tall pawn by adjusting the parameter, fix it and send a pull request!
Hopefully, this will encourage you to check out OpenSCAD and try designing a couple things yourself, seeing how it’s within reach of most programmers.
With 3D printing starting to be more accessible, I think it’s important to have the equivalent of open source projects for fundamental libraries that produce gears, pulleys, and other machines. When something fundamental becomes digitized, we will want to share it, and have the freedoms to adjust it as we see fit for our own use without restricting the use for other people. I’m pretty excited to see where this will all lead.
[1] King’s Gambit is an old chess opening that’s not used much anymore at the master level. The idea of a sacrific that puts the king at risk for a calculated advantage is amusing, so I named it after that.
[2] For Mac users, you need to use the (currently) development version 2012.01.25+. Then under Preferences -> Advanced, check the box for “Goldfeather”. This is a workaround for the current bug with the underlying OpenGL drivers with Intel GPUs.
[3] You need to first compile and render your model using CGAL (F6, not just F5), before you’re able to export to STL files (common exchange format). Otherwise, you won’t be prompted to do so.
[4] For those of you that are Electrical Engineers, the Minkowski is kinda like convolution of polygons.