1.绘制不规则平面
using UnityEngine;
usingSystem.Collections;
public classPlaneDraw_CTRL : MonoBehaviour
{
publicGameObject planeDraw;
MeshplaneDraw_mesh;
//Use this for initialization
voidStart ()
{
planeDraw_mesh= planeDraw.GetComponent<MeshFilter> ().mesh;
Vector3[]test = new Vector3[8];
test[0] = new Vector3 (4f,0,0);
test[1] = new Vector3 (10f,0,0);
test[2] = new Vector3 (2f,0,0);
test[3] = new Vector3 (6f,0,0);
test[4] = new Vector3 (3f,1f,0);
test[5] = new Vector3 (2f,2f,0);
test[6] = new Vector3 (1f,5f,0);
test[7] = new Vector3 (1f,20f,0f);
drawPlane(test);
}
//Update is called once per frame
voidUpdate ()
{
}
publicvoid drawPlane(Vector3[] vertices)
{
intnumberOfTriangles = vertices.Length - 2;
int[]triangles = new int[numberOfTriangles*3];
intf = 0, b = vertices.Length - 1;
intm = (vertices.Length + 1) / 2;
for(inti=1; i<=numberOfTriangles; i++)
{
if(i%2==1)
{
triangles[3*i-3]= f++;
triangles[3*i-2]= f;
triangles[3*i-1]= b;
}
else
{
triangles[3*i-1]= b--;
triangles[3*i-2]= b;
triangles[3*i-3]= f;
}
}
planeDraw_mesh.vertices= vertices;
planeDraw_mesh.triangles= triangles;
}
}