unity 点位绘制面片
效果:image.png
image.png
image.png
image.png
image.png
public void CreatePlane(GameObject obj, List<Vector2> vertices2D) { Triangulator tr = new Triangulator(vertices2D); int[] indices = tr.Triangulate(); //创建顶点 Vector3[] vertices = new Vector3; Vector2[] uvs= new Vector2; for (int i = 0; i < vertices.Length; i++) { vertices = new Vector3(vertices2D.x,0, vertices2D.y); uvs = new Vector2(vertices2D.x / 1f, vertices2D.y / 1f); } // 设置游戏对象; // 创建mesh Mesh msh = new Mesh(); msh.vertices = vertices; msh.triangles = indices; msh.uv = uvs; msh.RecalculateNormals(); msh.RecalculateBounds(); obj.AddComponent<MeshRenderer>(); MeshFilter filter = obj.AddComponent<MeshFilter>(); filter.mesh = msh; obj.AddComponent<MeshCollider>(); obj.GetComponent<MeshRenderer>().material = Resources.Load("Materials/Custom_Floor") as Material; obj.GetComponent<MeshRenderer>().material.color = Color.white; }
这里没有附加对三角面得排序
页:
[1]