public void CreatePoint(int index, Vector3 position)
        {
            ClearSelection();

            if (editablePath.shapeType == ShapeType.Polygon)
            {
                editablePath.InsertPoint(index + 1, new ControlPoint()
                {
                    position = position
                });
            }
            else if (editablePath.shapeType == ShapeType.Spline)
            {
                var nextIndex    = NextIndex(index);
                var currentPoint = editablePath.GetPoint(index);
                var nextPoint    = editablePath.GetPoint(nextIndex);

                float t;
                var   closestPoint = BezierUtility.ClosestPointOnCurve(
                    position,
                    currentPoint.position,
                    nextPoint.position,
                    GetRightTangentPosition(index),
                    GetLeftTangentPosition(nextIndex),
                    out t);

                Vector3 leftStartPosition;
                Vector3 leftEndPosition;
                Vector3 leftStartTangent;
                Vector3 leftEndTangent;

                Vector3 rightStartPosition;
                Vector3 rightEndPosition;
                Vector3 rightStartTangent;
                Vector3 rightEndTangent;

                BezierUtility.SplitBezier(t, currentPoint.position, nextPoint.position, GetRightTangentPosition(index), GetLeftTangentPosition(nextIndex),
                                          out leftStartPosition, out leftEndPosition, out leftStartTangent, out leftEndTangent,
                                          out rightStartPosition, out rightEndPosition, out rightStartTangent, out rightEndTangent);

                var newPointIndex = index + 1;
                var newPoint      = new ControlPoint()
                {
                    position     = closestPoint,
                    leftTangent  = leftEndTangent,
                    rightTangent = rightStartTangent,
                    tangentMode  = TangentMode.Continuous
                };

                currentPoint.rightTangent = leftStartTangent;
                nextPoint.leftTangent     = rightEndTangent;

                if (currentPoint.tangentMode == TangentMode.Linear && nextPoint.tangentMode == TangentMode.Linear)
                {
                    newPoint.tangentMode           = TangentMode.Linear;
                    newPoint.localLeftTangent      = Vector3.zero;
                    newPoint.localRightTangent     = Vector3.zero;
                    currentPoint.localRightTangent = Vector3.zero;
                    nextPoint.localLeftTangent     = Vector3.zero;
                }
                else
                {
                    if (currentPoint.tangentMode == TangentMode.Linear)
                    {
                        currentPoint.tangentMode = TangentMode.Broken;
                    }

                    if (nextPoint.tangentMode == TangentMode.Linear)
                    {
                        nextPoint.tangentMode = TangentMode.Broken;
                    }
                }

                editablePath.SetPoint(index, currentPoint);
                editablePath.SetPoint(nextIndex, nextPoint);
                editablePath.InsertPoint(newPointIndex, newPoint);
            }
        }
        public override void AddPoint(ControlPoint controlPoint)
        {
            base.AddPoint(controlPoint);

            m_Data.Add(Create());
        }
        public override void InsertPoint(int index, ControlPoint controlPoint)
        {
            base.InsertPoint(index, controlPoint);

            m_Data.Insert(index, Create());
        }
Пример #4
0
 public virtual void AddPoint(ControlPoint controlPoint)
 {
     m_EditablePath.AddPoint(controlPoint);
 }
Пример #5
0
 public virtual void SetPoint(int index, ControlPoint controlPoint)
 {
     m_EditablePath.SetPoint(index, controlPoint);
 }
Пример #6
0
 public void SetPoint(int index, ControlPoint controlPoint)
 {
     m_ControlPoints[index] = TransformPoint(worldToLocalMatrix, controlPoint);
 }
Пример #7
0
 public void InsertPoint(int index, ControlPoint controlPoint)
 {
     m_ControlPoints.Insert(index, TransformPoint(worldToLocalMatrix, controlPoint));
 }
Пример #8
0
 public void AddPoint(ControlPoint controlPoint)
 {
     m_ControlPoints.Insert(pointCount, TransformPoint(worldToLocalMatrix, controlPoint));
 }