支持凸多边形和凹多边形,具体算法如下,稍作修改就能用了。
Mesh CreateMesh(int mLength,Vector3[] Vertices,Mesh mymesh) {
//利用mesh类画不规则多边形
//the triangle arraylist
//
int i = 0;
int j = 0;
int numTiangle = (mLength - 2) * 3;
Vector3[] normals;
Vector2[] newUV;
int[] newTiangles;
newTiangles = new int[numTiangle];
normals = new Vector3[mLength];
newUV = new Vector2[mLength];
mymesh.vertices = Vertices;
ChangeToTriangle (newTiangles);
mymesh.triangles = newTiangles;
for(i = 0;i<mLength;i++)
{
normals[i] = Vector3.left;
}
mymesh.normals = normals;
for(i = 0;i<mLength;i++)
{
newUV[i] = new Vector2(newVertices[i].x,newVertices[i].y);
}
mymesh.uv = newUV;
mymesh.RecalculateBounds();
mymesh.RecalculateNormals();
return mymesh;
}
void ChangeToTriangle(int[] T