diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2018-09-05 16:17:59 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2018-09-20 11:52:42 +0300 |
commit | 12788906113c4f2b304b368001bd2ef68c4dc6b8 (patch) | |
tree | 866371adf7cb11e65b3809ec2fb9358799d2656e | |
parent | 1789c1e90df373293338dadd4f7140c9995c456f (diff) |
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
-rw-r--r-- | source/blender/blenkernel/BKE_blender_version.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_key.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 68 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 211 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 70 | ||||
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 79 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_key_types.h | 11 |
8 files changed, 288 insertions, 162 deletions
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 1b31688d461..6d41abe1a14 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -28,7 +28,7 @@ * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 280 -#define BLENDER_SUBVERSION 22 +#define BLENDER_SUBVERSION 23 /* Several breakages with 280, e.g. collections vs layers */ #define BLENDER_MINVERSION 280 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index bd787311ef4..73a6f5047b2 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -86,6 +86,7 @@ void BKE_keyblock_update_from_lattice(struct Lattice *lt, struct KeyBlock *kb void BKE_keyblock_convert_from_lattice(struct Lattice *lt, struct KeyBlock *kb); void BKE_keyblock_convert_to_lattice(struct KeyBlock *kb, struct Lattice *lt); +int BKE_keyblock_curve_element_count(struct ListBase *nurb); void BKE_keyblock_update_from_curve(struct Curve *cu, struct KeyBlock *kb, struct ListBase *nurb); void BKE_keyblock_convert_from_curve(struct Curve *cu, struct KeyBlock *kb, struct ListBase *nurb); void BKE_keyblock_convert_to_curve(struct KeyBlock *kb, struct Curve *cu, struct ListBase *nurb); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index a9e86087f42..8d6a7f97a4a 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -4657,18 +4657,18 @@ float (*BKE_curve_nurbs_keyVertexCos_get(ListBase *lb, float *key))[3] BezTriple *bezt = nu->bezt; for (i = 0; i < nu->pntsu; i++, bezt++) { - copy_v3_v3(co, key); co += 3; key += 3; - copy_v3_v3(co, key); co += 3; key += 3; - copy_v3_v3(co, key); co += 3; key += 3; - key += 3; /* skip tilt */ + copy_v3_v3(co, &key[0]); co += 3; + copy_v3_v3(co, &key[3]); co += 3; + copy_v3_v3(co, &key[6]); co += 3; + key += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { BPoint *bp = nu->bp; for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { - copy_v3_v3(co, key); co += 3; key += 3; - key++; /* skip tilt */ + copy_v3_v3(co, key); co += 3; + key += KEYELEM_FLOAT_LEN_BPOINT; } } } @@ -4686,18 +4686,18 @@ void BKE_curve_nurbs_keyVertexTilts_apply(ListBase *lb, float *key) BezTriple *bezt = nu->bezt; for (i = 0; i < nu->pntsu; i++, bezt++) { - key += 3 * 3; - bezt->alfa = *key; - key += 3; + bezt->alfa = key[9]; + bezt->radius = key[10]; + key += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { BPoint *bp = nu->bp; for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { - key += 3; - bp->alfa = *key; - key++; + bp->alfa = key[3]; + bp->radius = key[4]; + key += KEYELEM_FLOAT_LEN_BPOINT; } } } @@ -5167,8 +5167,29 @@ void BKE_curve_transform_ex( KeyBlock *kb; for (kb = cu->key->block.first; kb; kb = kb->next) { float *fp = kb->data; - for (i = kb->totelem; i--; fp += 3) { - mul_m4_v3(mat, fp); + int n = kb->totelem; + + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + for (i = nu->pntsu; i && (n -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; i--) { + mul_m4_v3(mat, &fp[0]); + mul_m4_v3(mat, &fp[3]); + mul_m4_v3(mat, &fp[6]); + if (do_props) { + fp[10] *= unit_scale; /* radius */ + } + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; + } + } + else { + for (i = nu->pntsu * nu->pntsv; i && (n -= KEYELEM_ELEM_LEN_BPOINT) >= 0; i--) { + mul_m4_v3(mat, fp); + if (do_props) { + fp[4] *= unit_scale; /* radius */ + } + fp += KEYELEM_FLOAT_LEN_BPOINT; + } + } } } } @@ -5212,8 +5233,23 @@ void BKE_curve_translate(Curve *cu, float offset[3], const bool do_keys) KeyBlock *kb; for (kb = cu->key->block.first; kb; kb = kb->next) { float *fp = kb->data; - for (i = kb->totelem; i--; fp += 3) { - add_v3_v3(fp, offset); + int n = kb->totelem; + + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + for (i = nu->pntsu; i && (n -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; i--) { + add_v3_v3(&fp[0], offset); + add_v3_v3(&fp[3], offset); + add_v3_v3(&fp[6], offset); + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; + } + } + else { + for (i = nu->pntsu * nu->pntsv; i && (n -= KEYELEM_ELEM_LEN_BPOINT) >= 0; i--) { + add_v3_v3(fp, offset); + fp += KEYELEM_FLOAT_LEN_BPOINT; + } + } } } } diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index c9051313481..fdcf38c7d41 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -813,7 +813,7 @@ static void curve_calc_modifiers_pre( ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData); ModifierData *pretessellatePoint; Curve *cu = ob->data; - int numVerts = 0; + int numElems = 0, numVerts = 0; const bool editmode = (!for_render && (cu->editnurb || cu->editfont)); ModifierApplyFlag app_flag = 0; float (*deformedVerts)[3] = NULL; @@ -839,15 +839,17 @@ static void curve_calc_modifiers_pre( required_mode |= eModifierMode_Editmode; if (!editmode) { - keyVerts = BKE_key_evaluate_object(ob, &numVerts); + keyVerts = BKE_key_evaluate_object(ob, &numElems); if (keyVerts) { + BLI_assert(BKE_keyblock_curve_element_count(nurb) == numElems); + /* split coords from key data, the latter also includes * tilts, which is passed through in the modifier stack. * this is also the reason curves do not use a virtual * shape key modifier yet. */ deformedVerts = BKE_curve_nurbs_keyVertexCos_get(nurb, keyVerts); - BLI_assert(BKE_nurbList_verts_count(nurb) == numVerts); + numVerts = BKE_nurbList_verts_count(nurb); } } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 32043c073e9..a01d78f5c36 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -125,31 +125,31 @@ Key *BKE_key_add(Main *bmain, ID *id) /* common function */ case ID_ME: el = key->elemstr; - el[0] = 3; + el[0] = KEYELEM_FLOAT_LEN_COORD; el[1] = IPO_FLOAT; el[2] = 0; - key->elemsize = 12; + key->elemsize = sizeof(float[KEYELEM_FLOAT_LEN_COORD]); break; case ID_LT: el = key->elemstr; - el[0] = 3; + el[0] = KEYELEM_FLOAT_LEN_COORD; el[1] = IPO_FLOAT; el[2] = 0; - key->elemsize = 12; + key->elemsize = sizeof(float[KEYELEM_FLOAT_LEN_COORD]); break; case ID_CU: el = key->elemstr; - el[0] = 4; + el[0] = KEYELEM_ELEM_SIZE_CURVE; el[1] = IPO_BPOINT; el[2] = 0; - key->elemsize = 16; + key->elemsize = sizeof(float[KEYELEM_ELEM_SIZE_CURVE]); break; @@ -546,31 +546,33 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char ** /* currently only the first value of 'ofs' may be set. */ -static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs) +static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs, int *step) { if (key->from == NULL) { return false; } + *step = 1; + switch (GS(key->from->name)) { case ID_ME: - *ofs = sizeof(float) * 3; + *ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]); *poinsize = *ofs; break; case ID_LT: - *ofs = sizeof(float) * 3; + *ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]); *poinsize = *ofs; break; case ID_CU: if (mode == KEY_MODE_BPOINT) { - *ofs = sizeof(float) * 4; - *poinsize = *ofs; + *ofs = sizeof(float[KEYELEM_FLOAT_LEN_BPOINT]); + *step = KEYELEM_ELEM_LEN_BPOINT; } else { - ofs[0] = sizeof(float) * 12; - *poinsize = (*ofs) / 3; + *ofs = sizeof(float[KEYELEM_FLOAT_LEN_BEZTRIPLE]); + *step = KEYELEM_ELEM_LEN_BEZTRIPLE; } - + *poinsize = sizeof(float[KEYELEM_ELEM_SIZE_CURVE]); break; default: BLI_assert(!"invalid 'key->from' ID type"); @@ -583,14 +585,14 @@ static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int static void cp_key(const int start, int end, const int tot, char *poin, Key *key, KeyBlock *actkb, KeyBlock *kb, float *weights, const int mode) { float ktot = 0.0, kd = 0.0; - int elemsize, poinsize = 0, a, *ofsp, ofs[32], flagflo = 0; + int elemsize, poinsize = 0, a, step, *ofsp, ofs[32], flagflo = 0; char *k1, *kref, *freek1, *freekref; char *cp, elemstr[8]; /* currently always 0, in future key_pointer_size may assign */ ofs[1] = 0; - if (!key_pointer_size(key, mode, &poinsize, &ofs[0])) + if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) return; if (end > tot) end = tot; @@ -634,10 +636,9 @@ static void cp_key(const int start, int end, const int tot, char *poin, Key *key } /* just do it here, not above! */ - elemsize = key->elemsize; - if (mode == KEY_MODE_BEZTRIPLE) elemsize *= 3; + elemsize = key->elemsize * step; - for (a = start; a < end; a++) { + for (a = start; a < end; a += step) { cp = key->elemstr; if (mode == KEY_MODE_BEZTRIPLE) cp = elemstr; @@ -648,20 +649,20 @@ static void cp_key(const int start, int end, const int tot, char *poin, Key *key switch (cp[1]) { case IPO_FLOAT: if (weights) { - memcpy(poin, kref, sizeof(float) * 3); + memcpy(poin, kref, sizeof(float[KEYELEM_FLOAT_LEN_COORD])); if (*weights != 0.0f) - rel_flerp(cp[0], (float *)poin, (float *)kref, (float *)k1, *weights); + rel_flerp(KEYELEM_FLOAT_LEN_COORD, (float *)poin, (float *)kref, (float *)k1, *weights); weights++; } else { - memcpy(poin, k1, sizeof(float) * 3); + memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_COORD])); } break; case IPO_BPOINT: - memcpy(poin, k1, sizeof(float) * 4); + memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_BPOINT])); break; case IPO_BEZTRIPLE: - memcpy(poin, k1, sizeof(float) * 12); + memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_BEZTRIPLE])); break; default: /* should never happen */ @@ -688,10 +689,6 @@ static void cp_key(const int start, int end, const int tot, char *poin, Key *key k1 += elemsize; kref += elemsize; } - - if (mode == KEY_MODE_BEZTRIPLE) { - a += 2; - } } if (freek1) MEM_freeN(freek1); @@ -705,7 +702,7 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) { if (nu->bp) { - step = nu->pntsu * nu->pntsv; + step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; a1 = max_ii(a, start); a2 = min_ii(a + step, end); @@ -713,7 +710,7 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const if (a1 < a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BPOINT); } else if (nu->bezt) { - step = 3 * nu->pntsu; + step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; /* exception because keys prefer to work with complete blocks */ a1 = max_ii(a, start); @@ -732,14 +729,14 @@ static void key_evaluate_relative( float **per_keyblock_weights, const int mode) { KeyBlock *kb; - int *ofsp, ofs[3], elemsize, b; + int *ofsp, ofs[3], elemsize, b, step; char *cp, *poin, *reffrom, *from, elemstr[8]; int poinsize, keyblock_index; /* currently always 0, in future key_pointer_size may assign */ ofs[1] = 0; - if (!key_pointer_size(key, mode, &poinsize, &ofs[0])) + if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) return; if (end > tot) end = tot; @@ -750,8 +747,7 @@ static void key_evaluate_relative( elemstr[2] = 0; /* just here, not above! */ - elemsize = key->elemsize; - if (mode == KEY_MODE_BEZTRIPLE) elemsize *= 3; + elemsize = key->elemsize * step; /* step 1 init */ cp_key(start, end, tot, basispoin, key, actkb, key->refkey, NULL, mode); @@ -780,7 +776,7 @@ static void key_evaluate_relative( reffrom += key->elemsize * start; // key elemsize yes! from += key->elemsize * start; - for (b = start; b < end; b++) { + for (b = start; b < end; b += step) { weight = weights ? (*weights * icuval) : icuval; @@ -793,13 +789,13 @@ static void key_evaluate_relative( switch (cp[1]) { case IPO_FLOAT: - rel_flerp(3, (float *)poin, (float *)reffrom, (float *)from, weight); + rel_flerp(KEYELEM_FLOAT_LEN_COORD, (float *)poin, (float *)reffrom, (float *)from, weight); break; case IPO_BPOINT: - rel_flerp(4, (float *)poin, (float *)reffrom, (float *)from, weight); + rel_flerp(KEYELEM_FLOAT_LEN_BPOINT, (float *)poin, (float *)reffrom, (float *)from, weight); break; case IPO_BEZTRIPLE: - rel_flerp(12, (float *)poin, (float *)reffrom, (float *)from, weight); + rel_flerp(KEYELEM_FLOAT_LEN_BEZTRIPLE, (float *)poin, (float *)reffrom, (float *)from, weight); break; default: /* should never happen */ @@ -818,7 +814,6 @@ static void key_evaluate_relative( reffrom += elemsize; from += elemsize; - if (mode == KEY_MODE_BEZTRIPLE) b += 2; if (weights) weights++; } @@ -834,7 +829,7 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key { float k1tot = 0.0, k2tot = 0.0, k3tot = 0.0, k4tot = 0.0; float k1d = 0.0, k2d = 0.0, k3d = 0.0, k4d = 0.0; - int a, ofs[32], *ofsp; + int a, step, ofs[32], *ofsp; int flagdo = 15, flagflo = 0, elemsize, poinsize = 0; char *k1, *k2, *k3, *k4, *freek1, *freek2, *freek3, *freek4; char *cp, elemstr[8]; @@ -842,7 +837,7 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key /* currently always 0, in future key_pointer_size may assign */ ofs[1] = 0; - if (!key_pointer_size(key, mode, &poinsize, &ofs[0])) + if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) return; if (end > tot) end = tot; @@ -960,11 +955,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key elemstr[2] = 0; /* only here, not above! */ - elemsize = key->elemsize; - if (mode == KEY_MODE_BEZTRIPLE) elemsize *= 3; - - for (a = start; a < end; a++) { + elemsize = key->elemsize * step; + for (a = start; a < end; a += step) { cp = key->elemstr; if (mode == KEY_MODE_BEZTRIPLE) cp = elemstr; @@ -974,13 +967,13 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key switch (cp[1]) { case IPO_FLOAT: - flerp(3, (float *)poin, (float *)k1, (float *)k2, (float *)k3, (float *)k4, t); + flerp(KEYELEM_FLOAT_LEN_COORD, (float *)poin, (float *)k1, (float *)k2, (float *)k3, (float *)k4, t); break; case IPO_BPOINT: - flerp(4, (float *)poin, (float *)k1, (float *)k2, (float *)k3, (float *)k4, t); + flerp(KEYELEM_FLOAT_LEN_BPOINT, (float *)poin, (float *)k1, (float *)k2, (float *)k3, (float *)k4, t); break; case IPO_BEZTRIPLE: - flerp(12, (void *)poin, (void *)k1, (void *)k2, (void *)k3, (void *)k4, t); + flerp(KEYELEM_FLOAT_LEN_BEZTRIPLE, (void *)poin, (void *)k1, (void *)k2, (void *)k3, (void *)k4, t); break; default: /* should never happen */ @@ -1045,8 +1038,6 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k4 += elemsize; } } - - if (mode == KEY_MODE_BEZTRIPLE) a += 2; } if (freek1) MEM_freeN(freek1); @@ -1207,11 +1198,11 @@ static void do_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) { if (nu->bp) { - step = nu->pntsu * nu->pntsv; + step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BPOINT); } else if (nu->bezt) { - step = 3 * nu->pntsu; + step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BEZTRIPLE); } else { @@ -1227,11 +1218,11 @@ static void do_rel_cu_key(Curve *cu, Key *key, KeyBlock *actkb, char *out, const for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) { if (nu->bp) { - step = nu->pntsu * nu->pntsv; + step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; key_evaluate_relative(a, a + step, tot, out, key, actkb, NULL, KEY_MODE_BPOINT); } else if (nu->bezt) { - step = 3 * nu->pntsu; + step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; key_evaluate_relative(a, a + step, tot, out, key, actkb, NULL, KEY_MODE_BEZTRIPLE); } else { @@ -1311,28 +1302,19 @@ float *BKE_key_evaluate_object_ex( Mesh *me = ob->data; tot = me->totvert; - size = tot * 3 * sizeof(float); + size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]); } else if (ob->type == OB_LATTICE) { Lattice *lt = ob->data; tot = lt->pntsu * lt->pntsv * lt->pntsw; - size = tot * 3 * sizeof(float); + size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]); } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = ob->data; - Nurb *nu; - for (nu = cu->nurb.first; nu; nu = nu->next) { - if (nu->bezt) { - tot += 3 * nu->pntsu; - size += nu->pntsu * 12 * sizeof(float); - } - else if (nu->bp) { - tot += nu->pntsu * nu->pntsv; - size += nu->pntsu * nu->pntsv * 12 * sizeof(float); - } - } + tot = BKE_keyblock_curve_element_count(&cu->nurb); + size = tot * sizeof(float[KEYELEM_ELEM_SIZE_CURVE]); } /* if nothing to interpolate, cancel */ @@ -1668,6 +1650,24 @@ void BKE_keyblock_convert_to_lattice(KeyBlock *kb, Lattice *lt) } /************************* Curve ************************/ + +int BKE_keyblock_curve_element_count(ListBase *nurb) +{ + Nurb *nu; + int tot = 0; + + nu = nurb->first; + while (nu) { + if (nu->bezt) + tot += KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; + else if (nu->bp) + tot += KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; + + nu = nu->next; + } + return tot; +} + void BKE_keyblock_update_from_curve(Curve *UNUSED(cu), KeyBlock *kb, ListBase *nurb) { Nurb *nu; @@ -1677,7 +1677,7 @@ void BKE_keyblock_update_from_curve(Curve *UNUSED(cu), KeyBlock *kb, ListBase *n int a, tot; /* count */ - BLI_assert(BKE_nurbList_verts_count(nurb) == kb->totelem); + BLI_assert(BKE_keyblock_curve_element_count(nurb) == kb->totelem); tot = kb->totelem; if (tot == 0) return; @@ -1686,21 +1686,20 @@ void BKE_keyblock_update_from_curve(Curve *UNUSED(cu), KeyBlock *kb, ListBase *n for (nu = nurb->first; nu; nu = nu->next) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { - int i; - - for (i = 0; i < 3; i++, fp += 3) { - copy_v3_v3(fp, bezt->vec[i]); + for (int i = 0; i < 3; i++) { + copy_v3_v3(&fp[i * 3], bezt->vec[i]); } - fp[0] = bezt->alfa; - fp += 3; /* alphas */ + fp[9] = bezt->alfa; + fp[10] = bezt->radius; + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { - - ; - for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, fp += 4, bp++) { + for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++) { copy_v3_v3(fp, bp->vec); fp[3] = bp->alfa; + fp[4] = bp->radius; + fp += KEYELEM_FLOAT_LEN_BPOINT; } } } @@ -1711,7 +1710,7 @@ void BKE_keyblock_convert_from_curve(Curve *cu, KeyBlock *kb, ListBase *nurb) int tot; /* count */ - tot = BKE_nurbList_verts_count(nurb); + tot = BKE_keyblock_curve_element_count(nurb); if (tot == 0) return; MEM_SAFE_FREE(kb->data); @@ -1730,26 +1729,27 @@ void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nu const float *fp; int a, tot; - tot = BKE_nurbList_verts_count(nurb); + tot = BKE_keyblock_curve_element_count(nurb); tot = min_ii(kb->totelem, tot); fp = kb->data; for (nu = nurb->first; nu && tot > 0; nu = nu->next) { if (nu->bezt) { - for (a = nu->pntsu, bezt = nu->bezt; a && tot > 0; a--, tot -= 3, bezt++) { - int i; - - for (i = 0; i < 3; i++, fp += 3) { - copy_v3_v3(bezt->vec[i], fp); + for (a = nu->pntsu, bezt = nu->bezt; a && (tot -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; a--, bezt++) { + for (int i = 0; i < 3; i++) { + copy_v3_v3(bezt->vec[i], &fp[i * 3]); } - bezt->alfa = fp[0]; - fp += 3; /* alphas */ + bezt->alfa = fp[9]; + bezt->radius = fp[10]; + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { - for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a && tot; a--, tot--, fp += 4, bp++) { + for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a && (tot -= KEYELEM_ELEM_LEN_BPOINT) >= 0; a--, bp++) { copy_v3_v3(bp->vec, fp); bp->alfa = fp[3]; + bp->radius = fp[4]; + fp += KEYELEM_FLOAT_LEN_BPOINT; } } } @@ -1878,7 +1878,7 @@ void BKE_keyblock_update_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos) } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = ob->data; - BLI_assert(BKE_nurbList_verts_count(&cu->nurb) == kb->totelem); + BLI_assert(BKE_keyblock_curve_element_count(&cu->nurb) == kb->totelem); } else if (ob->type == OB_MESH) { Mesh *me = ob->data; @@ -1907,17 +1907,16 @@ void BKE_keyblock_update_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos) for (nu = cu->nurb.first; nu; nu = nu->next) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { - int i; - - for (i = 0; i < 3; i++, fp += 3, co++) { - copy_v3_v3(fp, *co); + for (int i = 0; i < 3; i++, co++) { + copy_v3_v3(&fp[i * 3], *co); } - fp += 3; /* skip alphas */ + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { - for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, fp += 4, co++) { + for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, co++) { copy_v3_v3(fp, *co); + fp += KEYELEM_FLOAT_LEN_BPOINT; } } } @@ -1944,7 +1943,7 @@ void BKE_keyblock_convert_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = (Curve *)ob->data; elemsize = cu->key->elemsize; - tot = BKE_nurbList_verts_count(&cu->nurb); + tot = BKE_keyblock_curve_element_count(&cu->nurb); } if (tot == 0) return; @@ -1994,17 +1993,16 @@ float (*BKE_keyblock_convert_to_vertcos(Object *ob, KeyBlock *kb))[3] for (nu = cu->nurb.first; nu; nu = nu->next) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { - int i; - - for (i = 0; i < 3; i++, fp += 3, co++) { - copy_v3_v3(*co, fp); + for (int i = 0; i < 3; i++, co++) { + copy_v3_v3(*co, &fp[i * 3]); } - fp += 3; /* skip alphas */ + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { - for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, fp += 4, co++) { + for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, co++) { copy_v3_v3(*co, fp); + fp += KEYELEM_FLOAT_LEN_BPOINT; } } } @@ -2033,17 +2031,16 @@ void BKE_keyblock_update_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3]) for (nu = cu->nurb.first; nu; nu = nu->next) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { - int i; - - for (i = 0; i < 3; i++, fp += 3, ofs++) { - add_v3_v3(fp, *ofs); + for (int i = 0; i < 3; i++, ofs++) { + add_v3_v3(&fp[i * 3], *ofs); } - fp += 3; /* skip alphas */ + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { - for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, fp += 4, ofs++) { + for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, ofs++) { add_v3_v3(fp, *ofs); + fp += KEYELEM_FLOAT_LEN_BPOINT; } } } diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index cbf0fa8bb83..9174b7bf588 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -58,6 +58,8 @@ #include "DNA_genfile.h" #include "DNA_gpencil_types.h" #include "DNA_workspace_types.h" +#include "DNA_key_types.h" +#include "DNA_curve_types.h" #include "BKE_collection.h" #include "BKE_constraint.h" @@ -82,6 +84,7 @@ #include "BKE_paint.h" #include "BKE_object.h" #include "BKE_cloth.h" +#include "BKE_key.h" #include "BLT_translation.h" @@ -789,6 +792,73 @@ void do_versions_after_linking_280(Main *bmain) } #endif + /* Update Curve object Shape Key data layout to include the Radius property */ + if (!MAIN_VERSION_ATLEAST(bmain, 280, 23)) { + for (Curve *cu = bmain->curve.first; cu; cu = cu->id.next) { + if (!cu->key || cu->key->elemsize != sizeof(float[4])) + continue; + + cu->key->elemstr[0] = 3; /*KEYELEM_ELEM_SIZE_CURVE*/ + cu->key->elemsize = sizeof(float[3]); + + int new_count = BKE_keyblock_curve_element_count(&cu->nurb); + + for (KeyBlock *block = cu->key->block.first; block; block = block->next) { + int old_count = block->totelem; + void *old_data = block->data; + + if (!old_data || old_count <= 0) + continue; + + block->totelem = new_count; + block->data = MEM_callocN(sizeof(float[3]) * new_count, __func__); + + float *oldptr = old_data; + float (*newptr)[3] = block->data; + + for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->bezt) { + BezTriple *bezt = nu->bezt; + + for (int a = 0; a < nu->pntsu; a++, bezt++) { + if ((old_count -= 3) < 0) { + memcpy(newptr, bezt->vec, sizeof(float[3*3])); + newptr[3][0] = bezt->alfa; + } + else { + memcpy(newptr, oldptr, sizeof(float[3*4])); + } + + newptr[3][1] = bezt->radius; + + oldptr += 3*4; + newptr += 4; /*KEYELEM_ELEM_LEN_BEZTRIPLE*/ + } + } + else if (nu->bp) { + BPoint *bp = nu->bp; + + for (int a = 0; a < nu->pntsu*nu->pntsv; a++, bp++) { + if (--old_count < 0) { + copy_v3_v3(newptr[0], bp->vec); + newptr[1][0] = bp->alfa; + } + else { + memcpy(newptr, oldptr, sizeof(float[4])); + } + + newptr[1][1] = bp->radius; + + oldptr += 4; + newptr += 2; /*KEYELEM_ELEM_LEN_BPOINT*/ + } + } + } + + MEM_freeN(old_data); + } + } + } } /* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already. diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 6b3c2643ad7..ff0fdbe8f2a 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -165,7 +165,7 @@ static void init_editNurb_keyIndex(EditNurb *editnurb, ListBase *origBase) *origbezt_cpy = *origbezt; keyIndex = init_cvKeyIndex(origbezt_cpy, key_index, nu_index, pt_index, vertex_index); BLI_ghash_insert(gh, bezt, keyIndex); - key_index += 12; + key_index += KEYELEM_FLOAT_LEN_BEZTRIPLE; vertex_index += 3; bezt++; origbezt++; @@ -185,7 +185,7 @@ static void init_editNurb_keyIndex(EditNurb *editnurb, ListBase *origBase) *origbp_cpy = *origbp; keyIndex = init_cvKeyIndex(origbp_cpy, key_index, nu_index, pt_index, vertex_index); BLI_ghash_insert(gh, bp, keyIndex); - key_index += 4; + key_index += KEYELEM_FLOAT_LEN_BPOINT; bp++; origbp++; pt_index++; @@ -468,13 +468,13 @@ static void switch_keys_direction(Curve *cu, Nurb *actnu) if (getKeyIndexOrig_bezt(editnurb, bezt)) { swap_v3_v3(fp, fp + 6); *(fp + 9) = -*(fp + 9); - fp += 12; + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } bezt++; } } else { - fp += a * 12; + fp += a * KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { @@ -484,13 +484,13 @@ static void switch_keys_direction(Curve *cu, Nurb *actnu) while (a--) { if (getKeyIndexOrig_bp(editnurb, bp)) { *(fp + 3) = -*(fp + 3); - fp += 4; + fp += KEYELEM_FLOAT_LEN_BPOINT; } bp++; } } else { - fp += a * 4; + fp += a * KEYELEM_FLOAT_LEN_BPOINT; } } @@ -541,12 +541,14 @@ static void key_to_bezt(float *key, BezTriple *basebezt, BezTriple *bezt) memcpy(bezt, basebezt, sizeof(BezTriple)); memcpy(bezt->vec, key, sizeof(float) * 9); bezt->alfa = key[9]; + bezt->radius = key[10]; } static void bezt_to_key(BezTriple *bezt, float *key) { memcpy(key, bezt->vec, sizeof(float) * 9); key[9] = bezt->alfa; + key[10] = bezt->radius; } static void calc_keyHandles(ListBase *nurb, float *key) @@ -569,7 +571,7 @@ static void calc_keyHandles(ListBase *nurb, float *key) if (nu->flagu & CU_NURB_CYCLIC) { prevp = bezt + (a - 1); - prevfp = fp + (12 * (a - 1)); + prevfp = fp + (KEYELEM_FLOAT_LEN_BEZTRIPLE * (a - 1)); } else { prevp = NULL; @@ -577,7 +579,7 @@ static void calc_keyHandles(ListBase *nurb, float *key) } nextp = bezt + 1; - nextfp = fp + 12; + nextfp = fp + KEYELEM_FLOAT_LEN_BEZTRIPLE; while (a--) { key_to_bezt(fp, bezt, &cur); @@ -602,16 +604,16 @@ static void calc_keyHandles(ListBase *nurb, float *key) } else { nextp++; - nextfp += 12; + nextfp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } bezt++; - fp += 12; + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } } else { a = nu->pntsu * nu->pntsv; - fp += a * 4; + fp += a * KEYELEM_FLOAT_LEN_BPOINT; } nu = nu->next; @@ -631,7 +633,7 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) BezTriple *bezt, *oldbezt; BPoint *bp, *oldbp; Nurb *nu, *newnu; - int totvert = BKE_nurbList_verts_count(&editnurb->nurbs); + int totvert = BKE_keyblock_curve_element_count(&editnurb->nurbs); float (*ofs)[3] = NULL; float *oldkey, *newkey, *ofp; @@ -671,7 +673,9 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) sub_v3_v3v3(ofs[i], bezt->vec[j], oldbezt->vec[j]); i++; } - ofs[i++][0] = bezt->alfa - oldbezt->alfa; + ofs[i][0] = bezt->alfa - oldbezt->alfa; + ofs[i][1] = bezt->radius - oldbezt->radius; + i++; } else { i += 4; @@ -687,6 +691,7 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) if (oldbp) { sub_v3_v3v3(ofs[i], bp->vec, oldbp->vec); ofs[i + 1][0] = bp->alfa - oldbp->alfa; + ofs[i + 1][1] = bp->radius - oldbp->radius; } i += 2; bp++; @@ -723,22 +728,23 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) int j; oldbezt = getKeyIndexOrig_bezt(editnurb, bezt); - for (j = 0; j < 3; ++j, ++i) { - copy_v3_v3(fp, bezt->vec[j]); + for (j = 0; j < 3; j++, i++) { + copy_v3_v3(&fp[j * 3], bezt->vec[j]); if (restore && oldbezt) { copy_v3_v3(newbezt->vec[j], oldbezt->vec[j]); } - - fp += 3; } - fp[0] = bezt->alfa; + fp[9] = bezt->alfa; + fp[10] = bezt->radius; if (restore && oldbezt) { newbezt->alfa = oldbezt->alfa; + newbezt->radius = oldbezt->radius; } - fp += 3; ++i; /* alphas */ + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; + i++; bezt++; newbezt++; } @@ -753,13 +759,15 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) copy_v3_v3(fp, bp->vec); fp[3] = bp->alfa; + fp[4] = bp->radius; if (restore && oldbp) { copy_v3_v3(newbp->vec, oldbp->vec); newbp->alfa = oldbp->alfa; + newbp->radius = oldbp->radius; } - fp += 4; + fp += KEYELEM_FLOAT_LEN_BPOINT; bp++; newbp++; i += 2; @@ -781,34 +789,33 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) int j; curofp = ofp + index; - for (j = 0; j < 3; ++j, ++i) { - copy_v3_v3(fp, curofp); + for (j = 0; j < 3; j++, i++) { + copy_v3_v3(&fp[j * 3], &curofp[j * 3]); if (apply_offset) { - add_v3_v3(fp, ofs[i]); + add_v3_v3(&fp[j * 3], ofs[i]); } - - fp += 3; curofp += 3; } - fp[0] = curofp[0]; + fp[9] = curofp[9]; + fp[10] = curofp[10]; if (apply_offset) { /* apply alfa offsets */ - add_v3_v3(fp, ofs[i]); + add_v3_v3(fp + 9, ofs[i]); i++; } - fp += 3; /* alphas */ + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } else { int j; - for (j = 0; j < 3; ++j, ++i) { - copy_v3_v3(fp, bezt->vec[j]); - fp += 3; + for (j = 0; j < 3; j++, i++) { + copy_v3_v3(&fp[j * 3], bezt->vec[j]); } - fp[0] = bezt->alfa; + fp[9] = bezt->alfa; + fp[10] = bezt->radius; - fp += 3; /* alphas */ + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } bezt++; } @@ -823,18 +830,20 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) curofp = ofp + index; copy_v3_v3(fp, curofp); fp[3] = curofp[3]; + fp[4] = curofp[4]; if (apply_offset) { add_v3_v3(fp, ofs[i]); - fp[3] += ofs[i + 1][0]; + add_v3_v3(&fp[3], ofs[i + 1]); } } else { copy_v3_v3(fp, bp->vec); fp[3] = bp->alfa; + fp[4] = bp->radius; } - fp += 4; + fp += KEYELEM_FLOAT_LEN_BPOINT; bp++; i += 2; } diff --git a/source/blender/makesdna/DNA_key_types.h b/source/blender/makesdna/DNA_key_types.h index 2b097092bc4..fa58f8f8abd 100644 --- a/source/blender/makesdna/DNA_key_types.h +++ b/source/blender/makesdna/DNA_key_types.h @@ -135,4 +135,15 @@ enum { KEYBLOCK_LOCKED = (1 << 2) }; +#define KEYELEM_FLOAT_LEN_COORD 3 + +/* Curve key data layout constants */ +#define KEYELEM_ELEM_SIZE_CURVE 3 + +#define KEYELEM_ELEM_LEN_BPOINT 2 +#define KEYELEM_FLOAT_LEN_BPOINT (KEYELEM_ELEM_LEN_BPOINT * KEYELEM_ELEM_SIZE_CURVE) + +#define KEYELEM_ELEM_LEN_BEZTRIPLE 4 +#define KEYELEM_FLOAT_LEN_BEZTRIPLE (KEYELEM_ELEM_LEN_BEZTRIPLE * KEYELEM_ELEM_SIZE_CURVE) + #endif /* __DNA_KEY_TYPES_H__ */ |