public override void ApplyPolygonList(List <DTPolygon> dtPolygonList)
        {
            if (dtPolygon == dtPolygonList[0])
            {
                return;
            }
            dtPolygon = dtPolygonList[0];

            DTProfilerMarkers.Triangulation.Begin();
            DTMesh triMesh = GetTriangulator().PolygonToMesh(dtPolygon);

            DTProfilerMarkers.Triangulation.End();

            DTConvexPolygroup triPolygroup = triMesh.ToPolygroup();

            // Collider from polygon
            DTProfilerMarkers.HertelMehlhorn.Begin();
            DTConvexPolygroup hmPolygroup = HertelMehlhorn.PolyPartitionHM.Instance.ExecuteToPolygroup(triPolygroup);

            DTProfilerMarkers.HertelMehlhorn.End();

            DTProfilerMarkers.ApplyCollider.Begin();
            ApplyCollider(hmPolygroup);
            DTProfilerMarkers.ApplyCollider.End();

            // Create mesh from triangulated polygon
            ApplyRenderMesh(triMesh);
        }
    public static DTConvexPolygroup ToPolygroup(this DTMesh mesh)
    {
        DTProfilerMarkers.MeshToPolygroup.Begin();
        DTConvexPolygroup polygroup = new DTConvexPolygroup(
            mesh.Partitions.Select(part => part.Select(i => mesh.Vertices[i]).ToList()).ToList());

        DTProfilerMarkers.MeshToPolygroup.End();
        return(polygroup);
    }
Пример #3
0
        protected void ApplyCollider(DTConvexPolygroup polygroup)
        {
            PolygonCollider2D polygonCollider = GetComponent <PolygonCollider2D>();

            polygonCollider.pathCount = polygroup.Count;
            for (int i = 0; i < polygroup.Count; i++)
            {
                polygonCollider.SetPath(i, polygroup[i]);
            }

            if (GetComponent <Rigidbody2D>().mass < MassCutoff)
            {
                Destroy(gameObject);
            }
        }
        public override void ApplyPolygonList(List <DTPolygon> clippedPolygonList)
        {
            // The clipped polygons could potentially be concave or have holes, so we will triangulate each one before applying
            DTProfilerMarkers.Triangulation.Begin();
            dtPolygroup = DTUtility.TriangulateAll(clippedPolygonList, GetTriangulator());
            DTProfilerMarkers.Triangulation.End();

            // Collider from polygon
            DTProfilerMarkers.ApplyCollider.Begin();
            ApplyCollider(dtPolygroup);
            DTProfilerMarkers.ApplyCollider.End();

            // Create mesh from triangulated polygon
            ApplyRenderMesh(dtPolygroup.ToMesh());
        }
Пример #5
0
        public override void ApplyPolygonList(List <DTPolygon> clippedPolygonList)
        {
            // The clipped polygons could potentially be concave or have holes, so we will triangulate each one before applying
            DTProfilerMarkers.Triangulation.Begin();
            DTConvexPolygroup triangulatedPolygroup = DTUtility.TriangulateAll(clippedPolygonList, GetTriangulator());

            DTProfilerMarkers.Triangulation.End();

            // Collider from polygon
            DTProfilerMarkers.HertelMehlhorn.Begin();
            hmPolygroup = HertelMehlhorn.PolyPartitionHM.Instance.ExecuteToPolygroup(triangulatedPolygroup);
            DTProfilerMarkers.HertelMehlhorn.End();

            // Collider from polygon
            DTProfilerMarkers.ApplyCollider.Begin();
            ApplyCollider(hmPolygroup);
            DTProfilerMarkers.ApplyCollider.End();

            // Create mesh from triangulated polygon
            ApplyRenderMesh(triangulatedPolygroup.ToMesh());
        }
    public static DTMesh ToMesh(this DTConvexPolygroup polygroup)
    {
        DTProfilerMarkers.PolygroupToMesh.Begin();

        // List of unique vertices for the mesh
        List <Vector2> vertices = new List <Vector2>();

        // Maps each vertex to its index in the vertices list
        Dictionary <Vector2, int> vertexMap = new Dictionary <Vector2, int>(new ApproximateVector2Comparer());

        // List of partitions, each of which is a list of vertex indices
        List <List <int> > partitions = new List <List <int> >(polygroup.Count);

        foreach (var poly in polygroup)
        {
            // Indices of the vertices in this partition
            List <int> indices = new List <int>();
            foreach (var v in poly)
            {
                // Get the mapped index of the vertex. If the vertex is not yet mapped, map it to the index at the end
                // of the vertices list
                if (!vertexMap.TryGetValue(v, out int index))
                {
                    index = vertices.Count;
                    vertexMap.Add(v, index);
                    vertices.Add(v);
                }
                indices.Add(index);
            }
            partitions.Add(indices);
        }

        DTMesh mesh = new DTMesh(vertices, partitions);

        DTProfilerMarkers.PolygroupToMesh.End();
        return(mesh);
    }
        public override void ApplyPolygonList(List <DTPolygon> clippedPolygonList)
        {
            // The clipped polygons could potentially be concave or have holes, so we will triangulate each one before applying
            DTProfilerMarkers.Triangulation.Begin();
            DTConvexPolygroup triangleList = DTUtility.TriangulateAll(clippedPolygonList, GetTriangulator());

            DTProfilerMarkers.Triangulation.End();

            // Our Hertel-Mehlhorn implementation takes a DTMesh, so convert before instead of after
            DTMesh triangulatedMesh = triangleList.ToMesh();

            // Collider from polygon
            DTProfilerMarkers.HertelMehlhorn.Begin();
            hmMesh = HertelMehlhorn.CustomHM.Instance.ExecuteToMesh(triangulatedMesh);
            DTProfilerMarkers.HertelMehlhorn.End();

            // Collider from polygon
            DTProfilerMarkers.ApplyCollider.Begin();
            ApplyCollider(hmMesh);
            DTProfilerMarkers.ApplyCollider.End();

            // Create mesh from triangulated polygon
            ApplyRenderMesh(triangulatedMesh);
        }
Пример #8
0
 public DTConvexPolygroup ExecuteToPolygroup(DTConvexPolygroup input)
 {
     HertelMehlhorn(input.ToTPPLPolyList(), out TPPLPolyList output);
     return(output.ToPolygroup());
 }
Пример #9
0
 public DTMesh ExecuteToMesh(DTConvexPolygroup input)
 {
     return(ExecuteToPolygroup(input).ToMesh());
 }
Пример #10
0
        public override void ApplyPolygonList(List <DTPolygon> clippedPolygonList)
        {
            DTConvexPolygroup triangles = DTUtility.TriangulateAll(clippedPolygonList, GetTriangulator());

            ApplyPolygroupModifier(new PolygroupModifier(null, null, triangles));
        }