SDF Mesh Library
Facepunch Facepunch Library update 10mo ago

SDF Mesh Library

Marching cubes & squares mesh generation

favorite29favorites
thumb_up25upvotes
hard_drive 0 MB folder 57 files build Engine v22 history Last update 328d ago
open_in_new View on sbox.game

About This Package

About SDF Mesh Library

Allows you to define a 2D / 3D field of signed distances to a virtual surface, perform operations with primitive shapes, and then generate a 3D mesh of the surface in real-time.

Create a world

using Sandbox.Sdf;

// ...

var sdfWorld = new Sdf2DWorld
{
    // Rotate so that Y is up
    LocalRotation = Rotation.FromRoll( 90f )
};

In this example we've rotated it by 90 degrees, so that the Y axis when doing 2D operations becomes the Z (up) axis in world space.

Draw some shapes

Still in server-side code, you can modify the SDF world like this:

// Shape that we want to add
var circle = new CircleSdf( new Vector2( localPos.x, localPos.y ), radius );

// Load the material to use
var material = ResourceLibrary.Get<Sdf2DLayer>( "layers/sdf2d/checkerboard.sdflayer" );

// Draw the circle!
sdfWorld.Add( circle, material );

// Move the circle to the right, then subtract it!
sdfWorld.Subtract( circle.Translate( new Vector2( 32f, 0f ) ), baseMat );

Media (6)

6,523
Total Users
16,980
Total Sessions
5.8 months
Total Playtime
Package ID: facepunch.libsdf
Created: 2023-04-27 10:24 UTC
Updated: 2025-09-30 15:14 UTC
Type: library
Public: Yes
Version: 121787
files: 57
Size: 0.5 MB
Engine Version: 22
Asset Version ID: 121787
Version Created: 2025-09-30 15:14 UTC
Hash: 8250603074539432805
Manifest: Open manifest
Project Template:
Cs Proj Name:
Summary: Marching cubes & squares mesh generation
Description: * Sdf2DWorld for 2D layers * Sdf3DWorld for 3D volumes
Public: true
Compiler: Sandbox, SANDBOX;ADDON;DEBUG, 1701;1702;1591;, Array, Array
Replace Tags: procgen mesh 3d 2d
Resources: /shaders/*.hlsl
Code Package References:
new_releases Latest Update Sep 30, 2025
Changes on 2025-09-30
121787 Sep 30, 2025
Changes on 2025-09-30
114518 Aug 18, 2025
Changes on 2025-08-18
77682 Nov 19, 2024
Changes on 2024-11-19
77637 Nov 19, 2024
Changes on 2024-11-19
71520 Aug 31, 2024
Changes on 2024-08-31
70881 Aug 28, 2024
Changes on 2024-08-28
70398 Aug 27, 2024
Changes on 2024-08-27
62649 Aug 1, 2024
Changes on 2024-08-01
62647 Aug 1, 2024
Changes on 2024-08-01
62629 Aug 1, 2024
Changes on 2024-08-01