Exemple #1
0
 public ControlPoint(Vector3 position, Vector3 normal, Vector3 inTangent, Vector3 outTangent, BezierCPMode tangentMode)
 {
     this.position    = position;
     this.normal      = normal;
     this.inTangent   = inTangent;
     this.outTangent  = outTangent;
     this.tangentMode = tangentMode;
 }
Exemple #2
0
 public ControlPoint(Vector3 position, Vector3 normal)
 {
     this.position    = position;
     this.normal      = normal;
     this.inTangent   = -Vector3.right * 0.33f;
     this.outTangent  = Vector3.right * 0.33f;
     this.tangentMode = BezierCPMode.Aligned;
 }
        public void EnforceMode(int index)
        {
            int          modeIndex = (index + 1) / 3;
            BezierCPMode mode      = controlPointModes[modeIndex];

            if (mode == BezierCPMode.Free || !closed && (modeIndex == 0 || modeIndex == controlPointModes.Count - 1))
            {
                return;
            }

            int middleIndex = modeIndex * 3;
            int fixedIndex, enforcedIndex;

            if (index <= middleIndex)
            {
                fixedIndex = middleIndex - 1;
                if (fixedIndex < 0)
                {
                    fixedIndex = controlPoints.Count - 2;
                }
                enforcedIndex = middleIndex + 1;
                if (enforcedIndex >= controlPoints.Count)
                {
                    enforcedIndex = 1;
                }
            }
            else
            {
                fixedIndex = middleIndex + 1;
                if (fixedIndex >= controlPoints.Count)
                {
                    fixedIndex = 1;
                }
                enforcedIndex = middleIndex - 1;
                if (enforcedIndex < 0)
                {
                    enforcedIndex = controlPoints.Count - 2;
                }
            }

            Vector3 middle          = controlPoints[middleIndex];
            Vector3 enforcedTangent = middle - controlPoints[fixedIndex];

            if (mode == BezierCPMode.Aligned)
            {
                enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, controlPoints[enforcedIndex]);
            }
            controlPoints[enforcedIndex] = middle + enforcedTangent;
        }
        public void SetControlPointMode(int index, BezierCPMode mode)
        {
            int i = (index + 1) / 3;

            controlPointModes[i] = mode;

            if (closed)
            {
                if (i == 0)
                {
                    controlPointModes[controlPointModes.Count - 1] = mode;
                }
                else if (i == controlPointModes.Count - 1)
                {
                    controlPointModes[0] = mode;
                }
            }

            EnforceMode(index);
        }
        protected override void SetClosed(bool closed)
        {
            if (this.closed == closed)
            {
                return;
            }

            if (!this.closed && closed)
            {
                lastOpenCP           = controlPoints[0];
                lastOpenCPMode       = controlPointModes[0];
                controlPoints[0]     = controlPoints[controlPoints.Count - 1];
                controlPointModes[0] = controlPointModes[controlPointModes.Count - 1];
            }
            else
            {
                controlPoints[0]     = lastOpenCP;
                controlPointModes[0] = lastOpenCPMode;
            }

            this.closed = closed;
            EnforceMode(0);
        }