Example #1
0
        public static void SubdivideVertexInfoList(List <ShapeVertexInfo> vertexList, List <ShapeVertexInfo> vertexListSubdivided)
        {
            vertexListSubdivided.Clear();
            if (vertexList.Count < 2)
            {
                return;
            }

            for (int i = 0; i < vertexList.Count - 1; i++)
            {
                ShapeVertexInfo v1 = vertexList[i];
                ShapeVertexInfo v2 = vertexList[i + 1];

                if (v1.type == ShapePointType.Corner && v2.type == ShapePointType.Corner)
                {
                    //Debug.Log ("corner " + i);
                    vertexListSubdivided.Add(v1);

                    if (i == vertexList.Count - 2)                     // only draw last point when at end of shape
                    {
                        vertexListSubdivided.Add(v2);
                    }

                    continue;
                }

                BezierUtils.SubdivideBezier(v1.position, v1.position + v1.outTangent, v2.position + v2.inTangent, v2.position, subdivisionLerpTemp, subdivisionPointsTemp, subdivisionMaxAngle, subdivisionMinDist);

                int lastSubdivPointId = subdivisionLerpTemp.Count - 1;
                int firstDrawPoint    = 0;
                int lastDrawPoint     = lastSubdivPointId;

                if (i < vertexList.Count - 2)                 // hide last point except when at end of shape
                {
                    lastDrawPoint -= 1;
                }

                if (i == 0)
                {
                    firstDrawPoint = lastDrawPoint;
                }
                if (i == vertexList.Count - 2)
                {
                    lastDrawPoint = firstDrawPoint + 1;
                }


                //Debug.Log ("bezier "+i + " min " + firstDrawPoint + " max " + lastDrawPoint +  " subdivcount "+subdivisionLerp.Count);

                for (int j = firstDrawPoint; j <= lastDrawPoint; j++)
                {
                    float           lerp = Mathf.InverseLerp(0, lastSubdivPointId, j);
                    ShapeVertexInfo v    = v1;
                    v.position    = subdivisionPointsTemp[j];
                    v.strokeWidth = Mathf.Lerp(v1.strokeWidth, v2.strokeWidth, lerp);
                    v.strokeColor = Color.Lerp(v1.strokeColor, v2.strokeColor, lerp);
                    v.posOnLine   = Mathf.Lerp(v1.posOnLine, v2.posOnLine, lerp);

                    vertexListSubdivided.Add(v);
                }
            }

            /*for (int i = 0; i < _vertexInfoListSubdivided.Count-1; i++) {
             *
             *      Color c = Color.green;
             *      if (i == 0)
             *              c = Color.red;
             *      if (i == _vertexInfoListSubdivided.Count - 2)
             *              c = Color.blue;
             *      Debug.DrawLine (_vertexInfoListSubdivided [i].position, _vertexInfoListSubdivided [i + 1].position,c);
             * }*/
        }