Unity3d学习10

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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值