- Home /
How to remove small & thin triangles from a marching cubes voxel engine?
Is there a method for customizing marching cubes cases or another processing approach to remove small & thin triangles?
See example of problem here; https://youtu.be/DFr6RJQEcpA
sorry, original link didn't work. should be there now; https://youtu.be/DFr6RJQEcpA
Answer by Bunny83 · Dec 20, 2017 at 01:11 AM
This question doesn't make much sense, even with an example. Marching cubes works with exactly 256 predefined triangle configurations (actually only 15 in you remove all symmetrical duplicates) if you "remove" any of the triangles you no longer get a closed mesh.
So either you actually do not talk about marching cubes or you do something really strange.
edit. OK since you now posted the video it seams you don't really talk about thin triangles (triangles are two dimensional shapes) but simply about small voxel clusters.
This "problem" should not be solved by changing the marching cubes algorithm. It's a pure rendering algorithm. You should try solving this when editing your voxel data. However there's not really an easy, straight forward solution. When removing a spherical section of your data you should check the surrounding data for integrity. So you might want to remove such small left over clusters automatically.
It doesn't make sense? I'm talking about a modification to the predefined triangle sets or a post processing of resulting mesh to solve the thin/small triangle cases.
If it takes something strange to make this work, i'd like to hear about it.
Answer by tomaszfoster · Jan 23, 2018 at 04:36 PM
So marching cubes will have those triangles but you can use an alternative method like Naive Surface Nets.
Mikola Lysenko discusses in detail the different methods on his blog: https://0fps.net/2012/07/12/smooth-voxel-terrain-part-2/
and if you're looking for a C#/Unity solution I have the code available on GitHub with detailed comments. Maybe it'll help: https://github.com/TomaszFoster/NaiveSurfaceNets
Thanks $$anonymous$$asz, I spent much time with $$anonymous$$ikola's brilliant js code for this but could not get it to work correctly in C#. I am very grateful you have made this publicly available.
I will see if i can adapt your code to work with a density array. From what i can see it should be a matter of swapping out your sampling function?
$$anonymous$$y implementation differs in that I pulled out each step into its own function. It’s not as efficient but it should be much easier to understand.
First you create a 3d grid of voxels, then you find the weighted averages for each voxel based on what tolerance you have set and save only voxels which have intersections into a new list, then you create the triangles for the voxels you’ve just made. If you already have a voxel grid and have calculated the weighted averages, you could probably just use the triangulation function.
If you have any questions or if I didn’t explain something let me know and I’ll see if I can help. Best of luck!
I like what you've done. It is much easier to understand. Some of the areas i still don't know exactly what's going on, it's a lot for my $$anonymous$$d to unpack.
I had a go at implementing it but still missing a few bits. I may just need to get back to basics to see where i've messed up.
Any feedback or suggestions would be welcome. I've posted screenshots and the modified code of yours i'm testing in my engine. http://www.nuzly.com/
I'm glad that helped. It took me days to go through and try to make everything work and I could probably clean up some of the names for more clarity and add some better documentation. Converting from JS to C# was a bit weird since one is dynamic and one is statically typed but it worked!
What bits are you missing? I saw that you switched the order of this operator corner$$anonymous$$ask |= ((sample < threshold) ? (1 << i) : 0);
from sample > threshold
to sample < threshold
.
Also I noticed your images don't load for me on Chrome or Safari, I got a 500 URL rewrite error