[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47361] trunk/blender/source/blender/ modifiers/intern/MOD_mask.c: Mask Modifier - Bugfix and dead-code cleanup

Joshua Leung aligorith at gmail.com
Sun Jun 3 03:05:37 CEST 2012


Revision: 47361
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47361
Author:   aligorith
Date:     2012-06-03 01:05:20 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
Mask Modifier - Bugfix and dead-code cleanup

'Armature' mode for the Mask Modifier was not working at all anymore even when
the selection <-> depsgraph recalc issue was patched to work (this latter fix is
coming in another commit). It appears that this probably happened during one or
more of the refactors which may have taken place around here over the years
since I first introduced it.

This commit does two things:
* Removed the unused/redundant "vgroupHash"
* Fixed the incorrect assumption used for determining if the vertex actually
belonged to a vgroup corresponding to a selected bone.

Modified Paths:
--------------
    trunk/blender/source/blender/modifiers/intern/MOD_mask.c

Modified: trunk/blender/source/blender/modifiers/intern/MOD_mask.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_mask.c	2012-06-03 00:02:24 UTC (rev 47360)
+++ trunk/blender/source/blender/modifiers/intern/MOD_mask.c	2012-06-03 01:05:20 UTC (rev 47361)
@@ -138,7 +138,6 @@
 	
 	/* if mode is to use selected armature bones, aggregate the bone groups */
 	if (mmd->mode == MOD_MASK_MODE_ARM) { /* --- using selected bones --- */
-		GHash *vgroupHash;
 		Object *oba = mmd->ob_arm;
 		bPoseChannel *pchan;
 		bDeformGroup *def;
@@ -147,9 +146,10 @@
 		const int defbase_tot = BLI_countlist(&ob->defbase);
 		
 		/* check that there is armature object with bones to use, otherwise return original mesh */
-		if (ELEM3(NULL, mmd->ob_arm, mmd->ob_arm->pose, ob->defbase.first))
+		if (ELEM3(NULL, oba, oba->pose, ob->defbase.first))
 			return derivedData;
 		
+		/* determine whether each vertexgroup is associated with a selected bone or not */
 		bone_select_array = MEM_mallocN(defbase_tot * sizeof(char), "mask array");
 		
 		for (i = 0, def = ob->defbase.first; def; def = def->next, i++) {
@@ -162,46 +162,40 @@
 				bone_select_array[i] = FALSE;
 			}
 		}
-
-		/* hashes for finding mapping of:
-		 * - vgroups to indices -> vgroupHash  (string, int)
-		 * - bones to vgroup indices -> boneHash (index of vgroup, dummy)
-		 */
-		vgroupHash = BLI_ghash_str_new("mask vgroup gh");
 		
-		/* build mapping of names of vertex groups to indices */
-		for (i = 0, def = ob->defbase.first; def; def = def->next, i++) 
-			BLI_ghash_insert(vgroupHash, def->name, SET_INT_IN_POINTER(i));
-		
 		/* if no bones selected, free hashes and return original mesh */
 		if (bone_select_tot == 0) {
-			BLI_ghash_free(vgroupHash, NULL, NULL);
 			MEM_freeN(bone_select_array);
-			
 			return derivedData;
 		}
 		
 		/* repeat the previous check, but for dverts */
 		dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
 		if (dvert == NULL) {
-			BLI_ghash_free(vgroupHash, NULL, NULL);
 			MEM_freeN(bone_select_array);
-			
 			return derivedData;
 		}
 		
-		/* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
+		/* verthash gives mapping from original vertex indicies to the new indices (including selected matches only)
+		 * 	key=oldindex, value=newindex 
+		 */
 		vertHash = BLI_ghash_int_new("mask vert gh");
 		
-		/* add vertices which exist in vertexgroups into vertHash for filtering */
+		/* add vertices which exist in vertexgroups into vertHash for filtering 
+		 * - dv = for each vertex, what vertexgroups does it belong to
+		 * - dw = weight that vertex was assigned to a vertexgroup it belongs to
+		 */
 		for (i = 0, dv = dvert; i < maxVerts; i++, dv++) {
 			MDeformWeight *dw = dv->dw;
+			short found = 0;
 			int j;
 			
-			for (j = dv->totweight; j > 0; j--, dw++) {
+			/* check the groups that vertex is assigned to, and see if it was any use */
+			for (j = 0; j < dv->totweight; j++, dw++) {
 				if (dw->def_nr < defbase_tot) {
 					if (bone_select_array[dw->def_nr]) {
 						if (dw->weight != 0.0f) {
+							found = TRUE;
 							break;
 						}
 					}
@@ -211,11 +205,11 @@
 			/* check if include vert in vertHash */
 			if (mmd->flag & MOD_MASK_INV) {
 				/* if this vert is in the vgroup, don't include it in vertHash */
-				if (dw) continue;
+				if (found) continue;
 			}
 			else {
 				/* if this vert isn't in the vgroup, don't include it in vertHash */
-				if (!dw) continue;
+				if (!found) continue;
 			}
 			
 			/* add to ghash for verts (numVerts acts as counter for mapping) */
@@ -224,7 +218,6 @@
 		}
 		
 		/* free temp hashes */
-		BLI_ghash_free(vgroupHash, NULL, NULL);
 		MEM_freeN(bone_select_array);
 	}
 	else {  /* --- Using Nominated VertexGroup only --- */




More information about the Bf-blender-cvs mailing list