It is kinda neat, but OpenSCAD's limitations are the main thing that motivated me to write this Python library to generate 3D meshes used signed distance functions:

https://github.com/fogleman/sdf

One big plus to doing it this way is that it's "just" Python and you can use arbitrary logic to help construct your model.

You can even load an existing 3D mesh and operate on it as an SDF. Great for hollowing, chopping, eroding/dilating, etc. existing models.

I should probably do more with this project. I think there's a lot of interest in this space.

Could you please elaborate on how this is different than the other python based modeling tools - build123d[0] and CadQuery[1].

I recently also got annoyed with OpenSCAD and its limitations and therefore started experimenting with Build123d. I'm very much a beginner in the CAD space and would love to understand what inspired you to build sdf.

My basic understanding is that STL files are essentially like Bitmap images and store a list of triangles and their positions, whereas STEP files are more like Vector art where there is a list of instructions on how to build the model. Most CAD GUI programs also operate on a similar model to vector art where they record a list of operations one on top of another. It's why STEP files are a standardized format and can be imported / exported from most GUI based CAD builders. I think.

Given that SDF also seems like it builds only STL files (I could be wrong), wouldn't learning build123d or CadQuery work better if one cares about compatibility with existing GUI based CAD modeling software?

Additionally, atleast build123d offers a similar conceptual model to using Fusion360 and FreeCad - I have limited experience here - but essentially you sketch something in 2D on a particular plane, and then apply some operations to convert it to 3d in a particular manner - the simplest being extruding. This means the mental modeling of how to construct something is very similar across both GUI based CAD programs and Build123d, and that makes it easier for me to jump between GUI based and code based CAD modelling.

I'd love to understand your point of view, and learn more.

[0] - https://github.com/gumyr/build123d

[1] - https://github.com/CadQuery/cadquery

It seems like you already understand the differences. I wasn't aware of those other projects. build123d looks pretty neat.

Like most of my projects, this was just for fun and I mainly made it for myself. I'm a DIY kind of guy when it comes to software. I just throw things up on GitHub in case anyone else can get some use or inspiration out of it.

> It seems like you already understand the differences.

Honestly I was about to ask the same questions as the parent comment. Whenever I'm interested in something I usually look at what available tools exists out there already; seeing a new tool mentioned that I've never heard of before, my reflex is to ask "oh neat, what makes it different than the existing tools?". I don't think the question was ill-intended, just genuine curiosity; assuming that you wrote your library because you had no idea build123d existed rather than because you were unsatisfied with it and wanted to tackle the problem differently is a bit of a leap.

I know it wasn't ill-intended, but my answer is largely the same. I like the idea of using SDFs to define models and this was just a fun little side project. And FWIW, my project predates build123d.

Interestingly, PythonSCAD has support for SDF by way of libfive:

https://pythonscad.org/examples.php

(search for "sdf" about halfway down the page)

> You can even load an existing 3D mesh and operate on it as an SDF. Great for hollowing, chopping, eroding/dilating, etc. existing models.

This has my instant interest. Multiple times I have wanted to take an existing .STL file and cut a hole on it or add another object to it and have never had success.

I've tried things like Meshlab, but while the interface has what appears to be a hundred different functions, attempting to use anything returns some error code that requires a PhD to understand and none of the "repair" functions seem to help.

I mean seriously: Mesh inputs must induce a piecewise constant winding number field.

How the hell am I supposed to accomplish that on a STL file?

You can do that effortlessly right in openscad itself or in freecad for a more visual way, or in every single cad app in existence I think.

In freecad you first just open the stl file, then Part -> Create part from mesh, then you have a solid you can modify.

Sounds great in theory until you actually try it and discover that anytime a STL touches another object the F6 render craps out with "Manifold conversion failed: NotManifold"

I just tried this in OpenSCAD and it crashed:

intersection() { import("3DBenchy.stl"); sphere(30); }

FYI, I just tested this in OpenSCAD version 2025.09.13 and it works fine.

Indeed it does. Looks like their recent dev builds are way better. Good to know.

