当前位置: 首页>>代码示例>>C#>>正文


C# Clipper.AddPath方法代码示例

本文整理汇总了C#中ClipperLib.Clipper.AddPath方法的典型用法代码示例。如果您正苦于以下问题:C# Clipper.AddPath方法的具体用法?C# Clipper.AddPath怎么用?C# Clipper.AddPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClipperLib.Clipper的用法示例。


在下文中一共展示了Clipper.AddPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MeshDifference

    public static Vector3[] MeshDifference(Vector3[] mesh1, Vector3[] mesh2)
    {
        List<IntPoint> subj = MeshToPath3D(mesh1);
        List<IntPoint> clip = MeshToPath3D(mesh2);
        List<List<IntPoint>> solution = new List<List<IntPoint>>();

        Clipper c = new Clipper();
        c.AddPath(subj, PolyType.ptSubject, true);
        c.AddPath(clip, PolyType.ptClip, true);
        c.Execute(ClipType.ctDifference, solution,
          PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);

        return PathToMesh3D(solution[0]);
    }
开发者ID:knappus,项目名称:madchen_prototype,代码行数:14,代码来源:ClipperInterface.cs

示例2: Clip

        public void Clip(double x0, double x1, double y0, double y1)
        {
            var p00 = new Point3d(x0, y0, 0.0);
            var p01 = new Point3d(x0, y1, 0.0);
            var p11 = new Point3d(x1, y1, 0.0);
            var p10 = new Point3d(x1, y0, 0.0);

            var clip = new[] { p00, p10, p11, p01, p00 }.ToPolygon(Plane.WorldXY, Unit);

            var clipper = new Clipper();

            clipper.AddPaths(Polygons, PolyType.ptSubject, true);
            clipper.AddPath(clip, PolyType.ptClip, true);

            var solution = new List<List<IntPoint>>();

            clipper.Execute(ClipType.ctIntersection, solution, PolyFillType.pftEvenOdd, PolyFillType.pftNonZero);

            Polygons = solution;
            Curves = Polygons.ToCurves(Plane, Unit);
        }
开发者ID:olitur,项目名称:Bowerbird,代码行数:21,代码来源:SlitPlane.cs

示例3: Remove_Overlap_In_XY_Plane

        private static List<List<Point>> Remove_Overlap_In_XY_Plane(List<Point> points1, List<List<Point>> otherPolygonsPoints)
        {
            var clipper = new Clipper();
            
            clipper.StrictlySimple = true; //we only handle so-called simple polygons, this helps ensure that the only results clipper returns are simple polygons
            
            clipper.AddPath(ToClipperPath(points1), PolyType.ptSubject, true);
            foreach (var pointList in otherPolygonsPoints)
            { 
                clipper.AddPath(ToClipperPath(pointList), PolyType.ptClip, true);
            }

            var soln = new Paths();
            // clipper offers 4 operations: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/ClipType.htm
            var success = clipper.Execute(ClipType.ctDifference, soln);
            
            var resultantPolygonPoints = new List<List<Point>>();
            if (success.Not())
            {
                return null;
            }
            foreach (var pointList in soln)
            {
                resultantPolygonPoints.Add(ToPoints(pointList));
            }
            return resultantPolygonPoints;
        }
开发者ID:ParagonTruss,项目名称:GeometryClassLibrary,代码行数:27,代码来源:ClipperPort.cs

