Ejemplo n.º 1
0
        public static GameObject CreateMeshStrip(List <Vector3> vertices, Transform transform, bool debugMode = false)
        {
            MeshTool.MeshObject meshObject = MeshTool.InitTransformForMesh(transform);
            List <Vector2>      list       = new List <Vector2>();

            for (int i = 0; i < vertices.Count; i++)
            {
                list.Add(new Vector2(vertices[i].x, vertices[i].y));
            }
            List <int> list2 = new List <int>();

            for (int j = 0; j < vertices.Count - 2; j++)
            {
                list2.Add(j);
                if (j % 2 == 0)
                {
                    list2.Add(j + 2);
                    list2.Add(j + 1);
                }
                else
                {
                    list2.Add(j + 1);
                    list2.Add(j + 2);
                }
            }
            if (!debugMode)
            {
                Mesh mesh = new Mesh();
                mesh.name      = transform.name;
                mesh.vertices  = vertices.ToArray();
                mesh.uv        = list.ToArray();
                mesh.triangles = list2.ToArray();
                mesh.RecalculateNormals();
                meshObject.mf.sharedMesh = mesh;
            }
            return(meshObject.parent);
        }
Ejemplo n.º 2
0
        public static GameObject CreateMeshFromPolygon(List <Vector3> vertices, Transform transform, MentalMath.AxisSpace space, bool debugMode = false)
        {
            MeshTool.MeshObject meshObject = MeshTool.InitTransformForMesh(transform);
            if (debugMode)
            {
                for (int i = 0; i < vertices.Count; i++)
                {
                }
            }
            List <Vector2> list = new List <Vector2>();

            for (int j = 0; j < vertices.Count; j++)
            {
                list.Add(new Vector2(vertices[j].x, vertices[j].y));
            }
            List <int> list2 = new List <int>();

            bool[] array = new bool[vertices.Count];
            for (int k = 0; k < array.Length; k++)
            {
                array[k] = true;
            }
            int num  = 0;
            int num2 = 1;
            int num3 = 2;
            int l    = vertices.Count;
            int num4 = l * 10;

            while (l > 0)
            {
                num4--;
                if (num4 < 0)
                {
                    break;
                }
                bool flag = true;
                for (int m = 0; m < vertices.Count; m++)
                {
                    if (num != m && num2 != m && num3 != m)
                    {
                        if (MentalMath.PointInTriangle(vertices[m], vertices[num], vertices[num2], vertices[num3], MentalMath.AxisSpace.XY))
                        {
                            flag = false;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    Vector3 a       = vertices[num2] - vertices[num];
                    Vector3 tangent = a + (vertices[num3] - vertices[num2]);
                    Vector3 counterClockwiseNormal = MentalMath.GetCounterClockwiseNormal(tangent, space);
                    float   num5 = Vector3.Angle(-a, counterClockwiseNormal);
                    flag = (num5 > 90f);
                }
                if (!flag)
                {
                    num  = num2;
                    num2 = num3;
                }
                else
                {
                    if (debugMode)
                    {
                        Vector3 vector = transform.position + Vector3.up * 3f;
                    }
                    list2.Add(num);
                    list2.Add(num2);
                    list2.Add(num3);
                    l--;
                    if (l <= 2)
                    {
                        if (debugMode)
                        {
                        }
                        break;
                    }
                    array[num2] = false;
                    num2        = num3;
                }
                int num6 = num2;
                int num7 = vertices.Count;
                while (num2 == num3)
                {
                    num7--;
                    if (num7 < 0)
                    {
                        break;
                    }
                    num6++;
                    if (num6 >= vertices.Count)
                    {
                        num6 = 0;
                    }
                    if (array[num6] && num != num6 && num2 != num6)
                    {
                        if (debugMode)
                        {
                        }
                        num3 = num6;
                        break;
                    }
                }
            }
            if (!debugMode)
            {
                Mesh mesh = new Mesh();
                mesh.name      = transform.name;
                mesh.vertices  = vertices.ToArray();
                mesh.uv        = list.ToArray();
                mesh.triangles = list2.ToArray();
                mesh.RecalculateNormals();
                meshObject.mf.sharedMesh = mesh;
            }
            return(meshObject.parent);
        }