Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better STL Generation #6

Open
deadsy opened this issue Feb 24, 2018 · 10 comments
Open

Better STL Generation #6

deadsy opened this issue Feb 24, 2018 · 10 comments

Comments

@deadsy
Copy link
Owner

deadsy commented Feb 24, 2018

Problem: The marching cubes algorithm gives STLs that are large in size and have aliasing defects on sharp edges.

Solution: Have a mesh generation algorithm that is adaptive to the curvature of the object. ie- big triangles on flat surfaces, small triangles for sharper curves. A quality metric could allow trade-offs between file size and mesh accuracy.

@deadsy
Copy link
Owner Author

deadsy commented Feb 24, 2018

I've been reading this book.

@ghost
Copy link

ghost commented Mar 9, 2018

Like a LOD algo ? Level of detail.

It's been used in games for years based on distance.
Are you proposing to do it based on curve radius per object ?

It would be very useful to allow the LOD to be driven changed at runtime based off distance too as it would make a 3d viewer very efficient

@deadsy
Copy link
Owner Author

deadsy commented Mar 9, 2018

Not so much LoD. More like minimizing the number of triangles needed to represent the local detail of the object. Marching cubes samples the bounding box and generates triangles whose size matches the sampling resolution. As a result even planar surfaces end up with lots of little triangles. Those surfaces would be more efficiently represented with a few large triangles. The CGAL project has code that can deal with kind of thing. E.g. https://doc.cgal.org/latest/Surface_mesher/index.html#Chapter_3D_Surface_Mesh_Generation

@ghost
Copy link

ghost commented Aug 25, 2018

I have been again playing with this to use with a Milling machine.

Regarding the mesh generation and sharp edges, has there been any movements or thought on this.
The reason i ask is not just because of the tessellation problem on sharp edges.
The other reason is because i want to build in the ability to manually push and pull the mesh in a GUI.
This is basically where you want to do manual adjustments for more organic looking shapes.

@deadsy
Copy link
Owner Author

deadsy commented Aug 25, 2018

No code written - thinking about it on and off. It's a well recognized problem when it comes to representing objects with meshes. There are solutions out there that just remove triangles selectively from a given mesh. The difference here is that the triangle tuning can be done with on-going knowledge of the SDF, thereby leading to a more accurate mesh. BTW - when it comes to 3d printing the STL file I haven't had any problem with the corner aliasing - it's too small to make a difference- so it's mostly an annoyance in the mesh viewer. I'm sure the slicer would work faster if it wasn't dealing with so many triangles, but it hasn't been an insurmountable problem, and the output gcode will be roughly the same irrespective of the input mesh size. I assume the milling machine experience would be about the same.

@deadsy
Copy link
Owner Author

deadsy commented Aug 25, 2018

do manual adjustments for more organic looking shapes

That might be easier if you have lot's of triangles on a surface to start off with - which is what you have here.

@ghost
Copy link

ghost commented Aug 25, 2018 via email

@ghost
Copy link

ghost commented Aug 25, 2018

found this !
https://github.com/g3n/engine

All golang 3D gui viewer. I think i can use this as a canvas and load up the STL's into it to do the pushing and pulling.

Its nice to see this type of 3D stuff in the golang world.

@danieltwagner
Copy link
Contributor

https://github.com/danieltwagner/sdfx/tree/simplify has a WIP mesh simplification algorithm. The idea is to not lose any details, i.e. only reduce coplanar triangles. It's mostly working but I must be generating a few triangles with bogus normals (maybe zero-size triangles?). I'll try to sort out the issue and tidy it all up and then put it up as a PR but would appreciate another pair of eyes.

I attach an example below. You can see that a few wireframe lines are visible in the wrong orientation and as a result the interior cutout doesn't appear smooth.

Before (160160 triangles):
Screen Shot 2020-10-17 at 11 36 45 PM

Screen Shot 2020-10-17 at 11 36 40 PM

After (2648 triangles):
Screen Shot 2020-10-17 at 11 37 27 PM

Screen Shot 2020-10-17 at 11 37 31 PM

@deadsy
Copy link
Owner Author

deadsy commented Nov 9, 2020

I haven't had a chance to review your code yet...

I saw this and thought it was of interest:

https://www.reddit.com/r/computervision/comments/jq98ow/shape_aware_mesh_simplification_after_scanning/?utm_source=share&utm_medium=web2x&context=3

Based on: https://www.cs.cmu.edu/~garland/thesis/thesis.html

Also: There are (at least) two approaches to this:

  1. Use marching cubes to build a fine triangle mesh and then simplify the mesh.
  2. Use something other than marching cubes to perform adaptive sampling that does a better job of the features with high spatial frequencies. ie get rid of the aliasing that is present on corners/edges.

Approach 2 is possible, we have an SDF model that can be sampled wherever we like, it's just a bit beyond my sophisication at the moment. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants