diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-01-26 20:07:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-01-26 20:07:47 +0300 |
commit | 246bcf48ade22aefd06cb9e5c0dbd4e0f5e68f3c (patch) | |
tree | d52d6a4846e80c7a37d95417c978dbe55a4b2789 /source/blender/editors/object | |
parent | e308fe9632b990ab2616d5ecc8402c945e15de3d (diff) |
weight panel editing now supports mirroring
- use mirror when the option is enabled in editmode.
- fliped group names are used when they exist.
- only the setting that is edited will be applied to the mirrored verts group.
- copy value is applied to all mirrored verts of the selection.
- normalize normalizes all vgroups and mirrors.
utility functions defvert_sync and defvert_sync_mapped, similar to defvert_copy but does not remove existing groups and optionally creates groups as needed.
defvert_sync_mapped uses a an int array for mapping the flipped values.
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 71 |
1 files changed, 13 insertions, 58 deletions
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 990c609dc06..728f3214584 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -85,51 +85,6 @@ static Lattice *vgroup_edit_lattice(Object *ob) return NULL; } -/* check if deform vertex has defgroup index */ -MDeformWeight *ED_vgroup_weight_get(MDeformVert *dv, int defgroup) -{ - int i; - - if(!dv || defgroup<0) - return NULL; - - for(i=0; i<dv->totweight; i++) - if(dv->dw[i].def_nr == defgroup) - return dv->dw+i; - - return NULL; -} - -/* Ensures that mv has a deform weight entry for the specified defweight group */ -/* Note this function is mirrored in editmesh_tools.c, for use for editvertices */ -MDeformWeight *ED_vgroup_weight_verify(MDeformVert *dv, int defgroup) -{ - MDeformWeight *newdw; - - /* do this check always, this function is used to check for it */ - if(!dv || defgroup<0) - return NULL; - - newdw = ED_vgroup_weight_get(dv, defgroup); - if(newdw) - return newdw; - - newdw = MEM_callocN(sizeof(MDeformWeight)*(dv->totweight+1), "deformWeight"); - if(dv->dw) { - memcpy(newdw, dv->dw, sizeof(MDeformWeight)*dv->totweight); - MEM_freeN(dv->dw); - } - dv->dw=newdw; - - dv->dw[dv->totweight].weight=0.0f; - dv->dw[dv->totweight].def_nr=defgroup; - /* Group index */ - - dv->totweight++; - - return dv->dw+(dv->totweight-1); -} - bDeformGroup *ED_vgroup_add_name(Object *ob, char *name) { bDeformGroup *defgroup; @@ -569,11 +524,11 @@ static void vgroup_duplicate(Object *ob) for(i = 0; i < dvert_tot; i++) { dvert = dvert_array+i; - org = ED_vgroup_weight_get(dvert, idg); + org = defvert_find_index(dvert, idg); if(org) { float weight = org->weight; - /* ED_vgroup_weight_verify re-allocs org so need to store the weight first */ - cpy = ED_vgroup_weight_verify(dvert, icdg); + /* defvert_verify_index re-allocs org so need to store the weight first */ + cpy = defvert_verify_index(dvert, icdg); cpy->weight = weight; } } @@ -597,7 +552,7 @@ static void vgroup_normalize(Object *ob) for(i = 0; i < dvert_tot; i++) { dvert = dvert_array+i; - dw = ED_vgroup_weight_get(dvert, def_nr); + dw = defvert_find_index(dvert, def_nr); if(dw) { weight_max = MAX2(dw->weight, weight_max); } @@ -606,7 +561,7 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { dvert = dvert_array+i; - dw = ED_vgroup_weight_get(dvert, def_nr); + dw = defvert_find_index(dvert, def_nr); if(dw) { dw->weight /= weight_max; @@ -634,7 +589,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) for(i = 0; i < dvert_tot; i++) { dvert = dvert_array+i; - dw = ED_vgroup_weight_get(dvert, def_nr); + dw = defvert_find_index(dvert, def_nr); if(dw) { dw->weight = gain * (dw->weight + offset); @@ -745,9 +700,9 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) dvert = dvert_array+i; if(auto_assign) { - dw= ED_vgroup_weight_verify(dvert, def_nr); + dw= defvert_verify_index(dvert, def_nr); } else { - dw= ED_vgroup_weight_get(dvert, def_nr); + dw= defvert_find_index(dvert, def_nr); } if(dw) { @@ -820,7 +775,7 @@ static void vgroup_blend(Object *ob) if(em) dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT); else dvert= dvert_array+i2; - dw= ED_vgroup_weight_get(dvert, def_nr); + dw= defvert_find_index(dvert, def_nr); if(dw) { vg_weights[i1] += dw->weight; @@ -835,7 +790,7 @@ static void vgroup_blend(Object *ob) if(em) dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT); else dvert= dvert_array+i; - dw= ED_vgroup_weight_verify(dvert, def_nr); + dw= defvert_verify_index(dvert, def_nr); dw->weight= vg_weights[i] / (float)vg_users[i]; } @@ -863,7 +818,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) for(i = 0; i < dvert_tot; i++) { dvert = dvert_array+i; - dw= ED_vgroup_weight_get(dvert, def_nr); + dw= defvert_find_index(dvert, def_nr); if(dw) { if(dw->weight <= eul) @@ -923,7 +878,7 @@ void ED_vgroup_mirror(Object *ob, int mirror_weights, int flip_vgroups) if(!CustomData_has_layer(&em->vdata, CD_MDEFORMVERT)) return; - flip_map= defgroup_flip_map(ob); + flip_map= defgroup_flip_map(ob, 0); /* Go through the list of editverts and assign them */ for(eve=em->verts.first; eve; eve=eve->next){ @@ -1042,7 +997,7 @@ static void vgroup_delete_object_mode(Object *ob) for(i = 0; i < dvert_tot; i++) { dvert = dvert_array + i; if(dvert) { - if(ED_vgroup_weight_get(dvert, (ob->actdef-1))) + if(defvert_find_index(dvert, (ob->actdef-1))) ED_vgroup_vert_remove(ob, dg, i); } } |