[Bf-blender-cvs] [12788906113] blender2.8: Put the Radius property of Curve points under shape key control.

Alexander Gavrilov noreply at git.blender.org
Thu Sep 20 10:53:26 CEST 2018


Commit: 12788906113c4f2b304b368001bd2ef68c4dc6b8
Author: Alexander Gavrilov
Date:   Wed Sep 5 16:17:59 2018 +0300
Branches: blender2.8
https://developer.blender.org/rB12788906113c4f2b304b368001bd2ef68c4dc6b8

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

===================================================================

M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/displist.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/makesdna/DNA_key_types.h

===================================================================

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]));
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list