News for hackers. Stuff that matters.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by fogleman on Monday February 15, 2021 @11:45AM (#26144352)
Hi HN.

Well, I wanted to make a 3D model and 3D print it, but I just didn't want to use OpenSCAD. So I ended up making a whole new 3D modeling library based on signed distance functions. I'm pretty happy with how it turned out so far, so I thought I would write a nice README and share it here.

It's certainly complete enough that you could try it out and make your own 3D models - let me know if you make anything interesting!

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by sjkelly on Monday February 15, 2021 @09:05PM (#26150110)
That's pretty cool. I see you are using marching cubes. How are you handling sharp geometry (I'm assuming previews use a finite difference for normals)?

Also I see you are at formlabs. I'm sure you know of Matt Keeter's libfive :)

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by fogleman on Monday February 15, 2021 @09:50PM (#26150389)
Yes, I'm well aware of libfive!

I'm not doing anything special for sharp geometry. For now you just need to use sufficient resolution until it looks "good enough." Normals are just based on the triangle normals.

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by bhouston on Tuesday February 16, 2021 @09:41PM (#26162012)
Take the spatial derivative for the normals? Runga-kutta methods work wonders for that: https://en.m.wikipedia.org/wiki/Runge–Kutta_methods That works well if they are true signed distance.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by user-the-name on Wednesday February 17, 2021 @05:01AM (#26164708)
Since you have a distance, you could fairly easily implement dual contouring, I think?
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by andybak on Wednesday February 17, 2021 @09:44AM (#26166795)
Or Surface Nets. Nice compromise of speed and quality. Marching cubes needs a lot of resolution and it's imperfections are especially ugly my eyes.

Maybe mesh resolution isn't a problem for 3D printing. But if 3D printing is the main goal why bother with a mesh? Just go straight to voxels that can be fed directly to the printer.

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by user-the-name on Wednesday February 17, 2021 @10:18AM (#26167238)
The printer does not use voxels, it uses G-codes, which are tool paths for the print head.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by tdotuos on Wednesday February 24, 2021 @11:49PM (#26259813)
True for FDM, but for SLA you have the potential rendering a direct slice of the SDF.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by andybak on Wednesday February 17, 2021 @12:42PM (#26169089)
OK. But a voxel representation has to be a closer match than a mesh. I guess overhang, solidity etc still need to be calculated and dealt with. Which is non-trivial.

Is it that "mesh to G-code" libraries are more mature than "voxel to G-code"?

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by stuntkite on Tuesday February 16, 2021 @02:59AM (#26151859)
This is great. Thank you for making it! The api layout tells me you are a nice person.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by tboerstad on Wednesday February 17, 2021 @06:48AM (#26165366)
Love the library! I did not know about signed distance functions, and I am just amazed of the complex shapes that can be made from simple primitives.

Thank you!

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by mfost on Wednesday February 17, 2021 @09:25AM (#26166572)
If you want to go even deeper than that: https://www.youtube.com/watch?v=8--5LwHRhjk
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by jmpeax on Wednesday February 17, 2021 @12:13AM (#26162973)
What a beautiful library and api! I don't 3D print, but I'll be studying your code as a master-class in how python should be done.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by blt on Wednesday February 17, 2021 @12:36AM (#26163092)
out of curiosity, why did you not want to use OpenSCAD?
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by bvrmn on Wednesday February 17, 2021 @06:00AM (#26165042)
OpenSCAD is pretty rigorous regarding defining relative geometry. Like shifting origin and sketch on plane rotated 30° around X. It leads to unnecessary math to place objects.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by alpaca128 on Wednesday February 17, 2021 @06:13AM (#26165134)
It can be a bit cumbersome sometimes, but the only thing that really slows me down is the rendering performance. As soon as the detail level exceeds a certain range it basically becomes a bottleneck the size of a singularity.

Just the last few days I spent hours creating an external preprocessor for a project so I can feed as little data as necessary into OpenSCAD. Luckily it kind of worked and got me from "process gets killed after 70 minutes" down to "finished rendering in 5 minutes".

Still it's my favorite CAD software because the coding paradigm just feels so much more intuitive and simple than what FreeCAD and others do.

I'm definitely going to try out this project, though; it looks very promising as well.

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by sitkack on Wednesday February 17, 2021 @10:09AM (#26167119)
(to the channel), I am sure you know about it, but this [1] technique for making a big design a tree of smaller designs works ok.

I feel like OpenSCAD is like 2 standard deviations away from perfection. Functions vs Modules and how clunky composition and application of operators over the object tree. It almost needs to be Datalog. Right now, it is a notch under SQL.

[1] https://old.reddit.com/r/openscad/comments/lbq58y/my_approac...

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by alpaca128 on Wednesday February 17, 2021 @01:50PM (#26169972)
The problem in my case was that I wanted to combine a pattern with my objects that I precomputed using an external program because it contained a lot of curved surfaces. As I already knew OpenSCAD basically becomes unusable if you try to use a png image as heightmap I decided to instead generate a .scad file containing an array with precomputed coordinates, and then used that to build and extrude 2d polygons.

This kind of works for the 3d preview, but the stl renderer was not happy regardless. It was basically the worst case for OpenSCAD. But still, the fact I could just auto-generate a text file and use it directly for building models is fantastic. With tools like FreeCAD I wouldn't even know where to start, here it was basically a case of "it just works" and with a few more minutes it can be combined with a bash script for batch rendering.

Re:Show HN: 3D Meshes of Signed Distance Functions in Python by blt on Wednesday February 17, 2021 @01:59PM (#26170081)
Isn't this par for the course for constructive methods though? I agree that some things that are easy in a classic constraint-based CAD package are a huge burden in OpenSCAD. However, I don't see how signed distance fields would change that.
Re:Show HN: 3D Meshes of Signed Distance Functions in Python by bhouston on Tuesday February 16, 2021 @09:39PM (#26162000)
So elegant. Nice job!