Exemplo n.º 1
0
        public static CutResult Cut(Vector2 lineStart, Vector2 lineEnd, Collider2D[] colliders)
        {
            CutResult result = new CutResult();

            result.firstSideColliderRepresentations  = new List <PolygonColliderParametersRepresentation>();
            result.secondSideColliderRepresentations = new List <PolygonColliderParametersRepresentation>();

            foreach (Collider2D collider in colliders)
            {
                List <Vector2[]> paths = ColliderPathsCreator.GetPolygonColliderPathsFrom(collider);
                foreach (Vector2[] path in paths)
                {
                    ShapeCutter.CutResult cutResult = ShapeCutter.CutShapeIntoTwo(lineStart, lineEnd, path);

                    if (cutResult.firstSidePoints.Length > 0)
                    {
                        PolygonColliderParametersRepresentation repr = new PolygonColliderParametersRepresentation();
                        repr.CopyParametersFrom(collider);
                        repr.paths.Add(cutResult.firstSidePoints);
                        result.firstSideColliderRepresentations.Add(repr);
                    }
                    if (cutResult.secondSidePoints.Length > 0)
                    {
                        PolygonColliderParametersRepresentation repr = new PolygonColliderParametersRepresentation();
                        repr.CopyParametersFrom(collider);
                        repr.paths.Add(cutResult.secondSidePoints);
                        result.secondSideColliderRepresentations.Add(repr);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public static CutResult Cut(Vector2 lineStart, Vector2 lineEnd, Mesh mesh)
        {
            CutResult result = new CutResult();

            Vector2[]             shape          = ConvertVerticesToShape(mesh.vertices);
            ShapeCutter.CutResult shapeCutResult = ShapeCutter.CutShapeIntoTwo(lineStart, lineEnd, shape);
            if (shapeCutResult.firstSidePoints.Length < 3 ||
                shapeCutResult.secondSidePoints.Length < 3)
            {
                return(result);
            }

            result.firstSideMesh  = GenerateHalfMeshFrom(mesh, shapeCutResult.firstSidePoints);
            result.secondSideMesh = GenerateHalfMeshFrom(mesh, shapeCutResult.secondSidePoints);

            return(result);
        }