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.
This commit is contained in:
Joshua Leung 2012-06-03 01:05:20 +00:00
parent 345a8d8170
commit 1d4213b2bc

@ -138,7 +138,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* if mode is to use selected armature bones, aggregate the bone groups */ /* if mode is to use selected armature bones, aggregate the bone groups */
if (mmd->mode == MOD_MASK_MODE_ARM) { /* --- using selected bones --- */ if (mmd->mode == MOD_MASK_MODE_ARM) { /* --- using selected bones --- */
GHash *vgroupHash;
Object *oba = mmd->ob_arm; Object *oba = mmd->ob_arm;
bPoseChannel *pchan; bPoseChannel *pchan;
bDeformGroup *def; bDeformGroup *def;
@ -147,9 +146,10 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
const int defbase_tot = BLI_countlist(&ob->defbase); const int defbase_tot = BLI_countlist(&ob->defbase);
/* check that there is armature object with bones to use, otherwise return original mesh */ /* 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; 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"); bone_select_array = MEM_mallocN(defbase_tot * sizeof(char), "mask array");
for (i = 0, def = ob->defbase.first; def; def = def->next, i++) { for (i = 0, def = ob->defbase.first; def; def = def->next, i++) {
@ -162,46 +162,40 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
bone_select_array[i] = FALSE; 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 no bones selected, free hashes and return original mesh */
if (bone_select_tot == 0) { if (bone_select_tot == 0) {
BLI_ghash_free(vgroupHash, NULL, NULL);
MEM_freeN(bone_select_array); MEM_freeN(bone_select_array);
return derivedData; return derivedData;
} }
/* repeat the previous check, but for dverts */ /* repeat the previous check, but for dverts */
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
if (dvert == NULL) { if (dvert == NULL) {
BLI_ghash_free(vgroupHash, NULL, NULL);
MEM_freeN(bone_select_array); MEM_freeN(bone_select_array);
return derivedData; 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"); 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++) { for (i = 0, dv = dvert; i < maxVerts; i++, dv++) {
MDeformWeight *dw = dv->dw; MDeformWeight *dw = dv->dw;
short found = 0;
int j; 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 (dw->def_nr < defbase_tot) {
if (bone_select_array[dw->def_nr]) { if (bone_select_array[dw->def_nr]) {
if (dw->weight != 0.0f) { if (dw->weight != 0.0f) {
found = TRUE;
break; break;
} }
} }
@ -211,11 +205,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* check if include vert in vertHash */ /* check if include vert in vertHash */
if (mmd->flag & MOD_MASK_INV) { if (mmd->flag & MOD_MASK_INV) {
/* if this vert is in the vgroup, don't include it in vertHash */ /* if this vert is in the vgroup, don't include it in vertHash */
if (dw) continue; if (found) continue;
} }
else { else {
/* if this vert isn't in the vgroup, don't include it in vertHash */ /* 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) */ /* add to ghash for verts (numVerts acts as counter for mapping) */
@ -224,7 +218,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
} }
/* free temp hashes */ /* free temp hashes */
BLI_ghash_free(vgroupHash, NULL, NULL);
MEM_freeN(bone_select_array); MEM_freeN(bone_select_array);
} }
else { /* --- Using Nominated VertexGroup only --- */ else { /* --- Using Nominated VertexGroup only --- */