Project Nayuki

Nanoblock modeling in POV-Ray


The instructions for building a physical Nanoblock model are relatively easy to translate into a 3D model in POV-Ray. As an overview, a Nanoblock model generally consists of layers of tiles, where each tile is either a simple 1×1 cylinder or an L×W rectangular brick. All tiles have the same thickness.

This article describes my approach to modeling Nanoblock in POV-Ray and how the scene description code works. It features my completed virtual version of the Kaminarimon (雷門) and alpaca models.


  1. First we set up a 3D coordinate system. Because the official instructions are given mostly in terms of 2D planes, we will use the x and y axes to represent the ground plane. We define the positive x direction to point right on the page and the positive y direction to point down on the page – this corresponds to the axes convention for computer images (but differs from the convention for mathematical graphing). The positive z direction shall point up out of the page, so higher layers have higher z coordinates. Overall this is a left-handed coordinate system, which corresponds with POV-Ray’s convention.

  2. For convenience, we make one x or y unit correspond to one tile length, and we make one z unit correspond to one layer thickness. In the real world, the smallest Nanoblock tile has dimensions 4 mm × 4 mm × 3 mm (with the thickness being the shorter dimension).

  3. We define a macro Barrel() that makes a 1×1 cylinder that spans from (x, y, z) to (x+1, y+1, z+1).

  4. We also define a macro Brick() that makes an L×W×1 tile that spans from (x, y, z) to (x+L, y+W, z+1).

  5. To keep the code organized, for each step in the official instructions we will group all the tiles produced and assign the object to a variable named like Step1. This makes it easier to isolate and check each step; we can compare the instructions and the virtual model one step at a time.

  6. Building the model can get tedious in the real or virtual world, but sometimes we can take shortcuts in the code. Not only can we copy and paste lines of code, we can also take advantage of symmetry: We only explicitly define one side and then duplicate the subobject within POV-Ray and apply reflections and translations to the copy.

  7. Finally, we add the other components of the scene and do some tweaking on the model. We set up the camera, lights, bottom plane, and miscellaneous configuration. We normalize the scale of the model to 1×1 in the x and y axes and center it at (0, 0). We also shrink the z axis to make the tile aspect ratio physically accurate.


Kaminarimon – Complete model

Kaminarimon – Individual steps: All, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Kaminarimon – 360° view animation (click for MP4 video)

Alpaca – Complete model

Kaminarimon – Instructions sample

Alpaca – Full instructions

Source code

Room for improvement