fu5ha / sdfu

Signed Distance Field Utilities
https://crates.io/crates/sdfu
118 stars 11 forks source link

Question: Use sdfu for programmatic CAD #2

Closed giannissc closed 3 years ago

giannissc commented 5 years ago

Can this library replace something like OpenSCAD or ImplicitCAD or do more operations (e.g. 2D extrusion, minkowski addition, hull) need to be implemented?

Also can this library be paired with a rasterizer instead of a path tracer for real time rendering?

Finally how much work would it take to export to something like an STL or STEP format?

Thanks you in advance!

fu5ha commented 5 years ago

Hi!

At the moment only relatively basic operations are limited so yes, more operations would need to be added. This could replace something like openscad if you were going to be using it in a computer graphics pipeline that could render SDFs, but it couldn't directly replace it if you need a triangulated output.

If you wanted a triangle mesh (STL), it would be possible to do this, however not easy at all. You'd need to implement a mesh generation algorithm that accepts an SDF as input, which is non trivial. And as far as STEP, I'm not really sure because I'm not super familiar with how that format works.

In the end, this library isn't really intended to be used as a CAD tool, but rather as a way to make pretty pictures :)

giannissc commented 5 years ago

Hi back and thank for the quick reply! I must admit that is does take great pictures ;)

How about if the output is stored in a blender file and then have blender convert it to STL or STEP?

I would be interested in contributing to this crate by adding more CSG operations and attempting to built a mesh generation pipeline!! (This is a go project that has a similar scope https://github.com/deadsy/sdfx)

Would these be a good place to start?

CSG: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.697.4388&rep=rep1&type=pdf https://www.researchgate.net/publication/221314157_Real-time_CSG_rendering_using_fragment_sort https://pdfs.semanticscholar.org/7a49/eff46897f6db95d37929c3610aaf2786813b.pdf

SDF: https://arxiv.org/pdf/1903.00353.pdf

PS. I have been having trouble compiling your path tracing crate (rayn). Could you help figure out what went wrong?

fu5ha commented 4 years ago

I must admit that is does take great pictures ;)

Heh, thanks!

How about if the output is stored in a blender file and then have blender convert it to STL or STEP?

I don't think this would help as blender doesn't have native support for SDFs. You still have the problem of converting from an SDF to a polygon mesh.

I would be interested in contributing to this crate by adding more CSG operations and attempting to built a mesh generation pipeline!! (This is a go project that has a similar scope https://github.com/deadsy/sdfx)

Sounds awesome, I'd be in support of it! I know there's been some rumblings of interest in something like this from a game asset creation point of view as well; a mesh generation pipeline for CAD should also be usable in a game asset creation pipeline.

Would these be a good place to start?

The papers on CSG are probably not directly helpful in this case as they are defining how to do CSG operations directly on polyhedra mesh or other areas.

The one you linked on SDFs is actually doing the inverse of what you'll need to do. What you want is to take an SDF and turn it into a triangle mesh, not take a triangle mesh and turn it into an SDF.

I'm not sure if there are papers on this (there probably are), but a relatively simple c++ implementation of one way to do this is here https://github.com/Magnus2/MeshReconstruction

PS. I have been having trouble compiling your path tracing crate (rayn). Could you help figure out what went wrong?

Sure! Post an issue on that repo and I'll be happy to help.

piaoger commented 4 years ago

see curv: https://github.com/curv3d/curv/blob/master/ideas/v-rep/To_Mesh.rst

giannissc commented 4 years ago

Thank you both for your replies. I will look into them!

I have another question though: What is the benefit of doing CSG using SDFs vs polyherda mesh?

I assume it would be higher resolution?

giannissc commented 4 years ago

Also the error I have had was quite simple to solve. Basically after the rendering of the image it wouldn't store it on the png and the process was crushing due to the render directory missing. As soon as I created a renders folder everything compiled just fine. You might want to look into that!

giannissc commented 4 years ago

Another question: Is rayn meant to be used as a library or was it just a toy project? Cause if it's the former you should consider specifying so in the config file and moving the main.rs file into an examples folder

giannissc commented 4 years ago

Also I am not sure if the render.png file you have as part of the repository should be the same image as the one I get when running the project cause currently they are not

fu5ha commented 4 years ago

Glad you got it working. I do actually know about that but, it's happened to me a couple times heh, just haven't gotten around to fixing it.

rayn is its own project, not meant to be a library but rather a binary in itself.