diff --git a/source/blender/blenkernel/BKE_key.hh b/source/blender/blenkernel/BKE_key.hh index 7721bbe7fc9..f563ccced81 100644 --- a/source/blender/blenkernel/BKE_key.hh +++ b/source/blender/blenkernel/BKE_key.hh @@ -11,6 +11,8 @@ #include "BLI_math_vector_types.hh" #include "BLI_span.hh" +#include "DNA_key_types.h" + /** \file * \ingroup bke */ @@ -33,15 +35,15 @@ Key *BKE_key_add(Main *bmain, ID *id); */ void BKE_key_sort(Key *key); -void key_curve_position_weights(float t, float data[4], int type); +void key_curve_position_weights(float t, float data[4], KeyInterpolationType type); /** * First derivative. */ -void key_curve_tangent_weights(float t, float data[4], int type); +void key_curve_tangent_weights(float t, float data[4], KeyInterpolationType type); /** * Second derivative. */ -void key_curve_normal_weights(float t, float data[4], int type); +void key_curve_normal_weights(float t, float data[4], KeyInterpolationType type); /** * Returns key coordinates (+ tilt) when key applied, NULL otherwise. diff --git a/source/blender/blenkernel/intern/curve.cc b/source/blender/blenkernel/intern/curve.cc index ed6280ab427..52368104d86 100644 --- a/source/blender/blenkernel/intern/curve.cc +++ b/source/blender/blenkernel/intern/curve.cc @@ -1972,7 +1972,7 @@ static void tilt_bezpart(const BezTriple *prevbezt, (bezt->tilt - prevbezt->tilt) * (3.0f * fac * fac - 2.0f * fac * fac * fac); } else { - key_curve_position_weights(fac, t, nu->tilt_interp); + key_curve_position_weights(fac, t, KeyInterpolationType(nu->tilt_interp)); *tilt_array = t[0] * pprev->tilt + t[1] * prevbezt->tilt + t[2] * bezt->tilt + t[3] * next->tilt; } @@ -1992,7 +1992,7 @@ static void tilt_bezpart(const BezTriple *prevbezt, /* reuse interpolation from tilt if we can */ if (tilt_array == nullptr || nu->tilt_interp != nu->radius_interp) { - key_curve_position_weights(fac, t, nu->radius_interp); + key_curve_position_weights(fac, t, KeyInterpolationType(nu->radius_interp)); } *radius_array = t[0] * pprev->radius + t[1] * prevbezt->radius + t[2] * bezt->radius + t[3] * next->radius; diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index e047041b8d6..ec89d8583a9 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -338,116 +338,122 @@ void BKE_key_sort(Key *key) /**************** do the key ****************/ -void key_curve_position_weights(float t, float data[4], int type) +void key_curve_position_weights(float t, float data[4], KeyInterpolationType type) { float t2, t3, fc; - if (type == KEY_LINEAR) { - data[0] = 0.0f; - data[1] = -t + 1.0f; - data[2] = t; - data[3] = 0.0f; - } - else if (type == KEY_CARDINAL) { - t2 = t * t; - t3 = t2 * t; - fc = 0.71f; + switch (type) { + case KEY_LINEAR: + data[0] = 0.0f; + data[1] = -t + 1.0f; + data[2] = t; + data[3] = 0.0f; + break; + case KEY_CARDINAL: + t2 = t * t; + t3 = t2 * t; + fc = 0.71f; - 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; - } - else if (type == KEY_BSPLINE) { - t2 = t * t; - t3 = t2 * t; + 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; + break; + case KEY_BSPLINE: + t2 = t * t; + t3 = t2 * t; - data[0] = -0.16666666f * t3 + 0.5f * t2 - 0.5f * t + 0.16666666f; - data[1] = 0.5f * t3 - t2 + 0.66666666f; - 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] = -0.16666666f * t3 + 0.5f * t2 - 0.5f * t + 0.16666666f; + data[1] = 0.5f * t3 - t2 + 0.66666666f; + data[2] = -0.5f * t3 + 0.5f * t2 + 0.5f * t + 0.16666666f; + data[3] = 0.16666666f * t3; + break; + case 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; + 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; + break; } } -void key_curve_tangent_weights(float t, float data[4], int type) +void key_curve_tangent_weights(float t, float data[4], KeyInterpolationType type) { float t2, fc; - if (type == KEY_LINEAR) { - data[0] = 0.0f; - data[1] = -1.0f; - data[2] = 1.0f; - data[3] = 0.0f; - } - else if (type == KEY_CARDINAL) { - t2 = t * t; - fc = 0.71f; + switch (type) { + case KEY_LINEAR: + data[0] = 0.0f; + data[1] = -1.0f; + data[2] = 1.0f; + data[3] = 0.0f; + break; + case KEY_CARDINAL: + t2 = t * t; + fc = 0.71f; - 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; - } - else if (type == KEY_BSPLINE) { - t2 = t * t; + 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; + break; + case KEY_BSPLINE: + t2 = t * t; - data[0] = -0.5f * t2 + t - 0.5f; - data[1] = 1.5f * t2 - t * 2.0f; - 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] = -0.5f * t2 + t - 0.5f; + data[1] = 1.5f * t2 - t * 2.0f; + data[2] = -1.5f * t2 + t + 0.5f; + data[3] = 0.5f * t2; + break; + case 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; + 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; + break; } } -void key_curve_normal_weights(float t, float data[4], int type) +void key_curve_normal_weights(float t, float data[4], KeyInterpolationType type) { float fc; - if (type == KEY_LINEAR) { - data[0] = 0.0f; - data[1] = 0.0f; - data[2] = 0.0f; - data[3] = 0.0f; - } - else if (type == KEY_CARDINAL) { - fc = 0.71f; + switch (type) { + case KEY_LINEAR: + data[0] = 0.0f; + data[1] = 0.0f; + data[2] = 0.0f; + data[3] = 0.0f; + break; + case KEY_CARDINAL: + fc = 0.71f; - 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; - } - else if (type == KEY_BSPLINE) { - data[0] = -1.0f * t + 1.0f; - data[1] = 3.0f * t - 2.0f; - 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; + break; + case KEY_BSPLINE: + data[0] = -1.0f * t + 1.0f; + data[1] = 3.0f * t - 2.0f; + data[2] = -3.0f * t + 1.0f; + data[3] = 1.0f * t; + break; + case 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; + 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; + break; } } @@ -584,11 +590,11 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl) } /* interpolation */ - key_curve_position_weights(d, t, k[1]->type); + key_curve_position_weights(d, t, KeyInterpolationType(k[1]->type)); if (k[1]->type != k[2]->type) { float t_other[4]; - key_curve_position_weights(d, t_other, k[2]->type); + key_curve_position_weights(d, t_other, KeyInterpolationType(k[2]->type)); interp_v4_v4v4(t, t, t_other, d); } diff --git a/source/blender/blenkernel/intern/lattice_deform.cc b/source/blender/blenkernel/intern/lattice_deform.cc index 19caa6f8e7c..b42813b86da 100644 --- a/source/blender/blenkernel/intern/lattice_deform.cc +++ b/source/blender/blenkernel/intern/lattice_deform.cc @@ -167,7 +167,7 @@ void BKE_lattice_deform_data_eval_co(LatticeDeformData *lattice_deform_data, u = (vec[0] - lt->fu) / lt->du; ui = int(floor(u)); u -= ui; - key_curve_position_weights(u, tu, lt->typeu); + key_curve_position_weights(u, tu, KeyInterpolationType(lt->typeu)); } else { tu[0] = tu[2] = tu[3] = 0.0; @@ -179,7 +179,7 @@ void BKE_lattice_deform_data_eval_co(LatticeDeformData *lattice_deform_data, v = (vec[1] - lt->fv) / lt->dv; vi = int(floor(v)); v -= vi; - key_curve_position_weights(v, tv, lt->typev); + key_curve_position_weights(v, tv, KeyInterpolationType(lt->typev)); } else { tv[0] = tv[2] = tv[3] = 0.0; @@ -191,7 +191,7 @@ void BKE_lattice_deform_data_eval_co(LatticeDeformData *lattice_deform_data, w = (vec[2] - lt->fw) / lt->dw; wi = int(floor(w)); w -= wi; - key_curve_position_weights(w, tw, lt->typew); + key_curve_position_weights(w, tw, KeyInterpolationType(lt->typew)); } else { tw[0] = tw[2] = tw[3] = 0.0; diff --git a/source/blender/blenkernel/intern/particle.cc b/source/blender/blenkernel/intern/particle.cc index c7c1b0cfcf0..7cb1c870f26 100644 --- a/source/blender/blenkernel/intern/particle.cc +++ b/source/blender/blenkernel/intern/particle.cc @@ -1145,7 +1145,7 @@ void psys_interpolate_particle( interp_cubic_v3(result->co, result->vel, keys[1].co, keys[1].vel, keys[2].co, keys[2].vel, dt); } else { - key_curve_position_weights(dt, t, type); + key_curve_position_weights(dt, t, KeyInterpolationType(type)); interp_v3_v3v3v3v3(result->co, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); @@ -1153,12 +1153,12 @@ void psys_interpolate_particle( float temp[3]; if (dt > 0.999f) { - key_curve_position_weights(dt - 0.001f, t, type); + key_curve_position_weights(dt - 0.001f, t, KeyInterpolationType(type)); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); sub_v3_v3v3(result->vel, result->co, temp); } else { - key_curve_position_weights(dt + 0.001f, t, type); + key_curve_position_weights(dt + 0.001f, t, KeyInterpolationType(type)); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); sub_v3_v3v3(result->vel, temp, result->co); } diff --git a/source/blender/makesdna/DNA_key_types.h b/source/blender/makesdna/DNA_key_types.h index 4004238fe7c..bdf35ba6313 100644 --- a/source/blender/makesdna/DNA_key_types.h +++ b/source/blender/makesdna/DNA_key_types.h @@ -18,39 +18,45 @@ struct AnimData; struct Ipo; +/** + * The struct that holds the data for an individual Shape Key. Depending on which object owns the + * `Key`, the contained data type can vary (see `void *data;`). + */ typedef struct KeyBlock { struct KeyBlock *next, *prev; /** - * point in time (Key->type == KEY_NORMAL) only, - * for historic reasons this is relative to (Key->ctime / 100), + * A point in time used in case of `(Key::type == KEY_NORMAL)` only, + * for historic reasons this is relative to (Key::ctime / 100), * so this value increments by 0.1f per frame. */ float pos; - /** influence (typically [0 - 1] but can be more), `(Key->type == KEY_RELATIVE)` only. */ + /** Influence (typically [0 - 1] but can be more), `(Key::type == KEY_RELATIVE)` only. */ float curval; - /** Interpolation type `(Key->type == KEY_NORMAL)` only. */ + /** Interpolation type. Used for `(Key::type == KEY_NORMAL)` only (KeyInterpolationType). */ short type; char _pad1[2]; - /** relative == 0 means first key is reference, otherwise the index of Key->blocks */ + /** `relative == 0` means first key is reference, otherwise the index of Key::blocks. */ short relative; + /* KeyBlockFlag */ short flag; - /** total number if items in the keyblock (compare with mesh/curve verts to check we match) */ + /** Total number of items in the keyblock (compare with mesh/curve verts to check we match). */ int totelem; - /** for meshes only, match the unique number with the customdata layer */ + /** For meshes only, match the unique number with the customdata layer. */ int uid; - /** array of shape key values, size is `(Key->elemsize * KeyBlock->totelem)` */ + /** Array of shape key values, size is `(Key::elemsize * KeyBlock->totelem)`. + * E.g. meshes use float3. */ void *data; - /** MAX_NAME (unique name, user assigned) */ + /** MAX_NAME (unique name, user assigned). */ char name[64]; - /** MAX_VGROUP_NAME (optional vertex group), array gets allocated into 'weights' when set */ + /** MAX_VGROUP_NAME (optional vertex group), array gets allocated into 'weights' when set. */ char vgroup[64]; - /** ranges, for RNA and UI only to clamp 'curval' */ + /** Ranges, for RNA and UI only to clamp 'curval'. */ float slidermin; float slidermax; @@ -67,9 +73,9 @@ typedef struct Key { struct AnimData *adt; /** - * commonly called 'Basis', `(Key->type == KEY_RELATIVE)` only. - * Looks like this is _always_ 'key->block.first', - * perhaps later on it could be defined as some other KeyBlock - campbell + * Commonly called 'Basis', `(Key::type == KEY_RELATIVE)` only. + * Looks like this is _always_ 'key->block.first', + * perhaps later on it could be defined as some other KeyBlock - campbell. */ KeyBlock *refkey; @@ -82,21 +88,22 @@ typedef struct Key { int elemsize; char _pad[4]; - /** list of KeyBlock's */ + /** A list of KeyBlock's. */ ListBase block; - /** old animation system, deprecated for 2.5 */ + /** Old animation system, deprecated for 2.5. */ struct Ipo *ipo DNA_DEPRECATED; ID *from; - /** (totkey == BLI_listbase_count(&key->block)) */ + /** (totkey == BLI_listbase_count(&key->block)). */ int totkey; + /* ShapekeyContainerFlag */ short flag; - /** absolute or relative shape key */ + /** Absolute or relative shape key (ShapekeyContainerType). */ char type; char _pad2; - /** Only used when (Key->type == KEY_NORMAL), this value is used as a time slider, + /** Only used when (Key::type == KEY_NORMAL), this value is used as a time slider, * rather than using the scene's time, this value can be animated to give greater control */ float ctime; @@ -109,35 +116,35 @@ typedef struct Key { /* **************** KEY ********************* */ -/* Key->type: KeyBlocks are interpreted as... */ -enum { - /* Sequential positions over time (using KeyBlock->pos and Key->ctime) */ +/* Key::type: KeyBlocks are interpreted as... */ +typedef enum ShapekeyContainerType { + /* Sequential positions over time (using KeyBlock::pos and Key::ctime) */ KEY_NORMAL = 0, /* States to blend between (default) */ KEY_RELATIVE = 1, -}; +} ShapekeyContainerType; -/* Key->flag */ -enum { +/* Key::flag */ +typedef enum ShapekeyContainerFlag { KEY_DS_EXPAND = 1, -}; +} ShapekeyContainerFlag; -/* KeyBlock->type */ -enum { +/* The obvious name would be `KeyBlockType` but this enum is actually used in places outside of + * Shape Keys (NURBS, particles, etc.). */ +typedef enum KeyInterpolationType { KEY_LINEAR = 0, KEY_CARDINAL = 1, KEY_BSPLINE = 2, KEY_CATMULL_ROM = 3, -}; +} KeyInterpolationType; -/* KeyBlock->flag */ -enum { +typedef enum KeyBlockFlag { KEYBLOCK_MUTE = (1 << 0), KEYBLOCK_SEL = (1 << 1), KEYBLOCK_LOCKED = (1 << 2), KEYBLOCK_LOCKED_SHAPE = (1 << 3), -}; +} KeyBlockFlag; #define KEYELEM_FLOAT_LEN_COORD 3 diff --git a/source/blender/makesdna/DNA_lattice_types.h b/source/blender/makesdna/DNA_lattice_types.h index ecfbc4e5de9..a86db306196 100644 --- a/source/blender/makesdna/DNA_lattice_types.h +++ b/source/blender/makesdna/DNA_lattice_types.h @@ -46,6 +46,7 @@ typedef struct Lattice { short pntsu, pntsv, pntsw, flag; short opntsu, opntsv, opntsw; char _pad2[3]; + /* KeyInterpolationType */ char typeu, typev, typew; /** Active element index, unset with LT_ACTBP_NONE. */ int actbp;