示例4: GetIntersectionPolygon

        /// <summary>
        /// Applies a buoyant force, drag and lift to an object submerged in the water.
        /// </summary>
        /// <param name="subjectPoly"> The polygon of the object in the water.</param>
        /// <param name="minIndex"> The min index for a value in the "waterLinePoints" list. </param>
        /// <param name="maxIndex"> The max index for a value in the "waterLinePoints" list. </param>
        /// <param name="isIntersecting"> Are the subject and clipping polygon intersecting?. </param>
        private List<List<Vector2>> GetIntersectionPolygon(Vector2[] subjectPoly, int minIndex, int maxIndex, out bool isIntersecting)
        {
            Vector2 bottomHandleGlobalPos = transform.TransformPoint(water2D.handlesPosition[1]);
            List<List<Vector2>> intersectionPoly = new List<List<Vector2>>();
            List<Vector2> clipPolygon = new List<Vector2>();
            Clipper clipper = new Clipper();
            Paths solutionPath = new Paths();
            Path subjPath = new Path();
            Path clipPath = new Path();
            int len, len2, min, max;
            isIntersecting = true;

            if (surfaceVertsCount > meshSegmentsPerWaterLineSegment)
            {
                min = (int)Mathf.Floor(minIndex / meshSegmentsPerWaterLineSegment);
                max = (int)Mathf.Floor(maxIndex / meshSegmentsPerWaterLineSegment) + 1;

                if (max > waterLinePoints.Count - 2)
                    max = waterLinePoints.Count - 2;

                for (int i = min; i <= max; i++)
                {
                    clipPolygon.Add(waterLinePoints[i]);
                }

                int last = clipPolygon.Count - 1;
                clipPolygon.Add(new Vector2(clipPolygon[last].x, bottomHandleGlobalPos.y));
                clipPolygon.Add(new Vector2(clipPolygon[0].x, bottomHandleGlobalPos.y));
            }
            else
            {
                Vector2 vertGlobalPos = transform.TransformPoint(vertices[surfaceVertsCount]);
                clipPolygon.Add(vertGlobalPos);
                vertGlobalPos = transform.TransformPoint(vertices[surfaceVertsCount + surfaceVertsCount - 1]);
                clipPolygon.Add(new Vector2(vertGlobalPos.x, vertGlobalPos.y));

                int last = clipPolygon.Count - 1;
                clipPolygon.Add(new Vector2(clipPolygon[last].x, bottomHandleGlobalPos.y));
                clipPolygon.Add(new Vector2(clipPolygon[0].x, bottomHandleGlobalPos.y));
            }

            if (showClippingPlolygon)
            {
                for (int i = 0; i < clipPolygon.Count; i++)
                {
                    if (i < clipPolygon.Count - 1)
                        Debug.DrawLine(clipPolygon[i], clipPolygon[i + 1], Color.green);
                    else
                        Debug.DrawLine(clipPolygon[i], clipPolygon[0], Color.green);
                }
            }

            len = subjectPoly.Length;
            for (int i = 0; i < len; i++)
            {
                subjPath.Add(new IntPoint(subjectPoly[i].x * scaleFactor, subjectPoly[i].y * scaleFactor));
            }

            len = clipPolygon.Count;
            for (int i = 0; i < len; i++)
            {
                clipPath.Add(new IntPoint(clipPolygon[i].x * scaleFactor, clipPolygon[i].y * scaleFactor));
            }

            clipper.AddPath(subjPath, PolyType.ptSubject, true);
            clipper.AddPath(clipPath, PolyType.ptClip, true);
            clipper.Execute(ClipType.ctIntersection, solutionPath, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);

            if (solutionPath.Count != 0)
            {
                len = solutionPath.Count;

                for (int i = 0; i < len; i++)
                {
                    len2 = solutionPath[i].Count;
                    List<Vector2> list = new List<Vector2>();

                    for (int j = 0; j < len2; j++)
                    {
                        list.Add(new Vector2(solutionPath[i][j].X / scaleFactor, solutionPath[i][j].Y / scaleFactor));
                    }

                    intersectionPoly.Add(list);
                }
                return intersectionPoly;
            }
            else
            {
                isIntersecting = false;
                return null;
            }
        }
开发者ID:Bakiet,项目名称:UnityZombieCross,代码行数:99,代码来源:Water2D_Simulation.cs

示例5: SimplifyPolygon

      //------------------------------------------------------------------------------
#endif

    //------------------------------------------------------------------------------
      // SimplifyPolygon functions ...
      // Convert self-intersecting polygons into simple polygons
      //------------------------------------------------------------------------------

      public static Paths SimplifyPolygon(Path poly, 
            PolyFillType fillType = PolyFillType.pftEvenOdd)
      {
          Paths result = new Paths();
          Clipper c = new Clipper();
          c.StrictlySimple = true;
          c.AddPath(poly, PolyType.ptSubject, true);
          c.Execute(ClipType.ctUnion, result, fillType, fillType);
          return result;
      }
