美文网首页
unity 点位绘制面片

unity 点位绘制面片

作者: WOTTOW | 来源:发表于2021-03-23 17:59 被阅读0次

    效果:


    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[vertices2D.Count];
            Vector2[] uvs= new Vector2[vertices2D.Count];
    
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vector3(vertices2D[i].x,0, vertices2D[i].y);
                uvs[i] = new Vector2(vertices2D[i].x / 1f, vertices2D[i].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;
        }
    

    这里没有附加对三角面得排序

    相关文章

      网友评论

          本文标题:unity 点位绘制面片

          本文链接:https://www.haomeiwen.com/subject/rtofhltx.html