Show HN: 3D Meshes of Signed Distance Functions in Python
github.com
github.com
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!
Also I see you are at formlabs. I'm sure you know of Matt Keeter's 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.
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.
Is it that "mesh to G-code" libraries are more mature than "voxel to G-code"?
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.
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...
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.
Thank you!
Something that I find inspiring in his work is that he seems to use pretty !boring! tech (imho). No rust?! No lisp/reactive/functional/esoteric programming!? what?! You can't be cool if you use mainstream tech like go or python, right? Well, it turns out, you can!
Well done sir :-)
Thanks for the kind words.
I'm a little more comfortable in python, plus I think the language is better suited to this, as a DSL or something like it. I'll definitely try it out, thank you for sharing.
I just got text working, which is very exciting. It was surprisingly easy, too.
1) Render text to a high resolution 1-bit array using PIL 2) Compute the distance transform using scipy 3) Do some index fiddling to map it into world space, and it's done!
Even works with unicode: https://twitter.com/FogleBird/status/1361523405821005824
CadQuery is another library for programming 3d-models in Python. A good alternative to OpenSCAD. Has integration in FreeCAD but can also be used stand-alone.
SDF and mesh extraction are one of my favorite areas of research. I think it is very important for additive manufacturing in particular. The value will be hybrid SDF and spline methods for complex and highly integrated applications such as fluid and heat transfer or compliant mechanisms.
Modeling a box or cylinder with SDF isn't the right application IMO. Optimized topology for a given PDE is.
Like anything in engineering and design, IMO, it depends on who you are what you are doing.
> SDF and mesh extraction are one of my favorite areas of research.
Why convert a SDF to a mesh to do visualization and engineering analysis? Even with FDM, which can be thought of a 2D filling problem like scan conversion once you have a SDF, meshless may be the way forward with additive manufacturing as well. One can think of reasons you would have to do mesh extraction, but for niche areas of manufacturing.
Check out the company/product nTopology. It's IMO the future for engineering modelling and CAD for AM.
I used to work for an AM company and was essentially the internal evangelist that complained about STL's and "traditional" CAD formats that are proprietary or just outright a PITA to work with (I'm looking at you, STEP...)
As for rendering, the SDF can be rasterized in shader, or it can be cube-marched to mesh and rendered in standard pipeline. It would be great to hear your opinions on both methods in context of real-time graphics.
Edit: Here's a video of Dreams shape manipulation https://youtu.be/D4Kk36oqGMY?t=589
The basic idea is that if you evaluate the SDF at a given point, you get the distance to the nearest surface. Thus, you know it is safe to step that far in any direction without crossing a surface. So you can step along a ray with a step size determined by the SDF at each point to quickly converge on a surface.
How would you end up with badly-formed SDFs?
So in practice what you try to do is find an SDF that is not TOO far off from what it should be. Ideally, it should always have an absolute value that is equal to or less than (but not by too much) the real, ideal SDF.