U3D中 一个GameObject被new出来就在场景中了 他有一些东西 MeshFilter MeshRenderer
filter是mesh的attribute部分 renderer是材质的部分
GameObject m_cube=new GameObject ();
m_cube.AddComponent<MeshFilter> ();
m_cube.AddComponent<MeshRenderer> ();
这样就初始一个 然后创建vertices normals uvs indeices这个就是triangles
Vector3[] vertices = {
new Vector3(-1,-1,0),
new Vector3(1,-1,0),
new Vector3(0,0.5f,0)};
Vector2[] uvs = {
new Vector2(-1,0),
new Vector2(1,0),
new Vector2(0,1)};
int[] triangles = {1,0,2 };
然后赋值给mesh就创建好了
Mesh mesh = new Mesh ();
m_cube.GetComponent<MeshFilter>().mesh = mesh;
mesh.vertices = vertices;
mesh.uv = uvs;
mesh.triangles = triangles;
//m_cube.GetComponent<MeshRenderer> ().material = new Material ();