Free Plugins for SketchUp

Menger Sponge

Download SketchUp Plugin Level 1 Menger Sponge Level 2 Menger Sponge Level 3 Menger Sponge Level 4 Menger Sponge

Background

The Menger Sponge is a 3D fractal in the Mathematical world. It is defined recursively, where each level is constructed from components of the previous level. What I find fascinating is that by applying a few simple rules over and over one can create such a complex -- and frankly, bizarre looking -- structure.

Actually, you don't need a plugin to do this. You can create any level of the Menger Sponge just using the SketchUp GUI. This plugin was basically an exercise in using the SketchUp Ruby API to build complex components from subcomponents. I left the source code unscrambled, if anyone wants an example.

In the first iteration, you start with a cube, scale it down to one third the size, make 27 copies, and arrange them like the cublets in a Rubik's Cube. Then remove the cube at the middle of each face, and remove the cube in the center, leaving 20 cubes. This gives you the first level sponge.

The second iteration is the same process, only instead of a cube, you start with the first level sponge, scale it down, and translate 20 copies as before.

To get the third level, the same process is applied to 20 copies of the second level sponge.

Ditto for the fourth level, which is shown below. It takes about a minute to generate the geometry, and has around 200k faces.

Usage

Menger Sponge Dialog Box

This plugin is accessed from the Draw menu (Draw > Menger Sponge). This will open a dialog box to enter the parameter values.

The outside color was left undefined, and shows up as white by default. You can easily change the outside color by clicking anywhere on the component with the paint bucket.

You can change the color of the inside faces almost as easily. Open the component by double-clicking on it with the select tool. The faces are grouped by material. So, if you click on any inside face with the paint bucket, all the faces that are the same color will be painted.

When you click OK, the Menger Sponge is created as a component, and the component placement tool is activated to position the spiral in the model.

The dialog box remembers the values between SketchUp sessions.

Installation and Removal

Installation Questions? Please see this SketchUp Help Article. To remove the plugin, just delete the file from the SketchUp Plugins folder.