コード例 #1
0
    /// <summary>
    /// 合并边与孔
    /// </summary>
    /// <param name="pPolygon1Point"></param>
    /// <param name="pPolygon2Point"></param>
    /// <returns></returns>
    public static zzSimplyPolygon combinePolygon(zz2DPoint pPolygon1Point, zz2DPoint pPolygon2Point)
    {
        zzSimplyPolygon lOut = new zzSimplyPolygon();

        lOut.bounds = new zz2DBounds(pPolygon1Point.position);
        zz2DPoint lPolygon1FirstPoint;
        zz2DPoint lPolygon1LastPoint;
        lOut.addOtherPolygonPoint(pPolygon1Point, pPolygon1Point,
            out lPolygon1FirstPoint, out  lPolygon1LastPoint);
        //zz2DPoint l1EndNode = lOut.addOtherPolygonPoint(ref lNode, false);
        //lOut.linkPoint(lPrePoint, l1EndNode);

        zz2DPoint lPolygon2FirstPoint;
        zz2DPoint lPolygon2LastPoint;
        lOut.addOtherPolygonPoint(pPolygon2Point, pPolygon2Point,
            out lPolygon2FirstPoint, out  lPolygon2LastPoint);

        lOut.linkPoint(lPolygon1LastPoint, lPolygon2FirstPoint);
        lOut.linkPoint(lPolygon2LastPoint, lPolygon1FirstPoint);

        lOut.checkConcave(lPolygon1FirstPoint);
        lOut.checkConcave(lPolygon1LastPoint);
        lOut.checkConcave(lPolygon2FirstPoint);
        lOut.checkConcave(lPolygon2LastPoint);

        return lOut;
    }
コード例 #2
0
    public void addHole(Vector2[] points)
    {
        zzSimplyPolygon lSimplyPolygon = new zzSimplyPolygon();
        lSimplyPolygon.setShape(points);

        addHole(lSimplyPolygon);
    }
コード例 #3
0
 public static GameObject createDebuger(zzSimplyPolygon pPolygon, string pName,Transform parent, Color lDebugLineColor)
 {
     GameObject lOut = createDebuger(pPolygon, pName);
     lOut.transform.parent = parent;
     lOut.GetComponent<zzSimplyPolygonDebuger>().lineColor = lDebugLineColor;
     return lOut;
 }
コード例 #4
0
    public static GameObject createDebuger(zzSimplyPolygon pPolygon, string pName)
    {
        GameObject lPolygonDebugerObject = new GameObject(pName);
        zzSimplyPolygonDebuger lPolygonDebuger = lPolygonDebugerObject.AddComponent<zzSimplyPolygonDebuger>();

        lPolygonDebuger.polygon = pPolygon;
        return lPolygonDebugerObject;
    }
コード例 #5
0
 public static GameObject[] createDebuger(zzSimplyPolygon[] pPolygons, string pName,Transform parent)
 {
     GameObject[] lOut = createDebuger(pPolygons, pName);
     foreach (var lObject in lOut)
     {
         lObject.transform.parent = parent;
     }
     return lOut;
 }
コード例 #6
0
 public static GameObject[] createDebuger(zzSimplyPolygon[] pPolygons, string pName)
 {
     GameObject[] lOut = new GameObject[pPolygons.Length];
     for(int i=0;i<pPolygons.Length;++i)
     {
         lOut[i]=createDebuger(pPolygons[i], pName + i);
     }
     return lOut;
 }
コード例 #7
0
    static GameObject createFlatMesh(zzSimplyPolygon[] pPolygons, string pName, Transform pParent)
    {
        GameObject lOut;
        Transform   lParent;
        if(pParent)
        {
            lOut = pParent.gameObject;
            lParent = pParent;
        }
        else
        {
            lOut = new GameObject(pName);
            lParent = lOut.transform;
        }

        int i = 0;
        foreach (var lPolygon in pPolygons)
        {
            createFlatMesh(lPolygon.getShape(),pName+i,lParent);
            ++i;
        }
        return lOut;
    }
コード例 #8
0
    zzSimplyPolygon addSimplyPolygon(Vector2[] pPoints, string pName, Transform pDebugerObject, Color lDebugLineColor)
    {
        if (pPoints.Length < 3)
            return null;

        zzSimplyPolygon lPolygon = new zzSimplyPolygon();
        lPolygon.setShape(pPoints);

        pointNumber += lPolygon.pointNum;
        return lPolygon;
    }
