Beispiel #1
0
    public void CalculateBevelOutline(List <Vector2> vertices, float strokeWidth, ref List <Vector3> verts, ref List <Vector2> uvs, ref List <int> tris)
    {
        int n = vertices.Count;

        int initIndex = verts.Count;

        int i       = 0;
        int vertNum = initIndex;

        float   pFactor = 0, nFactor = 0;
        Vector2 pVer = vertices[n - 1];
        Vector2 cVer = vertices[0];
        Vector2 nVer = vertices[1];
        float   pDis = Vector2.Distance(pVer, cVer);
        float   nDis;      // = Vector2.Distance(cVer, nVer);

//		int sign = ForceEarCut.ComputeSpannedAreaSign(pVer, cVer, nVer);
        Vector2 firstSkewPoint = pVer;

        Debug.LogError(gameObject.name + " is going on to enter while ... ! ");

        while (i < n + 1)
        {
            nDis = Vector2.Distance(cVer, nVer);
            if (nDis < strokeWidth)
            {
                pDis = Vector2.Distance(pVer, nVer);
                i++;
//				cVer = nVer;
                nVer = vertices[i % n];

                continue;
            }

            pFactor = pDis / strokeWidth;
            nFactor = nDis / strokeWidth;

            Vector2 perPC = CGAlgorithm.Perp(pVer, cVer, strokeWidth);
            Vector2 perCN = CGAlgorithm.Perp(cVer, nVer, strokeWidth);

            int sign = ForceEarCut.ComputeSpannedAreaSign(pVer, cVer, nVer);
            if (sign < 0)
            {
                //	sign < 0 :
                //		  p
                //		   \
                //			\
                //		=== c --> n ===

                Vector2 skewPoint = cVer + perPC;
                //CGAlgorithm.Intersect2D_2SkewSegments(pVer + perPC, cVer + perPC , cVer + perCN, nVer + perCN, ref skewPoint) ;
                if (CGAlgorithm.Intersect2D_2SkewSegments(pVer + perPC, cVer + perPC, cVer + perCN, nVer + perCN, ref skewPoint))
                {
                    if (vertNum > initIndex)
                    {
                        verts[vertNum - 1] = skewPoint;
                    }


                    verts.Add(pVer);
                    verts.Add(skewPoint);
                    verts.Add(cVer);
                    verts.Add(nVer + perCN);

                    uvs.Add(new Vector2(0, 0));
                    uvs.Add(new Vector2(1, pFactor));
                    uvs.Add(new Vector2(0, pFactor));
                    uvs.Add(new Vector2(1, pFactor + nFactor));

                    if (_facing == Facing.FACE_FORWARD)
                    {
                        tris.Add(vertNum);
                        tris.Add(vertNum + 2);
                        tris.Add(vertNum + 1);
                        tris.Add(vertNum + 2);
                        tris.Add(vertNum + 3);
                        tris.Add(vertNum + 1);
                    }
                    else if (_facing == Facing.FACE_BACK)
                    {
                        tris.Add(vertNum);
                        tris.Add(vertNum + 1);
                        tris.Add(vertNum + 2);
                        tris.Add(vertNum + 2);
                        tris.Add(vertNum + 1);
                        tris.Add(vertNum + 3);
                    }

                    vertNum += 4;
                }
            }
            else
            {
                // or sign > 0 :
                //					 p
                //		            /
                //				   /
                //		=== n <-- c ===
                //


                //				}else{
                //---------------------------------------------------------------------------

                verts.Add(pVer);
                verts.Add(cVer + perPC);
                verts.Add(cVer);
                verts.Add(cVer + perCN);
                verts.Add(nVer + perCN);

                uvs.Add(new Vector2(0, 0));
                uvs.Add(new Vector2(1, pFactor));
                uvs.Add(new Vector2(0, pFactor));
                uvs.Add(new Vector2(1, pFactor));
                uvs.Add(new Vector2(1, pFactor + nFactor));

                if (_facing == Facing.FACE_FORWARD)
                {
                    tris.Add(vertNum);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 1);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 3);
                    tris.Add(vertNum + 1);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 4);
                    tris.Add(vertNum + 3);
                }
                else if (_facing == Facing.FACE_BACK)
                {
                    tris.Add(vertNum);
                    tris.Add(vertNum + 1);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 1);
                    tris.Add(vertNum + 3);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 3);
                    tris.Add(vertNum + 4);
                }
                vertNum += 5;
            }
            i++;
            pVer = cVer;
            cVer = nVer;
            nVer = vertices[i % n];
            pDis = nDis;
        }
    }
