What is an SDF?

Signed Distance Fields (SDFs or distance volumes) are scalar fields most often stored as 3D voxel grids. Each voxel here records the shortest or unsigned or signed distance to a target surface. The value is negative inside the closed surface, zero on it, and positive outside. This makes SDFs ideal for various geometric queries.

Why Convert a Mesh to an SDF?

Converting a mesh to an SDF unlocks a set of operations and smooth shape edits

  • Offsets. One is free to grow or shrink a whole object by an exact distance (e.g., adding a uniform 2 mm shell everywhere), without causing the mesh to fold over itself.
  • Double‑offset blending, i.e., inflating each part, deflating their union, and obtaining seamless fillets or organic morphs.
  • Booleans by simple min/max of two fields. You can add, cut, or overlap models reliably because the math happens on a tidy voxel grid rather than the raw triangles.
  • Closed‑mesh re-meshing, i.e., rebuilding a watertight surface for already closed inputs at any chosen detail level (open meshes first need hole‑aware sign assignment).

Algorithms to Compute SDF

Before we dive into the nuts and bolts below, remember the end‑game: you compute a mesh signed distance grid, so that every point in space knows exactly how far it sits from your model. That single dataset then powers everything from offsets to rebuilds. And if you are calculating a mesh creating signed distance field for mesh boolean work, too, the same grid lets you union, intersect, or subtract shapes with one-line min/max math.

Now, let’s explore the options:

  1. Per‑voxel nearest‑surface query (voxel scan + BVH). We march through each candidate voxel and ask a BVH‑accelerated ‘closest‑triangle distance?’. You can compare it with looping over a 3D spreadsheet and writing down how far every little cube is from the model.
  2. Sign assignment. After unsigned distances are known, vote inside vs. outside with winding numbers or ray hits or flood‑fill the signs. Think of colouring voxels red for ‘inside’ and blue for “outside,” then spreading that colour through the grid.
  3. GPU‑parallel voxel scan: Run the same nearest‑surface query, but split the work across thousands of GPU threads for big speed‑ups. Effectively, the graphics card measures all cubes at once instead of the CPU doing them one‑by‑one.
  4. Sparse / adaptive grids. Store fine voxels only near the surface and keep coarse blocks elsewhere to cut memory and compute. In other words, save detail where the action is and skip the empty air.

How to Create SDF from 3D Mesh with MeshLib?

MeshLib gives you several flexible ways to get mesh signed distance data, depending on your geometry and downstream needs. 
There are several types of volumes:

  • VDB grids. These are based on the OpenVDB library which tells MeshLib how to assign ‘inside’ vs ‘outside’ labels during volume creation. These store only useful voxels, as sparse grids, which is good for SDFs.
  • Simple voxels (existing as raw data)
  • Functional volume which stores nothing, while being able to process your distance calculation queries.

Sparse volume

Objective:

meshToDistanceVdbVolume(), converts a mesh (or a part of it) into a sparse distance field using OpenVDB. It builds a tree-structured signed or unsigned distance grid, storing only active voxels. i.e., those near the surface, which makes it memory-efficient. For signed distances, the input mesh must be closed. The function returns a VdbVolume.

Applications:

Great for large or complex models, especially when working with, say, ray-marched rendering or any workflow that benefits from fast queries but does not need every voxel stored. Think of this as your go-to option for scalable, production-grade SDF generation.

Code examples:

				
					from meshlib import mrmeshpy as mm

mesh = mm.loadMesh("mesh.stl")

params = mm.MeshToVolumeParams()
params.surfaceOffset = 3 # 3 voxel layers around surface will be active
params.type = mm.MeshToVolumeParams.Type.Signed if mesh.topology.isClosed() else mm.MeshToVolumeParams.Type.Unsigned
params.voxelSize = mm.Vector3f.diagonal(mm.suggestVoxelSize(mesh,1e7)) # voxel size to have approximately 10mln voxels
voxelsShift = mm.AffineXf3f()
params.outXf = voxelsShift # shift of voxels to original mesh
vdbVolume = mm.meshToDistanceVdbVolume(mesh,params)

gSettings = mm.GridToMeshSettings()
gSettings.voxelSize = params.voxelSize
gSettings.isoValue = 0.5 # in voxels measure
offMesh = mm.gridToMesh(vdbVolume.data,gSettings)
offMesh.transform(voxelsShift) # shift out mesh to initial mesh position

mm.saveMesh(offMesh,"out_mesh.stl")
				
			
Before
Original 3D mesh before conversion to signed distance field (SDF)
After
Signed distance field (SDF) representation of a 3D mesh

Step-by-Step Mesh to SDF conversion flow

A. Load the mesh
C. Make your choice, what volume you need
D. Adjust meshToVolumeParams or meshToDistanceVolumeParams
E. Run the conversion and use the field, calling the function

MeshLib: Library for Mesh to SDF

