A Python library for generating 3D meshes from signed distance functions (SDFs) with a simple API.
sdf is a Python library for generating 3D meshes from signed distance functions (SDFs). It allows developers to define shapes mathematically using a simple API and export them as 3D printable files like STL. The library implements the marching cubes algorithm efficiently with numpy and multi-threading to create complex geometries programmatically.
Python developers, hobbyists, and researchers interested in procedural 3D modeling, computational geometry, or generating meshes for 3D printing and visualization without relying on traditional CAD software.
It offers a pure-Python, dependency-light solution for SDF-based mesh generation with an intuitive API that supports boolean operations, transformations, and extrusion, making it ideal for scripting custom 3D models quickly.
Simple SDF mesh generation in Python
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses Python operators like |, -, & for union, difference, and intersection, making code as simple as `sphere(1) & box(1.5)` for CSG operations, as shown in the canonical example.
Leverages meshio to support over 20 file formats including OBJ, PLY, and VTK, allowing seamless integration with various 3D tools, as mentioned in the File Formats section.
Provides `show_slice()` function with matplotlib integration to plot 2D slices of SDFs for debugging, which is only imported when called to minimize dependencies.
Implements multi-threading with numpy batch evaluations to accelerate the marching cubes algorithm, using worker threads based on CPU count for faster mesh generation.
Using meshes as SDFs requires OpenVDB, which must be built from source with a non-trivial CMake process involving manual copying of files, as detailed in the installation notes.
Non-uniform scaling and other inexact SDFs can cause issues with automatic bounds estimation and sparse sampling, potentially leading to holes in the output mesh, requiring manual bounds specification.
While optimized with numpy and threading, the library is still Python-based and may struggle with very high-resolution meshes or real-time applications compared to compiled alternatives like C++ libraries.