正方体:
一共有8个顶点,6个面。
其中背面和侧面,需要想象把物体转到自己的正面来。
举例:(正面看的话,4,7,6为逆时针,)
4,7,6,
5,4,6, //后

MeshFilter mesh_filter = gameObject.AddComponent<MeshFilter>();
MeshRenderer mesh_renderer = gameObject.AddComponent<MeshRenderer>();
// gameObject.GetComponent<MeshRenderer>().material
Mesh mesh = mesh_filter.mesh;
mesh.Clear();
//设置顶点
Vector3[] vertices = new Vector3[]
{ new Vector3(0, 0, 0),
new Vector3(1, 0, 0),
new Vector3(1, 1, 0),
new Vector3(0, 1, 0),
new Vector3(0, 1, 1),
new Vector3(1, 1, 1),
new Vector3(1, 0, 1),
new Vector3(0, 0, 1),
};
int[] triangles = new int[]
{
0,2,1,
0,3,2, //前
3,4,2,
4,5,2, //上
4,7,6,
5,4,6, //后
0,1,7,
1,6,7, //底
4,3,0,
4,0,7, //左
2,5,6,
2,6,1 //右
};
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
网友评论