/// <summary> /// Set <see cref="Knot"/> <paramref name="knot"/> info in local coordinates at the <paramref name="index"/> /// position in the collection. /// </summary> public void SetKnot(int index, Knot knot) { //If knot is set to auto, adjust handles accordingly _knotRotations[index] = knot.rotation; _autoKnotsCache[index] = knot.auto; if (knot.IsUsingAutoHandles) { PositionAutoHandles(index, ref knot); } //Automate knots around this knot int preKnotIndex, postKnotIndex; GetKnotIndicesForKnot(index, out preKnotIndex, out postKnotIndex); var preKnot = new Knot(); if (preKnotIndex != -1) { preKnot = GetKnot(preKnotIndex); if (preKnot.IsUsingAutoHandles) { int preKnotPreCurveIndex, preKnotPostCurveIndex; GetCurveIndicesForKnot(preKnotIndex, out preKnotPreCurveIndex, out preKnotPostCurveIndex); if (preKnotPreCurveIndex != -1) { PositionAutoHandles( preKnotIndex, ref preKnot, _curves[preKnotPreCurveIndex].StartPoint, knot.position); _curves[preKnotPreCurveIndex] = new Bezier3DCurve( _curves[preKnotPreCurveIndex].StartPoint, _curves[preKnotPreCurveIndex].FirstHandle, preKnot.handleIn, preKnot.position, InterpolationStepsPerCurve); } else { PositionAutoHandles( preKnotIndex, ref preKnot, Vector3.zero, knot.position); } } } var postKnot = new Knot(); if (postKnotIndex != -1) { postKnot = GetKnot(postKnotIndex); if (postKnot.IsUsingAutoHandles) { int postKnotPreCurveIndex, postKnotPostCurveIndex; GetCurveIndicesForKnot(postKnotIndex, out postKnotPreCurveIndex, out postKnotPostCurveIndex); if (postKnotPostCurveIndex != -1) { PositionAutoHandles( postKnotIndex, ref postKnot, knot.position, _curves[postKnotPostCurveIndex].EndPoint); _curves[postKnotPostCurveIndex] = new Bezier3DCurve( postKnot.position, postKnot.handleOut, _curves[postKnotPostCurveIndex].SecondHandle, _curves[postKnotPostCurveIndex].EndPoint, InterpolationStepsPerCurve); } else { PositionAutoHandles( postKnotIndex, ref postKnot, knot.position, Vector3.zero); } } } //Get the curve indices in direct contact with knot int preCurveIndex, postCurveIndex; GetCurveIndicesForKnot(index, out preCurveIndex, out postCurveIndex); //Adjust curves in direct contact with the knot if (preCurveIndex != -1) { _curves[preCurveIndex] = new Bezier3DCurve( preKnot.position, preKnot.handleOut, knot.handleIn, knot.position, InterpolationStepsPerCurve); } if (postCurveIndex != -1) { _curves[postCurveIndex] = new Bezier3DCurve( knot.position, knot.handleOut, postKnot.handleIn, postKnot.position, InterpolationStepsPerCurve); } _totalLength = GetTotalLength(); }