我創建了一個使用C#的飛機,我得到它「工作」我得到一架飛機。但是三角形似乎沒有正確連接,我無法弄清楚爲什麼。創建一個統一的飛機,三角形看起來不正確
正如你可以通過圖片看到,它比我能解釋它更好。
我相信這個問題只是與我的指數,但我不知道。
我想也可能有一個三角形不在那裏,所以我認爲我的數組也因爲某些原因而變小。
Mesh CreatePlane(int width, int depth)
{
Mesh m = new Mesh();
int numVert=(width+1)*(depth+1);
Vector3[] vertecies = new Vector3[numVert];
Vector2[] uvs = new Vector2[numVert];
int[] triangles = new int[width*depth*6];
float uvx = 1.0f/width;
float uvy = 1.0f/depth;
int index = 0;
for (int i = 0;i<width;i++)
{
for(int j = 0;j<depth;j++)
{
vertecies[index] = new Vector3(i,0,-j);
uvs[index++] = new Vector2(j*uvx,i*uvy);
}
}
index = 0;
for(int j=0; j<depth; j++)
{
for(int i=0; i<width; i++)
{
triangles[index++] = (j * (width+1)) + i;
triangles[index++] = ((j+1) * (width+1)) + i;
triangles[index++] = (j * (width+1)) + i + 1;
triangles[index++] = ((j+1) * (width+1)) + i;
triangles[index++] = ((j+1) * (width+1)) + i + 1;
triangles[index++] = (j * (width+1)) + i + 1;
}
}
m.name = "ScriptPlane";
m.vertices = vertecies;
m.uv = uvs;
m.triangles = triangles;
m.RecalculateNormals();
return m;
}
請不要包含關於問題標題中使用的語言的信息,除非在沒有它的情況下沒有意義。標籤用於此目的。 –