[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45544] trunk/blender/source/blender: bmesh shape key conversion on exiting editmode.

Campbell Barton ideasman42 at gmail.com
Wed Apr 11 17:24:14 CEST 2012


Revision: 45544
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45544
Author:   campbellbarton
Date:     2012-04-11 15:24:13 +0000 (Wed, 11 Apr 2012)
Log Message:
-----------
bmesh shape key conversion on exiting editmode.

there were 2 blocks of code (both calculating the offset array), now move the fallback method into the main key conversions block.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_mesh_conv.c
    trunk/blender/source/blender/makesdna/DNA_key_types.h

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_mesh_conv.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_mesh_conv.c	2012-04-11 14:59:35 UTC (rev 45543)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_mesh_conv.c	2012-04-11 15:24:13 UTC (rev 45544)
@@ -498,8 +498,7 @@
 	BMLoop *l;
 	BMFace *f;
 	BMIter iter, liter;
-	int i, j, *keyi, ototvert;
-	int use_old_key_code_fallback = FALSE;
+	int i, j, ototvert;
 
 	ototvert = me->totvert;
 
@@ -766,12 +765,16 @@
 
 
 		for (currkey = me->key->block.first; currkey; currkey = currkey->next) {
+			int apply_offset = (ofs && (currkey != actkey) && (bm->shapenr - 1 == currkey->relative));
+			int *keyi;
+			float (*ofs_pt)[3] = ofs;
+			float *fp;
+
 			j = bm_to_mesh_shape_layer_index_from_kb(bm, currkey);
 
 			if (j != -1) {
-				int apply_offset = (ofs && (currkey != actkey) && (bm->shapenr - 1 == currkey->relative));
-				float *fp, *co;
-				float (*ofs_pt)[3] = ofs;
+				/* new bmesh conversion method */
+				float *co;
 
 				if (currkey->data)
 					MEM_freeN(currkey->data);
@@ -806,91 +809,58 @@
 			else {
 				/* if we didn't find a shapekey, tag the block to be reconstructed
 				 * via the old method below */
-				currkey->flag |= KEYBLOCK_MISSING;
-				use_old_key_code_fallback = TRUE;
-			}
-		}
 
-		if (ofs) MEM_freeN(ofs);
-	}
+				/* old method of reconstructing keys via vertice's original key indices,
+				 * currently used if the new method above fails (which is theoretically
+				 * possible in certain cases of undo) */
 
-	/* XXX, code below is from trunk and a duplicate functionality
-	 * to the block above.
-	 * We should use one or the other, having both means we have to maintain
-	 * both and keep them working the same way which is a hassle - campbell */
+				float *newkey, *oldkey;
 
