Example #1
0
        public static ComplexShape ToTrianglesLegacy(this PolygonShape p_polygon)
        {
            List <int>          v_trianglesIndex = p_polygon.Triangulate();
            List <PolygonShape> v_shapes         = new List <PolygonShape>();

            for (int i = 0; i < v_trianglesIndex.Count - 2; i += 3)
            {
                if (v_trianglesIndex[i] < p_polygon.Vertices.Count && v_trianglesIndex[i + 1] < p_polygon.Vertices.Count && v_trianglesIndex[i + 2] < p_polygon.Vertices.Count)
                {
                    PolygonShape v_polyShape = new PolygonShape(new List <Vector2>()
                    {
                        p_polygon.Vertices[v_trianglesIndex[i]], p_polygon.Vertices[v_trianglesIndex[i + 1]], p_polygon.Vertices[v_trianglesIndex[i + 2]]
                    });
                    v_shapes.Add(v_polyShape);
                }
            }
            return(new ComplexShape(v_shapes, false));
        }
Example #2
0
        static List <int> GetTrianglesWithDefaultOption(this PolygonShape p_polygon)
        {
            List <int> v_indexes = p_polygon.Triangulate();

            //First Index in PolygonShape is the Center. When using default tringulation this value is not used so we must add one to each index
            for (int i = 0; i < v_indexes.Count; i++)
            {
                v_indexes[i] += 1;
            }
            //Prevent Erros when indexes is not multiple of 3
            var v_extraElements = (v_indexes.Count % 3);

            if (v_extraElements != 0)
            {
                v_indexes.ClampToCount(Mathf.Max(0, v_indexes.Count - v_extraElements));
            }
            return(v_indexes);
        }