3

マーチング キューブ アルゴリズムの 256 ルックアップ テーブルに 3 ~ 4 日間取り組んだ後、ようやく機能するようになりました。動作するようになったので、最適化を試みたいと思います。私が考えたことの 1 つは、1 つのフロート エリアで大きなフラット エリアを削除することです。

私が考えていることを示す例の画像 私が考えていることを示す例の画像

ルックアップ テーブルを使用してメッシュを生成する方法

 /* 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();

私を正しい方向に向けたり、これを解決するのに役立つ何かをありがとう.

編集*私が取り組んでいること

4

0 に答える 0