- Home /
Mesh simplification for Marching Cubes algorithm?
In the picture you can see the blue wireframe of marching cubes, I drew in the red lines, they represent what I want to accomplish.
Essentially I want to reduce the number of triangles used to accomplish the flat surfaces of the marching cubes algorithm.
Here is another picture to show the shear mad number of triangle that make up a couple flat surface's.
I'm slowly but surely working on this. It's see$$anonymous$$gly simple so I should have an answer eventually so check back if your interested.
I've simplified only the surfaces that are parallel with the x y and z axis. Here is a screeny...
I stored the faces in an array that can be accessed through position.. like array[x,y,z]. Then I checked the face's normals against neighboring faces.
It is all pretty specific to my marching cubes code. I wouldn't be able to simplify models that are loaded in.
Any chance you could post the code for simplifying the mesh faces?
It is pretty messy and inefficient code but if you can learn something I'm happy to share. Just put the marchsect script on an object and run. The code that handles simplifying is named Gensect.
Let me know if you have any questions. $$anonymous$$aybe one day when I have more time I'll go back and make it efficient.
also please let me know what you think.. even though its older I do appreciate criticism!
Omg stupid linky ..link text
did it work Ill post scripts seperatley if not link text
Would it be possible to see your source? Just for the marching cubes implementation.
I gave up on the decimating the diaganal faces I'll come back to it.. umm I sappose I could post the source, later though. perhaps tonight.
I'm posting a file of the c# code I'm currently using for a marching cubes level generator. I plan to make a castle full of rooms generated by this code.
Answer by HappyMoo · Jan 02, 2014 at 02:39 AM
That's interesting... makes me wanna implement marching cubes...
The problem with unity meshes is that they are not easily traversable as they are built for speed and don't have stuff like references to neighboring tris etc. which would help, but maybe you can build some helper classes that allow you to do this and also mark tris etc.
Now... what you would do is start at a triangle and recursively(doesn't have to be implemented that way of course) visit all neighbors with the same (float precision!) normal and gather them all in a group - also mark them, so they wont get visited on the next iteration when you start from an yet unused triangle.
So.. we're having a group of triangles, all connected and complanar. Start with a triangle somewhere and create a bigger and bigger polygon(pink line) by removing the edge to the next neighbor. Here you may need to watch out that you don't break into triangles you already used.
You won't have holes very often like in the example, but if you do, the internal edge connecting the outside with the holes can look very ugly, but some simple rules like always traversing open neighboring triangles ordered by x,y,z will prevent the worst.
After that, traverse all the edges of the new polygon and remove all collinear verts we don't need (blue line). And retriangulate (orange)
You'll hear a lot that marching cubes is composed of 14 edge combination but there are more triangle combinations I didn't realize that and I was stuck for while.
Some of the opposite edge combinations require a unique triangle combination.
Oh yah I also didn't realize you are sapposed to check for opposite edge cases, for example the triangle set used for the bottom front left is also used when every edge, except for the bottom front left, is marked or on or checked or whatever. The triangle sets normals are just flipped.
/ the pictures wont post >:(( /
One picture is of the 13-14 origial triangle combinations you can find anywhere.. The other is the 7-8 alt cases that took me a while to find. Ill reupload that one..
Thanks for the warning. I was also planing to do my list from scratch if I was to implement vanilla $$anonymous$$arching Cubes, however, I found some other interesting algorithms so I'm not sure yet which one to do.
http://swiftcoder.wordpress.com/planets/isosurface-extraction/
It's also not that I actually need it for something currently - I'd do it just for fun, so maybe I'll delay that decision some more.
Can you link to these pictures once more? Seems the server didn't actually upload them. $$anonymous$$aybe because of the spaces and () in the name
I just now relized you had that cool gif image in your post, seems like a good way to do it.
Answer by Cherno · Mar 05, 2015 at 09:58 PM
Take a look at "greedy mesh" algorithms, and especially take a look (heh, 52 pages and counting!) at this thread: