patch [#35830] Add Catmull-Rom spline as an option for lattice deformer

This commit is contained in:
Campbell Barton 2013-06-25 10:49:20 +00:00
parent 37f5945188
commit 64968e3618
3 changed files with 30 additions and 1 deletions

@ -289,6 +289,16 @@ void key_curve_position_weights(float t, float data[4], int type)
data[2] = -0.5f * t3 + 0.5f * t2 + 0.5f * t + 0.16666666f;
data[3] = 0.16666666f * t3;
}
else if (type == KEY_CATMULL_ROM) {
t2 = t * t;
t3 = t2 * t;
fc = 0.5f;
data[0] = -fc * t3 + 2.0f * fc * t2 - fc * t;
data[1] = (2.0f - fc) * t3 + (fc - 3.0f) * t2 + 1.0f;
data[2] = (fc - 2.0f) * t3 + (3.0f - 2.0f * fc) * t2 + fc * t;
data[3] = fc * t3 - fc * t2;
}
}
/* first derivative */
@ -319,6 +329,15 @@ void key_curve_tangent_weights(float t, float data[4], int type)
data[2] = -1.5f * t2 + t + 0.5f;
data[3] = 0.5f * t2;
}
else if (type == KEY_CATMULL_ROM) {
t2 = t * t;
fc = 0.5f;
data[0] = -3.0f * fc * t2 + 4.0f * fc * t - fc;
data[1] = 3.0f * (2.0f - fc) * t2 + 2.0f * (fc - 3.0f) * t;
data[2] = 3.0f * (fc - 2.0f) * t2 + 2.0f * (3.0f - 2.0f * fc) * t + fc;
data[3] = 3.0f * fc * t2 - 2.0f * fc * t;
}
}
/* second derivative */
@ -346,6 +365,14 @@ void key_curve_normal_weights(float t, float data[4], int type)
data[2] = -3.0f * t + 1.0f;
data[3] = 1.0f * t;
}
else if (type == KEY_CATMULL_ROM) {
fc = 0.5f;
data[0] = -6.0f * fc * t + 4.0f * fc;
data[1] = 6.0f * (2.0f - fc) * t + 2.0f * (fc - 3.0f);
data[2] = 6.0f * (fc - 2.0f) * t + 2.0f * (3.0f - 2.0f * fc);
data[3] = 6.0f * fc * t - 2.0f * fc;
}
}
static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl)

@ -125,7 +125,8 @@ enum {
enum {
KEY_LINEAR = 0,
KEY_CARDINAL = 1,
KEY_BSPLINE = 2
KEY_BSPLINE = 2,
KEY_CATMULL_ROM = 3,
};
/* KeyBlock->flag */

@ -458,6 +458,7 @@ static char *rna_ShapeKeyPoint_path(PointerRNA *ptr)
EnumPropertyItem keyblock_type_items[] = {
{KEY_LINEAR, "KEY_LINEAR", 0, "Linear", ""},
{KEY_CARDINAL, "KEY_CARDINAL", 0, "Cardinal", ""},
{KEY_CATMULL_ROM, "KEY_CATMULL_ROM", 0, "Catmull-Rom", ""},
{KEY_BSPLINE, "KEY_BSPLINE", 0, "BSpline", ""},
{0, NULL, 0, NULL, NULL}
};