teaching machines

Mesh Differencing

A feature that I’ve long wanted in Madeup is the ability to subtract away holes from a mesh. I try to implement most features myself, because I want to learn. However, constructive solid geometry is too much for me. I turned to libigl, CGAL, Eigen, and Boost for help, and now I can join solids in interesting ways. The first three things I made? A car body with holes for the axles, a spring-loaded hand cannon with holes for a locking pin, and the requisite six-sided die.

I’m still tweaking the first two, but to commemorate the moment, I’ll share the d6. It was made by creating a cube using the box solidifier and then visiting all the pips as nodes for the spheres solidifier. The difference mesh is computed as die - pips. (Union and intersection are expressed using or and and, respectively.)

A d6, which is a cube minus 21 hemispheres.

A d6, which is a cube minus 21 hemispheres.

boxRadius = 1
boxDiameter = 2 * boxRadius
sphereRadius = 0.2
fillPercent = 0.7
offset = fillPercent * boxDiameter // 3

.radius = boxRadius
moveto 0, 0, 0
die = box

.radius = sphereRadius
-- one
moveto 0, boxRadius, 0
-- two
moveto (-offset), -boxRadius, (-offset)
moveto offset, -boxRadius, offset
-- three
moveto boxRadius, -offset, -offset
moveto boxRadius, 0, 0
moveto boxRadius, offset, offset
-- four
moveto (-boxRadius), -offset, -offset
moveto (-boxRadius), offset, -offset
moveto (-boxRadius), -offset, offset
moveto (-boxRadius), offset, offset
-- five
moveto (-offset), -offset, boxRadius
moveto offset, -offset, boxRadius
moveto (-offset), offset, boxRadius
moveto offset, offset, boxRadius
moveto 0, 0, boxRadius
-- six
moveto (-offset), -offset, -boxRadius
moveto (-offset), 0, -boxRadius
moveto (-offset), offset, -boxRadius
moveto offset, -offset, -boxRadius
moveto offset, 0, -boxRadius
moveto offset, offset, -boxRadius

nsides = 10
pips = spheres

.rgb = {0.99, 0.98, 0.81}
die - pips

I didn’t have a real d6 in front of me (the Internet doesn’t count), so I guessed on the face arrangement. It looks like I was wrong. 1 opposes 6, 5 opposes 2, and 3 opposes 4. I hadn’t realized before that opposite faces sum to 7.

The pips should be black, shouldn’t they? Sadly, I don’t think libigl preserves vertex metadata when applying boolean operations between meshes, so coloring them differently seems like a job better suited for a mouse-based modeling program.


  1. […] that Madeup allows me to subtract one mesh from another, I am able to accomplish one of my dreams: print a car for my car-loving children. I traced out the […]

Leave a Reply

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