Marching Cube algorithm help


Recommended Posts

Hey there i am trying to copy what is done in this video: (622) How to Make 7 Days to Die in Unity - 01 - Marching Cubes - YouTube

but unfortunately i am confusing some terms and i don't know what exactly I'm doing wrong, right now my goal is to show all the different configurations of  the marching cube algorithm by pressing 'SPACE', it should just go to the next configuration but i have the following problems:

  • only the 1st config is shown right all the others are not as this:2880px-MarchingCubes.svg.png
  • the previous config does not get removed or overwritten even if i reset the values of the object.


i think i am building the mesh incorrectly  in the example given they just do:

    void BuildMesh () {

        Mesh mesh = new Mesh();
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        meshFilter.mesh = mesh;


but the way Unigine makes meshes is still a bit confusing to me.

this is the only piece i generate correctly:


can some1 help me with this please. here is the class:

Edited by Kireita
Link to post


You can check some marching cube algorithm implementations in SDK Browser -> Samples -> UnigineScript -> Objects -> dynamic_** (01 / 02 / 03). I think you can easily rewrite them to the C#.


  • Like 1

How to submit a good bug report
FTP server for test scenes and user uploads:

Link to post

Ki kireita,


I already implemented an complete marching cube algorithm for my project during last year, but with C++. The goal was to have an input for raw voxel data and the algorithm should take the rest. Just contact me via PN, I will forward you the necessary files.



  • Like 1
Link to post
3 hours ago, silent said:


You can check some marching cube algorithm implementations in SDK Browser -> Samples -> UnigineScript -> Objects -> dynamic_** (01 / 02 / 03). I think you can easily rewrite them to the C#.



Hey @silent, i saw these examples and also used it with my project but unfortunatly i did not understand half of what was going on that is why i resorted in the forum.

i will ask @christian.wolf2 for some help and i will see how far i can get, thanks!

Link to post


In BuildMesh function you are using mesh.AddTriangles(1), but triangles list contains the triangle indices. Instead, I added all triangle indices. After that, you can see different combinations. In the attached component you can see my changes.



  • Like 2
Link to post

@karpych11 omg thank you!!! it is finally working! :D

a big thanks to @christian.wolf2 and @silent for both helping me i finally got it working, 

i am still confused how it works with the triangles, because i tried to use the uniginescript as reference i got confused.

just to be clear @karpych11 for each triangle that is in that configuration you just need to add the 3 indexes, indicating the triangle's position? am i understanding that correctly?

also this:


i definitely needed that, thank you! :D

here is the first iteration:

but i am definitely happy it is working now, this thread can be closed :D

Link to post

just as a last question

what would be the equivalent of the perlin noise funciton of unigine vs unity?

i was succesfully able to generate a map with marching cubes but the problem is i need to play with the perlin noise to get the exact result as the video.


 float thisHeight = (float)height * Mathf.PerlinNoise((float)x / 16f * 1.5f + 0.001f, (float)z / 16f * 1.5f + 0.001f);


var xxx = Game.GetNoise2( new vec2((float)x / 16f * 1.5f + 0.001f, (float)z / 16f * 1.5f + 0.001f), new vec2(x, y),16);


this is the map i was able to generate with the values i had:

i do like the fact that i have a terrain now so that is not the problem, i just want to understand how to work with perlin noise correclty.


the result in unity was this:

i just want to know how to translate the perlin noise functions of unity to unigine, thats all.

thank you again :D

Link to post


Yes, three indexes completely describe a polygon in the form of a triangle. These indices simply give numbers of vertices that form triangle. For generation I tried using GetNoise2 function with different parameters. You can see the result in the image below or in the video. The attached component contains all the source code.



  • Like 3
Link to post

@karpych11 o wow!, i just wanted to understand  how perlin noise worked but this is even better :o!

you basically remade what i wanted to make, thank you! and it looks so smooth.

i will stop asking questions now XD thank you!

Link to post