Guillaume's Blog
Fun side projects & learnings
3D printed mazes in Blender script
Playing around with Blender script to generate printable mazes automatically.

I was looking for an idea of a game that would be hard to build if it was not for 3D printing. A 3D maze came to mind. I used to make those out of legos with marbles when I was a kid: place the marble at one end, and tilt the maze to direct the ball all the way to the exit. For extra difficulty, make the maze opaque: you do not really know the structure inside, but you can use the sound of the marble hitting walls to get an idea of where it is.

Before moving on to fully three dimensional mazes, let’s start with printing a 2D maze. I decided to model the maze in Blender using the scripting language so that I could make arbitrarily large and complex mazes later.

Here is a sample ASCII Art maze, that can be generated with a short program:

Ascii Art Maze

Those ‘W’ become little cubes to make the walls. Then we add a floor and a ceiling. And finally a couple of curved walls at the exits to avoid losing the ball (after losing a couple…).

3D model

One learning: Blender Script is not entirely obvious when it comes to Boolean operations. Below is the kind of code needed to subtract a cylinder from another one in Blender 2.73a. This is one step towards building the little walls at he exits. Note the use of ‘active’ instead of ‘selected’ in this particular operation, which is a bit inconsistent with the rest of the API.

# One Cylinder
bpy.ops.mesh.primitive_cylinder_add(
	radius=1, depth=0.5, location=(0,0,0))
cyl1 = bpy.context.object

# Another one, smaller in radius but taller
bpy.ops.mesh.primitive_cylinder_add(
	radius=0.8, depth=1.0, location=(0,0,0))
cyl2 = bpy.context.object

# Add a diff modifier
diff1 = cyl1.modifiers.new('Diff1', 'BOOLEAN')
diff1.object = cyl2
diff1.operation = 'DIFFERENCE'

# Apply the modifier and get rid of the extra object.
bpy.context.scene.objects.active = cyl1
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Diff1")
scene.objects.unlink(cyl2)

And here is the result! It was too hard to complete when I first printed it as a blind maze (with no structure on top). But it became quite fun to play with after that modification - it made the game challenging but not overly difficult.

Printed maze

Two things to watch out for:

  • make sure that the 3d printer head moves along the walls as much as possible, otherwise it may create printing artifacts inside the maze that block off certain passages.
  • buy a lot of marbles!

Next step: a multi-layer 3D maze…


Last modified on 2016-01-20