MeshLib will help you as a highly functional modern C++ library, featuring official API bindings for Python, C, and C#. This versatility makes it easy to integrate into any geometry pipeline, whether you are building tools, simulations, or custom viewers. All in all, MeshLib library allows you to rely on the Laplacian approach with an ideal balance.
If you are looking for a mesh signed distance field generator that works, MeshLib gives you native tools to create robust SDFs from triangle meshes.

Voxel Guide: Size, Distance, Types

Get started with setup and bindings:

Language Support and Compatibility

  • C++: fully supported on all systems with no limitations.
  • Python: compatible with Python 3.8 to 3.13 across platforms:
    • Windows: Python 3.8–3.13
    • macOS: Python 3.8–3.13 (except 3.8 on macOS x64)
    • Linux: Python 3.8–3.13 on any manylinux_2_31+ system

You can employ MeshLib’s Python bindings to quickly implement a signed distance function mesh workflow in just a few lines of code.

Explore the full source code, prebuilt modules, and examples in the GitHub repository for converting a mesh to a signed distance field.

Whether you are prototyping in Python or embedding SDF tools into a C++ engine, MeshLib offers a flexible and high-performance foundation for any signed distance function mesh project.

The Full List of Mesh File Formats We Support

Format
Import
Texture Support
Color Support
Export
STL
Yes
No
No
Yes
OBJ
Yes
Yes
Yes
Yes
OFF
Yes
No
No
Yes
DXF
Yes
No
No
Yes
STEP
Yes
No
No
No
STP
Yes
No
Yes
No
CTM
Yes
No
Yes
Yes
3MF
Yes
Yes
Yes
No
MODEL
Yes
No
No
No
PLY
Yes
No
Yes
Yes
GLTF
Yes
Yes
Yes
Yes

What our customers say

Thomas Tong

Founder, Polyga

MeshLib% filename%
When we set out to develop our new Podkit scanning platform, we chose MeshInspector’s MeshLib as the foundation. That partnership let us accelerate development, ship new features faster, and get to market months sooner than we could have on our own. The MeshInspector team has been outstanding — quick answers, deep technical know-how, and genuine enthusiasm for our success. We simply wouldn’t be where we are today without their support.

Gal Cohen

CTO, customed.ai

MeshLib% filename%
“MeshLib has been a game-changer for our company, providing all the essential operations we need to handle meshes and create highly accurate personal surgical instruments (PSIs), which are our primary products. After extensive research and comparison, MeshLib stands out as the best solution on the market. Their team is exceptionally professional and knowledgeable. Collaborating with them has been an absolute pleasure—they respond to any issues we encounter promptly and always deliver effective solutions. Their commitment to customer support and technical excellence is truly unmatched.”

Mariusz Hermansdorfer

Head of Computational Design at Henning Larsen Architechts

MeshLib% filename%
“Over the past year, MeshLib has transformed my approach to design and analysis in landscape architecture and architecture projects. This powerful library excels in critical areas, such as geometry processing, interactive booleans, point cloud manipulation, and curve offsetting. These features enhance design workflows, allowing for dynamic modifications, efficient terrain modeling, stormwater flow analysis, and advanced wind flow visualiiza…..”

HeonJae Cho, DDS, MSD, PhD

Chief Executive Officer, 3DONS INC

MeshLib% filename%
“MeshLib SDK helped us achieve faster and more accurate calculation results and outperformed any other Mesh Processing library that we evaluated. For us in digital dentistry, it was a game-changer. Mesh processing operations, such as inspecting and editing the mesh to create dental devices for the treatment plan, are crucial. MeshInspector support liberated our team from technical constraints so we concentrated on creating exactly what we wanted. I highly recommend incorporating the MeshLib into your software arsenal.”

Ruedger Rubbert

Chief Technology Officer, Brius Technologies Inc

MeshLib% filename%
“With MeshInspector MeshLib we were able to automate many of our workflow processes, thanks to its advanced, modern, and efficient dental and geometry oriented algorithms, covering many of our orthodontic-related tasks: CT and intraoral scan segmentation, voxel and Boolean operations, editing, aligning, visualization, inspection, and import/export of mesh objects. We use the versatile MeshInspector MeshLib API, both in production and R&D for fast prototyping and testing of our ideas.”

Start Your Journey with MeshLib

MeshLib SDK offers multiple ways to dive in — from live technical demos to full application trials and hands-on SDK access. No complicated setups or hidden steps. Just the tools you need to start building smarter, faster, and better.

Journey with MeshLib SDK
Core Developers
MeshLib Team, official authors of MeshInspector App and MeshLib SDK, leverages over 20 years of 3D data-processing and mathematical expertise to deliver high-performance, plug-and-play algorithms that simplify even the most complex mesh workflows.
Leave a review about this post
{{ reviewsTotal }}{{ options.labels.singularReviewCountLabel }}
{{ reviewsTotal }}{{ options.labels.pluralReviewCountLabel }}
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}
Share this post on social media