public virtual void AddPoint(ControlPoint controlPoint)
 {
     m_EditablePath.AddPoint(controlPoint);
 }
 public virtual void SetPoint(int index, ControlPoint controlPoint)
 {
     m_EditablePath.SetPoint(index, controlPoint);
 }
Esempio n. 3
0
        public override void InsertPoint(int index, ControlPoint controlPoint)
        {
            base.InsertPoint(index, controlPoint);

            m_Data.Insert(index, Create());
        }
        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);
            }
        }
Esempio n. 5
0
        public override void AddPoint(ControlPoint controlPoint)
        {
            base.AddPoint(controlPoint);

            m_Data.Add(Create());
        }