Beispiel #2
0
    public void CalculateMeshData(List <Vector2> vertices, float strokeWidth, ref List <Vector3> verts, ref List <Vector2> uvs, ref List <int> tris)
    {
        int n = vertices.Count;

        int initIndex = verts.Count;

        int i       = 0;
        int vertNum = initIndex;

        float   pFactor = 0, nFactor = 0;
        Vector2 pVer = vertices[n - 1];
        Vector2 cVer = vertices[0];
        Vector2 nVer = vertices[1];
        float   pDis = Vector2.Distance(pVer, cVer);
        float   nDis;      // = Vector2.Distance(cVer, nVer);

        //		int sign = ForceEarCut.ComputeSpannedAreaSign(pVer, cVer, nVer);
        Vector2 firstSkewPoint = pVer;

        while (i < n + 1)
        {
            nDis = Vector2.Distance(cVer, nVer);
            if (nDis < strokeWidth)
            {
                pDis = Vector2.Distance(pVer, nVer);
                i++;
                //				cVer = nVer;
                nVer = vertices[i % n];

                continue;
            }

            pFactor = pDis / strokeWidth;
            nFactor = nDis / strokeWidth;

            Vector2 perPC = CGAlgorithm.Perp(pVer, cVer, strokeWidth);
            Vector2 perCN = CGAlgorithm.Perp(cVer, nVer, strokeWidth);

            Vector2 skewPoint = cVer + perPC;
            //CGAlgorithm.Intersect2D_2SkewSegments(pVer + perPC, cVer + perPC , cVer + perCN, nVer + perCN, ref skewPoint) ;
            Vector2 pcDir = (cVer - pVer).normalized * strokeWidth * 5;
            Vector2 cnDir = (cVer - nVer).normalized * strokeWidth * 5;
            if (CGAlgorithm.Intersect2D_2SkewSegments(
                    pVer + perPC, cVer + perPC + pcDir,
                    cVer + perCN + cnDir, nVer + perCN,
                    ref skewPoint))
            {
                if (vertNum == initIndex)
                {
                    firstSkewPoint = skewPoint;
                }
                else
                {
                    verts[vertNum - 1] = skewPoint;
                }
                verts.Add(pVer);
                verts.Add(skewPoint);
                verts.Add(cVer);
                if (i == n)
                {
                    verts.Add(firstSkewPoint);
                }
                else
                {
                    verts.Add(nVer);                     //(nVer + perCN);
                }

                uvs.Add(new Vector2(0, 0));
                uvs.Add(new Vector2(1, pFactor));
                uvs.Add(new Vector2(0, pFactor));

                uvs.Add(new Vector2(1, pFactor + nFactor));

                if (_facing == Facing.FACE_FORWARD)
                {
                    tris.Add(vertNum);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 1);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 3);
                    tris.Add(vertNum + 1);
                }
                else if (_facing == Facing.FACE_BACK)
                {
                    tris.Add(vertNum);
                    tris.Add(vertNum + 1);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 2);
                    tris.Add(vertNum + 1);
                    tris.Add(vertNum + 3);
                }

                vertNum += 4;
            }
            else
            {
                Debug.LogError("Outline .... no intersect???");
            }
            i++;
            pVer = cVer;
            cVer = nVer;
            nVer = vertices[i % n];
            pDis = nDis;
        }
    }