0

次のような 3D 地形を生成するコードに取り組んでいます。 例

頂点を共有する地形を生成するコードを以前に作成しましたが、四角形を個別にテクスチャリングしたいので、各四角形の三角形に対して 4 つの頂点と 6 つのインデックスが必要になります。

頂点とインデックスに 1 次元配列を使用していますが、頂点を正しい位置に配置し、三角形の正しいインデックスを計算するためのアルゴリズムを理解するのに苦労しています。

共有頂点を使用した古いコードを次に示します。

for (int x = 0; x < worldData.Width; x++)
            for (int y = 0; y < worldData.Height; y++)
            {
                vertices[x + (y * worldData.Width)] = new Vector3(x * TileDiameter, worldData.Elevation[x + (y * worldData.Width)] * HeightUnitValue, y * TileDiameter);
            }

    int t = 0;
    for (int x = 0; x < worldData.Width - 1; x++)
        for (int y = 0; y < worldData.Height - 1; y++)
        {
            int upperLeft = x + worldData.Width + (y * worldData.Width);
            int upperRight = x + worldData.Width + 1 + (y * worldData.Width);
            int lowerLeft = x + (y * worldData.Width);
            int lowerRight = x + 1 + (y * worldData.Width);

            triangles[t] = upperLeft;
            triangles[t + 1] = upperRight;
            triangles[t + 2] = lowerLeft;
            triangles[t + 3] = lowerLeft;
            triangles[t + 4] = upperRight;
            triangles[t + 5] = lowerRight;
            t += 6;
        }
4

0 に答える 0