1.任何物体都是由mesh构成
2.mesh是由若干个三角形组成
3.三角形三个顶点组成顺时针为正面,逆时针为背面
4.添加材质。每个mesh的材质有4个面,0-1分别对应材质球的四个顶点。
MeshFilter mesh_filter = gameObject.AddComponent<MeshFilter>();
MeshRenderer mesh_renderer = gameObject.AddComponent<MeshRenderer>();
Mesh mesh = mesh_filter.mesh;
mesh.Clear();
//设置顶点
mesh.vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0),new Vector3(1, 0, 0) };
//设置三角形顶点顺序,顺时针设置
mesh.triangles = new int[] { 0,1,2, 2,3,0 };
添加材质:
public Material mat;
Vector2[] uvs = new Vector2[]{new Vector2(0,0),new Vector2(0,1),new Vector2(1,1),new Vector2(1,0)};
mesh.uv = uvs;
mesh_renderer.material = mat;
网友评论