MetaStruct is a small Python project initially created during 2020-21. It’s primary purpose was to teach me some of the mathematics behind implicit modelling, by creating a simple geometry kernel in Python. This is a technique made famous by computer graphics, and is being increasingly used in modern design software (nTopology, Metafold).
Last Updated :

MetaStruct is simple, and written for pretty much anyone to be able to understand what’s happening. The general workflow is as follows:
- Create a “DesignSpace” object – this is just a regular grid of sample points where we will evaluate the distance field function
- Define some geometry – there are primitive shapes and some lattices to choose from, you can import a mesh, or you could implement your own function
- Evaluate the grid – the sample points are used as inputs for the distance functions defined in the geometry
- Extract a mesh – here we use the marching cubes algorithm
- Refine the mesh – the library has some IGL functions implemented for simplification, subdivision, and smoothing
- View or export!
All the underlying implicit equations are exposed and visible, and it’s easy to implement new geometry classes.
Primitive Shapes
Lets take a look at one of the primitive shapes implemented in the library, the humble sphere.
class Sphere(Spheroid):
def __init__(self, design_space, x=0, y=0, z=0, r=1):
super().__init__(design_space, x, y, z, xr=r, yr=r, zr=r)
self.r = r
def evaluate_point(self, x, y, z):
x0 = self.x
y0 = self.y
z0 = self.z
r = self.r
return ne.evaluate('sqrt((x-x0)**2 + (y-y0)**2 + (z-z0)**2) - r')
This code segment is pretty basic. In fact, the function that will do the majority of the work here is the evaluate_point function. This is where we actually evaluate the distance field of the sphere at some input point (x, y, z), given a radius r and the sphere’s centre point (x0, y0, z0). This is the only function we need to implement to create a shape.
This function gives us exactly the distance to the surface of the sphere. It also tells us if we are inside or outside of the sphere; if the distance value is negative, we are inside the shape, and if it is a positive value we are outside.
Extracting the Isosurface
After we have evaluated all of the points in our regular 3D grid of sample points, we are ready to create a surface mesh! In this kernel, I use the Marching Cubes algorithm. I won’t go into details here, but essentially, for each cube of 8 vertices in the sample grid, the algorithm places triangles in specific patterns depending on the values of each corner compared to the isosurface value.
For implicit geometry, we always use 0 as the isosurface value. This is of course because we want to extract the shape’s own surface.

This is a really fast algorithm, because it performs a dictionary lookup for each cube of 8 vertices and adds the relevant triangle combination as required.
If the distance function is evaluated for all of the sample points in our design space, and then the marching cubes algorithm is exectuted, we are left with our sphere as a mesh.

This output mesh can then be previewed with MetaStruct using the Mayavi viewer, or exported to a file.
Summary
In this article, I have briefly presented my implicit geometry kernel written in Python, MetaStruct. In future articles, we will explore a few more features, including boolean operations, warping the coordinate system, and TPMS lattice structures.
I hope you’ve been able to see that creating objects using implicit functions is really not as complex as it initially seems!
Go check out the project on GitHub – https://github.com/wilko339/MetaStruct

Leave a comment