- Home /
How can I get an accurate bounding rect for an AnimationCurve
Hi guys
I'm currently using the following to get my curve bounding rect:
public static Rect GetBounds(this AnimationCurve extends)
{
if (extends.length == 0)
return new Rect();
float xMin = extends.keys.First().time;
float xMax = extends.keys.Last().time;
float yMin = extends.keys.First().value;
float yMax = yMin;
foreach (Keyframe frame in extends.keys)
{
if (frame.value < yMin)
yMin = frame.value;
if (frame.value > yMax)
yMax = frame.value;
}
return Rect.MinMaxRect(xMin, yMax, xMax, yMin);
}
The problem is that this method doesn't consider the tangents of each KeyFrame.
I presume Unity already has some hidden method for getting the bounding Rect since it is able to focus curves in the curve editor.
Does anyone know how I can get an accurate bounding Rect for my AnimationCurves?
Thanks, Ves
Answer by VesuvianPrime · Aug 04, 2014 at 04:57 PM
I've ended up using reflection to get at the NormalCurveRenderer class and call GetBounds.
Your answer
Follow this Question
Related Questions
How to convert cubic Bezier curve into AnimationCurve 3 Answers
How can I set my Animation Curve's Tangents to Flat in script? 0 Answers
How can I convert AnimationCurve.in/outTangent to an angle 2 Answers
What is the length of the Keyframe tangent? 0 Answers
How do I modify a keyframe/curve's tangent in code? 2 Answers