开发者ID:CharlesTaylor95,项目名称:clipper,代码行数:18,代码来源:clipper.cs

示例6: ClipPolygon

 public static List<List<IntPoint>> ClipPolygon(List<List<IntPoint>> polygons, List<IntPoint> clipPath)
 {
     Clipper clipper = new Clipper();
     clipper.AddPaths(polygons, PolyType.ptSubject, true);
     clipper.AddPath(clipPath, PolyType.ptClip, true);            
     List<List<IntPoint>> solution = new List<List<IntPoint>>();
     clipper.Execute(ClipType.ctIntersection, solution);
     return solution;
 } 
开发者ID:GordeyChernyy,项目名称:CommuteRitual,代码行数:9,代码来源:SVGGeom.cs

示例7: Generate

    public void Generate()
    {
        generationMessage = "Generating points...";

        //Generate some points...
        List<Point> generationPoints = new List<Point>();

        for(int i = 0; i < numberOfPoints; i++) {
            Point randomPoint = new Point(Random.Range(-levelRadius, levelRadius), Random.Range(-levelRadius, levelRadius));
            randomPoint = new Point( (randomPoint.x * delaunayPointSnap) / delaunayPointSnap, (randomPoint.y * delaunayPointSnap) / delaunayPointSnap);
            if(!generationPoints.Contains(randomPoint)) {
                generationPoints.Add(randomPoint);
            }
        }

        //Clean up duplicates

        generationMessage = "Triangulating...";
        //Generate a delaunay triangulation of the points
        Poly2Tri.PointSet ps = new Poly2Tri.PointSet(generationPoints.Select(d=>(Poly2Tri.TriangulationPoint)d).ToList());
        Poly2Tri.P2T.Triangulate (ps);
        List<Poly2Tri.DelaunayTriangle> delaunayTriangles = ps.Triangles.ToList();

        generationMessage = "Performing Brownian Walk through triangulation...";
        //Brownian Walk through the triangles.
        Poly2TriDelaunayTriangulationWalker walker = new Poly2TriDelaunayTriangulationWalker (delaunayTriangles);
        List<Poly2Tri.DelaunayTriangle> levelTriangleSet = new List<Poly2Tri.DelaunayTriangle>();

        for (int i = 0; i < numberOfStepsForBrownianWalk; i++) {
            Poly2Tri.DelaunayTriangle nextTriangle = walker.Next();
            if(!levelTriangleSet.Contains(nextTriangle)) {
                levelTriangleSet.Add(nextTriangle);
            }
        }

        generationMessage = "Performing Tendril Walks...";
        for (int i = 0; i < numberOfTendrilWalksToComplete; i++) {
            generationMessage = "Performing Tendril Walk: " + i;
            walker.SetCurrentTriangleIndex(delaunayTriangles.IndexOf(levelTriangleSet[Mathf.FloorToInt(Random.value * levelTriangleSet.Count)]));
            for (int j = 0; j < numberOfStepsForBrownianWalk; j++) {
                Poly2Tri.DelaunayTriangle nextTriangle = walker.Next();
                if(!levelTriangleSet.Contains(nextTriangle)) {
                    levelTriangleSet.Add(nextTriangle);
                }
            }
        }

        generationMessage = "Getting level boolean...";
        //List<Poly2Tri.DelaunayTriangle> booleanFromLevelSet = delaunayTriangles.Where (x => !levelTriangleSet.Contains (x)).ToList ();

        /* Debugging delaunay triangulation
        foreach (Poly2Tri.DelaunayTriangle tri in booleanFromLevelSet) {
            Gizmos.DrawLine(new Vector2(tri.Points[0].Xf, tri.Points[0].Yf), new Vector2(tri.Points[1].Xf, tri.Points[1].Yf));
            Gizmos.DrawLine(new Vector2(tri.Points[1].Xf, tri.Points[1].Yf), new Vector2(tri.Points[2].Xf, tri.Points[2].Yf));
            Gizmos.DrawLine(new Vector2(tri.Points[2].Xf, tri.Points[2].Yf), new Vector2(tri.Points[0].Xf, tri.Points[0].Yf));
        }
        */

        //Generate colliders...
        ClipperLib.Clipper clipper = new ClipperLib.Clipper ();
        foreach(Poly2Tri.DelaunayTriangle tri in levelTriangleSet) {
            Polygon trianglePoints = new Polygon();
            for(int i = 0; i < 3; i++) {
                trianglePoints.points.Add(tri.Points[i]);
            }
            clipper.AddPath(trianglePoints, ClipperLib.PolyType.ptSubject, true);

        }

        List<List<ClipperLib.IntPoint>> solution = new List<List<ClipperLib.IntPoint>> ();
        clipper.Execute (ClipperLib.ClipType.ctUnion, solution, ClipperLib.PolyFillType.pftPositive, ClipperLib.PolyFillType.pftPositive);

        generationMessage = "Generating mesh from boolean...";
        DestructibleLevel level = GetComponent<DestructibleLevel> ();
        if (level == null) {
            level = gameObject.AddComponent<DestructibleLevel>();
        }

        foreach (List<ClipperLib.IntPoint> polygon in solution) {
            level.booleanPolygons.Add(new Tinkerbox.Geometry.Polygon(polygon));
        }

        level.UpdateMesh();

        generationMessage = "Calling Callback..";
        OnFinishedGeneration();
        GameObject[] players = GameObject.FindGameObjectsWithTag ("Player");
        Poly2Tri.DelaunayTriangle spawnTriangle = levelTriangleSet [Mathf.FloorToInt (Random.value * levelTriangleSet.Count)];

        generationMessage = "Spawning Players...";
        Vector2 spawnPoint = new Vector2 (spawnTriangle.Centroid ().Xf, spawnTriangle.Centroid ().Yf);

        foreach (GameObject player in players) {
            player.transform.position = spawnPoint + Random.insideUnitCircle;

        }

        generationMessage = "Spawning Decorations...";
        for (int i = 0; i < decorationsToSpawn; i++) {
            GameObject decoration = (GameObject) Instantiate(decorations[Mathf.FloorToInt(Random.value * decorations.Length)]);
//.........这里部分代码省略.........
开发者ID:JakeCataford,项目名称:unity-tinkerbox,代码行数:101,代码来源:DelaunayLevelGenerator.cs

示例8: Punch

 private PolyTree Punch(PolyTree input, PolyTree hole)
 {
     var subtractClipper = new Clipper(Clipper.ioStrictlySimple);
      for (var it = input.GetFirst(); it != null; it = it.GetNext()) {
     subtractClipper.AddPath(it.Contour, PolyType.ptSubject, true);
      }
      for (var it = hole.GetFirst(); it != null; it = it.GetNext()) {
     subtractClipper.AddPath(it.Contour, PolyType.ptClip, true);
      }
      var result = new PolyTree();
      subtractClipper.Execute(ClipType.ctDifference, result, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
      return result;
 }
开发者ID:ItzWarty,项目名称:AdventuresInShade,代码行数:13,代码来源:Triangulator.cs

示例9: Union

 private PolyTree Union(PolyTree a, PolyTree b)
 {
     var landUnionClipper = new Clipper(Clipper.ioStrictlySimple);
      var s = new Stack<PolyNode>();
      s.Push(a);
      s.Push(b);
      while (s.Any()) {
     var node = s.Pop();
     if (!node.IsHole) {
        landUnionClipper.AddPath(node.Contour, PolyType.ptSubject, true);
     }
     node.Childs.ForEach(s.Push);
      }
      PolyTree landUnionPolyTree = new PolyTree();
      landUnionClipper.Execute(ClipType.ctUnion, landUnionPolyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
      return landUnionPolyTree;
 }
开发者ID:ItzWarty,项目名称:AdventuresInShade,代码行数:17,代码来源:Triangulator.cs

示例10: GetClippedFixtures

        /// <summary>
        /// Returns a list of fixtures and their shapes with regions inside portals clipped away.  
        /// This excludes portal fixtures and the shapes are in world coordinates.
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        private static List<Tuple<Fixture, Vector2[]>> GetClippedFixtures(Body body)
        {
            BodyData data = GetData(body);

            /* If this body isn't colliding with any portals then we just return a list of
             * fixtures and vertices.*/
            if (data.PortalCollisions().Count <= 0)
            {
                List<Tuple<Fixture, Vector2[]>> fixtures = new List<Tuple<Fixture, Vector2[]>>();
                foreach (Fixture f in body.FixtureList)
                {
                    fixtures.Add(new Tuple<Fixture, Vector2[]>(f, FixtureExt.GetWorldPoints(f)));
                }
                return fixtures;
            }

            Vector2 center = GetLocalOrigin(body);

            List<List<IntPoint>> clipPaths = new List<List<IntPoint>>();
            foreach (IPortal p in data.PortalCollisions())
            {
                Vector2[] verts = Portal.GetWorldVerts(p);
                float scale = 100;

                Vector2 v0 = verts[0] + (verts[1] - verts[0]).Normalized() * scale;
                Vector2 v1 = verts[1] - (verts[1] - verts[0]).Normalized() * scale;
                Vector2 depth = (verts[1] - verts[0]).PerpendicularLeft.Normalized() * scale;
                if (new LineF(v0, v1).GetSideOf(v1 + depth) == new LineF(v0, v1).GetSideOf(center))
                {
                    depth *= -1;
                }

                Vector2[] box = new Vector2[]
                {
                    v0, v1, v1 + depth, v0 + depth
                };
                box = MathExt.SetWinding(box, true);

                clipPaths.Add(ClipperConvert.ToIntPoint(box));
            }

            List<Tuple<Fixture, Vector2[]>> clippedFixtures = new List<Tuple<Fixture, Vector2[]>>();

            Clipper clipper = new Clipper();
            foreach (Fixture f in body.FixtureList)
            {
                if (!FixtureExt.GetData(f).IsPortalParentless())
                {
                    continue;
                }

                clipper.Clear();
                clipper.AddPaths(clipPaths, PolyType.ptClip, true);

                clipper.AddPath(
                    ClipperConvert.ToIntPoint(FixtureExt.GetWorldPoints(f)),
                    PolyType.ptSubject,
                    true);

                List<List<IntPoint>> result = new List<List<IntPoint>>();
                clipper.Execute(ClipType.ctDifference, result, PolyFillType.pftEvenOdd, PolyFillType.pftNonZero);
                Debug.Assert(
                    result.Count <= 1,
                    "This fixture is too large for the portal masking or something has gone wrong with the clipper.");

                if (result.Count > 0)
                {
                    clippedFixtures.Add(new Tuple<Fixture, Vector2[]>(f, ClipperConvert.ToVector2(result[0])));
                }
            }

            Debug.Assert(clippedFixtures.Count > 0);
            return clippedFixtures;
        }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:80,代码来源:BodyExt.cs

示例11: UnionPolygonsToTree

        public PolyTree UnionPolygonsToTree(IReadOnlyList<IReadOnlyList<TriangulationPoint>> polygons)
        {
            if (polygons == null) return null;

             var clipper = new Clipper(Clipper.ioStrictlySimple);
             foreach (var polygon in polygons) {
            clipper.AddPath(polygon.MapList(UpscalePoint), PolyType.ptSubject, true);
             }
             PolyTree polyTree = new PolyTree();
             clipper.Execute(ClipType.ctUnion, polyTree, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
            //         Console.WriteLine(polygons.Count + " vs " + polyTree.Total + " " + polyTree.Childs.Count);
             return polyTree;
        }
开发者ID:ItzWarty,项目名称:AdventuresInShade,代码行数:13,代码来源:Triangulator.cs

示例12: PrepairPolyTree

        private PolyTreeEdgesRetained PrepairPolyTree(Collider2D[] floorColliders, Collider2D[] wallColliders)
        {
            if(floorColliders.Length == 0)
            {
                throw new System.Exception("No colliders in the scene on the floor layer.");
            }

            PolyTreeEdgesRetained TreeAndEdges = new PolyTreeEdgesRetained();

            TreeAndEdges.Edges = new List<List<IntPoint>>();
            TreeAndEdges.Tree = new PolyTree();

            Clipper finalClipper = new Clipper();

            if (floorColliders.Length > 0)
            {
                Clipper tempC = new Clipper();
                ClipperOffset tempCo = new ClipperOffset();

                foreach (Collider2D d in floorColliders)
                {
                    List<IntPoint> p = PolygonFromCollider2D(d, false);
                    if (p != null && p.Count != 0)
                    {
                        if (ClipperLib.Clipper.Orientation(p))
                            p.Reverse();

                        tempC.AddPath(p, PolyType.ptSubject, true);
                    }
                }

                List<List<IntPoint>> solution = new List<List<IntPoint>>();
                tempC.Execute(ClipType.ctUnion, solution, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
                tempC.Clear();

                foreach (List<IntPoint> intPoints in solution)
                {
                    tempCo.AddPath(intPoints, (JoinType)GenerationInformation.JoinType, EndType.etClosedPolygon);
                    TreeAndEdges.Edges.Add(intPoints);
                }
                solution.Clear();
                tempCo.Execute(ref solution, -GenerationInformation.ColliderPadding * GenerationInformation.CalculationScaleFactor);
                finalClipper.AddPaths(solution, PolyType.ptSubject, true);
            }

            if(wallColliders.Length > 0)
            {
                Clipper tempC = new Clipper();
                ClipperOffset tempCo = new ClipperOffset();

                foreach (Collider2D d in wallColliders)
                {
                    List<IntPoint> p = PolygonFromCollider2D(d, false);
                    if (p != null && p.Count != 0)
                    {
                        if (ClipperLib.Clipper.Orientation(p))
                            p.Reverse();

                        tempC.AddPath(p, PolyType.ptSubject, true);
                    }
                }

                List<List<IntPoint>> solution = new List<List<IntPoint>>();
                tempC.Execute(ClipType.ctUnion, solution, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
                tempC.Clear();

                foreach (List<IntPoint> intPoints in solution)
                {
                    tempCo.AddPath(intPoints, (JoinType)GenerationInformation.JoinType, EndType.etClosedPolygon);
                    TreeAndEdges.Edges.Add(intPoints);
                }
                solution.Clear();

                tempCo.Execute(ref solution, GenerationInformation.ColliderPadding * GenerationInformation.CalculationScaleFactor);
                finalClipper.AddPaths(solution, PolyType.ptClip, true);
            }

            finalClipper.Execute(ClipType.ctDifference, TreeAndEdges.Tree, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);

            return TreeAndEdges;
        }
开发者ID:JaySantos,项目名称:LD29,代码行数:81,代码来源:Navmesh2DEditor.cs

示例13: UpdateMesh

    public void UpdateMesh()
    {
        //clean up
        booleanUnionSolution.Clear ();
        //solutions.Clear ();
        EdgeCollider2D[] cols = GetComponents<EdgeCollider2D> ();
        foreach (EdgeCollider2D col in cols) {
            DestroyImmediate(col);
        }

        PolygonCollider2D[] polyCols = GetComponents<PolygonCollider2D> ();
        foreach (PolygonCollider2D polyCol in polyCols) {
            DestroyImmediate(polyCol);
        }

        //Wind the square to boolean from.
        levelArea.points.Clear ();
        levelArea.points.Add (new Point (-1000f, 1000f));
        levelArea.points.Add (new Point (1000f, 1000f));
        levelArea.points.Add (new Point (1000f, -1000f));
        levelArea.points.Add (new Point (-1000f, -1000f));
        ClipperLib.Clipper clipper = new ClipperLib.Clipper ();
        //Strictly simple is computationally expensive, but prevents points from appearing too close together and making Poly2Tri Shit the bed.
        clipper.StrictlySimple = true;
        foreach (Polygon polygon in booleanPolygons) {
            clipper.AddPath(polygon,ClipperLib.PolyType.ptClip, true);
        }

        clipper.Execute (ClipperLib.ClipType.ctUnion, booleanUnionSolution, ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero);
        clipper.Clear ();
        clipper.AddPath (levelArea, ClipperLib.PolyType.ptSubject, true);
        foreach (List<ClipperLib.IntPoint> polygon in booleanUnionSolution) {
            clipper.AddPath(polygon,ClipperLib.PolyType.ptClip, true);
        }
        List<List<ClipperLib.IntPoint>> solution = new List<List<ClipperLib.IntPoint>> ();
        clipper.Execute (ClipperLib.ClipType.ctDifference, solution, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNonZero);
        mesh = Utils.PolygonsToMesh (solution.Select(x=> (Polygon)x).ToList());
        solutions = solution.Select (x => (Polygon)x).ToList ();
        GetComponent<MeshFilter> ().sharedMesh = mesh;

        foreach (Polygon polygon in solution) {
            Vector2[] unityPoints = new Vector2[polygon.points.Count + 1];
            for(int i = 0; i < polygon.points.Count; i++) {
                unityPoints[i] = new Vector2(polygon.points[i].x,polygon.points[i].y);
            }
            unityPoints[polygon.points.Count] = new Vector2(polygon.points[0].x,polygon.points[0].y);
            EdgeCollider2D collider = gameObject.AddComponent<EdgeCollider2D>();
            collider.points = unityPoints;
        }

        solutionCount = booleanUnionSolution.Count;
        //No need to store polygons that we won't need to reference...
        booleanPolygons = booleanUnionSolution.Select(x=>(Polygon)x).ToList();
    }
开发者ID:JakeCataford,项目名称:unity-tinkerbox,代码行数:54,代码来源:DestructibleLevel.cs

示例14: FillPath

      public void FillPath(Color fillColor) {
         var fillClipper = new Clipper(Clipper.ioStrictlySimple);
         var points = pathSegments.SelectMany(s => new[] { new IntPoint(s.Head.Location.X * 1000, s.Head.Location.Y * 1000), new IntPoint(s.Tail.Location.X * 1000, s.Tail.Location.Y * 1000) });
         fillClipper.AddPath(points.ToList(), PolyType.ptSubject, true);
         var polytree = new PolyTree();
         fillClipper.Execute(ClipType.ctUnion, polytree, PolyFillType.pftEvenOdd, PolyFillType.pftNonZero);
         var triangles = new Triangulator().TriangulateComplex(polytree);

         using (RenderTargetSwap()) {
            GraphicsDevice.SetRasterizerState(rasterizerState);

            foreach (var pass in effect.CurrentTechnique.Passes) {
               pass.Apply();
               var x = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
               x.Begin();
               foreach (var triangle in triangles) {
                  var p1 = triangle.Points[0];
                  var p2 = triangle.Points[1];
                  var p3 = triangle.Points[2];
                  x.DrawTriangle(
                     new VertexPositionColor(new Vector3((float)p1.X, (float)p1.Y, 100), fillColor),
                     new VertexPositionColor(new Vector3((float)p2.X, (float)p2.Y, 100), fillColor),
                     new VertexPositionColor(new Vector3((float)p3.X, (float)p3.Y, 100), fillColor)
                     );
               }
               x.End();
            }
         }
      }
开发者ID:ItzWarty,项目名称:AdventuresInShade,代码行数:29,代码来源:Canvas.cs

示例15: MinkowskiSum

 //------------------------------------------------------------------------------
 public static List<List<IntPoint>> MinkowskiSum(List<IntPoint> pattern, List<List<IntPoint>> paths, bool pathIsClosed)
 {
     List<List<IntPoint>> solution = new List<List<IntPoint>>();
     Clipper c = new Clipper();
     for (int i = 0; i < paths.Count; ++i)
     {
         List<List<IntPoint>> tmp = Minkowski(pattern, paths[i], true, pathIsClosed);
         c.AddPaths(tmp, PolyType.ptSubject, true);
         if (pathIsClosed)
         {
             List<IntPoint> path = TranslatePath(paths[i], pattern[0]);
             c.AddPath(path, PolyType.ptClip, true);
         }
     }
     c.Execute(ClipType.ctUnion, solution,
       PolyFillType.pftNonZero, PolyFillType.pftNonZero);
     return solution;
 }
开发者ID:JapaMala,项目名称:armok-vision,代码行数:19,代码来源:Clipper.cs


注:本文中的ClipperLib.Clipper.AddPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。