3-Dimensional Metaball Computer Graphics

Articles —> 3-Dimensional Metaball Computer Graphics

Metaball 3-d isosurface

Metaballs are computer graphics shapes which often have an organic and squishy look to them. The shape and form of a Metaball is controlled by an underlying mathematical formula which is used to compute the value for a given spacial coordinate, the values as a whole can then be used to construct the actual shape surfaces - also called an isosurface - by specifying an isovalue, a value which defines whether a coordinate is within a metaballs. The creation of several Metaballs allows their values to interact, resulting in a behavior which often has a tendency to smoothly merge metaballs, resulting in an almost liquidlike behavior.

Metaballs are technically just a point in space accompanied by an underlying mathematical formula which defines the Metaball's behavior surrounding its location. The typical formula for 3-dimensions... 1 / ((x0 - x)2 + (y0 - y)2 + (z0 - z)2)...derives from equation for a sphere. Thus for an object at position {10,10,10}, the value in space at {9,9,9} is 1 / ((10-9)2 + (10-9)2 + (10-9)2) = 1/3.

To create one or more Metaballs one first must define the coordinate space containing the objects - in the examples shown here a 3-dimensional space is created and specified computationally as a 3-dimensional array of values. The values for each position in this array is then defined by the the sum of all of the Metaball object's respective functions. Iteration through all space values results in a completed grid.

Once the coordinate space is filled with the resulting values from all Metaballs, one must reconstruct the isosurfaces. One can do so via racasting or Marching Cubes. Either way, one must choose an isovalue which defines which coordinates are interior or exterior to the Metaballs. In the example below I used a java implementation of Marching Cubes adapted from Paul Bourke's C code. Marching cubes is efficient and elegant and is an algorithm I've used in the past to construct objects such as molecular surfaces and to model reaction diffusion. While the resulting surface constructed by marching cubes can appear somewhat cubical when small spaces are used, the surface can be further smoothed by surface subdivision, such as Catmull Clark Subdivision.

Metaball Sphere in 3-dimensions Metaball Diamonds in 3-dimensions Metaball Sinusoid in 3-dimensions

Three different Metaball functions. Left: Spherical. Middle: Diamond (radius / (|x - x0| + |y - y0| + |z - z0|). Right: sinusoid (1 / sin(x - x0) + sin(y - y0) + sin(z - z0)) ).

One can also color meteballs, merging colors between adjacent or combined objects by weighting the coordinate color based upon its distance between objects:

Colored metaballs

To construct the movie below, a spherical function was used and each object was given a random position and velocity - its position updated with every iteration based upon its velocity. All Metaballs were constrained within a 3-dimensional cube (with some border), thus collisions with the walls may be occasionally seen. The movie was created by rendering the resulting scene in OpenGL, following by saving each frame as an image, and lastly piecing the images together into a movie using ffmeg.

Resources

  1. Exploring Metaballs in 2D. Excellent article on the history, features, and creation of metaballs.
  2. Ryan's Blobs: overview of Metaballs in 2 and 3-dimensions.



There are no comments on this article.

Back to Articles


© 2008-2022 Greg Cope