logoalt Hacker News

foglemanyesterday at 8:24 PM11 repliesview on HN

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.


Replies

vhandayesterday at 10:13 PM

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

show 1 reply
WillAdamstoday at 2:46 PM

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

https://pythonscad.org/examples.php

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

mosuratoday at 2:15 PM

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

jandreseyesterday at 9:12 PM

> 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?

show 6 replies
the_cat_kittlestoday at 5:14 PM

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

userbinatortoday at 9:40 AM

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

show 1 reply
FeepingCreatureyesterday at 11:23 PM

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.

show 1 reply
JonathanRainesyesterday at 8:40 PM

I've used your library and really like it!

zimpenfishyesterday at 10:43 PM

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.

ur-whaletoday at 4:00 AM

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).

show 1 reply