People should share the original files or at least step files along with the stl files. But if you must work with stl, Fusion works brilliantly for this. You can open the stl file, which gives you the usual mesh that's hard to work with. You then convert that mesh to a solid object, on which you can use "direct modeling". It's not the same as a parametric object, but the editing features are quite powerful and sort of mindblowing. [1]

If you have the paid version of Fusion, you can run "feature detection" to turn things like holes, fillets, extrusions etc. into dedicated features which are even easier to edit. [2]

[1] https://www.autodesk.com/learn/ondemand/curated/direct-model...

[2] https://www.autodesk.com/learn/ondemand/curated/direct-model...

That feature requires getting pyopenvdb installed, which can be a headache, and I never really updated the README with examples, but it does work. There is one example script:

https://github.com/fogleman/sdf/blob/main/examples/mesh.py

You basically just say:

f = Mesh.from_file(path).sdf(voxel_size=0.25, half_width=1)

Then you can operate on `f`.

If it's a one-time thing, Prusa Slicer (and some other slicers too, probably) allow adding and subtracting simple shapes. So if, for example, you need to add a hole for a screw, you can do it directly in the slicer without messing with (and breaking the mesh of) an STL.

Blender also has a high learning curve but you typically don't need a PhD to understand the errors (instead you just watch youtube videos and copy what they do).

Removing faces from an STL and adding other objects is quite straightforward. Previously, Autodesk had Meshmixer and 123D, I guess Meshmixer is still available: https://meshmixer.org/ and I found it to be great for quick editing of the type you're describing.

OpenSCAD can load STLs and cut holes in them.

Tinkercad is a very low-barrier-to-entry option here

This is brilliant. The ability to do blobby/metaball style blends so easily is a big benefit.

From what I know, SDFs were popularised by the demoscene; it's interesting that they've now found more practical applications as a result.

They long pre-date the demoscene, going back centuries in mathematics. Ray tracing/casting of implicit surfaces (described with SDFs and more general signed functions) for computer graphics goes back to the 1960s and 70s. The 1990s demoscene 2D metaball effects were based on computer graphics work by Jim Blinn for Cosmos in 1980. Most current applications are based on that long ongoing research. (I did my PhD in implicit surface stuff, so I've seen tons of academic papers on it going back ages, and I never ran into demoscene methods in that context.)

Going back centuries piqued my interest, but I assume you just meant decades?

Not sure about SDFs, but ray casting/tracing goes back a long way being used to design sundials thousands of years ago. A method of ray casting was published in the 1600s to show how to trace out the outline of the Moon on the Earth during a solar eclipse.

See also my site fncad https://fncad.github.io ! It's basically intended as "SDFs in your browser with realtime preview with openscad-like syntax". I mostly use it for 3d models for printing.

What do you use for sdf meshing? I never really got the perf where I wanted it.

It's explained in the README. The SDF is evaluated on whole batches of points (32x32x32 tiles by default) using numpy. (And it's multithreaded.)

So uniform sampling? And then I guess marching cubes or sth?

I see you still haven't read the README.

marching cubes yep.

[deleted]

I've used your library and really like it!

Bless you for your service, sir! I have used `sdf` to create a whole bunch of stuff (buttons for my mother, tealight holders, etc.) and `gg` gets used in a bunch of places (including a couple of bots).

> I should probably do more with this project.

I, for one, would be glad.

maybe this will finally be the solution to my tapered variable pitch helix woes. it looks cool, thanks

SDFs are very neat up until the point where you need to build parts that have very precise specifications.

Something like two precisely interlocking gears with a tooth geometry with a profile that's the developed curve of the opposite tooth is a nightmare to build with SDFs

Or precise fillets.

Or hard intersections and differences.

Very useful for doing soft, squishy shapes, less so for hard CAD.

Also, a suggestion: in your project, please consider using Wavefront OBJ as an output format, it is a much, much better choice than STL (STL can't represent the actual topology of the object, it has to be reconstructed).

[deleted]