Metaball

Overview

Metaballs are a fascinating technique used to generate complex, organic-looking shapes from simple input data. They are particularly known for their ability to form smooth borders by merging 'balls' in 3D space. This technique is versatile and can be used to create organic shapes from various primitives, making it a powerful tool in computer graphics and modeling.

How Metaballs Work

The concept of metaballs revolves around the idea of merging multiple spherical shapes, or "balls," to form a single, cohesive shape. The merging process results in smooth transitions between the individual balls, creating an organic appearance. This is achieved through a mathematical formula that calculates the influence of each ball on the surrounding space.

Metaball Formula

A common formula used to create metaballs involves the normalized inverse of a sum of inverse distances to the ball centers, adjusted by an offset that controls the thickness of the resulting shape. Here is an example of such a formula implemented in Python:

balls = [(-6, -5), (9, -8), (0, 9)]   #1
offset = -1.25                        #2
SDF = (1.
      / sum([1 / distance_p2p(X, Y, ball[0], ball[1]) for ball in balls])
      / len(balls)
      + offset)                       #3
#1 The ball’s centers
#2 The predefined offset, a number making the metaballs thinner or thicker
#3 The formula

In this code snippet:

  • balls represents the centers of the individual balls.
  • offset is a predefined number that adjusts the thickness of the metaballs.
  • SDF is the signed distance function that determines the shape of the metaball.

Applications and Flexibility

While the initial impression might be that metaballs are limited to spherical shapes, their true power lies in their ability to transform any signed distance functions (SDFs) into organic-looking shapes. This means that not only can you create shapes from metarectangles and metasegments, but you can also combine different shapes—such as a ball, a segment, and a rectangle—into a single, smooth, organic-looking form.

Visual Example

To illustrate the concept of metaballs, consider the following example:

Figure 10.22 A metaball example, made of three “balls” Figure 10.22 A metaball example, made of three “balls”

In this figure, a complex shape is generated using just three points and a single offset number. The resulting shape demonstrates the smooth, organic appearance characteristic of metaballs.