Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Marching cubes help.

Discussion in 'Scripting' started by kennethrunescape2019, Sep 20, 2019.

  1. kennethrunescape2019

    kennethrunescape2019

    Joined:
    Feb 5, 2019
    Posts:
    109
    Hi, I have been trying to make a terrain system that the player can terraform, and at the same time is smooth enough for vehicles to drive over.

    What I have found is called marching cubes but I have not found any decent tutorials that show how to implement it in unity. Can soneone please help me or point me to some documentation / tutorials?
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I implemented it using this paper: http://paulbourke.net/geometry/polygonise/
    However, be aware that it's a somewhat advanced topic, especially when you start to consider performance.

    The idea is that you calculate the index of an imaginary cube, based on the scalar values in its vertices. Doing this for all values in your scalar field resembles a "cube marching through the data", hence the name.

    This calculated cube index is then used to look up the list of corresponding edge indices, which tells you which edges you need to connect in order to create the mesh that belongs in that cube-sized space. You can then, for example, take the center points of the edges and connect all these points in the given order to create the actual triangles that make up the mesh. To create more smooth terrain, you will want to interpolate the position on the edge, based on the values of the vertices that the edge connects.