bansheeGz / BGCurve

Bezier spline editor for Unity game engine
MIT License
145 stars 27 forks source link

How can i convert absent curve to smooth (symmetry bezier) in runtime? #19

Closed ShockWave2048 closed 4 years ago

ShockWave2048 commented 4 years ago

Hi! A just add in runtime (from script) simple points to curve with symmetry bezier type (and absent), it's have to crazy broken view - https://prnt.sc/t1i182 How can i convert this points curve to right smooth (symmetry bezier)? Thanks for answer!

banshee-gzzz commented 4 years ago

Hi! You can set point's interpolation mode (Absent/BezierIndependent/BezierSymmetrical) when you create a point, like so:

        for (var i = 0; i < 3; i++)
        {
            var controlSecond = Vector3.right;
            curve.AddPoint(new BGCurvePoint(curve, Vector3.forward * i, BGCurvePoint.ControlTypeEnum.BezierSymmetrical, -controlSecond, controlSecond));
        }

Alternatively, iterate over points and change their mode if current mode==Absent:

for (var i = 0; i < curve.PointsCount; i++)
        {
            var point = curve[i];
            if (point.ControlType == BGCurvePoint.ControlTypeEnum.Absent)
            {
                point.ControlType = BGCurvePoint.ControlTypeEnum.BezierSymmetrical;
                point.ControlSecondLocal = Vector3.right;
            }
        }
ShockWave2048 commented 4 years ago

Thanks very match! Will try today!