3

After 3-4 days of working on a 256 look up table for the marching cubes algorithm I finally have it working. Now That I have it working I want to try to optimize it. One thing I thought of is removing big flat areas with one float area.

Example Image to show what I am thinking Example Image to show what I am thinking

How I use my lookup table to Generate the mesh

 /* Cube description:
 *        p7 ________p6           ____e6__          
 *         /|       /|        e7/|       /|         
 *       /  |     /  |        /  |     /e5|      
 *  p4 /_______ /    |      /__e4___ /    e10     
 *    |     |  |p5   |     |    e11 |     |     
 *    |   p3|__|_____|p2   |     |__|__2__|     
 *    |    /   |    /     e8  e3/   e9   /      
 *    |  /     |  /        |  /     |  /e1       
 *    |/_______|/          |/__e0___|/          
 *   p0        p1                  
 */

 for (int x = 0; x < chunkSize; x++)
    {
        for (int y = 0; y < chunkSize; y++)
        {
            for(int z = 0; z < chunkSize; z++)
            {
                Vector3 point = new Vector3(x, y, z);

                int value = 0;

                if (voxelData.Contains(point))
                    value += (int)LookupTable.VoxelPoint.p0;
                if (voxelData.Contains(point + Vector3.forward))
                    value += (int)LookupTable.VoxelPoint.p3;
                if (voxelData.Contains(point + Vector3.right))
                    value += (int)LookupTable.VoxelPoint.p1;
                if (voxelData.Contains(point + Vector3.right + Vector3.forward))
                    value += (int)LookupTable.VoxelPoint.p2;
                if (voxelData.Contains(point + Vector3.up))
                    value += (int)LookupTable.VoxelPoint.p4;
                if (voxelData.Contains(point + Vector3.up + Vector3.forward))
                    value += (int)LookupTable.VoxelPoint.p7;
                if (voxelData.Contains(point + Vector3.up + Vector3.right))
                    value += (int)LookupTable.VoxelPoint.p5;
                if (voxelData.Contains(point + Vector3.up + Vector3.forward + Vector3.right))
                    value += (int)LookupTable.VoxelPoint.p6;

                Vector3[] vertsOutput = LookupTable.GetVerticies(value);

                    if(vertsOutput == null)
                        continue;

                foreach (var vert in vertsOutput)
                {
                    tris.Add(verts.Count);
                    verts.Add(point + vert);
                }
            }
        }
    }

    mesh.vertices = verts.ToArray();
    mesh.triangles = tris.ToArray();

Thank you for anything that may point me in the right way or help me solve this.

Edit* What im working on

Shredder2500
  • 1,065
  • 2
  • 11
  • 26
  • Interesting. You are trying to put all meshes that belong to the same **plane** in space inside one bigger mesh. The vertices of one edge of this bigger mesh is defined by the vertices of the triangles of the smaller meshes that share the same **line**. – Roberto Feb 26 '14 at 04:06
  • 1
    Perhaps you should take a look at this too: http://www.giawa.com/journal-entry-6-greedy-mesh-optimization/ – Roberto Feb 26 '14 at 04:09
  • @Roberto Yes that is a really good way of explaining it, I will take a look at that link. Thanks! – Shredder2500 Feb 26 '14 at 04:10
  • @Roberto Thanks for the Link! looking over it, it looks like it may work but will need some tweaking for the angled planes. I will try to implement this tomorrow and see if it works. Thanks Again, will let you know if it works. – Shredder2500 Feb 26 '14 at 04:27
  • 1
    @Roberto Yeah I am unable to get this working with the Marching cubes algorithm. It could be I don't understand the code in that link well enough but I did some research into the greedy algorithm and couldn't find anything under the greedy algorithm that would help in this case. If you understand how it would work with marching cubes please explain it a bit. – Shredder2500 Feb 26 '14 at 22:24
  • Have you decided this or saw anything appropriate? – Julia Grabovska Feb 22 '17 at 09:25

0 Answers0