-	/* old method of reconstructing keys via vertice's original key indices,
-	 * currently used if the new method above fails (which is theoretically
-	 * possible in certain cases of undo) */
-	if (me->key && use_old_key_code_fallback) {
-		float *fp, *newkey, *oldkey;
-		KeyBlock *currkey;
-		KeyBlock *actkey = BLI_findlink(&me->key->block, bm->shapenr - 1);
+				printf("warning: had to hackishly reconstruct shape key \"%s\","
+				       " it may not be correct anymore.\n", currkey->name);
 
-		float (*ofs)[3] = NULL;
+				fp = newkey = MEM_callocN(me->key->elemsize * bm->totvert,  "currkey->data");
+				oldkey = currkey->data;
 
-		/* editing the base key should update others */
-		if (me->key->type == KEY_RELATIVE && oldverts) {
-			ofs = bm_to_mesh_shape_basis_offset(me, bm); /* may be NULL */
-		}
+				mvert = me->mvert;
+				BM_ITER(eve, &iter, bm, BM_VERTS_OF_MESH, NULL) {
+					keyi = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_SHAPE_KEYINDEX);
 
-		/* Lets reorder the key data so that things line up roughly
-		 * with the way things were before editmode */
-		for (currkey = me->key->block.first; currkey; currkey = currkey->next) {
-			int apply_offset = (ofs && (currkey != actkey) && (bm->shapenr - 1 == currkey->relative));
-
-			if (!(currkey->flag & KEYBLOCK_MISSING)) {
-				currkey = currkey->next;
-				continue;
-			}
-
-			printf("warning: had to hackishly reconstruct shape key \"%s\","
-			       " it may not be correct anymore.\n", currkey->name);
-
-			currkey->flag &= ~KEYBLOCK_MISSING;
-
-			fp = newkey = MEM_callocN(me->key->elemsize * bm->totvert,  "currkey->data");
-			oldkey = currkey->data;
-
-			eve = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL);
-
-			mvert = me->mvert;
-			BM_ITER_INDEX(eve, &iter, bm, BM_VERTS_OF_MESH, NULL, i) {
-				keyi = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_SHAPE_KEYINDEX);
-
-				if (keyi && *keyi != ORIGINDEX_NONE && *keyi < currkey->totelem) { /* valid old vertex */
-					if (currkey == actkey) {
-						if (actkey == me->key->refkey) {
-							copy_v3_v3(fp, mvert->co);
+					if (keyi && *keyi != ORIGINDEX_NONE && *keyi < currkey->totelem) { /* valid old vertex */
+						if (currkey == actkey) {
+							if (actkey == me->key->refkey) {
+								copy_v3_v3(fp, mvert->co);
+							}
+							else {
+								copy_v3_v3(fp, mvert->co);
+								if (oldverts) {
+									copy_v3_v3(mvert->co, oldverts[*keyi].co);
+								}
+							}
 						}
 						else {
-							copy_v3_v3(fp, mvert->co);
-							if (oldverts) {
-								copy_v3_v3(mvert->co, oldverts[*keyi].co);
+							if (oldkey) {
+								copy_v3_v3(fp, oldkey + 3 * *keyi);
 							}
 						}
 					}
 					else {
-						if (oldkey) {
-							copy_v3_v3(fp, oldkey + 3 * *keyi);
-						}
+						copy_v3_v3(fp, mvert->co);
 					}
-				}
-				else {
-					copy_v3_v3(fp, mvert->co);
-				}
 
-				/* propagate edited basis offsets to other shapes */
-				if (apply_offset) {
-					add_v3_v3(fp, ofs[i]);
-				}
+					/* propagate edited basis offsets to other shapes */
+					if (apply_offset) {
+						add_v3_v3(fp, *ofs_pt++);
+					}
 
-				fp += 3;
-				mvert++;
+					fp += 3;
+					mvert++;
+				}
+				currkey->totelem = bm->totvert;
+				if (currkey->data) MEM_freeN(currkey->data);
+				currkey->data = newkey;
+				/* end old compad code */
 			}
-			currkey->totelem = bm->totvert;
-			if (currkey->data) MEM_freeN(currkey->data);
-			currkey->data = newkey;
 		}
 
 		if (ofs) MEM_freeN(ofs);

Modified: trunk/blender/source/blender/makesdna/DNA_key_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_key_types.h	2012-04-11 14:59:35 UTC (rev 45543)
+++ trunk/blender/source/blender/makesdna/DNA_key_types.h	2012-04-11 15:24:13 UTC (rev 45544)
@@ -83,20 +83,28 @@
 /* **************** KEY ********************* */
 
 /* key->type */
-#define KEY_NORMAL      0
-#define KEY_RELATIVE    1
+enum {
+	KEY_NORMAL      = 0,
+	KEY_RELATIVE    = 1
+};
 
 /* key->flag */
-#define KEY_DS_EXPAND	1
+enum {
+	KEY_DS_EXPAND   = 1
+};
 
 /* keyblock->type */
-#define KEY_LINEAR      0
-#define KEY_CARDINAL    1
-#define KEY_BSPLINE     2
+enum {
+	KEY_LINEAR      = 0,
+	KEY_CARDINAL    = 1,
+	KEY_BSPLINE     = 2
+};
 
 /* keyblock->flag */
-#define KEYBLOCK_MUTE			(1<<0)
-#define KEYBLOCK_SEL			(1<<1)
-#define KEYBLOCK_LOCKED			(1<<2)
-#define KEYBLOCK_MISSING		(1<<3) /*temporary flag*/
-#endif
+enum {
+	KEYBLOCK_MUTE       = (1 << 0),
+	KEYBLOCK_SEL        = (1 << 1),
+	KEYBLOCK_LOCKED     = (1 << 2)
+};
+
+#endif /* __DNA_KEY_TYPES_H__  */




More information about the Bf-blender-cvs mailing list