diff options
author | Ton Roosendaal <ton@blender.org> | 2005-10-23 15:03:51 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2005-10-23 15:03:51 +0400 |
commit | 84f66424379734dfd40c1f2cd69ff2f6e8652333 (patch) | |
tree | 004f9cd89c1c2eccf63d81adb3f0feed1c7dc2d8 /source | |
parent | de655553ab1a88638ab0b3ecec7127812c49672b (diff) |
Another useful tool for efficient usage of WeightPaint:
Press SHIFT+LMB, and it shows a menu with all Vertex Groups the vertices of
the indicated face has, also allowing selection of Groups.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/src/vpaint.c | 174 |
1 files changed, 123 insertions, 51 deletions
diff --git a/source/blender/src/vpaint.c b/source/blender/src/vpaint.c index 0a4a0c7805c..4973b10d57d 100644 --- a/source/blender/src/vpaint.c +++ b/source/blender/src/vpaint.c @@ -813,12 +813,14 @@ static MDeformWeight *get_defweight(MDeformVert *dv, int defgroup) return NULL; } -/* used for 3d view */ -/* cant sample frontbuf, weight colors are interpolated too unpredictable */ -/* so we return the closest value to vertex, wich is actually correct anyway */ -void sample_wpaint() +/* used for 3d view, on active object, assumes me->dvert exists */ +/* if mode==1: */ +/* samples cursor location, and gives menu with vertex groups to activate */ +/* else */ +/* sets editbutvweight to the closest weight value to vertex */ +/* note: we cant sample frontbuf, weight colors are interpolated too unpredictable */ +static void sample_wpaint(int mode) { - extern float editbutvweight; Object *ob= OBACT; Mesh *me= get_mesh(ob); int index; @@ -829,57 +831,124 @@ void sample_wpaint() if(index && index<=me->totface) { MFace *mface; - DerivedMesh *dm; - MDeformWeight *dw; - float w1, w2, w3, w4, co[3], fac; - int needsFree; - - dm = mesh_get_derived_deform(ob, &needsFree); mface= ((MFace *)me->mface) + index-1; - /* calc 3 or 4 corner weights */ - dm->getVertCo(dm, mface->v1, co); - project_short_noclip(co, sco); - w1= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); - - dm->getVertCo(dm, mface->v2, co); - project_short_noclip(co, sco); - w2= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); - - dm->getVertCo(dm, mface->v3, co); - project_short_noclip(co, sco); - w3= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); - - if(mface->v4) { - dm->getVertCo(dm, mface->v4, co); - project_short_noclip(co, sco); - w4= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); - } - else w4= 1.0e10; - - fac= MIN4(w1, w2, w3, w4); - if(w1==fac) { - dw= get_defweight(me->dvert+mface->v1, ob->actdef-1); - if(dw) editbutvweight= dw->weight; else editbutvweight= 0.0f; - } - else if(w2==fac) { - dw= get_defweight(me->dvert+mface->v2, ob->actdef-1); - if(dw) editbutvweight= dw->weight; else editbutvweight= 0.0f; - } - else if(w3==fac) { - dw= get_defweight(me->dvert+mface->v3, ob->actdef-1); - if(dw) editbutvweight= dw->weight; else editbutvweight= 0.0f; + if(mode==1) { /* sampe which groups are in here */ + MDeformVert *dv; + int a, totgroup; + + totgroup= BLI_countlist(&ob->defbase); + if(totgroup) { + int totmenu=0; + int *groups=MEM_callocN(totgroup*sizeof(int), "groups"); + + dv= me->dvert+mface->v1; + for(a=0; a<dv->totweight; a++) { + if (dv->dw[a].def_nr<totgroup) + groups[dv->dw[a].def_nr]= 1; + } + dv= me->dvert+mface->v2; + for(a=0; a<dv->totweight; a++) { + if (dv->dw[a].def_nr<totgroup) + groups[dv->dw[a].def_nr]= 1; + } + dv= me->dvert+mface->v3; + for(a=0; a<dv->totweight; a++) { + if (dv->dw[a].def_nr<totgroup) + groups[dv->dw[a].def_nr]= 1; + } + if(mface->v4) { + dv= me->dvert+mface->v4; + for(a=0; a<dv->totweight; a++) { + if (dv->dw[a].def_nr<totgroup) + groups[dv->dw[a].def_nr]= 1; + } + } + for(a=0; a<totgroup; a++) + if(groups[a]) totmenu++; + + if(totmenu==0) { + notice("No Vertex Group Selected"); + } + else { + bDeformGroup *dg; + short val; + char item[40], *str= MEM_mallocN(40*totmenu+40, "menu"); + + strcpy(str, "Vertex Groups %t"); + for(a=0, dg=ob->defbase.first; dg && a<totgroup; a++, dg= dg->next) { + if(groups[a]) { + sprintf(item, "|%s %%x%d", dg->name, a); + strcat(str, item); + } + } + + val= pupmenu(str); + if(val>=0) { + ob->actdef= val+1; + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWOOPS, 0); + allqueue(REDRAWBUTSEDIT, 0); + } + MEM_freeN(str); + } + MEM_freeN(groups); + } + else notice("No Vertex Groups in Object"); } - else if(w4==fac) { + else { + DerivedMesh *dm; + MDeformWeight *dw; + extern float editbutvweight; + float w1, w2, w3, w4, co[3], fac; + int needsFree; + + dm = mesh_get_derived_deform(ob, &needsFree); + + /* calc 3 or 4 corner weights */ + dm->getVertCo(dm, mface->v1, co); + project_short_noclip(co, sco); + w1= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); + + dm->getVertCo(dm, mface->v2, co); + project_short_noclip(co, sco); + w2= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); + + dm->getVertCo(dm, mface->v3, co); + project_short_noclip(co, sco); + w3= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); + if(mface->v4) { - dw= get_defweight(me->dvert+mface->v4, ob->actdef-1); + dm->getVertCo(dm, mface->v4, co); + project_short_noclip(co, sco); + w4= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1])); + } + else w4= 1.0e10; + + fac= MIN4(w1, w2, w3, w4); + if(w1==fac) { + dw= get_defweight(me->dvert+mface->v1, ob->actdef-1); if(dw) editbutvweight= dw->weight; else editbutvweight= 0.0f; } - } - - if (needsFree) - dm->release(dm); + else if(w2==fac) { + dw= get_defweight(me->dvert+mface->v2, ob->actdef-1); + if(dw) editbutvweight= dw->weight; else editbutvweight= 0.0f; + } + else if(w3==fac) { + dw= get_defweight(me->dvert+mface->v3, ob->actdef-1); + if(dw) editbutvweight= dw->weight; else editbutvweight= 0.0f; + } + else if(w4==fac) { + if(mface->v4) { + dw= get_defweight(me->dvert+mface->v4, ob->actdef-1); + if(dw) editbutvweight= dw->weight; else editbutvweight= 0.0f; + } + } + if (needsFree) + dm->release(dm); + } } allqueue(REDRAWBUTSEDIT, 0); @@ -936,7 +1005,11 @@ void weight_paint(void) create_dverts(me); if(G.qual & LR_CTRLKEY) { - sample_wpaint(); + sample_wpaint(0); + return; + } + if(G.qual & LR_SHIFTKEY) { + sample_wpaint(1); return; } @@ -1172,7 +1245,6 @@ void weight_paint(void) if(ob->soft) ob->softflag |= OB_SB_REDO; allqueue(REDRAWVIEW3D, 0); - } void vertex_paint() |