コード例 #9
0
    public override void sweepPicture()
    {
        pointNumber = 0;
        polygonNumber = 0;
        holeNumber = 0;
        var lPatternResult = zzOutlineSweeper.sweeper(activeChart);
        imagePatterns = new Texture2D[lPatternResult.Count];
        imagePatternBounds = new zzPointBounds[lPatternResult.Count];

        //拾取图块
        for (int i = 0; i < lPatternResult.Count; ++i)
        {
            zzPointBounds lBounds = lPatternResult.sweeperPointResults[i].Bounds;
            imagePatternBounds[i] = lBounds;
            var lBoundMin = lBounds.min;
            var lBoundMax = lBounds.max;
            zzPoint lPatternSize = new zzPoint(
                Mathf.NextPowerOfTwo(lBoundMax.x - lBoundMin.x + 1),
                Mathf.NextPowerOfTwo(lBoundMax.y - lBoundMin.y + 1)
                );
            imagePatterns[i] = zzImagePatternPicker.pick(lPatternResult.patternMark, i + 1,
                picture, lBounds, lPatternSize);
        }
        //var lSweeperResults = zzOutlineSweeper.sweeper(activeChart, ignoreDistanceInSweeping);
        var lSweeperResults = zzOutlineSweeper
            .simplifySweeperResult(lPatternResult.sweeperPointResults, ignoreDistanceInSweeping);
        modelsSize = new Vector2((float)activeChart.width, (float)activeChart.height);

        //存储结果
        concaves = new List<zz2DConcave>();
        var lNewImagePatterns =new List<Texture2D>(lPatternResult.Count);
        var lNewPatternBounds = new List<zzPointBounds>(lPatternResult.Count);
        for (int i = 0; i < lSweeperResults.Count; ++i)
        {
            var lSweeperResult = lSweeperResults[i];
            var lImage = imagePatterns[i];
            if (lSweeperResult.edge.Length < 2 || lImage.width < 3 || lImage.height<3)
                continue;
            lNewImagePatterns.Add(lImage);
            lNewPatternBounds.Add(imagePatternBounds[i]);
            zzSimplyPolygon lPolygon = new zzSimplyPolygon();
            lPolygon.setShape(lSweeperResult.edge);

            zz2DConcave lConcave = new zz2DConcave();
            lConcave.setShape(lPolygon);
            ++polygonNumber;

            foreach (var lHole in lSweeperResult.holes)
            {
                if (lHole.Length < 2)
                    continue;
                zzSimplyPolygon lHolePolygon = new zzSimplyPolygon();
                lHolePolygon.setShape(lHole);
                lConcave.addHole(lHolePolygon);
                ++holeNumber;
            }

            concaves.Add(lConcave);
        }

        imagePatterns = lNewImagePatterns.ToArray();
        imagePatternBounds = lNewPatternBounds.ToArray();
    }
コード例 #10
0
    public static zzSimplyPolygon getSubPolygon(zz2DPoint pBeginPoint,zz2DPoint pEndPoint)
    {
        if (
            pBeginPoint.listNode.List != pEndPoint.listNode.List
            )
        {
            Debug.LogError("point is not in the polygon");
            return null;
        }

        zzSimplyPolygon lOut = new zzSimplyPolygon();

        //zz2DPoint lNode = pBeginPoint;
        lOut.bounds = new zz2DBounds(pBeginPoint.position);
        zz2DPoint lFirstPoint;
        zz2DPoint lLastPoint;
        lOut.addOtherPolygonPoint(pBeginPoint, pEndPoint, out lFirstPoint, out  lLastPoint);

        lOut.linkPoint(lLastPoint, lFirstPoint);

        lOut.checkConcave(lLastPoint);
        lOut.checkConcave(lFirstPoint);

        return lOut;
    }
コード例 #11
0
 public void addHole(zzSimplyPolygon pSimplyPolygon)
 {
     mHolePoint.Add(pSimplyPolygon);
 }
コード例 #12
0
 public void setShape(zzSimplyPolygon lSimplyPolygon)
 {
     mOutSidePoint = lSimplyPolygon;
 }
コード例 #13
0
 public void setShape(Vector2[] points)
 {
     mOutSidePoint = new zzSimplyPolygon();
     mOutSidePoint.setShape(points);
 }
コード例 #14
0
 public static GameObject createDebuger(zzSimplyPolygon pPolygon, string pName,Transform parent)
 {
     GameObject lOut = createDebuger(pPolygon, pName);
     lOut.transform.parent = parent;
     return lOut;
 }
コード例 #15
0
 public static zzSimplyPolygon toPolygon(zzPainterPoint pPoint)
 {
     zzSimplyPolygon lOut = new zzSimplyPolygon();
     List<Vector2> lPoints = new List<Vector2>();
     zzPainterPoint lNowPoint = pPoint;
     do
     {
         Vector3 l3DPoint = lNowPoint.transform.position;
         lPoints.Add(new Vector2(l3DPoint.x, l3DPoint.y));
         lNowPoint = lNowPoint.nextPoint;
     }
     while (lNowPoint != pPoint);
     lOut.setShape(lPoints.ToArray());
     return lOut;
 }