void CalculateBounds()
{
float angle = Vector3.Angle(m_bezier.a, m_bezier.b);
if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
{
angle = Vector3.Angle(m_bezier.b, m_bezier.c);
if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
{
angle = Vector3.Angle(m_bezier.c, m_bezier.d);
if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
{
// linear bezier
Bounds bounds = m_bezier.GetBounds();
bounds.Expand(1f);
m_bounds = new Bounds[] { bounds };
return;
}
}
}
// split bezier in 10 parts to correctly raycast curves
Bezier3 bezier;
int amount = 10;
m_bounds = new Bounds[amount];
float size = 1f / amount;
for (int i = 0; i < amount; i++)
{
bezier = m_bezier.Cut(i * size, (i+1) * size);
Bounds bounds = bezier.GetBounds();
bounds.Expand(1f);
m_bounds[i] = bounds;
}
}
}