Hello,

I’m working around with unity for a few months. I have some experience in java. I’m honest to you. I feel like actually dying. I’m googling, reading, testing for 2 weeks with no solution in sight. If i would see any hope I wouldnt open a post. I’m really desperate.

My plan is to generate a smooth voxel terrain. I’ve read tutorials and all kind of stuff with voxels and marching cubes for 2 weeks. (b4 I played around with hightmaps and meshes)

I’m at the point that I have created a surface simply cloning a prefab cube over and over again and adding a perlin noise.

The cubes are only instantiated, not in a array, list, etc.

So how do i actually get from my cubes to marching cubes?

I do understand how the algorithm roughly works in theory, but I can’t recreate it in C#-

I have read Paul Bourke’s article several times. I got an idea how it works but i have no idea how to implement it in C# and make it work with my cubes.

I have also found some example code, I sadly didn’t get it to work. I do somehow understand what some methods will do but I can’t recreate it and I don’t know how i get from the cubes to the point i can implement a marching cubes algorithm.

I feel like saving the cubes in a 3d array would be a good start… but what next?

This is how my “terrain” looks like:

I am trying to figure this out myself, but I think your first step should be creating a single mesh for this ‘chunk’ of terrain. In order to do this you will need the vertices, uvs, and triangles of the mesh you want to make. I guess you might be able to calculate this from from your cubes however I would recommend checking out Nintendo Examiner’s Let’s make a voxel game series. One downside to this is that at a few points he makes fixes/changes to his scripts off camera, however you can find them by looking at the script in his video. Also do not use his github download link because it does not work, and his scripts are more complicated than in the tutorial.

Well, implementing marching cubes from scretch is quite difficult because it’s quite hard to setup the 256 triangle combinations right. Though I’d like to add that if your voxel data is only composed of binary values (a bit like minecraft: occupied or not) then all you need are the 256 cases which are just rotated versions of the 15 base configurations as you can see them on the marching cubes wiki article.All vertices are exactly half way between two corners of an edge. Though when you have a real iso surface things get a bit more complicated. Since each “voxel value” does no longer correspond to occupied or not but each value has a float indicating the “size” of each voxel. You still need the binary representation to pick the right triangle configuration though. This is done by a simple threshold comparison. Once you have picked the configurations the vertices are not just placed at the center of each edge, but are interpolated based on the actual voxel values.

The most tricky part may be to create shared vertices (if you want / need them). Since each edge in the voxel grid is shared by 4 triangle configurations the vertex on that edge belongs to those 4 configurations. It should be also noted that with the 15 case solution there are ambiguous situations (mainly for iso surfaces) which can be resolved by checking the interpolated center like described on page 3 of this paper

Note that it’s probably easier to just use an existing solution. Google gave me this one. It has an MIT license. Though if you insist in implementing it yourself that’s something you have to decide if you can pull this off or not ^^.