10-08-2014, 11:14 PM
Hey there,
I've encountered a few bugs (and some minor missing features) here and there over the past several months working with Curvy; I'm post my solutions here in hopes you'll consider putting them into an upcoming release (as it will make merging new versions easier for me )
1. TCB interpolation does not respect previous and next control point positions if those positions come from different connected splines. I changed a line in CurvySplineSegment's Interpolate method from this:
to this:
It's consistent with the other interpolation modes and seems to work fine.
2. The 'MeshInfo' constructor in CurvyUtility allocates a temporary mesh when 'mirror' is set to true but forgets to destroy it after finishing. I added this to the end:
3. FlipSpline doesn't behave very well in TCB mode; the shape changes drastically since the various parameters are not mirrored correctly between control points. My version of the function looks like this:
4. CurvySplineGroups do not check for null entries in their member array either in their OnDisable or Update methods, which is problematic when you're working in the editor and slots are temporarily left empty (spawns a bunch of needless errors). I added some simple null checks:
5. CurvySpline's update method can create an infinite refresh loop when two splines are connected to one another at both ends because each orders the other to refresh orientation next frame. I got around this by using kind of a hack - I just call the private doRefreshOrientation() method right away instead of scheduling it:
I've done a bunch of work with Curvy aside from this and it is by far the most useful thing I've found in the Asset Store. Keep up the good work
I've encountered a few bugs (and some minor missing features) here and there over the past several months working with Curvy; I'm post my solutions here in hopes you'll consider putting them into an upcoming release (as it will make merging new versions easier for me )
1. TCB interpolation does not respect previous and next control point positions if those positions come from different connected splines. I changed a line in CurvySplineSegment's Interpolate method from this:
Code:
return CurvySpline.TCB(PreviousTransform.position, Transform.position, NextTransform.position, NextControlPoint.NextTransform.position, localF, t0, c0, b0, t1, c1, b1);
Code:
return CurvySpline.TCB(GetPrevPosition(), Transform.position, GetNextPosition(), GetNextNextPosition(), localF, t0, c0, b0, t1, c1, b1);
It's consistent with the other interpolation modes and seems to work fine.
2. The 'MeshInfo' constructor in CurvyUtility allocates a temporary mesh when 'mirror' is set to true but forgets to destroy it after finishing. I added this to the end:
Code:
if(mirror) GameObject.DestroyImmediate(mesh);
3. FlipSpline doesn't behave very well in TCB mode; the shape changes drastically since the various parameters are not mirrored correctly between control points. My version of the function looks like this:
Code:
/// <summary>
/// Flips the direction of a spline, i.e. the first Control Point will become the last and vice versa.
/// </summary>
public static void FlipSpline(CurvySpline spline)
{
spline.Bias *= -1;
for(int i = spline.ControlPointCount - 1; i >= 0; i--) {
CurvySplineSegment cur = spline.ControlPoints[i];
Vector3 h = cur.HandleIn;
cur.HandleIn = cur.HandleOut;
cur.HandleOut = h;
int j = i - 1;
if(j >= 0) {
CurvySplineSegment prev = spline.ControlPoints[j];
cur.EndBias = prev.StartBias * -1;
cur.EndContinuity = prev.StartContinuity;
cur.EndTension = prev.StartTension;
cur.StartBias = prev.EndBias * -1;
cur.StartContinuity = prev.EndContinuity;
cur.StartTension = prev.EndTension;
cur.OverrideGlobalBias = prev.OverrideGlobalBias;
cur.OverrideGlobalContinuity = prev.OverrideGlobalContinuity;
cur.OverrideGlobalTension = prev.OverrideGlobalTension;
cur.SynchronizeTCB = prev.SynchronizeTCB;
}
}
spline.ControlPoints.Reverse();
spline._RenameControlPointsByIndex();
spline.RefreshImmediately(true, true, false);
}
4. CurvySplineGroups do not check for null entries in their member array either in their OnDisable or Update methods, which is problematic when you're working in the editor and slots are temporarily left empty (spawns a bunch of needless errors). I added some simple null checks:
Code:
void OnDisable()
{
foreach (CurvySpline spl in Splines)
if(spl != null) spl.OnRefresh -= OnSplineRefresh;
}
void Update()
{
for (int i=0;i<Count;i++){
if(this[i] != null) {
this[i].OnRefresh -= OnSplineRefresh;
this[i].OnRefresh += OnSplineRefresh;
}
}
if (mNeedLengthRefresh || mNeedOrientationRefresh)
RefreshImmediately(mNeedLengthRefresh, mNeedOrientationRefresh, mSkipRefreshIfInitialized);
}
5. CurvySpline's update method can create an infinite refresh loop when two splines are connected to one another at both ends because each orders the other to refresh orientation next frame. I got around this by using kind of a hack - I just call the private doRefreshOrientation() method right away instead of scheduling it:
Code:
// refresh orientation of connected splines in the editor
if (!Application.isPlaying && ControlPointCount>0 && ControlPoints[ControlPointCount - 1].ConnectedBy.Count > 0) {
var otherSpl = ControlPoints[ControlPointCount - 1].ConnectedBy[0].Spline;
if(otherSpl.IsInitialized) {
otherSpl.doRefreshOrientation();
} else {
otherSpl.Refresh(false, true, false);
}
}
I've done a bunch of work with Curvy aside from this and it is by far the most useful thing I've found in the Asset Store. Keep up the good work