Flying through the Mengersponge

# Menger Sponge in VR

• Author: Armin Schikorra
• Date: Spring 2019

The Menger sponge is among the simplest three-dimensional fractals. We start with a large cube, which we divide into 27 subcubes of one third sidelength of the original cube. We throw away the middle cubes on all sides and the cube in the center. The remaining 20 cubes we treat with the same method.

This proof-of-concept project is about learning the basics of Unity, it took roughly 5-10 hours to make this run. It runs with Oculus Rift with the touch controllers.

We see the Menger sponge, we can increase/decrease its iteration with the touch controller. We can fly through the sponge by pointing the controller into the direction we want to fly and pressing the trigger.

There are two scripts:

• mengersponge.cs creates the Menger sponge: one can increase and decrease the iteration number if a button is clicked on the touch-controller. Technically, we introduce the sub-class “Cube” which is one cube (defined by its base corner and three directions). This Cube-class can compute its own children and generate a mesh that can be rendered. So a large Menger sponge is simply a bunch of small cubes. This is very inefficient since the Mesh grows exponentially large (there is no effort in efficiency, all cubes have six sides, even if that side cannot be seen). There is a (Unity-set) upper bound on vertices in a Mesh that needed to be increased (Unity throws no error code if you have too many vertices in a mesh, it just forgets some). The inefficiency in this construction (which could be easily improved with a bit more care) leads to an overload of my computer after 4 or 5 iterations.

• cameracontrol.cs to move the camera towards or away from where we point