From 179b9267a85a423edf19f92844470963332ac30d Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Mon, 23 May 2011 13:37:18 +0000 Subject: [PATCH 01/68] Creating GSoC 2011 radish branch. From 85febf4549e7274f5b96c030529ca15554109860 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 23 May 2011 17:26:14 +0000 Subject: [PATCH 02/68] --- source/blender/editors/sculpt_paint/paint_vertex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 692d33bd091..caed38384dc 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1326,6 +1326,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr) { + //Jason's test commit (I'll undo this afterwards) ToolSettings *ts= CTX_data_tool_settings(C); VPaint *wp= ts->wpaint; Brush *brush = paint_brush(&wp->paint); From ee9445041f54816fdab2bef93e46276808a10e44 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 23 May 2011 17:26:50 +0000 Subject: [PATCH 03/68] --- source/blender/editors/sculpt_paint/paint_vertex.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index caed38384dc..692d33bd091 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1326,7 +1326,6 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr) { - //Jason's test commit (I'll undo this afterwards) ToolSettings *ts= CTX_data_tool_settings(C); VPaint *wp= ts->wpaint; Brush *brush = paint_brush(&wp->paint); From 3cde378fead4b176e1fe3ef3cecfa8c2add2ddf3 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Fri, 27 May 2011 19:13:54 +0000 Subject: [PATCH 04/68] --- .../startup/bl_ui/properties_data_mesh.py | 5 +- .../editors/sculpt_paint/paint_vertex.c | 104 +++++++++++++++++- source/blender/makesdna/DNA_object_types.h | 2 + source/blender/makesrna/intern/rna_object.c | 5 + 4 files changed, 109 insertions(+), 7 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 7097988d25b..1aa5433190e 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -127,7 +127,8 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel): ob = context.object group = ob.vertex_groups.active - + + rows = 2 if group: rows = 5 @@ -136,6 +137,8 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel): row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows) col = row.column(align=True) + # Jason was here # + col.prop(group, "flag") col.operator("object.vertex_group_add", icon='ZOOMIN', text="") col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="") col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="") diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 692d33bd091..e9fa572bb9b 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -73,6 +73,7 @@ #include "BKE_object.h" #include "BKE_paint.h" + #include "WM_api.h" #include "WM_types.h" @@ -346,7 +347,6 @@ void vpaint_fill(Object *ob, unsigned int paintcol) DAG_id_tag_update(&me->id, 0); } - /* fills in the selected faces with the current weight and vertex group */ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) { @@ -362,7 +362,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) me= ob->data; if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return; - + selected= (me->editflag & ME_EDIT_PAINT_MASK); indexar= get_indexarray(me); @@ -1029,6 +1029,74 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } } +/*Jason was here +not sure where these prototypes belong at them moment +static char* gen_lck_flags(Object* ob); +static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw); + +gen_lck_flags gets the status of "flag" for each bDeformGroup in ob->defbase and returns an array containing them +*/ +static char* gen_lck_flags(Object* ob) +{ + char is_locked = 0; + int i, k; + int defcnt = BLI_countlist(&ob->defbase); + char *flags = MEM_mallocN(defcnt*sizeof(char), "defflags"); + bDeformGroup *defgroup = ob->defbase.first; + for(i = 0; i < defcnt && defgroup; i++) { + flags[i] = defgroup->flag; + defgroup = defgroup->next; + if(flags[i]) { + is_locked = 1; + } + } + if(is_locked){ + return flags; + } + return NULL; +} +/*Jason was here +this alters the weights in order to maintain the ratios to match with the change in weights of pnt_dw +*/ +static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw) +{ + int i, k, totvert, cnt; + float scaledown = 1.0f; + float neww = pnt_dw->weight; + int defgroup = pnt_dw->def_nr; + totvert = me->totvert; + pnt_dw->weight = oldw; + + if(oldw == 0 || neww == 0){ + return; + } + + for(i = 0; i < totvert; i++) { + cnt = (me->dvert+i)->totweight; + for(k = 0; k < cnt; k++) { + MDeformWeight *dw = ((me->dvert+i)->dw+k); + if(dw->def_nr == defgroup){ + dw->weight = neww * (dw->weight / oldw); + if(dw->weight > scaledown){ + scaledown = dw->weight; + } + break; + } + } + } + if(scaledown > 1.0f) { + for(i = 0; i < totvert; i++) { + cnt = (me->dvert+i)->totweight; + for(k = 0; k < cnt; k++) { + MDeformWeight *dw = ((me->dvert+i)->dw+k); + if(dw->def_nr == defgroup){ + dw->weight /= scaledown; + break; + } + } + } + } +} static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, float alpha, float paintweight, int flip, int vgroup_mirror, char *validmap) @@ -1037,6 +1105,10 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, MDeformWeight *dw, *uw; int vgroup= ob->actdef-1; + /* Jason was here */ + char *flags; + float oldw; + if(wp->flag & VP_ONLYVGROUP) { dw= defvert_find_index(me->dvert+index, vgroup); uw= defvert_find_index(wp->wpaint_prev+index, vgroup); @@ -1047,8 +1119,20 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } if(dw==NULL || uw==NULL) return; - + /* Jason was here */ + flags = gen_lck_flags(ob); + oldw = dw->weight; + wpaint_blend(wp, dw, uw, alpha, paintweight, flip); + + /* Jason was here */ + /* you are not allowed to go to or from zero if the group is locked */ + if(flags && flags[dw->def_nr]) { + if(oldw == 0 || dw->weight == 0){ + dw->weight = oldw; + } + } + do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ @@ -1065,6 +1149,13 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap); } } + /* Jason was here */ + if(flags){ + if(flags[dw->def_nr]) { + fix_weight_ratios(me, dw, oldw); + } + MEM_freeN(flags); + } } @@ -1229,7 +1320,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED struct WPaintData *wpd; Mesh *me; float mat[4][4], imat[4][4]; - + if(scene->obedit) return OPERATOR_CANCELLED; me= get_mesh(ob); @@ -1240,7 +1331,8 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED ED_vgroup_data_create(&me->id); WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); } - + + /* make mode data storage */ wpd= MEM_callocN(sizeof(struct WPaintData), "WPaintData"); paint_stroke_set_mode_data(stroke, wpd); @@ -1320,7 +1412,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED wpd->vgroup_mirror= actdef; } } - + return 1; } diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 54a885a0860..6938e3bc311 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -62,6 +62,8 @@ struct bGPdata; typedef struct bDeformGroup { struct bDeformGroup *next, *prev; char name[32]; + /* Jason was here: need this flag for locking weights */ + char flag, pad[7]; } bDeformGroup; #define MAX_VGROUP_NAME 32 diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 4407ca8ad4e..c6d1bfc22db 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1237,6 +1237,11 @@ static void rna_def_vertex_group(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Name", "Vertex group name"); RNA_def_struct_name_property(srna, prop); RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */ + /* Jason was here */ + prop= RNA_def_property(srna, "flag", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_ui_text(prop, "", "Maintain the relative weights for the group"); + RNA_def_property_boolean_sdna(prop, "bDeformGroup", "flag", 0); + RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */ prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED); RNA_def_property_clear_flag(prop, PROP_EDITABLE); From 09b5d512c81d0bc885711ba35554445d90a80bb6 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 30 May 2011 16:33:23 +0000 Subject: [PATCH 05/68] --- .../editors/sculpt_paint/paint_vertex.c | 117 +++++++++++++----- 1 file changed, 89 insertions(+), 28 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index e9fa572bb9b..7fb4764bfc9 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1028,15 +1028,74 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } } } +/* Jason was here +this function will handle normalize with locked groups +it assumes that the current ratios (of locked groups) +are the intended ratios. + +also, it does not attempt to force them to add up to 1, that would destroy intergroup weight ratios, +it simply makes the highest weight sum add up to one + +the Mesh is needed to change the ratios across the group +*/ +static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, char* map) +{ + float highestSum = 0.0f; + float currentSum; + int cnt; + int i, k; + int totvert = me->totvert; + MDeformVert dv; + + if(!map) { + return; + } + + for(i = 0; i < totvert; i++) { + dv = dvert[i]; + cnt = dv.totweight; + currentSum = 0.0f; + for(k = 0; k < cnt; k++) { + currentSum += (dv.dw+k)->weight; + } + if(highestSum < currentSum) { + highestSum = currentSum; + } + } + if(highestSum == 1.0f) { + return; + } + for(i = 0; i < totvert; i++) { + dv = dvert[i]; + cnt = dv.totweight; + + for(k = 0; k < cnt; k++) { + (dv.dw+k)->weight /= highestSum; + } + } +} +/* Jason was here */ +static char get_locked_flag(Object *ob, int vgroup) +{ + int i = 0; + bDeformGroup *defgroup = ob->defbase.first; + for(i = 0; i < vgroup && defgroup; i++) { + defgroup = defgroup->next; + } + return defgroup->flag; +} /*Jason was here not sure where these prototypes belong at them moment static char* gen_lck_flags(Object* ob); static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw); -gen_lck_flags gets the status of "flag" for each bDeformGroup in ob->defbase and returns an array containing them +gen_lck_flags gets the status of "flag" for each bDeformGroup +in ob->defbase and returns an array containing them + +But I didn't need all of them in one place yet, so I'm using get_locked_flag() */ -static char* gen_lck_flags(Object* ob) +/*static char* gen_lck_flags(Object* ob) { char is_locked = 0; int i, k; @@ -1054,7 +1113,7 @@ static char* gen_lck_flags(Object* ob) return flags; } return NULL; -} +}*/ /*Jason was here this alters the weights in order to maintain the ratios to match with the change in weights of pnt_dw */ @@ -1064,17 +1123,21 @@ static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw) float scaledown = 1.0f; float neww = pnt_dw->weight; int defgroup = pnt_dw->def_nr; + MDeformVert *dvert; + MDeformVert dv; + MDeformWeight *dw; totvert = me->totvert; pnt_dw->weight = oldw; if(oldw == 0 || neww == 0){ return; } - + dvert = me->dvert; for(i = 0; i < totvert; i++) { - cnt = (me->dvert+i)->totweight; + dv = dvert[i]; + cnt = dv.totweight; for(k = 0; k < cnt; k++) { - MDeformWeight *dw = ((me->dvert+i)->dw+k); + dw = dv.dw+k; if(dw->def_nr == defgroup){ dw->weight = neww * (dw->weight / oldw); if(dw->weight > scaledown){ @@ -1086,9 +1149,10 @@ static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw) } if(scaledown > 1.0f) { for(i = 0; i < totvert; i++) { - cnt = (me->dvert+i)->totweight; + dv = dvert[i]; + cnt = dv.totweight; for(k = 0; k < cnt; k++) { - MDeformWeight *dw = ((me->dvert+i)->dw+k); + dw = dv.dw+k; if(dw->def_nr == defgroup){ dw->weight /= scaledown; break; @@ -1106,7 +1170,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int vgroup= ob->actdef-1; /* Jason was here */ - char *flags; + char locked; float oldw; if(wp->flag & VP_ONLYVGROUP) { @@ -1120,21 +1184,18 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dw==NULL || uw==NULL) return; /* Jason was here */ - flags = gen_lck_flags(ob); + locked = get_locked_flag(ob, vgroup); oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, flip); /* Jason was here */ - /* you are not allowed to go to or from zero if the group is locked */ - if(flags && flags[dw->def_nr]) { - if(oldw == 0 || dw->weight == 0){ - dw->weight = oldw; - } + if(locked) { + fix_weight_ratios(me, dw, oldw); + do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + }else { + do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } - - do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); - if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); if(j>=0) { @@ -1143,19 +1204,19 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw= defvert_verify_index(me->dvert+j, vgroup_mirror); else uw= defvert_verify_index(me->dvert+j, vgroup); - - uw->weight= dw->weight; + /* Jason */ + oldw = uw->weight; - do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap); + uw->weight= dw->weight; + /* Jason */ + if(locked) { + fix_weight_ratios(me, uw, oldw); + do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + } else { + do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap); + } } } - /* Jason was here */ - if(flags){ - if(flags[dw->def_nr]) { - fix_weight_ratios(me, dw, oldw); - } - MEM_freeN(flags); - } } From 54d2034a2d869d287b64a30a04c7853fdccc0537 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 31 May 2011 00:52:02 +0000 Subject: [PATCH 06/68] paint_vertex.c Tweaked get_locked_flag() so 'i' wasn't initialized twice Fixed a problem in do_weight_paint_vertex() that involved accidentally auto normalizing a locked group incorrectly if you painted an unlocked group. --- .../editors/sculpt_paint/paint_vertex.c | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 7fb4764bfc9..acc80fcf2ea 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1077,12 +1077,27 @@ static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, cha /* Jason was here */ static char get_locked_flag(Object *ob, int vgroup) { - int i = 0; + int i; bDeformGroup *defgroup = ob->defbase.first; for(i = 0; i < vgroup && defgroup; i++) { defgroup = defgroup->next; } - return defgroup->flag; + if(defgroup) { + return defgroup->flag; + } + return 0; +} +/* Jason was here */ +static int locked_group_exists(Object *ob) +{ + bDeformGroup *defgroup = ob->defbase.first; + while(defgroup) { + if(defgroup->flag){ + return TRUE; + } + defgroup = defgroup->next; + } + return FALSE; } /*Jason was here @@ -1171,6 +1186,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason was here */ char locked; + int lge = 0; float oldw; if(wp->flag & VP_ONLYVGROUP) { @@ -1193,7 +1209,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(locked) { fix_weight_ratios(me, dw, oldw); do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); - }else { + } else if((lge = locked_group_exists(ob))) { + do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + } else { do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ @@ -1212,6 +1230,8 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(locked) { fix_weight_ratios(me, uw, oldw); do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + } else if(lge) { + do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); } else { do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap); } From 392bf56a974edf078f78a673fc8c18321c6889da Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 1 Jun 2011 15:45:09 +0000 Subject: [PATCH 07/68] Remembered to free memory in gen_lck_flags() when it returned NULL when there were no locks present. Changed the lock system to redistribute changes of unlocked groups to other unlocked groups instead of just maintaining ratios within locked groups. --- .../editors/sculpt_paint/paint_vertex.c | 144 ++++++++++++++---- 1 file changed, 117 insertions(+), 27 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index acc80fcf2ea..37649a57952 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1075,7 +1075,7 @@ static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, cha } } /* Jason was here */ -static char get_locked_flag(Object *ob, int vgroup) +/*static char get_locked_flag(Object *ob, int vgroup) { int i; bDeformGroup *defgroup = ob->defbase.first; @@ -1086,7 +1086,7 @@ static char get_locked_flag(Object *ob, int vgroup) return defgroup->flag; } return 0; -} +}*/ /* Jason was here */ static int locked_group_exists(Object *ob) { @@ -1099,40 +1099,53 @@ static int locked_group_exists(Object *ob) } return FALSE; } - +/* Jason was here */ +/* +See if the current deform group has a locked group +*/ +static char has_locked_group(MDeformVert *dvert, char *flags) +{ + int i; + for(i = 0; i < dvert->totweight; i++) { + if(flags[(dvert->dw+i)->def_nr]) { + return TRUE; + } + } + return FALSE; +} /*Jason was here -not sure where these prototypes belong at them moment +not sure where the prototypes belong at the moment static char* gen_lck_flags(Object* ob); -static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw); gen_lck_flags gets the status of "flag" for each bDeformGroup in ob->defbase and returns an array containing them - -But I didn't need all of them in one place yet, so I'm using get_locked_flag() */ -/*static char* gen_lck_flags(Object* ob) +static char* gen_lck_flags(Object* ob, int defcnt) { - char is_locked = 0; - int i, k; - int defcnt = BLI_countlist(&ob->defbase); + char is_locked = FALSE; + int i; + //int defcnt = BLI_countlist(&ob->defbase); char *flags = MEM_mallocN(defcnt*sizeof(char), "defflags"); bDeformGroup *defgroup = ob->defbase.first; for(i = 0; i < defcnt && defgroup; i++) { flags[i] = defgroup->flag; defgroup = defgroup->next; if(flags[i]) { - is_locked = 1; + is_locked = TRUE; } } if(is_locked){ return flags; } + // don't forget to free it + MEM_freeN(flags); return NULL; -}*/ +} /*Jason was here this alters the weights in order to maintain the ratios to match with the change in weights of pnt_dw +This was not the intended solution evidently */ -static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw) +/*static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw) { int i, k, totvert, cnt; float scaledown = 1.0f; @@ -1175,6 +1188,73 @@ static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw) } } } +}*/ +/* Jason was here */ +/* +The idea behind this function is to get the difference in weight for pnt_dw, +and to redistribute that weight to the unlocked groups +(if it has to, then it will put some/all of the change +back onto the original group) +*/ +static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw, float oldw, char* flags, int defcnt) +{ + int i; + float change_left = oldw - pnt_dw->weight; + float change; + char was_a_change; + int groups_left_that_can_change = 0; + char* change_status = MEM_mallocN(defcnt*sizeof(char), "defflags"); + MDeformWeight *dw; + //printf("start\n"); + for(i = 0; i < defcnt; i++) { + if(pnt_dw->def_nr == i) { + change_status[i] = FALSE; + } else { + change_status[i] = !flags[i]; + } + if(change_status[i]) { + groups_left_that_can_change++; + } + //printf("group %d, change status: %d flag: %d active?: %d\n", i, change_status[i], flags[i], pnt_dw->def_nr == i); + } + //printf("\n"); + if(groups_left_that_can_change > 0) { + do { + was_a_change = FALSE; + for(i = 0; i < dvert->totweight; i++) { + dw = (dvert->dw+i); + if(!change_status[dw->def_nr]) { + continue; + } + + change = change_left/groups_left_that_can_change; + + dw->weight += change; + change_left -= change; + //printf("group %d, change: %f weight: %f groups left: %d\n", dw->def_nr, change, dw->weight, groups_left_that_can_change); + + if(dw->weight >= 1.0f) { + + change_left += dw->weight-1.0f; + dw->weight = 1.0f; + groups_left_that_can_change--; + change_status[dw->def_nr] = FALSE; + + }else if(dw->weight <= 0.0f) { + + change_left += dw->weight; + dw->weight = 0.0f; + groups_left_that_can_change--; + change_status[dw->def_nr] = FALSE; + } + was_a_change = TRUE; + } + } while(groups_left_that_can_change > 0 && change_left != 0.0f && was_a_change); + } + // add any remaining change back to the original weight + pnt_dw->weight += change_left; + MEM_freeN(change_status); + //printf("done\n"); } static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, float alpha, float paintweight, int flip, @@ -1185,9 +1265,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int vgroup= ob->actdef-1; /* Jason was here */ - char locked; - int lge = 0; + char* flags; float oldw; + int defcnt; if(wp->flag & VP_ONLYVGROUP) { dw= defvert_find_index(me->dvert+index, vgroup); @@ -1200,17 +1280,20 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dw==NULL || uw==NULL) return; /* Jason was here */ - locked = get_locked_flag(ob, vgroup); + flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase)); oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, flip); /* Jason was here */ - if(locked) { - fix_weight_ratios(me, dw, oldw); - do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); - } else if((lge = locked_group_exists(ob))) { - do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + if(flags && has_locked_group(me->dvert+index, flags)) { + if(flags[dw->def_nr]) { + // cannot change locked groups! + dw->weight = oldw; + } else { + redistribute_weight_change(me->dvert+index, dw, oldw, flags, defcnt); + do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + } } else { do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } @@ -1227,16 +1310,23 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw->weight= dw->weight; /* Jason */ - if(locked) { - fix_weight_ratios(me, uw, oldw); - do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); - } else if(lge) { - do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + if(flags && has_locked_group(me->dvert+j, flags)) { + if(flags[uw->def_nr]) { + // cannot change locked groups! + uw->weight = oldw; + } else { + redistribute_weight_change(me->dvert+j, uw, oldw, flags, defcnt); + do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + } } else { do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap); } } } + /* Jason */ + if(flags) { + MEM_freeN(flags); + } } From ca6929bbe753a929ebb73f3f02665a7761022a67 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 1 Jun 2011 17:04:32 +0000 Subject: [PATCH 08/68] I've begun treating unlocked misc vertex groups differently than unlocked bone groups- unlocked misc vertex groups should no longer have any involvement in the redistribution of weights. I may need a better auto normalize solution, however, because the weights can become 0 with enough division. --- .../editors/sculpt_paint/paint_vertex.c | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 37649a57952..8f03b6051bf 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1037,6 +1037,9 @@ also, it does not attempt to force them to add up to 1, that would destroy inter it simply makes the highest weight sum add up to one the Mesh is needed to change the ratios across the group + +I need to resolve a precision error issue, however: +dividing can cause the weights to drop to 0 */ static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, char* map) { @@ -1056,7 +1059,10 @@ static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, cha cnt = dv.totweight; currentSum = 0.0f; for(k = 0; k < cnt; k++) { - currentSum += (dv.dw+k)->weight; + if(map[dv.dw->def_nr]) { + //printf("group %d considered\n", dv.dw->def_nr); + currentSum += (dv.dw+k)->weight; + } } if(highestSum < currentSum) { highestSum = currentSum; @@ -1070,7 +1076,9 @@ static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, cha cnt = dv.totweight; for(k = 0; k < cnt; k++) { - (dv.dw+k)->weight /= highestSum; + if(map[dv.dw->def_nr]) { + (dv.dw+k)->weight /= highestSum; + } } } } @@ -1107,7 +1115,7 @@ static char has_locked_group(MDeformVert *dvert, char *flags) { int i; for(i = 0; i < dvert->totweight; i++) { - if(flags[(dvert->dw+i)->def_nr]) { + if(flags[(dvert->dw+i)->def_nr] && (dvert->dw+i)->weight > 0.0f) { return TRUE; } } @@ -1196,7 +1204,7 @@ and to redistribute that weight to the unlocked groups (if it has to, then it will put some/all of the change back onto the original group) */ -static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw, float oldw, char* flags, int defcnt) +static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw, float oldw, char* flags, int defcnt, char *map) { int i; float change_left = oldw - pnt_dw->weight; @@ -1207,7 +1215,7 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw MDeformWeight *dw; //printf("start\n"); for(i = 0; i < defcnt; i++) { - if(pnt_dw->def_nr == i) { + if(pnt_dw->def_nr == i || !map[i]) { change_status[i] = FALSE; } else { change_status[i] = !flags[i]; @@ -1256,6 +1264,24 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw MEM_freeN(change_status); //printf("done\n"); } +/* Jason */ +static void check_locks_and_normalize(Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups) +{ + if(flags && has_locked_group(me->dvert+index, flags)) { + if(flags[dw->def_nr]) { + // cannot change locked groups! + dw->weight = oldw; + } else if(bone_groups[dw->def_nr]) { + redistribute_weight_change(me->dvert+index, dw, oldw, flags, defcnt, bone_groups); + do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + } + } else { + do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); + } +} +// Jason +static char *wpaint_make_validmap(Object *ob); + static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, float alpha, float paintweight, int flip, int vgroup_mirror, char *validmap) @@ -1266,8 +1292,14 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason was here */ char* flags; + char* bone_groups; float oldw; int defcnt; + if(validmap) { + bone_groups = validmap; + }else { + bone_groups = wpaint_make_validmap(ob); + } if(wp->flag & VP_ONLYVGROUP) { dw= defvert_find_index(me->dvert+index, vgroup); @@ -1286,17 +1318,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, wpaint_blend(wp, dw, uw, alpha, paintweight, flip); /* Jason was here */ - if(flags && has_locked_group(me->dvert+index, flags)) { - if(flags[dw->def_nr]) { - // cannot change locked groups! - dw->weight = oldw; - } else { - redistribute_weight_change(me->dvert+index, dw, oldw, flags, defcnt); - do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); - } - } else { - do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); - } + check_locks_and_normalize(me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); if(j>=0) { @@ -1310,23 +1332,16 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw->weight= dw->weight; /* Jason */ - if(flags && has_locked_group(me->dvert+j, flags)) { - if(flags[uw->def_nr]) { - // cannot change locked groups! - uw->weight = oldw; - } else { - redistribute_weight_change(me->dvert+j, uw, oldw, flags, defcnt); - do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); - } - } else { - do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap); - } + check_locks_and_normalize(me, j, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups); } } /* Jason */ if(flags) { MEM_freeN(flags); } + if(!validmap) { + MEM_freeN(bone_groups); + } } From d7758d77eedc9b08d326d30ecd603565fd70bb5e Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 1 Jun 2011 19:21:36 +0000 Subject: [PATCH 09/68] Fixed the redistribute_weight_change() function so that it spreads the change evenly and cannot /0. --- source/blender/editors/sculpt_paint/paint_vertex.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 8f03b6051bf..4910cdc42fe 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1211,6 +1211,8 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw float change; char was_a_change; int groups_left_that_can_change = 0; + // make sure there is no case for division by 0, and make the redistribution the same per loop. + int groups_currently_left; char* change_status = MEM_mallocN(defcnt*sizeof(char), "defflags"); MDeformWeight *dw; //printf("start\n"); @@ -1227,6 +1229,7 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw } //printf("\n"); if(groups_left_that_can_change > 0) { + groups_currently_left = groups_left_that_can_change; do { was_a_change = FALSE; for(i = 0; i < dvert->totweight; i++) { @@ -1245,18 +1248,19 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw change_left += dw->weight-1.0f; dw->weight = 1.0f; - groups_left_that_can_change--; + groups_currently_left--; change_status[dw->def_nr] = FALSE; }else if(dw->weight <= 0.0f) { change_left += dw->weight; dw->weight = 0.0f; - groups_left_that_can_change--; + groups_currently_left--; change_status[dw->def_nr] = FALSE; } was_a_change = TRUE; } + groups_left_that_can_change = groups_currently_left; } while(groups_left_that_can_change > 0 && change_left != 0.0f && was_a_change); } // add any remaining change back to the original weight From 8038dcf91df81be8c7073509067169b60fa2680c Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 2 Jun 2011 14:15:07 +0000 Subject: [PATCH 10/68] My earlier custom auto normalize is no longer necessary to maintain inner group ratios (since the system changed) --- source/blender/editors/sculpt_paint/paint_vertex.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 4910cdc42fe..6c1de59a0c2 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1041,7 +1041,7 @@ the Mesh is needed to change the ratios across the group I need to resolve a precision error issue, however: dividing can cause the weights to drop to 0 */ -static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, char* map) +/*static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, char* map) { float highestSum = 0.0f; float currentSum; @@ -1081,7 +1081,7 @@ static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, cha } } } -} +}*/ /* Jason was here */ /*static char get_locked_flag(Object *ob, int vgroup) { @@ -1096,7 +1096,7 @@ static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, cha return 0; }*/ /* Jason was here */ -static int locked_group_exists(Object *ob) +/*static int locked_group_exists(Object *ob) { bDeformGroup *defgroup = ob->defbase.first; while(defgroup) { @@ -1106,7 +1106,7 @@ static int locked_group_exists(Object *ob) defgroup = defgroup->next; } return FALSE; -} +}*/ /* Jason was here */ /* See if the current deform group has a locked group @@ -1277,11 +1277,11 @@ static void check_locks_and_normalize(Mesh *me, int index, int vgroup, MDeformWe dw->weight = oldw; } else if(bone_groups[dw->def_nr]) { redistribute_weight_change(me->dvert+index, dw, oldw, flags, defcnt, bone_groups); - do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + //do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);//do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); } - } else { + } //else if(bone_groups[dw->def_nr]) // should it be disabled for the active group if it is not a bone group do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); - } + } // Jason static char *wpaint_make_validmap(Object *ob); From 8684d99e6186f06f85080d62ea8c7f47f861e594 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 2 Jun 2011 17:28:04 +0000 Subject: [PATCH 11/68] Made misc vgroups unable to change bone groups' weights when auto normalize is active Added buttons for locking all vgroups, unlocking all vgroups, and inverting the locks of all vgroups --- .../startup/bl_ui/properties_data_mesh.py | 7 ++ source/blender/editors/object/object_intern.h | 5 + source/blender/editors/object/object_ops.c | 5 + source/blender/editors/object/object_vgroup.c | 108 +++++++++++++++++- .../editors/sculpt_paint/paint_vertex.c | 9 +- 5 files changed, 128 insertions(+), 6 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 1aa5433190e..888ba55be3d 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -139,6 +139,7 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel): col = row.column(align=True) # Jason was here # col.prop(group, "flag") + col.operator("object.vertex_group_add", icon='ZOOMIN', text="") col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="") col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="") @@ -149,6 +150,12 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel): if group: row = layout.row() row.prop(group, "name") + #Jason was here + row = layout.row() + sub = row.row(align=True) + sub.operator("object.vertex_group_lock_all", text="Lock All") + sub.operator("object.vertex_group_invert_locks", text="Invert Locks") + sub.operator("object.vertex_group_unlock_all", text="Unlock All") if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0: row = layout.row() diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 801880f0f32..1d3d0a311e0 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -199,6 +199,11 @@ void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); +/* Jason was here */ +void OBJECT_OT_vertex_group_lock_all(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_invert_locks(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_unlock_all(struct wmOperatorType *ot); + void OBJECT_OT_vertex_group_invert(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_blend(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_clean(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index ff9b13379a2..c9e6004510c 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -173,6 +173,11 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); + /* Jason was here */ + WM_operatortype_append(OBJECT_OT_vertex_group_invert_locks); + WM_operatortype_append(OBJECT_OT_vertex_group_lock_all); + WM_operatortype_append(OBJECT_OT_vertex_group_unlock_all); + WM_operatortype_append(OBJECT_OT_vertex_group_invert); WM_operatortype_append(OBJECT_OT_vertex_group_levels); WM_operatortype_append(OBJECT_OT_vertex_group_blend); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 53562caf1b5..bc598a5b8e4 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -829,7 +829,33 @@ static void vgroup_normalize_all(Object *ob, int lock_active) if (dvert_array) MEM_freeN(dvert_array); } - +/* Jason was here */ +static void vgroup_invert_locks(Object *ob) +{ + bDeformGroup *dg = ob->defbase.first; + while(dg) { + dg->flag = !dg->flag; + dg = dg->next; + } +} +/* Jason was here */ +static void vgroup_lock_all(Object *ob) +{ + bDeformGroup *dg = ob->defbase.first; + while(dg) { + dg->flag = TRUE; + dg = dg->next; + } +} +/* Jason was here */ +static void vgroup_unlock_all(Object *ob) +{ + bDeformGroup *dg = ob->defbase.first; + while(dg) { + dg->flag = FALSE; + dg = dg->next; + } +} static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) { @@ -1746,7 +1772,87 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active", "Keep the values of the active group while normalizing others."); } +/* Jason was here */ +static int vertex_group_invert_locks_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + vgroup_invert_locks(ob); + // not sure what these 3 do yet! + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} +/* Jason was here */ +void OBJECT_OT_vertex_group_invert_locks(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Invert All Vertex Group Locks"; + ot->idname= "OBJECT_OT_vertex_group_invert_locks"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_invert_locks_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} +/* Jason was here */ +static int vertex_group_lock_all_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + + vgroup_lock_all(ob); + // not sure what these 3 do yet! + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} +/* Jason was here */ +void OBJECT_OT_vertex_group_lock_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Turn on all Vertex Group Locks"; + ot->idname= "OBJECT_OT_vertex_group_lock_all"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_lock_all_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} +/* Jason was here */ +static int vertex_group_unlock_all_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + + vgroup_unlock_all(ob); + // not sure what these 3 do yet! + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} +/* Jason was here */ +void OBJECT_OT_vertex_group_unlock_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Turn off all Vertex Group Locks"; + ot->idname= "OBJECT_OT_vertex_group_unlock_all"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_unlock_all_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} static int vertex_group_invert_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 6c1de59a0c2..ecd09975355 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1230,6 +1230,7 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw //printf("\n"); if(groups_left_that_can_change > 0) { groups_currently_left = groups_left_that_can_change; + change = change_left/groups_left_that_can_change; do { was_a_change = FALSE; for(i = 0; i < dvert->totweight; i++) { @@ -1238,12 +1239,9 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw continue; } - change = change_left/groups_left_that_can_change; - dw->weight += change; change_left -= change; //printf("group %d, change: %f weight: %f groups left: %d\n", dw->def_nr, change, dw->weight, groups_left_that_can_change); - if(dw->weight >= 1.0f) { change_left += dw->weight-1.0f; @@ -1277,10 +1275,11 @@ static void check_locks_and_normalize(Mesh *me, int index, int vgroup, MDeformWe dw->weight = oldw; } else if(bone_groups[dw->def_nr]) { redistribute_weight_change(me->dvert+index, dw, oldw, flags, defcnt, bone_groups); - //do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);//do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);//do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); } - } //else if(bone_groups[dw->def_nr]) // should it be disabled for the active group if it is not a bone group + } else if(bone_groups[dw->def_nr]) {// disable auto normalize if the active group is not a bone group do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); + } } // Jason From 23737357ff789a5ccbe8d72bd6c2db4c9d7b6db5 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Fri, 3 Jun 2011 16:08:03 +0000 Subject: [PATCH 12/68] Added a hard coded check box to the vertex group list items in interface/interface_templates.c list_item_row() Made my 3 new buttons only appear in weight paint mode when there are vertex groups present in properties_data_mesh.py I took the now redundant check box out of properties_data_mesh.py I took out unnecessary code (resulting from copy/paste) from my lock all, unlock all, and invert all functions of object/object_vgroup.c (and I got rid of a new line in paint_vertex.c :) ) --- .../scripts/startup/bl_ui/properties_data_mesh.py | 15 ++++++++------- .../editors/interface/interface_templates.c | 6 ++++++ source/blender/editors/object/object_vgroup.c | 12 ------------ .../blender/editors/sculpt_paint/paint_vertex.c | 1 - 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 888ba55be3d..74270b156d6 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -137,8 +137,8 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel): row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows) col = row.column(align=True) - # Jason was here # - col.prop(group, "flag") + # Jason was here, this was replaced by hardcoded list view checkboxes. # + #col.prop(group, "flag") col.operator("object.vertex_group_add", icon='ZOOMIN', text="") col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="") @@ -151,11 +151,12 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel): row = layout.row() row.prop(group, "name") #Jason was here - row = layout.row() - sub = row.row(align=True) - sub.operator("object.vertex_group_lock_all", text="Lock All") - sub.operator("object.vertex_group_invert_locks", text="Invert Locks") - sub.operator("object.vertex_group_unlock_all", text="Unlock All") + if ob.mode == 'WEIGHT_PAINT' and len(ob.vertex_groups) > 0: + row = layout.row() + sub = row.row(align=True) + sub.operator("object.vertex_group_lock_all", text="Lock All") + sub.operator("object.vertex_group_invert_locks", text="Invert Locks") + sub.operator("object.vertex_group_unlock_all", text="Unlock All") if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0: row = layout.row() diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index af5a69da653..4d048540e07 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2118,6 +2118,12 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe //uiItemR(row, itemptr, "mute", 0, "", ICON_MUTE_IPO_OFF); uiBlockSetEmboss(block, UI_EMBOSS); } + /* Jason was here: I need the RNA struct for vertex groups */ + else if(RNA_struct_is_a(itemptr->type, &RNA_VertexGroup)) { + uiItemL(sub, name, icon); + uiBlockSetEmboss(block, UI_EMBOSS); + uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "flag", 0, 0, 0, 0, 0, NULL); + } else uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */ diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index bc598a5b8e4..8e19b2985ab 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1778,10 +1778,6 @@ static int vertex_group_invert_locks_exec(bContext *C, wmOperator *op) Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; vgroup_invert_locks(ob); - // not sure what these 3 do yet! - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); return OPERATOR_FINISHED; } @@ -1805,10 +1801,6 @@ static int vertex_group_lock_all_exec(bContext *C, wmOperator *op) Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; vgroup_lock_all(ob); - // not sure what these 3 do yet! - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); return OPERATOR_FINISHED; } @@ -1832,10 +1824,6 @@ static int vertex_group_unlock_all_exec(bContext *C, wmOperator *op) Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; vgroup_unlock_all(ob); - // not sure what these 3 do yet! - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index ecd09975355..4793b5687d1 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1280,7 +1280,6 @@ static void check_locks_and_normalize(Mesh *me, int index, int vgroup, MDeformWe } else if(bone_groups[dw->def_nr]) {// disable auto normalize if the active group is not a bone group do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } - } // Jason static char *wpaint_make_validmap(Object *ob); From 70895a6789488806b647686464716381ab40ad4c Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 7 Jun 2011 17:59:38 +0000 Subject: [PATCH 13/68] editarmature.c and paint_vertex.c I added the first version of multi-bone selection for faster, temporary locking/unlocking; right now, if multiple bones are selected, the selection is considered unlocked, despite any vgroup checkbox status. Every other group is considered locked. paint_vertex.c A modified Auto Normalize was inserted to normalize the active group normally instead of locking the values: it was causing the active group to steal weights from locked groups if the active group had a weight of 1.0, and that destroyed the locked groups deformations. --- .../blender/editors/armature/editarmature.c | 54 ++++++- .../editors/sculpt_paint/paint_vertex.c | 132 +++++++++++++----- 2 files changed, 146 insertions(+), 40 deletions(-) diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index b31bcc710f4..48cbb3e2c3d 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4385,6 +4385,21 @@ static int bone_looper(Object *ob, Bone *bone, void *data, return count; } +// Jason +Bone* get_other_selected_bone(Object *ob) { + Bone *bone; + int i; + bone = get_indexed_bone(ob, 0); + for(i = 0; bone;){ + if(bone->flag & BONE_SELECTED) { + return bone; + } + i++; + bone = get_indexed_bone(ob, i); + } + + return NULL; +} /* called from editview.c, for mode-less pose selection */ /* assumes scene obact and basact is still on old situation */ @@ -4392,7 +4407,8 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor { Object *ob= base->object; Bone *nearBone; - + // Jason + Bone *new_act_bone; if (!ob || !ob->pose) return 0; nearBone= get_bone_from_selectbuffer(scene, base, buffer, hits, 1); @@ -4402,11 +4418,37 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor bArmature *arm= ob->data; /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ - if (!(extend) || (base != scene->basact)) { - ED_pose_deselectall(ob, 0); - nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - arm->act_bone= nearBone; - + /* Jason was here, I'm doing a unified select for locking now */ + if ((base != scene->basact)) {//if (!(extend) || (base != scene->basact)) { + /* Jason was here */ + /* only deselect all if they aren't using 'shift' */ + if(!extend) { + ED_pose_deselectall(ob, 0); + nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_bone= nearBone; + ED_vgroup_select_by_name(OBACT, nearBone->name); + DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); + } + // Jason deselect this bone specifically if it is selected already + else { + if (nearBone->flag & BONE_SELECTED) { + nearBone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + if(nearBone == arm->act_bone) { + // make a different bone the active one if it exists + + new_act_bone = get_other_selected_bone(ob); + if(new_act_bone) { + new_act_bone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_bone = new_act_bone; + ED_vgroup_select_by_name(OBACT, new_act_bone->name); + DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); + } + } + } else { + nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_bone= nearBone; + } + } // XXX old cruft! use notifiers instead //select_actionchannel_by_name(ob->action, nearBone->name, 1); } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 4793b5687d1..8a03d46fe19 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1028,6 +1028,35 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } } } +// Jason was here: the active group should be involved in auto normalize +static void do_weight_paint_auto_normalize_change_act_group(MDeformVert *dvert, char *map) +{ +// MDeformWeight *dw = dvert->dw; + float sum=0.0f, fac=0.0f; + int i, tot=0; + + if (!map) + return; + + for (i=0; itotweight; i++) { + if (map[dvert->dw[i].def_nr]) { + tot += 1; + sum += dvert->dw[i].weight; + } + } + + if (!tot || sum == 1.0f) + return; + + fac = sum; + fac = fac==0.0f ? 1.0f : 1.0f / fac; + + for (i=0; itotweight; i++) { + if (map[dvert->dw[i].def_nr]) { + dvert->dw[i].weight *= fac; + } + } +} /* Jason was here this function will handle normalize with locked groups it assumes that the current ratios (of locked groups) @@ -1109,7 +1138,7 @@ dividing can cause the weights to drop to 0 }*/ /* Jason was here */ /* -See if the current deform group has a locked group +See if the current deform vertex has a locked group */ static char has_locked_group(MDeformVert *dvert, char *flags) { @@ -1122,30 +1151,57 @@ static char has_locked_group(MDeformVert *dvert, char *flags) return FALSE; } /*Jason was here -not sure where the prototypes belong at the moment -static char* gen_lck_flags(Object* ob); - gen_lck_flags gets the status of "flag" for each bDeformGroup in ob->defbase and returns an array containing them + +if there are multiple bones selected, however, they are the only ones that are treated as "unlocked" */ -static char* gen_lck_flags(Object* ob, int defcnt) +static char* gen_lck_flags(Object* ob, int defcnt, char *map) { char is_locked = FALSE; int i; //int defcnt = BLI_countlist(&ob->defbase); char *flags = MEM_mallocN(defcnt*sizeof(char), "defflags"); - bDeformGroup *defgroup = ob->defbase.first; - for(i = 0; i < defcnt && defgroup; i++) { - flags[i] = defgroup->flag; - defgroup = defgroup->next; - if(flags[i]) { - is_locked = TRUE; + bDeformGroup *defgroup; + char was_selected = FALSE; + int selected = 0; + bPose *pose; + bPoseChannel *chan; + Bone *bone; + + Object *armob = ED_object_pose_armature(ob); + + if(armob) { + pose = armob->pose; + for (chan=pose->chanbase.first; chan; chan=chan->next) { + bone = chan->bone; + was_selected = FALSE; + for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { + if(!strcmp(defgroup->name, bone->name)) { + flags[i] = !(bone->flag & BONE_SELECTED); + if(flags[i]) { + is_locked = TRUE; + } else if(!was_selected){ + selected++; + was_selected = TRUE; + } + } + } + } + } + if(selected <= 1) { + is_locked = FALSE; + for(i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { + flags[i] = defgroup->flag; + if(flags[i]) { + is_locked = TRUE; + } } } if(is_locked){ return flags; } - // don't forget to free it + // don't forget to free it if it is unneeded MEM_freeN(flags); return NULL; } @@ -1204,18 +1260,17 @@ and to redistribute that weight to the unlocked groups (if it has to, then it will put some/all of the change back onto the original group) */ -static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw, float oldw, char* flags, int defcnt, char *map) +static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index, MDeformWeight *pnt_dw, float oldw, char* flags, int defcnt, char *map) { int i; + float old_change_left; float change_left = oldw - pnt_dw->weight; + // make sure the redistribution the same per loop. float change; char was_a_change; int groups_left_that_can_change = 0; - // make sure there is no case for division by 0, and make the redistribution the same per loop. - int groups_currently_left; char* change_status = MEM_mallocN(defcnt*sizeof(char), "defflags"); MDeformWeight *dw; - //printf("start\n"); for(i = 0; i < defcnt; i++) { if(pnt_dw->def_nr == i || !map[i]) { change_status[i] = FALSE; @@ -1224,13 +1279,15 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw } if(change_status[i]) { groups_left_that_can_change++; + defvert_verify_index(dvert, i); } - //printf("group %d, change status: %d flag: %d active?: %d\n", i, change_status[i], flags[i], pnt_dw->def_nr == i); } - //printf("\n"); if(groups_left_that_can_change > 0) { - groups_currently_left = groups_left_that_can_change; change = change_left/groups_left_that_can_change; + /* the division could cause it to be zero, so if it is, forget it*/ + if(change == 0) { + change = change_left; + } do { was_a_change = FALSE; for(i = 0; i < dvert->totweight; i++) { @@ -1240,45 +1297,53 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw } dw->weight += change; + old_change_left = change_left; change_left -= change; - //printf("group %d, change: %f weight: %f groups left: %d\n", dw->def_nr, change, dw->weight, groups_left_that_can_change); + // sign change? + if(change_left!=0 && change_left/fabs(change_left) != old_change_left/fabs(old_change_left)) { + dw->weight -= change; + change_left = old_change_left; + break; + } if(dw->weight >= 1.0f) { change_left += dw->weight-1.0f; dw->weight = 1.0f; - groups_currently_left--; + groups_left_that_can_change--; change_status[dw->def_nr] = FALSE; }else if(dw->weight <= 0.0f) { change_left += dw->weight; dw->weight = 0.0f; - groups_currently_left--; + groups_left_that_can_change--; change_status[dw->def_nr] = FALSE; } was_a_change = TRUE; + /* if it was too small, don't get stuck in an infinite loop! */ + if(old_change_left == change_left) { + change *= 2; + } } - groups_left_that_can_change = groups_currently_left; } while(groups_left_that_can_change > 0 && change_left != 0.0f && was_a_change); } // add any remaining change back to the original weight pnt_dw->weight += change_left; MEM_freeN(change_status); - //printf("done\n"); } /* Jason */ -static void check_locks_and_normalize(Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups) +static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups) { if(flags && has_locked_group(me->dvert+index, flags)) { if(flags[dw->def_nr]) { // cannot change locked groups! dw->weight = oldw; } else if(bone_groups[dw->def_nr]) { - redistribute_weight_change(me->dvert+index, dw, oldw, flags, defcnt, bone_groups); - do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);//do_wp_auto_normalize_locked_groups(me, me->dvert, validmap); + redistribute_weight_change(ob, me->dvert+index, index, dw, oldw, flags, defcnt, bone_groups); + do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } } else if(bone_groups[dw->def_nr]) {// disable auto normalize if the active group is not a bone group - do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); + do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } } // Jason @@ -1291,7 +1356,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, Mesh *me= ob->data; MDeformWeight *dw, *uw; int vgroup= ob->actdef-1; - + /* Jason was here */ char* flags; char* bone_groups; @@ -1314,13 +1379,12 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dw==NULL || uw==NULL) return; /* Jason was here */ - flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase)); + flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase), bone_groups); oldw = dw->weight; - wpaint_blend(wp, dw, uw, alpha, paintweight, flip); - /* Jason was here */ - check_locks_and_normalize(me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups); + check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups); + if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); if(j>=0) { @@ -1334,7 +1398,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw->weight= dw->weight; /* Jason */ - check_locks_and_normalize(me, j, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups); + check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups); } } /* Jason */ From b967d8695ffba91cc138022d7e6860559ac81d3d Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 8 Jun 2011 19:05:17 +0000 Subject: [PATCH 14/68] Heard that multi-bone selection would be better used for painting multiple bones; took out select lock. Added a basic multiple bone group paint feature "Multi-Paint" and its corresponding checkbox next to "Auto Normalize," but I need to access the ToolSettings for it in armature to make bone selection function/draw correctly When you multi-paint, it paints on selected bones while keeping the weight ratios on a vertex of the selected groups the same. You can't currently multi-paint on a vertex with a locked deform group. --- .../startup/bl_ui/space_view3d_toolbar.py | 2 + .../blender/blenkernel/intern/DerivedMesh.c | 72 +++++++- .../blender/editors/armature/editarmature.c | 12 +- .../editors/sculpt_paint/paint_vertex.c | 154 ++++++++++++------ source/blender/makesdna/DNA_scene_types.h | 5 +- source/blender/makesrna/intern/rna_scene.c | 6 + 6 files changed, 188 insertions(+), 63 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 503a1d806ac..7b015206f0d 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -639,6 +639,8 @@ class VIEW3D_PT_tools_brush(PaintPanel, bpy.types.Panel): elif context.weight_paint_object and brush: layout.prop(context.tool_settings, "vertex_group_weight", text="Weight", slider=True) layout.prop(context.tool_settings, "use_auto_normalize", text="Auto Normalize") + # Jason was here + layout.prop(context.tool_settings, "use_multipaint", text="Multi-Paint") col = layout.column() diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index d9c98bc0200..4e570d304e5 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -40,6 +40,9 @@ #include "DNA_cloth_types.h" #include "DNA_key_types.h" #include "DNA_meshdata_types.h" +// Jason +#include "DNA_armature_types.h" + #include "DNA_object_types.h" #include "DNA_scene_types.h" // N_T @@ -72,6 +75,8 @@ #include "GPU_material.h" #include "ED_sculpt.h" /* for ED_sculpt_modifiers_changed */ +// Jason was here, this is for multi-paint +#include "ED_armature.h" /////////////////////////////////// /////////////////////////////////// @@ -1602,7 +1607,7 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb) } } -static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col) +static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected) { Mesh *me = ob->data; float colf[4], input = 0.0f; @@ -1610,8 +1615,14 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u if (me->dvert) { for (i=0; idvert[vert].totweight; i++) - if (me->dvert[vert].dw[i].def_nr==ob->actdef-1) - input+=me->dvert[vert].dw[i].weight; + // Jason was here + if ((selected<=1 && me->dvert[vert].dw[i].def_nr==ob->actdef-1) || dg_flags[me->dvert[vert].dw[i].def_nr]) {// + input+=me->dvert[vert].dw[i].weight; + } + } + // Jason was here + if(selected) { + input/=selected; } CLAMP(input, 0.0f, 1.0f); @@ -1633,7 +1644,44 @@ void vDM_ColorBand_store(ColorBand *coba) { stored_cb= coba; } +/* Jason was here */ +static char* get_selected_defgroups(Object *ob, int defcnt) { + bPoseChannel *chan; + bPose *pose; + bDeformGroup *defgroup; + //Bone *bone; + char was_selected = FALSE; + char *dg_flags = MEM_mallocN(defcnt*sizeof(char), "dg_selected_flags"); + int i; + Object *armob = ED_object_pose_armature(ob); + if(armob) { + pose = armob->pose; + for (chan=pose->chanbase.first; chan; chan=chan->next) { + for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { + if(!strcmp(defgroup->name, chan->bone->name)) { + // TODO get BONE_SELECTED flag + dg_flags[i] = (chan->bone->flag & 1); + was_selected = TRUE; + } + } + } + } + + return dg_flags; +} +/* Jason was here */ +static int count_true(char *list, int len) +{ + int i; + int cnt = 0; + for(i = 0; i < len; i++) { + if (list[i]) { + cnt++; + } + } + return cnt; +} static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm) { Mesh *me = ob->data; @@ -1641,18 +1689,24 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm) ColorBand *coba= stored_cb; /* warning, not a local var */ unsigned char *wtcol; int i; - + // Jason was here + int defcnt = BLI_countlist(&ob->defbase); + char *dg_flags = get_selected_defgroups(ob, defcnt); + int selected = count_true(dg_flags, defcnt); + wtcol = MEM_callocN (sizeof (unsigned char) * me->totface*4*4, "weightmap"); memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4); for (i=0; itotface; i++, mf++) { - calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4]); - calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4]); - calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4]); + calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected); + calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected); + calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected); if (mf->v4) - calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4]); + calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected); } - + // Jason + MEM_freeN(dg_flags); + CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData); } diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 48cbb3e2c3d..b889f9938ff 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4400,7 +4400,6 @@ Bone* get_other_selected_bone(Object *ob) { return NULL; } - /* called from editview.c, for mode-less pose selection */ /* assumes scene obact and basact is still on old situation */ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, short hits, short extend) @@ -4412,13 +4411,13 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor if (!ob || !ob->pose) return 0; nearBone= get_bone_from_selectbuffer(scene, base, buffer, hits, 1); - + /* if the bone cannot be affected, don't do anything */ if ((nearBone) && !(nearBone->flag & BONE_UNSELECTABLE)) { bArmature *arm= ob->data; /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ - /* Jason was here, I'm doing a unified select for locking now */ + /* Jason was here, I'm doing a select for multibone painting */ if ((base != scene->basact)) {//if (!(extend) || (base != scene->basact)) { /* Jason was here */ /* only deselect all if they aren't using 'shift' */ @@ -4427,28 +4426,27 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); arm->act_bone= nearBone; ED_vgroup_select_by_name(OBACT, nearBone->name); - DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); } - // Jason deselect this bone specifically if it is selected already else { + // Jason deselect this bone specifically if it is selected already if (nearBone->flag & BONE_SELECTED) { nearBone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); if(nearBone == arm->act_bone) { // make a different bone the active one if it exists - new_act_bone = get_other_selected_bone(ob); if(new_act_bone) { new_act_bone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); arm->act_bone = new_act_bone; ED_vgroup_select_by_name(OBACT, new_act_bone->name); - DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); } } + // or select the bone if they are using shift } else { nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); arm->act_bone= nearBone; } } + DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); // XXX old cruft! use notifiers instead //select_actionchannel_by_name(ob->action, nearBone->name, 1); } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 8a03d46fe19..5485401d5c9 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1153,8 +1153,6 @@ static char has_locked_group(MDeformVert *dvert, char *flags) /*Jason was here gen_lck_flags gets the status of "flag" for each bDeformGroup in ob->defbase and returns an array containing them - -if there are multiple bones selected, however, they are the only ones that are treated as "unlocked" */ static char* gen_lck_flags(Object* ob, int defcnt, char *map) { @@ -1163,39 +1161,12 @@ static char* gen_lck_flags(Object* ob, int defcnt, char *map) //int defcnt = BLI_countlist(&ob->defbase); char *flags = MEM_mallocN(defcnt*sizeof(char), "defflags"); bDeformGroup *defgroup; - char was_selected = FALSE; int selected = 0; - bPose *pose; - bPoseChannel *chan; - Bone *bone; - Object *armob = ED_object_pose_armature(ob); - - if(armob) { - pose = armob->pose; - for (chan=pose->chanbase.first; chan; chan=chan->next) { - bone = chan->bone; - was_selected = FALSE; - for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { - if(!strcmp(defgroup->name, bone->name)) { - flags[i] = !(bone->flag & BONE_SELECTED); - if(flags[i]) { - is_locked = TRUE; - } else if(!was_selected){ - selected++; - was_selected = TRUE; - } - } - } - } - } - if(selected <= 1) { - is_locked = FALSE; - for(i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { - flags[i] = defgroup->flag; - if(flags[i]) { - is_locked = TRUE; - } + for(i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { + flags[i] = defgroup->flag; + if(flags[i]) { + is_locked = TRUE; } } if(is_locked){ @@ -1332,10 +1303,60 @@ static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index MEM_freeN(change_status); } /* Jason */ -static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups) +/* return TRUE on success, FALSE on failure +failure occurs when zero elements exist in the selection, +nonzero elements reach zero, +and if they go above 1 if auto normalize is off */ +static int multipaint_vgroups(MDeformVert *dvert, MDeformWeight *dw, float oldw, char* validmap, char* bone_groups, char* selection, int defcnt) { + int i; + float change; + MDeformWeight *w; + float val; + if(oldw == 0 || !selection) { + return FALSE; + } + change = dw->weight/oldw; + if(change == 1 || !change) { + return FALSE; + } + dw->weight = oldw; + // make sure all selected dverts exist + for(i = 0; i < defcnt; i++) { + if(selection[i]){ + defvert_verify_index(dvert, i); + } + } + // see if all changes are valid before doing any + for(i = 0; i < dvert->totweight; i++) { + w = (dvert->dw+i); + if(!selection[w->def_nr] || !bone_groups[w->def_nr]) { + continue; + } + if(w->weight == 0) { + if(selection[w->def_nr]) { + return FALSE; + } + continue; + } + val = w->weight*change; + if(val <= 0 || (val > 1 && !validmap)) { + return FALSE; + } + } + for(i = 0; i < dvert->totweight; i++) { + w = (dvert->dw+i); + if(!selection[w->def_nr] || !bone_groups[w->def_nr] || w->weight == 0) { + continue; + } + w->weight *= change; + } + return TRUE; +} +/* Jason */ +static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups, char *selection, int multipaint) { if(flags && has_locked_group(me->dvert+index, flags)) { - if(flags[dw->def_nr]) { + if(flags[dw->def_nr] || multipaint) { // cannot change locked groups! dw->weight = oldw; } else if(bone_groups[dw->def_nr]) { @@ -1343,23 +1364,60 @@ static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgrou do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } } else if(bone_groups[dw->def_nr]) {// disable auto normalize if the active group is not a bone group - do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); + if(multipaint) { + // try to alter the other bone groups in the dvert with the changed dw if possible, if it isn't, change it back + if(selection[dw->def_nr] && multipaint_vgroups(me->dvert+index, dw, oldw, validmap, bone_groups, selection, defcnt)) { + do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); + }else { + // multipaint failed + dw->weight = oldw; + } + }else { + do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); + } } } +/* Jason was here duplicate function I used in DerivedMesh.c*/ +static char* get_selected_defgroups(Object *ob, int defcnt) { + bPoseChannel *chan; + bPose *pose; + bDeformGroup *defgroup; + //Bone *bone; + char was_selected = FALSE; + char *dg_flags = MEM_mallocN(defcnt*sizeof(char), "dg_selected_flags"); + int i; + Object *armob = ED_object_pose_armature(ob); + + if(armob) { + pose = armob->pose; + for (chan=pose->chanbase.first; chan; chan=chan->next) { + for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { + if(!strcmp(defgroup->name, chan->bone->name)) { + // TODO get BONE_SELECTED flag + dg_flags[i] = (chan->bone->flag & 1); + was_selected = TRUE; + } + } + } + } + + return dg_flags; +} // Jason static char *wpaint_make_validmap(Object *ob); static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, float alpha, float paintweight, int flip, - int vgroup_mirror, char *validmap) + int vgroup_mirror, char *validmap, int multipaint) { Mesh *me= ob->data; MDeformWeight *dw, *uw; int vgroup= ob->actdef-1; /* Jason was here */ - char* flags; - char* bone_groups; + char *flags; + char *bone_groups; + char *selection; float oldw; int defcnt; if(validmap) { @@ -1380,10 +1438,11 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, return; /* Jason was here */ flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase), bone_groups); + selection = get_selected_defgroups(ob, defcnt); oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, flip); /* Jason was here */ - check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups); + check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, multipaint); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); @@ -1398,13 +1457,16 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw->weight= dw->weight; /* Jason */ - check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups); + check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups, selection, multipaint); } } /* Jason */ if(flags) { MEM_freeN(flags); } + if(selection) { + MEM_freeN(selection); + } if(!validmap) { MEM_freeN(bone_groups); } @@ -1590,7 +1652,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED paint_stroke_set_mode_data(stroke, wpd); view3d_set_viewcontext(C, &wpd->vc); wpd->vgroup_mirror= -1; - + /*set up auto-normalize, and generate map for detecting which vgroups affect deform bones*/ wpd->auto_normalize = ts->auto_normalize; @@ -1796,7 +1858,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P if(alpha) { do_weight_paint_vertex(wp, ob, mface->v1, alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); + wpd->vgroup_validmap, ts->multipaint); } (me->dvert+mface->v1)->flag= 0; } @@ -1806,7 +1868,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P if(alpha) { do_weight_paint_vertex(wp, ob, mface->v2, alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); + wpd->vgroup_validmap, ts->multipaint); } (me->dvert+mface->v2)->flag= 0; } @@ -1816,7 +1878,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P if(alpha) { do_weight_paint_vertex(wp, ob, mface->v3, alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); + wpd->vgroup_validmap, ts->multipaint); } (me->dvert+mface->v3)->flag= 0; } @@ -1827,7 +1889,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P if(alpha) { do_weight_paint_vertex(wp, ob, mface->v4, alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); + wpd->vgroup_validmap, ts->multipaint); } (me->dvert+mface->v4)->flag= 0; } diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 657bfb1c884..0e4b1e60f9a 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -734,10 +734,13 @@ typedef struct ToolSettings { short snap_flag, snap_target; short proportional, prop_mode; char proportional_objects; /* proportional edit, object mode */ - char pad[3]; + char pad[7]; int auto_normalize; /*auto normalizing mode in wpaint*/ + //Jason + int multipaint; /* paint multiple bones in wpaint */ + short sculpt_paint_settings; /* user preferences for sculpt and paint */ short pad1; int sculpt_paint_unified_size; /* unified radius of brush in pixels */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 44dcabe40f9..3f9710a5852 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1087,6 +1087,12 @@ static void rna_def_tool_settings(BlenderRNA *brna) "Ensure all bone-deforming vertex groups add up to 1.0 while " "weight painting"); + prop = RNA_def_property(srna, "use_multipaint", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "multipaint", 1); + RNA_def_property_ui_text(prop, "WPaint Multi-Paint", + "Paint across all selected bones while " + "weight painting"); + prop= RNA_def_property(srna, "vertex_paint", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "vpaint"); RNA_def_property_ui_text(prop, "Vertex Paint", ""); From 42e062fc882f0fb9df7671e457d8047fc6e04a39 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 9 Jun 2011 16:38:47 +0000 Subject: [PATCH 15/68] Made the Multi-Paint check box control what was being drawn so that it doesn't always draw the groups together when multiple bones are selected. --- .../blender/blenkernel/intern/DerivedMesh.c | 27 +++++++++---------- .../blender/editors/armature/editarmature.c | 12 ++++++++- .../editors/sculpt_paint/paint_vertex.c | 4 +-- source/blender/makesrna/intern/rna_internal.h | 2 ++ source/blender/makesrna/intern/rna_object.c | 10 +++++++ source/blender/makesrna/intern/rna_scene.c | 1 + 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 4e570d304e5..c71ebd915a2 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1607,7 +1607,7 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb) } } -static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected) +static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int multipaint) { Mesh *me = ob->data; float colf[4], input = 0.0f; @@ -1616,12 +1616,12 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u if (me->dvert) { for (i=0; idvert[vert].totweight; i++) // Jason was here - if ((selected<=1 && me->dvert[vert].dw[i].def_nr==ob->actdef-1) || dg_flags[me->dvert[vert].dw[i].def_nr]) {// + if ((!multipaint && me->dvert[vert].dw[i].def_nr==ob->actdef-1) || (multipaint && dg_flags[me->dvert[vert].dw[i].def_nr])) {// input+=me->dvert[vert].dw[i].weight; } } // Jason was here - if(selected) { + if(multipaint && selected) { input/=selected; } @@ -1644,7 +1644,7 @@ void vDM_ColorBand_store(ColorBand *coba) { stored_cb= coba; } -/* Jason was here */ +/* Jason was here duplicate function in paint_vertex.c*/ static char* get_selected_defgroups(Object *ob, int defcnt) { bPoseChannel *chan; bPose *pose; @@ -1660,8 +1660,7 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { for (chan=pose->chanbase.first; chan; chan=chan->next) { for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { if(!strcmp(defgroup->name, chan->bone->name)) { - // TODO get BONE_SELECTED flag - dg_flags[i] = (chan->bone->flag & 1); + dg_flags[i] = (chan->bone->flag & BONE_SELECTED); was_selected = TRUE; } } @@ -1682,7 +1681,7 @@ static int count_true(char *list, int len) } return cnt; } -static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm) +static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int multipaint) { Mesh *me = ob->data; MFace *mf = me->mface; @@ -1698,11 +1697,11 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm) memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4); for (i=0; itotface; i++, mf++) { - calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected); - calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected); - calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected); + calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, multipaint); + calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, multipaint); + calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, multipaint); if (mf->v4) - calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected); + calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, multipaint); } // Jason MEM_freeN(dg_flags); @@ -1913,7 +1912,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, dm); + add_weight_mcol_dm(ob, dm, scene->toolsettings->multipaint);// Jason /* Constructive modifiers need to have an origindex * otherwise they wont have anywhere to copy the data from. @@ -2023,7 +2022,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos CDDM_calc_normals(finaldm); if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm); + add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint);// Jason } else if(dm) { finaldm = dm; } else { @@ -2035,7 +2034,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm); + add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint);// Jason } /* add an orco layer if needed */ diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index b889f9938ff..66fcced1d8e 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4408,6 +4408,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor Bone *nearBone; // Jason Bone *new_act_bone; + if (!ob || !ob->pose) return 0; nearBone= get_bone_from_selectbuffer(scene, base, buffer, hits, 1); @@ -5210,6 +5211,10 @@ void POSE_OT_select_inverse(wmOperatorType *ot) static int pose_de_select_all_exec(bContext *C, wmOperator *op) { int action = RNA_enum_get(op->ptr, "action"); + //Jason + Object *ob = NULL; + Scene *scene= CTX_data_scene(C); + int multipaint = scene->toolsettings->multipaint; if (action == SEL_TOGGLE) { action= CTX_DATA_COUNT(C, selected_pose_bones) ? SEL_DESELECT : SEL_SELECT; @@ -5239,7 +5244,12 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) CTX_DATA_END; WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, NULL); - + // Jason + if(multipaint) { + ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + } + return OPERATOR_FINISHED; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 5485401d5c9..8e6c320e49f 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1393,8 +1393,7 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { for (chan=pose->chanbase.first; chan; chan=chan->next) { for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { if(!strcmp(defgroup->name, chan->bone->name)) { - // TODO get BONE_SELECTED flag - dg_flags[i] = (chan->bone->flag & 1); + dg_flags[i] = (chan->bone->flag & BONE_SELECTED); was_selected = TRUE; } } @@ -1472,7 +1471,6 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } - /* *************** set wpaint operator ****************** */ static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */ diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index a9fb545ec3f..133c24e85f3 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -214,6 +214,8 @@ int rna_object_shapekey_index_set(struct ID *id, PointerRNA value, int current); void rna_Object_internal_update_data(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); void rna_Mesh_update_draw(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); void rna_TextureSlot_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); +//Jason +void rna_update_active_object(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); /* basic poll functions for object types */ int rna_Armature_object_poll(struct PointerRNA *ptr, struct PointerRNA value); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index c6d1bfc22db..8dc095841a2 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -218,6 +218,16 @@ void rna_Object_internal_update_data(Main *bmain, Scene *scene, PointerRNA *ptr) DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA); WM_main_add_notifier(NC_OBJECT|ND_DRAW, ptr->id.data); } +// Jason +void rna_update_active_object(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + Object *ob; + Base *basact = scene->basact; + if(basact && (ob = basact->object)) { + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_main_add_notifier(NC_OBJECT|ND_DRAW, &ob->id); + } +} void rna_Object_active_shape_update(Main *bmain, Scene *scene, PointerRNA *ptr) { diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 3f9710a5852..9511ca75f77 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1092,6 +1092,7 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "WPaint Multi-Paint", "Paint across all selected bones while " "weight painting"); + RNA_def_property_update(prop, 0, "rna_update_active_object"); prop= RNA_def_property(srna, "vertex_paint", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "vpaint"); From a24dac8b8fea2abf1df129d209b13539b006668e Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Fri, 10 Jun 2011 19:47:53 +0000 Subject: [PATCH 16/68] Fixed Multi-Paint so that it doesn't stop painting unless the maximum cap has been met. Also, the color display now only shows colors for the areas that are shared by the selected groups. Finally, Multi-Paint responds to auto normalize, it determines when it can not be edited. --- .../blender/blenkernel/intern/DerivedMesh.c | 67 ++++-- .../editors/sculpt_paint/paint_vertex.c | 199 +++++------------- source/blender/makesrna/intern/rna_scene.c | 1 + 3 files changed, 99 insertions(+), 168 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index c71ebd915a2..dfd89b989c8 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1607,25 +1607,49 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb) } } -static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int multipaint) +static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int unselected, int multipaint, int auto_normalize) { Mesh *me = ob->data; - float colf[4], input = 0.0f; + float colf[4], input = 0.0f, unsel_sum = 0.0f;// Jason int i; + //Jason, a dw might be absent from dvert + int cnt = 0; if (me->dvert) { - for (i=0; idvert[vert].totweight; i++) + for (i=0; idvert[vert].totweight; i++) { // Jason was here - if ((!multipaint && me->dvert[vert].dw[i].def_nr==ob->actdef-1) || (multipaint && dg_flags[me->dvert[vert].dw[i].def_nr])) {// + if(multipaint && selected > 1) { + if(dg_flags[me->dvert[vert].dw[i].def_nr]) { + if(!me->dvert[vert].dw[i].weight) { + input = -1; + unsel_sum = 0; + break; + } + input+=me->dvert[vert].dw[i].weight; + cnt++; + } + // TODO unselected non-bone groups should not be involved in this sum + else if(auto_normalize) { + unsel_sum+=me->dvert[vert].dw[i].weight; + } + } else if (me->dvert[vert].dw[i].def_nr==ob->actdef-1) { input+=me->dvert[vert].dw[i].weight; } + } + // Jason was here + if(multipaint && selected > 1) { + if(cnt!=selected || input == 1.0f && auto_normalize && !unsel_sum) { + input = -1; + } else { + input/=selected; + } + } } - // Jason was here - if(multipaint && selected) { - input/=selected; + + if(!multipaint || selected <= 1) { + CLAMP(input, 0.0f, 1.0f); } - - CLAMP(input, 0.0f, 1.0f); + if(coba) do_colorband(coba, input, colf); @@ -1644,14 +1668,14 @@ void vDM_ColorBand_store(ColorBand *coba) { stored_cb= coba; } +/* TODO move duplicates to header */ /* Jason was here duplicate function in paint_vertex.c*/ static char* get_selected_defgroups(Object *ob, int defcnt) { bPoseChannel *chan; bPose *pose; bDeformGroup *defgroup; //Bone *bone; - char was_selected = FALSE; - char *dg_flags = MEM_mallocN(defcnt*sizeof(char), "dg_selected_flags"); + char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags"); int i; Object *armob = ED_object_pose_armature(ob); @@ -1661,7 +1685,6 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { if(!strcmp(defgroup->name, chan->bone->name)) { dg_flags[i] = (chan->bone->flag & BONE_SELECTED); - was_selected = TRUE; } } } @@ -1669,7 +1692,8 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { return dg_flags; } -/* Jason was here */ +/* TODO move duplicates to header */ +/* Jason was here duplicate function */ static int count_true(char *list, int len) { int i; @@ -1681,7 +1705,7 @@ static int count_true(char *list, int len) } return cnt; } -static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int multipaint) +static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int multipaint, int auto_normalize) { Mesh *me = ob->data; MFace *mf = me->mface; @@ -1692,16 +1716,17 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int multipaint) int defcnt = BLI_countlist(&ob->defbase); char *dg_flags = get_selected_defgroups(ob, defcnt); int selected = count_true(dg_flags, defcnt); + int unselected = defcnt - selected; wtcol = MEM_callocN (sizeof (unsigned char) * me->totface*4*4, "weightmap"); memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4); for (i=0; itotface; i++, mf++) { - calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, multipaint); - calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, multipaint); - calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, multipaint); + calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, unselected, multipaint, auto_normalize); + calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, unselected, multipaint, auto_normalize); + calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, unselected, multipaint, auto_normalize); if (mf->v4) - calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, multipaint); + calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, unselected, multipaint, auto_normalize); } // Jason MEM_freeN(dg_flags); @@ -1912,7 +1937,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, dm, scene->toolsettings->multipaint);// Jason + add_weight_mcol_dm(ob, dm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason /* Constructive modifiers need to have an origindex * otherwise they wont have anywhere to copy the data from. @@ -2022,7 +2047,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos CDDM_calc_normals(finaldm); if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint);// Jason + add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason } else if(dm) { finaldm = dm; } else { @@ -2034,7 +2059,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint);// Jason + add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason } /* add an orco layer if needed */ diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 8e6c320e49f..7e30a67d7be 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1057,85 +1057,6 @@ static void do_weight_paint_auto_normalize_change_act_group(MDeformVert *dvert, } } } -/* Jason was here -this function will handle normalize with locked groups -it assumes that the current ratios (of locked groups) -are the intended ratios. - -also, it does not attempt to force them to add up to 1, that would destroy intergroup weight ratios, -it simply makes the highest weight sum add up to one - -the Mesh is needed to change the ratios across the group - -I need to resolve a precision error issue, however: -dividing can cause the weights to drop to 0 -*/ -/*static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, char* map) -{ - float highestSum = 0.0f; - float currentSum; - int cnt; - int i, k; - int totvert = me->totvert; - MDeformVert dv; - - if(!map) { - return; - } - - for(i = 0; i < totvert; i++) { - dv = dvert[i]; - cnt = dv.totweight; - currentSum = 0.0f; - for(k = 0; k < cnt; k++) { - if(map[dv.dw->def_nr]) { - //printf("group %d considered\n", dv.dw->def_nr); - currentSum += (dv.dw+k)->weight; - } - } - if(highestSum < currentSum) { - highestSum = currentSum; - } - } - if(highestSum == 1.0f) { - return; - } - for(i = 0; i < totvert; i++) { - dv = dvert[i]; - cnt = dv.totweight; - - for(k = 0; k < cnt; k++) { - if(map[dv.dw->def_nr]) { - (dv.dw+k)->weight /= highestSum; - } - } - } -}*/ -/* Jason was here */ -/*static char get_locked_flag(Object *ob, int vgroup) -{ - int i; - bDeformGroup *defgroup = ob->defbase.first; - for(i = 0; i < vgroup && defgroup; i++) { - defgroup = defgroup->next; - } - if(defgroup) { - return defgroup->flag; - } - return 0; -}*/ -/* Jason was here */ -/*static int locked_group_exists(Object *ob) -{ - bDeformGroup *defgroup = ob->defbase.first; - while(defgroup) { - if(defgroup->flag){ - return TRUE; - } - defgroup = defgroup->next; - } - return FALSE; -}*/ /* Jason was here */ /* See if the current deform vertex has a locked group @@ -1176,54 +1097,6 @@ static char* gen_lck_flags(Object* ob, int defcnt, char *map) MEM_freeN(flags); return NULL; } -/*Jason was here -this alters the weights in order to maintain the ratios to match with the change in weights of pnt_dw -This was not the intended solution evidently -*/ -/*static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw) -{ - int i, k, totvert, cnt; - float scaledown = 1.0f; - float neww = pnt_dw->weight; - int defgroup = pnt_dw->def_nr; - MDeformVert *dvert; - MDeformVert dv; - MDeformWeight *dw; - totvert = me->totvert; - pnt_dw->weight = oldw; - - if(oldw == 0 || neww == 0){ - return; - } - dvert = me->dvert; - for(i = 0; i < totvert; i++) { - dv = dvert[i]; - cnt = dv.totweight; - for(k = 0; k < cnt; k++) { - dw = dv.dw+k; - if(dw->def_nr == defgroup){ - dw->weight = neww * (dw->weight / oldw); - if(dw->weight > scaledown){ - scaledown = dw->weight; - } - break; - } - } - } - if(scaledown > 1.0f) { - for(i = 0; i < totvert; i++) { - dv = dvert[i]; - cnt = dv.totweight; - for(k = 0; k < cnt; k++) { - dw = dv.dw+k; - if(dw->def_nr == defgroup){ - dw->weight /= scaledown; - break; - } - } - } - } -}*/ /* Jason was here */ /* The idea behind this function is to get the difference in weight for pnt_dw, @@ -1303,15 +1176,14 @@ static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index MEM_freeN(change_status); } /* Jason */ -/* return TRUE on success, FALSE on failure -failure occurs when zero elements exist in the selection, -nonzero elements reach zero, -and if they go above 1 if auto normalize is off */ -static int multipaint_vgroups(MDeformVert *dvert, MDeformWeight *dw, float oldw, char* validmap, char* bone_groups, char* selection, int defcnt) { +/* get the change that is needed to get a valid multipaint (if it can)*/ +static float get_valid_multipaint_change(MDeformVert *dvert, MDeformWeight *dw, float oldw, char* validmap, char* bone_groups, char* selection, int defcnt) { int i; float change; MDeformWeight *w; float val; + // see if you need to do anything (if it is normalized) + float sumw = 0.0f; if(oldw == 0 || !selection) { return FALSE; } @@ -1332,6 +1204,10 @@ static int multipaint_vgroups(MDeformVert *dvert, MDeformWeight *dw, float oldw, if(!selection[w->def_nr] || !bone_groups[w->def_nr]) { continue; } + // already reached the cap + if(change > 1 && w->weight==1) { + return FALSE; + } if(w->weight == 0) { if(selection[w->def_nr]) { return FALSE; @@ -1339,22 +1215,38 @@ static int multipaint_vgroups(MDeformVert *dvert, MDeformWeight *dw, float oldw, continue; } val = w->weight*change; - if(val <= 0 || (val > 1 && !validmap)) { + // no success here-I'm not going to force it to try to be just above 0 by changing 'change' + if(val <= 0) { return FALSE; } + if (validmap){ + sumw += w->weight; + }else if(val > 1) { + // use the transitive property to make magic, all of the others + // will still end up within the boundaries if the worst case does + change = 1.0f/w->weight; + } } + if(validmap && sumw == 1.0f) { + return FALSE; + } + return change; +} +static void multipaint_vgroups(MDeformVert *dvert, float change, char* bone_groups, char* selection) { + int i; + MDeformWeight *w; for(i = 0; i < dvert->totweight; i++) { w = (dvert->dw+i); - if(!selection[w->def_nr] || !bone_groups[w->def_nr] || w->weight == 0) { + if(!bone_groups[w->def_nr] || !selection[w->def_nr] || w->weight == 0) { continue; } w->weight *= change; } - return TRUE; } /* Jason */ -static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups, char *selection, int multipaint) +static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups, char *selection, int selected, int multipaint) { + float change=0.0f; if(flags && has_locked_group(me->dvert+index, flags)) { if(flags[dw->def_nr] || multipaint) { // cannot change locked groups! @@ -1364,17 +1256,17 @@ static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgrou do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } } else if(bone_groups[dw->def_nr]) {// disable auto normalize if the active group is not a bone group - if(multipaint) { + if(multipaint && selected > 1) { // try to alter the other bone groups in the dvert with the changed dw if possible, if it isn't, change it back - if(selection[dw->def_nr] && multipaint_vgroups(me->dvert+index, dw, oldw, validmap, bone_groups, selection, defcnt)) { - do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); + if(selection[dw->def_nr] && (change = get_valid_multipaint_change(me->dvert+index, dw, oldw, validmap, bone_groups, selection, defcnt)) > 0) { + multipaint_vgroups(me->dvert+index, change, bone_groups, selection); + do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap); }else { - // multipaint failed + // multi-paint failed dw->weight = oldw; } - }else { - do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); } + do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap); } } /* Jason was here duplicate function I used in DerivedMesh.c*/ @@ -1383,8 +1275,7 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { bPose *pose; bDeformGroup *defgroup; //Bone *bone; - char was_selected = FALSE; - char *dg_flags = MEM_mallocN(defcnt*sizeof(char), "dg_selected_flags"); + char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags"); int i; Object *armob = ED_object_pose_armature(ob); @@ -1394,7 +1285,6 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { if(!strcmp(defgroup->name, chan->bone->name)) { dg_flags[i] = (chan->bone->flag & BONE_SELECTED); - was_selected = TRUE; } } } @@ -1402,6 +1292,19 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { return dg_flags; } +/* TODO move duplicates to header */ +/* Jason was here duplicate function */ +static int count_true(char *list, int len) +{ + int i; + int cnt = 0; + for(i = 0; i < len; i++) { + if (list[i]) { + cnt++; + } + } + return cnt; +} // Jason static char *wpaint_make_validmap(Object *ob); @@ -1417,6 +1320,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, char *flags; char *bone_groups; char *selection; + int selected; float oldw; int defcnt; if(validmap) { @@ -1438,10 +1342,11 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason was here */ flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase), bone_groups); selection = get_selected_defgroups(ob, defcnt); + selected = count_true(selection, defcnt); oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, flip); /* Jason was here */ - check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, multipaint); + check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); @@ -1456,7 +1361,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw->weight= dw->weight; /* Jason */ - check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups, selection, multipaint); + check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); } } /* Jason */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 9511ca75f77..180fec264a8 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1086,6 +1086,7 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "WPaint Auto-Normalize", "Ensure all bone-deforming vertex groups add up to 1.0 while " "weight painting"); + RNA_def_property_update(prop, 0, "rna_update_active_object"); prop = RNA_def_property(srna, "use_multipaint", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "multipaint", 1); From 51fe8aaec2a9965fa1ad18473d822fba24e52b6d Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 13 Jun 2011 17:16:44 +0000 Subject: [PATCH 17/68] Made a var that determines if the color can be black (so it knows if it should use CLAMP or not) --- source/blender/blenkernel/intern/DerivedMesh.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index dfd89b989c8..b0eb547f826 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1612,8 +1612,10 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u Mesh *me = ob->data; float colf[4], input = 0.0f, unsel_sum = 0.0f;// Jason int i; - //Jason, a dw might be absent from dvert + //Jason, a dw might be absent from dvert, so count the dw's you find + // to see if it should be disabled in multipaint int cnt = 0; + char make_black = FALSE; if (me->dvert) { for (i=0; idvert[vert].totweight; i++) { @@ -1621,8 +1623,7 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u if(multipaint && selected > 1) { if(dg_flags[me->dvert[vert].dw[i].def_nr]) { if(!me->dvert[vert].dw[i].weight) { - input = -1; - unsel_sum = 0; + make_black = TRUE; break; } input+=me->dvert[vert].dw[i].weight; @@ -1637,16 +1638,18 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u } } // Jason was here - if(multipaint && selected > 1) { + if(multipaint && selected > 1 && !make_black) { if(cnt!=selected || input == 1.0f && auto_normalize && !unsel_sum) { - input = -1; + make_black = TRUE; } else { input/=selected; } } } - if(!multipaint || selected <= 1) { + if(make_black) { + input = -1; + }else { CLAMP(input, 0.0f, 1.0f); } From 53baa881b2938bcd61d2692180a7bb7d8ea2db74 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 14 Jun 2011 19:11:01 +0000 Subject: [PATCH 18/68] Made Multi-Paint support vertices containing locked groups Changed locking system to check the amount of space in unlocked groups ahead of time. --- .../editors/sculpt_paint/paint_vertex.c | 168 +++++++++++++----- 1 file changed, 125 insertions(+), 43 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 7e30a67d7be..560ee550aed 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1098,17 +1098,54 @@ static char* gen_lck_flags(Object* ob, int defcnt, char *map) return NULL; } /* Jason was here */ +static int has_locked_group_selected(int defcnt, char *selection, char *flags) { + int i; + for(i = 0; i < defcnt; i++) { + if(selection[i] && flags[i]) { + return TRUE; + } + } + return FALSE; +} +/* Jason was here */ +static float get_change_allowed_from_unlocked_bone_groups(MDeformVert *dvert, int def_nr, int defcnt, char *selection, int pos, char *flags, char *bone_groups) { + int i; + float allowed_totchange = 0.0f; + for(i = 0; i < defcnt; i++) { + if(def_nr != i && bone_groups[i] && !selection[i] && !flags[i]) { + // positive change + if(pos == 1) { + allowed_totchange -= 1-defvert_verify_index(dvert, i)->weight; + } else {//negative change + allowed_totchange -= defvert_verify_index(dvert, i)->weight; + } + } + } + return allowed_totchange; +} +/* Jason was here */ +static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int selected, char *flags, char *bone_groups) { + int i; + if(defcnt == selected) { + return FALSE; + } + for(i = 0; i < defcnt; i++) { + if(bone_groups[i] && !selection[i] && !flags[i]) { + return TRUE; + } + } + return FALSE; +} /* -The idea behind this function is to get the difference in weight for pnt_dw, +The idea behind this function is to get the difference in weight, and to redistribute that weight to the unlocked groups (if it has to, then it will put some/all of the change back onto the original group) */ -static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index, MDeformWeight *pnt_dw, float oldw, char* flags, int defcnt, char *map) +static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index, int def_nr, int multipaint, char *selection, int selected, float change_left, char* flags, int defcnt, char *map) { int i; float old_change_left; - float change_left = oldw - pnt_dw->weight; // make sure the redistribution the same per loop. float change; char was_a_change; @@ -1116,7 +1153,7 @@ static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index char* change_status = MEM_mallocN(defcnt*sizeof(char), "defflags"); MDeformWeight *dw; for(i = 0; i < defcnt; i++) { - if(pnt_dw->def_nr == i || !map[i]) { + if(def_nr == i || (multipaint && selection[i]) || !map[i]) { change_status[i] = FALSE; } else { change_status[i] = !flags[i]; @@ -1135,19 +1172,19 @@ static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index do { was_a_change = FALSE; for(i = 0; i < dvert->totweight; i++) { - dw = (dvert->dw+i); + dw = defvert_verify_index(dvert, i); if(!change_status[dw->def_nr]) { continue; } - dw->weight += change; old_change_left = change_left; change_left -= change; // sign change? if(change_left!=0 && change_left/fabs(change_left) != old_change_left/fabs(old_change_left)) { - dw->weight -= change; change_left = old_change_left; break; + } else { + dw->weight += change; } if(dw->weight >= 1.0f) { @@ -1163,53 +1200,57 @@ static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index groups_left_that_can_change--; change_status[dw->def_nr] = FALSE; } - was_a_change = TRUE; /* if it was too small, don't get stuck in an infinite loop! */ - if(old_change_left == change_left) { - change *= 2; + if(old_change_left != change_left) { + was_a_change = TRUE; } } } while(groups_left_that_can_change > 0 && change_left != 0.0f && was_a_change); } + // now it should never have any left, unless there are precision problems // add any remaining change back to the original weight - pnt_dw->weight += change_left; + if(change_left > 0) { + if(multipaint) { + for(i = 0; i < defcnt; i++) { + if(selection[i]) { + defvert_find_index(dvert, i)->weight += change_left/selected; + } + } + } else { + defvert_find_index(dvert, def_nr)->weight += change_left; + } + } MEM_freeN(change_status); } /* Jason */ /* get the change that is needed to get a valid multipaint (if it can)*/ -static float get_valid_multipaint_change(MDeformVert *dvert, MDeformWeight *dw, float oldw, char* validmap, char* bone_groups, char* selection, int defcnt) { +static float get_valid_multipaint_change(MDeformVert *dvert, float neww, float oldw, float allowed_totchange, char* validmap, char* bone_groups, char* selection, int defcnt) { int i; float change; + float tchange; MDeformWeight *w; float val; // see if you need to do anything (if it is normalized) float sumw = 0.0f; - if(oldw == 0 || !selection) { + if(allowed_totchange == 0 || oldw == 0 || !selection) { return FALSE; } - change = dw->weight/oldw; + change = neww/oldw; if(change == 1 || !change) { return FALSE; } - dw->weight = oldw; - // make sure all selected dverts exist - for(i = 0; i < defcnt; i++) { - if(selection[i]){ - defvert_verify_index(dvert, i); - } - } // see if all changes are valid before doing any - for(i = 0; i < dvert->totweight; i++) { - w = (dvert->dw+i); - if(!selection[w->def_nr] || !bone_groups[w->def_nr]) { + for(i = 0; i < defcnt; i++) { + if(!selection[i] || !bone_groups[i]) { continue; } + w = defvert_verify_index(dvert, i); // already reached the cap if(change > 1 && w->weight==1) { return FALSE; } if(w->weight == 0) { - if(selection[w->def_nr]) { + if(selection[i]) { return FALSE; } continue; @@ -1230,44 +1271,80 @@ static float get_valid_multipaint_change(MDeformVert *dvert, MDeformWeight *dw, if(validmap && sumw == 1.0f) { return FALSE; } + if(allowed_totchange>0) { + for(i = 0; i < defcnt; i++) { + w = defvert_find_index(dvert, i); + if(w && selection[i] && bone_groups[i]) { + tchange += w->weight*change; + } + } + tchange = tchange/allowed_totchange; + if(tchange < change) { + change = tchange; + } + } return change; } -static void multipaint_vgroups(MDeformVert *dvert, float change, char* bone_groups, char* selection) { +static float multipaint_vgroups(MDeformVert *dvert, float change, char* bone_groups, char* selection) { int i; + float totchange = 0.0f; + float old; MDeformWeight *w; for(i = 0; i < dvert->totweight; i++) { w = (dvert->dw+i); if(!bone_groups[w->def_nr] || !selection[w->def_nr] || w->weight == 0) { continue; } + old = w->weight; w->weight *= change; + totchange += w->weight - old; } + return totchange; } /* Jason */ static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups, char *selection, int selected, int multipaint) { float change=0.0f; - if(flags && has_locked_group(me->dvert+index, flags)) { - if(flags[dw->def_nr] || multipaint) { + float totchange=0.0f; + float allowed_totchange; + int def_nr = dw->def_nr; + float orig_change = oldw-dw->weight; + float neww = dw->weight; + dw->weight = oldw; + if(flags && (has_locked_group(me->dvert+index, flags) || flags[dw->def_nr])) { + if(flags[dw->def_nr] || (multipaint && has_locked_group_selected(defcnt, selection, flags)) || !has_unselected_unlocked_bone_group(defcnt, selection, selected, flags, bone_groups)) { // cannot change locked groups! - dw->weight = oldw; - } else if(bone_groups[dw->def_nr]) { - redistribute_weight_change(ob, me->dvert+index, index, dw, oldw, flags, defcnt, bone_groups); - do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap);//do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); - } - } else if(bone_groups[dw->def_nr]) {// disable auto normalize if the active group is not a bone group - if(multipaint && selected > 1) { - // try to alter the other bone groups in the dvert with the changed dw if possible, if it isn't, change it back - if(selection[dw->def_nr] && (change = get_valid_multipaint_change(me->dvert+index, dw, oldw, validmap, bone_groups, selection, defcnt)) > 0) { - multipaint_vgroups(me->dvert+index, change, bone_groups, selection); - do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap); - }else { - // multi-paint failed - dw->weight = oldw; + } else if((allowed_totchange = get_change_allowed_from_unlocked_bone_groups(me->dvert+index, def_nr, defcnt, selection, (int)(fabs(orig_change)/orig_change), flags, bone_groups)) != 0) { + dw = defvert_find_index(me->dvert+index, def_nr); + if (multipaint && selected > 1) { + if(selection[dw->def_nr] && (change = get_valid_multipaint_change(me->dvert+index, neww, oldw, allowed_totchange, validmap, bone_groups, selection, defcnt))) { + totchange = multipaint_vgroups(me->dvert+index, change, bone_groups, selection); + if(totchange !=0){ + redistribute_weight_change(ob, me->dvert+index, index, def_nr, multipaint, selection, selected, totchange, flags, defcnt, bone_groups); + } + } + } else if(bone_groups[dw->def_nr]) { + totchange = oldw - neww; + if(fabs(totchange) > fabs(allowed_totchange)) { + totchange = allowed_totchange; + } + if(totchange !=0){ + redistribute_weight_change(ob, me->dvert+index, index, def_nr, FALSE, selection, selected, totchange, flags, defcnt, bone_groups); + dw->weight -= totchange; + } } } - do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap); + } else if(bone_groups[dw->def_nr]) { + if(multipaint && selected > 1) { + // try to alter the other bone groups in the dvert with the changed dw if possible, if it isn't, change it back + if(selection[dw->def_nr] && (change = get_valid_multipaint_change(me->dvert+index, neww, oldw, -1, validmap, bone_groups, selection, defcnt))) { + multipaint_vgroups(me->dvert+index, change, bone_groups, selection); + } + }else { + dw->weight = neww; + } } + do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap); } /* Jason was here duplicate function I used in DerivedMesh.c*/ static char* get_selected_defgroups(Object *ob, int defcnt) { @@ -1343,10 +1420,15 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase), bone_groups); selection = get_selected_defgroups(ob, defcnt); selected = count_true(selection, defcnt); + if(!selected && ob->actdef) { + selected = 1; + } oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, flip); /* Jason was here */ check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); + // dvert may have been altered greatly + dw = defvert_find_index(me->dvert+index, vgroup); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); From 0e7a42ebfa7bb184963bc5b36bb282d0bd2d9e50 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 16 Jun 2011 19:05:05 +0000 Subject: [PATCH 19/68] Made Multi-Paint and Locking more independent to better support future features. (an if statement surrounding Multi-Paint still checks the lock flags to see if it should bother changing anything) Also, I changed lock's redistribution method so that if there was no enough space on other unlocked groups, it tries to keep the new weights' ratios to each other --- .../blender/blenkernel/intern/DerivedMesh.c | 18 +- .../editors/sculpt_paint/paint_vertex.c | 413 +++++++++--------- 2 files changed, 210 insertions(+), 221 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index b0eb547f826..0e4f5e0a552 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1612,8 +1612,6 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u Mesh *me = ob->data; float colf[4], input = 0.0f, unsel_sum = 0.0f;// Jason int i; - //Jason, a dw might be absent from dvert, so count the dw's you find - // to see if it should be disabled in multipaint int cnt = 0; char make_black = FALSE; @@ -1622,12 +1620,10 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u // Jason was here if(multipaint && selected > 1) { if(dg_flags[me->dvert[vert].dw[i].def_nr]) { - if(!me->dvert[vert].dw[i].weight) { - make_black = TRUE; - break; + if(me->dvert[vert].dw[i].weight) { + input+=me->dvert[vert].dw[i].weight; + cnt++; } - input+=me->dvert[vert].dw[i].weight; - cnt++; } // TODO unselected non-bone groups should not be involved in this sum else if(auto_normalize) { @@ -1638,11 +1634,11 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u } } // Jason was here - if(multipaint && selected > 1 && !make_black) { - if(cnt!=selected || input == 1.0f && auto_normalize && !unsel_sum) { + if(multipaint && selected > 1) { + if(cnt == 0 || input == 1.0f && auto_normalize && !unsel_sum) { make_black = TRUE; - } else { - input/=selected; + } else if (!auto_normalize){ + input /= selected; } } } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 560ee550aed..54956134ea9 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1029,7 +1029,7 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } } // Jason was here: the active group should be involved in auto normalize -static void do_weight_paint_auto_normalize_change_act_group(MDeformVert *dvert, char *map) +static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map) { // MDeformWeight *dw = dvert->dw; float sum=0.0f, fac=0.0f; @@ -1107,22 +1107,7 @@ static int has_locked_group_selected(int defcnt, char *selection, char *flags) { } return FALSE; } -/* Jason was here */ -static float get_change_allowed_from_unlocked_bone_groups(MDeformVert *dvert, int def_nr, int defcnt, char *selection, int pos, char *flags, char *bone_groups) { - int i; - float allowed_totchange = 0.0f; - for(i = 0; i < defcnt; i++) { - if(def_nr != i && bone_groups[i] && !selection[i] && !flags[i]) { - // positive change - if(pos == 1) { - allowed_totchange -= 1-defvert_verify_index(dvert, i)->weight; - } else {//negative change - allowed_totchange -= defvert_verify_index(dvert, i)->weight; - } - } - } - return allowed_totchange; -} + /* Jason was here */ static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int selected, char *flags, char *bone_groups) { int i; @@ -1136,216 +1121,222 @@ static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int s } return FALSE; } -/* -The idea behind this function is to get the difference in weight, -and to redistribute that weight to the unlocked groups -(if it has to, then it will put some/all of the change -back onto the original group) -*/ -static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index, int def_nr, int multipaint, char *selection, int selected, float change_left, char* flags, int defcnt, char *map) -{ + +/*Jason*/ +static void multipaint_selection(MDeformVert *dvert, float change, char *selection, int defcnt) { int i; - float old_change_left; - // make sure the redistribution the same per loop. - float change; - char was_a_change; - int groups_left_that_can_change = 0; - char* change_status = MEM_mallocN(defcnt*sizeof(char), "defflags"); MDeformWeight *dw; + // make sure they are all at most 1 after the change for(i = 0; i < defcnt; i++) { - if(def_nr == i || (multipaint && selection[i]) || !map[i]) { - change_status[i] = FALSE; - } else { - change_status[i] = !flags[i]; - } - if(change_status[i]) { - groups_left_that_can_change++; - defvert_verify_index(dvert, i); - } - } - if(groups_left_that_can_change > 0) { - change = change_left/groups_left_that_can_change; - /* the division could cause it to be zero, so if it is, forget it*/ - if(change == 0) { - change = change_left; - } - do { - was_a_change = FALSE; - for(i = 0; i < dvert->totweight; i++) { - dw = defvert_verify_index(dvert, i); - if(!change_status[dw->def_nr]) { - continue; - } - - old_change_left = change_left; - change_left -= change; - // sign change? - if(change_left!=0 && change_left/fabs(change_left) != old_change_left/fabs(old_change_left)) { - change_left = old_change_left; - break; - } else { - dw->weight += change; - } - if(dw->weight >= 1.0f) { - - change_left += dw->weight-1.0f; - dw->weight = 1.0f; - groups_left_that_can_change--; - change_status[dw->def_nr] = FALSE; - - }else if(dw->weight <= 0.0f) { - - change_left += dw->weight; - dw->weight = 0.0f; - groups_left_that_can_change--; - change_status[dw->def_nr] = FALSE; - } - /* if it was too small, don't get stuck in an infinite loop! */ - if(old_change_left != change_left) { - was_a_change = TRUE; + if(selection[i]) { + dw = defvert_find_index(dvert, i); + if(dw && dw->weight) { + if(dw->weight * change > 1) { + change = 1.0f/dw->weight; } } - } while(groups_left_that_can_change > 0 && change_left != 0.0f && was_a_change); - } - // now it should never have any left, unless there are precision problems - // add any remaining change back to the original weight - if(change_left > 0) { - if(multipaint) { - for(i = 0; i < defcnt; i++) { - if(selection[i]) { - defvert_find_index(dvert, i)->weight += change_left/selected; - } - } - } else { - defvert_find_index(dvert, def_nr)->weight += change_left; } } - MEM_freeN(change_status); + for(i = 0; i < defcnt; i++) { + if(selection[i]) { + dw = defvert_find_index(dvert, i); + if(dw && dw->weight) { + dw->weight = dw->weight * change; + } + } + } } -/* Jason */ -/* get the change that is needed to get a valid multipaint (if it can)*/ -static float get_valid_multipaint_change(MDeformVert *dvert, float neww, float oldw, float allowed_totchange, char* validmap, char* bone_groups, char* selection, int defcnt) { - int i; +/*Jason*/ +static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, char *validmap, float totchange, float total_valid) { + float was_change; float change; - float tchange; - MDeformWeight *w; - float val; - // see if you need to do anything (if it is normalized) - float sumw = 0.0f; - if(allowed_totchange == 0 || oldw == 0 || !selection) { - return FALSE; - } - change = neww/oldw; - if(change == 1 || !change) { - return FALSE; - } - // see if all changes are valid before doing any - for(i = 0; i < defcnt; i++) { - if(!selection[i] || !bone_groups[i]) { - continue; - } - w = defvert_verify_index(dvert, i); - // already reached the cap - if(change > 1 && w->weight==1) { - return FALSE; - } - if(w->weight == 0) { - if(selection[i]) { - return FALSE; - } - continue; - } - val = w->weight*change; - // no success here-I'm not going to force it to try to be just above 0 by changing 'change' - if(val <= 0) { - return FALSE; - } - if (validmap){ - sumw += w->weight; - }else if(val > 1) { - // use the transitive property to make magic, all of the others - // will still end up within the boundaries if the worst case does - change = 1.0f/w->weight; - } - } - if(validmap && sumw == 1.0f) { - return FALSE; - } - if(allowed_totchange>0) { - for(i = 0; i < defcnt; i++) { - w = defvert_find_index(dvert, i); - if(w && selection[i] && bone_groups[i]) { - tchange += w->weight*change; - } - } - tchange = tchange/allowed_totchange; - if(tchange < change) { - change = tchange; - } - } - return change; -} -static float multipaint_vgroups(MDeformVert *dvert, float change, char* bone_groups, char* selection) { + float oldval; + MDeformWeight *ndw; int i; - float totchange = 0.0f; - float old; - MDeformWeight *w; - for(i = 0; i < dvert->totweight; i++) { - w = (dvert->dw+i); - if(!bone_groups[w->def_nr] || !selection[w->def_nr] || w->weight == 0) { - continue; + do { + was_change = FALSE; + change = totchange/total_valid; + for(i = 0; i < ndv->totweight && total_valid && totchange; i++) { + ndw = (ndv->dw+i); + if(change_status[ndw->def_nr] == changeme) { + oldval = ndw->weight; + if(!validmap && ndw->weight + change > 1) { + totchange -= 1-ndw->weight; + ndw->weight = 1; + change_status[ndw->def_nr] = changeto; + total_valid--; + } else if(ndw->weight + change < 0) { + totchange -= ndw->weight; + ndw->weight = 0; + change_status[ndw->def_nr] = changeto; + total_valid--; + } else { + totchange -= change; + ndw->weight += change; + } + if(oldval != ndw->weight) { + was_change = TRUE; + } + } } - old = w->weight; - w->weight *= change; - totchange += w->weight - old; - } + }while(was_change && total_valid && totchange); return totchange; } -/* Jason */ -static void check_locks_and_normalize(Object *ob, Mesh *me, int index, int vgroup, MDeformWeight *dw, float oldw, char *validmap, char *flags, int defcnt, char *bone_groups, char *selection, int selected, int multipaint) -{ - float change=0.0f; - float totchange=0.0f; - float allowed_totchange; - int def_nr = dw->def_nr; - float orig_change = oldw-dw->weight; - float neww = dw->weight; - dw->weight = oldw; - if(flags && (has_locked_group(me->dvert+index, flags) || flags[dw->def_nr])) { - if(flags[dw->def_nr] || (multipaint && has_locked_group_selected(defcnt, selection, flags)) || !has_unselected_unlocked_bone_group(defcnt, selection, selected, flags, bone_groups)) { - // cannot change locked groups! - } else if((allowed_totchange = get_change_allowed_from_unlocked_bone_groups(me->dvert+index, def_nr, defcnt, selection, (int)(fabs(orig_change)/orig_change), flags, bone_groups)) != 0) { - dw = defvert_find_index(me->dvert+index, def_nr); - if (multipaint && selected > 1) { - if(selection[dw->def_nr] && (change = get_valid_multipaint_change(me->dvert+index, neww, oldw, allowed_totchange, validmap, bone_groups, selection, defcnt))) { - totchange = multipaint_vgroups(me->dvert+index, change, bone_groups, selection); - if(totchange !=0){ - redistribute_weight_change(ob, me->dvert+index, index, def_nr, multipaint, selection, selected, totchange, flags, defcnt, bone_groups); - } - } - } else if(bone_groups[dw->def_nr]) { - totchange = oldw - neww; - if(fabs(totchange) > fabs(allowed_totchange)) { - totchange = allowed_totchange; - } - if(totchange !=0){ - redistribute_weight_change(ob, me->dvert+index, index, def_nr, FALSE, selection, selected, totchange, flags, defcnt, bone_groups); - dw->weight -= totchange; - } +/*Jason*/ +static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char *flags, char *bone_groups, char *validmap) { + float totchange = 0.0f; + float totchange_allowed = 0.0f; + float left_over; + float change; + int total_valid = 0; + int total_changed = 0; + int i; + MDeformWeight *ndw; + MDeformWeight *odw; + MDeformWeight *ndw2; + MDeformWeight *odw2; + int designatedw = -1; + int designatedw_changed = FALSE; + float storedw; + char *change_status; + char new_weight_has_zero = FALSE; + + if(!flags || !has_locked_group(ndv, flags)) { + return; + } + + change_status = MEM_callocN(sizeof(char)*defcnt, "unlocked_unchanged"); + + for(i = 0; i < defcnt; i++) { + ndw = defvert_find_index(ndv, i); + odw = defvert_find_index(odv, i); + if(!ndw || !odw) { + if (!flags[i] && bone_groups[i]){ + defvert_verify_index(odv, i); + defvert_verify_index(ndv, i); + total_valid++; + change_status[i] = 1; // can be altered while redistributing } + continue; } - } else if(bone_groups[dw->def_nr]) { - if(multipaint && selected > 1) { - // try to alter the other bone groups in the dvert with the changed dw if possible, if it isn't, change it back - if(selection[dw->def_nr] && (change = get_valid_multipaint_change(me->dvert+index, neww, oldw, -1, validmap, bone_groups, selection, defcnt))) { - multipaint_vgroups(me->dvert+index, change, bone_groups, selection); + if(flags[i]) { + ndw->weight = odw->weight; + } else if(ndw->weight != odw->weight) { + totchange += ndw->weight-odw->weight; + change_status[i] = 2; // was altered already + total_changed++; + if(ndw->weight == 0) { + new_weight_has_zero = TRUE; + } else if(!designatedw){ + designatedw = i; } - }else { - dw->weight = neww; + } else if (bone_groups[i]){ + totchange_allowed += ndw->weight; + total_valid++; + change_status[i] = 1; // can be altered while redistributing } } - do_weight_paint_auto_normalize_change_act_group(me->dvert+index, validmap); + if(total_changed) { + if(totchange_allowed) { + if(totchange < 0) { + totchange_allowed = total_valid - totchange_allowed; + } else { + totchange_allowed *= -1; + } + left_over = 0; + if(fabs(totchange_allowed) < fabs(totchange)) { + left_over = fabs(fabs(totchange)-fabs(totchange_allowed)); + if(totchange > 0) { + left_over *= -1; + } + }else { + totchange_allowed = -totchange; + } + // move the weight evenly between the allowed groups, move excess back onto the used groups based on the change + totchange_allowed = redistribute_change(ndv, change_status, 1, -1, validmap, totchange_allowed, total_valid); + left_over += totchange_allowed; + if(left_over) { + // more than one nonzero weights were changed with the same ratio, so keep them changed that way! + if(total_changed > 1 && !new_weight_has_zero) { + ndw = defvert_find_index(ndv, designatedw); + odw = defvert_find_index(odv, designatedw); + storedw = ndw->weight; + for(i = 0; i < ndv->totweight; i++) { + if(change_status[ndw->def_nr] == 2) { + odw2 = (odv->dw+i); + ndw2 = (ndv->dw+i); + if(!designatedw_changed) { + ndw->weight = (totchange_allowed + odw->weight + odw2->weight)/(1 + ndw2->weight/ndw->weight); + designatedw_changed = TRUE; + } + ndw2->weight = ndw->weight*ndw2->weight/storedw; + } + } + } + // a weight was changed to zero, or only one weight was changed + // put weight back as evenly as possible + else { + redistribute_change(ndv, change_status, 2, -2, validmap, left_over, total_changed); + } + } + } else { + // reset the weights + for(i = 0; i < ndv->totweight; i++) { + (ndv->dw+i)->weight = (odv->dw+i)->weight; + } + } + } + + MEM_freeN(change_status); } +/*Jason*/ +static float get_mp_change(MDeformVert *odv, char *selection, float oldw, float neww) { + int i; + + if(oldw) { + return neww/oldw; + } + + for(i = 0; i < odv->totweight; i++) { + if(selection[(odv->dw+i)->def_nr]) { + if((odv->dw+i)->weight) { + return ((odv->dw+i)->weight+neww) / (odv->dw+i)->weight; + } + } + } + return 0; +} +/*Jason*/ +/* fresh start to make multi-paint and locking modular */ +static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float oldw, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { + MDeformVert *dvert = me->dvert+index; + MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); + float neww = dw->weight; + float change = 0.0f; + int i; + dw->weight = oldw; + + //defvert_copy(dv, dvert); + dv->dw= MEM_dupallocN(dvert->dw); + dv->flag = dvert->flag; + dv->totweight = dvert->totweight; + + if(!flags || flags && !has_locked_group_selected(defcnt, selection, flags) && !flags[dw->def_nr]) {// !flags[dw->def_nr] helps if nothing is selected, but active group is locked + if(multipaint && selected > 1 && (change = get_mp_change(dv, selection, oldw, neww)) && change!=1) { + multipaint_selection(dvert, change, selection, defcnt); + } else { + dw->weight = neww; + change = 0.0f; + } + } + enforce_locks(dv, dvert, defcnt, flags, bone_groups, validmap); + + do_weight_paint_auto_normalize_all_groups(dvert, validmap); + + MEM_freeN(dv->dw); + MEM_freeN(dv); +} + /* Jason was here duplicate function I used in DerivedMesh.c*/ static char* get_selected_defgroups(Object *ob, int defcnt) { bPoseChannel *chan; @@ -1426,7 +1417,8 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, flip); /* Jason was here */ - check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); + apply_mp_lcks_normalize(ob, me, index, dw, defcnt, oldw, selection, selected, bone_groups, validmap, flags, multipaint); + //check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); // dvert may have been altered greatly dw = defvert_find_index(me->dvert+index, vgroup); @@ -1443,7 +1435,8 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw->weight= dw->weight; /* Jason */ - check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); + apply_mp_lcks_normalize(ob, me, j, uw, defcnt, oldw, selection, selected, bone_groups, validmap, flags, multipaint); + //check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); } } /* Jason */ From 1876b592daffb86a60890b9f8db55d676d7cae1c Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 21 Jun 2011 19:20:42 +0000 Subject: [PATCH 20/68] Tweaked multi-paint and the way the colors are displayed so one of the artists could see it- when you paint the active group, and makes the others match based on the change factor; so the active group being 0 is not handled. --- .../blender/blenkernel/intern/DerivedMesh.c | 22 ++++- .../editors/sculpt_paint/paint_vertex.c | 80 +++++++++++++------ 2 files changed, 73 insertions(+), 29 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 0e4f5e0a552..1e8bba01717 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1612,18 +1612,27 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u Mesh *me = ob->data; float colf[4], input = 0.0f, unsel_sum = 0.0f;// Jason int i; - int cnt = 0; char make_black = FALSE; + char was_a_nonzero = FALSE; + char actdef_nonzero = FALSE; if (me->dvert) { for (i=0; idvert[vert].totweight; i++) { // Jason was here if(multipaint && selected > 1) { if(dg_flags[me->dvert[vert].dw[i].def_nr]) { + if(ob->actdef-1 == me->dvert[vert].dw[i].def_nr) { + if (me->dvert[vert].dw[i].weight == 0) { + //make_black = TRUE; + break; + } + actdef_nonzero = TRUE; + } if(me->dvert[vert].dw[i].weight) { input+=me->dvert[vert].dw[i].weight; - cnt++; + was_a_nonzero = TRUE; } + } // TODO unselected non-bone groups should not be involved in this sum else if(auto_normalize) { @@ -1633,13 +1642,18 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u input+=me->dvert[vert].dw[i].weight; } } + // Jason was here - if(multipaint && selected > 1) { - if(cnt == 0 || input == 1.0f && auto_normalize && !unsel_sum) { + if(!make_black && multipaint && selected > 1) { + /*if(input == 1.0f && auto_normalize && !unsel_sum) { + make_black = TRUE; + } else */ + if(!(was_a_nonzero && actdef_nonzero)) { make_black = TRUE; } else if (!auto_normalize){ input /= selected; } + } } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 54956134ea9..925ed8af99c 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -812,7 +812,8 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float if (dw->weight > paintval) dw->weight = paintval*alpha + dw->weight*(1.0f-alpha); } - CLAMP(dw->weight, 0.0f, 1.0f); + // Jason delay clamping until the end so multi-paint can function when the active group is at the limits + //CLAMP(dw->weight, 0.0f, 1.0f); /* if no spray, clip result with orig weight & orig alpha */ if((wp->flag & VP_SPRAY)==0) { @@ -839,7 +840,7 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float else testw = uw->weight; } - CLAMP(testw, 0.0f, 1.0f); + //CLAMP(testw, 0.0f, 1.0f); if( testwweight ) { if(dw->weight < testw) dw->weight= testw; @@ -1126,12 +1127,14 @@ static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int s static void multipaint_selection(MDeformVert *dvert, float change, char *selection, int defcnt) { int i; MDeformWeight *dw; + float val; // make sure they are all at most 1 after the change for(i = 0; i < defcnt; i++) { if(selection[i]) { dw = defvert_find_index(dvert, i); if(dw && dw->weight) { - if(dw->weight * change > 1) { + val = dw->weight * change; + if(val > 1) { change = 1.0f/dw->weight; } } @@ -1237,6 +1240,10 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * } } if(total_changed) { + // auto normalize will allow weights to temporarily go above 1 in redistribution + if(validmap && total_changed < 0 && total_valid) { + totchange_allowed = total_valid; + } if(totchange_allowed) { if(totchange < 0) { totchange_allowed = total_valid - totchange_allowed; @@ -1291,32 +1298,45 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * } /*Jason*/ static float get_mp_change(MDeformVert *odv, char *selection, float oldw, float neww) { - int i; - if(oldw) { return neww/oldw; } - - for(i = 0; i < odv->totweight; i++) { - if(selection[(odv->dw+i)->def_nr]) { - if((odv->dw+i)->weight) { - return ((odv->dw+i)->weight+neww) / (odv->dw+i)->weight; - } - } - } return 0; } /*Jason*/ +/*static void reset_to_prev(VPaint *wv, MDeformVert *dv, int vgroup) { + int i; + MDeformWeight *d; + MDeformWeight *w; + for(i = 0; i < dv->totweight; i++) { + d = dv->dw+i; + if(d->def_nr == vgroup) { + continue; + } + w = defvert_find_index(wv, d->def_nr); + if(w) { + d->weight = w->weight; + } else { + d->weight = 0; + } + } +}*/ +/* Jason */ +static void clamp_weights(MDeformVert *dvert) { + int i; + for (i = 0; i < dvert->totweight; i++) { + CLAMP((dvert->dw+i)->weight, 0.0f, 1.0f); + } +} +/*Jason*/ /* fresh start to make multi-paint and locking modular */ -static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float oldw, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { +static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { MDeformVert *dvert = me->dvert+index; MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); - float neww = dw->weight; float change = 0.0f; int i; dw->weight = oldw; - - //defvert_copy(dv, dvert); + dv->dw= MEM_dupallocN(dvert->dw); dv->flag = dvert->flag; dv->totweight = dvert->totweight; @@ -1329,6 +1349,8 @@ static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeig change = 0.0f; } } + clamp_weights(me->dvert+index); + enforce_locks(dv, dvert, defcnt, flags, bone_groups, validmap); do_weight_paint_auto_normalize_all_groups(dvert, validmap); @@ -1390,7 +1412,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, char *selection; int selected; float oldw; + float neww; int defcnt; + int i; if(validmap) { bone_groups = validmap; }else { @@ -1414,11 +1438,19 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(!selected && ob->actdef) { selected = 1; } + oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, flip); + neww = dw->weight; + if(selected > 1 && multipaint) { + if(!oldw || neww <= 0) { + neww = oldw; + dw->weight = oldw; + } + } /* Jason was here */ - apply_mp_lcks_normalize(ob, me, index, dw, defcnt, oldw, selection, selected, bone_groups, validmap, flags, multipaint); - //check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); + apply_mp_lcks_normalize(ob, me, index, dw, defcnt, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); + // dvert may have been altered greatly dw = defvert_find_index(me->dvert+index, vgroup); @@ -1433,19 +1465,17 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason */ oldw = uw->weight; - uw->weight= dw->weight; + //uw->weight= dw->weight; + uw->weight = neww; /* Jason */ - apply_mp_lcks_normalize(ob, me, j, uw, defcnt, oldw, selection, selected, bone_groups, validmap, flags, multipaint); - //check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint); + apply_mp_lcks_normalize(ob, me, j, uw, defcnt, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); } } /* Jason */ if(flags) { MEM_freeN(flags); } - if(selection) { - MEM_freeN(selection); - } + MEM_freeN(selection); if(!validmap) { MEM_freeN(bone_groups); } From 2ecf22fff6ecb970cf0f51eb6201b4b46126a936 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 29 Jun 2011 18:20:39 +0000 Subject: [PATCH 21/68] Made multi-paint change the weight values based on the artist's suggestion. + fixed a huge problem with reseting the weights while using multi-paint. --- .../blender/blenkernel/intern/DerivedMesh.c | 11 +- .../editors/sculpt_paint/paint_vertex.c | 120 +++++++++++++----- 2 files changed, 86 insertions(+), 45 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 1e8bba01717..74fbd59720e 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1614,25 +1614,16 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u int i; char make_black = FALSE; char was_a_nonzero = FALSE; - char actdef_nonzero = FALSE; if (me->dvert) { for (i=0; idvert[vert].totweight; i++) { // Jason was here if(multipaint && selected > 1) { if(dg_flags[me->dvert[vert].dw[i].def_nr]) { - if(ob->actdef-1 == me->dvert[vert].dw[i].def_nr) { - if (me->dvert[vert].dw[i].weight == 0) { - //make_black = TRUE; - break; - } - actdef_nonzero = TRUE; - } if(me->dvert[vert].dw[i].weight) { input+=me->dvert[vert].dw[i].weight; was_a_nonzero = TRUE; } - } // TODO unselected non-bone groups should not be involved in this sum else if(auto_normalize) { @@ -1648,7 +1639,7 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u /*if(input == 1.0f && auto_normalize && !unsel_sum) { make_black = TRUE; } else */ - if(!(was_a_nonzero && actdef_nonzero)) { + if(!was_a_nonzero) { make_black = TRUE; } else if (!auto_normalize){ input /= selected; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 4e2e13b81cd..8e186265577 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -792,7 +792,7 @@ static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], fl return alpha; } -static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval, int flip) +static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval, int flip, int multipaint) { Brush *brush = paint_brush(&wp->paint); int tool = brush->vertexpaint_tool; @@ -859,14 +859,15 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float testw = uw->weight; } //CLAMP(testw, 0.0f, 1.0f); - - if( testwweight ) { - if(dw->weight < testw) dw->weight= testw; - else if(dw->weight > uw->weight) dw->weight= uw->weight; - } - else { - if(dw->weight > testw) dw->weight= testw; - else if(dw->weight < uw->weight) dw->weight= uw->weight; + if(!multipaint) { + if( testwweight ) { + if(dw->weight < testw) dw->weight= testw; + else if(dw->weight > uw->weight) dw->weight= uw->weight; + } + else { + if(dw->weight > testw) dw->weight= testw; + else if(dw->weight < uw->weight) dw->weight= uw->weight; + } } } @@ -1205,6 +1206,9 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *selecti if(val > 1) { change = 1.0f/dw->weight; } + if(val <= 0) { + return; + } } } } @@ -1365,22 +1369,27 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * MEM_freeN(change_status); } /*Jason*/ -static float get_mp_change(MDeformVert *odv, char *selection, float oldw, float neww) { - if(oldw) { - return neww/oldw; +static float get_mp_change(MDeformVert *odv, char *selection, float brush_change) { + float selwsum = 0.0f; + int i; + MDeformWeight *dw; + for(i=0; i < odv->totweight; i++) { + if(selection[(dw = (odv->dw+i))->def_nr]) { + selwsum += dw->weight; + } } - return 0; + if(selwsum && selwsum+brush_change > 0) { + return (selwsum+brush_change)/selwsum; + } + return 0.0f; } /*Jason*/ -/*static void reset_to_prev(VPaint *wv, MDeformVert *dv, int vgroup) { +static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { int i; MDeformWeight *d; MDeformWeight *w; for(i = 0; i < dv->totweight; i++) { d = dv->dw+i; - if(d->def_nr == vgroup) { - continue; - } w = defvert_find_index(wv, d->def_nr); if(w) { d->weight = w->weight; @@ -1388,7 +1397,7 @@ static float get_mp_change(MDeformVert *odv, char *selection, float oldw, float d->weight = 0; } } -}*/ +} /* Jason */ static void clamp_weights(MDeformVert *dvert) { int i; @@ -1398,23 +1407,23 @@ static void clamp_weights(MDeformVert *dvert) { } /*Jason*/ /* fresh start to make multi-paint and locking modular */ -static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { +static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float change, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { MDeformVert *dvert = me->dvert+index; MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); - float change = 0.0f; + //float change = 0.0f; int i; - dw->weight = oldw; - + dv->dw= MEM_dupallocN(dvert->dw); dv->flag = dvert->flag; dv->totweight = dvert->totweight; if(!flags || flags && !has_locked_group_selected(defcnt, selection, flags) && !flags[dw->def_nr]) {// !flags[dw->def_nr] helps if nothing is selected, but active group is locked - if(multipaint && selected > 1 && (change = get_mp_change(dv, selection, oldw, neww)) && change!=1) { - multipaint_selection(dvert, change, selection, defcnt); + if(multipaint && selected > 1) { + if(change && change!=1) { + multipaint_selection(dvert, change, selection, defcnt); + } } else { dw->weight = neww; - change = 0.0f; } } clamp_weights(me->dvert+index); @@ -1463,6 +1472,17 @@ static int count_true(char *list, int len) } return cnt; } +static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *selection) { + int i; + MDeformWeight *dw; + for(i=0; i< dvert->totweight; i++) { + dw = dvert->dw+i; + if(selection[dw->def_nr] && dw->weight > 0) { + return i; + } + } + return -1; +} // Jason static char *wpaint_make_validmap(Object *ob); @@ -1471,7 +1491,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int vgroup_mirror, char *validmap, int multipaint) { Mesh *me= ob->data; - MDeformWeight *dw, *uw; + MDeformWeight *dw, *uw, *tdw, *tuw; int vgroup= ob->actdef-1; /* Jason was here */ @@ -1481,7 +1501,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int selected; float oldw; float neww; + float testw; int defcnt; + float change = 0; int i; if(validmap) { bone_groups = validmap; @@ -1508,16 +1530,47 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } oldw = dw->weight; - wpaint_blend(wp, dw, uw, alpha, paintweight, flip); + wpaint_blend(wp, dw, uw, alpha, paintweight, flip, multipaint && selected >1); neww = dw->weight; + dw->weight = oldw; if(selected > 1 && multipaint) { - if(!oldw || neww <= 0) { - neww = oldw; - dw->weight = oldw; + tdw = dw; + tuw = uw; + change = get_mp_change(wp->wpaint_prev+index, selection, neww-oldw); + if(change) { + if(!tdw->weight) { + i = get_first_selected_nonzero_weight(me->dvert+index, selection); + if(i>=0) { + tdw = ((me->dvert+index)->dw+i); + tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); + } else { + change = 0; + } + } + if(change && tdw->weight * change && tuw->weight) { + if(tdw->weight != tuw->weight) { + testw = tuw->weight*change; + if( testw > tuw->weight ) { + if(change > tdw->weight/tuw->weight) { + reset_to_prev(wp->wpaint_prev+index, me->dvert+index); + } else { + change = 0; + } + } else { + if(change < tdw->weight/tuw->weight) { + reset_to_prev(wp->wpaint_prev+index, me->dvert+index); + } else { + change = 0; + } + } + } + } else { + change = 0; + } } } /* Jason was here */ - apply_mp_lcks_normalize(ob, me, index, dw, defcnt, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); + apply_mp_lcks_normalize(ob, me, index, dw, defcnt, change, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); // dvert may have been altered greatly dw = defvert_find_index(me->dvert+index, vgroup); @@ -1531,12 +1584,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, else uw= defvert_verify_index(me->dvert+j, vgroup); /* Jason */ - oldw = uw->weight; - //uw->weight= dw->weight; - uw->weight = neww; /* Jason */ - apply_mp_lcks_normalize(ob, me, j, uw, defcnt, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); + apply_mp_lcks_normalize(ob, me, j, uw, defcnt, change, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); } } /* Jason */ From 5d720bb98d942faae5cfe6498f147946a6d763fd Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 5 Jul 2011 18:03:31 +0000 Subject: [PATCH 22/68] Added Selection support to weight paint. "Started" putting in wp's circle select, but it isn't there yet. --- .../blender/blenkernel/intern/cdderivedmesh.c | 6 +- source/blender/editors/include/ED_mesh.h | 3 +- source/blender/editors/include/ED_view3d.h | 3 + source/blender/editors/mesh/editmesh.c | 34 ++++++ .../editors/sculpt_paint/paint_vertex.c | 1 + .../blender/editors/space_view3d/drawobject.c | 40 +++++++ .../editors/space_view3d/view3d_select.c | 112 +++++++++++++++++- 7 files changed, 193 insertions(+), 6 deletions(-) diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index a7451a2ce80..d850cb57c64 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -277,12 +277,14 @@ static void cdDM_drawSelectedVerts(DerivedMesh *dm) if( GPU_buffer_legacy(dm) ) { glBegin(GL_POINTS); for(i = 0; i < dm->numVertData; i++, mv++) { - if(mv->flag & 1) {//TODO define selected + if((mv->flag & 1)) {//TODO define selected glColor3f(1.0f, 1.0f, 0.0f); }else { glColor3f(0.0f, 0.0f, 0.0f); } - glVertex3fv(mv->co); + if(!(mv->flag & ME_HIDE)) { + glVertex3fv(mv->co); + } } glEnd(); } diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 8bb77ad43a0..cdad34a9d42 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -122,7 +122,8 @@ int EM_texFaceCheck(struct EditMesh *em); int EM_vertColorCheck(struct EditMesh *em); void undo_push_mesh(struct bContext *C, const char *name); - +/* Jason */ +void paintvert_flush_flags(struct Object *ob); /* editmesh_lib.c */ diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index dfe0a304748..62feeb151fa 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -215,6 +215,9 @@ void ED_view3d_project_float(struct ARegion *a, const float vec[3], float adr[2] void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short do_shift); /* drawobject.c iterators */ +/*Jason*/ +void mesh_obmode_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct MVert *mv, int x, int y, int index), void *userData, int clipVerts); + void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts); void mesh_foreachScreenEdge(struct ViewContext *vc, void (*func)(void *userData, struct EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts); void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData, struct EditFace *efa, int x, int y, int index), void *userData); diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index ec08bfccda3..feaa1899059 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -1959,3 +1959,37 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc) vc->em= me->edit_mesh; } } + + +/* Jason (similar to void paintface_flush_flags(Object *ob)) + * copy the vertex flags, most importantly selection from the mesh to the final derived mesh, + * use in object mode when selecting vertices (while painting) */ +void paintvert_flush_flags(Object *ob) +{ + Mesh *me= get_mesh(ob); + DerivedMesh *dm= ob->derivedFinal; + MVert *verts, *mv, *mv_orig; + int *index_array = NULL; + int totvert; + int i; + + if(me==NULL || dm==NULL) + return; + + index_array = dm->getVertDataArray(dm, CD_ORIGINDEX); + + verts = dm->getVertArray(dm); + totvert = dm->getNumVerts(dm); + + mv= verts; + + for (i= 0; imvert + index_array[i]; + mv->flag= mv_orig->flag; + } else { + mv_orig= me->mvert + i; + mv->flag= mv_orig->flag; + } + } +} \ No newline at end of file diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 8e186265577..c8475378f56 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1204,6 +1204,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *selecti if(dw && dw->weight) { val = dw->weight * change; if(val > 1) { + // Jason TODO: when the change is reduced, you need to recheck the earlier values to make sure they are not 0 (precision error) change = 1.0f/dw->weight; } if(val <= 0) { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index bc5c73b9814..22233b895cb 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -58,6 +58,7 @@ #include "BKE_anim.h" //for the where_on_path function #include "BKE_constraint.h" // for the get_constraint_target function #include "BKE_DerivedMesh.h" + #include "BKE_deform.h" #include "BKE_displist.h" #include "BKE_font.h" @@ -1657,7 +1658,45 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe dm->release(dm); } +/*Jason */ +static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) +{ + struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData; + Mesh *me = data->vc.obact->data; + MVert *mv = me->mvert+index; + //MVert *dmv = CDDM_get_verts(data->vc.obact->derivedFinal)+index; + //MVert *mv = CDDM_get_verts(data->vc.obact->derivedFinal)+index; + if ((mv->flag & ME_HIDE)==0) { + short s[2]= {IS_CLIPPED, 0}; + if (data->clipVerts) { + view3d_project_short_clip(data->vc.ar, co, s, 1); + } else { + view3d_project_short_noclip(data->vc.ar, co, s); + } + + if (s[0]!=IS_CLIPPED) + data->func(data->userData, me->mvert, s[0], s[1], index); + } +} +/*Jason*/ +void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, MVert *mv, int x, int y, int index), void *userData, int clipVerts) +{ + struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } data; + DerivedMesh *dm = mesh_get_derived_final(vc->scene, vc->obact, CD_MASK_BAREMESH); + + data.vc= *vc; + data.func = func; + data.userData = userData; + data.clipVerts = clipVerts; + + if(clipVerts) + ED_view3d_local_clipping(vc->rv3d, vc->obact->obmat); /* for local clipping lookups */ + + dm->foreachMappedVert(dm, mesh_obmode_foreachScreenVert__mapFunc, &data); + + dm->release(dm); +} static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co) { struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData; @@ -2744,6 +2783,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D dm->drawEdges(dm, (dt==OB_WIRE || totface==0), me->drawflag); glPointSize(3.0f); dm->drawSelectedVerts(dm); + //draw_obmode_dm_verts(dm, 1); glPointSize(1.0f); } } diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 9290e1fc631..19aa8ab1886 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -197,6 +197,22 @@ static void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select) } } } +/* Jason */ +static void EM_backbuf_checkAndSelectTVerts(Mesh *me, int select) +{ + MVert *mv = me->mvert; + int a; + + if (mv) { + for(a=1; a<=me->totvert; a++, mv++) { + if(EM_check_backbuf(a)) { + if(!(mv->flag & ME_HIDE)) { + mv->flag = select?(mv->flag|SELECT):(mv->flag&~SELECT); + } + } + } + } +} static void EM_backbuf_checkAndSelectTFaces(Mesh *me, int select) { @@ -1827,6 +1843,69 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) /* rna */ WM_operator_properties_gesture_border(ot, TRUE); } +/*Jason*/ +static void findnearestWPvert__doClosest(void *userData, MVert *mv, int x, int y, int index) +{ + struct { MVert *mv; short dist, select; int mval[2]; } *data = userData; + float temp = abs(data->mval[0]-x) + abs(data->mval[1]-y); + mv = mv+index; + if((mv->flag & SELECT)==data->select) + temp += 5; + + if(tempdist) { + data->dist = temp; + + data->mv = mv; + } +} +/*Jason*/ +static MVert *findnearestWPvert(ViewContext *vc, Object *obact, Mesh *me, const int mval[2], int sel) +{ + /* sel==1: selected gets a disadvantage */ + struct { MVert *mv; short dist, select; int mval[2]; } data = {NULL}; + + data.dist = 100; + data.select = sel; + data.mval[0]= mval[0]; + data.mval[1]= mval[1]; + + mesh_obmode_foreachScreenVert(vc, findnearestWPvert__doClosest, &data, 1); + + return data.mv; +} +/* Jason */ +/* mouse selection in weight paint */ +/* gets called via generic mouse select operator */ +int mouse_wp_select(bContext *C, const int mval[2], short extend, Object *obact, Mesh* me) +{ + MVert *mv; + ViewContext *vc = NULL; + vc = MEM_callocN(sizeof(ViewContext), "wp_m_sel_viewcontext"); + vc->ar= CTX_wm_region(C); + vc->scene= CTX_data_scene(C); + vc->v3d= CTX_wm_view3d(C); + vc->rv3d= CTX_wm_region_view3d(C); + vc->obact= obact; + vc->mval[0] = mval[0]; + vc->mval[1] = mval[1]; + + ED_view3d_init_mats_rv3d(obact, vc->rv3d); + + if(mv = findnearestWPvert(vc, obact, me, mval, 1)) { + if(extend) { + mv->flag ^= 1; + } else { + mv->flag |= 1; + } + paintvert_flush_flags(vc->obact); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); + + MEM_freeN(vc); + return 1; + } + MEM_freeN(vc); + return 0; +} /* ****** Mouse Select ****** */ @@ -1839,9 +1918,11 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) short center= RNA_boolean_get(op->ptr, "center"); short enumerate= RNA_boolean_get(op->ptr, "enumerate"); int retval = 0; + // Jason + Mesh *me; + Scene *scene = CTX_data_scene(C); view3d_operator_needs_opengl(C); - if(obedit) { if(obedit->type==OB_MESH) retval = mouse_mesh(C, event->mval, extend); @@ -1861,8 +1942,12 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) return PE_mouse_particles(C, event->mval, extend); else if(obact && paint_facesel_test(obact)) retval = paintface_mouse_select(C, obact, event->mval, extend); - else + /*Jason*/ + else if (scene->toolsettings->wp_vert_sel && obact && obact->mode & OB_MODE_WEIGHT_PAINT && (me = (Mesh*)(obact->data))) {//Jason + retval = mouse_wp_select(C, event->mval, extend, obact, me); + } else { retval = mouse_select(C, event->mval, extend, center, enumerate); + } /* passthrough allows tweaks * FINISHED to signal one operator worked @@ -1985,6 +2070,22 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m } } +/* Jason */ +static void paint_vertsel_circle_select(ViewContext *vc, int select, const int mval[2], float rad) +{ + Object *ob= vc->obact; + Mesh *me = ob?ob->data:NULL; + int bbsel; + + if (me) { + em_vertoffs= me->totvert+1; /* max index array */ + + bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f)); + EM_backbuf_checkAndSelectTVerts(me, select==LEFTMOUSE); + EM_free_backbuf(); + } +} + static void nurbscurve_circle_doSelect(void *userData, Nurb *UNUSED(nu), BPoint *bp, BezTriple *bezt, int beztindex, int x, int y) { @@ -2257,7 +2358,12 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); } else if(paint_facesel_test(obact)) { - paint_facesel_circle_select(&vc, select, mval, (float)radius); + /* Jason */ + if(scene->toolsettings->wp_vert_sel) { + paint_vertsel_circle_select(&vc, select, mval, (float)radius); + } else { + paint_facesel_circle_select(&vc, select, mval, (float)radius); + } WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); } else if(obact->mode & OB_MODE_POSE) From 4f8b9a4033f849417710a9ca4ba7c1d6337f89e0 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 7 Jul 2011 17:59:15 +0000 Subject: [PATCH 23/68] Removed code I no longer needed for multi-paint's newer system. Added comments to the more complex functions. --- .../startup/bl_ui/properties_data_mesh.py | 1 + .../blender/blenkernel/intern/DerivedMesh.c | 13 ++--- .../editors/sculpt_paint/paint_vertex.c | 54 +++++++++++++++---- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 3718a07446e..013ba8b44d1 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -158,6 +158,7 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel): row = layout.row() row.prop(group, "name") #Jason was here + # add buttons to make it faster to lock/unlock vgroups if ob.mode == 'WEIGHT_PAINT' and len(ob.vertex_groups) > 0: row = layout.row() sub = row.row(align=True) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 74fbd59720e..a35ad48e599 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1610,7 +1610,7 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb) static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int unselected, int multipaint, int auto_normalize) { Mesh *me = ob->data; - float colf[4], input = 0.0f, unsel_sum = 0.0f;// Jason + float colf[4], input = 0.0f;// Jason int i; char make_black = FALSE; char was_a_nonzero = FALSE; @@ -1618,6 +1618,8 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u if (me->dvert) { for (i=0; idvert[vert].totweight; i++) { // Jason was here + // in multipaint, get the average if auto normalize is inactive + // get the sum if it is active if(multipaint && selected > 1) { if(dg_flags[me->dvert[vert].dw[i].def_nr]) { if(me->dvert[vert].dw[i].weight) { @@ -1625,23 +1627,18 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u was_a_nonzero = TRUE; } } - // TODO unselected non-bone groups should not be involved in this sum - else if(auto_normalize) { - unsel_sum+=me->dvert[vert].dw[i].weight; - } } else if (me->dvert[vert].dw[i].def_nr==ob->actdef-1) { input+=me->dvert[vert].dw[i].weight; } } // Jason was here + // make it black if the selected groups have no weight on a vertex if(!make_black && multipaint && selected > 1) { - /*if(input == 1.0f && auto_normalize && !unsel_sum) { - make_black = TRUE; - } else */ if(!was_a_nonzero) { make_black = TRUE; } else if (!auto_normalize){ + // get the average input /= selected; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index c8475378f56..c1603e6c7f6 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1207,12 +1207,14 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *selecti // Jason TODO: when the change is reduced, you need to recheck the earlier values to make sure they are not 0 (precision error) change = 1.0f/dw->weight; } + // the value should never reach zero while multi-painting if it was nonzero beforehand if(val <= 0) { return; } } } } + // apply the valid change for(i = 0; i < defcnt; i++) { if(selection[i]) { dw = defvert_find_index(dvert, i); @@ -1223,6 +1225,8 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *selecti } } /*Jason*/ +// move all change onto valid, unchanged groups. If there is change left over, then return it. +// assumes there are valid groups to shift weight onto static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, char *validmap, float totchange, float total_valid) { float was_change; float change; @@ -1230,35 +1234,46 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan MDeformWeight *ndw; int i; do { + // assume there is no change until you see one was_change = FALSE; + // change each group by the same amount each time change = totchange/total_valid; for(i = 0; i < ndv->totweight && total_valid && totchange; i++) { ndw = (ndv->dw+i); + // change only the groups with a valid status if(change_status[ndw->def_nr] == changeme) { oldval = ndw->weight; + // if auto normalize is active, don't worry about upper bounds if(!validmap && ndw->weight + change > 1) { totchange -= 1-ndw->weight; ndw->weight = 1; + // stop the changes to this group change_status[ndw->def_nr] = changeto; total_valid--; - } else if(ndw->weight + change < 0) { + } else if(ndw->weight + change < 0) { // check the lower bound totchange -= ndw->weight; ndw->weight = 0; change_status[ndw->def_nr] = changeto; total_valid--; - } else { + } else {// a perfectly valid change occurred to ndw->weight totchange -= change; ndw->weight += change; } + // see if there was a change if(oldval != ndw->weight) { was_change = TRUE; } } } + // don't go again if there was no change, if there is no valid group, or there is no change left }while(was_change && total_valid && totchange); + // left overs return totchange; } /*Jason*/ +// observe the changes made to the weights of groups. +// make sure all locked groups on the vertex have the same deformation +// by moving the changes made to groups onto other unlocked groups static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char *flags, char *bone_groups, char *validmap) { float totchange = 0.0f; float totchange_allowed = 0.0f; @@ -1280,12 +1295,13 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * if(!flags || !has_locked_group(ndv, flags)) { return; } - + // record if a group was changed, unlocked and not changed, or locked change_status = MEM_callocN(sizeof(char)*defcnt, "unlocked_unchanged"); for(i = 0; i < defcnt; i++) { ndw = defvert_find_index(ndv, i); odw = defvert_find_index(odv, i); + // the weights are zero, so we can assume a lot if(!ndw || !odw) { if (!flags[i] && bone_groups[i]){ defvert_verify_index(odv, i); @@ -1295,9 +1311,10 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * } continue; } + // locked groups should not be changed if(flags[i]) { ndw->weight = odw->weight; - } else if(ndw->weight != odw->weight) { + } else if(ndw->weight != odw->weight) { // changed groups are handled here totchange += ndw->weight-odw->weight; change_status[i] = 2; // was altered already total_changed++; @@ -1306,18 +1323,23 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * } else if(!designatedw){ designatedw = i; } - } else if (bone_groups[i]){ + } // unchanged, unlocked bone groups are handled here + else if (bone_groups[i]){ totchange_allowed += ndw->weight; total_valid++; change_status[i] = 1; // can be altered while redistributing } } + // if there was any change, redistribute it if(total_changed) { // auto normalize will allow weights to temporarily go above 1 in redistribution if(validmap && total_changed < 0 && total_valid) { totchange_allowed = total_valid; } + // there needs to be change allowed, or you should not bother if(totchange_allowed) { + // the way you modify the unlocked+unchanged groups is different depending + // on whether or not you are painting the weight(s) up or down if(totchange < 0) { totchange_allowed = total_valid - totchange_allowed; } else { @@ -1325,11 +1347,13 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * } left_over = 0; if(fabs(totchange_allowed) < fabs(totchange)) { + // this amount goes back onto the changed, unlocked weights left_over = fabs(fabs(totchange)-fabs(totchange_allowed)); if(totchange > 0) { left_over *= -1; } }else { + // all of the change will be permitted totchange_allowed = -totchange; } // move the weight evenly between the allowed groups, move excess back onto the used groups based on the change @@ -1338,6 +1362,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * if(left_over) { // more than one nonzero weights were changed with the same ratio, so keep them changed that way! if(total_changed > 1 && !new_weight_has_zero) { + // this dw is special, it is used as a base to determine how to change the others ndw = defvert_find_index(ndv, designatedw); odw = defvert_find_index(odv, designatedw); storedw = ndw->weight; @@ -1370,6 +1395,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * MEM_freeN(change_status); } /*Jason*/ +// multi-paint's initial, potential change is computed here based on the user's stroke static float get_mp_change(MDeformVert *odv, char *selection, float brush_change) { float selwsum = 0.0f; int i; @@ -1385,6 +1411,8 @@ static float get_mp_change(MDeformVert *odv, char *selection, float brush_change return 0.0f; } /*Jason*/ +// change the weights back to the wv's weights +// it assumes you already have the correct pointer index static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { int i; MDeformWeight *d; @@ -1392,6 +1420,7 @@ static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { for(i = 0; i < dv->totweight; i++) { d = dv->dw+i; w = defvert_find_index(wv, d->def_nr); + // if there was no w when there is a d, then the old weight was 0 if(w) { d->weight = w->weight; } else { @@ -1411,19 +1440,20 @@ static void clamp_weights(MDeformVert *dvert) { static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float change, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { MDeformVert *dvert = me->dvert+index; MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); - //float change = 0.0f; + int i; dv->dw= MEM_dupallocN(dvert->dw); dv->flag = dvert->flag; dv->totweight = dvert->totweight; - - if(!flags || flags && !has_locked_group_selected(defcnt, selection, flags) && !flags[dw->def_nr]) {// !flags[dw->def_nr] helps if nothing is selected, but active group is locked + // do not multi-paint if a locked group is selected or the active group is locked + // !flags[dw->def_nr] helps if nothing is selected, but active group is locked + if(!flags || flags && !has_locked_group_selected(defcnt, selection, flags) && !flags[dw->def_nr]) { if(multipaint && selected > 1) { if(change && change!=1) { multipaint_selection(dvert, change, selection, defcnt); } - } else { + } else {// this lets users paint normally, but don't let them paint locked groups dw->weight = neww; } } @@ -1457,7 +1487,7 @@ static char* get_selected_defgroups(Object *ob, int defcnt) { } } } - + // the array has whether or not the corresponding group is selected return dg_flags; } /* TODO move duplicates to header */ @@ -1473,6 +1503,8 @@ static int count_true(char *list, int len) } return cnt; } +// within the current dvert index, get the dw that is selected and has a weight above 0 +// this helps multi-paint static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *selection) { int i; MDeformWeight *dw; @@ -1506,6 +1538,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int defcnt; float change = 0; int i; + // Need to know which groups are bone groups if(validmap) { bone_groups = validmap; }else { @@ -1534,6 +1567,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, wpaint_blend(wp, dw, uw, alpha, paintweight, flip, multipaint && selected >1); neww = dw->weight; dw->weight = oldw; + // setup multi-paint if(selected > 1 && multipaint) { tdw = dw; tuw = uw; From 30412f85aaa3916e656aac5b236c147dfd67501f Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 11 Jul 2011 17:27:37 +0000 Subject: [PATCH 24/68] Found and fixed a problem with locking (noticed it when it was being used with multi-paint): it did not have a proper condition to set designatedw --- source/blender/editors/sculpt_paint/paint_vertex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index c1603e6c7f6..2ccf53a35fd 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1320,7 +1320,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * total_changed++; if(ndw->weight == 0) { new_weight_has_zero = TRUE; - } else if(!designatedw){ + } else if(designatedw == -1){ designatedw = i; } } // unchanged, unlocked bone groups are handled here @@ -1361,7 +1361,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * left_over += totchange_allowed; if(left_over) { // more than one nonzero weights were changed with the same ratio, so keep them changed that way! - if(total_changed > 1 && !new_weight_has_zero) { + if(total_changed > 1 && !new_weight_has_zero && designatedw >= 0) { // this dw is special, it is used as a base to determine how to change the others ndw = defvert_find_index(ndv, designatedw); odw = defvert_find_index(odv, designatedw); @@ -1378,7 +1378,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * } } } - // a weight was changed to zero, or only one weight was changed + // a weight was changed to zero, only one weight was changed, or designatedw is still -1 // put weight back as evenly as possible else { redistribute_change(ndv, change_status, 2, -2, validmap, left_over, total_changed); From 9a808e7b8cef56befc0e54b254571b41afe242e3 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 12 Jul 2011 19:06:06 +0000 Subject: [PATCH 25/68] Lots of incomplete changes: Weight Paint Vertex Select tweaked to act like edit mode's select and Circle select was added, but clipping is not working properly for either. Select all was added too, but to the Q key until I look into overriding A's select all bones. The select vertices checkbox was moved to the header, but it does not force face select mask to turn off yet--and it doesn't have the correct icon. There will definitely be an update tomorrow to fix the problems with all or most of the issues. --- .../startup/bl_ui/space_view3d_toolbar.py | 1 - source/blender/blenkernel/BKE_paint.h | 3 +- source/blender/blenkernel/intern/paint.c | 6 +- source/blender/editors/include/ED_mesh.h | 1 + source/blender/editors/mesh/editmesh.c | 59 +++++++++++++++++++ source/blender/editors/mesh/editmesh_mods.c | 1 + .../editors/sculpt_paint/paint_image.c | 6 +- .../editors/sculpt_paint/paint_intern.h | 3 + .../blender/editors/sculpt_paint/paint_ops.c | 7 +++ .../editors/sculpt_paint/paint_utils.c | 24 ++++++++ .../blender/editors/space_view3d/drawobject.c | 2 +- .../editors/space_view3d/view3d_header.c | 1 + .../editors/space_view3d/view3d_select.c | 49 ++++++++++----- source/blender/makesdna/DNA_mesh_types.h | 2 +- source/blender/makesdna/DNA_scene_types.h | 3 +- source/blender/makesrna/intern/rna_mesh.c | 5 ++ source/blender/makesrna/intern/rna_scene.c | 6 -- 17 files changed, 149 insertions(+), 30 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 5dd7c30cf9a..7b015206f0d 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -641,7 +641,6 @@ class VIEW3D_PT_tools_brush(PaintPanel, bpy.types.Panel): layout.prop(context.tool_settings, "use_auto_normalize", text="Auto Normalize") # Jason was here layout.prop(context.tool_settings, "use_multipaint", text="Multi-Paint") - layout.prop(context.tool_settings, "use_wp_vert_sel", text="Select Vertices") col = layout.column() diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index ef16129e1e7..cee97e7631f 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -59,7 +59,8 @@ void paint_brush_set(struct Paint *paint, struct Brush *br); * Texture paint could be removed since selected faces are not used * however hiding faces is useful */ int paint_facesel_test(struct Object *ob); - +/* Jason */ +int paint_vertsel_test(struct Object *ob); /* Session data (mode-specific) */ typedef struct SculptSession { diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 5be492d1108..fa6ecb09f48 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -93,7 +93,11 @@ int paint_facesel_test(Object *ob) { return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_MASK) && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))); } - +/* Jason */ +int paint_vertsel_test(Object *ob) +{ + return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & (OB_MODE_WEIGHT_PAINT))); +} void paint_init(Paint *p, const char col[3]) { Brush *brush; diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index cdad34a9d42..8005032f0a5 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -124,6 +124,7 @@ int EM_vertColorCheck(struct EditMesh *em); void undo_push_mesh(struct bContext *C, const char *name); /* Jason */ void paintvert_flush_flags(struct Object *ob); +void paintvert_deselect_all_visible(struct Object *ob, int action, short flush_flags); /* editmesh_lib.c */ diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index feaa1899059..73ceb0fb3d7 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -1992,4 +1992,63 @@ void paintvert_flush_flags(Object *ob) mv->flag= mv_orig->flag; } } +} +/* Jason note: caller needs to run paintvert_flush_flags(ob) after this */ +void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) +{ + Mesh *me; + MVert *mvert; + int a; + + me= get_mesh(ob); + if(me==NULL) return; + + if(action == SEL_INVERT) { + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0) { + mvert->flag ^= SELECT; + } + mvert++; + } + } + else { + if (action == SEL_TOGGLE) { + action = SEL_SELECT; + + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0 && mvert->flag & SELECT) { + action = SEL_DESELECT; + break; + } + mvert++; + } + } + + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0) { + switch (action) { + case SEL_SELECT: + mvert->flag |= SELECT; + break; + case SEL_DESELECT: + mvert->flag &= ~SELECT; + break; + case SEL_INVERT: + mvert->flag ^= SELECT; + break; + } + } + mvert++; + } + } + + if(flush_flags) { + paintvert_flush_flags(ob); + } } \ No newline at end of file diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 741cfd7078c..a1a6e88fa0c 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -328,6 +328,7 @@ int EM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); + else if(paint_vertsel_test(vc->obact));// Jason, vertex selecting else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index cae5c14aa97..5f38bdcf4af 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5414,7 +5414,11 @@ int facemask_paint_poll(bContext *C) { return paint_facesel_test(CTX_data_active_object(C)); } - +// Jason +int vert_paint_poll(bContext *C) +{ + return paint_vertsel_test(CTX_data_active_object(C)); +} /* use project paint to re-apply an image */ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op) { diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 5a0ee19d6c9..9894469fa82 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -121,6 +121,9 @@ void PAINT_OT_face_select_all(struct wmOperatorType *ot); void PAINT_OT_face_select_inverse(struct wmOperatorType *ot); void PAINT_OT_face_select_hide(struct wmOperatorType *ot); void PAINT_OT_face_select_reveal(struct wmOperatorType *ot); +/* Jason */ +void PAINT_OT_vert_select_all(struct wmOperatorType *ot); +int vert_paint_poll(struct bContext *C); int facemask_paint_poll(struct bContext *C); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 69af50415cc..ad339b07eb7 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -373,6 +373,9 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_weight_sample); WM_operatortype_append(PAINT_OT_weight_sample_group); + /* Jason, vertex selection */ + WM_operatortype_append(PAINT_OT_vert_select_all); + /* vertex */ WM_operatortype_append(PAINT_OT_vertex_paint_toggle); WM_operatortype_append(PAINT_OT_vertex_paint); @@ -607,6 +610,10 @@ void ED_keymap_paint(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0); + // Jason + WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", QKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0); + /* Image/Texture Paint mode */ keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0); keymap->poll= image_texture_paint_poll; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 09f5c32bea0..18f59536092 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -358,6 +358,30 @@ void PAINT_OT_face_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } +/* Jason */ +static int vert_select_all_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + paintvert_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), TRUE); + ED_region_tag_redraw(CTX_wm_region(C)); + return OPERATOR_FINISHED; +} + +/* Jason */ +void PAINT_OT_vert_select_all(wmOperatorType *ot) +{ + ot->name= "Vertex Selection"; + ot->description= "Change selection for all vertices"; + ot->idname= "PAINT_OT_vert_select_all"; + + ot->exec= vert_select_all_exec; + ot->poll= vert_paint_poll; + + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + WM_operator_properties_select_all(ot); +} + static int face_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_active_object(C); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 22233b895cb..d7b6511aff9 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2777,7 +2777,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D GPU_disable_material(); // Jason - if(scene->toolsettings->wp_vert_sel) { + if(paint_vertsel_test(ob)) { glColor3f(0.0f, 0.0f, 0.0f); glPointSize(2.0f); dm->drawEdges(dm, (dt==OB_WIRE || totface==0), me->drawflag); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 75c8d5cae73..dea46b2e7c3 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -498,6 +498,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr); uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + uiItemR(layout, &meshptr, "wp_vert_sel", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);// Jason } else { const char *str_menu; diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 19aa8ab1886..be2ec3a39c8 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -247,7 +247,7 @@ static int view3d_selectable_data(bContext *C) if (ob->mode & OB_MODE_SCULPT) { return 0; } - if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob)) { + if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) {//Jason return 0; } } @@ -1895,9 +1895,10 @@ int mouse_wp_select(bContext *C, const int mval[2], short extend, Object *obact, if(extend) { mv->flag ^= 1; } else { + paintvert_deselect_all_visible(obact, SEL_DESELECT, FALSE); mv->flag |= 1; } - paintvert_flush_flags(vc->obact); + paintvert_flush_flags(obact); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); MEM_freeN(vc); @@ -1943,7 +1944,7 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) else if(obact && paint_facesel_test(obact)) retval = paintface_mouse_select(C, obact, event->mval, extend); /*Jason*/ - else if (scene->toolsettings->wp_vert_sel && obact && obact->mode & OB_MODE_WEIGHT_PAINT && (me = (Mesh*)(obact->data))) {//Jason + else if (paint_vertsel_test(obact) && (me = (Mesh*)(obact->data))) { retval = mouse_wp_select(C, event->mval, extend, obact, me); } else { retval = mouse_select(C, event->mval, extend, center, enumerate); @@ -1991,6 +1992,18 @@ static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y eve->f = data->select?(eve->f|1):(eve->f&~1); } } +/* Jason */ +static void mesh_obmode_circle_doSelectVert(void *userData, MVert *mv, int x, int y, int index) +{ + struct {ViewContext *vc; short select; int mval[2]; float radius; } *data = userData; + int mx = x - data->mval[0], my = y - data->mval[1]; + float r = sqrt(mx*mx + my*my); + mv = mv+index; + if (r<=data->radius) { + mv->flag = data->select?(mv->flag|1):(mv->flag&~1); + } +} + static void mesh_circle_doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int UNUSED(index)) { struct {ViewContext *vc; short select; int mval[2]; float radius; } *data = userData; @@ -2075,14 +2088,19 @@ static void paint_vertsel_circle_select(ViewContext *vc, int select, const int m { Object *ob= vc->obact; Mesh *me = ob?ob->data:NULL; - int bbsel; + struct {ViewContext *vc; short select; int mval[2]; float radius; } data = {NULL}; if (me) { - em_vertoffs= me->totvert+1; /* max index array */ + ED_view3d_init_mats_rv3d(ob, vc->rv3d); + data.radius = rad; + data.vc = vc; + data.select = select; + data.mval[0]= mval[0]; + data.mval[1]= mval[1]; - bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f)); - EM_backbuf_checkAndSelectTVerts(me, select==LEFTMOUSE); - EM_free_backbuf(); + mesh_obmode_foreachScreenVert(vc, mesh_obmode_circle_doSelectVert, &data, 1); + + paintvert_flush_flags(ob); } } @@ -2340,8 +2358,8 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) int select; select= (gesture_mode==GESTURE_MODAL_SELECT); - - if( CTX_data_edit_object(C) || paint_facesel_test(obact) || + // Jason + if( CTX_data_edit_object(C) || paint_facesel_test(obact) || paint_vertsel_test(obact) || (obact && (obact->mode & (OB_MODE_PARTICLE_EDIT|OB_MODE_POSE))) ) { ViewContext vc; @@ -2358,12 +2376,11 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); } else if(paint_facesel_test(obact)) { - /* Jason */ - if(scene->toolsettings->wp_vert_sel) { - paint_vertsel_circle_select(&vc, select, mval, (float)radius); - } else { - paint_facesel_circle_select(&vc, select, mval, (float)radius); - } + paint_facesel_circle_select(&vc, select, mval, (float)radius); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); + }/* Jason */ + else if(paint_vertsel_test(obact)) { + paint_vertsel_circle_select(&vc, select, mval, (float)radius); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); } else if(obact->mode & OB_MODE_POSE) diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 6ad60ac2df9..bbd21a89f0a 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -125,7 +125,7 @@ typedef struct TFace { #define ME_EDIT_PAINT_MASK (1 << 3) #define ME_EDIT_MIRROR_TOPO (1 << 4) - +#define ME_EDIT_VERT_SEL (1 << 5)// Jason /* me->flag */ /* #define ME_ISDONE 1 */ diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index debe51bf795..251329a04f6 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -724,13 +724,12 @@ typedef struct ToolSettings { short snap_flag, snap_target; short proportional, prop_mode; char proportional_objects; /* proportional edit, object mode */ - char pad[3]; + char pad[7]; int auto_normalize; /*auto normalizing mode in wpaint*/ //Jason int multipaint; /* paint multiple bones in wpaint */ - int wp_vert_sel; /* selectable vertices in wpaint */ short sculpt_paint_settings; /* user preferences for sculpt and paint */ short pad1; diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 80c98e8c428..c976dc82be9 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -2077,6 +2077,11 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0); RNA_def_property_update(prop, 0, "rna_Mesh_update_draw"); + prop= RNA_def_property(srna, "wp_vert_sel", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERT_SEL); + RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex Selection for auto brushes"); + RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0); + RNA_def_property_update(prop, 0, "rna_Mesh_update_draw"); /* readonly editmesh info - use for extrude menu */ prop= RNA_def_property(srna, "total_vert_sel", PROP_INT, PROP_UNSIGNED); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 3c19ea00eca..11a1c3a023d 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1097,12 +1097,6 @@ static void rna_def_tool_settings(BlenderRNA *brna) "weight painting"); RNA_def_property_update(prop, 0, "rna_update_active_object"); - prop = RNA_def_property(srna, "use_wp_vert_sel", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "wp_vert_sel", 1); - RNA_def_property_ui_text(prop, "WPaint Vertex Selection", - "Allow vertices to be selected in Weight Paint Mode "); - RNA_def_property_update(prop, 0, "rna_update_active_object"); - prop= RNA_def_property(srna, "vertex_paint", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "vpaint"); RNA_def_property_ui_text(prop, "Vertex Paint", ""); From 2cf7f619183fdf577e5de1b5dcea733ad091ede0 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 13 Jul 2011 20:45:09 +0000 Subject: [PATCH 26/68] Made a vertex selection keymap for weight paint so that the 'A' key could override pose mode's select all (like face mask) Minor note, changed the icon to the vertex selection icon, but it still doesn't force face mask to turn off. Clipping is still not functional in wp. And I'll need to hear how the backbuffer select is supposed to work for lasso select since the selection is arbitrary. --- .../blender/editors/sculpt_paint/paint_ops.c | 8 +++++- .../editors/space_view3d/space_view3d.c | 4 +++ .../editors/space_view3d/view3d_header.c | 9 ++++--- .../editors/space_view3d/view3d_select.c | 25 +++++++++++++++++++ source/blender/makesrna/intern/rna_mesh.c | 3 ++- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index ad339b07eb7..6aab104b79a 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -611,7 +611,13 @@ void ED_keymap_paint(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0); // Jason - WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", QKEY, KM_PRESS, 0, 0); + /*Weight paint's Vertex Selection Mode */ + keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0); + keymap->poll= vert_paint_poll; + WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0)->ptr, "deselect", 1); WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0); /* Image/Texture Paint mode */ diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 6833dec2e43..8773a67447f 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -371,6 +371,10 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar) keymap= WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); + /* Jason */ + keymap= WM_keymap_find(wm->defaultconf, "Weight Paint Vertex Selection", 0, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); + /* pose is not modal, operator poll checks for this */ keymap= WM_keymap_find(wm->defaultconf, "Pose", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index dea46b2e7c3..a1a73b27b8d 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -495,10 +495,13 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) /* Manipulators aren't used in weight paint mode */ PointerRNA meshptr; - RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr); - uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); - uiItemR(layout, &meshptr, "wp_vert_sel", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);// Jason + //uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + // Jason + row= uiLayoutRow(layout, 1); + // TODO: make it so at most one can be active. + uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + uiItemR(row, &meshptr, "wp_vert_sel", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); } else { const char *str_menu; diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index be2ec3a39c8..0a3a67644c2 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -742,7 +742,30 @@ static void do_lasso_select_meta(ViewContext *vc, int mcords[][2], short moves, } } } +/* Jason */ +static void do_lasso_select_paintvert(ViewContext *vc, int mcords[][2], short moves, short extend, short select) +{ + Object *ob= vc->obact; + Mesh *me= ob?ob->data:NULL; + rcti rect; + if(me==NULL || me->totvert==0) + return; + + if(extend==0 && select) + paintvert_deselect_all_visible(ob, SEL_DESELECT, FALSE); /* flush selection at the end */ + + em_vertoffs= me->totvert+1; /* max index array */ + + lasso_select_boundbox(&rect, mcords, moves); + EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + + EM_backbuf_checkAndSelectTVerts(me, select); + + EM_free_backbuf(); + + paintface_flush_flags(ob); +} static void do_lasso_select_paintface(ViewContext *vc, int mcords[][2], short moves, short extend, short select) { Object *ob= vc->obact; @@ -805,6 +828,8 @@ static void view3d_lasso_select(bContext *C, ViewContext *vc, int mcords[][2], s if(vc->obedit==NULL) { /* Object Mode */ if(paint_facesel_test(ob)) do_lasso_select_paintface(vc, mcords, moves, extend, select); + else if(paint_vertsel_test(ob)) + do_lasso_select_paintvert(vc, mcords, moves, extend, select); else if(ob && ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) ; else if(ob && ob->mode & OB_MODE_PARTICLE_EDIT) diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index c976dc82be9..c1b92f8fc56 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -2077,10 +2077,11 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0); RNA_def_property_update(prop, 0, "rna_Mesh_update_draw"); + /* Jason */ prop= RNA_def_property(srna, "wp_vert_sel", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERT_SEL); RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex Selection for auto brushes"); - RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0); + RNA_def_property_ui_icon(prop, ICON_VERTEXSEL, 0); RNA_def_property_update(prop, 0, "rna_Mesh_update_draw"); /* readonly editmesh info - use for extrude menu */ From 23fe53778897b4f185ffb18585afae68f8fb9ab5 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 14 Jul 2011 18:04:48 +0000 Subject: [PATCH 27/68] Added Lasso select and Box select to weight paint. Clipping still doesn't work properly there. --- .../blender/editors/space_view3d/drawobject.c | 2 +- .../editors/space_view3d/view3d_select.c | 70 +++++++++++++++---- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index d7b6511aff9..67ac571db1d 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -1676,7 +1676,7 @@ static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, fl } if (s[0]!=IS_CLIPPED) - data->func(data->userData, me->mvert, s[0], s[1], index); + data->func(data->userData, mv, s[0], s[1], index); } } /*Jason*/ diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 0a3a67644c2..749c3dfda94 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -641,7 +641,15 @@ static void do_lasso_select_curve(ViewContext *vc, int mcords[][2], short moves, ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */ nurbs_foreachScreenVert(vc, do_lasso_select_curve__doSelect, &data); } +/* Jason */ +static void do_obmode_lasso_select__doSelect(void *userData, MVert *mv, int x, int y) +{ + struct { int (*mcords)[2]; short moves; short select; } *data = userData; + if (lasso_inside(data->mcords, data->moves, x, y)) { + mv->flag = data->select?(mv->flag|SELECT):(mv->flag&~SELECT); + } +} static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, int x, int y) { struct { int (*mcords)[2]; short moves; short select; } *data = userData; @@ -743,28 +751,61 @@ static void do_lasso_select_meta(ViewContext *vc, int mcords[][2], short moves, } } /* Jason */ +static void do_obmode_box_select__doSelect(void *userData, MVert *mv, int x, int y) +{ + struct { ViewContext vc; rcti *rect; int select; } *data = userData; + + if (BLI_in_rcti(data->rect, x, y)) { + mv->flag = data->select?(mv->flag|SELECT):(mv->flag&~SELECT); + } +} +/* Jason */ +int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) +{ + Object *ob= vc->obact; + Mesh *me= ob?ob->data:NULL; + int sx= rect->xmax-rect->xmin+1; + int sy= rect->ymax-rect->ymin+1; + bglMats mats; + struct { ViewContext vc; rcti *rect; int select; } data = {NULL}; + + if(me==NULL || me->totvert==0 || sx*sy <= 0) + return OPERATOR_CANCELLED; + + if(extend==0 && select) + paintvert_deselect_all_visible(ob, SEL_DESELECT, FALSE); /* flush selection at the end */ + + ED_view3d_init_mats_rv3d(ob, vc->rv3d); + data.vc = *vc; + data.rect = rect; + data.select= select; + + mesh_obmode_foreachScreenVert(vc, do_obmode_box_select__doSelect, &data, 1); + + paintvert_flush_flags(ob); + + return OPERATOR_FINISHED; +} +/* Jason */ static void do_lasso_select_paintvert(ViewContext *vc, int mcords[][2], short moves, short extend, short select) { Object *ob= vc->obact; Mesh *me= ob?ob->data:NULL; - rcti rect; + + struct { int (*mcords)[2]; short moves; short select; } data = {NULL}; if(me==NULL || me->totvert==0) return; if(extend==0 && select) paintvert_deselect_all_visible(ob, SEL_DESELECT, FALSE); /* flush selection at the end */ + ED_view3d_init_mats_rv3d(ob, vc->rv3d); + data.select = select; + data.mcords = mcords; + data.moves= moves; + mesh_obmode_foreachScreenVert(vc, do_obmode_lasso_select__doSelect, &data, 1); - em_vertoffs= me->totvert+1; /* max index array */ - - lasso_select_boundbox(&rect, mcords, moves); - EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); - - EM_backbuf_checkAndSelectTVerts(me, select); - - EM_free_backbuf(); - - paintface_flush_flags(ob); + paintvert_flush_flags(ob); } static void do_lasso_select_paintface(ViewContext *vc, int mcords[][2], short moves, short extend, short select) { @@ -1833,6 +1874,9 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) else if(vc.obact && paint_facesel_test(vc.obact)) { ret= do_paintface_box_select(&vc, &rect, select, extend); } + else if(vc.obact && paint_vertsel_test(vc.obact)) { + ret= do_paintvert_box_select(&vc, &rect, select, extend); + } else if(vc.obact && vc.obact->mode & OB_MODE_PARTICLE_EDIT) { ret= PE_border_select(C, &rect, select, extend); } @@ -2018,12 +2062,12 @@ static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y } } /* Jason */ -static void mesh_obmode_circle_doSelectVert(void *userData, MVert *mv, int x, int y, int index) +static void mesh_obmode_circle_doSelectVert(void *userData, MVert *mv, int x, int y, int UNUSED(index)) { struct {ViewContext *vc; short select; int mval[2]; float radius; } *data = userData; int mx = x - data->mval[0], my = y - data->mval[1]; float r = sqrt(mx*mx + my*my); - mv = mv+index; + if (r<=data->radius) { mv->flag = data->select?(mv->flag|1):(mv->flag&~1); } From 882e29650582f46efde115c1d45c1faec7a169fc Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Fri, 15 Jul 2011 17:09:43 +0000 Subject: [PATCH 28/68] Removed a remnant to an unsuccessful attempt to get clipping functional so I can merge again. --- source/blender/editors/space_view3d/view3d_select.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 749c3dfda94..94049e6d385 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -766,7 +766,7 @@ int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) Mesh *me= ob?ob->data:NULL; int sx= rect->xmax-rect->xmin+1; int sy= rect->ymax-rect->ymin+1; - bglMats mats; + struct { ViewContext vc; rcti *rect; int select; } data = {NULL}; if(me==NULL || me->totvert==0 || sx*sy <= 0) From ace48a51cde08c20add86264cd9d41f26f1bb43a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 18 Jul 2011 14:56:13 +0000 Subject: [PATCH 29/68] manually copying changes from trunk, these were somehow missed in merged --- CMakeLists.txt | 131 ++++++++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1a6136382b..ebf7aa8a6c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,6 @@ if(NOT EXECUTABLE_OUTPUT_PATH) set(FIRST_RUN "TRUE") endif() - # this starts out unset list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules") @@ -158,7 +157,7 @@ option(WITH_IMAGE_HDR "Enable HDR Image Support" ON) option(WITH_IMAGE_REDCODE "Enable RedCode Image Support" OFF) # Audio/Video format support -option(WITH_CODEC_FFMPEG "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu)" OFF) +option(WITH_CODEC_FFMPEG "Enable FFMPeg Support (http://ffmpeg.org)" OFF) option(WITH_CODEC_SNDFILE "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF) if(APPLE OR (WIN32 AND NOT UNIX)) option(WITH_CODEC_QUICKTIME "Enable Quicktime Support" OFF) @@ -264,11 +263,24 @@ TEST_SSE_SUPPORT() set(WITH_BINRELOC OFF) # MAXOSX only, set to avoid uninitialized -set(EXETYPE "") +set(EXETYPE) + +# C/C++ flags +set(PLATFORM_CFLAGS) # these are added to later on. -set(C_WARNINGS "") -set(CXX_WARNINGS "") +set(C_WARNINGS) +set(CXX_WARNINGS) + +# libraries to link the binary with passed to target_link_libraries() +# known as LLIBS to scons +set(PLATFORM_LINKLIBS) + +# Added to linker flags in setup_liblinks +# - CMAKE_EXE_LINKER_FLAGS +# - CMAKE_EXE_LINKER_FLAGS_DEBUG +set(PLATFORM_LINKFLAGS) +set(PLATFORM_LINKFLAGS_DEBUG) # disabled for now, not supported @@ -371,7 +383,7 @@ if(UNIX AND NOT APPLE) endif() if(WITH_CODEC_FFMPEG) - set(FFMPEG /usr CACHE FILEPATH "FFMPEG Directory") + set(FFMPEG /usr CACHE PATH "FFMPEG Directory") mark_as_advanced(FFMPEG) set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include) set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries") @@ -415,18 +427,18 @@ if(UNIX AND NOT APPLE) endif() if(WITH_OPENCOLLADA) - set(OPENCOLLADA /usr/local/opencollada CACHE FILEPATH "OpenCollada Directory") + set(OPENCOLLADA /usr/local/opencollada CACHE PATH "OpenCollada Directory") mark_as_advanced(OPENCOLLADA) set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib) set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2) set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}) - set(PCRE /usr CACHE FILEPATH "PCRE Directory") + set(PCRE /usr CACHE PATH "PCRE Directory") mark_as_advanced(PCRE) set(PCRE_LIBPATH ${PCRE}/lib) set(PCRE_LIB pcre) - set(EXPAT /usr CACHE FILEPATH "Expat Directory") + set(EXPAT /usr CACHE PATH "Expat Directory") mark_as_advanced(EXPAT) set(EXPAT_LIBPATH ${EXPAT}/lib) set(EXPAT_LIB expat) @@ -440,24 +452,24 @@ if(UNIX AND NOT APPLE) endif() # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed - set(LLIBS "-lutil -lc -lm -lpthread -lstdc++") + set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++") if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL)) find_package(X11 REQUIRED) find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH}) mark_as_advanced(X11_XF86keysym_INCLUDE_PATH) - list(APPEND LLIBS ${X11_X11_LIB}) + list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB}) if(WITH_X11_XINPUT) - list(APPEND LLIBS ${X11_Xinput_LIB}) + list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB}) endif() endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux") if(NOT WITH_PYTHON_MODULE) # BSD's dont use libdl.so - list(APPEND LLIBS -ldl) + list(APPEND PLATFORM_LINKLIBS -ldl) # binreloc is linux only set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include) set(WITH_BINRELOC ON) @@ -568,13 +580,15 @@ elseif(WIN32) if(MSVC) if(CMAKE_CL_64) - set(LLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid) + set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid) else() - set(LLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid) + set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid) endif() - - set(CMAKE_CXX_FLAGS "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB /nologo /Ob1 /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE) - set(CMAKE_C_FLAGS "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB /nologo /Ob1 /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE) + + add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB) + + set(CMAKE_CXX_FLAGS "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE) + set(CMAKE_C_FLAGS "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE) if(CMAKE_CL_64) set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE) @@ -611,24 +625,22 @@ elseif(WIN32) endif() set(JPEG_LIBRARIES libjpeg) - set(ZLIB ${LIBDIR}/zlib) - set(ZLIB_INCLUDE_DIRS ${ZLIB}/include) - set(ZLIB_LIBPATH ${ZLIB}/lib) + set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include) if(CMAKE_CL_64) - set(ZLIB_LIBRARIES libz) + set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib) else() - set(ZLIB_LIBRARIES zlib) + set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib) endif() - set(PTHREADS ${LIBDIR}/pthreads) - set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include) - set(PTHREADS_LIBPATH ${PTHREADS}/lib) - set(PTHREADS_LIBRARIES pthreadVC2) - + set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include) + set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib) + set(FREETYPE ${LIBDIR}/freetype) - set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2) - set(FREETYPE_LIBPATH ${FREETYPE}/lib) - set(FREETYPE_LIBRARY freetype2ST) + set(FREETYPE_INCLUDE_DIRS + ${LIBDIR}/freetype/include + ${LIBDIR}/freetype/include/freetype2 + ) + set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib) if(WITH_FFTW3) set(FFTW3 ${LIBDIR}/fftw3) @@ -659,10 +671,17 @@ elseif(WIN32) endif() if(WITH_CODEC_FFMPEG) - set(FFMPEG ${LIBDIR}/ffmpeg) - set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include/msvc) - set(FFMPEG_LIBRARIES avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0) - set(FFMPEG_LIBPATH ${FFMPEG}/lib) + set(FFMPEG_INCLUDE_DIRS + ${LIBDIR}/ffmpeg/include + ${LIBDIR}/ffmpeg/include/msvc + ) + set(FFMPEG_LIBRARIES + ${LIBDIR}/ffmpeg/lib/avcodec-52.lib + ${LIBDIR}/ffmpeg/lib/avformat-52.lib + ${LIBDIR}/ffmpeg/lib/avdevice-52.lib + ${LIBDIR}/ffmpeg/lib/avutil-50.lib + ${LIBDIR}/ffmpeg/lib/swscale-0.lib + ) endif() if(WITH_IMAGE_OPENEXR) @@ -697,17 +716,16 @@ elseif(WIN32) endif() if(WITH_IMAGE_TIFF) - set(TIFF ${LIBDIR}/tiff) - set(TIFF_LIBRARY libtiff) - set(TIFF_INCLUDE_DIR ${TIFF}/include) - set(TIFF_LIBPATH ${TIFF}/lib) + set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib) + set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include) endif() if(WITH_JACK) - set(JACK ${LIBDIR}/jack) - set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include) - set(JACK_LIBRARIES libjack) - set(JACK_LIBPATH ${JACK}/lib) + set(JACK_INCLUDE_DIRS + ${LIBDIR}/jack/include/jack + ${LIBDIR}/jack/include + ) + set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib) endif() if(WITH_PYTHON) @@ -721,23 +739,24 @@ elseif(WIN32) set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") endif() + set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib") + # MSVC only, Mingw doesnt need if(CMAKE_CL_64) - set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /MACHINE:X64 /STACK:2097152 /OPT:NOREF /INCREMENTAL:NO /NODEFAULTLIB:\"msvcrt.lib\" /NODEFAULTLIB:\"msvcmrt.lib\" /NODEFAULTLIB:\"msvcurt.lib\" /NODEFAULTLIB:\"msvcrtd.lib\" ") + set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}") else() - set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /MACHINE:IX86 /STACK:2097152 /INCREMENTAL:NO /LARGEADDRESSAWARE /NODEFAULTLIB:\"msvcrt.lib\" /NODEFAULTLIB:\"msvcmrt.lib\" /NODEFAULTLIB:\"msvcurt.lib\" /NODEFAULTLIB:\"msvcrtd.lib\" ") + set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}") endif() - set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib;libc.lib ") + set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib") else() # keep GCC spesific stuff here if(CMAKE_COMPILER_IS_GNUCC) - set(LLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid") + set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid") set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE") + add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE) endif() add_definitions(-DFREE_WINDOWS) @@ -952,7 +971,7 @@ elseif(APPLE) set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib) endif() - set(LLIBS stdc++ SystemStubs) + set(PLATFORM_LINKLIBS stdc++ SystemStubs) if(WITH_COCOA) set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA") @@ -1176,6 +1195,18 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Intel") endif() +# MSVC2010 fails to links C++ libs right +if(MSVC10) + if(WITH_IMAGE_OPENEXR) + message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008") + set(WITH_IMAGE_OPENEXR OFF) + endif() + if(WITH_OPENCOLLADA) + message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008") + set(WITH_OPENCOLLADA OFF) + endif() +endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(WITH_IK_ITASC OR WITH_MOD_FLUID) message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.") From 64e8f9f3d8301b50f7b81551c1b411a9d1da0e1a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 18 Jul 2011 15:05:50 +0000 Subject: [PATCH 30/68] manually make small changes to sync with trunk --- intern/ghost/intern/GHOST_SystemCocoa.mm | 9 +- source/blender/blenlib/intern/math_geom.c | 2 +- .../blender/editors/armature/armature_ops.c | 4 +- .../editors/sculpt_paint/paint_vertex.c | 4 +- .../blender/editors/space_view3d/drawobject.c | 1 - .../editors/space_view3d/view3d_select.c | 1 + .../python/generic/mathutils_geometry.c | 1099 ----------------- 7 files changed, 12 insertions(+), 1108 deletions(-) delete mode 100644 source/blender/python/generic/mathutils_geometry.c diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 69423f2dfbf..bb3d6e3aee3 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -1498,15 +1498,18 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr) GHOST_TInt32 x_mouse= mousePos.x; GHOST_TInt32 y_mouse= mousePos.y; GHOST_TInt32 x_accum, y_accum, x_cur, y_cur, x, y; - GHOST_Rect bounds, correctedBounds; + GHOST_Rect bounds, windowBounds, correctedBounds; /* fallback to window bounds */ if(window->getCursorGrabBounds(bounds)==GHOST_kFailure) window->getClientBounds(bounds); //Switch back to Cocoa coordinates orientation (y=0 at botton,the same as blender internal btw!), and to client coordinates - window->screenToClient(bounds.m_l, bounds.m_b, correctedBounds.m_l, correctedBounds.m_b); - window->screenToClient(bounds.m_r, bounds.m_t, correctedBounds.m_r, correctedBounds.m_t); + window->getClientBounds(windowBounds); + window->screenToClient(bounds.m_l, bounds.m_b, correctedBounds.m_l, correctedBounds.m_t); + window->screenToClient(bounds.m_r, bounds.m_t, correctedBounds.m_r, correctedBounds.m_b); + correctedBounds.m_b = (windowBounds.m_b - windowBounds.m_t) - correctedBounds.m_b; + correctedBounds.m_t = (windowBounds.m_b - windowBounds.m_t) - correctedBounds.m_t; //Update accumulation counts window->getCursorGrabAccum(x_accum, y_accum); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 9d945e9baa3..fc329fe1bf1 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -430,7 +430,7 @@ int isect_line_sphere_v2(const float l1[2], const float l2[2], l2[1] - l1[1] }; - const float a= dot_v3v3(ldir, ldir); + const float a= dot_v2v2(ldir, ldir); const float b= 2.0f * (ldir[0] * (l1[0] - sp[0]) + diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index 7bc9bb48a4c..16b748737ca 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -265,7 +265,7 @@ void ED_keymap_armature(wmKeyConfig *keyconf) /* set flags */ WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_toggle", WKEY, KM_PRESS, KM_SHIFT, 0); - WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_enable", WKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_enable", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_disable", WKEY, KM_PRESS, KM_ALT, 0); /* armature/bone layers */ @@ -343,7 +343,7 @@ void ED_keymap_armature(wmKeyConfig *keyconf) /* set flags */ WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_toggle", WKEY, KM_PRESS, KM_SHIFT, 0); - WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_enable", WKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_enable", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_disable", WKEY, KM_PRESS, KM_ALT, 0); /* armature/bone layers */ diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 2ccf53a35fd..562a46586b9 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -75,7 +75,6 @@ #include "BKE_paint.h" #include "BKE_report.h" - #include "WM_api.h" #include "WM_types.h" @@ -386,6 +385,7 @@ void vpaint_fill(Object *ob, unsigned int paintcol) DAG_id_tag_update(&me->id, 0); } + /* fills in the selected faces with the current weight and vertex group */ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) { @@ -401,7 +401,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) me= ob->data; if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return; - + selected= (me->editflag & ME_EDIT_PAINT_MASK); indexar= get_indexarray(me); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 67ac571db1d..0196149c789 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -58,7 +58,6 @@ #include "BKE_anim.h" //for the where_on_path function #include "BKE_constraint.h" // for the get_constraint_target function #include "BKE_DerivedMesh.h" - #include "BKE_deform.h" #include "BKE_displist.h" #include "BKE_font.h" diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 94049e6d385..99f3580fa15 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1993,6 +1993,7 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) Scene *scene = CTX_data_scene(C); view3d_operator_needs_opengl(C); + if(obedit) { if(obedit->type==OB_MESH) retval = mouse_mesh(C, event->mval, extend); diff --git a/source/blender/python/generic/mathutils_geometry.c b/source/blender/python/generic/mathutils_geometry.c deleted file mode 100644 index 55c1e69d558..00000000000 --- a/source/blender/python/generic/mathutils_geometry.c +++ /dev/null @@ -1,1099 +0,0 @@ -/* - * $Id$ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * This is a new part of Blender. - * - * Contributor(s): Joseph Gilbert, Campbell Barton - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/python/generic/mathutils_geometry.c - * \ingroup pygen - */ - - -#include - -#include "mathutils_geometry.h" - -/* Used for PolyFill */ -#include "MEM_guardedalloc.h" - -#include "BLI_blenlib.h" -#include "BLI_boxpack2d.h" -#include "BLI_math.h" -#include "BLI_utildefines.h" - -#include "BKE_displist.h" - -#include "BKE_curve.h" - -#define SWAP_FLOAT(a, b, tmp) tmp=a; a=b; b=tmp -#define eps 0.000001 - - -/*-------------------------DOC STRINGS ---------------------------*/ -PyDoc_STRVAR(M_Geometry_doc, -"The Blender geometry module" -); - -//---------------------------------INTERSECTION FUNCTIONS-------------------- - -PyDoc_STRVAR(M_Geometry_intersect_ray_tri_doc, -".. function:: intersect_ray_tri(v1, v2, v3, ray, orig, clip=True)\n" -"\n" -" Returns the intersection between a ray and a triangle, if possible, returns None otherwise.\n" -"\n" -" :arg v1: Point1\n" -" :type v1: :class:`mathutils.Vector`\n" -" :arg v2: Point2\n" -" :type v2: :class:`mathutils.Vector`\n" -" :arg v3: Point3\n" -" :type v3: :class:`mathutils.Vector`\n" -" :arg ray: Direction of the projection\n" -" :type ray: :class:`mathutils.Vector`\n" -" :arg orig: Origin\n" -" :type orig: :class:`mathutils.Vector`\n" -" :arg clip: When False, don't restrict the intersection to the area of the triangle, use the infinite plane defined by the triangle.\n" -" :type clip: boolean\n" -" :return: The point of intersection or None if no intersection is found\n" -" :rtype: :class:`mathutils.Vector` or None\n" -); -static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *ray, *ray_off, *vec1, *vec2, *vec3; - float dir[3], orig[3], v1[3], v2[3], v3[3], e1[3], e2[3], pvec[3], tvec[3], qvec[3]; - float det, inv_det, u, v, t; - int clip= 1; - - if(!PyArg_ParseTuple(args, "O!O!O!O!O!|i:intersect_ray_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &ray, &vector_Type, &ray_off , &clip)) { - return NULL; - } - if(vec1->size != 3 || vec2->size != 3 || vec3->size != 3 || ray->size != 3 || ray_off->size != 3) { - PyErr_SetString(PyExc_ValueError, "only 3D vectors for all parameters"); - return NULL; - } - - if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(ray) == -1 || BaseMath_ReadCallback(ray_off) == -1) - return NULL; - - VECCOPY(v1, vec1->vec); - VECCOPY(v2, vec2->vec); - VECCOPY(v3, vec3->vec); - - VECCOPY(dir, ray->vec); - normalize_v3(dir); - - VECCOPY(orig, ray_off->vec); - - /* find vectors for two edges sharing v1 */ - sub_v3_v3v3(e1, v2, v1); - sub_v3_v3v3(e2, v3, v1); - - /* begin calculating determinant - also used to calculated U parameter */ - cross_v3_v3v3(pvec, dir, e2); - - /* if determinant is near zero, ray lies in plane of triangle */ - det= dot_v3v3(e1, pvec); - - if (det > -0.000001f && det < 0.000001f) { - Py_RETURN_NONE; - } - - inv_det= 1.0f / det; - - /* calculate distance from v1 to ray origin */ - sub_v3_v3v3(tvec, orig, v1); - - /* calculate U parameter and test bounds */ - u= dot_v3v3(tvec, pvec) * inv_det; - if (clip && (u < 0.0f || u > 1.0f)) { - Py_RETURN_NONE; - } - - /* prepare to test the V parameter */ - cross_v3_v3v3(qvec, tvec, e1); - - /* calculate V parameter and test bounds */ - v= dot_v3v3(dir, qvec) * inv_det; - - if (clip && (v < 0.0f || u + v > 1.0f)) { - Py_RETURN_NONE; - } - - /* calculate t, ray intersects triangle */ - t= dot_v3v3(e2, qvec) * inv_det; - - mul_v3_fl(dir, t); - add_v3_v3v3(pvec, orig, dir); - - return newVectorObject(pvec, 3, Py_NEW, NULL); -} - -/* Line-Line intersection using algorithm from mathworld.wolfram.com */ - -PyDoc_STRVAR(M_Geometry_intersect_line_line_doc, -".. function:: intersect_line_line(v1, v2, v3, v4)\n" -"\n" -" Returns a tuple with the points on each line respectively closest to the other.\n" -"\n" -" :arg v1: First point of the first line\n" -" :type v1: :class:`mathutils.Vector`\n" -" :arg v2: Second point of the first line\n" -" :type v2: :class:`mathutils.Vector`\n" -" :arg v3: First point of the second line\n" -" :type v3: :class:`mathutils.Vector`\n" -" :arg v4: Second point of the second line\n" -" :type v4: :class:`mathutils.Vector`\n" -" :rtype: tuple of :class:`mathutils.Vector`'s\n" -); -static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject *args) -{ - PyObject *tuple; - VectorObject *vec1, *vec2, *vec3, *vec4; - float v1[3], v2[3], v3[3], v4[3], i1[3], i2[3]; - - if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) { - return NULL; - } - if(vec1->size != vec2->size || vec1->size != vec3->size || vec3->size != vec2->size) { - PyErr_SetString(PyExc_ValueError,"vectors must be of the same size"); - return NULL; - } - - if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1) - return NULL; - - if(vec1->size == 3 || vec1->size == 2) { - int result; - - if (vec1->size == 3) { - VECCOPY(v1, vec1->vec); - VECCOPY(v2, vec2->vec); - VECCOPY(v3, vec3->vec); - VECCOPY(v4, vec4->vec); - } - else { - v1[0]= vec1->vec[0]; - v1[1]= vec1->vec[1]; - v1[2]= 0.0f; - - v2[0]= vec2->vec[0]; - v2[1]= vec2->vec[1]; - v2[2]= 0.0f; - - v3[0]= vec3->vec[0]; - v3[1]= vec3->vec[1]; - v3[2]= 0.0f; - - v4[0]= vec4->vec[0]; - v4[1]= vec4->vec[1]; - v4[2]= 0.0f; - } - - result= isect_line_line_v3(v1, v2, v3, v4, i1, i2); - - if (result == 0) { - /* colinear */ - Py_RETURN_NONE; - } - else { - tuple= PyTuple_New(2); - PyTuple_SET_ITEM(tuple, 0, newVectorObject(i1, vec1->size, Py_NEW, NULL)); - PyTuple_SET_ITEM(tuple, 1, newVectorObject(i2, vec1->size, Py_NEW, NULL)); - return tuple; - } - } - else { - PyErr_SetString(PyExc_ValueError, "2D/3D vectors only"); - return NULL; - } -} - - - - -//----------------------------geometry.normal() ------------------- -PyDoc_STRVAR(M_Geometry_normal_doc, -".. function:: normal(v1, v2, v3, v4=None)\n" -"\n" -" Returns the normal of the 3D tri or quad.\n" -"\n" -" :arg v1: Point1\n" -" :type v1: :class:`mathutils.Vector`\n" -" :arg v2: Point2\n" -" :type v2: :class:`mathutils.Vector`\n" -" :arg v3: Point3\n" -" :type v3: :class:`mathutils.Vector`\n" -" :arg v4: Point4 (optional)\n" -" :type v4: :class:`mathutils.Vector`\n" -" :rtype: :class:`mathutils.Vector`\n" -); -static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *vec1, *vec2, *vec3, *vec4; - float n[3]; - - if(PyTuple_GET_SIZE(args) == 3) { - if(!PyArg_ParseTuple(args, "O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) { - return NULL; - } - if(vec1->size != vec2->size || vec1->size != vec3->size) { - PyErr_SetString(PyExc_ValueError, "vectors must be of the same size"); - return NULL; - } - if(vec1->size < 3) { - PyErr_SetString(PyExc_ValueError, "2D vectors unsupported"); - return NULL; - } - - if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1) - return NULL; - - normal_tri_v3(n, vec1->vec, vec2->vec, vec3->vec); - } - else { - if(!PyArg_ParseTuple(args, "O!O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) { - return NULL; - } - if(vec1->size != vec2->size || vec1->size != vec3->size || vec1->size != vec4->size) { - PyErr_SetString(PyExc_ValueError,"vectors must be of the same size"); - return NULL; - } - if(vec1->size < 3) { - PyErr_SetString(PyExc_ValueError, "2D vectors unsupported"); - return NULL; - } - - if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1) - return NULL; - - normal_quad_v3(n, vec1->vec, vec2->vec, vec3->vec, vec4->vec); - } - - return newVectorObject(n, 3, Py_NEW, NULL); -} - -//--------------------------------- AREA FUNCTIONS-------------------- - -PyDoc_STRVAR(M_Geometry_area_tri_doc, -".. function:: area_tri(v1, v2, v3)\n" -"\n" -" Returns the area size of the 2D or 3D triangle defined.\n" -"\n" -" :arg v1: Point1\n" -" :type v1: :class:`mathutils.Vector`\n" -" :arg v2: Point2\n" -" :type v2: :class:`mathutils.Vector`\n" -" :arg v3: Point3\n" -" :type v3: :class:`mathutils.Vector`\n" -" :rtype: float\n" -); -static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *vec1, *vec2, *vec3; - - if(!PyArg_ParseTuple(args, "O!O!O!:area_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) { - return NULL; - } - - if(vec1->size != vec2->size || vec1->size != vec3->size) { - PyErr_SetString(PyExc_ValueError, "vectors must be of the same size"); - return NULL; - } - - if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1) - return NULL; - - if (vec1->size == 3) { - return PyFloat_FromDouble(area_tri_v3(vec1->vec, vec2->vec, vec3->vec)); - } - else if (vec1->size == 2) { - return PyFloat_FromDouble(area_tri_v2(vec1->vec, vec2->vec, vec3->vec)); - } - else { - PyErr_SetString(PyExc_ValueError, "only 2D,3D vectors are supported"); - return NULL; - } -} - -/*----------------------------------geometry.PolyFill() -------------------*/ -PyDoc_STRVAR(M_Geometry_tesselate_polygon_doc, -".. function:: tesselate_polygon(veclist_list)\n" -"\n" -" Takes a list of polylines (each point a vector) and returns the point indices for a polyline filled with triangles.\n" -"\n" -" :arg veclist_list: list of polylines\n" -" :rtype: list\n" -); -/* PolyFill function, uses Blenders scanfill to fill multiple poly lines */ -static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *polyLineSeq) -{ - PyObject *tri_list; /*return this list of tri's */ - PyObject *polyLine, *polyVec; - int i, len_polylines, len_polypoints, ls_error= 0; - - /* display listbase */ - ListBase dispbase={NULL, NULL}; - DispList *dl; - float *fp; /*pointer to the array of malloced dl->verts to set the points from the vectors */ - int index, *dl_face, totpoints=0; - - if(!PySequence_Check(polyLineSeq)) { - PyErr_SetString(PyExc_TypeError, "expected a sequence of poly lines"); - return NULL; - } - - len_polylines= PySequence_Size(polyLineSeq); - - for(i= 0; i < len_polylines; ++i) { - polyLine= PySequence_GetItem(polyLineSeq, i); - if (!PySequence_Check(polyLine)) { - freedisplist(&dispbase); - Py_XDECREF(polyLine); /* may be null so use Py_XDECREF*/ - PyErr_SetString(PyExc_TypeError, "One or more of the polylines is not a sequence of mathutils.Vector's"); - return NULL; - } - - len_polypoints= PySequence_Size(polyLine); - if (len_polypoints>0) { /* dont bother adding edges as polylines */ -#if 0 - if (EXPP_check_sequence_consistency(polyLine, &vector_Type) != 1) { - freedisplist(&dispbase); - Py_DECREF(polyLine); - PyErr_SetString(PyExc_TypeError, "A point in one of the polylines is not a mathutils.Vector type"); - return NULL; - } -#endif - dl= MEM_callocN(sizeof(DispList), "poly disp"); - BLI_addtail(&dispbase, dl); - dl->type= DL_INDEX3; - dl->nr= len_polypoints; - dl->type= DL_POLY; - dl->parts= 1; /* no faces, 1 edge loop */ - dl->col= 0; /* no material */ - dl->verts= fp= MEM_callocN(sizeof(float)*3*len_polypoints, "dl verts"); - dl->index= MEM_callocN(sizeof(int)*3*len_polypoints, "dl index"); - - for(index= 0; indexvec[0]; - fp[1]= ((VectorObject *)polyVec)->vec[1]; - if(((VectorObject *)polyVec)->size > 2) - fp[2]= ((VectorObject *)polyVec)->vec[2]; - else - fp[2]= 0.0f; /* if its a 2d vector then set the z to be zero */ - } - else { - ls_error= 1; - } - - totpoints++; - Py_DECREF(polyVec); - } - } - Py_DECREF(polyLine); - } - - if(ls_error) { - freedisplist(&dispbase); /* possible some dl was allocated */ - PyErr_SetString(PyExc_TypeError, "A point in one of the polylines is not a mathutils.Vector type"); - return NULL; - } - else if (totpoints) { - /* now make the list to return */ - filldisplist(&dispbase, &dispbase, 0); - - /* The faces are stored in a new DisplayList - thats added to the head of the listbase */ - dl= dispbase.first; - - tri_list= PyList_New(dl->parts); - if(!tri_list) { - freedisplist(&dispbase); - PyErr_SetString(PyExc_RuntimeError, "geometry.PolyFill failed to make a new list"); - return NULL; - } - - index= 0; - dl_face= dl->index; - while(index < dl->parts) { - PyList_SET_ITEM(tri_list, index, Py_BuildValue("iii", dl_face[0], dl_face[1], dl_face[2])); - dl_face+= 3; - index++; - } - freedisplist(&dispbase); - } - else { - /* no points, do this so scripts dont barf */ - freedisplist(&dispbase); /* possible some dl was allocated */ - tri_list= PyList_New(0); - } - - return tri_list; -} - -PyDoc_STRVAR(M_Geometry_intersect_line_line_2d_doc, -".. function:: intersect_line_line_2d(lineA_p1, lineA_p2, lineB_p1, lineB_p2)\n" -"\n" -" Takes 2 lines (as 4 vectors) and returns a vector for their point of intersection or None.\n" -"\n" -" :arg lineA_p1: First point of the first line\n" -" :type lineA_p1: :class:`mathutils.Vector`\n" -" :arg lineA_p2: Second point of the first line\n" -" :type lineA_p2: :class:`mathutils.Vector`\n" -" :arg lineB_p1: First point of the second line\n" -" :type lineB_p1: :class:`mathutils.Vector`\n" -" :arg lineB_p2: Second point of the second line\n" -" :type lineB_p2: :class:`mathutils.Vector`\n" -" :return: The point of intersection or None when not found\n" -" :rtype: :class:`mathutils.Vector` or None\n" -); -static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *line_a1, *line_a2, *line_b1, *line_b2; - float vi[2]; - if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line_2d", - &vector_Type, &line_a1, - &vector_Type, &line_a2, - &vector_Type, &line_b1, - &vector_Type, &line_b2) - ) { - return NULL; - } - - if(BaseMath_ReadCallback(line_a1) == -1 || BaseMath_ReadCallback(line_a2) == -1 || BaseMath_ReadCallback(line_b1) == -1 || BaseMath_ReadCallback(line_b2) == -1) - return NULL; - - if(isect_seg_seg_v2_point(line_a1->vec, line_a2->vec, line_b1->vec, line_b2->vec, vi) == 1) { - return newVectorObject(vi, 2, Py_NEW, NULL); - } - else { - Py_RETURN_NONE; - } -} - - -PyDoc_STRVAR(M_Geometry_intersect_line_plane_doc, -".. function:: intersect_line_plane(line_a, line_b, plane_co, plane_no, no_flip=False)\n" -"\n" -" Takes 2 lines (as 4 vectors) and returns a vector for their point of intersection or None.\n" -"\n" -" :arg line_a: First point of the first line\n" -" :type line_a: :class:`mathutils.Vector`\n" -" :arg line_b: Second point of the first line\n" -" :type line_b: :class:`mathutils.Vector`\n" -" :arg plane_co: A point on the plane\n" -" :type plane_co: :class:`mathutils.Vector`\n" -" :arg plane_no: The direction the plane is facing\n" -" :type plane_no: :class:`mathutils.Vector`\n" -" :arg no_flip: Always return an intersection on the directon defined bt line_a -> line_b\n" -" :type no_flip: :boolean\n" -" :return: The point of intersection or None when not found\n" -" :rtype: :class:`mathutils.Vector` or None\n" -); -static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *line_a, *line_b, *plane_co, *plane_no; - int no_flip= 0; - float isect[3]; - if(!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_plane", - &vector_Type, &line_a, - &vector_Type, &line_b, - &vector_Type, &plane_co, - &vector_Type, &plane_no, - &no_flip) - ) { - return NULL; - } - - if( BaseMath_ReadCallback(line_a) == -1 || - BaseMath_ReadCallback(line_b) == -1 || - BaseMath_ReadCallback(plane_co) == -1 || - BaseMath_ReadCallback(plane_no) == -1 - ) { - return NULL; - } - - if(ELEM4(2, line_a->size, line_b->size, plane_co->size, plane_no->size)) { - PyErr_SetString(PyExc_RuntimeError, "geometry.intersect_line_plane(...) can't use 2D Vectors"); - return NULL; - } - - if(isect_line_plane_v3(isect, line_a->vec, line_b->vec, plane_co->vec, plane_no->vec, no_flip) == 1) { - return newVectorObject(isect, 3, Py_NEW, NULL); - } - else { - Py_RETURN_NONE; - } -} - - -PyDoc_STRVAR(M_Geometry_intersect_line_sphere_doc, -".. function:: intersect_line_sphere(line_a, line_b, sphere_co, sphere_radius, clip=True)\n" -"\n" -" Takes a lines (as 2 vectors), a sphere as a point and a radius and\n" -" returns the intersection\n" -"\n" -" :arg line_a: First point of the first line\n" -" :type line_a: :class:`mathutils.Vector`\n" -" :arg line_b: Second point of the first line\n" -" :type line_b: :class:`mathutils.Vector`\n" -" :arg sphere_co: The center of the sphere\n" -" :type sphere_co: :class:`mathutils.Vector`\n" -" :arg sphere_radius: Radius of the sphere\n" -" :type sphere_radius: sphere_radius\n" -" :return: The intersection points as a pair of vectors or None when there is no intersection\n" -" :rtype: A tuple pair containing :class:`mathutils.Vector` or None\n" -); -static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *line_a, *line_b, *sphere_co; - float sphere_radius; - int clip= TRUE; - - float isect_a[3]; - float isect_b[3]; - - if(!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere", - &vector_Type, &line_a, - &vector_Type, &line_b, - &vector_Type, &sphere_co, - &sphere_radius, &clip) - ) { - return NULL; - } - - if( BaseMath_ReadCallback(line_a) == -1 || - BaseMath_ReadCallback(line_b) == -1 || - BaseMath_ReadCallback(sphere_co) == -1 - ) { - return NULL; - } - - if(ELEM3(2, line_a->size, line_b->size, sphere_co->size)) { - PyErr_SetString(PyExc_RuntimeError, "geometry.intersect_line_sphere(...) can't use 2D Vectors"); - return NULL; - } - else { - short use_a= TRUE; - short use_b= TRUE; - float lambda; - - PyObject *ret= PyTuple_New(2); - - switch(isect_line_sphere_v3(line_a->vec, line_b->vec, sphere_co->vec, sphere_radius, isect_a, isect_b)) { - case 1: - if(!(!clip || (((lambda= line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE; - use_b= FALSE; - break; - case 2: - if(!(!clip || (((lambda= line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE; - if(!(!clip || (((lambda= line_point_factor_v3(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b= FALSE; - break; - default: - use_a= FALSE; - use_b= FALSE; - } - - if(use_a) { PyTuple_SET_ITEM(ret, 0, newVectorObject(isect_a, 3, Py_NEW, NULL)); } - else { PyTuple_SET_ITEM(ret, 0, Py_None); Py_INCREF(Py_None); } - - if(use_b) { PyTuple_SET_ITEM(ret, 1, newVectorObject(isect_b, 3, Py_NEW, NULL)); } - else { PyTuple_SET_ITEM(ret, 1, Py_None); Py_INCREF(Py_None); } - - return ret; - } -} - -/* keep in sync with M_Geometry_intersect_line_sphere */ -PyDoc_STRVAR(M_Geometry_intersect_line_sphere_2d_doc, -".. function:: intersect_line_sphere_2d(line_a, line_b, sphere_co, sphere_radius, clip=True)\n" -"\n" -" Takes a lines (as 2 vectors), a sphere as a point and a radius and\n" -" returns the intersection\n" -"\n" -" :arg line_a: First point of the first line\n" -" :type line_a: :class:`mathutils.Vector`\n" -" :arg line_b: Second point of the first line\n" -" :type line_b: :class:`mathutils.Vector`\n" -" :arg sphere_co: The center of the sphere\n" -" :type sphere_co: :class:`mathutils.Vector`\n" -" :arg sphere_radius: Radius of the sphere\n" -" :type sphere_radius: sphere_radius\n" -" :return: The intersection points as a pair of vectors or None when there is no intersection\n" -" :rtype: A tuple pair containing :class:`mathutils.Vector` or None\n" -); -static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *line_a, *line_b, *sphere_co; - float sphere_radius; - int clip= TRUE; - - float isect_a[3]; - float isect_b[3]; - - if(!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere_2d", - &vector_Type, &line_a, - &vector_Type, &line_b, - &vector_Type, &sphere_co, - &sphere_radius, &clip) - ) { - return NULL; - } - - if( BaseMath_ReadCallback(line_a) == -1 || - BaseMath_ReadCallback(line_b) == -1 || - BaseMath_ReadCallback(sphere_co) == -1 - ) { - return NULL; - } - else { - short use_a= TRUE; - short use_b= TRUE; - float lambda; - - PyObject *ret= PyTuple_New(2); - - switch(isect_line_sphere_v3(line_a->vec, line_b->vec, sphere_co->vec, sphere_radius, isect_a, isect_b)) { - case 1: - if(!(!clip || (((lambda= line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE; - use_b= FALSE; - break; - case 2: - if(!(!clip || (((lambda= line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a= FALSE; - if(!(!clip || (((lambda= line_point_factor_v2(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b= FALSE; - break; - default: - use_a= FALSE; - use_b= FALSE; - } - - if(use_a) { PyTuple_SET_ITEM(ret, 0, newVectorObject(isect_a, 2, Py_NEW, NULL)); } - else { PyTuple_SET_ITEM(ret, 0, Py_None); Py_INCREF(Py_None); } - - if(use_b) { PyTuple_SET_ITEM(ret, 1, newVectorObject(isect_b, 2, Py_NEW, NULL)); } - else { PyTuple_SET_ITEM(ret, 1, Py_None); Py_INCREF(Py_None); } - - return ret; - } -} - -PyDoc_STRVAR(M_Geometry_intersect_point_line_doc, -".. function:: intersect_point_line(pt, line_p1, line_p2)\n" -"\n" -" Takes a point and a line and returns a tuple with the closest point on the line and its distance from the first point of the line as a percentage of the length of the line.\n" -"\n" -" :arg pt: Point\n" -" :type pt: :class:`mathutils.Vector`\n" -" :arg line_p1: First point of the line\n" -" :type line_p1: :class:`mathutils.Vector`\n" -" :arg line_p1: Second point of the line\n" -" :type line_p1: :class:`mathutils.Vector`\n" -" :rtype: (:class:`mathutils.Vector`, float)\n" -); -static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *pt, *line_1, *line_2; - float pt_in[3], pt_out[3], l1[3], l2[3]; - float lambda; - PyObject *ret; - - if(!PyArg_ParseTuple(args, "O!O!O!:intersect_point_line", - &vector_Type, &pt, - &vector_Type, &line_1, - &vector_Type, &line_2) - ) { - return NULL; - } - - if(BaseMath_ReadCallback(pt) == -1 || BaseMath_ReadCallback(line_1) == -1 || BaseMath_ReadCallback(line_2) == -1) - return NULL; - - /* accept 2d verts */ - if (pt->size==3) { VECCOPY(pt_in, pt->vec);} - else { pt_in[2]=0.0; VECCOPY2D(pt_in, pt->vec) } - - if (line_1->size==3) { VECCOPY(l1, line_1->vec);} - else { l1[2]=0.0; VECCOPY2D(l1, line_1->vec) } - - if (line_2->size==3) { VECCOPY(l2, line_2->vec);} - else { l2[2]=0.0; VECCOPY2D(l2, line_2->vec) } - - /* do the calculation */ - lambda= closest_to_line_v3(pt_out, pt_in, l1, l2); - - ret= PyTuple_New(2); - PyTuple_SET_ITEM(ret, 0, newVectorObject(pt_out, 3, Py_NEW, NULL)); - PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(lambda)); - return ret; -} - -PyDoc_STRVAR(M_Geometry_intersect_point_tri_2d_doc, -".. function:: intersect_point_tri_2d(pt, tri_p1, tri_p2, tri_p3)\n" -"\n" -" Takes 4 vectors (using only the x and y coordinates): one is the point and the next 3 define the triangle. Returns 1 if the point is within the triangle, otherwise 0.\n" -"\n" -" :arg pt: Point\n" -" :type v1: :class:`mathutils.Vector`\n" -" :arg tri_p1: First point of the triangle\n" -" :type tri_p1: :class:`mathutils.Vector`\n" -" :arg tri_p2: Second point of the triangle\n" -" :type tri_p2: :class:`mathutils.Vector`\n" -" :arg tri_p3: Third point of the triangle\n" -" :type tri_p3: :class:`mathutils.Vector`\n" -" :rtype: int\n" -); -static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *pt_vec, *tri_p1, *tri_p2, *tri_p3; - - if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_point_tri_2d", - &vector_Type, &pt_vec, - &vector_Type, &tri_p1, - &vector_Type, &tri_p2, - &vector_Type, &tri_p3) - ) { - return NULL; - } - - if(BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(tri_p1) == -1 || BaseMath_ReadCallback(tri_p2) == -1 || BaseMath_ReadCallback(tri_p3) == -1) - return NULL; - - return PyLong_FromLong(isect_point_tri_v2(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec)); -} - -PyDoc_STRVAR(M_Geometry_intersect_point_quad_2d_doc, -".. function:: intersect_point_quad_2d(pt, quad_p1, quad_p2, quad_p3, quad_p4)\n" -"\n" -" Takes 5 vectors (using only the x and y coordinates): one is the point and the next 4 define the quad, only the x and y are used from the vectors. Returns 1 if the point is within the quad, otherwise 0.\n" -"\n" -" :arg pt: Point\n" -" :type v1: :class:`mathutils.Vector`\n" -" :arg quad_p1: First point of the quad\n" -" :type quad_p1: :class:`mathutils.Vector`\n" -" :arg quad_p2: Second point of the quad\n" -" :type quad_p2: :class:`mathutils.Vector`\n" -" :arg quad_p3: Third point of the quad\n" -" :type quad_p3: :class:`mathutils.Vector`\n" -" :arg quad_p4: Forth point of the quad\n" -" :type quad_p4: :class:`mathutils.Vector`\n" -" :rtype: int\n" -); -static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *pt_vec, *quad_p1, *quad_p2, *quad_p3, *quad_p4; - - if(!PyArg_ParseTuple(args, "O!O!O!O!O!:intersect_point_quad_2d", - &vector_Type, &pt_vec, - &vector_Type, &quad_p1, - &vector_Type, &quad_p2, - &vector_Type, &quad_p3, - &vector_Type, &quad_p4) - ) { - return NULL; - } - - if(BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(quad_p1) == -1 || BaseMath_ReadCallback(quad_p2) == -1 || BaseMath_ReadCallback(quad_p3) == -1 || BaseMath_ReadCallback(quad_p4) == -1) - return NULL; - - return PyLong_FromLong(isect_point_quad_v2(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec)); -} - -static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray) -{ - int len, i; - PyObject *list_item, *item_1, *item_2; - boxPack *box; - - - /* Error checking must already be done */ - if(!PyList_Check(value)) { - PyErr_SetString(PyExc_TypeError, "can only back a list of [x, y, w, h]"); - return -1; - } - - len= PyList_Size(value); - - (*boxarray)= MEM_mallocN(len*sizeof(boxPack), "boxPack box"); - - - for(i= 0; i < len; i++) { - list_item= PyList_GET_ITEM(value, i); - if(!PyList_Check(list_item) || PyList_Size(list_item) < 4) { - MEM_freeN(*boxarray); - PyErr_SetString(PyExc_TypeError, "can only pack a list of [x, y, w, h]"); - return -1; - } - - box= (*boxarray)+i; - - item_1= PyList_GET_ITEM(list_item, 2); - item_2= PyList_GET_ITEM(list_item, 3); - - box->w= (float)PyFloat_AsDouble(item_1); - box->h= (float)PyFloat_AsDouble(item_2); - box->index= i; - - if (box->w < 0.0f || box->h < 0.0f) { - MEM_freeN(*boxarray); - PyErr_SetString(PyExc_TypeError, "error parsing width and height values from list: [x, y, w, h], not numbers or below zero"); - return -1; - } - - /* verts will be added later */ - } - return 0; -} - -static void boxPack_ToPyObject(PyObject *value, boxPack **boxarray) -{ - int len, i; - PyObject *list_item; - boxPack *box; - - len= PyList_Size(value); - - for(i= 0; i < len; i++) { - box= (*boxarray)+i; - list_item= PyList_GET_ITEM(value, box->index); - PyList_SET_ITEM(list_item, 0, PyFloat_FromDouble(box->x)); - PyList_SET_ITEM(list_item, 1, PyFloat_FromDouble(box->y)); - } - MEM_freeN(*boxarray); -} - -PyDoc_STRVAR(M_Geometry_box_pack_2d_doc, -".. function:: box_pack_2d(boxes)\n" -"\n" -" Returns the normal of the 3D tri or quad.\n" -"\n" -" :arg boxes: list of boxes, each box is a list where the first 4 items are [x, y, width, height, ...] other items are ignored.\n" -" :type boxes: list\n" -" :return: the width and height of the packed bounding box\n" -" :rtype: tuple, pair of floats\n" -); -static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlist) -{ - float tot_width= 0.0f, tot_height= 0.0f; - int len; - - PyObject *ret; - - if(!PyList_Check(boxlist)) { - PyErr_SetString(PyExc_TypeError, "expected a list of boxes [[x, y, w, h], ... ]"); - return NULL; - } - - len= PyList_GET_SIZE(boxlist); - if (len) { - boxPack *boxarray= NULL; - if(boxPack_FromPyObject(boxlist, &boxarray) == -1) { - return NULL; /* exception set */ - } - - /* Non Python function */ - boxPack2D(boxarray, len, &tot_width, &tot_height); - - boxPack_ToPyObject(boxlist, &boxarray); - } - - ret= PyTuple_New(2); - PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(tot_width)); - PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(tot_width)); - return ret; -} - -PyDoc_STRVAR(M_Geometry_interpolate_bezier_doc, -".. function:: interpolate_bezier(knot1, handle1, handle2, knot2, resolution)\n" -"\n" -" Interpolate a bezier spline segment.\n" -"\n" -" :arg knot1: First bezier spline point.\n" -" :type knot1: :class:`mathutils.Vector`\n" -" :arg handle1: First bezier spline handle.\n" -" :type handle1: :class:`mathutils.Vector`\n" -" :arg handle2: Second bezier spline handle.\n" -" :type handle2: :class:`mathutils.Vector`\n" -" :arg knot2: Second bezier spline point.\n" -" :type knot2: :class:`mathutils.Vector`\n" -" :arg resolution: Number of points to return.\n" -" :type resolution: int\n" -" :return: The interpolated points\n" -" :rtype: list of :class:`mathutils.Vector`'s\n" -); -static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject* args) -{ - VectorObject *vec_k1, *vec_h1, *vec_k2, *vec_h2; - int resolu; - int dims; - int i; - float *coord_array, *fp; - PyObject *list; - - float k1[4]= {0.0, 0.0, 0.0, 0.0}; - float h1[4]= {0.0, 0.0, 0.0, 0.0}; - float k2[4]= {0.0, 0.0, 0.0, 0.0}; - float h2[4]= {0.0, 0.0, 0.0, 0.0}; - - - if(!PyArg_ParseTuple(args, "O!O!O!O!i:interpolate_bezier", - &vector_Type, &vec_k1, - &vector_Type, &vec_h1, - &vector_Type, &vec_h2, - &vector_Type, &vec_k2, &resolu) - ) { - return NULL; - } - - if(resolu <= 1) { - PyErr_SetString(PyExc_ValueError, "resolution must be 2 or over"); - return NULL; - } - - if(BaseMath_ReadCallback(vec_k1) == -1 || BaseMath_ReadCallback(vec_h1) == -1 || BaseMath_ReadCallback(vec_k2) == -1 || BaseMath_ReadCallback(vec_h2) == -1) - return NULL; - - dims= MAX4(vec_k1->size, vec_h1->size, vec_h2->size, vec_k2->size); - - for(i=0; i < vec_k1->size; i++) k1[i]= vec_k1->vec[i]; - for(i=0; i < vec_h1->size; i++) h1[i]= vec_h1->vec[i]; - for(i=0; i < vec_k2->size; i++) k2[i]= vec_k2->vec[i]; - for(i=0; i < vec_h2->size; i++) h2[i]= vec_h2->vec[i]; - - coord_array= MEM_callocN(dims * (resolu) * sizeof(float), "interpolate_bezier"); - for(i=0; isize != 3 || - vec_t1_src->size != 3 || - vec_t2_src->size != 3 || - vec_t3_src->size != 3 || - vec_t1_tar->size != 3 || - vec_t2_tar->size != 3 || - vec_t3_tar->size != 3) - { - PyErr_SetString(PyExc_ValueError, "One of more of the vector arguments wasnt a 3D vector"); - return NULL; - } - - barycentric_transform(vec, vec_pt->vec, - vec_t1_tar->vec, vec_t2_tar->vec, vec_t3_tar->vec, - vec_t1_src->vec, vec_t2_src->vec, vec_t3_src->vec); - - return newVectorObject(vec, 3, Py_NEW, NULL); -} - -static PyMethodDef M_Geometry_methods[]= { - {"intersect_ray_tri", (PyCFunction) M_Geometry_intersect_ray_tri, METH_VARARGS, M_Geometry_intersect_ray_tri_doc}, - {"intersect_point_line", (PyCFunction) M_Geometry_intersect_point_line, METH_VARARGS, M_Geometry_intersect_point_line_doc}, - {"intersect_point_tri_2d", (PyCFunction) M_Geometry_intersect_point_tri_2d, METH_VARARGS, M_Geometry_intersect_point_tri_2d_doc}, - {"intersect_point_quad_2d", (PyCFunction) M_Geometry_intersect_point_quad_2d, METH_VARARGS, M_Geometry_intersect_point_quad_2d_doc}, - {"intersect_line_line", (PyCFunction) M_Geometry_intersect_line_line, METH_VARARGS, M_Geometry_intersect_line_line_doc}, - {"intersect_line_line_2d", (PyCFunction) M_Geometry_intersect_line_line_2d, METH_VARARGS, M_Geometry_intersect_line_line_2d_doc}, - {"intersect_line_plane", (PyCFunction) M_Geometry_intersect_line_plane, METH_VARARGS, M_Geometry_intersect_line_plane_doc}, - {"intersect_line_sphere", (PyCFunction) M_Geometry_intersect_line_sphere, METH_VARARGS, M_Geometry_intersect_line_sphere_doc}, - {"intersect_line_sphere_2d", (PyCFunction) M_Geometry_intersect_line_sphere_2d, METH_VARARGS, M_Geometry_intersect_line_sphere_2d_doc}, - {"interpolate_bezier", (PyCFunction) M_Geometry_interpolate_bezier, METH_VARARGS, M_Geometry_interpolate_bezier_doc}, - {"area_tri", (PyCFunction) M_Geometry_area_tri, METH_VARARGS, M_Geometry_area_tri_doc}, - {"normal", (PyCFunction) M_Geometry_normal, METH_VARARGS, M_Geometry_normal_doc}, - {"tesselate_polygon", (PyCFunction) M_Geometry_tesselate_polygon, METH_O, M_Geometry_tesselate_polygon_doc}, - {"box_pack_2d", (PyCFunction) M_Geometry_box_pack_2d, METH_O, M_Geometry_box_pack_2d_doc}, - {"barycentric_transform", (PyCFunction) M_Geometry_barycentric_transform, METH_VARARGS, M_Geometry_barycentric_transform_doc}, - {NULL, NULL, 0, NULL} -}; - -static struct PyModuleDef M_Geometry_module_def= { - PyModuleDef_HEAD_INIT, - "mathutils.geometry", /* m_name */ - M_Geometry_doc, /* m_doc */ - 0, /* m_size */ - M_Geometry_methods, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ -}; - -/*----------------------------MODULE INIT-------------------------*/ -PyMODINIT_FUNC BPyInit_mathutils_geometry(void) -{ - PyObject *submodule= PyModule_Create(&M_Geometry_module_def); - return submodule; -} From c31a5f99f90cacb1035fd1e0cb13e12c1aadfd91 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 18 Jul 2011 15:12:35 +0000 Subject: [PATCH 31/68] update to match changes in trunk --- source/blender/blenkernel/intern/cdderivedmesh.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 7c9c654b27b..d0ea14bc18c 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -291,8 +291,8 @@ static void cdDM_drawSelectedVerts(DerivedMesh *dm) else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ GPU_vertex_setup(dm); if( !GPU_buffer_legacy(dm) ) { - if(dm->drawObject->nelements) glDrawArrays(GL_POINTS,0, dm->drawObject->nelements); - else glDrawArrays(GL_POINTS,0, dm->drawObject->nlooseverts); + if(dm->drawObject->tot_triangle_point) glDrawArrays(GL_POINTS,0, dm->drawObject->tot_triangle_point); + else glDrawArrays(GL_POINTS,0, dm->drawObject->tot_loose_point); } GPU_buffer_unbind(); } From 9661d88f2bb6435aaa41e9347bb0e21301c9ecd2 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 18 Jul 2011 16:47:21 +0000 Subject: [PATCH 32/68] Fixed an indexing problem with the regular mouse vertex select in weight paint. It will draw vertices in wire mode. --- .../blender/editors/space_view3d/drawobject.c | 29 ++++++++++--------- .../editors/space_view3d/view3d_select.c | 3 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 0196149c789..66539b2b25d 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2619,7 +2619,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D Mesh *me = ob->data; Material *ma= give_current_material(ob, 1); const short hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO)); - const short is_paint_sel= (ob==OBACT && paint_facesel_test(ob)); + const short is_paint_sel= (ob==OBACT && (paint_facesel_test(ob))); int draw_wire = 0; int /* totvert,*/ totedge, totface; DerivedMesh *dm= mesh_get_derived_final(scene, ob, scene->customdata_mask); @@ -2775,16 +2775,6 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D glDisable(GL_LIGHTING); GPU_disable_material(); - // Jason - if(paint_vertsel_test(ob)) { - glColor3f(0.0f, 0.0f, 0.0f); - glPointSize(2.0f); - dm->drawEdges(dm, (dt==OB_WIRE || totface==0), me->drawflag); - glPointSize(3.0f); - dm->drawSelectedVerts(dm); - //draw_obmode_dm_verts(dm, 1); - glPointSize(1.0f); - } } else if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_TEXTURE_PAINT)) { if(me->mcol) @@ -2796,7 +2786,6 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D } } } - /* set default draw color back for wire or for draw-extra later on */ if (dt!=OB_WIRE) { if(base->flag & SELECT) { @@ -2855,7 +2844,21 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D bglPolygonOffset(rv3d->dist, 0.0); } } - + // Jason + if(paint_vertsel_test(ob)) { + glColor3f(0.0f, 0.0f, 0.0f); + glPointSize(2.0f); + // TODO clarify: + // there is clearly something I don't understand, when it was + // dt != OB_WIRE instead, it still drew in wire mode! + if(dt != OB_SOLID) { + dm->drawEdges(dm, (totface==0), TRUE); + } + glPointSize(3.0f); + dm->drawSelectedVerts(dm); + //draw_obmode_dm_verts(dm, 1); + glPointSize(1.0f); + } dm->release(dm); } diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 99f3580fa15..d362575e401 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1913,11 +1913,10 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) WM_operator_properties_gesture_border(ot, TRUE); } /*Jason*/ -static void findnearestWPvert__doClosest(void *userData, MVert *mv, int x, int y, int index) +static void findnearestWPvert__doClosest(void *userData, MVert *mv, int x, int y, int UNUSED(index)) { struct { MVert *mv; short dist, select; int mval[2]; } *data = userData; float temp = abs(data->mval[0]-x) + abs(data->mval[1]-y); - mv = mv+index; if((mv->flag & SELECT)==data->select) temp += 5; From 6d6bb264ef52680cb4c559627b512723d8f07095 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 18 Jul 2011 17:38:17 +0000 Subject: [PATCH 33/68] Started adding vertex masking--supports regular painting, and setting weight (Shift+K) Removed my unreferenced vars --- .../blender/editors/armature/meshlaplacian.c | 18 ++++++----- source/blender/editors/mesh/editmesh_mods.c | 1 - .../editors/sculpt_paint/paint_image.c | 5 ++++ .../editors/sculpt_paint/paint_intern.h | 1 + .../editors/sculpt_paint/paint_vertex.c | 30 +++++++++++++------ 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index b99605e65c1..0c2f8ca2ed4 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -657,22 +657,26 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, int *vertsflipped = NULL, *mask= NULL; int a, totface, j, bbone, firstsegment, lastsegment; + // Jason + MVert *mv = me->mvert; + int selectedVerts; + *err_str= NULL; /* count triangles and create mask */ - if(me->editflag & ME_EDIT_PAINT_MASK) + if((me->editflag & ME_EDIT_PAINT_MASK) || (selectedVerts=(me->editflag & ME_EDIT_VERT_SEL))) mask= MEM_callocN(sizeof(int)*me->totvert, "heat_bone_weighting mask"); for(totface=0, a=0, mface=me->mface; atotface; a++, mface++) { totface++; if(mface->v4) totface++; - - if(mask && (mface->flag & ME_FACE_SEL)) { - mask[mface->v1]= 1; - mask[mface->v2]= 1; - mask[mface->v3]= 1; + // Jason (added selectedVerts content for vertex mask, they used to just equal 1) + if(mask && ((mface->flag & ME_FACE_SEL) || selectedVerts)) { + mask[mface->v1]= selectedVerts ? ((mv+mface->v1)->flag & 1): 1; + mask[mface->v2]= selectedVerts ? ((mv+mface->v2)->flag & 1): 1; + mask[mface->v3]= selectedVerts ? ((mv+mface->v3)->flag & 1): 1; if(mface->v4) - mask[mface->v4]= 1; + mask[mface->v4]= selectedVerts ? ((mv+mface->v4)->flag & 1): 1; } } diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 0f7538249bc..9497370a4fa 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -328,7 +328,6 @@ int EM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); - else if(paint_vertsel_test(vc->obact));// Jason, vertex selecting else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 3843f2e371b..ba8ed35b33e 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5400,6 +5400,11 @@ int vert_paint_poll(bContext *C) { return paint_vertsel_test(CTX_data_active_object(C)); } +// Jason +int mask_paint_poll(bContext *C) +{ + return paint_facesel_test(CTX_data_active_object(C)) || paint_vertsel_test(CTX_data_active_object(C)); +} /* use project paint to re-apply an image */ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op) { diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 9894469fa82..95a6d0c2732 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -124,6 +124,7 @@ void PAINT_OT_face_select_reveal(struct wmOperatorType *ot); /* Jason */ void PAINT_OT_vert_select_all(struct wmOperatorType *ot); int vert_paint_poll(struct bContext *C); +int mask_paint_poll(struct bContext *C); int facemask_paint_poll(struct bContext *C); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 562a46586b9..0f2e8b84e9f 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -398,11 +398,15 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) unsigned char i; int vgroup_mirror= -1; int selected; - + // Jason + int selectedVerts; + me= ob->data; if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return; selected= (me->editflag & ME_EDIT_PAINT_MASK); + // Jason + selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); indexar= get_indexarray(me); @@ -438,6 +442,11 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) faceverts[3]= mface->v4; for (i=0; i<3 || faceverts[i]; i++) { if(!((me->dvert+faceverts[i])->flag)) { + // Jason + if(selectedVerts && !((me->mvert+faceverts[i])->flag & 1)) { + continue; + } + dw= defvert_verify_index(me->dvert+faceverts[i], vgroup); if(dw) { uw= defvert_verify_index(wp->wpaint_prev+faceverts[i], vgroup); @@ -1278,7 +1287,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * float totchange = 0.0f; float totchange_allowed = 0.0f; float left_over; - float change; + int total_valid = 0; int total_changed = 0; int i; @@ -1441,8 +1450,6 @@ static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeig MDeformVert *dvert = me->dvert+index; MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); - int i; - dv->dw= MEM_dupallocN(dvert->dw); dv->flag = dvert->flag; dv->totweight = dvert->totweight; @@ -1888,6 +1895,9 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float alpha; float mval[2], pressure; + // Jason + int selectedVerts; + /* cannot paint if there is no stroke data */ if (wpd == NULL) { // XXX: force a redraw here, since even though we can't paint, @@ -1935,6 +1945,8 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P } } } + // Jason + selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); if((me->editflag & ME_EDIT_PAINT_MASK) && me->mface) { for(index=0; indextotface) { MFace *mface= me->mface + (indexar[index]-1); - (me->dvert+mface->v1)->flag= 1; - (me->dvert+mface->v2)->flag= 1; - (me->dvert+mface->v3)->flag= 1; - if(mface->v4) (me->dvert+mface->v4)->flag= 1; + (me->dvert+mface->v1)->flag= selectedVerts ? ((me->mvert+mface->v1)->flag & 1): 1; + (me->dvert+mface->v2)->flag= selectedVerts ? ((me->mvert+mface->v2)->flag & 1): 1; + (me->dvert+mface->v3)->flag= selectedVerts ? ((me->mvert+mface->v3)->flag & 1): 1; + if(mface->v4) (me->dvert+mface->v4)->flag= selectedVerts ? ((me->mvert+mface->v4)->flag & 1): 1; if(brush->vertexpaint_tool==VP_BLUR) { MDeformWeight *dw, *(*dw_func)(MDeformVert *, const int); @@ -2144,7 +2156,7 @@ void PAINT_OT_weight_set(wmOperatorType *ot) /* api callbacks */ ot->exec= weight_paint_set_exec; - ot->poll= facemask_paint_poll; + ot->poll= mask_paint_poll; // Jason, it was facemask_paint_poll /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; From c6444eaa0f1a3ef7bf50c1e2d0d0b54406f75732 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Jul 2011 00:06:43 +0000 Subject: [PATCH 34/68] avoid setting the color for every loop --- .../blender/blenkernel/intern/cdderivedmesh.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index d0ea14bc18c..edad8ee0dac 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -275,14 +275,23 @@ static void cdDM_drawSelectedVerts(DerivedMesh *dm) MVert *mv = cddm->mvert; int i; if( GPU_buffer_legacy(dm) ) { + char prev_sel= 0; /* always invalid */; + glBegin(GL_POINTS); for(i = 0; i < dm->numVertData; i++, mv++) { - if((mv->flag & 1)) {//TODO define selected - glColor3f(1.0f, 1.0f, 0.0f); - }else { - glColor3f(0.0f, 0.0f, 0.0f); - } if(!(mv->flag & ME_HIDE)) { + const char sel= mv->flag & 1; + if(prev_sel != sel) { + prev_sel= sel; + + // TODO define selected color + if(sel) { + glColor3f(1.0f, 1.0f, 0.0f); + }else { + glColor3f(0.0f, 0.0f, 0.0f); + } + } + glVertex3fv(mv->co); } } From fb3783bd13c5258e48d3c94abce82e3b9156adac Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 20 Jul 2011 15:56:35 +0000 Subject: [PATCH 35/68] Added vertex masking support for the weight paint vgroup functions including: Normalize, Normalize All, Invert, Clean, and Levels. Face mask and vertex select/mask are now mutually exclusive options. Went ahead and allowed vertex selection support and masking for vertex paint. --- .../blender/blenkernel/intern/DerivedMesh.c | 2 +- source/blender/blenkernel/intern/paint.c | 2 +- source/blender/editors/object/object_vgroup.c | 64 +++++++++++++++- .../editors/sculpt_paint/paint_vertex.c | 75 ++++++++++++++----- .../blender/editors/space_view3d/drawmesh.c | 2 +- .../blender/editors/space_view3d/drawobject.c | 8 +- .../editors/space_view3d/view3d_header.c | 14 ++-- source/blender/makesrna/intern/rna_mesh.c | 22 +++++- 8 files changed, 156 insertions(+), 33 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index a35ad48e599..ba67e580aca 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -2333,7 +2333,7 @@ static void clear_mesh_caches(Object *ob) static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask) { Object *obact = scene->basact?scene->basact->object:NULL; - int editing = paint_facesel_test(ob); + int editing = paint_facesel_test(ob) || paint_vertsel_test(ob);// Jason: paint_vertsel_test /* weight paint and face select need original indices because of selection buffer drawing */ int needMapping = (ob==obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT|OB_MODE_VERTEX_PAINT))); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 9a0fc541bce..5dc58ba4aa8 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -99,7 +99,7 @@ int paint_facesel_test(Object *ob) /* Jason */ int paint_vertsel_test(Object *ob) { - return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & (OB_MODE_WEIGHT_PAINT))); + return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT))); } void paint_init(Paint *p, const char col[3]) { diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 4250e7e76fb..e70b36cfa13 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -701,6 +701,10 @@ static void vgroup_normalize(Object *ob) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; + // Jason + Mesh *me = ob->data; + MVert *mv = me->mvert; + int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -712,6 +716,11 @@ static void vgroup_normalize(Object *ob) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; dw = defvert_find_index(dvert, def_nr); if(dw) { @@ -721,6 +730,11 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; dw = defvert_find_index(dvert, def_nr); if(dw) { @@ -742,7 +756,11 @@ static void vgroup_levels(Object *ob, float offset, float gain) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - + // Jason + Mesh *me = ob->data; + MVert *mv = me->mvert; + int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); dg = BLI_findlink(&ob->defbase, (ob->actdef-1)); @@ -751,6 +769,11 @@ static void vgroup_levels(Object *ob, float offset, float gain) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; dw = defvert_find_index(dvert, def_nr); if(dw) { @@ -772,6 +795,11 @@ static void vgroup_normalize_all(Object *ob, int lock_active) int i, dvert_tot=0; float tot_weight; + // Jason + Mesh *me = ob->data; + MVert *mv = me->mvert; + int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); if(dvert_array) { @@ -781,6 +809,10 @@ static void vgroup_normalize_all(Object *ob, int lock_active) for(i = 0; i < dvert_tot; i++) { float lock_iweight= 1.0f; int j; + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } tot_weight= 0.0f; dw_act= NULL; @@ -821,6 +853,11 @@ static void vgroup_normalize_all(Object *ob, int lock_active) else { for(i = 0; i < dvert_tot; i++) { int j; + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } + tot_weight= 0.0f; dvert = dvert_array[i]; @@ -880,6 +917,10 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; + // Jason + Mesh *me = ob->data; + MVert *mv = me->mvert; + int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -890,6 +931,10 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) for(i = 0; i < dvert_tot; i++) { + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } dvert = dvert_array[i]; if(auto_assign) { @@ -1002,6 +1047,10 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; + // Jason + Mesh *me = ob->data; + MVert *mv = me->mvert; + int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1011,6 +1060,10 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } dvert = dvert_array[i]; dw= defvert_find_index(dvert, def_nr); @@ -1032,12 +1085,21 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, dvert_tot=0; + // Jason + Mesh *me = ob->data; + MVert *mv = me->mvert; + int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); if(dvert_array) { for(i = 0; i < dvert_tot; i++) { int j; + // Jason + if(selectedVerts && !((mv+i)->flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; j= dvert->totweight; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 0f2e8b84e9f..c0822ca134a 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -361,8 +361,10 @@ void vpaint_fill(Object *ob, unsigned int paintcol) Mesh *me; MFace *mf; unsigned int *mcol; - int i, selected; - + int i, selected, selectedVerts;//Jason + // Jason + MVert *mv; + me= get_mesh(ob); if(me==NULL || me->totface==0) return; @@ -370,15 +372,29 @@ void vpaint_fill(Object *ob, unsigned int paintcol) make_vertexcol(ob); selected= (me->editflag & ME_EDIT_PAINT_MASK); + // Jason + selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); + mv = me->mvert; mf = me->mface; mcol = (unsigned int*)me->mcol; for (i = 0; i < me->totface; i++, mf++, mcol+=4) { - if (!selected || mf->flag & ME_FACE_SEL) { - mcol[0] = paintcol; - mcol[1] = paintcol; - mcol[2] = paintcol; - mcol[3] = paintcol; + if (!selected || mf->flag & ME_FACE_SEL || selectedVerts) { + if(selectedVerts) { + if(((mv+mf->v1)->flag & SELECT)) + mcol[0] = paintcol; + if(((mv+mf->v2)->flag & SELECT)) + mcol[1] = paintcol; + if(((mv+mf->v3)->flag & SELECT)) + mcol[2] = paintcol; + if(mf->v4 && ((mv+mf->v4)->flag & SELECT)) + mcol[3] = paintcol; + } else { + mcol[0] = paintcol; + mcol[1] = paintcol; + mcol[2] = paintcol; + mcol[3] = paintcol; + } } } @@ -443,7 +459,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) for (i=0; i<3 || faceverts[i]; i++) { if(!((me->dvert+faceverts[i])->flag)) { // Jason - if(selectedVerts && !((me->mvert+faceverts[i])->flag & 1)) { + if(selectedVerts && !((me->mvert+faceverts[i])->flag & SELECT)) { continue; } @@ -1972,10 +1988,10 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P if(indexar[index] && indexar[index]<=me->totface) { MFace *mface= me->mface + (indexar[index]-1); - (me->dvert+mface->v1)->flag= selectedVerts ? ((me->mvert+mface->v1)->flag & 1): 1; - (me->dvert+mface->v2)->flag= selectedVerts ? ((me->mvert+mface->v2)->flag & 1): 1; - (me->dvert+mface->v3)->flag= selectedVerts ? ((me->mvert+mface->v3)->flag & 1): 1; - if(mface->v4) (me->dvert+mface->v4)->flag= selectedVerts ? ((me->mvert+mface->v4)->flag & 1): 1; + (me->dvert+mface->v1)->flag= selectedVerts ? ((me->mvert+mface->v1)->flag & SELECT): 1; + (me->dvert+mface->v2)->flag= selectedVerts ? ((me->mvert+mface->v2)->flag & SELECT): 1; + (me->dvert+mface->v3)->flag= selectedVerts ? ((me->mvert+mface->v3)->flag & SELECT): 1; + if(mface->v4) (me->dvert+mface->v4)->flag= selectedVerts ? ((me->mvert+mface->v4)->flag & SELECT): 1; if(brush->vertexpaint_tool==VP_BLUR) { MDeformWeight *dw, *(*dw_func)(MDeformVert *, const int); @@ -2298,14 +2314,33 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index Brush *brush = paint_brush(&vp->paint); Mesh *me = get_mesh(ob); MFace *mface= ((MFace*)me->mface) + index; + // Jason + MVert *mv = me->mvert; + int selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); + char *m; + unsigned int *mcol= ((unsigned int*)me->mcol) + 4*index; unsigned int *mcolorig= ((unsigned int*)vp->vpaint_prev) + 4*index; float alpha; int i; + // Jason + if(selectedVerts) { + m = MEM_mallocN(sizeof(char)*4, "selectedVerts"); + m[0] = ((mv+mface->v1)->flag & SELECT); + m[1] = ((mv+mface->v2)->flag & SELECT); + m[2] = ((mv+mface->v3)->flag & SELECT); + m[3] = (mface->v4 && ((mv+mface->v4)->flag & SELECT)); + } + if((vp->flag & VP_COLINDEX && mface->mat_nr!=ob->actcol-1) || - ((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL))) - return; + ((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)) + || (selectedVerts && !(m[0] || m[1] || m[2] || m[3]))) {// Jason + if(selectedVerts) { + MEM_freeN(m); + } + return; + } if(brush->vertexpaint_tool==VP_BLUR) { unsigned int fcol1= mcol_blend( mcol[0], mcol[1], 128); @@ -2320,9 +2355,15 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index } for(i = 0; i < (mface->v4 ? 4 : 3); ++i) { - alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval, pressure); - if(alpha) - vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, (int)(alpha*255.0f)); + if(!selectedVerts || m[i]) { + alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval, pressure); + if(alpha) + vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, (int)(alpha*255.0f)); + } + } + // Jason + if(selectedVerts) { + MEM_freeN(m); } } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index f070bae4e54..81de12320e4 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -587,7 +587,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl) if(ob->mode & OB_MODE_EDIT) return; else if(ob==OBACT) - if(paint_facesel_test(ob)) + if(paint_facesel_test(ob) || paint_vertsel_test(ob)) return; ddm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 66539b2b25d..457d882845e 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2619,7 +2619,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D Mesh *me = ob->data; Material *ma= give_current_material(ob, 1); const short hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO)); - const short is_paint_sel= (ob==OBACT && (paint_facesel_test(ob))); + const short is_paint_sel= (ob==OBACT && paint_facesel_test(ob)); int draw_wire = 0; int /* totvert,*/ totedge, totface; DerivedMesh *dm= mesh_get_derived_final(scene, ob, scene->customdata_mask); @@ -2847,11 +2847,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D // Jason if(paint_vertsel_test(ob)) { glColor3f(0.0f, 0.0f, 0.0f); - glPointSize(2.0f); + glPointSize(2.0f); // TODO clarify: // there is clearly something I don't understand, when it was - // dt != OB_WIRE instead, it still drew in wire mode! - if(dt != OB_SOLID) { + // dt != OB_WIRE instead, it still drew in wire mode! (in weight paint mode) + if(dt != OB_SOLID || ob->mode & OB_MODE_VERTEX_PAINT) { dm->drawEdges(dm, (totface==0), TRUE); } glPointSize(3.0f); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index a1a73b27b8d..680bd6b62e4 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -496,12 +496,14 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) PointerRNA meshptr; RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr); - //uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); - // Jason - row= uiLayoutRow(layout, 1); - // TODO: make it so at most one can be active. - uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); - uiItemR(row, &meshptr, "wp_vert_sel", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + if(ob->mode & OB_MODE_TEXTURE_PAINT) { + uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + } else { + // Jason + row= uiLayoutRow(layout, 1); + uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + uiItemR(row, &meshptr, "wp_vert_sel", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + } } else { const char *str_menu; diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index c1b92f8fc56..adec9883ca8 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -90,6 +90,24 @@ void rna_Mesh_update_draw(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA } } +/* Jason */ +void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + Mesh* me = ptr->data; + if ((me->editflag & ME_EDIT_VERT_SEL) && (me->editflag & ME_EDIT_PAINT_MASK)) { + me->editflag ^= ME_EDIT_PAINT_MASK; + } + rna_Mesh_update_draw(bmain, scene, ptr); +} +/* Jason */ +void rna_Mesh_update_facemask(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + Mesh* me = ptr->data; + if ((me->editflag & ME_EDIT_VERT_SEL) && (me->editflag & ME_EDIT_PAINT_MASK)) { + me->editflag ^= ME_EDIT_VERT_SEL; + } + rna_Mesh_update_draw(bmain, scene, ptr); +} static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value) { MVert *mvert= (MVert*)ptr->data; @@ -2075,14 +2093,14 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_PAINT_MASK); RNA_def_property_ui_text(prop, "Paint Mask", "Face selection masking for painting"); RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0); - RNA_def_property_update(prop, 0, "rna_Mesh_update_draw"); + RNA_def_property_update(prop, 0, "rna_Mesh_update_facemask"); /* Jason */ prop= RNA_def_property(srna, "wp_vert_sel", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERT_SEL); RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex Selection for auto brushes"); RNA_def_property_ui_icon(prop, ICON_VERTEXSEL, 0); - RNA_def_property_update(prop, 0, "rna_Mesh_update_draw"); + RNA_def_property_update(prop, 0, "rna_Mesh_update_vertmask"); /* readonly editmesh info - use for extrude menu */ prop= RNA_def_property(srna, "total_vert_sel", PROP_INT, PROP_UNSIGNED); From fc2376c1dd8481058a3109b65d7a76422e11e30f Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 21 Jul 2011 16:25:07 +0000 Subject: [PATCH 36/68] Fixed a Multi-Paint + Auto Normalize issue. Beforehand, auto normalize could cause the weight to change as you brushed over vertices even if the change was less extreme than the last change. --- .../editors/sculpt_paint/paint_vertex.c | 72 +++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index c0822ca134a..32f57bb9ddb 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1462,7 +1462,7 @@ static void clamp_weights(MDeformVert *dvert) { } /*Jason*/ /* fresh start to make multi-paint and locking modular */ -static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float change, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { +static int apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defcnt, float change, float oldChange, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { MDeformVert *dvert = me->dvert+index; MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); @@ -1480,14 +1480,40 @@ static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeig dw->weight = neww; } } - clamp_weights(me->dvert+index); + clamp_weights(dvert); enforce_locks(dv, dvert, defcnt, flags, bone_groups, validmap); do_weight_paint_auto_normalize_all_groups(dvert, validmap); - + + if(oldChange && multipaint && selected > 1) { + if(tdw->weight != oldw) { + if( neww > oldw ) { + if(tdw->weight > oldw) { + //printf("should have changed\n"); + } else { + //printf("should not have changed\n"); + //reset_to_prev(dv, dvert); + MEM_freeN(dv->dw); + MEM_freeN(dv); + return TRUE; + } + } else { + if(tdw->weight < oldw) { + //printf("should have changed\n"); + } else { + //printf("should not have changed\n"); + //reset_to_prev(dv, dvert); + MEM_freeN(dv->dw); + MEM_freeN(dv); + return TRUE; + } + } + } + } MEM_freeN(dv->dw); MEM_freeN(dv); + return FALSE; } /* Jason was here duplicate function I used in DerivedMesh.c*/ @@ -1547,7 +1573,8 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int vgroup_mirror, char *validmap, int multipaint) { Mesh *me= ob->data; - MDeformWeight *dw, *uw, *tdw, *tuw; + // Jason: tdw, tuw + MDeformWeight *dw, *uw, *tdw = NULL, *tuw; int vgroup= ob->actdef-1; /* Jason was here */ @@ -1557,10 +1584,13 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int selected; float oldw; float neww; - float testw; + float testw=0; int defcnt; float change = 0; + float oldChange = 0; int i; + MDeformVert *dv = NULL; + // Need to know which groups are bone groups if(validmap) { bone_groups = validmap; @@ -1590,8 +1620,14 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, wpaint_blend(wp, dw, uw, alpha, paintweight, flip, multipaint && selected >1); neww = dw->weight; dw->weight = oldw; + // setup multi-paint if(selected > 1 && multipaint) { + dv = MEM_mallocN(sizeof (*(me->dvert+index)), "prevMDeformVert"); + + dv->dw= MEM_dupallocN((me->dvert+index)->dw); + dv->flag = (me->dvert+index)->flag; + dv->totweight = (me->dvert+index)->totweight; tdw = dw; tuw = uw; change = get_mp_change(wp->wpaint_prev+index, selection, neww-oldw); @@ -1605,17 +1641,18 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, change = 0; } } - if(change && tdw->weight * change && tuw->weight) { + if(change && tuw->weight && tuw->weight * change) { if(tdw->weight != tuw->weight) { + oldChange = tdw->weight/tuw->weight; testw = tuw->weight*change; if( testw > tuw->weight ) { - if(change > tdw->weight/tuw->weight) { + if(change > oldChange) { reset_to_prev(wp->wpaint_prev+index, me->dvert+index); } else { change = 0; } } else { - if(change < tdw->weight/tuw->weight) { + if(change < oldChange) { reset_to_prev(wp->wpaint_prev+index, me->dvert+index); } else { change = 0; @@ -1628,8 +1665,15 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } /* Jason was here */ - apply_mp_lcks_normalize(ob, me, index, dw, defcnt, change, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); - + if(apply_mp_lcks_normalize(ob, me, index, dw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint)) { + reset_to_prev(dv, me->dvert+index); + change = 0; + oldChange = 0; + } + if(dv) { + MEM_freeN(dv->dw); + MEM_freeN(dv); + } // dvert may have been altered greatly dw = defvert_find_index(me->dvert+index, vgroup); @@ -1644,7 +1688,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason */ //uw->weight= dw->weight; /* Jason */ - apply_mp_lcks_normalize(ob, me, j, uw, defcnt, change, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); + apply_mp_lcks_normalize(ob, me, j, uw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); } } /* Jason */ @@ -2336,9 +2380,9 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index if((vp->flag & VP_COLINDEX && mface->mat_nr!=ob->actcol-1) || ((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)) || (selectedVerts && !(m[0] || m[1] || m[2] || m[3]))) {// Jason - if(selectedVerts) { - MEM_freeN(m); - } + if(selectedVerts) { + MEM_freeN(m); + } return; } From 2e7144bed84633729ca442cc92969dda629a57aa Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 21 Jul 2011 18:46:59 +0000 Subject: [PATCH 37/68] Removed my earlier vertex paint vertex select--someone is changing it drastically in Salad (dynamic paint, I think), so I shouldn't have messed with it. --- source/blender/blenkernel/intern/paint.c | 2 +- .../editors/sculpt_paint/paint_vertex.c | 60 ++++--------------- .../editors/space_view3d/view3d_header.c | 2 +- 3 files changed, 12 insertions(+), 52 deletions(-) diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 5dc58ba4aa8..eac98519fcc 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -99,7 +99,7 @@ int paint_facesel_test(Object *ob) /* Jason */ int paint_vertsel_test(Object *ob) { - return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT))); + return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & OB_MODE_WEIGHT_PAINT)); } void paint_init(Paint *p, const char col[3]) { diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 32f57bb9ddb..1bfaa1ea6a4 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -361,9 +361,7 @@ void vpaint_fill(Object *ob, unsigned int paintcol) Mesh *me; MFace *mf; unsigned int *mcol; - int i, selected, selectedVerts;//Jason - // Jason - MVert *mv; + int i, selected; me= get_mesh(ob); if(me==NULL || me->totface==0) return; @@ -372,29 +370,15 @@ void vpaint_fill(Object *ob, unsigned int paintcol) make_vertexcol(ob); selected= (me->editflag & ME_EDIT_PAINT_MASK); - // Jason - selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); - mv = me->mvert; mf = me->mface; mcol = (unsigned int*)me->mcol; for (i = 0; i < me->totface; i++, mf++, mcol+=4) { - if (!selected || mf->flag & ME_FACE_SEL || selectedVerts) { - if(selectedVerts) { - if(((mv+mf->v1)->flag & SELECT)) - mcol[0] = paintcol; - if(((mv+mf->v2)->flag & SELECT)) - mcol[1] = paintcol; - if(((mv+mf->v3)->flag & SELECT)) - mcol[2] = paintcol; - if(mf->v4 && ((mv+mf->v4)->flag & SELECT)) - mcol[3] = paintcol; - } else { - mcol[0] = paintcol; - mcol[1] = paintcol; - mcol[2] = paintcol; - mcol[3] = paintcol; - } + if (!selected || mf->flag & ME_FACE_SEL) { + mcol[0] = paintcol; + mcol[1] = paintcol; + mcol[2] = paintcol; + mcol[3] = paintcol; } } @@ -2358,33 +2342,15 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index Brush *brush = paint_brush(&vp->paint); Mesh *me = get_mesh(ob); MFace *mface= ((MFace*)me->mface) + index; - // Jason - MVert *mv = me->mvert; - int selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); - char *m; unsigned int *mcol= ((unsigned int*)me->mcol) + 4*index; unsigned int *mcolorig= ((unsigned int*)vp->vpaint_prev) + 4*index; float alpha; int i; - - // Jason - if(selectedVerts) { - m = MEM_mallocN(sizeof(char)*4, "selectedVerts"); - m[0] = ((mv+mface->v1)->flag & SELECT); - m[1] = ((mv+mface->v2)->flag & SELECT); - m[2] = ((mv+mface->v3)->flag & SELECT); - m[3] = (mface->v4 && ((mv+mface->v4)->flag & SELECT)); - } if((vp->flag & VP_COLINDEX && mface->mat_nr!=ob->actcol-1) || - ((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)) - || (selectedVerts && !(m[0] || m[1] || m[2] || m[3]))) {// Jason - if(selectedVerts) { - MEM_freeN(m); - } + ((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL))) return; - } if(brush->vertexpaint_tool==VP_BLUR) { unsigned int fcol1= mcol_blend( mcol[0], mcol[1], 128); @@ -2399,15 +2365,9 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index } for(i = 0; i < (mface->v4 ? 4 : 3); ++i) { - if(!selectedVerts || m[i]) { - alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval, pressure); - if(alpha) - vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, (int)(alpha*255.0f)); - } - } - // Jason - if(selectedVerts) { - MEM_freeN(m); + alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval, pressure); + if(alpha) + vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, (int)(alpha*255.0f)); } } diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 680bd6b62e4..4632e0897f2 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -496,7 +496,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) PointerRNA meshptr; RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr); - if(ob->mode & OB_MODE_TEXTURE_PAINT) { + if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) { uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); } else { // Jason From 566d9361798ade5d9749cf59231b8c88c21bbe20 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Fri, 29 Jul 2011 17:36:49 +0000 Subject: [PATCH 38/68] 'Fix Deforms' op added to weight paint tools to smooth (remove/reduce) spiking caused by bones by altering vgroup weights --it's still really simplistic (and slow!) so don't try fixing an entire mesh! xD Also, don't use it on a mesh with a mirror modifier yet, just noticed that it does both vertices instead of one. Minor UI text update for Vertex Masking --- release/scripts/startup/bl_ui/space_view3d.py | 2 + .../startup/bl_ui/space_view3d_toolbar.py | 1 + source/blender/editors/object/object_intern.h | 1 + source/blender/editors/object/object_ops.c | 1 + source/blender/editors/object/object_vgroup.c | 398 ++++++++++++++++++ source/blender/makesrna/intern/rna_mesh.c | 2 +- 6 files changed, 404 insertions(+), 1 deletion(-) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index aef6accb4e1..a206ff3b274 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -1072,6 +1072,8 @@ class VIEW3D_MT_paint_weight(bpy.types.Menu): layout.operator("object.vertex_group_invert", text="Invert") layout.operator("object.vertex_group_clean", text="Clean") layout.operator("object.vertex_group_levels", text="Levels") + #Jason + layout.operator("object.vertex_group_fix", text="Fix Deforms") layout.separator() diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 06873225611..85a6da35bea 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -1052,6 +1052,7 @@ class VIEW3D_PT_tools_weightpaint(View3DPanel, bpy.types.Panel): col.operator("object.vertex_group_invert", text="Invert") col.operator("object.vertex_group_clean", text="Clean") col.operator("object.vertex_group_levels", text="Levels") + col.operator("object.vertex_group_fix", text="Fix Deforms") class VIEW3D_PT_tools_weightpaint_options(View3DPanel, bpy.types.Panel): diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 1d3d0a311e0..e548e68d683 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -203,6 +203,7 @@ void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_lock_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_invert_locks(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_unlock_all(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_invert(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_blend(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index c9e6004510c..ad08f08696c 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -177,6 +177,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_invert_locks); WM_operatortype_append(OBJECT_OT_vertex_group_lock_all); WM_operatortype_append(OBJECT_OT_vertex_group_unlock_all); + WM_operatortype_append(OBJECT_OT_vertex_group_fix); WM_operatortype_append(OBJECT_OT_vertex_group_invert); WM_operatortype_append(OBJECT_OT_vertex_group_levels); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index e70b36cfa13..79e8f98c630 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -60,6 +60,7 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_report.h" +#include "BKE_DerivedMesh.h"//Jason #include "RNA_access.h" #include "RNA_define.h" @@ -749,6 +750,369 @@ static void vgroup_normalize(Object *ob) if (dvert_array) MEM_freeN(dvert_array); } +// Jason +static int tryToAddVerts(int *verts, int length, int a, int b) { + char containsA = FALSE; + char containsB = FALSE; + int added = 0; + int i; + for(i = 0; i < length && (!containsA || !containsB); i++) { + if(verts[i] == a) { + containsA = TRUE; + } else if(verts[i] == b) { + containsB = TRUE; + } else if(verts[i] == -1) { + if(!containsA) { + verts[i] = a; + containsA = TRUE; + added++; + } else if(!containsB){ + verts[i] = b; + containsB = TRUE; + added++; + } + } + } + return added; +} +//Jason +static int* getSurroundingVerts(Mesh *me, int vert, int *count) { + int length = 0; + int *tverts; + int *verts = NULL; + MFace *mf = me->mface; + int totface = me->totface; + int found = 0; + int i; + for(i = 0; i < totface; i++, mf++) { + if(vert == mf->v1 || vert == mf->v2 || vert == mf->v3 || (mf->v4 &&vert == mf->v4)) { + length+=2; + } + } + if(!length) { + return 0; + } + tverts = MEM_mallocN(sizeof(int)*length, "tempSurroundingVerts"); + mf = me->mface; + for(i = 0; i < length; i++) { + tverts[i] = -1; + } + for(i = 0; i < totface; i++, mf++) { + int a=-1, b=-1; + //printf("face %d verts: %d %d %d %d\n", i, mf->v1, mf->v2, mf->v3, mf->v4); + if(mf->v1 == vert) { + a = mf->v2; + if(mf->v4) { + b = mf->v4; + } else { + b = mf->v3; + } + } else if(mf->v2 == vert) { + a = mf->v1; + b = mf->v3; + } else if(mf->v3 == vert) { + a = mf->v2; + if(mf->v4) { + b = mf->v4; + } else { + b = mf->v1; + } + } else if (mf->v4 && mf->v4 == vert){ + a = mf->v1; + b = mf->v3; + } else { + continue; + } + found += tryToAddVerts(tverts, length, a, b); + } + if(found) { + verts = MEM_mallocN(sizeof(int)* found, "surroundingVerts"); + for(i = 0; i < found; i++) { + verts[i] = tverts[i]; + } + count[0] = found; + } + MEM_freeN(tverts); + return verts; +} +static void getSingleCoordinate(MVert **points, int count, float *coord) { + int i, k; + for(k = 0; k < 3; k++) { + coord[k] = 0; + } + for(i = 0; i < count; i++) { + for(k = 0; k < 3; k++) { + coord[k] += points[i]->co[k]; + } + } + for(k = 0; k < 3; k++) { + coord[k] /= count; + } +} +static void getNearestPointOnPlane(float *norm, float d, float *coord, float *point, float *dst) { + float *temp = MEM_callocN(sizeof(float)*3, "temp"); + int i; + float dotprod = 0; + for(i = 0; i < 3; i++) { + temp[i] = point[i]-coord[i]; + } + for(i = 0; i < 3; i++) { + dotprod += temp[i]*norm[i]; + } + MEM_freeN(temp); + for(i = 0; i < 3; i++) { + dst[i] = point[i] - dotprod*norm[i]; + } +} +static float distance(float* a, float *b, int length) { + int i; + float sum = 0; + for(i = 0; i < length; i++) { + sum += (b[i]-a[i])*(b[i]-a[i]); + } + return sqrt(sum); +} +static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float **changes, int index) { + // A=Q-((Q-P).N)N + // D = (a*x0 + b*y0 +c*z0 +d) + float *projA, *projB; + projA = MEM_callocN(sizeof(float)*3, "projectedA"); + projB = MEM_callocN(sizeof(float)*3, "projectedB"); + getNearestPointOnPlane(norm, d, coord, start, projA); + getNearestPointOnPlane(norm, d, coord, end, projB); + // vertical change + changes[index][0] = norm[0]*end[0] + norm[1]*end[1] + norm[2]*end[2] + d - distToStart; + //printf("vc %f %f\n", distance(end, projB, 3)-distance(start, projA, 3), changes[index][0]); + // horizontal change + changes[index][1] = distance(projA, projB, 3); + MEM_freeN(projA); + MEM_freeN(projB); +} +static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float *norm, float *coord, float d, float distToBe, float strength, float cp) { + DerivedMesh *dm; + MDeformWeight *dw; + MVert m; + MDeformVert *dvert = me->dvert+index; + int totweight = dvert->totweight; + float oldw = 0; + float *oldPos = MEM_callocN(sizeof(float)*3, "oldPosition"); + float vc, hc; + int i, k; + float **changes = MEM_mallocN(sizeof(float)*totweight, "vertHorzChange"); + int *upDown = MEM_callocN(sizeof(int)*totweight, "upDownTracker");// track if up or down moved it closer for each bone + int *dwIndices = MEM_callocN(sizeof(int)*totweight, "dwIndexTracker"); + float distToStart; + float bestChange = 0; + int bestIndex = 0; + char wasChange; + char wasUp; + int lastIndex = -1; + float originalDistToBe = distToBe; + for(i = 0; i < totweight; i++) { + changes[i] = MEM_callocN(sizeof(float)*2, "vertHorzChange_"+i); + } + do { + wasChange = FALSE; + dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + dm->getVert(dm, index, &m); + oldPos[0] = m.co[0]; + oldPos[1] = m.co[1]; + oldPos[2] = m.co[2]; + distToStart = norm[0]*oldPos[0] + norm[1]*oldPos[1] + norm[2]*oldPos[2] + d; + //printf("dist %f \n",distToStart); + //printf("mesh point %f %f %f dpoint %f %f %f \n", (me->mvert+index)->co[0], (me->mvert+index)->co[1], (me->mvert+index)->co[3], oldPos[0], oldPos[1], oldPos[2]); + if(distToBe == originalDistToBe) { + distToBe += distToStart - distToStart*strength; + } + for(i = 0; i < totweight; i++) { + dwIndices[i] = i; + dw = (dvert->dw+i); + vc = hc = 0; + if(!dw->weight) { + changes[i][0] = 0; + changes[i][1] = 0; + continue; + } + for(k = 0; k < 2; k++) { + if(dm) { + dm->needsFree = 1; + dm->release(dm); + dm = NULL; + ob->derivedDeform=NULL; + } + oldw = dw->weight; + if(k) { + dw->weight *= 1+cp; + } else { + dw->weight /= 1+cp; + } + if(dw->weight == oldw) { + changes[i][0] = 0; + changes[i][1] = 0; + break; + } + if(dw->weight > 1) { + dw->weight = 1; + } + dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + dm->getVert(dm, index, &m); + getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m.co, changes, i); + dw->weight = oldw; + if(!k) { + vc = changes[i][0]; + hc = changes[i][1]; + } else { + if(fabs(distToStart+vc - distToBe) < fabs(distToStart+changes[i][0] - distToBe)) { + upDown[i] = 0; + changes[i][0] = vc; + changes[i][1] = hc; + } else { + upDown[i] = 1; + } + if(fabs(distToStart+changes[i][0] - distToBe) > fabs(distToStart - distToBe)) { + changes[i][0] = 0; + changes[i][1] = 0; + } + } + } + //printf("final vc: %f\n", changes[i][0]); + } + // sort the changes by the vertical change + for(k = 0; k < totweight; k++) { + float tf; + int ti; + bestChange = changes[k][0]; + bestIndex = k; + for(i = k+1; i < totweight; i++) { + vc = changes[i][0]; + + if(fabs(vc) > fabs(bestChange)) { + bestIndex = i; + bestChange = vc; + } + } + // switch with k + if(bestIndex != k) { + ti = upDown[k]; + upDown[k] = upDown[bestIndex]; + upDown[bestIndex] = ti; + + ti = dwIndices[k]; + dwIndices[k] = dwIndices[bestIndex]; + dwIndices[bestIndex] = ti; + + tf = changes[k][0]; + changes[k][0] = changes[bestIndex][0]; + changes[bestIndex][0] = tf; + + tf = changes[k][1]; + changes[k][1] = changes[bestIndex][1]; + changes[bestIndex][1] = tf; + } + } + bestIndex = -1; + // find the best change with an acceptable horizontal change + for(i = 0; i < totweight; i++) { + if(fabs(changes[i][0]) > fabs(changes[i][1]*2.0f)) { + bestIndex = i; + break; + } + } + if(bestIndex != -1) { + //printf("changing %d\n", bestIndex); + wasChange = TRUE; + if(lastIndex != -1) { + if(wasUp != upDown[bestIndex]) { + wasChange = FALSE; + } + } + lastIndex = bestIndex; + wasUp = upDown[bestIndex]; + dw = (dvert->dw+dwIndices[bestIndex]); + oldw = dw->weight; + if(upDown[bestIndex]) { + dw->weight *= 1+cp; + } else { + dw->weight /= 1+cp; + } + if(dw->weight > 1) { + dw->weight = 1; + } + if(oldw == dw->weight) { + wasChange = FALSE; + } + if(dm) { + dm->needsFree = 1; + dm->release(dm); + dm = NULL; + ob->derivedDeform=NULL; + } + } + //printf("best vc=%f hc=%f \n", changes[bestIndex][0], changes[bestIndex][1]); + }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (distToStart+changes[bestIndex][0]-distToBe)/fabs(distToStart+changes[bestIndex][0]-distToBe)); + MEM_freeN(upDown); + for(i = 0; i < totweight; i++) { + MEM_freeN(changes[i]); + } + MEM_freeN(changes); + MEM_freeN(dwIndices); + MEM_freeN(oldPos); +} +// Jason +static void vgroup_fix(Scene *scene, Object *ob, float strength, float cp) +{ + int i; + + Mesh *me = ob->data; + MVert *mv = me->mvert; + int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + int *verts = NULL; + + for(i = 0; i < me->totvert && mv; i++, mv++) { + // Jason + if(selectedVerts && (mv->flag & SELECT)) { + int *pcount = MEM_callocN(sizeof(int), "intPointer"); + int count; + if((verts = getSurroundingVerts(me, i, pcount))) { + MVert m; + MVert **p = MEM_callocN(sizeof(MVert*)*(count = pcount[0]), "deformedPoints"); + int k; + + DerivedMesh *dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + for(k = 0; k < count; k++) { + dm->getVert(dm, verts[k], &m); + p[k] = &m; + //printf("deformed coords %f %f %f\n", p[k]->co[0], p[k]->co[1], p[k]->co[2]); + } + + if(count >= 3) { + float d, dist, mag; + float *coord = MEM_callocN(sizeof(float)*3, "deformedCoord"); + float *norm = MEM_callocN(sizeof(float)*3, "planeNorm"); + getSingleCoordinate(p, count, coord); + dm->getVert(dm, i, &m); + norm[0] = m.co[0]-coord[0]; + norm[1] = m.co[1]-coord[1]; + norm[2] = m.co[2]-coord[2]; + mag = sqrt(norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2]); + for(k = 0; k < 3; k++) { + norm[k]/=mag; + } + d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2]; + dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); + //printf("status plane: (%f %f %f) %f dist: %f\n", norm[0], norm[1], norm[2], d, dist); + moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, 0, strength, cp); + MEM_freeN(coord); + MEM_freeN(norm); + } + + MEM_freeN(verts); + MEM_freeN(p); + } + MEM_freeN(pcount); + } + } +} static void vgroup_levels(Object *ob, float offset, float gain) { @@ -1919,6 +2283,40 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active", "Keep the values of the active group while normalizing others."); } +/* Jason */ +static int vertex_group_fix_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + Scene *scene= CTX_data_scene(C); + + float strength= RNA_float_get(op->ptr,"strength"); + float cp= RNA_float_get(op->ptr,"cp"); + + vgroup_fix(scene, ob, strength, cp); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Fix Vertex Group Deform"; + ot->idname= "OBJECT_OT_vertex_group_fix"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_fix_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance to be moved can be changed by this.", -2.0f, 2.0f); + RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); +} /* Jason was here */ static int vertex_group_invert_locks_exec(bContext *C, wmOperator *op) { diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index adec9883ca8..a8b191c0576 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -2098,7 +2098,7 @@ static void rna_def_mesh(BlenderRNA *brna) /* Jason */ prop= RNA_def_property(srna, "wp_vert_sel", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERT_SEL); - RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex Selection for auto brushes"); + RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex selection masking for painting"); RNA_def_property_ui_icon(prop, ICON_VERTEXSEL, 0); RNA_def_property_update(prop, 0, "rna_Mesh_update_vertmask"); From 5b64ea472c5ca70c81c176782931276e69798dbd Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 3 Aug 2011 17:45:09 +0000 Subject: [PATCH 39/68] Fix deform op tweaks: The distance to/from the plane was added to the UI The change that makes the vertex closest to the desired point is used instead of the most significant change. --- source/blender/editors/object/object_vgroup.c | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 79e8f98c630..e592f66ac56 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -872,7 +872,7 @@ static float distance(float* a, float *b, int length) { } return sqrt(sum); } -static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float **changes, int index) { +static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float **changes, float *dists, int index) { // A=Q-((Q-P).N)N // D = (a*x0 + b*y0 +c*z0 +d) float *projA, *projB; @@ -880,11 +880,15 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f projB = MEM_callocN(sizeof(float)*3, "projectedB"); getNearestPointOnPlane(norm, d, coord, start, projA); getNearestPointOnPlane(norm, d, coord, end, projB); + // (vertical and horizontal refer to the plane's y and xz respectively) + // vertical distance + dists[index] = norm[0]*end[0] + norm[1]*end[1] + norm[2]*end[2] + d; // vertical change - changes[index][0] = norm[0]*end[0] + norm[1]*end[1] + norm[2]*end[2] + d - distToStart; + changes[index][0] = dists[index] - distToStart; //printf("vc %f %f\n", distance(end, projB, 3)-distance(start, projA, 3), changes[index][0]); // horizontal change changes[index][1] = distance(projA, projB, 3); + MEM_freeN(projA); MEM_freeN(projB); } @@ -896,13 +900,13 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in int totweight = dvert->totweight; float oldw = 0; float *oldPos = MEM_callocN(sizeof(float)*3, "oldPosition"); - float vc, hc; + float vc, hc, dist; int i, k; float **changes = MEM_mallocN(sizeof(float)*totweight, "vertHorzChange"); + float *dists = MEM_mallocN(sizeof(float)*totweight, "distance"); int *upDown = MEM_callocN(sizeof(int)*totweight, "upDownTracker");// track if up or down moved it closer for each bone int *dwIndices = MEM_callocN(sizeof(int)*totweight, "dwIndexTracker"); float distToStart; - float bestChange = 0; int bestIndex = 0; char wasChange; char wasUp; @@ -956,22 +960,25 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); dm->getVert(dm, index, &m); - getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m.co, changes, i); + getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m.co, changes, dists, i); dw->weight = oldw; if(!k) { vc = changes[i][0]; hc = changes[i][1]; + dist = dists[i]; } else { - if(fabs(distToStart+vc - distToBe) < fabs(distToStart+changes[i][0] - distToBe)) { + if(fabs(dist - distToBe) < fabs(dists[i] - distToBe)) { upDown[i] = 0; changes[i][0] = vc; changes[i][1] = hc; + dists[i] = dist; } else { upDown[i] = 1; } - if(fabs(distToStart+changes[i][0] - distToBe) > fabs(distToStart - distToBe)) { + if(fabs(dists[i] - distToBe) > fabs(distToStart - distToBe)) { changes[i][0] = 0; changes[i][1] = 0; + dists[i] = distToStart; } } } @@ -981,14 +988,12 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in for(k = 0; k < totweight; k++) { float tf; int ti; - bestChange = changes[k][0]; bestIndex = k; for(i = k+1; i < totweight; i++) { - vc = changes[i][0]; + dist = dists[i]; - if(fabs(vc) > fabs(bestChange)) { + if(fabs(dist) > fabs(dists[i])) { bestIndex = i; - bestChange = vc; } } // switch with k @@ -1008,6 +1013,10 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in tf = changes[k][1]; changes[k][1] = changes[bestIndex][1]; changes[bestIndex][1] = tf; + + tf = dists[k]; + dists[k] = dists[bestIndex]; + dists[bestIndex] = tf; } } bestIndex = -1; @@ -1049,29 +1058,30 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } } //printf("best vc=%f hc=%f \n", changes[bestIndex][0], changes[bestIndex][1]); - }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (distToStart+changes[bestIndex][0]-distToBe)/fabs(distToStart+changes[bestIndex][0]-distToBe)); + }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (dists[bestIndex]-distToBe)/fabs(dists[bestIndex]-distToBe)); MEM_freeN(upDown); for(i = 0; i < totweight; i++) { MEM_freeN(changes[i]); } MEM_freeN(changes); + MEM_freeN(dists); MEM_freeN(dwIndices); MEM_freeN(oldPos); } // Jason -static void vgroup_fix(Scene *scene, Object *ob, float strength, float cp) +static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, float cp) { int i; Mesh *me = ob->data; MVert *mv = me->mvert; int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; - int *verts = NULL; - + int *verts = NULL; + int *pcount = MEM_callocN(sizeof(int), "intPointer"); for(i = 0; i < me->totvert && mv; i++, mv++) { // Jason if(selectedVerts && (mv->flag & SELECT)) { - int *pcount = MEM_callocN(sizeof(int), "intPointer"); + int count; if((verts = getSurroundingVerts(me, i, pcount))) { MVert m; @@ -1101,7 +1111,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float strength, float cp) d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2]; dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); //printf("status plane: (%f %f %f) %f dist: %f\n", norm[0], norm[1], norm[2], d, dist); - moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, 0, strength, cp); + moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp); MEM_freeN(coord); MEM_freeN(norm); } @@ -1109,9 +1119,9 @@ static void vgroup_fix(Scene *scene, Object *ob, float strength, float cp) MEM_freeN(verts); MEM_freeN(p); } - MEM_freeN(pcount); } } + MEM_freeN(pcount); } static void vgroup_levels(Object *ob, float offset, float gain) @@ -2289,10 +2299,11 @@ static int vertex_group_fix_exec(bContext *C, wmOperator *op) Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; Scene *scene= CTX_data_scene(C); + float distToBe= RNA_float_get(op->ptr,"dist"); float strength= RNA_float_get(op->ptr,"strength"); float cp= RNA_float_get(op->ptr,"cp"); - vgroup_fix(scene, ob, strength, cp); + vgroup_fix(scene, ob, distToBe, strength, cp); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); @@ -2313,8 +2324,8 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance to be moved can be changed by this.", -2.0f, 2.0f); + RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to.", -FLT_MAX, FLT_MAX); + RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance moved can be changed by this multiplier.", -2.0f, 2.0f); RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); } /* Jason was here */ From 0e9e74ec8afb55759fbcc52ba7b4f4a5fcb7085f Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 4 Aug 2011 16:07:24 +0000 Subject: [PATCH 40/68] Fixed a small problem with the Fix Deforms op involving the case where a weight was zero. Adjusted the distance limitations on the UI to be more reasonable. --- source/blender/editors/object/object_vgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index e592f66ac56..24e098c8222 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -935,6 +935,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in if(!dw->weight) { changes[i][0] = 0; changes[i][1] = 0; + dists[i] = distToStart; continue; } for(k = 0; k < 2; k++) { @@ -2324,7 +2325,7 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to.", -FLT_MAX, FLT_MAX); + RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to.", -10.0f, 10.0f); RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance moved can be changed by this multiplier.", -2.0f, 2.0f); RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); } From 5e7ad7a66d41a4d9df66381340c1ad4ec71d7676 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Sun, 7 Aug 2011 17:19:18 +0000 Subject: [PATCH 41/68] Fixes a memory allocation problem Uses functions that reduce duplicate code for clearing/recalculating deformations. --- source/blender/editors/object/object_vgroup.c | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 24e098c8222..59d839708ee 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -892,6 +892,16 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f MEM_freeN(projA); MEM_freeN(projB); } +static int dm_deform_clear(DerivedMesh *dm, Object *ob) { + dm->needsFree = 1; + dm->release(dm); + ob->derivedDeform=NULL; + // dm = NULL; + return NULL; +} +static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob) { + return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); +} static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float *norm, float *coord, float d, float distToBe, float strength, float cp) { DerivedMesh *dm; MDeformWeight *dw; @@ -902,7 +912,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in float *oldPos = MEM_callocN(sizeof(float)*3, "oldPosition"); float vc, hc, dist; int i, k; - float **changes = MEM_mallocN(sizeof(float)*totweight, "vertHorzChange"); + float **changes = MEM_mallocN(sizeof(float *)*totweight, "vertHorzChange"); float *dists = MEM_mallocN(sizeof(float)*totweight, "distance"); int *upDown = MEM_callocN(sizeof(int)*totweight, "upDownTracker");// track if up or down moved it closer for each bone int *dwIndices = MEM_callocN(sizeof(int)*totweight, "dwIndexTracker"); @@ -917,7 +927,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } do { wasChange = FALSE; - dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + dm = dm_deform_recalc(scene, ob); dm->getVert(dm, index, &m); oldPos[0] = m.co[0]; oldPos[1] = m.co[1]; @@ -940,10 +950,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } for(k = 0; k < 2; k++) { if(dm) { - dm->needsFree = 1; - dm->release(dm); - dm = NULL; - ob->derivedDeform=NULL; + dm = dm_deform_clear(dm, ob); } oldw = dw->weight; if(k) { @@ -954,12 +961,13 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in if(dw->weight == oldw) { changes[i][0] = 0; changes[i][1] = 0; + dists[i] = distToStart; break; } if(dw->weight > 1) { dw->weight = 1; } - dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + dm = dm_deform_recalc(scene, ob); dm->getVert(dm, index, &m); getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m.co, changes, dists, i); dw->weight = oldw; @@ -1052,10 +1060,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in wasChange = FALSE; } if(dm) { - dm->needsFree = 1; - dm->release(dm); - dm = NULL; - ob->derivedDeform=NULL; + dm = dm_deform_clear(dm, ob); } } //printf("best vc=%f hc=%f \n", changes[bestIndex][0], changes[bestIndex][1]); From a42426071be46ee164e880822590752ac852fba6 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 9 Aug 2011 16:32:15 +0000 Subject: [PATCH 42/68] Weight Paint's vertex selection tools use zbuf like face select. Removed the extra, unused object mode specific selection functions I had added (they aren't being used anywhere as of now, and they didn't support zbuffering). --- source/blender/editors/mesh/editmesh_mods.c | 2 + source/blender/editors/object/object_vgroup.c | 3 + .../blender/editors/space_view3d/drawobject.c | 62 +++++- .../editors/space_view3d/view3d_select.c | 180 +++++++++--------- 4 files changed, 145 insertions(+), 102 deletions(-) diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 9497370a4fa..ef4ff2b2cff 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -266,6 +266,7 @@ int EM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, sho /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); + else if(paint_vertsel_test(vc->obact));//Jason else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; @@ -328,6 +329,7 @@ int EM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); + else if (paint_vertsel_test(vc->obact));//Jason else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 59d839708ee..ea5ce3fbc47 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -892,6 +892,7 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f MEM_freeN(projA); MEM_freeN(projB); } +// Jason static int dm_deform_clear(DerivedMesh *dm, Object *ob) { dm->needsFree = 1; dm->release(dm); @@ -899,9 +900,11 @@ static int dm_deform_clear(DerivedMesh *dm, Object *ob) { // dm = NULL; return NULL; } +// Jason static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob) { return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); } +// Jason static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float *norm, float *coord, float d, float distToBe, float strength, float cp) { DerivedMesh *dm; MDeformWeight *dw; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 4a0053889e0..18194fac8c5 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2860,16 +2860,8 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D // Jason if(paint_vertsel_test(ob)) { glColor3f(0.0f, 0.0f, 0.0f); - glPointSize(2.0f); - // TODO clarify: - // there is clearly something I don't understand, when it was - // dt != OB_WIRE instead, it still drew in wire mode! (in weight paint mode) - if(dt != OB_SOLID || ob->mode & OB_MODE_VERTEX_PAINT) { - dm->drawEdges(dm, (totface==0), TRUE); - } - glPointSize(3.0f); + glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE)); dm->drawSelectedVerts(dm); - //draw_obmode_dm_verts(dm, 1); glPointSize(1.0f); } dm->release(dm); @@ -6421,6 +6413,29 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) } /* ***************** BACKBUF SEL (BBS) ********* */ +/* Jason */ +static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) +{ + // TODO: support hidden vertices + int offset = (intptr_t) userData; + //EditVert *eve = EM_get_vert_for_index(index); + + //if (eve->h==0) { + WM_set_framebuffer_index_color(offset+index); + bglVertex3fv(co); + //} +} +/* Jason */ +static void bbs_obmode_mesh_verts(Scene* scene, Object *ob, DerivedMesh *dm, int offset) +{ + Mesh *me = (Mesh*)ob->data; + + glPointSize( UI_GetThemeValuef(TH_VERTEX_SIZE) ); + bglBegin(GL_POINTS); + dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, (void*)(intptr_t) offset); + bglEnd(); + glPointSize(1.0); +} static void bbs_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { @@ -6519,7 +6534,18 @@ static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUS return 0; } } +/* Jason */ +// must have called WM_set_framebuffer_index_color beforehand +static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r)) +{ + Mesh *me = userData; + if (!(me->mface[index].flag&ME_HIDE)) { + return 1; + } else { + return 0; + } +} static void bbs_mesh_solid(Scene *scene, Object *ob) { DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); @@ -6578,7 +6604,23 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec EM_free_index_arrays(); } - else bbs_mesh_solid(scene, ob); + else { + Mesh *me= ob->data; + if(me->editflag & ME_EDIT_VERT_SEL) { + DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); + WM_set_framebuffer_index_color(me->totvert+2); + glColor3ub(0, 0, 0); + + dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, me, 0, GPU_enable_material); + + + bbs_obmode_mesh_verts(scene, ob, dm, 1); + em_vertoffs = me->totvert+1; + dm->release(dm); + } + else bbs_mesh_solid(scene, ob); + } + } break; case OB_CURVE: diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 13af4ff1db7..4af5df626b7 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -54,6 +54,11 @@ #include "BLI_linklist.h" #include "BLI_utildefines.h" +// Jason--vertex box select +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" +#include "BKE_global.h" + #include "BKE_context.h" #include "BKE_paint.h" #include "BKE_armature.h" @@ -641,15 +646,6 @@ static void do_lasso_select_curve(ViewContext *vc, int mcords[][2], short moves, ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */ nurbs_foreachScreenVert(vc, do_lasso_select_curve__doSelect, &data); } -/* Jason */ -static void do_obmode_lasso_select__doSelect(void *userData, MVert *mv, int x, int y) -{ - struct { int (*mcords)[2]; short moves; short select; } *data = userData; - - if (lasso_inside(data->mcords, data->moves, x, y)) { - mv->flag = data->select?(mv->flag|SELECT):(mv->flag&~SELECT); - } -} static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, int x, int y) { struct { int (*mcords)[2]; short moves; short select; } *data = userData; @@ -751,38 +747,62 @@ static void do_lasso_select_meta(ViewContext *vc, int mcords[][2], short moves, } } /* Jason */ -static void do_obmode_box_select__doSelect(void *userData, MVert *mv, int x, int y) -{ - struct { ViewContext vc; rcti *rect; int select; } *data = userData; - - if (BLI_in_rcti(data->rect, x, y)) { - mv->flag = data->select?(mv->flag|SELECT):(mv->flag&~SELECT); - } -} -/* Jason */ int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) { - Object *ob= vc->obact; - Mesh *me= ob?ob->data:NULL; + Mesh *me; + MVert *mvert; + struct ImBuf *ibuf; + unsigned int *rt; + int a, index; + char *selar; int sx= rect->xmax-rect->xmin+1; int sy= rect->ymax-rect->ymin+1; - struct { ViewContext vc; rcti *rect; int select; } data = {NULL}; + me= vc->obact->data; if(me==NULL || me->totvert==0 || sx*sy <= 0) return OPERATOR_CANCELLED; - if(extend==0 && select) - paintvert_deselect_all_visible(ob, SEL_DESELECT, FALSE); /* flush selection at the end */ + selar= MEM_callocN(me->totvert+1, "selar"); - ED_view3d_init_mats_rv3d(ob, vc->rv3d); - data.vc = *vc; - data.rect = rect; - data.select= select; + if (extend == 0 && select) + paintvert_deselect_all_visible(vc->obact, SEL_DESELECT, FALSE); - mesh_obmode_foreachScreenVert(vc, do_obmode_box_select__doSelect, &data, 1); + view3d_validate_backbuf(vc); - paintvert_flush_flags(ob); + ibuf = IMB_allocImBuf(sx,sy,32,IB_rect); + rt = ibuf->rect; + glReadPixels(rect->xmin+vc->ar->winrct.xmin, rect->ymin+vc->ar->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); + if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); + + a= sx*sy; + while(a--) { + if(*rt) { + index= WM_framebuffer_to_index(*rt); + if(index<=me->totvert) selar[index]= 1; + } + rt++; + } + + mvert= me->mvert; + for(a=1; a<=me->totvert; a++, mvert++) { + if(selar[a]) { + if(mvert->flag & ME_HIDE); + else { + if(select) mvert->flag |= SELECT; + else mvert->flag &= ~SELECT; + } + } + } + + IMB_freeImBuf(ibuf); + MEM_freeN(selar); + +#ifdef __APPLE__ + glReadBuffer(GL_BACK); +#endif + + paintvert_flush_flags(vc->obact); return OPERATOR_FINISHED; } @@ -791,19 +811,21 @@ static void do_lasso_select_paintvert(ViewContext *vc, int mcords[][2], short mo { Object *ob= vc->obact; Mesh *me= ob?ob->data:NULL; - - struct { int (*mcords)[2]; short moves; short select; } data = {NULL}; + rcti rect; if(me==NULL || me->totvert==0) return; if(extend==0 && select) paintvert_deselect_all_visible(ob, SEL_DESELECT, FALSE); /* flush selection at the end */ - ED_view3d_init_mats_rv3d(ob, vc->rv3d); - data.select = select; - data.mcords = mcords; - data.moves= moves; - mesh_obmode_foreachScreenVert(vc, do_obmode_lasso_select__doSelect, &data, 1); + em_vertoffs= me->totvert+1; /* max index array */ + + lasso_select_boundbox(&rect, mcords, moves); + EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + + EM_backbuf_checkAndSelectTVerts(me, select); + + EM_free_backbuf(); paintvert_flush_flags(ob); } @@ -1913,53 +1935,44 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) WM_operator_properties_gesture_border(ot, TRUE); } /*Jason*/ -static void findnearestWPvert__doClosest(void *userData, MVert *mv, int x, int y, int UNUSED(index)) +/* much like facesel_face_pick()*/ +/* returns 0 if not found, otherwise 1 */ +static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, short rect) { - struct { MVert *mv; short dist, select; int mval[2]; } *data = userData; - float temp = abs(data->mval[0]-x) + abs(data->mval[1]-y); - if((mv->flag & SELECT)==data->select) - temp += 5; + ViewContext vc; + view3d_set_viewcontext(C, &vc); - if(tempdist) { - data->dist = temp; + if (!me || me->totvert==0) + return 0; - data->mv = mv; + if (rect) { + /* sample rect to increase changes of selecting, so that when clicking + on an face in the backbuf, we can still select a vert */ + + int dist; + *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totvert+1, &dist,0,NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); } -} -/*Jason*/ -static MVert *findnearestWPvert(ViewContext *vc, Object *obact, Mesh *me, const int mval[2], int sel) -{ - /* sel==1: selected gets a disadvantage */ - struct { MVert *mv; short dist, select; int mval[2]; } data = {NULL}; - data.dist = 100; - data.select = sel; - data.mval[0]= mval[0]; - data.mval[1]= mval[1]; + if ((*index)<=0 || (*index)>(unsigned int)me->totvert) + return 0; - mesh_obmode_foreachScreenVert(vc, findnearestWPvert__doClosest, &data, 1); - - return data.mv; + (*index)--; + + return 1; } /* Jason */ /* mouse selection in weight paint */ /* gets called via generic mouse select operator */ int mouse_wp_select(bContext *C, const int mval[2], short extend, Object *obact, Mesh* me) { + unsigned int index = 0; MVert *mv; - ViewContext *vc = NULL; - vc = MEM_callocN(sizeof(ViewContext), "wp_m_sel_viewcontext"); - vc->ar= CTX_wm_region(C); - vc->scene= CTX_data_scene(C); - vc->v3d= CTX_wm_view3d(C); - vc->rv3d= CTX_wm_region_view3d(C); - vc->obact= obact; - vc->mval[0] = mval[0]; - vc->mval[1] = mval[1]; - - ED_view3d_init_mats_rv3d(obact, vc->rv3d); - - if(mv = findnearestWPvert(vc, obact, me, mval, 1)) { + if(vertsel_vert_pick(C, me, mval, &index, 1)) { + mv = me->mvert+index; if(extend) { mv->flag ^= 1; } else { @@ -1968,11 +1981,8 @@ int mouse_wp_select(bContext *C, const int mval[2], short extend, Object *obact, } paintvert_flush_flags(obact); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); - - MEM_freeN(vc); return 1; } - MEM_freeN(vc); return 0; } @@ -2061,17 +2071,6 @@ static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y eve->f = data->select?(eve->f|1):(eve->f&~1); } } -/* Jason */ -static void mesh_obmode_circle_doSelectVert(void *userData, MVert *mv, int x, int y, int UNUSED(index)) -{ - struct {ViewContext *vc; short select; int mval[2]; float radius; } *data = userData; - int mx = x - data->mval[0], my = y - data->mval[1]; - float r = sqrt(mx*mx + my*my); - - if (r<=data->radius) { - mv->flag = data->select?(mv->flag|1):(mv->flag&~1); - } -} static void mesh_circle_doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int UNUSED(index)) { @@ -2157,17 +2156,14 @@ static void paint_vertsel_circle_select(ViewContext *vc, int select, const int m { Object *ob= vc->obact; Mesh *me = ob?ob->data:NULL; - + int bbsel; struct {ViewContext *vc; short select; int mval[2]; float radius; } data = {NULL}; if (me) { - ED_view3d_init_mats_rv3d(ob, vc->rv3d); - data.radius = rad; - data.vc = vc; - data.select = select; - data.mval[0]= mval[0]; - data.mval[1]= mval[1]; + em_vertoffs= me->totvert+1; /* max index array */ - mesh_obmode_foreachScreenVert(vc, mesh_obmode_circle_doSelectVert, &data, 1); + bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f)); + EM_backbuf_checkAndSelectTVerts(me, select==LEFTMOUSE); + EM_free_backbuf(); paintvert_flush_flags(ob); } From e9393aa252aaa0a69dfbe8be6390813b57ae8fad Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Wed, 10 Aug 2011 15:50:21 +0000 Subject: [PATCH 43/68] Added an error msg for Fix Deforms tool for active mirror modifiers Stopped trying to draw verts with subdivision surface modifier active-- or any other time the dm->drawSelectedVerts function is 0. --- source/blender/editors/object/object_vgroup.c | 12 ++++++++++++ source/blender/editors/space_view3d/drawobject.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index ea5ce3fbc47..6679b7425bd 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -2311,7 +2311,19 @@ static int vertex_group_fix_exec(bContext *C, wmOperator *op) float distToBe= RNA_float_get(op->ptr,"dist"); float strength= RNA_float_get(op->ptr,"strength"); float cp= RNA_float_get(op->ptr,"cp"); + ModifierData *md = ob->modifiers.first; + + while(md) { + if(md->type == eModifierType_Mirror && (md->mode&eModifierMode_Realtime)) { + break; + } + md = md->next; + } + if(md && md->type == eModifierType_Mirror) { + BKE_report(op->reports, RPT_ERROR_INVALID_CONTEXT, "This operator does not support an active mirror modifier"); + return OPERATOR_CANCELLED; + } vgroup_fix(scene, ob, distToBe, strength, cp); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 18194fac8c5..cbe29c984d4 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2858,7 +2858,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D } } // Jason - if(paint_vertsel_test(ob)) { + if(paint_vertsel_test(ob) && dm->drawSelectedVerts) { glColor3f(0.0f, 0.0f, 0.0f); glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE)); dm->drawSelectedVerts(dm); From 46eff2631286e01b8c6502650b23da9bc9c41523 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Thu, 11 Aug 2011 17:42:54 +0000 Subject: [PATCH 44/68] Small tweaks to vgroup_fix related functions. Added further documentation. --- source/blender/editors/object/object_vgroup.c | 58 ++++++++++++++----- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 6679b7425bd..8d2a584646a 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -751,6 +751,10 @@ static void vgroup_normalize(Object *ob) if (dvert_array) MEM_freeN(dvert_array); } // Jason +/* This adds the indices of vertices to a list if they are not already present +It returns the number that it added (0-2) +It relies on verts having -1 for unassigned indices +*/ static int tryToAddVerts(int *verts, int length, int a, int b) { char containsA = FALSE; char containsB = FALSE; @@ -776,6 +780,11 @@ static int tryToAddVerts(int *verts, int length, int a, int b) { return added; } //Jason +/* This finds all of the vertices connected to vert by an edge +and returns an array of indices of size count + +count is an int passed by reference so it can be assigned the value of the length here. +*/ static int* getSurroundingVerts(Mesh *me, int vert, int *count) { int length = 0; int *tverts; @@ -799,7 +808,6 @@ static int* getSurroundingVerts(Mesh *me, int vert, int *count) { } for(i = 0; i < totface; i++, mf++) { int a=-1, b=-1; - //printf("face %d verts: %d %d %d %d\n", i, mf->v1, mf->v2, mf->v3, mf->v4); if(mf->v1 == vert) { a = mf->v2; if(mf->v4) { @@ -830,11 +838,15 @@ static int* getSurroundingVerts(Mesh *me, int vert, int *count) { for(i = 0; i < found; i++) { verts[i] = tverts[i]; } - count[0] = found; + *count = found; } MEM_freeN(tverts); return verts; } +/* Jason */ +/* get a single point in space by averaging a point cloud (vectors of size 3) +coord is the place the average is stored, points is the point cloud, count is the number of points in the cloud +*/ static void getSingleCoordinate(MVert **points, int count, float *coord) { int i, k; for(k = 0; k < 3; k++) { @@ -849,6 +861,11 @@ static void getSingleCoordinate(MVert **points, int count, float *coord) { coord[k] /= count; } } +/* Jason */ +/* find the closest point on a plane to another point and store it in dst */ +/* coord is a point on the plane */ +/* point is the point that you want the nearest of */ +/* norm is the plane's normal, and d is the last number in the plane equation 0 = ax + by + cz + d */ static void getNearestPointOnPlane(float *norm, float d, float *coord, float *point, float *dst) { float *temp = MEM_callocN(sizeof(float)*3, "temp"); int i; @@ -864,6 +881,8 @@ static void getNearestPointOnPlane(float *norm, float d, float *coord, float *po dst[i] = point[i] - dotprod*norm[i]; } } +/* Jason */ +/* distance of two vectors a and b of size length */ static float distance(float* a, float *b, int length) { int i; float sum = 0; @@ -872,6 +891,11 @@ static float distance(float* a, float *b, int length) { } return sqrt(sum); } +/* Jason */ +/* given a plane and a start and end position, +compute the amount of vertical distance relative to the plane and store it in dists, +then get the horizontal and vertical change and store them in changes +*/ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float **changes, float *dists, int index) { // A=Q-((Q-P).N)N // D = (a*x0 + b*y0 +c*z0 +d) @@ -893,6 +917,7 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f MEM_freeN(projB); } // Jason +// I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc) static int dm_deform_clear(DerivedMesh *dm, Object *ob) { dm->needsFree = 1; dm->release(dm); @@ -901,10 +926,19 @@ static int dm_deform_clear(DerivedMesh *dm, Object *ob) { return NULL; } // Jason +// recalculate the deformation static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob) { return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); } // Jason +/* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to distToBe distance away from the provided plane +strength can change distToBe so that it moves towards distToBe by that percentage +cp changes how much the weights are adjusted to check the distance + +index is the index of the vertex being moved +norm and d are the plane's properties for the equation: ax + by + cz + d = 0 +coord is a point on the plane +*/ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float *norm, float *coord, float d, float distToBe, float strength, float cp) { DerivedMesh *dm; MDeformWeight *dw; @@ -936,8 +970,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in oldPos[1] = m.co[1]; oldPos[2] = m.co[2]; distToStart = norm[0]*oldPos[0] + norm[1]*oldPos[1] + norm[2]*oldPos[2] + d; - //printf("dist %f \n",distToStart); - //printf("mesh point %f %f %f dpoint %f %f %f \n", (me->mvert+index)->co[0], (me->mvert+index)->co[1], (me->mvert+index)->co[3], oldPos[0], oldPos[1], oldPos[2]); + if(distToBe == originalDistToBe) { distToBe += distToStart - distToStart*strength; } @@ -994,7 +1027,6 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } } } - //printf("final vc: %f\n", changes[i][0]); } // sort the changes by the vertical change for(k = 0; k < totweight; k++) { @@ -1040,8 +1072,9 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } } if(bestIndex != -1) { - //printf("changing %d\n", bestIndex); wasChange = TRUE; + // it is a good place to stop if it tries to move the opposite direction + // (relative to the plane) of last time if(lastIndex != -1) { if(wasUp != upDown[bestIndex]) { wasChange = FALSE; @@ -1066,7 +1099,6 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in dm = dm_deform_clear(dm, ob); } } - //printf("best vc=%f hc=%f \n", changes[bestIndex][0], changes[bestIndex][1]); }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (dists[bestIndex]-distToBe)/fabs(dists[bestIndex]-distToBe)); MEM_freeN(upDown); for(i = 0; i < totweight; i++) { @@ -1078,6 +1110,8 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in MEM_freeN(oldPos); } // Jason +/* this is used to try to smooth a surface by only adjusting the nonzero weights of a vertex +but it could be used to raise or lower an existing 'bump.' */ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, float cp) { int i; @@ -1086,22 +1120,20 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, MVert *mv = me->mvert; int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; int *verts = NULL; - int *pcount = MEM_callocN(sizeof(int), "intPointer"); for(i = 0; i < me->totvert && mv; i++, mv++) { // Jason if(selectedVerts && (mv->flag & SELECT)) { - int count; - if((verts = getSurroundingVerts(me, i, pcount))) { + int count=0; + if((verts = getSurroundingVerts(me, i, &count))) { MVert m; - MVert **p = MEM_callocN(sizeof(MVert*)*(count = pcount[0]), "deformedPoints"); + MVert **p = MEM_callocN(sizeof(MVert*)*(count), "deformedPoints"); int k; DerivedMesh *dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); for(k = 0; k < count; k++) { dm->getVert(dm, verts[k], &m); p[k] = &m; - //printf("deformed coords %f %f %f\n", p[k]->co[0], p[k]->co[1], p[k]->co[2]); } if(count >= 3) { @@ -1119,7 +1151,6 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, } d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2]; dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); - //printf("status plane: (%f %f %f) %f dist: %f\n", norm[0], norm[1], norm[2], d, dist); moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp); MEM_freeN(coord); MEM_freeN(norm); @@ -1130,7 +1161,6 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, } } } - MEM_freeN(pcount); } static void vgroup_levels(Object *ob, float offset, float gain) From c536a708f545d6ee212defc5fa8110b4c48a4da3 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Fri, 12 Aug 2011 15:42:16 +0000 Subject: [PATCH 45/68] Change two if-else statements to just if's since the conditions were initially for testing. --- .../blender/editors/sculpt_paint/paint_vertex.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 1bfaa1ea6a4..31366701afc 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1446,6 +1446,7 @@ static void clamp_weights(MDeformVert *dvert) { } /*Jason*/ /* fresh start to make multi-paint and locking modular */ +/* returns TRUE if it thinks you need to reset the weights due to normalizing while multi-painting */ static int apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defcnt, float change, float oldChange, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { MDeformVert *dvert = me->dvert+index; MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); @@ -1473,21 +1474,13 @@ static int apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeigh if(oldChange && multipaint && selected > 1) { if(tdw->weight != oldw) { if( neww > oldw ) { - if(tdw->weight > oldw) { - //printf("should have changed\n"); - } else { - //printf("should not have changed\n"); - //reset_to_prev(dv, dvert); + if(tdw->weight <= oldw) { MEM_freeN(dv->dw); MEM_freeN(dv); return TRUE; } } else { - if(tdw->weight < oldw) { - //printf("should have changed\n"); - } else { - //printf("should not have changed\n"); - //reset_to_prev(dv, dvert); + if(tdw->weight >= oldw) { MEM_freeN(dv->dw); MEM_freeN(dv); return TRUE; @@ -1631,8 +1624,11 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, testw = tuw->weight*change; if( testw > tuw->weight ) { if(change > oldChange) { + // reset the weights and use the new change reset_to_prev(wp->wpaint_prev+index, me->dvert+index); } else { + // the old change was more significant, + // so set the change to 0 so that it will not do another multi-paint change = 0; } } else { From e67b2ee6ebcd994f8a3cbd8d67e7541e992daee1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Sep 2011 14:38:05 +0000 Subject: [PATCH 46/68] quiet compiler warnings --- source/blender/editors/include/ED_view3d.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 648d9cf4a84..c774b5d3455 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -53,6 +53,7 @@ struct Scene; struct View3D; struct ViewContext; struct wmWindow; +struct MVert; /* for derivedmesh drawing callbacks, for view3d_select, .... */ From 272bdce84d476154a85c4ac02b751f49033fffc9 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Tue, 13 Sep 2011 20:28:43 +0000 Subject: [PATCH 47/68] Re-added the interface template for vertex groups' checkboxes (they were cut out in a merge conflict) --- source/blender/editors/interface/interface_templates.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 8c151712f95..2f6a84b0430 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2124,6 +2124,12 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe //uiItemR(row, itemptr, "mute", 0, "", ICON_MUTE_IPO_OFF); uiBlockSetEmboss(block, UI_EMBOSS); } + /* Jason was here: I need the RNA struct for vertex groups */ + else if(RNA_struct_is_a(itemptr->type, &RNA_VertexGroup)) { + uiItemL(sub, name, icon); + uiBlockSetEmboss(block, UI_EMBOSS); + uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "flag", 0, 0, 0, 0, 0, NULL); + } else if(itemptr->type == &RNA_KeyingSetPath) { KS_Path *ksp = (KS_Path*)itemptr->data; From 98961c9f192125c3d87ea3b2ae1bfca212d5d33c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Sep 2011 02:04:26 +0000 Subject: [PATCH 48/68] initial cleanup for weight paint branch - move get_selected_defgroups & count_selected_defgroups into blenkernel - split calc_weightpaint_vert_color() logic so its more obvious whats default and multipaint behavior --- .../startup/bl_ui/properties_data_mesh.py | 3 +- source/blender/blenkernel/BKE_armature.h | 3 + .../blender/blenkernel/intern/DerivedMesh.c | 123 ++++++++---------- source/blender/blenkernel/intern/armature.c | 39 ++++++ .../editors/sculpt_paint/paint_vertex.c | 39 +----- .../editors/space_view3d/view3d_select.c | 7 +- 6 files changed, 98 insertions(+), 116 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 7503959480b..ae3a27a776f 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -135,8 +135,7 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel): ob = context.object group = ob.vertex_groups.active - - + rows = 2 if group: rows = 5 diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 7d60c00156d..75a2d9c3193 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -100,6 +100,9 @@ void get_objectspace_bone_matrix (struct Bone* bone, float M_accumulatedMatrix[] void vec_roll_to_mat3(float *vec, float roll, float mat[][3]); void mat3_to_vec_roll(float mat[][3], float *vec, float *roll); +char* get_selected_defgroups(struct Object *ob, int defcnt); +int count_selected_defgroups(const char *list, int len); + /* Common Conversions Between Co-ordinate Spaces */ void armature_mat_world_to_pose(struct Object *ob, float inmat[][4], float outmat[][4]); void armature_loc_world_to_pose(struct Object *ob, float *inloc, float *outloc); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 63ce62503ad..720dfbaca94 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -62,6 +62,7 @@ #include "BKE_paint.h" #include "BKE_texture.h" #include "BKE_multires.h" +#include "BKE_armature.h" #include "BLO_sys_types.h" // for intptr_t support @@ -73,8 +74,6 @@ #include "GPU_material.h" extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */ -// Jason was here, this is for multi-paint -#include "ED_armature.h" /////////////////////////////////// /////////////////////////////////// @@ -1678,47 +1677,58 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb) } } -static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int unselected, int multipaint, int auto_normalize) +/* draw_flag's for calc_weightpaint_vert_color */ +enum { + CALC_WP_MULTIPAINT= (1<<0), + CALC_WP_AUTO_NORMALIZE= (1<<1), +}; + +static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int UNUSED(unselected), const int draw_flag) { Mesh *me = ob->data; - float colf[4], input = 0.0f;// Jason + float colf[4], input = 0.0f; int i; - char make_black = FALSE; - char was_a_nonzero = FALSE; + + // Jason was here + int make_black= FALSE; if (me->dvert) { - for (i=0; idvert[vert].totweight; i++) { + if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { // Jason was here - // in multipaint, get the average if auto normalize is inactive - // get the sum if it is active - if(multipaint && selected > 1) { + int was_a_nonzero= FALSE; + for (i=0; idvert[vert].totweight; i++) { + /* in multipaint, get the average if auto normalize is inactive + * get the sum if it is active */ if(dg_flags[me->dvert[vert].dw[i].def_nr]) { if(me->dvert[vert].dw[i].weight) { - input+=me->dvert[vert].dw[i].weight; - was_a_nonzero = TRUE; + input+= me->dvert[vert].dw[i].weight; + was_a_nonzero= TRUE; } } - } else if (me->dvert[vert].dw[i].def_nr==ob->actdef-1) { - input+=me->dvert[vert].dw[i].weight; - } - } - - // Jason was here - // make it black if the selected groups have no weight on a vertex - if(!make_black && multipaint && selected > 1) { - if(!was_a_nonzero) { - make_black = TRUE; - } else if (!auto_normalize){ - // get the average - input /= selected; } + /* make it black if the selected groups have no weight on a vertex */ + if(was_a_nonzero == FALSE) { + make_black = TRUE; + } + else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) { + input /= selected; /* get the average */ + } + } + else { + /* default, non tricky behavior */ + for (i=0; idvert[vert].totweight; i++) { + if (me->dvert[vert].dw[i].def_nr==ob->actdef-1) { + input+=me->dvert[vert].dw[i].weight; + } + } } } - if(make_black) { + if (make_black) { input = -1; - }else { + } + else { CLAMP(input, 0.0f, 1.0f); } @@ -1740,65 +1750,30 @@ void vDM_ColorBand_store(ColorBand *coba) { stored_cb= coba; } -/* TODO move duplicates to header */ -/* Jason was here duplicate function in paint_vertex.c*/ -static char* get_selected_defgroups(Object *ob, int defcnt) { - bPoseChannel *chan; - bPose *pose; - bDeformGroup *defgroup; - //Bone *bone; - char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags"); - int i; - Object *armob = ED_object_pose_armature(ob); - if(armob) { - pose = armob->pose; - for (chan=pose->chanbase.first; chan; chan=chan->next) { - for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { - if(!strcmp(defgroup->name, chan->bone->name)) { - dg_flags[i] = (chan->bone->flag & BONE_SELECTED); - } - } - } - } - - return dg_flags; -} -/* TODO move duplicates to header */ -/* Jason was here duplicate function */ -static int count_true(char *list, int len) -{ - int i; - int cnt = 0; - for(i = 0; i < len; i++) { - if (list[i]) { - cnt++; - } - } - return cnt; -} -static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int multipaint, int auto_normalize) +static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) { Mesh *me = ob->data; MFace *mf = me->mface; ColorBand *coba= stored_cb; /* warning, not a local var */ unsigned char *wtcol; int i; + // Jason was here int defcnt = BLI_countlist(&ob->defbase); char *dg_flags = get_selected_defgroups(ob, defcnt); - int selected = count_true(dg_flags, defcnt); + int selected = count_selected_defgroups(dg_flags, defcnt); int unselected = defcnt - selected; wtcol = MEM_callocN (sizeof (unsigned char) * me->totface*4*4, "weightmap"); memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4); for (i=0; itotface; i++, mf++) { - calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, unselected, multipaint, auto_normalize); - calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, unselected, multipaint, auto_normalize); - calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, unselected, multipaint, auto_normalize); + calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, unselected, draw_flag); + calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, unselected, draw_flag); + calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, unselected, draw_flag); if (mf->v4) - calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, unselected, multipaint, auto_normalize); + calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, unselected, draw_flag); } // Jason MEM_freeN(dg_flags); @@ -1830,6 +1805,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos int has_multires = mmd != NULL, multires_applied = 0; int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt; + // Jason + int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | + (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); + if(mmd && !mmd->sculptlvl) has_multires = 0; @@ -2009,7 +1988,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, dm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason + add_weight_mcol_dm(ob, dm, draw_flag); // Jason /* Constructive modifiers need to have an origindex * otherwise they wont have anywhere to copy the data from. @@ -2121,7 +2100,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos CDDM_calc_normals(finaldm); if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason + add_weight_mcol_dm(ob, finaldm, draw_flag);// Jason } else if(dm) { finaldm = dm; } else { @@ -2133,7 +2112,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason + add_weight_mcol_dm(ob, finaldm, draw_flag);// Jason } /* add an orco layer if needed */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 62ce184a2d7..38c7b55cf51 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2465,3 +2465,42 @@ void where_is_pose (Scene *scene, Object *ob) } } } + +/* Jason was here */ +char* get_selected_defgroups(Object *ob, int defcnt) +{ + bPoseChannel *chan; + bPose *pose; + bDeformGroup *defgroup; + //Bone *bone; + char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags"); + int i; + Object *armob = object_pose_armature_get(ob); + + if(armob) { + pose = armob->pose; + for (chan=pose->chanbase.first; chan; chan=chan->next) { + for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { + if(!strcmp(defgroup->name, chan->bone->name)) { + dg_flags[i] = (chan->bone->flag & BONE_SELECTED); + } + } + } + } + + return dg_flags; +} + +/* TODO move duplicates to header */ +/* Jason was here duplicate function */ +int count_selected_defgroups(const char *list, int len) +{ + int i; + int cnt = 0; + for(i = 0; i < len; i++) { + if (list[i]) { + cnt++; + } + } + return cnt; +} diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 31366701afc..1abaf569c5a 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -64,6 +64,7 @@ #include "RNA_enum_types.h" #include "BKE_DerivedMesh.h" +#include "BKE_armature.h" #include "BKE_action.h" #include "BKE_brush.h" #include "BKE_context.h" @@ -1493,42 +1494,6 @@ static int apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeigh return FALSE; } -/* Jason was here duplicate function I used in DerivedMesh.c*/ -static char* get_selected_defgroups(Object *ob, int defcnt) { - bPoseChannel *chan; - bPose *pose; - bDeformGroup *defgroup; - //Bone *bone; - char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags"); - int i; - Object *armob = ED_object_pose_armature(ob); - - if(armob) { - pose = armob->pose; - for (chan=pose->chanbase.first; chan; chan=chan->next) { - for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { - if(!strcmp(defgroup->name, chan->bone->name)) { - dg_flags[i] = (chan->bone->flag & BONE_SELECTED); - } - } - } - } - // the array has whether or not the corresponding group is selected - return dg_flags; -} -/* TODO move duplicates to header */ -/* Jason was here duplicate function */ -static int count_true(char *list, int len) -{ - int i; - int cnt = 0; - for(i = 0; i < len; i++) { - if (list[i]) { - cnt++; - } - } - return cnt; -} // within the current dvert index, get the dw that is selected and has a weight above 0 // this helps multi-paint static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *selection) { @@ -1588,7 +1553,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason was here */ flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase), bone_groups); selection = get_selected_defgroups(ob, defcnt); - selected = count_true(selection, defcnt); + selected = count_selected_defgroups(selection, defcnt); if(!selected && ob->actdef) { selected = 1; } diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 926678ab123..01a551e42e9 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -2004,9 +2004,6 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) short enumerate= RNA_boolean_get(op->ptr, "enumerate"); short object= RNA_boolean_get(op->ptr, "object"); int retval = 0; - // Jason - Mesh *me; - Scene *scene = CTX_data_scene(C); view3d_operator_needs_opengl(C); @@ -2040,8 +2037,8 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) else if(obact && paint_facesel_test(obact)) retval = paintface_mouse_select(C, obact, event->mval, extend); /*Jason*/ - else if (paint_vertsel_test(obact) && (me = (Mesh*)(obact->data))) { - retval = mouse_wp_select(C, event->mval, extend, obact, me); + else if (paint_vertsel_test(obact)) { + retval = mouse_wp_select(C, event->mval, extend, obact, obact->data); } else { retval = mouse_select(C, event->mval, extend, center, enumerate); } From 4c99d83b562b62bbd6c1b5450b9e9ca8cc49676e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Sep 2011 05:25:43 +0000 Subject: [PATCH 49/68] another cleanup pass, quiet all warnings for GCC - comment unused funcs/vars. - replace some allocs with stack variables. - use BLI_math functions to replace in-line vector math. --- source/blender/editors/object/object_vgroup.c | 48 +++++++++---------- .../editors/sculpt_paint/paint_vertex.c | 45 ++++++++--------- .../blender/editors/space_view3d/drawobject.c | 6 +-- .../editors/space_view3d/view3d_select.c | 2 +- 4 files changed, 49 insertions(+), 52 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 8d2a584646a..e729ac9bced 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -49,6 +49,7 @@ #include "DNA_scene_types.h" #include "DNA_particle_types.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_utildefines.h" @@ -866,20 +867,17 @@ static void getSingleCoordinate(MVert **points, int count, float *coord) { /* coord is a point on the plane */ /* point is the point that you want the nearest of */ /* norm is the plane's normal, and d is the last number in the plane equation 0 = ax + by + cz + d */ -static void getNearestPointOnPlane(float *norm, float d, float *coord, float *point, float *dst) { - float *temp = MEM_callocN(sizeof(float)*3, "temp"); - int i; - float dotprod = 0; - for(i = 0; i < 3; i++) { - temp[i] = point[i]-coord[i]; - } - for(i = 0; i < 3; i++) { - dotprod += temp[i]*norm[i]; - } - MEM_freeN(temp); - for(i = 0; i < 3; i++) { - dst[i] = point[i] - dotprod*norm[i]; - } +static void getNearestPointOnPlane(const float norm[3], const float coord[3], const float point[3], float dst_r[3]) +{ + float temp[3]; + float dotprod; + + sub_v3_v3v3(temp, point, coord); + dotprod= dot_v3v3(temp, norm); + + dst_r[0] = point[0] - (norm[0] * dotprod); + dst_r[1] = point[1] - (norm[1] * dotprod); + dst_r[2] = point[2] - (norm[2] * dotprod); } /* Jason */ /* distance of two vectors a and b of size length */ @@ -902,8 +900,8 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f float *projA, *projB; projA = MEM_callocN(sizeof(float)*3, "projectedA"); projB = MEM_callocN(sizeof(float)*3, "projectedB"); - getNearestPointOnPlane(norm, d, coord, start, projA); - getNearestPointOnPlane(norm, d, coord, end, projB); + getNearestPointOnPlane(norm, coord, start, projA); + getNearestPointOnPlane(norm, coord, end, projB); // (vertical and horizontal refer to the plane's y and xz respectively) // vertical distance dists[index] = norm[0]*end[0] + norm[1]*end[1] + norm[2]*end[2] + d; @@ -918,12 +916,10 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f } // Jason // I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc) -static int dm_deform_clear(DerivedMesh *dm, Object *ob) { +static void dm_deform_clear(DerivedMesh *dm, Object *ob) { dm->needsFree = 1; dm->release(dm); ob->derivedDeform=NULL; - // dm = NULL; - return NULL; } // Jason // recalculate the deformation @@ -986,7 +982,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } for(k = 0; k < 2; k++) { if(dm) { - dm = dm_deform_clear(dm, ob); + dm_deform_clear(dm, ob); dm = NULL; } oldw = dw->weight; if(k) { @@ -1096,7 +1092,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in wasChange = FALSE; } if(dm) { - dm = dm_deform_clear(dm, ob); + dm_deform_clear(dm, ob); dm = NULL; } } }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (dists[bestIndex]-distToBe)/fabs(dists[bestIndex]-distToBe)); @@ -1137,7 +1133,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, } if(count >= 3) { - float d, dist, mag; + float d /*, dist */ /* UNUSED */, mag; float *coord = MEM_callocN(sizeof(float)*3, "deformedCoord"); float *norm = MEM_callocN(sizeof(float)*3, "planeNorm"); getSingleCoordinate(p, count, coord); @@ -1150,7 +1146,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, norm[k]/=mag; } d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2]; - dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); + /* dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); */ /* UNUSED */ moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp); MEM_freeN(coord); MEM_freeN(norm); @@ -2380,7 +2376,7 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); } /* Jason was here */ -static int vertex_group_invert_locks_exec(bContext *C, wmOperator *op) +static int vertex_group_invert_locks_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; @@ -2403,7 +2399,7 @@ void OBJECT_OT_vertex_group_invert_locks(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /* Jason was here */ -static int vertex_group_lock_all_exec(bContext *C, wmOperator *op) +static int vertex_group_lock_all_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; @@ -2426,7 +2422,7 @@ void OBJECT_OT_vertex_group_lock_all(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /* Jason was here */ -static int vertex_group_unlock_all_exec(bContext *C, wmOperator *op) +static int vertex_group_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 1abaf569c5a..83496dcd3df 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1074,6 +1074,7 @@ void PAINT_OT_weight_sample_group(wmOperatorType *ot) } +#if 0 /* UNUSED */ static void do_weight_paint_auto_normalize(MDeformVert *dvert, int paint_nr, char *map) { @@ -1108,6 +1109,8 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } } } +#endif + // Jason was here: the active group should be involved in auto normalize static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map) { @@ -1151,18 +1154,17 @@ static char has_locked_group(MDeformVert *dvert, char *flags) } return FALSE; } -/*Jason was here -gen_lck_flags gets the status of "flag" for each bDeformGroup -in ob->defbase and returns an array containing them -*/ -static char* gen_lck_flags(Object* ob, int defcnt, char *map) +/* Jason was here + * gen_lck_flags gets the status of "flag" for each bDeformGroup + *in ob->defbase and returns an array containing them + */ +static char *gen_lck_flags(Object* ob, int defcnt) { char is_locked = FALSE; int i; //int defcnt = BLI_countlist(&ob->defbase); char *flags = MEM_mallocN(defcnt*sizeof(char), "defflags"); bDeformGroup *defgroup; - int selected = 0; for(i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { flags[i] = defgroup->flag; @@ -1189,6 +1191,7 @@ static int has_locked_group_selected(int defcnt, char *selection, char *flags) { } /* Jason was here */ +#if 0 /* UNUSED */ static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int selected, char *flags, char *bone_groups) { int i; if(defcnt == selected) { @@ -1201,6 +1204,7 @@ static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int s } return FALSE; } +#endif /*Jason*/ static void multipaint_selection(MDeformVert *dvert, float change, char *selection, int defcnt) { @@ -1448,16 +1452,16 @@ static void clamp_weights(MDeformVert *dvert) { /*Jason*/ /* fresh start to make multi-paint and locking modular */ /* returns TRUE if it thinks you need to reset the weights due to normalizing while multi-painting */ -static int apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defcnt, float change, float oldChange, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { +static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defcnt, float change, float oldChange, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { MDeformVert *dvert = me->dvert+index; - MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert"); + MDeformVert dv= {NULL}; - dv->dw= MEM_dupallocN(dvert->dw); - dv->flag = dvert->flag; - dv->totweight = dvert->totweight; + dv.dw= MEM_dupallocN(dvert->dw); + dv.flag = dvert->flag; + dv.totweight = dvert->totweight; // do not multi-paint if a locked group is selected or the active group is locked // !flags[dw->def_nr] helps if nothing is selected, but active group is locked - if(!flags || flags && !has_locked_group_selected(defcnt, selection, flags) && !flags[dw->def_nr]) { + if((flags == NULL) || (has_locked_group_selected(defcnt, selection, flags) == FALSE && flags[dw->def_nr] == FALSE)) { if(multipaint && selected > 1) { if(change && change!=1) { multipaint_selection(dvert, change, selection, defcnt); @@ -1468,7 +1472,7 @@ static int apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeigh } clamp_weights(dvert); - enforce_locks(dv, dvert, defcnt, flags, bone_groups, validmap); + enforce_locks(&dv, dvert, defcnt, flags, bone_groups, validmap); do_weight_paint_auto_normalize_all_groups(dvert, validmap); @@ -1476,21 +1480,18 @@ static int apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeigh if(tdw->weight != oldw) { if( neww > oldw ) { if(tdw->weight <= oldw) { - MEM_freeN(dv->dw); - MEM_freeN(dv); + MEM_freeN(dv.dw); return TRUE; } } else { if(tdw->weight >= oldw) { - MEM_freeN(dv->dw); - MEM_freeN(dv); + MEM_freeN(dv.dw); return TRUE; } } } } - MEM_freeN(dv->dw); - MEM_freeN(dv); + MEM_freeN(dv.dw); return FALSE; } @@ -1551,7 +1552,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dw==NULL || uw==NULL) return; /* Jason was here */ - flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase), bone_groups); + flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase)); selection = get_selected_defgroups(ob, defcnt); selected = count_selected_defgroups(selection, defcnt); if(!selected && ob->actdef) { @@ -1610,7 +1611,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } /* Jason was here */ - if(apply_mp_lcks_normalize(ob, me, index, dw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint)) { + if(apply_mp_lcks_normalize(me, index, dw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint)) { reset_to_prev(dv, me->dvert+index); change = 0; oldChange = 0; @@ -1633,7 +1634,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason */ //uw->weight= dw->weight; /* Jason */ - apply_mp_lcks_normalize(ob, me, j, uw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); + apply_mp_lcks_normalize(me, j, uw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); } } /* Jason */ diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 9d6b3157427..2bded88a461 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -6538,9 +6538,9 @@ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, //} } /* Jason */ -static void bbs_obmode_mesh_verts(Scene* scene, Object *ob, DerivedMesh *dm, int offset) +static void bbs_obmode_mesh_verts(Object *UNUSED(ob), DerivedMesh *dm, int offset) { - Mesh *me = (Mesh*)ob->data; + /* Mesh *me = (Mesh*)ob->data; */ /* UNUSED */ glPointSize( UI_GetThemeValuef(TH_VERTEX_SIZE) ); bglBegin(GL_POINTS); @@ -6725,7 +6725,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, me, 0, GPU_enable_material, NULL); - bbs_obmode_mesh_verts(scene, ob, dm, 1); + bbs_obmode_mesh_verts(ob, dm, 1); em_vertoffs = me->totvert+1; dm->release(dm); } diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 01a551e42e9..49a5f52f943 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -2172,7 +2172,7 @@ static void paint_vertsel_circle_select(ViewContext *vc, int select, const int m Object *ob= vc->obact; Mesh *me = ob?ob->data:NULL; int bbsel; - struct {ViewContext *vc; short select; int mval[2]; float radius; } data = {NULL}; + /* struct {ViewContext *vc; short select; int mval[2]; float radius; } data = {NULL}; */ /* UNUSED */ if (me) { em_vertoffs= me->totvert+1; /* max index array */ From 718f78d548ed58c7d82c1803bf4fb652421e926c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Sep 2011 05:56:25 +0000 Subject: [PATCH 50/68] remove count_selected_defgroups() function and make get_selected_defgroups() return the total selected items. also some variable renameing, no functional changes. --- source/blender/blenkernel/BKE_armature.h | 3 +- .../blender/blenkernel/intern/DerivedMesh.c | 18 ++--- source/blender/blenkernel/intern/armature.c | 46 +++++------- .../editors/sculpt_paint/paint_vertex.c | 74 +++++++++---------- 4 files changed, 65 insertions(+), 76 deletions(-) diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 75a2d9c3193..8836999bc9b 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -100,8 +100,7 @@ void get_objectspace_bone_matrix (struct Bone* bone, float M_accumulatedMatrix[] void vec_roll_to_mat3(float *vec, float roll, float mat[][3]); void mat3_to_vec_roll(float mat[][3], float *vec, float *roll); -char* get_selected_defgroups(struct Object *ob, int defcnt); -int count_selected_defgroups(const char *list, int len); +int get_selected_defgroups(struct Object *ob, char *defbase_sel, int defbase_len); /* Common Conversions Between Co-ordinate Spaces */ void armature_mat_world_to_pose(struct Object *ob, float inmat[][4], float outmat[][4]); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 720dfbaca94..e4198d578c4 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1760,23 +1760,23 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) int i; // Jason was here - int defcnt = BLI_countlist(&ob->defbase); - char *dg_flags = get_selected_defgroups(ob, defcnt); - int selected = count_selected_defgroups(dg_flags, defcnt); - int unselected = defcnt - selected; + int defbase_len = BLI_countlist(&ob->defbase); + char *defbase_sel = MEM_mallocN(defbase_len * sizeof(char), __func__); + int selected = get_selected_defgroups(ob, defbase_sel, defbase_len); + int unselected = defbase_len - selected; wtcol = MEM_callocN (sizeof (unsigned char) * me->totface*4*4, "weightmap"); memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4); for (i=0; itotface; i++, mf++) { - calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, unselected, draw_flag); - calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, unselected, draw_flag); - calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, unselected, draw_flag); + calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], defbase_sel, selected, unselected, draw_flag); + calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], defbase_sel, selected, unselected, draw_flag); + calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], defbase_sel, selected, unselected, draw_flag); if (mf->v4) - calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, unselected, draw_flag); + calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], defbase_sel, selected, unselected, draw_flag); } // Jason - MEM_freeN(dg_flags); + MEM_freeN(defbase_sel); CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData); } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 38c7b55cf51..3a14074d55b 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2467,40 +2467,30 @@ void where_is_pose (Scene *scene, Object *ob) } /* Jason was here */ -char* get_selected_defgroups(Object *ob, int defcnt) +/* Returns total selected vgroups */ +int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_len) { - bPoseChannel *chan; - bPose *pose; bDeformGroup *defgroup; - //Bone *bone; - char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags"); - int i; - Object *armob = object_pose_armature_get(ob); + unsigned int i; + Object *armob= object_pose_armature_get(ob); + int dg_flags_sel_tot= 0; if(armob) { - pose = armob->pose; - for (chan=pose->chanbase.first; chan; chan=chan->next) { - for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { - if(!strcmp(defgroup->name, chan->bone->name)) { - dg_flags[i] = (chan->bone->flag & BONE_SELECTED); - } + bPose *pose= armob->pose; + for (i= 0, defgroup= ob->defbase.first; i < defbase_len && defgroup; defgroup = defgroup->next, i++) { + bPoseChannel *pchan= get_pose_channel(pose, defgroup->name); + if(pchan && (pchan->bone->flag & BONE_SELECTED)) { + dg_selection[i]= TRUE; + dg_flags_sel_tot++; + } + else { + dg_selection[i]= FALSE; } } } - - return dg_flags; -} - -/* TODO move duplicates to header */ -/* Jason was here duplicate function */ -int count_selected_defgroups(const char *list, int len) -{ - int i; - int cnt = 0; - for(i = 0; i < len; i++) { - if (list[i]) { - cnt++; - } + else { + memset(dg_selection, FALSE, sizeof(char) * defbase_len); } - return cnt; + + return dg_flags_sel_tot; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 83496dcd3df..83d1c2d0d1d 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1158,15 +1158,15 @@ static char has_locked_group(MDeformVert *dvert, char *flags) * gen_lck_flags gets the status of "flag" for each bDeformGroup *in ob->defbase and returns an array containing them */ -static char *gen_lck_flags(Object* ob, int defcnt) +static char *gen_lck_flags(Object* ob, int defbase_len) { char is_locked = FALSE; int i; - //int defcnt = BLI_countlist(&ob->defbase); - char *flags = MEM_mallocN(defcnt*sizeof(char), "defflags"); + //int defbase_len = BLI_countlist(&ob->defbase); + char *flags = MEM_mallocN(defbase_len*sizeof(char), "defflags"); bDeformGroup *defgroup; - for(i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) { + for(i = 0, defgroup = ob->defbase.first; i < defbase_len && defgroup; defgroup = defgroup->next, i++) { flags[i] = defgroup->flag; if(flags[i]) { is_locked = TRUE; @@ -1180,10 +1180,10 @@ static char *gen_lck_flags(Object* ob, int defcnt) return NULL; } /* Jason was here */ -static int has_locked_group_selected(int defcnt, char *selection, char *flags) { +static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *flags) { int i; - for(i = 0; i < defcnt; i++) { - if(selection[i] && flags[i]) { + for(i = 0; i < defbase_len; i++) { + if(defbase_sel[i] && flags[i]) { return TRUE; } } @@ -1192,13 +1192,13 @@ static int has_locked_group_selected(int defcnt, char *selection, char *flags) { /* Jason was here */ #if 0 /* UNUSED */ -static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int selected, char *flags, char *bone_groups) { +static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel, int selected, char *flags, char *bone_groups) { int i; - if(defcnt == selected) { + if(defbase_len == selected) { return FALSE; } - for(i = 0; i < defcnt; i++) { - if(bone_groups[i] && !selection[i] && !flags[i]) { + for(i = 0; i < defbase_len; i++) { + if(bone_groups[i] && !defbase_sel[i] && !flags[i]) { return TRUE; } } @@ -1207,13 +1207,13 @@ static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int s #endif /*Jason*/ -static void multipaint_selection(MDeformVert *dvert, float change, char *selection, int defcnt) { +static void multipaint_selection(MDeformVert *dvert, float change, char *defbase_sel, int defbase_len) { int i; MDeformWeight *dw; float val; // make sure they are all at most 1 after the change - for(i = 0; i < defcnt; i++) { - if(selection[i]) { + for(i = 0; i < defbase_len; i++) { + if(defbase_sel[i]) { dw = defvert_find_index(dvert, i); if(dw && dw->weight) { val = dw->weight * change; @@ -1229,8 +1229,8 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *selecti } } // apply the valid change - for(i = 0; i < defcnt; i++) { - if(selection[i]) { + for(i = 0; i < defbase_len; i++) { + if(defbase_sel[i]) { dw = defvert_find_index(dvert, i); if(dw && dw->weight) { dw->weight = dw->weight * change; @@ -1288,7 +1288,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan // observe the changes made to the weights of groups. // make sure all locked groups on the vertex have the same deformation // by moving the changes made to groups onto other unlocked groups -static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char *flags, char *bone_groups, char *validmap) { +static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, char *flags, char *bone_groups, char *validmap) { float totchange = 0.0f; float totchange_allowed = 0.0f; float left_over; @@ -1310,9 +1310,9 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * return; } // record if a group was changed, unlocked and not changed, or locked - change_status = MEM_callocN(sizeof(char)*defcnt, "unlocked_unchanged"); + change_status = MEM_callocN(sizeof(char)*defbase_len, "unlocked_unchanged"); - for(i = 0; i < defcnt; i++) { + for(i = 0; i < defbase_len; i++) { ndw = defvert_find_index(ndv, i); odw = defvert_find_index(odv, i); // the weights are zero, so we can assume a lot @@ -1410,12 +1410,12 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char * } /*Jason*/ // multi-paint's initial, potential change is computed here based on the user's stroke -static float get_mp_change(MDeformVert *odv, char *selection, float brush_change) { +static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_change) { float selwsum = 0.0f; int i; MDeformWeight *dw; for(i=0; i < odv->totweight; i++) { - if(selection[(dw = (odv->dw+i))->def_nr]) { + if(defbase_sel[(dw = (odv->dw+i))->def_nr]) { selwsum += dw->weight; } } @@ -1452,7 +1452,7 @@ static void clamp_weights(MDeformVert *dvert) { /*Jason*/ /* fresh start to make multi-paint and locking modular */ /* returns TRUE if it thinks you need to reset the weights due to normalizing while multi-painting */ -static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defcnt, float change, float oldChange, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { +static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defbase_len, float change, float oldChange, float oldw, float neww, char *defbase_sel, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { MDeformVert *dvert = me->dvert+index; MDeformVert dv= {NULL}; @@ -1461,10 +1461,10 @@ static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDefo dv.totweight = dvert->totweight; // do not multi-paint if a locked group is selected or the active group is locked // !flags[dw->def_nr] helps if nothing is selected, but active group is locked - if((flags == NULL) || (has_locked_group_selected(defcnt, selection, flags) == FALSE && flags[dw->def_nr] == FALSE)) { + if((flags == NULL) || (has_locked_group_selected(defbase_len, defbase_sel, flags) == FALSE && flags[dw->def_nr] == FALSE)) { if(multipaint && selected > 1) { if(change && change!=1) { - multipaint_selection(dvert, change, selection, defcnt); + multipaint_selection(dvert, change, defbase_sel, defbase_len); } } else {// this lets users paint normally, but don't let them paint locked groups dw->weight = neww; @@ -1472,7 +1472,7 @@ static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDefo } clamp_weights(dvert); - enforce_locks(&dv, dvert, defcnt, flags, bone_groups, validmap); + enforce_locks(&dv, dvert, defbase_len, flags, bone_groups, validmap); do_weight_paint_auto_normalize_all_groups(dvert, validmap); @@ -1497,12 +1497,12 @@ static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDefo // within the current dvert index, get the dw that is selected and has a weight above 0 // this helps multi-paint -static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *selection) { +static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *defbase_sel) { int i; MDeformWeight *dw; for(i=0; i< dvert->totweight; i++) { dw = dvert->dw+i; - if(selection[dw->def_nr] && dw->weight > 0) { + if(defbase_sel[dw->def_nr] && dw->weight > 0) { return i; } } @@ -1523,12 +1523,12 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason was here */ char *flags; char *bone_groups; - char *selection; + char *defbase_sel; int selected; float oldw; float neww; float testw=0; - int defcnt; + int defbase_len; float change = 0; float oldChange = 0; int i; @@ -1552,9 +1552,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dw==NULL || uw==NULL) return; /* Jason was here */ - flags = gen_lck_flags(ob, defcnt = BLI_countlist(&ob->defbase)); - selection = get_selected_defgroups(ob, defcnt); - selected = count_selected_defgroups(selection, defcnt); + flags = gen_lck_flags(ob, defbase_len = BLI_countlist(&ob->defbase)); + defbase_sel = MEM_mallocN(defbase_len * sizeof(char), "dg_selected_flags"); + selected = get_selected_defgroups(ob, defbase_sel, defbase_len); if(!selected && ob->actdef) { selected = 1; } @@ -1573,10 +1573,10 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, dv->totweight = (me->dvert+index)->totweight; tdw = dw; tuw = uw; - change = get_mp_change(wp->wpaint_prev+index, selection, neww-oldw); + change = get_mp_change(wp->wpaint_prev+index, defbase_sel, neww-oldw); if(change) { if(!tdw->weight) { - i = get_first_selected_nonzero_weight(me->dvert+index, selection); + i = get_first_selected_nonzero_weight(me->dvert+index, defbase_sel); if(i>=0) { tdw = ((me->dvert+index)->dw+i); tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); @@ -1611,7 +1611,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } /* Jason was here */ - if(apply_mp_lcks_normalize(me, index, dw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint)) { + if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint)) { reset_to_prev(dv, me->dvert+index); change = 0; oldChange = 0; @@ -1634,14 +1634,14 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, /* Jason */ //uw->weight= dw->weight; /* Jason */ - apply_mp_lcks_normalize(me, j, uw, tdw, defcnt, change, oldChange, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint); + apply_mp_lcks_normalize(me, j, uw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint); } } /* Jason */ if(flags) { MEM_freeN(flags); } - MEM_freeN(selection); + MEM_freeN(defbase_sel); if(!validmap) { MEM_freeN(bone_groups); } From 86777f46e1d359ad9cf208c5ab3ed76d4a345267 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Sep 2011 07:07:17 +0000 Subject: [PATCH 51/68] - use a flag define for bDeformGroup->flag rather than setting TRUE/FALSE - rename RNA bDeformGroup.flag to "lock_weight" --- .../editors/interface/interface_templates.c | 4 +- source/blender/editors/object/object_vgroup.c | 4 +- .../editors/sculpt_paint/paint_vertex.c | 49 ++++++++++--------- source/blender/makesdna/DNA_object_types.h | 3 ++ source/blender/makesrna/intern/rna_object.c | 4 +- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 2f6a84b0430..a696e488800 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2125,10 +2125,10 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe uiBlockSetEmboss(block, UI_EMBOSS); } /* Jason was here: I need the RNA struct for vertex groups */ - else if(RNA_struct_is_a(itemptr->type, &RNA_VertexGroup)) { + else if(itemptr->type == &RNA_VertexGroup) { uiItemL(sub, name, icon); uiBlockSetEmboss(block, UI_EMBOSS); - uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "flag", 0, 0, 0, 0, 0, NULL); + uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "lock_weight", 0, 0, 0, 0, 0, NULL); } else if(itemptr->type == &RNA_KeyingSetPath) { KS_Path *ksp = (KS_Path*)itemptr->data; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index e729ac9bced..bbc707de718 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1306,7 +1306,7 @@ static void vgroup_lock_all(Object *ob) { bDeformGroup *dg = ob->defbase.first; while(dg) { - dg->flag = TRUE; + dg->flag |= DG_LOCK_WEIGHT; dg = dg->next; } } @@ -1315,7 +1315,7 @@ static void vgroup_unlock_all(Object *ob) { bDeformGroup *dg = ob->defbase.first; while(dg) { - dg->flag = FALSE; + dg->flag &= ~DG_LOCK_WEIGHT; dg = dg->next; } } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 83d1c2d0d1d..584e88d6a7a 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -363,7 +363,7 @@ void vpaint_fill(Object *ob, unsigned int paintcol) MFace *mf; unsigned int *mcol; int i, selected; - + me= get_mesh(ob); if(me==NULL || me->totface==0) return; @@ -442,9 +442,9 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) faceverts[2]= mface->v3; faceverts[3]= mface->v4; for (i=0; i<3 || faceverts[i]; i++) { - if(!((me->dvert+faceverts[i])->flag)) { + if(me->dvert[faceverts[i]].flag) { // Jason - if(selectedVerts && !((me->mvert+faceverts[i])->flag & SELECT)) { + if(selectedVerts && ((me->mvert[faceverts[i]].flag & SELECT) == 0)) { continue; } @@ -1167,10 +1167,8 @@ static char *gen_lck_flags(Object* ob, int defbase_len) bDeformGroup *defgroup; for(i = 0, defgroup = ob->defbase.first; i < defbase_len && defgroup; defgroup = defgroup->next, i++) { - flags[i] = defgroup->flag; - if(flags[i]) { - is_locked = TRUE; - } + flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); + is_locked |= flags[i]; } if(is_locked){ return flags; @@ -1519,7 +1517,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, // Jason: tdw, tuw MDeformWeight *dw, *uw, *tdw = NULL, *tuw; int vgroup= ob->actdef-1; - + /* Jason was here */ char *flags; char *bone_groups; @@ -1569,7 +1567,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, dv = MEM_mallocN(sizeof (*(me->dvert+index)), "prevMDeformVert"); dv->dw= MEM_dupallocN((me->dvert+index)->dw); - dv->flag = (me->dvert+index)->flag; + dv->flag = me->dvert[index].flag; dv->totweight = (me->dvert+index)->totweight; tdw = dw; tuw = uw; @@ -1647,6 +1645,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } + /* *************** set wpaint operator ****************** */ static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */ @@ -1808,7 +1807,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED struct WPaintData *wpd; Mesh *me; float mat[4][4], imat[4][4]; - + if(scene->obedit) return OPERATOR_CANCELLED; me= get_mesh(ob); @@ -1819,14 +1818,13 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED ED_vgroup_data_create(&me->id); WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); } - - + /* make mode data storage */ wpd= MEM_callocN(sizeof(struct WPaintData), "WPaintData"); paint_stroke_set_mode_data(stroke, wpd); view3d_set_viewcontext(C, &wpd->vc); wpd->vgroup_mirror= -1; - + /*set up auto-normalize, and generate map for detecting which vgroups affect deform bones*/ wpd->auto_normalize = ts->auto_normalize; @@ -1881,7 +1879,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED if(me->editflag & ME_EDIT_MIRROR_X) { wpaint_mirror_vgroup_ensure(ob, &wpd->vgroup_mirror); } - + return 1; } @@ -1977,11 +1975,19 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P for(index=0; indextotface) { MFace *mface= me->mface + (indexar[index]-1); - - (me->dvert+mface->v1)->flag= selectedVerts ? ((me->mvert+mface->v1)->flag & SELECT): 1; - (me->dvert+mface->v2)->flag= selectedVerts ? ((me->mvert+mface->v2)->flag & SELECT): 1; - (me->dvert+mface->v3)->flag= selectedVerts ? ((me->mvert+mface->v3)->flag & SELECT): 1; - if(mface->v4) (me->dvert+mface->v4)->flag= selectedVerts ? ((me->mvert+mface->v4)->flag & SELECT): 1; + + if(selectedVerts) { + me->dvert[mface->v1].flag = (me->mvert[mface->v1].flag & SELECT); + me->dvert[mface->v2].flag = (me->mvert[mface->v2].flag & SELECT); + me->dvert[mface->v3].flag = (me->mvert[mface->v3].flag & SELECT); + if(mface->v4) me->dvert[mface->v4].flag = (me->mvert[mface->v4].flag & SELECT); + } + else { + me->dvert[mface->v1].flag= 1; + me->dvert[mface->v2].flag= 1; + me->dvert[mface->v3].flag= 1; + if(mface->v4) me->dvert[mface->v4].flag= 1; + } if(brush->vertexpaint_tool==VP_BLUR) { MDeformWeight *dw, *(*dw_func)(MDeformVert *, const int); @@ -2304,15 +2310,14 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index Brush *brush = paint_brush(&vp->paint); Mesh *me = get_mesh(ob); MFace *mface= ((MFace*)me->mface) + index; - unsigned int *mcol= ((unsigned int*)me->mcol) + 4*index; unsigned int *mcolorig= ((unsigned int*)vp->vpaint_prev) + 4*index; float alpha; int i; - + if((vp->flag & VP_COLINDEX && mface->mat_nr!=ob->actcol-1) || ((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL))) - return; + return; if(brush->vertexpaint_tool==VP_BLUR) { unsigned int fcol1= mcol_blend( mcol[0], mcol[1], 128); diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index a2150292193..0b02006fea4 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -67,6 +67,9 @@ typedef struct bDeformGroup { } bDeformGroup; #define MAX_VGROUP_NAME 32 +/* bDeformGroup->flag */ +#define DG_LOCK_WEIGHT 1 + /** * The following illustrates the orientation of the * bounding box in local space diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 7d037264609..c460432c1b3 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1276,9 +1276,9 @@ static void rna_def_vertex_group(BlenderRNA *brna) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_VertexGroup_name_set"); RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */ /* Jason was here */ - prop= RNA_def_property(srna, "flag", PROP_BOOLEAN, PROP_NONE); + prop= RNA_def_property(srna, "lock_weight", PROP_BOOLEAN, PROP_NONE); RNA_def_property_ui_text(prop, "", "Maintain the relative weights for the group"); - RNA_def_property_boolean_sdna(prop, "bDeformGroup", "flag", 0); + RNA_def_property_boolean_sdna(prop, NULL, "flag", 0); RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */ prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED); From df433c7a1dd351831ca299e7aecfb7877a19b2f7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Sep 2011 08:21:21 +0000 Subject: [PATCH 52/68] - move vgroup lock buttons on the panel into the vgroup specials menu. - merge object.vertex_group_lock_all / object.vertex_group_invert_locks / "object.vertex_group_unlock_all into one operator. - change lock button from a checkbox to a lock icon. --- .../startup/bl_ui/properties_data_mesh.py | 15 +-- .../editors/interface/interface_templates.c | 9 +- source/blender/editors/object/object_intern.h | 4 +- source/blender/editors/object/object_ops.c | 4 +- source/blender/editors/object/object_vgroup.c | 109 ++++++------------ source/blender/makesdna/DNA_scene_types.h | 6 +- 6 files changed, 53 insertions(+), 94 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index ae3a27a776f..a94a45958de 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -35,6 +35,10 @@ class MESH_MT_vertex_group_specials(Menu): layout.operator("object.vertex_group_copy_to_selected", icon='LINK_AREA') layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT') layout.operator("object.vertex_group_remove", icon='X', text="Delete All").all = True + layout.separator() + layout.operator("object.vertex_group_lock", icon='LOCK', text="Lock All").action = 'SELECT' + layout.operator("object.vertex_group_lock", icon='UNLOCK', text="UnLock All").action = 'DESELECT' + layout.operator("object.vertex_group_lock", icon='LOCK', text="Lock Invert All").action = 'INVERT' class MESH_MT_shape_key_specials(Menu): @@ -144,9 +148,6 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel): row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows) col = row.column(align=True) - # Jason was here, this was replaced by hardcoded list view checkboxes. # - #col.prop(group, "flag") - col.operator("object.vertex_group_add", icon='ZOOMIN', text="") col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="") col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="") @@ -157,14 +158,6 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel): if group: row = layout.row() row.prop(group, "name") - #Jason was here - # add buttons to make it faster to lock/unlock vgroups - if ob.mode == 'WEIGHT_PAINT' and len(ob.vertex_groups) > 0: - row = layout.row() - sub = row.row(align=True) - sub.operator("object.vertex_group_lock_all", text="Lock All") - sub.operator("object.vertex_group_invert_locks", text="Invert Locks") - sub.operator("object.vertex_group_unlock_all", text="Unlock All") if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0: row = layout.row() diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index a696e488800..ff1c3c687f9 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2126,9 +2126,16 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe } /* Jason was here: I need the RNA struct for vertex groups */ else if(itemptr->type == &RNA_VertexGroup) { + bDeformGroup *dg= (bDeformGroup *)itemptr->data; uiItemL(sub, name, icon); - uiBlockSetEmboss(block, UI_EMBOSS); + /* RNA does not allow nice lock icons, use lower level buttons */ +#if 0 uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "lock_weight", 0, 0, 0, 0, 0, NULL); +#else + uiBlockSetEmboss(block, UI_EMBOSSN); + uiDefIconButBitC(block, TOG, DG_LOCK_WEIGHT, 0, (dg->flag & DG_LOCK_WEIGHT) ? ICON_LOCKED : ICON_UNLOCKED, 0, 0, UI_UNIT_X, UI_UNIT_Y, &dg->flag, 0, 0, 0, 0, "Maintain relative weights while painting"); + uiBlockSetEmboss(block, UI_EMBOSS); +#endif } else if(itemptr->type == &RNA_KeyingSetPath) { KS_Path *ksp = (KS_Path*)itemptr->data; diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index fb119b1d264..cbce1526c3c 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -201,9 +201,7 @@ void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); /* Jason was here */ -void OBJECT_OT_vertex_group_lock_all(struct wmOperatorType *ot); -void OBJECT_OT_vertex_group_invert_locks(struct wmOperatorType *ot); -void OBJECT_OT_vertex_group_unlock_all(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_invert(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index b36357facb1..c34fb2e22dc 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -175,9 +175,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); /* Jason was here */ - WM_operatortype_append(OBJECT_OT_vertex_group_invert_locks); - WM_operatortype_append(OBJECT_OT_vertex_group_lock_all); - WM_operatortype_append(OBJECT_OT_vertex_group_unlock_all); + WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); WM_operatortype_append(OBJECT_OT_vertex_group_invert); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index bbc707de718..49ff4ac212d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1292,31 +1292,34 @@ static void vgroup_normalize_all(Object *ob, int lock_active) if (dvert_array) MEM_freeN(dvert_array); } + /* Jason was here */ -static void vgroup_invert_locks(Object *ob) +static void vgroup_lock_all(Object *ob, int action) { - bDeformGroup *dg = ob->defbase.first; - while(dg) { - dg->flag = !dg->flag; - dg = dg->next; + bDeformGroup *dg; + + if(action == SEL_TOGGLE) { + action= SEL_SELECT; + for(dg= ob->defbase.first; dg; dg= dg->next) { + if(dg->flag & DG_LOCK_WEIGHT) { + action= SEL_DESELECT; + break; + } + } } -} -/* Jason was here */ -static void vgroup_lock_all(Object *ob) -{ - bDeformGroup *dg = ob->defbase.first; - while(dg) { - dg->flag |= DG_LOCK_WEIGHT; - dg = dg->next; - } -} -/* Jason was here */ -static void vgroup_unlock_all(Object *ob) -{ - bDeformGroup *dg = ob->defbase.first; - while(dg) { - dg->flag &= ~DG_LOCK_WEIGHT; - dg = dg->next; + + for(dg= ob->defbase.first; dg; dg= dg->next) { + switch(action) { + case SEL_SELECT: + dg->flag |= DG_LOCK_WEIGHT; + break; + case SEL_DESELECT: + dg->flag &= ~DG_LOCK_WEIGHT; + break; + case SEL_INVERT: + dg->flag ^= DG_LOCK_WEIGHT; + break; + } } } @@ -2375,75 +2378,35 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance moved can be changed by this multiplier.", -2.0f, 2.0f); RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); } + /* Jason was here */ -static int vertex_group_invert_locks_exec(bContext *C, wmOperator *UNUSED(op)) +static int vertex_group_lock_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - vgroup_invert_locks(ob); + int action = RNA_enum_get(op->ptr, "action"); + + vgroup_lock_all(ob, action); return OPERATOR_FINISHED; } /* Jason was here */ -void OBJECT_OT_vertex_group_invert_locks(wmOperatorType *ot) +void OBJECT_OT_vertex_group_lock(wmOperatorType *ot) { /* identifiers */ - ot->name= "Invert All Vertex Group Locks"; - ot->idname= "OBJECT_OT_vertex_group_invert_locks"; + ot->name= "Change the Lock On Vertex Groups"; + ot->idname= "OBJECT_OT_vertex_group_lock"; /* api callbacks */ ot->poll= vertex_group_poll; - ot->exec= vertex_group_invert_locks_exec; + ot->exec= vertex_group_lock_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + WM_operator_properties_select_all(ot); } -/* Jason was here */ -static int vertex_group_lock_all_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - vgroup_lock_all(ob); - - return OPERATOR_FINISHED; -} -/* Jason was here */ -void OBJECT_OT_vertex_group_lock_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Turn on all Vertex Group Locks"; - ot->idname= "OBJECT_OT_vertex_group_lock_all"; - - /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_lock_all_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} -/* Jason was here */ -static int vertex_group_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - - vgroup_unlock_all(ob); - - return OPERATOR_FINISHED; -} -/* Jason was here */ -void OBJECT_OT_vertex_group_unlock_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Turn off all Vertex Group Locks"; - ot->idname= "OBJECT_OT_vertex_group_unlock_all"; - - /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_unlock_all_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} static int vertex_group_invert_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 66244e87995..fe2566b4542 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -759,12 +759,12 @@ typedef struct ToolSettings { short snap_flag, snap_target; short proportional, prop_mode; char proportional_objects; /* proportional edit, object mode */ - char pad[7]; + char pad[5]; - int auto_normalize; /*auto normalizing mode in wpaint*/ + char auto_normalize; /*auto normalizing mode in wpaint*/ //Jason - int multipaint; /* paint multiple bones in wpaint */ + char multipaint; /* paint multiple bones in wpaint */ short sculpt_paint_settings; /* user preferences for sculpt and paint */ short pad1; From a31869f267d7a393555383e1b49dd61c7133651e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Sep 2011 08:45:12 +0000 Subject: [PATCH 53/68] some picky rna/variable renaming: Mesh.wp_vert_sel --> use_paint_mask_vertex --- .../blender/editors/armature/meshlaplacian.c | 14 ++++---- source/blender/editors/object/object_vgroup.c | 32 +++++++++---------- .../editors/sculpt_paint/paint_vertex.c | 12 +++---- .../editors/space_view3d/view3d_header.c | 2 +- source/blender/makesrna/intern/rna_mesh.c | 4 +-- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 127b2f4e663..4ce4a780d09 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -659,24 +659,24 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, // Jason MVert *mv = me->mvert; - int selectedVerts; + int use_vert_sel= FALSE; *err_str= NULL; /* count triangles and create mask */ - if((me->editflag & ME_EDIT_PAINT_MASK) || (selectedVerts=(me->editflag & ME_EDIT_VERT_SEL))) + if((me->editflag & ME_EDIT_PAINT_MASK) || (use_vert_sel= ((me->editflag & ME_EDIT_VERT_SEL) != 0))) mask= MEM_callocN(sizeof(int)*me->totvert, "heat_bone_weighting mask"); for(totface=0, a=0, mface=me->mface; atotface; a++, mface++) { totface++; if(mface->v4) totface++; // Jason (added selectedVerts content for vertex mask, they used to just equal 1) - if(mask && ((mface->flag & ME_FACE_SEL) || selectedVerts)) { - mask[mface->v1]= selectedVerts ? ((mv+mface->v1)->flag & 1): 1; - mask[mface->v2]= selectedVerts ? ((mv+mface->v2)->flag & 1): 1; - mask[mface->v3]= selectedVerts ? ((mv+mface->v3)->flag & 1): 1; + if(mask && ((mface->flag & ME_FACE_SEL) || use_vert_sel)) { + mask[mface->v1]= use_vert_sel ? ((mv+mface->v1)->flag & 1): 1; + mask[mface->v2]= use_vert_sel ? ((mv+mface->v2)->flag & 1): 1; + mask[mface->v3]= use_vert_sel ? ((mv+mface->v3)->flag & 1): 1; if(mface->v4) - mask[mface->v4]= selectedVerts ? ((mv+mface->v4)->flag & 1): 1; + mask[mface->v4]= use_vert_sel ? ((mv+mface->v4)->flag & 1): 1; } } diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 49ff4ac212d..7f78f25e1ce 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -706,7 +706,7 @@ static void vgroup_normalize(Object *ob) // Jason Mesh *me = ob->data; MVert *mv = me->mvert; - int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -719,7 +719,7 @@ static void vgroup_normalize(Object *ob) for(i = 0; i < dvert_tot; i++) { // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } @@ -733,7 +733,7 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } @@ -1114,11 +1114,11 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, Mesh *me = ob->data; MVert *mv = me->mvert; - int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; int *verts = NULL; for(i = 0; i < me->totvert && mv; i++, mv++) { // Jason - if(selectedVerts && (mv->flag & SELECT)) { + if(use_vert_sel && (mv->flag & SELECT)) { int count=0; if((verts = getSurroundingVerts(me, i, &count))) { @@ -1168,7 +1168,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) // Jason Mesh *me = ob->data; MVert *mv = me->mvert; - int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1179,7 +1179,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) for(i = 0; i < dvert_tot; i++) { // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } @@ -1207,7 +1207,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) // Jason Mesh *me = ob->data; MVert *mv = me->mvert; - int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1219,7 +1219,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) float lock_iweight= 1.0f; int j; // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } @@ -1263,7 +1263,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) for(i = 0; i < dvert_tot; i++) { int j; // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } @@ -1332,7 +1332,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) // Jason Mesh *me = ob->data; MVert *mv = me->mvert; - int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1344,7 +1344,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) for(i = 0; i < dvert_tot; i++) { // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } dvert = dvert_array[i]; @@ -1462,7 +1462,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) // Jason Mesh *me = ob->data; MVert *mv = me->mvert; - int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1473,7 +1473,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) for(i = 0; i < dvert_tot; i++) { // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } dvert = dvert_array[i]; @@ -1500,7 +1500,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) // Jason Mesh *me = ob->data; MVert *mv = me->mvert; - int selectedVerts = me->editflag & ME_EDIT_VERT_SEL; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1508,7 +1508,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) for(i = 0; i < dvert_tot; i++) { int j; // Jason - if(selectedVerts && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mv+i)->flag & SELECT)) { continue; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 584e88d6a7a..ec2e9761940 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -400,14 +400,14 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) int vgroup_mirror= -1; int selected; // Jason - int selectedVerts; + int use_vert_sel; me= ob->data; if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return; selected= (me->editflag & ME_EDIT_PAINT_MASK); // Jason - selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); + use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; indexar= get_indexarray(me); @@ -444,7 +444,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) for (i=0; i<3 || faceverts[i]; i++) { if(me->dvert[faceverts[i]].flag) { // Jason - if(selectedVerts && ((me->mvert[faceverts[i]].flag & SELECT) == 0)) { + if(use_vert_sel && ((me->mvert[faceverts[i]].flag & SELECT) == 0)) { continue; } @@ -1900,7 +1900,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float mval[2], pressure; // Jason - int selectedVerts; + int use_vert_sel; /* cannot paint if there is no stroke data */ if (wpd == NULL) { @@ -1950,7 +1950,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P } } // Jason - selectedVerts = (me->editflag & ME_EDIT_VERT_SEL); + use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; if((me->editflag & ME_EDIT_PAINT_MASK) && me->mface) { for(index=0; indextotface) { MFace *mface= me->mface + (indexar[index]-1); - if(selectedVerts) { + if(use_vert_sel) { me->dvert[mface->v1].flag = (me->mvert[mface->v1].flag & SELECT); me->dvert[mface->v2].flag = (me->mvert[mface->v2].flag & SELECT); me->dvert[mface->v3].flag = (me->mvert[mface->v3].flag & SELECT); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index b29373d0770..359f69596e5 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -505,7 +505,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) // Jason row= uiLayoutRow(layout, 1); uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); - uiItemR(row, &meshptr, "wp_vert_sel", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); } } else { const char *str_menu; diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index a8b191c0576..16817001bf4 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -2096,9 +2096,9 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Mesh_update_facemask"); /* Jason */ - prop= RNA_def_property(srna, "wp_vert_sel", PROP_BOOLEAN, PROP_NONE); + prop= RNA_def_property(srna, "use_paint_mask_vertex", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERT_SEL); - RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex selection masking for painting"); + RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex selection masking for painting (weight paint only)"); RNA_def_property_ui_icon(prop, ICON_VERTEXSEL, 0); RNA_def_property_update(prop, 0, "rna_Mesh_update_vertmask"); From 3585808bdbfdd54eceb52171cf0c5c0ea57ec27b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Sep 2011 12:44:21 +0000 Subject: [PATCH 54/68] fix for a bug painting on selected verts, also fix an error in my own recent commit. --- source/blender/editors/sculpt_paint/paint_vertex.c | 14 +++++++++----- source/blender/editors/space_view3d/drawobject.c | 1 - 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index ec2e9761940..62acacb4526 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -442,7 +442,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) faceverts[2]= mface->v3; faceverts[3]= mface->v4; for (i=0; i<3 || faceverts[i]; i++) { - if(me->dvert[faceverts[i]].flag) { + if(!me->dvert[faceverts[i]].flag) { // Jason if(use_vert_sel && ((me->mvert[faceverts[i]].flag & SELECT) == 0)) { continue; @@ -1927,10 +1927,16 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P mval[1]-= vc->ar->winrct.ymin; swap_m4m4(wpd->vc.rv3d->persmat, mat); - + + // Jason + use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; + /* which faces are involved */ if(wp->flag & VP_AREA) { + // Ugly hack, to avoid drawing vertex index when getting the face index buffer - campbell + me->editflag &= ~ME_EDIT_VERT_SEL; totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush_size(brush)); + me->editflag |= use_vert_sel ? ME_EDIT_VERT_SEL : 0; } else { indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); @@ -1949,9 +1955,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P } } } - // Jason - use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; - + if((me->editflag & ME_EDIT_PAINT_MASK) && me->mface) { for(index=0; indextotface) { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 2bded88a461..439f05c3986 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -6719,7 +6719,6 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec Mesh *me= ob->data; if(me->editflag & ME_EDIT_VERT_SEL) { DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); - WM_set_framebuffer_index_color(me->totvert+2); glColor3ub(0, 0, 0); dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, me, 0, GPU_enable_material, NULL); From 101937e2ddf4d0453868373b644873586febf6e2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 15 Sep 2011 07:06:45 +0000 Subject: [PATCH 55/68] replace rna_update_active_object with NC_GEOM|ND_DATA notifier (as pointed out by Matt Ebb), also some whitespace edits to match trunk. --- source/blender/editors/space_view3d/view3d_header.c | 1 + source/blender/editors/space_view3d/view3d_select.c | 2 +- source/blender/makesrna/intern/rna_internal.h | 2 -- source/blender/makesrna/intern/rna_object.c | 10 ---------- source/blender/makesrna/intern/rna_scene.c | 4 ++-- 5 files changed, 4 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 359f69596e5..5d23f2838cf 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -498,6 +498,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) /* Manipulators aren't used in weight paint mode */ PointerRNA meshptr; + RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr); if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) { uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 49a5f52f943..fabaa3901d4 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -646,6 +646,7 @@ static void do_lasso_select_curve(ViewContext *vc, int mcords[][2], short moves, ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */ nurbs_foreachScreenVert(vc, do_lasso_select_curve__doSelect, &data); } + static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, int x, int y) { struct { int (*mcords)[2]; short moves; short select; } *data = userData; @@ -2086,7 +2087,6 @@ static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y eve->f = data->select?(eve->f|1):(eve->f&~1); } } - static void mesh_circle_doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int UNUSED(index)) { struct {ViewContext *vc; short select; int mval[2]; float radius; } *data = userData; diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index b9682b7ee7f..78b8c67d92c 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -215,8 +215,6 @@ int rna_object_shapekey_index_set(struct ID *id, PointerRNA value, int current); void rna_Object_internal_update_data(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); void rna_Mesh_update_draw(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); void rna_TextureSlot_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); -//Jason -void rna_update_active_object(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); /* basic poll functions for object types */ int rna_Armature_object_poll(struct PointerRNA *ptr, struct PointerRNA value); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index c460432c1b3..59f5173f7ef 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -220,16 +220,6 @@ void rna_Object_internal_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA); WM_main_add_notifier(NC_OBJECT|ND_DRAW, ptr->id.data); } -// Jason -void rna_update_active_object(Main *bmain, Scene *scene, PointerRNA *ptr) -{ - Object *ob; - Base *basact = scene->basact; - if(basact && (ob = basact->object)) { - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_main_add_notifier(NC_OBJECT|ND_DRAW, &ob->id); - } -} void rna_Object_active_shape_update(Main *bmain, Scene *scene, PointerRNA *ptr) { diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 7718651a767..3a0183d70fb 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1120,14 +1120,14 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "WPaint Auto-Normalize", "Ensure all bone-deforming vertex groups add up to 1.0 while " "weight painting"); - RNA_def_property_update(prop, 0, "rna_update_active_object"); + RNA_def_property_update(prop, NC_GEOM|ND_DATA, 0); prop = RNA_def_property(srna, "use_multipaint", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "multipaint", 1); RNA_def_property_ui_text(prop, "WPaint Multi-Paint", "Paint across all selected bones while " "weight painting"); - RNA_def_property_update(prop, 0, "rna_update_active_object"); + RNA_def_property_update(prop, NC_GEOM|ND_DATA, 0); prop= RNA_def_property(srna, "vertex_paint", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "vpaint"); From 1b5d16f1bf80f2da8d3d4da5bbfaf4819c14a225 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Sun, 18 Sep 2011 01:09:18 +0000 Subject: [PATCH 56/68] I made multitude of fixes based on the comments provided online: Removed the drawSelectedVerts and added drawSelectedVertices, which uses dm->foreachMappedVert. In calc_weightpaint_vert_color(): Made the weight paint color black and return instead of input=-1 Made the pose bone selection normal when multi-paint is inactive. Name fix for functions using mv instead of mvert. Used vector functions provided by the math lib. Changed some MEM_callocN references to be stacks. Changed dm_deform_clear to use ob->derivedDeform primarily Made the variable "float **changes" into "float (*changes)[2]" Used CTX_data_active_object() in place of CTX_data_pointer_get_type() Added the invert selection hotkey "Ctrl+I" to weight paint's vertex mask. --- source/blender/blenkernel/BKE_DerivedMesh.h | 3 - .../blender/blenkernel/intern/DerivedMesh.c | 14 ++- .../blender/blenkernel/intern/cdderivedmesh.c | 40 ------- .../blender/editors/armature/editarmature.c | 9 +- source/blender/editors/mesh/editmesh.c | 2 +- source/blender/editors/object/object_vgroup.c | 110 ++++++++---------- .../editors/sculpt_paint/paint_intern.h | 1 + .../blender/editors/sculpt_paint/paint_ops.c | 2 + .../editors/sculpt_paint/paint_utils.c | 19 +++ .../blender/editors/space_view3d/drawobject.c | 60 +++++++--- 10 files changed, 133 insertions(+), 127 deletions(-) diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index a109d5722ab..6e17b056685 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -222,9 +222,6 @@ struct DerivedMesh { /* Draw all vertices as bgl points (no options) */ void (*drawVerts)(DerivedMesh *dm); - /* Jason Draw all selected vertices as bgl points (no options) */ - void (*drawSelectedVerts)(DerivedMesh *dm); - /* Draw edges in the UV mesh (if exists) */ void (*drawUVEdges)(DerivedMesh *dm); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index e4198d578c4..10feba59ccc 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1726,13 +1726,15 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u } if (make_black) { - input = -1; + col[3] = 0; + col[2] = 0; + col[1] = 0; + col[0] = 255; + return; } - else { - CLAMP(input, 0.0f, 1.0f); - } - - + + CLAMP(input, 0.0f, 1.0f); + if(coba) do_colorband(coba, input, colf); else diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index d810de9d182..44359a142c9 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -265,44 +265,6 @@ static void cdDM_update_normals_from_pbvh(DerivedMesh *dm) BLI_pbvh_update(cddm->pbvh, PBVH_UpdateNormals, face_nors); } -// Jason -static void cdDM_drawSelectedVerts(DerivedMesh *dm) -{ - CDDerivedMesh *cddm = (CDDerivedMesh*) dm; - MVert *mv = cddm->mvert; - int i; - if( GPU_buffer_legacy(dm) ) { - char prev_sel= 0; /* always invalid */; - - glBegin(GL_POINTS); - for(i = 0; i < dm->numVertData; i++, mv++) { - if(!(mv->flag & ME_HIDE)) { - const char sel= mv->flag & 1; - if(prev_sel != sel) { - prev_sel= sel; - - // TODO define selected color - if(sel) { - glColor3f(1.0f, 1.0f, 0.0f); - }else { - glColor3f(0.0f, 0.0f, 0.0f); - } - } - - glVertex3fv(mv->co); - } - } - glEnd(); - } - else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */ - GPU_vertex_setup(dm); - if( !GPU_buffer_legacy(dm) ) { - if(dm->drawObject->tot_triangle_point) glDrawArrays(GL_POINTS,0, dm->drawObject->tot_triangle_point); - else glDrawArrays(GL_POINTS,0, dm->drawObject->tot_loose_point); - } - GPU_buffer_unbind(); - } -} static void cdDM_drawVerts(DerivedMesh *dm) { @@ -1589,8 +1551,6 @@ static CDDerivedMesh *cdDM_create(const char *desc) dm->getFaceMap = cdDM_getFaceMap; dm->drawVerts = cdDM_drawVerts; - // Jason - dm->drawSelectedVerts = cdDM_drawSelectedVerts; dm->drawUVEdges = cdDM_drawUVEdges; dm->drawEdges = cdDM_drawEdges; diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index ad140681c66..80a7e703474 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4297,8 +4297,6 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor { Object *ob= base->object; Bone *nearBone; - // Jason - Bone *new_act_bone; if (!ob || !ob->pose) return 0; @@ -4310,7 +4308,8 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ /* Jason was here, I'm doing a select for multibone painting */ - if ((base != scene->basact)) {//if (!(extend) || (base != scene->basact)) { + if (scene->toolsettings->multipaint && (base != scene->basact)) {//if (!(extend) || (base != scene->basact)) { + Bone *new_act_bone; /* Jason was here */ /* only deselect all if they aren't using 'shift' */ if(!extend) { @@ -4341,6 +4340,10 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); // XXX old cruft! use notifiers instead //select_actionchannel_by_name(ob->action, nearBone->name, 1); + } else if (!(extend) || (base != scene->basact)) { + ED_pose_deselectall(ob, 0); + nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_bone= nearBone; } else { if (nearBone->flag & BONE_SELECTED) { diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index 1634b464dfd..024331e8dc6 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -1992,7 +1992,7 @@ void paintvert_flush_flags(Object *ob) } } } -/* Jason note: caller needs to run paintvert_flush_flags(ob) after this */ +/* Jason note: if the caller passes FALSE to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */ void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) { Mesh *me; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7f78f25e1ce..f1fb879f4c9 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -705,7 +705,7 @@ static void vgroup_normalize(Object *ob) int i, def_nr, dvert_tot=0; // Jason Mesh *me = ob->data; - MVert *mv = me->mvert; + MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -719,7 +719,7 @@ static void vgroup_normalize(Object *ob) for(i = 0; i < dvert_tot; i++) { // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -733,7 +733,7 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -848,19 +848,13 @@ static int* getSurroundingVerts(Mesh *me, int vert, int *count) { /* get a single point in space by averaging a point cloud (vectors of size 3) coord is the place the average is stored, points is the point cloud, count is the number of points in the cloud */ -static void getSingleCoordinate(MVert **points, int count, float *coord) { - int i, k; - for(k = 0; k < 3; k++) { - coord[k] = 0; - } +static void getSingleCoordinate(MVert *points, int count, float coord[3]) { + int i; + zero_v3(coord); for(i = 0; i < count; i++) { - for(k = 0; k < 3; k++) { - coord[k] += points[i]->co[k]; - } - } - for(k = 0; k < 3; k++) { - coord[k] /= count; + add_v3_v3(coord, points[i].co); } + mul_v3_fl(coord, 1.0f/count); } /* Jason */ /* find the closest point on a plane to another point and store it in dst */ @@ -894,12 +888,11 @@ static float distance(float* a, float *b, int length) { compute the amount of vertical distance relative to the plane and store it in dists, then get the horizontal and vertical change and store them in changes */ -static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float **changes, float *dists, int index) { +static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float (*changes)[2], float *dists, int index) { // A=Q-((Q-P).N)N // D = (a*x0 + b*y0 +c*z0 +d) - float *projA, *projB; - projA = MEM_callocN(sizeof(float)*3, "projectedA"); - projB = MEM_callocN(sizeof(float)*3, "projectedB"); + float projA[3] = {0}, projB[3] = {0}; + getNearestPointOnPlane(norm, coord, start, projA); getNearestPointOnPlane(norm, coord, end, projB); // (vertical and horizontal refer to the plane's y and xz respectively) @@ -910,16 +903,19 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f //printf("vc %f %f\n", distance(end, projB, 3)-distance(start, projA, 3), changes[index][0]); // horizontal change changes[index][1] = distance(projA, projB, 3); - - MEM_freeN(projA); - MEM_freeN(projB); } // Jason // I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc) static void dm_deform_clear(DerivedMesh *dm, Object *ob) { - dm->needsFree = 1; - dm->release(dm); - ob->derivedDeform=NULL; + if(ob->derivedDeform && (ob->derivedDeform)==dm) { + ob->derivedDeform->needsFree = 1; + ob->derivedDeform->release(ob->derivedDeform); + ob->derivedDeform = NULL; + } + else if(dm) { + dm->needsFree = 1; + dm->release(dm); + } } // Jason // recalculate the deformation @@ -935,17 +931,17 @@ index is the index of the vertex being moved norm and d are the plane's properties for the equation: ax + by + cz + d = 0 coord is a point on the plane */ -static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float *norm, float *coord, float d, float distToBe, float strength, float cp) { +static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float norm[3], float coord[3], float d, float distToBe, float strength, float cp) { DerivedMesh *dm; MDeformWeight *dw; MVert m; MDeformVert *dvert = me->dvert+index; int totweight = dvert->totweight; float oldw = 0; - float *oldPos = MEM_callocN(sizeof(float)*3, "oldPosition"); + float oldPos[3] = {0}; float vc, hc, dist; int i, k; - float **changes = MEM_mallocN(sizeof(float *)*totweight, "vertHorzChange"); + float (*changes)[2] = MEM_mallocN(sizeof(float *)*totweight*2, "vertHorzChange"); float *dists = MEM_mallocN(sizeof(float)*totweight, "distance"); int *upDown = MEM_callocN(sizeof(int)*totweight, "upDownTracker");// track if up or down moved it closer for each bone int *dwIndices = MEM_callocN(sizeof(int)*totweight, "dwIndexTracker"); @@ -955,9 +951,6 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in char wasUp; int lastIndex = -1; float originalDistToBe = distToBe; - for(i = 0; i < totweight; i++) { - changes[i] = MEM_callocN(sizeof(float)*2, "vertHorzChange_"+i); - } do { wasChange = FALSE; dm = dm_deform_recalc(scene, ob); @@ -1097,13 +1090,9 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in } }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (dists[bestIndex]-distToBe)/fabs(dists[bestIndex]-distToBe)); MEM_freeN(upDown); - for(i = 0; i < totweight; i++) { - MEM_freeN(changes[i]); - } MEM_freeN(changes); MEM_freeN(dists); MEM_freeN(dwIndices); - MEM_freeN(oldPos); } // Jason /* this is used to try to smooth a surface by only adjusting the nonzero weights of a vertex @@ -1113,43 +1102,42 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, int i; Mesh *me = ob->data; - MVert *mv = me->mvert; + MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; int *verts = NULL; - for(i = 0; i < me->totvert && mv; i++, mv++) { + for(i = 0; i < me->totvert && mvert; i++, mvert++) { // Jason - if(use_vert_sel && (mv->flag & SELECT)) { + if(use_vert_sel && (mvert->flag & SELECT)) { int count=0; if((verts = getSurroundingVerts(me, i, &count))) { MVert m; - MVert **p = MEM_callocN(sizeof(MVert*)*(count), "deformedPoints"); + MVert *p = MEM_callocN(sizeof(MVert)*(count), "deformedPoints"); int k; DerivedMesh *dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); for(k = 0; k < count; k++) { dm->getVert(dm, verts[k], &m); - p[k] = &m; + p[k] = m; } if(count >= 3) { float d /*, dist */ /* UNUSED */, mag; - float *coord = MEM_callocN(sizeof(float)*3, "deformedCoord"); - float *norm = MEM_callocN(sizeof(float)*3, "planeNorm"); + float coord[3] = {0}; + float norm[3] = {0}; getSingleCoordinate(p, count, coord); dm->getVert(dm, i, &m); norm[0] = m.co[0]-coord[0]; norm[1] = m.co[1]-coord[1]; norm[2] = m.co[2]-coord[2]; mag = sqrt(norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2]); - for(k = 0; k < 3; k++) { - norm[k]/=mag; + if(mag) {// zeros fix + mul_v3_fl(norm, 1.0f/mag); + + d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2]; + /* dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); */ /* UNUSED */ + moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp); } - d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2]; - /* dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); */ /* UNUSED */ - moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp); - MEM_freeN(coord); - MEM_freeN(norm); } MEM_freeN(verts); @@ -1167,7 +1155,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) int i, def_nr, dvert_tot=0; // Jason Mesh *me = ob->data; - MVert *mv = me->mvert; + MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1179,7 +1167,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) for(i = 0; i < dvert_tot; i++) { // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1206,7 +1194,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) // Jason Mesh *me = ob->data; - MVert *mv = me->mvert; + MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1219,7 +1207,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) float lock_iweight= 1.0f; int j; // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1263,7 +1251,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) for(i = 0; i < dvert_tot; i++) { int j; // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1331,7 +1319,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) int i, def_nr, dvert_tot=0; // Jason Mesh *me = ob->data; - MVert *mv = me->mvert; + MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1344,7 +1332,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) for(i = 0; i < dvert_tot; i++) { // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } dvert = dvert_array[i]; @@ -1461,7 +1449,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) int i, def_nr, dvert_tot=0; // Jason Mesh *me = ob->data; - MVert *mv = me->mvert; + MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1473,7 +1461,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) for(i = 0; i < dvert_tot; i++) { // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } dvert = dvert_array[i]; @@ -1499,7 +1487,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) int i, dvert_tot=0; // Jason Mesh *me = ob->data; - MVert *mv = me->mvert; + MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -1508,7 +1496,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) for(i = 0; i < dvert_tot; i++) { int j; // Jason - if(use_vert_sel && !((mv+i)->flag & SELECT)) { + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -2334,7 +2322,7 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) /* Jason */ static int vertex_group_fix_exec(bContext *C, wmOperator *op) { - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); float distToBe= RNA_float_get(op->ptr,"dist"); @@ -2382,7 +2370,7 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) /* Jason was here */ static int vertex_group_lock_exec(bContext *C, wmOperator *op) { - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + Object *ob= CTX_data_active_object(C); int action = RNA_enum_get(op->ptr, "action"); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 95a6d0c2732..c8ffdb73cf5 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -123,6 +123,7 @@ void PAINT_OT_face_select_hide(struct wmOperatorType *ot); void PAINT_OT_face_select_reveal(struct wmOperatorType *ot); /* Jason */ void PAINT_OT_vert_select_all(struct wmOperatorType *ot); +void PAINT_OT_vert_select_inverse(struct wmOperatorType *ot); int vert_paint_poll(struct bContext *C); int mask_paint_poll(struct bContext *C); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 6aab104b79a..5708cc0f602 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -375,6 +375,7 @@ void ED_operatortypes_paint(void) /* Jason, vertex selection */ WM_operatortype_append(PAINT_OT_vert_select_all); + WM_operatortype_append(PAINT_OT_vert_select_inverse); /* vertex */ WM_operatortype_append(PAINT_OT_vertex_paint_toggle); @@ -615,6 +616,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf) keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0); keymap->poll= vert_paint_poll; WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0); RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0)->ptr, "deselect", 1); diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 18f59536092..8d7a3323f57 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -381,7 +381,26 @@ void PAINT_OT_vert_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } +/* Jason */ +static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Object *ob= CTX_data_active_object(C); + paintvert_deselect_all_visible(ob, SEL_INVERT, TRUE); + ED_region_tag_redraw(CTX_wm_region(C)); + return OPERATOR_FINISHED; +} +/* Jason */ +void PAINT_OT_vert_select_inverse(wmOperatorType *ot) +{ + ot->name= "Vertex Select Invert"; + ot->description= "Invert selection of vertices"; + ot->idname= "PAINT_OT_vert_select_inverse"; + ot->exec= vert_select_inverse_exec; + ot->poll= vert_paint_poll; + + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} static int face_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_active_object(C); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 439f05c3986..7a10a7216d9 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -77,6 +77,7 @@ #include "BKE_pointcache.h" #include "BKE_unit.h" + #include "smoke_API.h" #include "IMB_imbuf.h" @@ -85,6 +86,7 @@ #include "BIF_gl.h" #include "BIF_glutil.h" +#include "GPU_buffers.h"// Jason #include "GPU_draw.h" #include "GPU_extensions.h" @@ -1752,6 +1754,32 @@ void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, dm->release(dm); } + +/* Jason draw callback */ +static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s) +{ + MVert *mv = userData; + mv+=index; + //printf("%d\n", index); + if(!(mv->flag & ME_HIDE)) { + const char sel= mv->flag & 1; + + // TODO define selected color + if(sel) { + glColor3f(1.0f, 1.0f, 0.0f); + }else { + glColor3f(0.0f, 0.0f, 0.0f); + } + + glVertex3fv(co); + } +} +/* Jason */ +static void drawSelectedVertices(DerivedMesh *dm, Mesh *me) { + glBegin(GL_POINTS); + dm->foreachMappedVert(dm, drawSelectedVertices__mapFunc, me->mvert); + glEnd(); +} static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co) { struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData; @@ -2937,10 +2965,13 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D } } // Jason - if(paint_vertsel_test(ob) && dm->drawSelectedVerts) { + if(paint_vertsel_test(ob)) { + glColor3f(0.0f, 0.0f, 0.0f); glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE)); - dm->drawSelectedVerts(dm); + + drawSelectedVertices(dm, ob->data); + glPointSize(1.0f); } dm->release(dm); @@ -6528,23 +6559,26 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) /* Jason */ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { - // TODO: support hidden vertices - int offset = (intptr_t) userData; - //EditVert *eve = EM_get_vert_for_index(index); + struct {void* offset; MVert *mvert;} *data = userData; + MVert *mv = data->mvert+index; + int offset = (intptr_t) data->offset; - //if (eve->h==0) { - WM_set_framebuffer_index_color(offset+index); - bglVertex3fv(co); - //} + if (!(mv->flag & ME_HIDE)) { + WM_set_framebuffer_index_color(offset+index); + bglVertex3fv(co); + } } /* Jason */ -static void bbs_obmode_mesh_verts(Object *UNUSED(ob), DerivedMesh *dm, int offset) +static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset) { - /* Mesh *me = (Mesh*)ob->data; */ /* UNUSED */ - + struct {void* offset; struct MVert *mvert;} data; + Mesh *me = ob->data; + MVert *mvert = me->mvert; + data.mvert = mvert; + data.offset = (void*)(intptr_t) offset; glPointSize( UI_GetThemeValuef(TH_VERTEX_SIZE) ); bglBegin(GL_POINTS); - dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, (void*)(intptr_t) offset); + dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, &data); bglEnd(); glPointSize(1.0); } From 8f925a39b9483e056ea87d0211ddd05932e3fd9e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 02:46:03 +0000 Subject: [PATCH 57/68] rename EM_backbuf_checkAndSelectTVerts to EM_backbuf_checkAndSelectVerts_obmode until we come up with a better name this one at least says its in object mode, also there is no such thing as a TVert. --- source/blender/editors/space_view3d/view3d_select.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index fabaa3901d4..a11aeb2976d 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -202,8 +202,10 @@ static void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select) } } } + /* Jason */ -static void EM_backbuf_checkAndSelectTVerts(Mesh *me, int select) +/* object mode, EM_ prefix is confusing here, rename? */ +static void EM_backbuf_checkAndSelectVerts_obmode(Mesh *me, int select) { MVert *mv = me->mvert; int a; @@ -218,7 +220,7 @@ static void EM_backbuf_checkAndSelectTVerts(Mesh *me, int select) } } } - +/* object mode, EM_ prefix is confusing here, rename? */ static void EM_backbuf_checkAndSelectTFaces(Mesh *me, int select) { MFace *mface = me->mface; @@ -824,7 +826,7 @@ static void do_lasso_select_paintvert(ViewContext *vc, int mcords[][2], short mo lasso_select_boundbox(&rect, mcords, moves); EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); - EM_backbuf_checkAndSelectTVerts(me, select); + EM_backbuf_checkAndSelectVerts_obmode(me, select); EM_free_backbuf(); @@ -2177,7 +2179,7 @@ static void paint_vertsel_circle_select(ViewContext *vc, int select, const int m em_vertoffs= me->totvert+1; /* max index array */ bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f)); - EM_backbuf_checkAndSelectTVerts(me, select==LEFTMOUSE); + EM_backbuf_checkAndSelectVerts_obmode(me, select==LEFTMOUSE); EM_free_backbuf(); paintvert_flush_flags(ob); From 6d2b98ac893cd3c0bc397b6ac40995c964d72fa0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 03:29:17 +0000 Subject: [PATCH 58/68] added back scene/object update function, its needed for multipaint switching. --- source/blender/makesrna/intern/rna_scene.c | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 3e7b1692a26..b176b3079af 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1044,6 +1044,22 @@ static KeyingSet *rna_Scene_keying_set_new(Scene *sce, ReportList *reports, cons } } +/* Jason */ + +/* note: without this, when Multi-Paint is activated/deactivated, the colors + * will not change right away when multiple bones are selected, this function + * is not for general use and only for the few cases where changing scene + * settings and NOT for general purpose updates, possibly this should be + * given its own notifier. */ +static void rna_Scene_update_active_object_data(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + Object *ob= OBACT; + if(ob) { + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_main_add_notifier(NC_OBJECT|ND_DRAW, &ob->id); + } +} + #else static void rna_def_transform_orientation(BlenderRNA *brna) @@ -1124,10 +1140,10 @@ static void rna_def_tool_settings(BlenderRNA *brna) prop = RNA_def_property(srna, "use_multipaint", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "multipaint", 1); - RNA_def_property_ui_text(prop, "WPaint Multi-Paint", - "Paint across all selected bones while " - "weight painting"); - RNA_def_property_update(prop, NC_GEOM|ND_DATA, 0); + RNA_def_property_ui_text(prop, "WPaint Multi-Paint", + "Paint across all selected bones while " + "weight painting"); + RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data"); prop= RNA_def_property(srna, "vertex_paint", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "vpaint"); From a9c99f58f47e4d40ab86803f882f44c8e849b6d9 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Sun, 18 Sep 2011 03:49:00 +0000 Subject: [PATCH 59/68] Changed the branch code markers to say "Radish" in response to a review. They weren't & aren't meant to show ownership, they just help me navigate my related code. --- release/scripts/startup/bl_ui/space_view3d.py | 2 +- .../startup/bl_ui/space_view3d_toolbar.py | 2 +- source/blender/blenkernel/BKE_paint.h | 2 +- .../blender/blenkernel/intern/DerivedMesh.c | 20 +++---- source/blender/blenkernel/intern/armature.c | 2 +- source/blender/blenkernel/intern/paint.c | 2 +- .../blender/editors/armature/editarmature.c | 12 ++-- .../blender/editors/armature/meshlaplacian.c | 4 +- source/blender/editors/include/ED_mesh.h | 2 +- source/blender/editors/include/ED_view3d.h | 2 +- .../editors/interface/interface_templates.c | 2 +- source/blender/editors/mesh/editmesh.c | 4 +- source/blender/editors/mesh/editmesh_mods.c | 4 +- source/blender/editors/object/object_intern.h | 2 +- source/blender/editors/object/object_ops.c | 2 +- source/blender/editors/object/object_vgroup.c | 60 +++++++++---------- .../editors/sculpt_paint/paint_image.c | 4 +- .../editors/sculpt_paint/paint_intern.h | 2 +- .../blender/editors/sculpt_paint/paint_ops.c | 4 +- .../editors/sculpt_paint/paint_utils.c | 8 +-- .../editors/sculpt_paint/paint_vertex.c | 56 ++++++++--------- .../blender/editors/space_view3d/drawobject.c | 18 +++--- .../editors/space_view3d/space_view3d.c | 2 +- .../editors/space_view3d/view3d_header.c | 2 +- .../editors/space_view3d/view3d_select.c | 22 +++---- source/blender/makesdna/DNA_mesh_types.h | 2 +- source/blender/makesdna/DNA_object_types.h | 2 +- source/blender/makesdna/DNA_scene_types.h | 2 +- source/blender/makesrna/intern/rna_mesh.c | 6 +- source/blender/makesrna/intern/rna_object.c | 2 +- source/blender/makesrna/intern/rna_scene.c | 2 +- 31 files changed, 129 insertions(+), 129 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index c9817cdf905..2fd90e91c6b 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -1072,7 +1072,7 @@ class VIEW3D_MT_paint_weight(Menu): layout.operator("object.vertex_group_invert", text="Invert") layout.operator("object.vertex_group_clean", text="Clean") layout.operator("object.vertex_group_levels", text="Levels") - #Jason + # Radish layout.operator("object.vertex_group_fix", text="Fix Deforms") layout.separator() diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 78b4a31f931..5dabc408c87 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -646,7 +646,7 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel): elif context.weight_paint_object and brush: layout.prop(context.tool_settings, "vertex_group_weight", text="Weight", slider=True) layout.prop(context.tool_settings, "use_auto_normalize", text="Auto Normalize") - # Jason was here + # Radish layout.prop(context.tool_settings, "use_multipaint", text="Multi-Paint") col = layout.column() diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 99f9944bc08..17249de9717 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -59,7 +59,7 @@ void paint_brush_set(struct Paint *paint, struct Brush *br); * Texture paint could be removed since selected faces are not used * however hiding faces is useful */ int paint_facesel_test(struct Object *ob); -/* Jason */ +/* Radish */ int paint_vertsel_test(struct Object *ob); /* Session data (mode-specific) */ diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 10feba59ccc..06c1c4163b7 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -40,7 +40,7 @@ #include "DNA_cloth_types.h" #include "DNA_key_types.h" #include "DNA_meshdata_types.h" -// Jason +/* Radish */ #include "DNA_armature_types.h" #include "DNA_object_types.h" @@ -1689,12 +1689,12 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u float colf[4], input = 0.0f; int i; - // Jason was here + /* Radish */ int make_black= FALSE; if (me->dvert) { if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { - // Jason was here + /* Radish */ int was_a_nonzero= FALSE; for (i=0; idvert[vert].totweight; i++) { /* in multipaint, get the average if auto normalize is inactive @@ -1761,7 +1761,7 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) unsigned char *wtcol; int i; - // Jason was here + /* Radish */ int defbase_len = BLI_countlist(&ob->defbase); char *defbase_sel = MEM_mallocN(defbase_len * sizeof(char), __func__); int selected = get_selected_defgroups(ob, defbase_sel, defbase_len); @@ -1777,7 +1777,7 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) if (mf->v4) calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], defbase_sel, selected, unselected, draw_flag); } - // Jason + /* Radish */ MEM_freeN(defbase_sel); CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData); @@ -1807,7 +1807,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos int has_multires = mmd != NULL, multires_applied = 0; int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt; - // Jason + /* Radish */ int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); @@ -1990,7 +1990,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, dm, draw_flag); // Jason + add_weight_mcol_dm(ob, dm, draw_flag); /* Radish */ /* Constructive modifiers need to have an origindex * otherwise they wont have anywhere to copy the data from. @@ -2102,7 +2102,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos CDDM_calc_normals(finaldm); if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, draw_flag);// Jason + add_weight_mcol_dm(ob, finaldm, draw_flag);/* Radish */ } else if(dm) { finaldm = dm; } else { @@ -2114,7 +2114,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, draw_flag);// Jason + add_weight_mcol_dm(ob, finaldm, draw_flag);/* Radish */ } /* add an orco layer if needed */ @@ -2387,7 +2387,7 @@ static void clear_mesh_caches(Object *ob) static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask) { Object *obact = scene->basact?scene->basact->object:NULL; - int editing = paint_facesel_test(ob) || paint_vertsel_test(ob);// Jason: paint_vertsel_test + int editing = paint_facesel_test(ob) || paint_vertsel_test(ob);/* Radish: paint_vertsel_test */ /* weight paint and face select need original indices because of selection buffer drawing */ int needMapping = (ob==obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT|OB_MODE_VERTEX_PAINT))); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 4682c4ceee2..a4908294b4b 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2465,7 +2465,7 @@ void where_is_pose (Scene *scene, Object *ob) } } -/* Jason was here */ +/* Radish */ /* Returns total selected vgroups */ int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_len) { diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index eac98519fcc..dac3630f396 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -96,7 +96,7 @@ int paint_facesel_test(Object *ob) { return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_MASK) && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))); } -/* Jason */ +/* Radish */ int paint_vertsel_test(Object *ob) { return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & OB_MODE_WEIGHT_PAINT)); diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 9a6be695555..4cbf93e9f10 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4276,7 +4276,7 @@ static int bone_looper(Object *ob, Bone *bone, void *data, return count; } -// Jason +/* Radish */ Bone* get_other_selected_bone(Object *ob) { Bone *bone; int i; @@ -4307,10 +4307,10 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor bArmature *arm= ob->data; /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ - /* Jason was here, I'm doing a select for multibone painting */ + /* Radish, I'm doing a select for multibone painting */ if (scene->toolsettings->multipaint && (base != scene->basact)) {//if (!(extend) || (base != scene->basact)) { Bone *new_act_bone; - /* Jason was here */ + /* Radish */ /* only deselect all if they aren't using 'shift' */ if(!extend) { ED_pose_deselectall(ob, 0); @@ -4319,7 +4319,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor ED_vgroup_select_by_name(OBACT, nearBone->name); } else { - // Jason deselect this bone specifically if it is selected already + /* Radish deselect this bone specifically if it is selected already */ if (nearBone->flag & BONE_SELECTED) { nearBone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); if(nearBone == arm->act_bone) { @@ -5105,7 +5105,7 @@ void POSE_OT_select_inverse(wmOperatorType *ot) static int pose_de_select_all_exec(bContext *C, wmOperator *op) { int action = RNA_enum_get(op->ptr, "action"); - //Jason + //Radish Object *ob = NULL; Scene *scene= CTX_data_scene(C); int multipaint = scene->toolsettings->multipaint; @@ -5138,7 +5138,7 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) CTX_DATA_END; WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, NULL); - // Jason + /* Radish */ if(multipaint) { ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; DAG_id_tag_update(&ob->id, OB_RECALC_DATA); diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 4ce4a780d09..20cf91e870a 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -657,7 +657,7 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, int *vertsflipped = NULL, *mask= NULL; int a, totface, j, bbone, firstsegment, lastsegment; - // Jason + /* Radish */ MVert *mv = me->mvert; int use_vert_sel= FALSE; @@ -670,7 +670,7 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, for(totface=0, a=0, mface=me->mface; atotface; a++, mface++) { totface++; if(mface->v4) totface++; - // Jason (added selectedVerts content for vertex mask, they used to just equal 1) + /* Radish (added selectedVerts content for vertex mask, they used to just equal 1) */ if(mask && ((mface->flag & ME_FACE_SEL) || use_vert_sel)) { mask[mface->v1]= use_vert_sel ? ((mv+mface->v1)->flag & 1): 1; mask[mface->v2]= use_vert_sel ? ((mv+mface->v2)->flag & 1): 1; diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 8005032f0a5..93f8c3fb003 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -122,7 +122,7 @@ int EM_texFaceCheck(struct EditMesh *em); int EM_vertColorCheck(struct EditMesh *em); void undo_push_mesh(struct bContext *C, const char *name); -/* Jason */ +/* Radish */ void paintvert_flush_flags(struct Object *ob); void paintvert_deselect_all_visible(struct Object *ob, int action, short flush_flags); diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index c774b5d3455..985130bb97f 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -216,7 +216,7 @@ void ED_view3d_project_float(struct ARegion *a, const float vec[3], float adr[2] void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short do_shift); /* drawobject.c iterators */ -/*Jason*/ +/* Radish */ void mesh_obmode_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct MVert *mv, int x, int y, int index), void *userData, int clipVerts); void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index ff1c3c687f9..9e5cda43b74 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2124,7 +2124,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe //uiItemR(row, itemptr, "mute", 0, "", ICON_MUTE_IPO_OFF); uiBlockSetEmboss(block, UI_EMBOSS); } - /* Jason was here: I need the RNA struct for vertex groups */ + /* Radish: I need the RNA struct for vertex groups */ else if(itemptr->type == &RNA_VertexGroup) { bDeformGroup *dg= (bDeformGroup *)itemptr->data; uiItemL(sub, name, icon); diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index 024331e8dc6..a868ee94712 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -1960,7 +1960,7 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc) } -/* Jason (similar to void paintface_flush_flags(Object *ob)) +/* Radish (similar to void paintface_flush_flags(Object *ob)) * copy the vertex flags, most importantly selection from the mesh to the final derived mesh, * use in object mode when selecting vertices (while painting) */ void paintvert_flush_flags(Object *ob) @@ -1992,7 +1992,7 @@ void paintvert_flush_flags(Object *ob) } } } -/* Jason note: if the caller passes FALSE to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */ +/* Radish note: if the caller passes FALSE to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */ void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) { Mesh *me; diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 27cc2b755e6..b0bf7915d7c 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -266,7 +266,7 @@ int EM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, sho /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); - else if(paint_vertsel_test(vc->obact));//Jason + else if(paint_vertsel_test(vc->obact));//Radish else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; @@ -329,7 +329,7 @@ int EM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); - else if (paint_vertsel_test(vc->obact));//Jason + else if (paint_vertsel_test(vc->obact));//Radish else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index cbce1526c3c..bc086283cb9 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -200,7 +200,7 @@ void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); -/* Jason was here */ +/* Radish */ void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index c34fb2e22dc..f4cb976bac6 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -174,7 +174,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); - /* Jason was here */ + /* Radish */ WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f1fb879f4c9..d96a6678572 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -61,7 +61,7 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_report.h" -#include "BKE_DerivedMesh.h"//Jason +#include "BKE_DerivedMesh.h"//Radish #include "RNA_access.h" #include "RNA_define.h" @@ -703,7 +703,7 @@ static void vgroup_normalize(Object *ob) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - // Jason + /* Radish */ Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -718,7 +718,7 @@ static void vgroup_normalize(Object *ob) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -732,7 +732,7 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -751,7 +751,7 @@ static void vgroup_normalize(Object *ob) if (dvert_array) MEM_freeN(dvert_array); } -// Jason +/* Radish */ /* This adds the indices of vertices to a list if they are not already present It returns the number that it added (0-2) It relies on verts having -1 for unassigned indices @@ -780,7 +780,7 @@ static int tryToAddVerts(int *verts, int length, int a, int b) { } return added; } -//Jason +//Radish /* This finds all of the vertices connected to vert by an edge and returns an array of indices of size count @@ -844,7 +844,7 @@ static int* getSurroundingVerts(Mesh *me, int vert, int *count) { MEM_freeN(tverts); return verts; } -/* Jason */ +/* Radish */ /* get a single point in space by averaging a point cloud (vectors of size 3) coord is the place the average is stored, points is the point cloud, count is the number of points in the cloud */ @@ -856,7 +856,7 @@ static void getSingleCoordinate(MVert *points, int count, float coord[3]) { } mul_v3_fl(coord, 1.0f/count); } -/* Jason */ +/* Radish */ /* find the closest point on a plane to another point and store it in dst */ /* coord is a point on the plane */ /* point is the point that you want the nearest of */ @@ -873,7 +873,7 @@ static void getNearestPointOnPlane(const float norm[3], const float coord[3], co dst_r[1] = point[1] - (norm[1] * dotprod); dst_r[2] = point[2] - (norm[2] * dotprod); } -/* Jason */ +/* Radish */ /* distance of two vectors a and b of size length */ static float distance(float* a, float *b, int length) { int i; @@ -883,7 +883,7 @@ static float distance(float* a, float *b, int length) { } return sqrt(sum); } -/* Jason */ +/* Radish */ /* given a plane and a start and end position, compute the amount of vertical distance relative to the plane and store it in dists, then get the horizontal and vertical change and store them in changes @@ -904,7 +904,7 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f // horizontal change changes[index][1] = distance(projA, projB, 3); } -// Jason +/* Radish */ // I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc) static void dm_deform_clear(DerivedMesh *dm, Object *ob) { if(ob->derivedDeform && (ob->derivedDeform)==dm) { @@ -917,12 +917,12 @@ static void dm_deform_clear(DerivedMesh *dm, Object *ob) { dm->release(dm); } } -// Jason +/* Radish */ // recalculate the deformation static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob) { return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); } -// Jason +/* Radish */ /* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to distToBe distance away from the provided plane strength can change distToBe so that it moves towards distToBe by that percentage cp changes how much the weights are adjusted to check the distance @@ -1094,7 +1094,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in MEM_freeN(dists); MEM_freeN(dwIndices); } -// Jason +/* Radish */ /* this is used to try to smooth a surface by only adjusting the nonzero weights of a vertex but it could be used to raise or lower an existing 'bump.' */ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, float cp) @@ -1106,7 +1106,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; int *verts = NULL; for(i = 0; i < me->totvert && mvert; i++, mvert++) { - // Jason + /* Radish */ if(use_vert_sel && (mvert->flag & SELECT)) { int count=0; @@ -1153,7 +1153,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - // Jason + /* Radish */ Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1166,7 +1166,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1192,7 +1192,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) int i, dvert_tot=0; float tot_weight; - // Jason + /* Radish */ Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1206,7 +1206,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) for(i = 0; i < dvert_tot; i++) { float lock_iweight= 1.0f; int j; - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1250,7 +1250,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) else { for(i = 0; i < dvert_tot; i++) { int j; - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1281,7 +1281,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) if (dvert_array) MEM_freeN(dvert_array); } -/* Jason was here */ +/* Radish */ static void vgroup_lock_all(Object *ob, int action) { bDeformGroup *dg; @@ -1317,7 +1317,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - // Jason + /* Radish */ Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1331,7 +1331,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) for(i = 0; i < dvert_tot; i++) { - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1447,7 +1447,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - // Jason + /* Radish */ Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1460,7 +1460,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1485,7 +1485,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, dvert_tot=0; - // Jason + /* Radish */ Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1495,7 +1495,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) if(dvert_array) { for(i = 0; i < dvert_tot; i++) { int j; - // Jason + /* Radish */ if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -2319,7 +2319,7 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active", "Keep the values of the active group while normalizing others."); } -/* Jason */ +/* Radish */ static int vertex_group_fix_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -2367,7 +2367,7 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); } -/* Jason was here */ +/* Radish */ static int vertex_group_lock_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -2378,7 +2378,7 @@ static int vertex_group_lock_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -/* Jason was here */ +/* Radish */ void OBJECT_OT_vertex_group_lock(wmOperatorType *ot) { /* identifiers */ diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 8992dc81784..b116d86335e 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5408,12 +5408,12 @@ int facemask_paint_poll(bContext *C) { return paint_facesel_test(CTX_data_active_object(C)); } -// Jason +/* Radish */ int vert_paint_poll(bContext *C) { return paint_vertsel_test(CTX_data_active_object(C)); } -// Jason +/* Radish */ int mask_paint_poll(bContext *C) { return paint_facesel_test(CTX_data_active_object(C)) || paint_vertsel_test(CTX_data_active_object(C)); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index c8ffdb73cf5..c70835907dc 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -121,7 +121,7 @@ void PAINT_OT_face_select_all(struct wmOperatorType *ot); void PAINT_OT_face_select_inverse(struct wmOperatorType *ot); void PAINT_OT_face_select_hide(struct wmOperatorType *ot); void PAINT_OT_face_select_reveal(struct wmOperatorType *ot); -/* Jason */ +/* Radish */ void PAINT_OT_vert_select_all(struct wmOperatorType *ot); void PAINT_OT_vert_select_inverse(struct wmOperatorType *ot); int vert_paint_poll(struct bContext *C); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 5708cc0f602..6708c40e6ae 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -373,7 +373,7 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_weight_sample); WM_operatortype_append(PAINT_OT_weight_sample_group); - /* Jason, vertex selection */ + /* Radish, vertex selection */ WM_operatortype_append(PAINT_OT_vert_select_all); WM_operatortype_append(PAINT_OT_vert_select_inverse); @@ -611,7 +611,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0); - // Jason + /* Radish */ /*Weight paint's Vertex Selection Mode */ keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0); keymap->poll= vert_paint_poll; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 8d7a3323f57..e76d21a9eec 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -358,7 +358,7 @@ void PAINT_OT_face_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } -/* Jason */ +/* Radish */ static int vert_select_all_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -367,7 +367,7 @@ static int vert_select_all_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -/* Jason */ +/* Radish */ void PAINT_OT_vert_select_all(wmOperatorType *ot) { ot->name= "Vertex Selection"; @@ -381,7 +381,7 @@ void PAINT_OT_vert_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } -/* Jason */ +/* Radish */ static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_active_object(C); @@ -389,7 +389,7 @@ static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; } -/* Jason */ +/* Radish */ void PAINT_OT_vert_select_inverse(wmOperatorType *ot) { ot->name= "Vertex Select Invert"; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 62acacb4526..2b35ef5316d 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -399,14 +399,14 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) unsigned char i; int vgroup_mirror= -1; int selected; - // Jason + /* Radish */ int use_vert_sel; me= ob->data; if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return; selected= (me->editflag & ME_EDIT_PAINT_MASK); - // Jason + /* Radish */ use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; indexar= get_indexarray(me); @@ -443,7 +443,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) faceverts[3]= mface->v4; for (i=0; i<3 || faceverts[i]; i++) { if(!me->dvert[faceverts[i]].flag) { - // Jason + /* Radish */ if(use_vert_sel && ((me->mvert[faceverts[i]].flag & SELECT) == 0)) { continue; } @@ -840,7 +840,7 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float if (dw->weight > paintval) dw->weight = paintval*alpha + dw->weight*(1.0f-alpha); } - // Jason delay clamping until the end so multi-paint can function when the active group is at the limits + /* Radish delay clamping until the end so multi-paint can function when the active group is at the limits */ //CLAMP(dw->weight, 0.0f, 1.0f); /* if no spray, clip result with orig weight & orig alpha */ @@ -1111,7 +1111,7 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } #endif -// Jason was here: the active group should be involved in auto normalize +/* Radish: the active group should be involved in auto normalize */ static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map) { // MDeformWeight *dw = dvert->dw; @@ -1140,7 +1140,7 @@ static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char * } } } -/* Jason was here */ +/* Radish */ /* See if the current deform vertex has a locked group */ @@ -1154,7 +1154,7 @@ static char has_locked_group(MDeformVert *dvert, char *flags) } return FALSE; } -/* Jason was here +/* Radish * gen_lck_flags gets the status of "flag" for each bDeformGroup *in ob->defbase and returns an array containing them */ @@ -1177,7 +1177,7 @@ static char *gen_lck_flags(Object* ob, int defbase_len) MEM_freeN(flags); return NULL; } -/* Jason was here */ +/* Radish */ static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *flags) { int i; for(i = 0; i < defbase_len; i++) { @@ -1188,7 +1188,7 @@ static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *f return FALSE; } -/* Jason was here */ +/* Radish */ #if 0 /* UNUSED */ static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel, int selected, char *flags, char *bone_groups) { int i; @@ -1204,7 +1204,7 @@ static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel } #endif -/*Jason*/ +/* Radish */ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase_sel, int defbase_len) { int i; MDeformWeight *dw; @@ -1216,7 +1216,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase if(dw && dw->weight) { val = dw->weight * change; if(val > 1) { - // Jason TODO: when the change is reduced, you need to recheck the earlier values to make sure they are not 0 (precision error) + /* Radish TODO: when the change is reduced, you need to recheck the earlier values to make sure they are not 0 (precision error) */ change = 1.0f/dw->weight; } // the value should never reach zero while multi-painting if it was nonzero beforehand @@ -1236,7 +1236,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase } } } -/*Jason*/ +/* Radish */ // move all change onto valid, unchanged groups. If there is change left over, then return it. // assumes there are valid groups to shift weight onto static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, char *validmap, float totchange, float total_valid) { @@ -1282,7 +1282,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan // left overs return totchange; } -/*Jason*/ +/* Radish */ // observe the changes made to the weights of groups. // make sure all locked groups on the vertex have the same deformation // by moving the changes made to groups onto other unlocked groups @@ -1406,7 +1406,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c MEM_freeN(change_status); } -/*Jason*/ +/* Radish */ // multi-paint's initial, potential change is computed here based on the user's stroke static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_change) { float selwsum = 0.0f; @@ -1422,7 +1422,7 @@ static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_chan } return 0.0f; } -/*Jason*/ +/* Radish */ // change the weights back to the wv's weights // it assumes you already have the correct pointer index static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { @@ -1440,14 +1440,14 @@ static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { } } } -/* Jason */ +/* Radish */ static void clamp_weights(MDeformVert *dvert) { int i; for (i = 0; i < dvert->totweight; i++) { CLAMP((dvert->dw+i)->weight, 0.0f, 1.0f); } } -/*Jason*/ +/* Radish */ /* fresh start to make multi-paint and locking modular */ /* returns TRUE if it thinks you need to reset the weights due to normalizing while multi-painting */ static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defbase_len, float change, float oldChange, float oldw, float neww, char *defbase_sel, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { @@ -1506,7 +1506,7 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *defbase_s } return -1; } -// Jason +/* Radish */ static char *wpaint_make_validmap(Object *ob); static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, @@ -1514,11 +1514,11 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int vgroup_mirror, char *validmap, int multipaint) { Mesh *me= ob->data; - // Jason: tdw, tuw + // Radish: tdw, tuw MDeformWeight *dw, *uw, *tdw = NULL, *tuw; int vgroup= ob->actdef-1; - /* Jason was here */ + /* Radish */ char *flags; char *bone_groups; char *defbase_sel; @@ -1549,7 +1549,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } if(dw==NULL || uw==NULL) return; - /* Jason was here */ + /* Radish */ flags = gen_lck_flags(ob, defbase_len = BLI_countlist(&ob->defbase)); defbase_sel = MEM_mallocN(defbase_len * sizeof(char), "dg_selected_flags"); selected = get_selected_defgroups(ob, defbase_sel, defbase_len); @@ -1608,7 +1608,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } } - /* Jason was here */ + /* Radish */ if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint)) { reset_to_prev(dv, me->dvert+index); change = 0; @@ -1629,13 +1629,13 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, uw= defvert_verify_index(me->dvert+j, vgroup_mirror); else uw= defvert_verify_index(me->dvert+j, vgroup); - /* Jason */ + /* Radish */ //uw->weight= dw->weight; - /* Jason */ + /* Radish */ apply_mp_lcks_normalize(me, j, uw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint); } } - /* Jason */ + /* Radish */ if(flags) { MEM_freeN(flags); } @@ -1899,7 +1899,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float alpha; float mval[2], pressure; - // Jason + /* Radish */ int use_vert_sel; /* cannot paint if there is no stroke data */ @@ -1928,7 +1928,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P swap_m4m4(wpd->vc.rv3d->persmat, mat); - // Jason + /* Radish */ use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; /* which faces are involved */ @@ -2172,7 +2172,7 @@ void PAINT_OT_weight_set(wmOperatorType *ot) /* api callbacks */ ot->exec= weight_paint_set_exec; - ot->poll= mask_paint_poll; // Jason, it was facemask_paint_poll + ot->poll= mask_paint_poll; /* Radish, it was facemask_paint_poll */ /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 5bbc6a24761..44adca688cc 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -86,7 +86,7 @@ #include "BIF_gl.h" #include "BIF_glutil.h" -#include "GPU_buffers.h"// Jason +#include "GPU_buffers.h"/* Radish */ #include "GPU_draw.h" #include "GPU_extensions.h" @@ -1741,7 +1741,7 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe dm->release(dm); } -/*Jason */ +/* Radish */ static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData; @@ -1762,7 +1762,7 @@ static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, fl data->func(data->userData, mv, s[0], s[1], index); } } -/*Jason*/ +/* Radish */ void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, MVert *mv, int x, int y, int index), void *userData, int clipVerts) { struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } data; @@ -1781,7 +1781,7 @@ void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, dm->release(dm); } -/* Jason draw callback */ +/* Radish draw callback */ static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s) { MVert *mv = userData; @@ -1800,7 +1800,7 @@ static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, glVertex3fv(co); } } -/* Jason */ +/* Radish */ static void drawSelectedVertices(DerivedMesh *dm, Mesh *me) { glBegin(GL_POINTS); dm->foreachMappedVert(dm, drawSelectedVertices__mapFunc, me->mvert); @@ -2990,7 +2990,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D bglPolygonOffset(rv3d->dist, 0.0); } } - // Jason + /* Radish */ if(paint_vertsel_test(ob)) { glColor3f(0.0f, 0.0f, 0.0f); @@ -6590,7 +6590,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) } /* ***************** BACKBUF SEL (BBS) ********* */ -/* Jason */ +/* Radish */ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { struct {void* offset; MVert *mvert;} *data = userData; @@ -6602,7 +6602,7 @@ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, bglVertex3fv(co); } } -/* Jason */ +/* Radish */ static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset) { struct {void* offset; struct MVert *mvert;} data; @@ -6714,7 +6714,7 @@ static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUS return 0; } } -/* Jason */ +/* Radish */ // must have called WM_set_framebuffer_index_color beforehand static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r)) { diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 8773a67447f..3399ab4e260 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -371,7 +371,7 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar) keymap= WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); - /* Jason */ + /* Radish */ keymap= WM_keymap_find(wm->defaultconf, "Weight Paint Vertex Selection", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 5d23f2838cf..6429730c429 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -503,7 +503,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) { uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); } else { - // Jason + /* Radish */ row= uiLayoutRow(layout, 1); uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index a11aeb2976d..e9719e8e868 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -54,7 +54,7 @@ #include "BLI_linklist.h" #include "BLI_utildefines.h" -// Jason--vertex box select +/* Radish--vertex box select */ #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "BKE_global.h" @@ -203,7 +203,7 @@ static void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select) } } -/* Jason */ +/* Radish */ /* object mode, EM_ prefix is confusing here, rename? */ static void EM_backbuf_checkAndSelectVerts_obmode(Mesh *me, int select) { @@ -254,7 +254,7 @@ static int view3d_selectable_data(bContext *C) if (ob->mode & OB_MODE_SCULPT) { return 0; } - if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) {//Jason + if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) {//Radish return 0; } } @@ -749,7 +749,7 @@ static void do_lasso_select_meta(ViewContext *vc, int mcords[][2], short moves, } } } -/* Jason */ +/* Radish */ int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) { Mesh *me; @@ -809,7 +809,7 @@ int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) return OPERATOR_FINISHED; } -/* Jason */ +/* Radish */ static void do_lasso_select_paintvert(ViewContext *vc, int mcords[][2], short moves, short extend, short select) { Object *ob= vc->obact; @@ -1943,7 +1943,7 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) /* rna */ WM_operator_properties_gesture_border(ot, TRUE); } -/*Jason*/ +/* Radish */ /* much like facesel_face_pick()*/ /* returns 0 if not found, otherwise 1 */ static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, short rect) @@ -1973,7 +1973,7 @@ static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], un return 1; } -/* Jason */ +/* Radish */ /* mouse selection in weight paint */ /* gets called via generic mouse select operator */ int mouse_wp_select(bContext *C, const int mval[2], short extend, Object *obact, Mesh* me) @@ -2039,7 +2039,7 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) return PE_mouse_particles(C, event->mval, extend); else if(obact && paint_facesel_test(obact)) retval = paintface_mouse_select(C, obact, event->mval, extend); - /*Jason*/ + /* Radish */ else if (paint_vertsel_test(obact)) { retval = mouse_wp_select(C, event->mval, extend, obact, obact->data); } else { @@ -2168,7 +2168,7 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m } } -/* Jason */ +/* Radish */ static void paint_vertsel_circle_select(ViewContext *vc, int select, const int mval[2], float rad) { Object *ob= vc->obact; @@ -2440,7 +2440,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) int select; select= (gesture_mode==GESTURE_MODAL_SELECT); - // Jason + /* Radish */ if( CTX_data_edit_object(C) || paint_facesel_test(obact) || paint_vertsel_test(obact) || (obact && (obact->mode & (OB_MODE_PARTICLE_EDIT|OB_MODE_POSE))) ) { @@ -2460,7 +2460,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) else if(paint_facesel_test(obact)) { paint_facesel_circle_select(&vc, select, mval, (float)radius); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); - }/* Jason */ + }/* Radish */ else if(paint_vertsel_test(obact)) { paint_vertsel_circle_select(&vc, select, mval, (float)radius); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index bbd21a89f0a..1cf2e46c375 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -125,7 +125,7 @@ typedef struct TFace { #define ME_EDIT_PAINT_MASK (1 << 3) #define ME_EDIT_MIRROR_TOPO (1 << 4) -#define ME_EDIT_VERT_SEL (1 << 5)// Jason +#define ME_EDIT_VERT_SEL (1 << 5)/* Radish */ /* me->flag */ /* #define ME_ISDONE 1 */ diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 0b02006fea4..6d0899d1fa9 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -62,7 +62,7 @@ struct bGPdata; typedef struct bDeformGroup { struct bDeformGroup *next, *prev; char name[32]; - /* Jason was here: need this flag for locking weights */ + /* Radish: need this flag for locking weights */ char flag, pad[7]; } bDeformGroup; #define MAX_VGROUP_NAME 32 diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index fe2566b4542..7e2278cd30e 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -763,7 +763,7 @@ typedef struct ToolSettings { char auto_normalize; /*auto normalizing mode in wpaint*/ - //Jason + //Radish char multipaint; /* paint multiple bones in wpaint */ short sculpt_paint_settings; /* user preferences for sculpt and paint */ diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 2fdb9923ca5..d7d7fb932dc 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -90,7 +90,7 @@ void rna_Mesh_update_draw(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA } } -/* Jason */ +/* Radish */ void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr) { Mesh* me = ptr->data; @@ -99,7 +99,7 @@ void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr) } rna_Mesh_update_draw(bmain, scene, ptr); } -/* Jason */ +/* Radish */ void rna_Mesh_update_facemask(Main *bmain, Scene *scene, PointerRNA *ptr) { Mesh* me = ptr->data; @@ -2095,7 +2095,7 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0); RNA_def_property_update(prop, 0, "rna_Mesh_update_facemask"); - /* Jason */ + /* Radish */ prop= RNA_def_property(srna, "use_paint_mask_vertex", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERT_SEL); RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex selection masking for painting (weight paint only)"); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index e777d2df98b..c4e0db98f5f 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1265,7 +1265,7 @@ static void rna_def_vertex_group(BlenderRNA *brna) RNA_def_struct_name_property(srna, prop); RNA_def_property_string_funcs(prop, NULL, NULL, "rna_VertexGroup_name_set"); RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */ - /* Jason was here */ + /* Radish */ prop= RNA_def_property(srna, "lock_weight", PROP_BOOLEAN, PROP_NONE); RNA_def_property_ui_text(prop, "", "Maintain the relative weights for the group"); RNA_def_property_boolean_sdna(prop, NULL, "flag", 0); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index b176b3079af..82b099fb218 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1044,7 +1044,7 @@ static KeyingSet *rna_Scene_keying_set_new(Scene *sce, ReportList *reports, cons } } -/* Jason */ +/* Radish */ /* note: without this, when Multi-Paint is activated/deactivated, the colors * will not change right away when multiple bones are selected, this function From 24eaf6b9b80a9dedc757a4b883ffd7f36137fd2e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 14:48:15 +0000 Subject: [PATCH 60/68] replace malloc of a single DeformVertex with stack variable. --- .../blender/editors/sculpt_paint/paint_vertex.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 2b35ef5316d..c939b79d205 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1530,7 +1530,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, float change = 0; float oldChange = 0; int i; - MDeformVert *dv = NULL; + MDeformVert dv= {NULL}; // Need to know which groups are bone groups if(validmap) { @@ -1564,11 +1564,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, // setup multi-paint if(selected > 1 && multipaint) { - dv = MEM_mallocN(sizeof (*(me->dvert+index)), "prevMDeformVert"); - - dv->dw= MEM_dupallocN((me->dvert+index)->dw); - dv->flag = me->dvert[index].flag; - dv->totweight = (me->dvert+index)->totweight; + dv.dw= MEM_dupallocN((me->dvert+index)->dw); + dv.flag = me->dvert[index].flag; + dv.totweight = (me->dvert+index)->totweight; tdw = dw; tuw = uw; change = get_mp_change(wp->wpaint_prev+index, defbase_sel, neww-oldw); @@ -1610,13 +1608,12 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } /* Radish */ if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint)) { - reset_to_prev(dv, me->dvert+index); + reset_to_prev(&dv, me->dvert+index); change = 0; oldChange = 0; } - if(dv) { - MEM_freeN(dv->dw); - MEM_freeN(dv); + if(dv.dw) { + MEM_freeN(dv.dw); } // dvert may have been altered greatly dw = defvert_find_index(me->dvert+index, vgroup); From f4207ca4176a98dd8741be28ca82d4b146c15265 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 14:54:41 +0000 Subject: [PATCH 61/68] style changes only --- .../editors/sculpt_paint/paint_vertex.c | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index c939b79d205..f8874fe10b7 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1533,11 +1533,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, MDeformVert dv= {NULL}; // Need to know which groups are bone groups - if(validmap) { - bone_groups = validmap; - }else { - bone_groups = wpaint_make_validmap(ob); - } + bone_groups = validmap ? validmap : wpaint_make_validmap(ob); if(wp->flag & VP_ONLYVGROUP) { dw= defvert_find_index(me->dvert+index, vgroup); @@ -1576,7 +1572,8 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(i>=0) { tdw = ((me->dvert+index)->dw+i); tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); - } else { + } + else { change = 0; } } @@ -1588,20 +1585,24 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(change > oldChange) { // reset the weights and use the new change reset_to_prev(wp->wpaint_prev+index, me->dvert+index); - } else { + } + else { // the old change was more significant, // so set the change to 0 so that it will not do another multi-paint change = 0; } - } else { + } + else { if(change < oldChange) { reset_to_prev(wp->wpaint_prev+index, me->dvert+index); - } else { + } + else { change = 0; } } } - } else { + } + else { change = 0; } } @@ -1622,10 +1623,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int j= mesh_get_x_mirror_vert(ob, index); if(j>=0) { /* copy, not paint again */ - if(vgroup_mirror != -1) - uw= defvert_verify_index(me->dvert+j, vgroup_mirror); - else - uw= defvert_verify_index(me->dvert+j, vgroup); + uw= defvert_verify_index(me->dvert+j, (vgroup_mirror != -1) ? vgroup_mirror : vgroup); /* Radish */ //uw->weight= dw->weight; /* Radish */ From f0071799b64604918e67b254e66c8940b143b8e7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 15:17:16 +0000 Subject: [PATCH 62/68] allow multiple bones to be selected in weight paint mode in a less complicated way (allow Shift+RMB) --- .../blender/editors/armature/editarmature.c | 65 ++++--------------- 1 file changed, 13 insertions(+), 52 deletions(-) diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 4cbf93e9f10..7ab8d29680d 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4276,74 +4276,35 @@ static int bone_looper(Object *ob, Bone *bone, void *data, return count; } -/* Radish */ -Bone* get_other_selected_bone(Object *ob) { - Bone *bone; - int i; - bone = get_indexed_bone(ob, 0); - for(i = 0; bone;){ - if(bone->flag & BONE_SELECTED) { - return bone; - } - i++; - bone = get_indexed_bone(ob, i); - } - return NULL; -} /* called from editview.c, for mode-less pose selection */ /* assumes scene obact and basact is still on old situation */ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, short hits, short extend) { Object *ob= base->object; Bone *nearBone; - + if (!ob || !ob->pose) return 0; nearBone= get_bone_from_selectbuffer(scene, base, buffer, hits, 1); - + /* if the bone cannot be affected, don't do anything */ if ((nearBone) && !(nearBone->flag & BONE_UNSELECTABLE)) { + Object *ob_act= OBACT; bArmature *arm= ob->data; - /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ - /* Radish, I'm doing a select for multibone painting */ - if (scene->toolsettings->multipaint && (base != scene->basact)) {//if (!(extend) || (base != scene->basact)) { - Bone *new_act_bone; - /* Radish */ - /* only deselect all if they aren't using 'shift' */ - if(!extend) { - ED_pose_deselectall(ob, 0); - nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - arm->act_bone= nearBone; - ED_vgroup_select_by_name(OBACT, nearBone->name); - } - else { - /* Radish deselect this bone specifically if it is selected already */ - if (nearBone->flag & BONE_SELECTED) { - nearBone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - if(nearBone == arm->act_bone) { - // make a different bone the active one if it exists - new_act_bone = get_other_selected_bone(ob); - if(new_act_bone) { - new_act_bone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - arm->act_bone = new_act_bone; - ED_vgroup_select_by_name(OBACT, new_act_bone->name); - } - } - // or select the bone if they are using shift - } else { - nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - arm->act_bone= nearBone; - } - } - DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); - // XXX old cruft! use notifiers instead - //select_actionchannel_by_name(ob->action, nearBone->name, 1); - } else if (!(extend) || (base != scene->basact)) { + /* since we do unified select, we don't shift+select a bone if the + * armature object was not active yet. + * note, special exception for armature mode so we can do multi-select + * we could check for multi-select explicitly but think its fine to + * always give pradictable behavior in weight paint mode - campbell */ + if (!(extend) || (base->object != ob_act && !(ob_act->mode & OB_MODE_WEIGHT_PAINT))) { ED_pose_deselectall(ob, 0); nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); arm->act_bone= nearBone; + + // XXX old cruft! use notifiers instead + //select_actionchannel_by_name(ob->action, nearBone->name, 1); } else { if (nearBone->flag & BONE_SELECTED) { @@ -4368,7 +4329,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor } /* in weightpaint we select the associated vertex group too */ - if (OBACT && OBACT->mode & OB_MODE_WEIGHT_PAINT) { + if (ob_act && ob_act->mode & OB_MODE_WEIGHT_PAINT) { if (nearBone == arm->act_bone) { ED_vgroup_select_by_name(OBACT, nearBone->name); DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); From e234cb463689a19436f9d5fa25111433b1d531d5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 15:20:10 +0000 Subject: [PATCH 63/68] add back object update function for auto-normalize too. --- source/blender/makesrna/intern/rna_scene.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 82b099fb218..a325e1b9d67 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1133,10 +1133,10 @@ static void rna_def_tool_settings(BlenderRNA *brna) prop = RNA_def_property(srna, "use_auto_normalize", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "auto_normalize", 1); - RNA_def_property_ui_text(prop, "WPaint Auto-Normalize", - "Ensure all bone-deforming vertex groups add up to 1.0 while " - "weight painting"); - RNA_def_property_update(prop, NC_GEOM|ND_DATA, 0); + RNA_def_property_ui_text(prop, "WPaint Auto-Normalize", + "Ensure all bone-deforming vertex groups add up " + "to 1.0 while weight painting"); + RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data"); prop = RNA_def_property(srna, "use_multipaint", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "multipaint", 1); From 73863a1da5436ec5f63566e40ffa07ecbb903c69 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Sun, 18 Sep 2011 17:10:28 +0000 Subject: [PATCH 64/68] Split do_weight_paint_vertex() to isolate the simple case. Added a tool-tip to the "fix deforms" op. Removed code markers: "Radish" --- source/blender/blenkernel/BKE_paint.h | 2 +- .../blender/blenkernel/intern/DerivedMesh.c | 20 +- source/blender/blenkernel/intern/armature.c | 2 +- source/blender/blenkernel/intern/paint.c | 2 +- source/blender/blenkernel/intern/particle.c | 2 +- .../blender/editors/armature/editarmature.c | 4 +- .../blender/editors/armature/meshlaplacian.c | 4 +- source/blender/editors/include/ED_mesh.h | 2 +- source/blender/editors/include/ED_view3d.h | 2 +- .../editors/interface/interface_handlers.c | 2 +- .../editors/interface/interface_templates.c | 2 +- source/blender/editors/mesh/editmesh.c | 4 +- source/blender/editors/mesh/editmesh_mods.c | 4 +- source/blender/editors/object/object_intern.h | 2 +- source/blender/editors/object/object_ops.c | 2 +- source/blender/editors/object/object_vgroup.c | 61 ++--- .../editors/sculpt_paint/paint_image.c | 4 +- .../editors/sculpt_paint/paint_intern.h | 2 +- .../blender/editors/sculpt_paint/paint_ops.c | 4 +- .../editors/sculpt_paint/paint_utils.c | 8 +- .../editors/sculpt_paint/paint_vertex.c | 245 ++++++++++-------- .../blender/editors/space_view3d/drawobject.c | 18 +- .../editors/space_view3d/space_view3d.c | 2 +- .../editors/space_view3d/view3d_header.c | 2 +- .../editors/space_view3d/view3d_select.c | 22 +- source/blender/imbuf/intern/md5.c | 2 +- source/blender/makesdna/DNA_mesh_types.h | 2 +- source/blender/makesdna/DNA_object_types.h | 2 +- source/blender/makesdna/DNA_scene_types.h | 2 +- source/blender/makesrna/intern/rna_mesh.c | 6 +- source/blender/makesrna/intern/rna_object.c | 2 +- source/blender/makesrna/intern/rna_scene.c | 2 +- 32 files changed, 233 insertions(+), 209 deletions(-) diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 17249de9717..ad5fa13126f 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -59,7 +59,7 @@ void paint_brush_set(struct Paint *paint, struct Brush *br); * Texture paint could be removed since selected faces are not used * however hiding faces is useful */ int paint_facesel_test(struct Object *ob); -/* Radish */ + int paint_vertsel_test(struct Object *ob); /* Session data (mode-specific) */ diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 06c1c4163b7..46f59c327aa 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -40,7 +40,7 @@ #include "DNA_cloth_types.h" #include "DNA_key_types.h" #include "DNA_meshdata_types.h" -/* Radish */ + #include "DNA_armature_types.h" #include "DNA_object_types.h" @@ -1689,12 +1689,12 @@ static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, u float colf[4], input = 0.0f; int i; - /* Radish */ + int make_black= FALSE; if (me->dvert) { if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { - /* Radish */ + int was_a_nonzero= FALSE; for (i=0; idvert[vert].totweight; i++) { /* in multipaint, get the average if auto normalize is inactive @@ -1761,7 +1761,7 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) unsigned char *wtcol; int i; - /* Radish */ + int defbase_len = BLI_countlist(&ob->defbase); char *defbase_sel = MEM_mallocN(defbase_len * sizeof(char), __func__); int selected = get_selected_defgroups(ob, defbase_sel, defbase_len); @@ -1777,7 +1777,7 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) if (mf->v4) calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], defbase_sel, selected, unselected, draw_flag); } - /* Radish */ + MEM_freeN(defbase_sel); CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData); @@ -1807,7 +1807,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos int has_multires = mmd != NULL, multires_applied = 0; int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt; - /* Radish */ + int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); @@ -1990,7 +1990,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, dm, draw_flag); /* Radish */ + add_weight_mcol_dm(ob, dm, draw_flag); /* Constructive modifiers need to have an origindex * otherwise they wont have anywhere to copy the data from. @@ -2102,7 +2102,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos CDDM_calc_normals(finaldm); if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, draw_flag);/* Radish */ + add_weight_mcol_dm(ob, finaldm, draw_flag); } else if(dm) { finaldm = dm; } else { @@ -2114,7 +2114,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) - add_weight_mcol_dm(ob, finaldm, draw_flag);/* Radish */ + add_weight_mcol_dm(ob, finaldm, draw_flag); } /* add an orco layer if needed */ @@ -2387,7 +2387,7 @@ static void clear_mesh_caches(Object *ob) static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask) { Object *obact = scene->basact?scene->basact->object:NULL; - int editing = paint_facesel_test(ob) || paint_vertsel_test(ob);/* Radish: paint_vertsel_test */ + int editing = paint_facesel_test(ob) || paint_vertsel_test(ob);/* paint_vertsel_test */ /* weight paint and face select need original indices because of selection buffer drawing */ int needMapping = (ob==obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT|OB_MODE_VERTEX_PAINT))); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index a4908294b4b..b3b7d07f2cf 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2465,7 +2465,7 @@ void where_is_pose (Scene *scene, Object *ob) } } -/* Radish */ + /* Returns total selected vgroups */ int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_len) { diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index dac3630f396..ddeb42d608e 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -96,7 +96,7 @@ int paint_facesel_test(Object *ob) { return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_MASK) && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))); } -/* Radish */ + int paint_vertsel_test(Object *ob) { return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & OB_MODE_WEIGHT_PAINT)); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 82a2436a010..afdbbccff2c 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -2870,7 +2870,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) PARTICLE_P; float birthtime = 0.0, dietime = 0.0; - float t, time = 0.0, dfra = 1.0 /* , frs_sec = sim->scene->r.frs_sec*/ /*UNUSED*/; + float t, time = 0.0, dfra = 1.0 /* frs_sec = sim->scene->r.frs_sec*/ /*UNUSED*/; float col[4] = {0.5f, 0.5f, 0.5f, 1.0f}; float prev_tangent[3] = {0.0f, 0.0f, 0.0f}, hairmat[4][4]; float rotmat[3][3]; diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 7ab8d29680d..d023889c89a 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -5066,7 +5066,7 @@ void POSE_OT_select_inverse(wmOperatorType *ot) static int pose_de_select_all_exec(bContext *C, wmOperator *op) { int action = RNA_enum_get(op->ptr, "action"); - //Radish + Object *ob = NULL; Scene *scene= CTX_data_scene(C); int multipaint = scene->toolsettings->multipaint; @@ -5099,7 +5099,7 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) CTX_DATA_END; WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, NULL); - /* Radish */ + if(multipaint) { ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; DAG_id_tag_update(&ob->id, OB_RECALC_DATA); diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 20cf91e870a..ad1d1f23c2b 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -657,7 +657,7 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, int *vertsflipped = NULL, *mask= NULL; int a, totface, j, bbone, firstsegment, lastsegment; - /* Radish */ + MVert *mv = me->mvert; int use_vert_sel= FALSE; @@ -670,7 +670,7 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, for(totface=0, a=0, mface=me->mface; atotface; a++, mface++) { totface++; if(mface->v4) totface++; - /* Radish (added selectedVerts content for vertex mask, they used to just equal 1) */ + /* (added selectedVerts content for vertex mask, they used to just equal 1) */ if(mask && ((mface->flag & ME_FACE_SEL) || use_vert_sel)) { mask[mface->v1]= use_vert_sel ? ((mv+mface->v1)->flag & 1): 1; mask[mface->v2]= use_vert_sel ? ((mv+mface->v2)->flag & 1): 1; diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 93f8c3fb003..9709979ff6a 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -122,7 +122,7 @@ int EM_texFaceCheck(struct EditMesh *em); int EM_vertColorCheck(struct EditMesh *em); void undo_push_mesh(struct bContext *C, const char *name); -/* Radish */ + void paintvert_flush_flags(struct Object *ob); void paintvert_deselect_all_visible(struct Object *ob, int action, short flush_flags); diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 985130bb97f..47984af5951 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -216,7 +216,7 @@ void ED_view3d_project_float(struct ARegion *a, const float vec[3], float adr[2] void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short do_shift); /* drawobject.c iterators */ -/* Radish */ + void mesh_obmode_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct MVert *mv, int x, int y, int index), void *userData, int clipVerts); void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 7661fa5994b..d9e9ef8730d 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3778,7 +3778,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx, Scopes *scopes = (Scopes *)but->poin; /* rcti rect; */ int changed= 1; - float /* dx, */ dy /* , yfac=1.f */; /* UNUSED */ + float /* dx, */ dy /* yfac=1.f */; /* UNUSED */ /* rect.xmin= but->x1; rect.xmax= but->x2; */ /* rect.ymin= but->y1; rect.ymax= but->y2; */ diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 9e5cda43b74..7c4b182d859 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2124,7 +2124,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe //uiItemR(row, itemptr, "mute", 0, "", ICON_MUTE_IPO_OFF); uiBlockSetEmboss(block, UI_EMBOSS); } - /* Radish: I need the RNA struct for vertex groups */ + /* I need the RNA struct for vertex groups */ else if(itemptr->type == &RNA_VertexGroup) { bDeformGroup *dg= (bDeformGroup *)itemptr->data; uiItemL(sub, name, icon); diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index a868ee94712..f74d419151e 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -1960,7 +1960,7 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc) } -/* Radish (similar to void paintface_flush_flags(Object *ob)) +/* (similar to void paintface_flush_flags(Object *ob)) * copy the vertex flags, most importantly selection from the mesh to the final derived mesh, * use in object mode when selecting vertices (while painting) */ void paintvert_flush_flags(Object *ob) @@ -1992,7 +1992,7 @@ void paintvert_flush_flags(Object *ob) } } } -/* Radish note: if the caller passes FALSE to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */ +/* note: if the caller passes FALSE to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */ void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) { Mesh *me; diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index b0bf7915d7c..f7c2f895ba5 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -266,7 +266,7 @@ int EM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, sho /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); - else if(paint_vertsel_test(vc->obact));//Radish + else if(paint_vertsel_test(vc->obact)); else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; @@ -329,7 +329,7 @@ int EM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); - else if (paint_vertsel_test(vc->obact));//Radish + else if (paint_vertsel_test(vc->obact)); else return 0; } else if(vc->v3d->drawtypev3d->flag & V3D_ZBUF_SELECT)==0) return 0; diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index bc086283cb9..6ba17076c23 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -200,7 +200,7 @@ void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); -/* Radish */ + void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index f4cb976bac6..a150b746901 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -174,7 +174,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); - /* Radish */ + WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index d96a6678572..5401b637646 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -61,7 +61,7 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_report.h" -#include "BKE_DerivedMesh.h"//Radish +#include "BKE_DerivedMesh.h" #include "RNA_access.h" #include "RNA_define.h" @@ -703,7 +703,7 @@ static void vgroup_normalize(Object *ob) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - /* Radish */ + Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -718,7 +718,7 @@ static void vgroup_normalize(Object *ob) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -732,7 +732,7 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -751,7 +751,7 @@ static void vgroup_normalize(Object *ob) if (dvert_array) MEM_freeN(dvert_array); } -/* Radish */ + /* This adds the indices of vertices to a list if they are not already present It returns the number that it added (0-2) It relies on verts having -1 for unassigned indices @@ -780,7 +780,7 @@ static int tryToAddVerts(int *verts, int length, int a, int b) { } return added; } -//Radish + /* This finds all of the vertices connected to vert by an edge and returns an array of indices of size count @@ -844,7 +844,7 @@ static int* getSurroundingVerts(Mesh *me, int vert, int *count) { MEM_freeN(tverts); return verts; } -/* Radish */ + /* get a single point in space by averaging a point cloud (vectors of size 3) coord is the place the average is stored, points is the point cloud, count is the number of points in the cloud */ @@ -856,7 +856,7 @@ static void getSingleCoordinate(MVert *points, int count, float coord[3]) { } mul_v3_fl(coord, 1.0f/count); } -/* Radish */ + /* find the closest point on a plane to another point and store it in dst */ /* coord is a point on the plane */ /* point is the point that you want the nearest of */ @@ -873,7 +873,7 @@ static void getNearestPointOnPlane(const float norm[3], const float coord[3], co dst_r[1] = point[1] - (norm[1] * dotprod); dst_r[2] = point[2] - (norm[2] * dotprod); } -/* Radish */ + /* distance of two vectors a and b of size length */ static float distance(float* a, float *b, int length) { int i; @@ -883,7 +883,7 @@ static float distance(float* a, float *b, int length) { } return sqrt(sum); } -/* Radish */ + /* given a plane and a start and end position, compute the amount of vertical distance relative to the plane and store it in dists, then get the horizontal and vertical change and store them in changes @@ -904,7 +904,7 @@ static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, f // horizontal change changes[index][1] = distance(projA, projB, 3); } -/* Radish */ + // I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc) static void dm_deform_clear(DerivedMesh *dm, Object *ob) { if(ob->derivedDeform && (ob->derivedDeform)==dm) { @@ -917,12 +917,12 @@ static void dm_deform_clear(DerivedMesh *dm, Object *ob) { dm->release(dm); } } -/* Radish */ + // recalculate the deformation static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob) { return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); } -/* Radish */ + /* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to distToBe distance away from the provided plane strength can change distToBe so that it moves towards distToBe by that percentage cp changes how much the weights are adjusted to check the distance @@ -1094,7 +1094,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in MEM_freeN(dists); MEM_freeN(dwIndices); } -/* Radish */ + /* this is used to try to smooth a surface by only adjusting the nonzero weights of a vertex but it could be used to raise or lower an existing 'bump.' */ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, float cp) @@ -1106,7 +1106,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; int *verts = NULL; for(i = 0; i < me->totvert && mvert; i++, mvert++) { - /* Radish */ + if(use_vert_sel && (mvert->flag & SELECT)) { int count=0; @@ -1153,7 +1153,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - /* Radish */ + Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1166,7 +1166,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1192,7 +1192,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) int i, dvert_tot=0; float tot_weight; - /* Radish */ + Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1206,7 +1206,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) for(i = 0; i < dvert_tot; i++) { float lock_iweight= 1.0f; int j; - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1250,7 +1250,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) else { for(i = 0; i < dvert_tot; i++) { int j; - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1281,7 +1281,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) if (dvert_array) MEM_freeN(dvert_array); } -/* Radish */ + static void vgroup_lock_all(Object *ob, int action) { bDeformGroup *dg; @@ -1317,7 +1317,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - /* Radish */ + Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1331,7 +1331,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) for(i = 0; i < dvert_tot; i++) { - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1447,7 +1447,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; - /* Radish */ + Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1460,7 +1460,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -1485,7 +1485,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, dvert_tot=0; - /* Radish */ + Mesh *me = ob->data; MVert *mvert = me->mvert; const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -1495,7 +1495,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) if(dvert_array) { for(i = 0; i < dvert_tot; i++) { int j; - /* Radish */ + if(use_vert_sel && !((mvert+i)->flag & SELECT)) { continue; } @@ -2319,7 +2319,7 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active", "Keep the values of the active group while normalizing others."); } -/* Radish */ + static int vertex_group_fix_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -2355,6 +2355,7 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) /* identifiers */ ot->name= "Fix Vertex Group Deform"; ot->idname= "OBJECT_OT_vertex_group_fix"; + ot->description= "Modify the position of selected vertices by changing only their respective groups' weights (this tool may be slow for many vertices)."; /* api callbacks */ ot->poll= vertex_group_poll; @@ -2367,7 +2368,7 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); } -/* Radish */ + static int vertex_group_lock_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -2378,7 +2379,7 @@ static int vertex_group_lock_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -/* Radish */ + void OBJECT_OT_vertex_group_lock(wmOperatorType *ot) { /* identifiers */ diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index b116d86335e..3b656338fd4 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5408,12 +5408,12 @@ int facemask_paint_poll(bContext *C) { return paint_facesel_test(CTX_data_active_object(C)); } -/* Radish */ + int vert_paint_poll(bContext *C) { return paint_vertsel_test(CTX_data_active_object(C)); } -/* Radish */ + int mask_paint_poll(bContext *C) { return paint_facesel_test(CTX_data_active_object(C)) || paint_vertsel_test(CTX_data_active_object(C)); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index c70835907dc..f671b7b1713 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -121,7 +121,7 @@ void PAINT_OT_face_select_all(struct wmOperatorType *ot); void PAINT_OT_face_select_inverse(struct wmOperatorType *ot); void PAINT_OT_face_select_hide(struct wmOperatorType *ot); void PAINT_OT_face_select_reveal(struct wmOperatorType *ot); -/* Radish */ + void PAINT_OT_vert_select_all(struct wmOperatorType *ot); void PAINT_OT_vert_select_inverse(struct wmOperatorType *ot); int vert_paint_poll(struct bContext *C); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 6708c40e6ae..287d204115c 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -373,7 +373,7 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_weight_sample); WM_operatortype_append(PAINT_OT_weight_sample_group); - /* Radish, vertex selection */ + /* vertex selection */ WM_operatortype_append(PAINT_OT_vert_select_all); WM_operatortype_append(PAINT_OT_vert_select_inverse); @@ -611,7 +611,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0); - /* Radish */ + /*Weight paint's Vertex Selection Mode */ keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0); keymap->poll= vert_paint_poll; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index e76d21a9eec..fe749011b98 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -358,7 +358,7 @@ void PAINT_OT_face_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } -/* Radish */ + static int vert_select_all_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -367,7 +367,7 @@ static int vert_select_all_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -/* Radish */ + void PAINT_OT_vert_select_all(wmOperatorType *ot) { ot->name= "Vertex Selection"; @@ -381,7 +381,7 @@ void PAINT_OT_vert_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } -/* Radish */ + static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_active_object(C); @@ -389,7 +389,7 @@ static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; } -/* Radish */ + void PAINT_OT_vert_select_inverse(wmOperatorType *ot) { ot->name= "Vertex Select Invert"; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index f8874fe10b7..6898febf092 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -399,14 +399,14 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) unsigned char i; int vgroup_mirror= -1; int selected; - /* Radish */ + int use_vert_sel; me= ob->data; if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return; selected= (me->editflag & ME_EDIT_PAINT_MASK); - /* Radish */ + use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; indexar= get_indexarray(me); @@ -443,7 +443,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) faceverts[3]= mface->v4; for (i=0; i<3 || faceverts[i]; i++) { if(!me->dvert[faceverts[i]].flag) { - /* Radish */ + if(use_vert_sel && ((me->mvert[faceverts[i]].flag & SELECT) == 0)) { continue; } @@ -840,8 +840,10 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float if (dw->weight > paintval) dw->weight = paintval*alpha + dw->weight*(1.0f-alpha); } - /* Radish delay clamping until the end so multi-paint can function when the active group is at the limits */ - //CLAMP(dw->weight, 0.0f, 1.0f); + /* delay clamping until the end so multi-paint can function when the active group is at the limits */ + if(multipaint == FALSE) { + CLAMP(dw->weight, 0.0f, 1.0f); + } /* if no spray, clip result with orig weight & orig alpha */ if((wp->flag & VP_SPRAY)==0) { @@ -868,8 +870,9 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float else testw = uw->weight; } - //CLAMP(testw, 0.0f, 1.0f); - if(!multipaint) { + + if(multipaint == FALSE) { + CLAMP(testw, 0.0f, 1.0f); if( testwweight ) { if(dw->weight < testw) dw->weight= testw; else if(dw->weight > uw->weight) dw->weight= uw->weight; @@ -1111,7 +1114,7 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } #endif -/* Radish: the active group should be involved in auto normalize */ +/* the active group should be involved in auto normalize */ static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map) { // MDeformWeight *dw = dvert->dw; @@ -1140,7 +1143,7 @@ static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char * } } } -/* Radish */ + /* See if the current deform vertex has a locked group */ @@ -1154,7 +1157,7 @@ static char has_locked_group(MDeformVert *dvert, char *flags) } return FALSE; } -/* Radish +/* * gen_lck_flags gets the status of "flag" for each bDeformGroup *in ob->defbase and returns an array containing them */ @@ -1177,7 +1180,7 @@ static char *gen_lck_flags(Object* ob, int defbase_len) MEM_freeN(flags); return NULL; } -/* Radish */ + static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *flags) { int i; for(i = 0; i < defbase_len; i++) { @@ -1188,7 +1191,7 @@ static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *f return FALSE; } -/* Radish */ + #if 0 /* UNUSED */ static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel, int selected, char *flags, char *bone_groups) { int i; @@ -1204,7 +1207,7 @@ static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel } #endif -/* Radish */ + static void multipaint_selection(MDeformVert *dvert, float change, char *defbase_sel, int defbase_len) { int i; MDeformWeight *dw; @@ -1216,7 +1219,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase if(dw && dw->weight) { val = dw->weight * change; if(val > 1) { - /* Radish TODO: when the change is reduced, you need to recheck the earlier values to make sure they are not 0 (precision error) */ + /* TODO: when the change is reduced, you need to recheck the earlier values to make sure they are not 0 (precision error) */ change = 1.0f/dw->weight; } // the value should never reach zero while multi-painting if it was nonzero beforehand @@ -1236,7 +1239,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase } } } -/* Radish */ + // move all change onto valid, unchanged groups. If there is change left over, then return it. // assumes there are valid groups to shift weight onto static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, char *validmap, float totchange, float total_valid) { @@ -1282,7 +1285,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan // left overs return totchange; } -/* Radish */ + // observe the changes made to the weights of groups. // make sure all locked groups on the vertex have the same deformation // by moving the changes made to groups onto other unlocked groups @@ -1406,7 +1409,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c MEM_freeN(change_status); } -/* Radish */ + // multi-paint's initial, potential change is computed here based on the user's stroke static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_change) { float selwsum = 0.0f; @@ -1422,7 +1425,7 @@ static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_chan } return 0.0f; } -/* Radish */ + // change the weights back to the wv's weights // it assumes you already have the correct pointer index static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { @@ -1440,14 +1443,14 @@ static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { } } } -/* Radish */ + static void clamp_weights(MDeformVert *dvert) { int i; for (i = 0; i < dvert->totweight; i++) { CLAMP((dvert->dw+i)->weight, 0.0f, 1.0f); } } -/* Radish */ + /* fresh start to make multi-paint and locking modular */ /* returns TRUE if it thinks you need to reset the weights due to normalizing while multi-painting */ static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defbase_len, float change, float oldChange, float oldw, float neww, char *defbase_sel, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { @@ -1506,7 +1509,7 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *defbase_s } return -1; } -/* Radish */ + static char *wpaint_make_validmap(Object *ob); static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, @@ -1514,26 +1517,16 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int vgroup_mirror, char *validmap, int multipaint) { Mesh *me= ob->data; - // Radish: tdw, tuw - MDeformWeight *dw, *uw, *tdw = NULL, *tuw; + + MDeformWeight *dw, *uw; int vgroup= ob->actdef-1; - /* Radish */ char *flags; - char *bone_groups; + char *defbase_sel; int selected; - float oldw; - float neww; - float testw=0; int defbase_len; - float change = 0; - float oldChange = 0; - int i; - MDeformVert dv= {NULL}; - // Need to know which groups are bone groups - bone_groups = validmap ? validmap : wpaint_make_validmap(ob); if(wp->flag & VP_ONLYVGROUP) { dw= defvert_find_index(me->dvert+index, vgroup); @@ -1545,99 +1538,129 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } if(dw==NULL || uw==NULL) return; - /* Radish */ + flags = gen_lck_flags(ob, defbase_len = BLI_countlist(&ob->defbase)); defbase_sel = MEM_mallocN(defbase_len * sizeof(char), "dg_selected_flags"); selected = get_selected_defgroups(ob, defbase_sel, defbase_len); if(!selected && ob->actdef) { selected = 1; } - - oldw = dw->weight; - wpaint_blend(wp, dw, uw, alpha, paintweight, flip, multipaint && selected >1); - neww = dw->weight; - dw->weight = oldw; - - // setup multi-paint - if(selected > 1 && multipaint) { - dv.dw= MEM_dupallocN((me->dvert+index)->dw); - dv.flag = me->dvert[index].flag; - dv.totweight = (me->dvert+index)->totweight; - tdw = dw; - tuw = uw; - change = get_mp_change(wp->wpaint_prev+index, defbase_sel, neww-oldw); - if(change) { - if(!tdw->weight) { - i = get_first_selected_nonzero_weight(me->dvert+index, defbase_sel); - if(i>=0) { - tdw = ((me->dvert+index)->dw+i); - tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); + // TODO: De-duplicate the simple weight paint + // If there are no locks or multipaint, then there is no need to run the more complicated checks + if((multipaint == FALSE || selected <= 1) && (flags == NULL || has_locked_group(me->dvert+index, flags) == FALSE)) { + wpaint_blend(wp, dw, uw, alpha, paintweight, flip, FALSE); + do_weight_paint_auto_normalize_all_groups(me->dvert+index, validmap); + + if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ + int j= mesh_get_x_mirror_vert(ob, index); + if(j>=0) { + /* copy, not paint again */ + uw= defvert_verify_index(me->dvert+j, (vgroup_mirror != -1) ? vgroup_mirror : vgroup); + + uw->weight= dw->weight; + + do_weight_paint_auto_normalize_all_groups(me->dvert+j, validmap); + } + } + } else { + // use locks and/or multipaint + // Need to know which groups are bone groups + char *bone_groups = validmap ? validmap : wpaint_make_validmap(ob); + + float oldw; + float neww; + float testw=0; + float change = 0; + float oldChange = 0; + int i; + MDeformWeight *tdw = NULL, *tuw; + MDeformVert dv= {NULL}; + + oldw = dw->weight; + wpaint_blend(wp, dw, uw, alpha, paintweight, flip, multipaint && selected >1); + neww = dw->weight; + dw->weight = oldw; + + // setup multi-paint + if(selected > 1 && multipaint) { + dv.dw= MEM_dupallocN((me->dvert+index)->dw); + dv.flag = me->dvert[index].flag; + dv.totweight = (me->dvert+index)->totweight; + tdw = dw; + tuw = uw; + change = get_mp_change(wp->wpaint_prev+index, defbase_sel, neww-oldw); + if(change) { + if(!tdw->weight) { + i = get_first_selected_nonzero_weight(me->dvert+index, defbase_sel); + if(i>=0) { + tdw = ((me->dvert+index)->dw+i); + tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); + } + else { + change = 0; + } + } + if(change && tuw->weight && tuw->weight * change) { + if(tdw->weight != tuw->weight) { + oldChange = tdw->weight/tuw->weight; + testw = tuw->weight*change; + if( testw > tuw->weight ) { + if(change > oldChange) { + // reset the weights and use the new change + reset_to_prev(wp->wpaint_prev+index, me->dvert+index); + } + else { + // the old change was more significant, + // so set the change to 0 so that it will not do another multi-paint + change = 0; + } + } + else { + if(change < oldChange) { + reset_to_prev(wp->wpaint_prev+index, me->dvert+index); + } + else { + change = 0; + } + } + } } else { change = 0; } } - if(change && tuw->weight && tuw->weight * change) { - if(tdw->weight != tuw->weight) { - oldChange = tdw->weight/tuw->weight; - testw = tuw->weight*change; - if( testw > tuw->weight ) { - if(change > oldChange) { - // reset the weights and use the new change - reset_to_prev(wp->wpaint_prev+index, me->dvert+index); - } - else { - // the old change was more significant, - // so set the change to 0 so that it will not do another multi-paint - change = 0; - } - } - else { - if(change < oldChange) { - reset_to_prev(wp->wpaint_prev+index, me->dvert+index); - } - else { - change = 0; - } - } - } - } - else { - change = 0; - } } - } - /* Radish */ - if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint)) { - reset_to_prev(&dv, me->dvert+index); - change = 0; - oldChange = 0; - } - if(dv.dw) { - MEM_freeN(dv.dw); - } - // dvert may have been altered greatly - dw = defvert_find_index(me->dvert+index, vgroup); + + if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint)) { + reset_to_prev(&dv, me->dvert+index); + change = 0; + oldChange = 0; + } + if(dv.dw) { + MEM_freeN(dv.dw); + } + // dvert may have been altered greatly + dw = defvert_find_index(me->dvert+index, vgroup); - if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ - int j= mesh_get_x_mirror_vert(ob, index); - if(j>=0) { - /* copy, not paint again */ - uw= defvert_verify_index(me->dvert+j, (vgroup_mirror != -1) ? vgroup_mirror : vgroup); - /* Radish */ - //uw->weight= dw->weight; - /* Radish */ - apply_mp_lcks_normalize(me, j, uw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint); + if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ + int j= mesh_get_x_mirror_vert(ob, index); + if(j>=0) { + /* copy, not paint again */ + uw= defvert_verify_index(me->dvert+j, (vgroup_mirror != -1) ? vgroup_mirror : vgroup); + + //uw->weight= dw->weight; + + apply_mp_lcks_normalize(me, j, uw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint); + } + } + if(!validmap) { + MEM_freeN(bone_groups); } } - /* Radish */ if(flags) { MEM_freeN(flags); } MEM_freeN(defbase_sel); - if(!validmap) { - MEM_freeN(bone_groups); - } } @@ -1894,7 +1917,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float alpha; float mval[2], pressure; - /* Radish */ + int use_vert_sel; /* cannot paint if there is no stroke data */ @@ -1923,7 +1946,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P swap_m4m4(wpd->vc.rv3d->persmat, mat); - /* Radish */ + use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; /* which faces are involved */ @@ -2167,7 +2190,7 @@ void PAINT_OT_weight_set(wmOperatorType *ot) /* api callbacks */ ot->exec= weight_paint_set_exec; - ot->poll= mask_paint_poll; /* Radish, it was facemask_paint_poll */ + ot->poll= mask_paint_poll; /* it was facemask_paint_poll */ /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 44adca688cc..a0269d5e0df 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -86,7 +86,7 @@ #include "BIF_gl.h" #include "BIF_glutil.h" -#include "GPU_buffers.h"/* Radish */ +#include "GPU_buffers.h" #include "GPU_draw.h" #include "GPU_extensions.h" @@ -1741,7 +1741,7 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe dm->release(dm); } -/* Radish */ + static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData; @@ -1762,7 +1762,7 @@ static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, fl data->func(data->userData, mv, s[0], s[1], index); } } -/* Radish */ + void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, MVert *mv, int x, int y, int index), void *userData, int clipVerts) { struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } data; @@ -1781,7 +1781,7 @@ void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, dm->release(dm); } -/* Radish draw callback */ +/* draw callback */ static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s) { MVert *mv = userData; @@ -1800,7 +1800,7 @@ static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, glVertex3fv(co); } } -/* Radish */ + static void drawSelectedVertices(DerivedMesh *dm, Mesh *me) { glBegin(GL_POINTS); dm->foreachMappedVert(dm, drawSelectedVertices__mapFunc, me->mvert); @@ -2990,7 +2990,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D bglPolygonOffset(rv3d->dist, 0.0); } } - /* Radish */ + if(paint_vertsel_test(ob)) { glColor3f(0.0f, 0.0f, 0.0f); @@ -6590,7 +6590,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) } /* ***************** BACKBUF SEL (BBS) ********* */ -/* Radish */ + static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { struct {void* offset; MVert *mvert;} *data = userData; @@ -6602,7 +6602,7 @@ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, bglVertex3fv(co); } } -/* Radish */ + static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset) { struct {void* offset; struct MVert *mvert;} data; @@ -6714,7 +6714,7 @@ static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUS return 0; } } -/* Radish */ + // must have called WM_set_framebuffer_index_color beforehand static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r)) { diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 3399ab4e260..c46b6b6d70b 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -371,7 +371,7 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar) keymap= WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); - /* Radish */ + keymap= WM_keymap_find(wm->defaultconf, "Weight Paint Vertex Selection", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 6429730c429..1b6bd7ed0e7 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -503,7 +503,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) { uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); } else { - /* Radish */ + row= uiLayoutRow(layout, 1); uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index e9719e8e868..77823c2d163 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -54,7 +54,7 @@ #include "BLI_linklist.h" #include "BLI_utildefines.h" -/* Radish--vertex box select */ +/* vertex box select */ #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "BKE_global.h" @@ -203,7 +203,7 @@ static void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select) } } -/* Radish */ + /* object mode, EM_ prefix is confusing here, rename? */ static void EM_backbuf_checkAndSelectVerts_obmode(Mesh *me, int select) { @@ -254,7 +254,7 @@ static int view3d_selectable_data(bContext *C) if (ob->mode & OB_MODE_SCULPT) { return 0; } - if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) {//Radish + if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) { return 0; } } @@ -749,7 +749,7 @@ static void do_lasso_select_meta(ViewContext *vc, int mcords[][2], short moves, } } } -/* Radish */ + int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) { Mesh *me; @@ -809,7 +809,7 @@ int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) return OPERATOR_FINISHED; } -/* Radish */ + static void do_lasso_select_paintvert(ViewContext *vc, int mcords[][2], short moves, short extend, short select) { Object *ob= vc->obact; @@ -1943,7 +1943,7 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) /* rna */ WM_operator_properties_gesture_border(ot, TRUE); } -/* Radish */ + /* much like facesel_face_pick()*/ /* returns 0 if not found, otherwise 1 */ static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, short rect) @@ -1973,7 +1973,7 @@ static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], un return 1; } -/* Radish */ + /* mouse selection in weight paint */ /* gets called via generic mouse select operator */ int mouse_wp_select(bContext *C, const int mval[2], short extend, Object *obact, Mesh* me) @@ -2039,7 +2039,7 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) return PE_mouse_particles(C, event->mval, extend); else if(obact && paint_facesel_test(obact)) retval = paintface_mouse_select(C, obact, event->mval, extend); - /* Radish */ + else if (paint_vertsel_test(obact)) { retval = mouse_wp_select(C, event->mval, extend, obact, obact->data); } else { @@ -2168,7 +2168,7 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m } } -/* Radish */ + static void paint_vertsel_circle_select(ViewContext *vc, int select, const int mval[2], float rad) { Object *ob= vc->obact; @@ -2440,7 +2440,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) int select; select= (gesture_mode==GESTURE_MODAL_SELECT); - /* Radish */ + if( CTX_data_edit_object(C) || paint_facesel_test(obact) || paint_vertsel_test(obact) || (obact && (obact->mode & (OB_MODE_PARTICLE_EDIT|OB_MODE_POSE))) ) { @@ -2460,7 +2460,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) else if(paint_facesel_test(obact)) { paint_facesel_circle_select(&vc, select, mval, (float)radius); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); - }/* Radish */ + } else if(paint_vertsel_test(obact)) { paint_vertsel_circle_select(&vc, select, mval, (float)radius); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); diff --git a/source/blender/imbuf/intern/md5.c b/source/blender/imbuf/intern/md5.c index 18148143eb9..3721f7a2af5 100644 --- a/source/blender/imbuf/intern/md5.c +++ b/source/blender/imbuf/intern/md5.c @@ -38,7 +38,7 @@ /* This array contains the bytes used to pad the buffer to the next 64-byte boundary. (RFC 1321, 3.1: Step 1) */ -static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; +static const unsigned char fillbuf[64] = { 0x80, 0 /* 0, 0, ... */ }; /* Initialize structure containing state of computation. diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 1cf2e46c375..25bb4958c97 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -125,7 +125,7 @@ typedef struct TFace { #define ME_EDIT_PAINT_MASK (1 << 3) #define ME_EDIT_MIRROR_TOPO (1 << 4) -#define ME_EDIT_VERT_SEL (1 << 5)/* Radish */ +#define ME_EDIT_VERT_SEL (1 << 5) /* me->flag */ /* #define ME_ISDONE 1 */ diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 6d0899d1fa9..f32f8d626de 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -62,7 +62,7 @@ struct bGPdata; typedef struct bDeformGroup { struct bDeformGroup *next, *prev; char name[32]; - /* Radish: need this flag for locking weights */ + /* need this flag for locking weights */ char flag, pad[7]; } bDeformGroup; #define MAX_VGROUP_NAME 32 diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 7e2278cd30e..24072e9f2c8 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -763,7 +763,7 @@ typedef struct ToolSettings { char auto_normalize; /*auto normalizing mode in wpaint*/ - //Radish + char multipaint; /* paint multiple bones in wpaint */ short sculpt_paint_settings; /* user preferences for sculpt and paint */ diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index d7d7fb932dc..a439ec471cd 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -90,7 +90,7 @@ void rna_Mesh_update_draw(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA } } -/* Radish */ + void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr) { Mesh* me = ptr->data; @@ -99,7 +99,7 @@ void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr) } rna_Mesh_update_draw(bmain, scene, ptr); } -/* Radish */ + void rna_Mesh_update_facemask(Main *bmain, Scene *scene, PointerRNA *ptr) { Mesh* me = ptr->data; @@ -2095,7 +2095,7 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0); RNA_def_property_update(prop, 0, "rna_Mesh_update_facemask"); - /* Radish */ + prop= RNA_def_property(srna, "use_paint_mask_vertex", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERT_SEL); RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex selection masking for painting (weight paint only)"); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index c4e0db98f5f..ee9d016dfe2 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1265,7 +1265,7 @@ static void rna_def_vertex_group(BlenderRNA *brna) RNA_def_struct_name_property(srna, prop); RNA_def_property_string_funcs(prop, NULL, NULL, "rna_VertexGroup_name_set"); RNA_def_property_update(prop, NC_GEOM|ND_DATA|NA_RENAME, "rna_Object_internal_update_data"); /* update data because modifiers may use [#24761] */ - /* Radish */ + prop= RNA_def_property(srna, "lock_weight", PROP_BOOLEAN, PROP_NONE); RNA_def_property_ui_text(prop, "", "Maintain the relative weights for the group"); RNA_def_property_boolean_sdna(prop, NULL, "flag", 0); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index a325e1b9d67..025bea8d190 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1044,7 +1044,7 @@ static KeyingSet *rna_Scene_keying_set_new(Scene *sce, ReportList *reports, cons } } -/* Radish */ + /* note: without this, when Multi-Paint is activated/deactivated, the colors * will not change right away when multiple bones are selected, this function From a89b253aa62021b9fb8cf5881629b136f1c236da Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 19 Sep 2011 02:43:03 +0000 Subject: [PATCH 65/68] edits to radish before merge with trunk - removed some unused functions. - renamed vars to make more sense paint_vertex.c 'flags' --> 'lock_flags' - some odd modifications were made in unrealted, commented code, copy these back from trunk. - rename vertex_group_fix 'cp' property to 'accuracy' - make style more consistant with trunk. - remove 'Radish' comments. --- release/scripts/startup/bl_ui/space_view3d.py | 1 - .../startup/bl_ui/space_view3d_toolbar.py | 1 - source/blender/blenkernel/BKE_paint.h | 2 +- .../blender/blenkernel/intern/DerivedMesh.c | 4 - source/blender/blenkernel/intern/particle.c | 2 +- .../blender/editors/armature/meshlaplacian.c | 33 +++-- source/blender/editors/include/ED_view3d.h | 3 - .../editors/interface/interface_handlers.c | 2 +- .../editors/interface/interface_templates.c | 1 - source/blender/editors/mesh/editmesh.c | 33 +++-- source/blender/editors/object/object_intern.h | 2 - source/blender/editors/object/object_ops.c | 2 - source/blender/editors/object/object_vgroup.c | 26 ++-- .../editors/sculpt_paint/paint_vertex.c | 133 +++++++++--------- .../blender/editors/space_view3d/drawobject.c | 57 ++------ .../editors/space_view3d/view3d_header.c | 3 +- .../editors/space_view3d/view3d_select.c | 2 +- source/blender/imbuf/intern/md5.c | 2 +- source/blender/makesdna/DNA_scene_types.h | 2 - 19 files changed, 140 insertions(+), 171 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 2fd90e91c6b..357c673edbd 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -1072,7 +1072,6 @@ class VIEW3D_MT_paint_weight(Menu): layout.operator("object.vertex_group_invert", text="Invert") layout.operator("object.vertex_group_clean", text="Clean") layout.operator("object.vertex_group_levels", text="Levels") - # Radish layout.operator("object.vertex_group_fix", text="Fix Deforms") layout.separator() diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 5dabc408c87..e322a6dcd13 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -646,7 +646,6 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel): elif context.weight_paint_object and brush: layout.prop(context.tool_settings, "vertex_group_weight", text="Weight", slider=True) layout.prop(context.tool_settings, "use_auto_normalize", text="Auto Normalize") - # Radish layout.prop(context.tool_settings, "use_multipaint", text="Multi-Paint") col = layout.column() diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index ad5fa13126f..2578a90808a 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -59,8 +59,8 @@ void paint_brush_set(struct Paint *paint, struct Brush *br); * Texture paint could be removed since selected faces are not used * however hiding faces is useful */ int paint_facesel_test(struct Object *ob); - int paint_vertsel_test(struct Object *ob); + /* Session data (mode-specific) */ typedef struct SculptSession { diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 46f59c327aa..1660ac29217 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -40,9 +40,7 @@ #include "DNA_cloth_types.h" #include "DNA_key_types.h" #include "DNA_meshdata_types.h" - #include "DNA_armature_types.h" - #include "DNA_object_types.h" #include "DNA_scene_types.h" // N_T @@ -1760,7 +1758,6 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) ColorBand *coba= stored_cb; /* warning, not a local var */ unsigned char *wtcol; int i; - int defbase_len = BLI_countlist(&ob->defbase); char *defbase_sel = MEM_mallocN(defbase_len * sizeof(char), __func__); @@ -1807,7 +1804,6 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos int has_multires = mmd != NULL, multires_applied = 0; int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt; - int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index afdbbccff2c..82a2436a010 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -2870,7 +2870,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) PARTICLE_P; float birthtime = 0.0, dietime = 0.0; - float t, time = 0.0, dfra = 1.0 /* frs_sec = sim->scene->r.frs_sec*/ /*UNUSED*/; + float t, time = 0.0, dfra = 1.0 /* , frs_sec = sim->scene->r.frs_sec*/ /*UNUSED*/; float col[4] = {0.5f, 0.5f, 0.5f, 1.0f}; float prev_tangent[3] = {0.0f, 0.0f, 0.0f}, hairmat[4][4]; float rotmat[3][3]; diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index ad1d1f23c2b..45caf41f438 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -657,26 +657,41 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, int *vertsflipped = NULL, *mask= NULL; int a, totface, j, bbone, firstsegment, lastsegment; - - MVert *mv = me->mvert; + MVert *mvert = me->mvert; int use_vert_sel= FALSE; + int use_face_sel= FALSE; *err_str= NULL; /* count triangles and create mask */ - if((me->editflag & ME_EDIT_PAINT_MASK) || (use_vert_sel= ((me->editflag & ME_EDIT_VERT_SEL) != 0))) + if( (use_face_sel= (me->editflag & ME_EDIT_PAINT_MASK) != 0) || + (use_vert_sel= ((me->editflag & ME_EDIT_VERT_SEL) != 0))) + { mask= MEM_callocN(sizeof(int)*me->totvert, "heat_bone_weighting mask"); + } for(totface=0, a=0, mface=me->mface; atotface; a++, mface++) { totface++; if(mface->v4) totface++; + /* (added selectedVerts content for vertex mask, they used to just equal 1) */ - if(mask && ((mface->flag & ME_FACE_SEL) || use_vert_sel)) { - mask[mface->v1]= use_vert_sel ? ((mv+mface->v1)->flag & 1): 1; - mask[mface->v2]= use_vert_sel ? ((mv+mface->v2)->flag & 1): 1; - mask[mface->v3]= use_vert_sel ? ((mv+mface->v3)->flag & 1): 1; - if(mface->v4) - mask[mface->v4]= use_vert_sel ? ((mv+mface->v4)->flag & 1): 1; + if(use_vert_sel) { + mask[mface->v1]= (mvert[mface->v1].flag & SELECT) != 0; + mask[mface->v2]= (mvert[mface->v2].flag & SELECT) != 0; + mask[mface->v3]= (mvert[mface->v3].flag & SELECT) != 0; + if(mface->v4) { + mask[mface->v4]= (mvert[mface->v4].flag & SELECT) != 0; + } + } + else { + if(use_face_sel) { + mask[mface->v1]= 1; + mask[mface->v2]= 1; + mask[mface->v3]= 1; + if(mface->v4) { + mask[mface->v4]= 1; + } + } } } diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 47984af5951..d574ddd3030 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -216,9 +216,6 @@ void ED_view3d_project_float(struct ARegion *a, const float vec[3], float adr[2] void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short do_shift); /* drawobject.c iterators */ - -void mesh_obmode_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct MVert *mv, int x, int y, int index), void *userData, int clipVerts); - void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts); void mesh_foreachScreenEdge(struct ViewContext *vc, void (*func)(void *userData, struct EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts); void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData, struct EditFace *efa, int x, int y, int index), void *userData); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index d9e9ef8730d..7661fa5994b 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3778,7 +3778,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx, Scopes *scopes = (Scopes *)but->poin; /* rcti rect; */ int changed= 1; - float /* dx, */ dy /* yfac=1.f */; /* UNUSED */ + float /* dx, */ dy /* , yfac=1.f */; /* UNUSED */ /* rect.xmin= but->x1; rect.xmax= but->x2; */ /* rect.ymin= but->y1; rect.ymax= but->y2; */ diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 7c4b182d859..b1d0b73b2b1 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2124,7 +2124,6 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe //uiItemR(row, itemptr, "mute", 0, "", ICON_MUTE_IPO_OFF); uiBlockSetEmboss(block, UI_EMBOSS); } - /* I need the RNA struct for vertex groups */ else if(itemptr->type == &RNA_VertexGroup) { bDeformGroup *dg= (bDeformGroup *)itemptr->data; uiItemL(sub, name, icon); diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index f74d419151e..1ff46ddb546 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -1967,28 +1967,33 @@ void paintvert_flush_flags(Object *ob) { Mesh *me= get_mesh(ob); DerivedMesh *dm= ob->derivedFinal; - MVert *verts, *mv, *mv_orig; + MVert *dm_mvert, *dm_mv; int *index_array = NULL; int totvert; int i; - + if(me==NULL || dm==NULL) return; index_array = dm->getVertDataArray(dm, CD_ORIGINDEX); - - verts = dm->getVertArray(dm); + + dm_mvert = dm->getVertArray(dm); totvert = dm->getNumVerts(dm); - - mv= verts; - - for (i= 0; imvert + index_array[i]; - mv->flag= mv_orig->flag; - } else { - mv_orig= me->mvert + i; - mv->flag= mv_orig->flag; + + dm_mv= dm_mvert; + + if(index_array) { + int orig_index; + for (i= 0; iflag= me->mvert[index_array[i]].flag; + } + } + } + else { + for (i= 0; iflag= me->mvert[i].flag; } } } diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 6ba17076c23..434111c1227 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -200,10 +200,8 @@ void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); - void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); - void OBJECT_OT_vertex_group_invert(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_blend(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_clean(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index a150b746901..12cb05637a7 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -174,10 +174,8 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); - WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); - WM_operatortype_append(OBJECT_OT_vertex_group_invert); WM_operatortype_append(OBJECT_OT_vertex_group_levels); WM_operatortype_append(OBJECT_OT_vertex_group_blend); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 5401b637646..2a3cdd015fa 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -719,7 +719,7 @@ static void vgroup_normalize(Object *ob) for(i = 0; i < dvert_tot; i++) { - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } @@ -733,7 +733,7 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } @@ -1167,7 +1167,7 @@ static void vgroup_levels(Object *ob, float offset, float gain) for(i = 0; i < dvert_tot; i++) { - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } @@ -1207,7 +1207,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) float lock_iweight= 1.0f; int j; - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } @@ -1251,7 +1251,7 @@ static void vgroup_normalize_all(Object *ob, int lock_active) for(i = 0; i < dvert_tot; i++) { int j; - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } @@ -1332,7 +1332,7 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) for(i = 0; i < dvert_tot; i++) { - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } dvert = dvert_array[i]; @@ -1461,7 +1461,7 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) for(i = 0; i < dvert_tot; i++) { - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } dvert = dvert_array[i]; @@ -1496,7 +1496,7 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) for(i = 0; i < dvert_tot; i++) { int j; - if(use_vert_sel && !((mvert+i)->flag & SELECT)) { + if(use_vert_sel && !(mvert[i].flag & SELECT)) { continue; } @@ -2325,10 +2325,10 @@ static int vertex_group_fix_exec(bContext *C, wmOperator *op) Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); - float distToBe= RNA_float_get(op->ptr,"dist"); - float strength= RNA_float_get(op->ptr,"strength"); - float cp= RNA_float_get(op->ptr,"cp"); - ModifierData *md = ob->modifiers.first; + float distToBe= RNA_float_get(op->ptr, "dist"); + float strength= RNA_float_get(op->ptr, "strength"); + float cp= RNA_float_get(op->ptr, "accuracy"); + ModifierData *md= ob->modifiers.first; while(md) { if(md->type == eModifierType_Mirror && (md->mode&eModifierMode_Realtime)) { @@ -2365,7 +2365,7 @@ void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to.", -10.0f, 10.0f); RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance moved can be changed by this multiplier.", -2.0f, 2.0f); - RNA_def_float(ot->srna, "cp", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); + RNA_def_float(ot->srna, "accuracy", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 6898febf092..46aa1b2e4da 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -443,8 +443,8 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) faceverts[3]= mface->v4; for (i=0; i<3 || faceverts[i]; i++) { if(!me->dvert[faceverts[i]].flag) { - - if(use_vert_sel && ((me->mvert[faceverts[i]].flag & SELECT) == 0)) { + + if(use_vert_sel && !(me->mvert[faceverts[i]].flag & SELECT)) { continue; } @@ -1147,11 +1147,11 @@ static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char * /* See if the current deform vertex has a locked group */ -static char has_locked_group(MDeformVert *dvert, char *flags) +static char has_locked_group(MDeformVert *dvert, char *lock_flags) { int i; for(i = 0; i < dvert->totweight; i++) { - if(flags[(dvert->dw+i)->def_nr] && (dvert->dw+i)->weight > 0.0f) { + if(lock_flags[dvert->dw[i].def_nr] && dvert->dw[i].weight > 0.0f) { return TRUE; } } @@ -1166,25 +1166,25 @@ static char *gen_lck_flags(Object* ob, int defbase_len) char is_locked = FALSE; int i; //int defbase_len = BLI_countlist(&ob->defbase); - char *flags = MEM_mallocN(defbase_len*sizeof(char), "defflags"); + char *lock_flags = MEM_mallocN(defbase_len*sizeof(char), "defflags"); bDeformGroup *defgroup; for(i = 0, defgroup = ob->defbase.first; i < defbase_len && defgroup; defgroup = defgroup->next, i++) { - flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); - is_locked |= flags[i]; + lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); + is_locked |= lock_flags[i]; } if(is_locked){ - return flags; + return lock_flags; } // don't forget to free it if it is unneeded - MEM_freeN(flags); + MEM_freeN(lock_flags); return NULL; } -static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *flags) { +static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *lock_flags) { int i; for(i = 0; i < defbase_len; i++) { - if(defbase_sel[i] && flags[i]) { + if(defbase_sel[i] && lock_flags[i]) { return TRUE; } } @@ -1193,13 +1193,13 @@ static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *f #if 0 /* UNUSED */ -static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel, int selected, char *flags, char *bone_groups) { +static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel, int selected, char *lock_flags, char *bone_groups) { int i; if(defbase_len == selected) { return FALSE; } for(i = 0; i < defbase_len; i++) { - if(bone_groups[i] && !defbase_sel[i] && !flags[i]) { + if(bone_groups[i] && !defbase_sel[i] && !lock_flags[i]) { return TRUE; } } @@ -1289,7 +1289,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan // observe the changes made to the weights of groups. // make sure all locked groups on the vertex have the same deformation // by moving the changes made to groups onto other unlocked groups -static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, char *flags, char *bone_groups, char *validmap) { +static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, char *lock_flags, char *bone_groups, char *validmap) { float totchange = 0.0f; float totchange_allowed = 0.0f; float left_over; @@ -1307,7 +1307,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c char *change_status; char new_weight_has_zero = FALSE; - if(!flags || !has_locked_group(ndv, flags)) { + if(!lock_flags || !has_locked_group(ndv, lock_flags)) { return; } // record if a group was changed, unlocked and not changed, or locked @@ -1318,7 +1318,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c odw = defvert_find_index(odv, i); // the weights are zero, so we can assume a lot if(!ndw || !odw) { - if (!flags[i] && bone_groups[i]){ + if (!lock_flags[i] && bone_groups[i]){ defvert_verify_index(odv, i); defvert_verify_index(ndv, i); total_valid++; @@ -1327,15 +1327,17 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c continue; } // locked groups should not be changed - if(flags[i]) { + if(lock_flags[i]) { ndw->weight = odw->weight; - } else if(ndw->weight != odw->weight) { // changed groups are handled here - totchange += ndw->weight-odw->weight; + } + else if(ndw->weight != odw->weight) { // changed groups are handled here + totchange += ndw->weight - odw->weight; change_status[i] = 2; // was altered already total_changed++; if(ndw->weight == 0) { new_weight_has_zero = TRUE; - } else if(designatedw == -1){ + } + else if(designatedw == -1){ designatedw = i; } } // unchanged, unlocked bone groups are handled here @@ -1357,17 +1359,19 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c // on whether or not you are painting the weight(s) up or down if(totchange < 0) { totchange_allowed = total_valid - totchange_allowed; - } else { + } + else { totchange_allowed *= -1; } left_over = 0; - if(fabs(totchange_allowed) < fabs(totchange)) { + if(fabsf(totchange_allowed) < fabsf(totchange)) { // this amount goes back onto the changed, unlocked weights - left_over = fabs(fabs(totchange)-fabs(totchange_allowed)); + left_over = fabsf(fabsf(totchange) - fabsf(totchange_allowed)); if(totchange > 0) { left_over *= -1; } - }else { + } + else { // all of the change will be permitted totchange_allowed = -totchange; } @@ -1389,7 +1393,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c ndw->weight = (totchange_allowed + odw->weight + odw2->weight)/(1 + ndw2->weight/ndw->weight); designatedw_changed = TRUE; } - ndw2->weight = ndw->weight*ndw2->weight/storedw; + ndw2->weight = ndw->weight * ndw2->weight / storedw; } } } @@ -1399,10 +1403,11 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c redistribute_change(ndv, change_status, 2, -2, validmap, left_over, total_changed); } } - } else { + } + else { // reset the weights for(i = 0; i < ndv->totweight; i++) { - (ndv->dw+i)->weight = (odv->dw+i)->weight; + ndv->dw[i].weight = odv->dw[i].weight; } } } @@ -1416,7 +1421,7 @@ static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_chan int i; MDeformWeight *dw; for(i=0; i < odv->totweight; i++) { - if(defbase_sel[(dw = (odv->dw+i))->def_nr]) { + if(defbase_sel[(dw= &odv->dw[i])->def_nr]) { selwsum += dw->weight; } } @@ -1433,14 +1438,10 @@ static void reset_to_prev(MDeformVert *wv, MDeformVert *dv) { MDeformWeight *d; MDeformWeight *w; for(i = 0; i < dv->totweight; i++) { - d = dv->dw+i; - w = defvert_find_index(wv, d->def_nr); - // if there was no w when there is a d, then the old weight was 0 - if(w) { - d->weight = w->weight; - } else { - d->weight = 0; - } + d= &dv->dw[i]; + w= defvert_find_index(wv, d->def_nr); + /* if there was no w when there is a d, then the old weight was 0 */ + d->weight = w ? w->weight : 0.0f; } } @@ -1453,38 +1454,41 @@ static void clamp_weights(MDeformVert *dvert) { /* fresh start to make multi-paint and locking modular */ /* returns TRUE if it thinks you need to reset the weights due to normalizing while multi-painting */ -static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defbase_len, float change, float oldChange, float oldw, float neww, char *defbase_sel, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) { +static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defbase_len, float change, float oldChange, float oldw, float neww, char *defbase_sel, int selected, char *bone_groups, char *validmap, char *lock_flags, int multipaint) +{ MDeformVert *dvert = me->dvert+index; MDeformVert dv= {NULL}; dv.dw= MEM_dupallocN(dvert->dw); dv.flag = dvert->flag; dv.totweight = dvert->totweight; - // do not multi-paint if a locked group is selected or the active group is locked - // !flags[dw->def_nr] helps if nothing is selected, but active group is locked - if((flags == NULL) || (has_locked_group_selected(defbase_len, defbase_sel, flags) == FALSE && flags[dw->def_nr] == FALSE)) { + /* do not multi-paint if a locked group is selected or the active group is locked + * !lock_flags[dw->def_nr] helps if nothing is selected, but active group is locked */ + if((lock_flags == NULL) || (lock_flags[dw->def_nr] == FALSE && has_locked_group_selected(defbase_len, defbase_sel, lock_flags) == FALSE)) { if(multipaint && selected > 1) { if(change && change!=1) { multipaint_selection(dvert, change, defbase_sel, defbase_len); } - } else {// this lets users paint normally, but don't let them paint locked groups + } + else { /* this lets users paint normally, but don't let them paint locked groups */ dw->weight = neww; } } clamp_weights(dvert); - enforce_locks(&dv, dvert, defbase_len, flags, bone_groups, validmap); + enforce_locks(&dv, dvert, defbase_len, lock_flags, bone_groups, validmap); do_weight_paint_auto_normalize_all_groups(dvert, validmap); if(oldChange && multipaint && selected > 1) { if(tdw->weight != oldw) { - if( neww > oldw ) { + if(neww > oldw) { if(tdw->weight <= oldw) { MEM_freeN(dv.dw); return TRUE; } - } else { + } + else { if(tdw->weight >= oldw) { MEM_freeN(dv.dw); return TRUE; @@ -1496,13 +1500,13 @@ static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDefo return FALSE; } -// within the current dvert index, get the dw that is selected and has a weight above 0 -// this helps multi-paint +/* within the current dvert index, get the dw that is selected and has a weight + * above 0, this helps multi-paint */ static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *defbase_sel) { int i; MDeformWeight *dw; for(i=0; i< dvert->totweight; i++) { - dw = dvert->dw+i; + dw = &dvert->dw[i]; if(defbase_sel[dw->def_nr] && dw->weight > 0) { return i; } @@ -1521,7 +1525,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, MDeformWeight *dw, *uw; int vgroup= ob->actdef-1; - char *flags; + char *lock_flags; char *defbase_sel; int selected; @@ -1539,15 +1543,18 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dw==NULL || uw==NULL) return; - flags = gen_lck_flags(ob, defbase_len = BLI_countlist(&ob->defbase)); + lock_flags = gen_lck_flags(ob, defbase_len = BLI_countlist(&ob->defbase)); defbase_sel = MEM_mallocN(defbase_len * sizeof(char), "dg_selected_flags"); selected = get_selected_defgroups(ob, defbase_sel, defbase_len); if(!selected && ob->actdef) { selected = 1; } - // TODO: De-duplicate the simple weight paint - // If there are no locks or multipaint, then there is no need to run the more complicated checks - if((multipaint == FALSE || selected <= 1) && (flags == NULL || has_locked_group(me->dvert+index, flags) == FALSE)) { + + /* TODO: De-duplicate the simple weight paint */ + + /* If there are no locks or multipaint, + * then there is no need to run the more complicated checks */ + if((multipaint == FALSE || selected <= 1) && (lock_flags == NULL || has_locked_group(&me->dvert[index], lock_flags) == FALSE)) { wpaint_blend(wp, dw, uw, alpha, paintweight, flip, FALSE); do_weight_paint_auto_normalize_all_groups(me->dvert+index, validmap); @@ -1562,9 +1569,10 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, do_weight_paint_auto_normalize_all_groups(me->dvert+j, validmap); } } - } else { - // use locks and/or multipaint - // Need to know which groups are bone groups + } + else { /* use locks and/or multipaint */ + + /* Need to know which groups are bone groups */ char *bone_groups = validmap ? validmap : wpaint_make_validmap(ob); float oldw; @@ -1593,7 +1601,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(!tdw->weight) { i = get_first_selected_nonzero_weight(me->dvert+index, defbase_sel); if(i>=0) { - tdw = ((me->dvert+index)->dw+i); + tdw = &(me->dvert[index].dw[i]); tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); } else { @@ -1631,7 +1639,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } - if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint)) { + if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, lock_flags, multipaint)) { reset_to_prev(&dv, me->dvert+index); change = 0; oldChange = 0; @@ -1650,15 +1658,15 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, //uw->weight= dw->weight; - apply_mp_lcks_normalize(me, j, uw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, flags, multipaint); + apply_mp_lcks_normalize(me, j, uw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, lock_flags, multipaint); } } if(!validmap) { MEM_freeN(bone_groups); } } - if(flags) { - MEM_freeN(flags); + if(lock_flags) { + MEM_freeN(lock_flags); } MEM_freeN(defbase_sel); } @@ -1916,8 +1924,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P int totindex, index, totw, flip; float alpha; float mval[2], pressure; - - int use_vert_sel; /* cannot paint if there is no stroke data */ @@ -1946,7 +1952,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P swap_m4m4(wpd->vc.rv3d->persmat, mat); - use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; /* which faces are involved */ @@ -1973,7 +1978,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P } } } - + if((me->editflag & ME_EDIT_PAINT_MASK) && me->mface) { for(index=0; indextotface) { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index a0269d5e0df..ecdac083aed 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -77,7 +77,6 @@ #include "BKE_pointcache.h" #include "BKE_unit.h" - #include "smoke_API.h" #include "IMB_imbuf.h" @@ -86,7 +85,6 @@ #include "BIF_gl.h" #include "BIF_glutil.h" -#include "GPU_buffers.h" #include "GPU_draw.h" #include "GPU_extensions.h" @@ -1742,58 +1740,19 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe dm->release(dm); } -static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) -{ - struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData; - Mesh *me = data->vc.obact->data; - MVert *mv = me->mvert+index; - //MVert *dmv = CDDM_get_verts(data->vc.obact->derivedFinal)+index; - //MVert *mv = CDDM_get_verts(data->vc.obact->derivedFinal)+index; - if ((mv->flag & ME_HIDE)==0) { - short s[2]= {IS_CLIPPED, 0}; - - if (data->clipVerts) { - view3d_project_short_clip(data->vc.ar, co, s, 1); - } else { - view3d_project_short_noclip(data->vc.ar, co, s); - } - - if (s[0]!=IS_CLIPPED) - data->func(data->userData, mv, s[0], s[1], index); - } -} - -void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, MVert *mv, int x, int y, int index), void *userData, int clipVerts) -{ - struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } data; - DerivedMesh *dm = mesh_get_derived_final(vc->scene, vc->obact, CD_MASK_BAREMESH); - - data.vc= *vc; - data.func = func; - data.userData = userData; - data.clipVerts = clipVerts; - - if(clipVerts) - ED_view3d_local_clipping(vc->rv3d, vc->obact->obmat); /* for local clipping lookups */ - - dm->foreachMappedVert(dm, mesh_obmode_foreachScreenVert__mapFunc, &data); - - dm->release(dm); -} - /* draw callback */ -static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s) +static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { - MVert *mv = userData; - mv+=index; - //printf("%d\n", index); + MVert *mv = &((MVert *)userData)[index]; + if(!(mv->flag & ME_HIDE)) { - const char sel= mv->flag & 1; + const char sel= mv->flag & SELECT; // TODO define selected color if(sel) { glColor3f(1.0f, 1.0f, 0.0f); - }else { + } + else { glColor3f(0.0f, 0.0f, 0.0f); } @@ -6594,7 +6553,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { struct {void* offset; MVert *mvert;} *data = userData; - MVert *mv = data->mvert+index; + MVert *mv = &data->mvert[index]; int offset = (intptr_t) data->offset; if (!(mv->flag & ME_HIDE)) { @@ -6720,7 +6679,7 @@ static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index, int *UNU { Mesh *me = userData; - if (!(me->mface[index].flag&ME_HIDE)) { + if (!(me->mface[index].flag & ME_HIDE)) { return 1; } else { return 0; diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 1b6bd7ed0e7..980e27ce116 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -502,7 +502,8 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr); if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) { uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); - } else { + } + else { row= uiLayoutRow(layout, 1); uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 77823c2d163..8cdb03abf38 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -2440,7 +2440,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) int select; select= (gesture_mode==GESTURE_MODAL_SELECT); - + if( CTX_data_edit_object(C) || paint_facesel_test(obact) || paint_vertsel_test(obact) || (obact && (obact->mode & (OB_MODE_PARTICLE_EDIT|OB_MODE_POSE))) ) { diff --git a/source/blender/imbuf/intern/md5.c b/source/blender/imbuf/intern/md5.c index 3721f7a2af5..18148143eb9 100644 --- a/source/blender/imbuf/intern/md5.c +++ b/source/blender/imbuf/intern/md5.c @@ -38,7 +38,7 @@ /* This array contains the bytes used to pad the buffer to the next 64-byte boundary. (RFC 1321, 3.1: Step 1) */ -static const unsigned char fillbuf[64] = { 0x80, 0 /* 0, 0, ... */ }; +static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; /* Initialize structure containing state of computation. diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 24072e9f2c8..9f176a22848 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -762,8 +762,6 @@ typedef struct ToolSettings { char pad[5]; char auto_normalize; /*auto normalizing mode in wpaint*/ - - char multipaint; /* paint multiple bones in wpaint */ short sculpt_paint_settings; /* user preferences for sculpt and paint */ From 8835a18e2e8521f88a809b78101efc109bd92848 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 19 Sep 2011 04:53:11 +0000 Subject: [PATCH 66/68] refactor wpaint_stroke_update_step not to call expensive functions per-vertex and move args passed to do_weight_paint_vertex into WeightPaintInfo structure since there were far too many args to this function. --- source/blender/blenkernel/intern/armature.c | 3 +- .../editors/sculpt_paint/paint_vertex.c | 275 ++++++++++-------- 2 files changed, 151 insertions(+), 127 deletions(-) diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index b3b7d07f2cf..1149d8eee25 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2466,7 +2466,8 @@ void where_is_pose (Scene *scene, Object *ob) } -/* Returns total selected vgroups */ +/* Returns total selected vgroups, + * wpi.defbase_sel is assumed malloc'd, all values are set */ int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_len) { bDeformGroup *defgroup; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 46aa1b2e4da..854febc0246 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1161,15 +1161,15 @@ static char has_locked_group(MDeformVert *dvert, char *lock_flags) * gen_lck_flags gets the status of "flag" for each bDeformGroup *in ob->defbase and returns an array containing them */ -static char *gen_lck_flags(Object* ob, int defbase_len) +static char *gen_lock_flags(Object* ob, int defbase_tot) { char is_locked = FALSE; int i; - //int defbase_len = BLI_countlist(&ob->defbase); - char *lock_flags = MEM_mallocN(defbase_len*sizeof(char), "defflags"); + //int defbase_tot = BLI_countlist(&ob->defbase); + char *lock_flags = MEM_mallocN(defbase_tot*sizeof(char), "defflags"); bDeformGroup *defgroup; - for(i = 0, defgroup = ob->defbase.first; i < defbase_len && defgroup; defgroup = defgroup->next, i++) { + for(i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); is_locked |= lock_flags[i]; } @@ -1181,9 +1181,9 @@ static char *gen_lck_flags(Object* ob, int defbase_len) return NULL; } -static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *lock_flags) { +static int has_locked_group_selected(int defbase_tot, char *defbase_sel, char *lock_flags) { int i; - for(i = 0; i < defbase_len; i++) { + for(i = 0; i < defbase_tot; i++) { if(defbase_sel[i] && lock_flags[i]) { return TRUE; } @@ -1193,12 +1193,12 @@ static int has_locked_group_selected(int defbase_len, char *defbase_sel, char *l #if 0 /* UNUSED */ -static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel, int selected, char *lock_flags, char *bone_groups) { +static int has_unselected_unlocked_bone_group(int defbase_tot, char *defbase_sel, int selected, char *lock_flags, char *bone_groups) { int i; - if(defbase_len == selected) { + if(defbase_tot == selected) { return FALSE; } - for(i = 0; i < defbase_len; i++) { + for(i = 0; i < defbase_tot; i++) { if(bone_groups[i] && !defbase_sel[i] && !lock_flags[i]) { return TRUE; } @@ -1208,12 +1208,12 @@ static int has_unselected_unlocked_bone_group(int defbase_len, char *defbase_sel #endif -static void multipaint_selection(MDeformVert *dvert, float change, char *defbase_sel, int defbase_len) { +static void multipaint_selection(MDeformVert *dvert, float change, char *defbase_sel, int defbase_tot) { int i; MDeformWeight *dw; float val; // make sure they are all at most 1 after the change - for(i = 0; i < defbase_len; i++) { + for(i = 0; i < defbase_tot; i++) { if(defbase_sel[i]) { dw = defvert_find_index(dvert, i); if(dw && dw->weight) { @@ -1230,7 +1230,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase } } // apply the valid change - for(i = 0; i < defbase_len; i++) { + for(i = 0; i < defbase_tot; i++) { if(defbase_sel[i]) { dw = defvert_find_index(dvert, i); if(dw && dw->weight) { @@ -1289,7 +1289,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan // observe the changes made to the weights of groups. // make sure all locked groups on the vertex have the same deformation // by moving the changes made to groups onto other unlocked groups -static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, char *lock_flags, char *bone_groups, char *validmap) { +static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, char *lock_flags, char *bone_groups, char *validmap) { float totchange = 0.0f; float totchange_allowed = 0.0f; float left_over; @@ -1311,9 +1311,9 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_len, c return; } // record if a group was changed, unlocked and not changed, or locked - change_status = MEM_callocN(sizeof(char)*defbase_len, "unlocked_unchanged"); + change_status = MEM_callocN(sizeof(char)*defbase_tot, "unlocked_unchanged"); - for(i = 0; i < defbase_len; i++) { + for(i = 0; i < defbase_tot; i++) { ndw = defvert_find_index(ndv, i); odw = defvert_find_index(odv, i); // the weights are zero, so we can assume a lot @@ -1452,51 +1452,87 @@ static void clamp_weights(MDeformVert *dvert) { } } -/* fresh start to make multi-paint and locking modular */ -/* returns TRUE if it thinks you need to reset the weights due to normalizing while multi-painting */ -static int apply_mp_lcks_normalize(Mesh *me, int index, MDeformWeight *dw, MDeformWeight *tdw, int defbase_len, float change, float oldChange, float oldw, float neww, char *defbase_sel, int selected, char *bone_groups, char *validmap, char *lock_flags, int multipaint) -{ - MDeformVert *dvert = me->dvert+index; - MDeformVert dv= {NULL}; +/* struct to avoid passing many args each call to do_weight_paint_vertex() */ +typedef struct WeightPaintInfo { - dv.dw= MEM_dupallocN(dvert->dw); - dv.flag = dvert->flag; - dv.totweight = dvert->totweight; + int defbase_tot; + + /* both must add up to 'defbase_tot' */ + int defbase_tot_sel; + int defbase_tot_unsel; + + int vgroup_mirror; /* mirror group or -1 */ + + char *lock_flags; /* boolean array for locked bones, + * length of defbase_tot */ + char *defbase_sel; /* boolean array for selected bones, + * length of defbase_tot */ + + + /* TODO, both are the result of wpaint_make_validmap() buy I'm not + * convinced they must be separated like this, nevertheless there are + * possible side-effects with merging them which need to be looked into + * carefully, for now keep both since theres not too much harm in it + * but review at some point if bone_group's var can use validmap instead. + * - campbell */ + char *vgroup_validmap; + char *bone_groups; + + + char do_flip; + char do_multipaint; +} WeightPaintInfo; + +/* fresh start to make multi-paint and locking modular */ +/* returns TRUE if it thinks you need to reset the weights due to + * normalizing while multi-painting */ +static int apply_mp_locks_normalize(Mesh *me, WeightPaintInfo *wpi, + const int index, + MDeformWeight *dw, MDeformWeight *tdw, + float change, float oldChange, + float oldw, float neww) +{ + MDeformVert *dv= me->dvert+index; + MDeformVert dv_test= {NULL}; + + dv_test.dw= MEM_dupallocN(dv->dw); + dv_test.flag = dv->flag; + dv_test.totweight = dv->totweight; /* do not multi-paint if a locked group is selected or the active group is locked * !lock_flags[dw->def_nr] helps if nothing is selected, but active group is locked */ - if((lock_flags == NULL) || (lock_flags[dw->def_nr] == FALSE && has_locked_group_selected(defbase_len, defbase_sel, lock_flags) == FALSE)) { - if(multipaint && selected > 1) { + if((wpi->lock_flags == NULL) || (wpi->lock_flags[dw->def_nr] == FALSE && has_locked_group_selected(wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags) == FALSE)) { + if(wpi->do_multipaint && wpi->defbase_tot_sel > 1) { if(change && change!=1) { - multipaint_selection(dvert, change, defbase_sel, defbase_len); + multipaint_selection(dv, change, wpi->defbase_sel, wpi->defbase_tot); } } else { /* this lets users paint normally, but don't let them paint locked groups */ dw->weight = neww; } } - clamp_weights(dvert); + clamp_weights(dv); - enforce_locks(&dv, dvert, defbase_len, lock_flags, bone_groups, validmap); + enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->lock_flags, wpi->vgroup_validmap, wpi->vgroup_validmap); - do_weight_paint_auto_normalize_all_groups(dvert, validmap); + do_weight_paint_auto_normalize_all_groups(dv, wpi->vgroup_validmap); - if(oldChange && multipaint && selected > 1) { + if(oldChange && wpi->do_multipaint && wpi->defbase_tot_sel > 1) { if(tdw->weight != oldw) { if(neww > oldw) { if(tdw->weight <= oldw) { - MEM_freeN(dv.dw); + MEM_freeN(dv_test.dw); return TRUE; } } else { if(tdw->weight >= oldw) { - MEM_freeN(dv.dw); + MEM_freeN(dv_test.dw); return TRUE; } } } } - MEM_freeN(dv.dw); + MEM_freeN(dv_test.dw); return FALSE; } @@ -1514,23 +1550,21 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *defbase_s return -1; } + static char *wpaint_make_validmap(Object *ob); -static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, - float alpha, float paintweight, int flip, - int vgroup_mirror, char *validmap, int multipaint) + +// int flip, int vgroup_mirror, char *validmap, int multipaint +static void do_weight_paint_vertex( /* vars which remain the same for every vert */ + VPaint *wp, Object *ob, WeightPaintInfo *wpi, + /* vars which change on each stroke */ + int index, float alpha, float paintweight + ) { Mesh *me= ob->data; MDeformWeight *dw, *uw; int vgroup= ob->actdef-1; - - char *lock_flags; - - char *defbase_sel; - int selected; - int defbase_len; - if(wp->flag & VP_ONLYVGROUP) { dw= defvert_find_index(me->dvert+index, vgroup); @@ -1543,38 +1577,29 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dw==NULL || uw==NULL) return; - lock_flags = gen_lck_flags(ob, defbase_len = BLI_countlist(&ob->defbase)); - defbase_sel = MEM_mallocN(defbase_len * sizeof(char), "dg_selected_flags"); - selected = get_selected_defgroups(ob, defbase_sel, defbase_len); - if(!selected && ob->actdef) { - selected = 1; - } - - /* TODO: De-duplicate the simple weight paint */ + /* TODO: De-duplicate the simple weight paint - jason */ + /* ... or not, since its <10 SLOC - campbell */ /* If there are no locks or multipaint, * then there is no need to run the more complicated checks */ - if((multipaint == FALSE || selected <= 1) && (lock_flags == NULL || has_locked_group(&me->dvert[index], lock_flags) == FALSE)) { - wpaint_blend(wp, dw, uw, alpha, paintweight, flip, FALSE); - do_weight_paint_auto_normalize_all_groups(me->dvert+index, validmap); + if((wpi->do_multipaint == FALSE || wpi->defbase_tot_sel <= 1) && (wpi->lock_flags == NULL || has_locked_group(&me->dvert[index], wpi->lock_flags) == FALSE)) { + wpaint_blend(wp, dw, uw, alpha, paintweight, wpi->do_flip, FALSE); + do_weight_paint_auto_normalize_all_groups(me->dvert+index, wpi->vgroup_validmap); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); if(j>=0) { /* copy, not paint again */ - uw= defvert_verify_index(me->dvert+j, (vgroup_mirror != -1) ? vgroup_mirror : vgroup); + uw= defvert_verify_index(me->dvert+j, (wpi->vgroup_mirror != -1) ? wpi->vgroup_mirror : vgroup); uw->weight= dw->weight; - do_weight_paint_auto_normalize_all_groups(me->dvert+j, validmap); + do_weight_paint_auto_normalize_all_groups(me->dvert+j, wpi->vgroup_validmap); } } } - else { /* use locks and/or multipaint */ - - /* Need to know which groups are bone groups */ - char *bone_groups = validmap ? validmap : wpaint_make_validmap(ob); - + else { + /* use locks and/or multipaint */ float oldw; float neww; float testw=0; @@ -1584,22 +1609,27 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, MDeformWeight *tdw = NULL, *tuw; MDeformVert dv= {NULL}; + /* Need to know which groups are bone groups */ + if(wpi->bone_groups == NULL) { + wpi->bone_groups= wpi->vgroup_validmap ? wpi->vgroup_validmap : wpaint_make_validmap(ob); + } + oldw = dw->weight; - wpaint_blend(wp, dw, uw, alpha, paintweight, flip, multipaint && selected >1); + wpaint_blend(wp, dw, uw, alpha, paintweight, wpi->do_flip, wpi->do_multipaint && wpi->defbase_tot_sel >1); neww = dw->weight; dw->weight = oldw; // setup multi-paint - if(selected > 1 && multipaint) { + if(wpi->defbase_tot_sel > 1 && wpi->do_multipaint) { dv.dw= MEM_dupallocN((me->dvert+index)->dw); dv.flag = me->dvert[index].flag; dv.totweight = (me->dvert+index)->totweight; tdw = dw; tuw = uw; - change = get_mp_change(wp->wpaint_prev+index, defbase_sel, neww-oldw); + change = get_mp_change(wp->wpaint_prev+index, wpi->defbase_sel, neww - oldw); if(change) { if(!tdw->weight) { - i = get_first_selected_nonzero_weight(me->dvert+index, defbase_sel); + i = get_first_selected_nonzero_weight(me->dvert+index, wpi->defbase_sel); if(i>=0) { tdw = &(me->dvert[index].dw[i]); tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); @@ -1639,7 +1669,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, } } - if(apply_mp_lcks_normalize(me, index, dw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, lock_flags, multipaint)) { + if(apply_mp_locks_normalize(me, wpi, index, dw, tdw, change, oldChange, oldw, neww)) { reset_to_prev(&dv, me->dvert+index); change = 0; oldChange = 0; @@ -1647,28 +1677,21 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, if(dv.dw) { MEM_freeN(dv.dw); } - // dvert may have been altered greatly + /* dvert may have been altered greatly */ dw = defvert_find_index(me->dvert+index, vgroup); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); if(j>=0) { /* copy, not paint again */ - uw= defvert_verify_index(me->dvert+j, (vgroup_mirror != -1) ? vgroup_mirror : vgroup); + uw= defvert_verify_index(me->dvert+j, (wpi->vgroup_mirror != -1) ? wpi->vgroup_mirror : vgroup); //uw->weight= dw->weight; - apply_mp_lcks_normalize(me, j, uw, tdw, defbase_len, change, oldChange, oldw, neww, defbase_sel, selected, bone_groups, validmap, lock_flags, multipaint); + apply_mp_locks_normalize(me, wpi, j, uw, tdw, change, oldChange, oldw, neww); } } - if(!validmap) { - MEM_freeN(bone_groups); - } } - if(lock_flags) { - MEM_freeN(lock_flags); - } - MEM_freeN(defbase_sel); } @@ -1770,9 +1793,6 @@ static char *wpaint_make_validmap(Object *ob) bDeformGroup *dg; ModifierData *md; char *validmap; - bPose *pose; - bPoseChannel *chan; - ArmatureModifierData *amd; GHash *gh = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "wpaint_make_validmap gh"); int i = 0, step1=1; @@ -1793,10 +1813,11 @@ static char *wpaint_make_validmap(Object *ob) if (md->type == eModifierType_Armature) { - amd = (ArmatureModifierData*) md; + ArmatureModifierData *amd= (ArmatureModifierData*) md; if(amd->object && amd->object->pose) { - pose = amd->object->pose; + bPose *pose= amd->object->pose; + bPoseChannel *chan; for (chan=pose->chanbase.first; chan; chan=chan->next) { if (chan->bone->flag & BONE_NO_DEFORM) @@ -1921,11 +1942,14 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float mat[4][4]; float paintweight; int *indexar; - int totindex, index, totw, flip; + int totindex, index, totw; float alpha; float mval[2], pressure; int use_vert_sel; + /* intentionally dont initialize as NULL, make sure we initialize all members below */ + WeightPaintInfo wpi; + /* cannot paint if there is no stroke data */ if (wpd == NULL) { // XXX: force a redraw here, since even though we can't paint, @@ -1944,12 +1968,29 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P /* load projection matrix */ mul_m4_m4m4(mat, ob->obmat, vc->rv3d->persmat); - flip = RNA_boolean_get(itemptr, "pen_flip"); pressure = RNA_float_get(itemptr, "pressure"); RNA_float_get_array(itemptr, "mouse", mval); mval[0]-= vc->ar->winrct.xmin; mval[1]-= vc->ar->winrct.ymin; - + + + + /* *** setup WeightPaintInfo - pass onto do_weight_paint_vertex *** */ + wpi.defbase_tot= BLI_countlist(&ob->defbase); + wpi.defbase_sel= MEM_mallocN(wpi.defbase_tot*sizeof(char), "wpi.defbase_sel"); + wpi.defbase_tot_sel= get_selected_defgroups(ob, wpi.defbase_sel, wpi.defbase_tot); + if(wpi.defbase_tot_sel == 0 && ob->actdef) wpi.defbase_tot_sel = 1; + wpi.defbase_tot_unsel= wpi.defbase_tot - wpi.defbase_tot_sel; + wpi.vgroup_mirror= wpd->vgroup_mirror; + wpi.lock_flags= gen_lock_flags(ob, wpi.defbase_tot); + wpi.vgroup_validmap= wpd->vgroup_validmap; + wpi.bone_groups= NULL; /* initialized on the fly */ + wpi.do_flip= RNA_boolean_get(itemptr, "pen_flip"); + wpi.do_multipaint= (ts->multipaint != 0); + /* *** done setting up WeightPaintInfo *** */ + + + swap_m4m4(wpd->vc.rv3d->persmat, mat); use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; @@ -2044,52 +2085,34 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P for(index=0; indextotface) { - MFace *mface= me->mface + (indexar[index]-1); - - if((me->dvert+mface->v1)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval, pressure); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v1, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap, ts->multipaint); - } - (me->dvert+mface->v1)->flag= 0; - } - - if((me->dvert+mface->v2)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval, pressure); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v2, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap, ts->multipaint); - } - (me->dvert+mface->v2)->flag= 0; - } - - if((me->dvert+mface->v3)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval, pressure); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v3, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap, ts->multipaint); - } - (me->dvert+mface->v3)->flag= 0; - } - - if((me->dvert+mface->v4)->flag) { - if(mface->v4) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval, pressure); + MFace *mf= me->mface + (indexar[index]-1); + unsigned int fidx= mf->v4 ? 3:2;; + do { + int vidx= *(&mf->v1 + fidx); + + if(me->dvert[vidx].flag) { + alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*vidx, mval, pressure); if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v4, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap, ts->multipaint); + do_weight_paint_vertex(wp, ob, &wpi, vidx, alpha, paintweight); } - (me->dvert+mface->v4)->flag= 0; + me->dvert[vidx].flag= 0; } - } + } while (fidx--); } } - + + + /* *** free wpi members */ + if(wpi.lock_flags) { + MEM_freeN(wpi.lock_flags); + } + if(wpi.bone_groups && (wpi.bone_groups != wpi.vgroup_validmap)) { + MEM_freeN(wpi.bone_groups); + } + MEM_freeN(wpi.defbase_sel); + /* *** dont freeing wpi members */ + + swap_m4m4(vc->rv3d->persmat, mat); DAG_id_tag_update(ob->data, 0); From e197b993d389d38b1ee6cbbdabe3ef2846f4aab6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 19 Sep 2011 05:06:21 +0000 Subject: [PATCH 67/68] remove duplicate variable - wpaint_make_validmap(ob) was being called twice for no good reason. --- .../editors/sculpt_paint/paint_vertex.c | 75 ++++++++----------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 854febc0246..6cda5e07118 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1147,7 +1147,7 @@ static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char * /* See if the current deform vertex has a locked group */ -static char has_locked_group(MDeformVert *dvert, char *lock_flags) +static char has_locked_group(MDeformVert *dvert, const char *lock_flags) { int i; for(i = 0; i < dvert->totweight; i++) { @@ -1193,13 +1193,13 @@ static int has_locked_group_selected(int defbase_tot, char *defbase_sel, char *l #if 0 /* UNUSED */ -static int has_unselected_unlocked_bone_group(int defbase_tot, char *defbase_sel, int selected, char *lock_flags, char *bone_groups) { +static int has_unselected_unlocked_bone_group(int defbase_tot, char *defbase_sel, int selected, char *lock_flags, char *vgroup_validmap) { int i; if(defbase_tot == selected) { return FALSE; } for(i = 0; i < defbase_tot; i++) { - if(bone_groups[i] && !defbase_sel[i] && !lock_flags[i]) { + if(vgroup_validmap[i] && !defbase_sel[i] && !lock_flags[i]) { return TRUE; } } @@ -1242,7 +1242,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase // move all change onto valid, unchanged groups. If there is change left over, then return it. // assumes there are valid groups to shift weight onto -static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, char *validmap, float totchange, float total_valid) { +static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, const char *vgroup_validmap, float totchange, float total_valid) { float was_change; float change; float oldval; @@ -1259,7 +1259,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan if(change_status[ndw->def_nr] == changeme) { oldval = ndw->weight; // if auto normalize is active, don't worry about upper bounds - if(!validmap && ndw->weight + change > 1) { + if(!vgroup_validmap && ndw->weight + change > 1) { totchange -= 1-ndw->weight; ndw->weight = 1; // stop the changes to this group @@ -1289,7 +1289,9 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan // observe the changes made to the weights of groups. // make sure all locked groups on the vertex have the same deformation // by moving the changes made to groups onto other unlocked groups -static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, char *lock_flags, char *bone_groups, char *validmap) { +static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, + const char *lock_flags, const char *vgroup_validmap) +{ float totchange = 0.0f; float totchange_allowed = 0.0f; float left_over; @@ -1318,7 +1320,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, c odw = defvert_find_index(odv, i); // the weights are zero, so we can assume a lot if(!ndw || !odw) { - if (!lock_flags[i] && bone_groups[i]){ + if (!lock_flags[i] && vgroup_validmap[i]){ defvert_verify_index(odv, i); defvert_verify_index(ndv, i); total_valid++; @@ -1341,7 +1343,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, c designatedw = i; } } // unchanged, unlocked bone groups are handled here - else if (bone_groups[i]){ + else if (vgroup_validmap[i]){ totchange_allowed += ndw->weight; total_valid++; change_status[i] = 1; // can be altered while redistributing @@ -1350,7 +1352,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, c // if there was any change, redistribute it if(total_changed) { // auto normalize will allow weights to temporarily go above 1 in redistribution - if(validmap && total_changed < 0 && total_valid) { + if(vgroup_validmap && total_changed < 0 && total_valid) { totchange_allowed = total_valid; } // there needs to be change allowed, or you should not bother @@ -1376,7 +1378,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, c totchange_allowed = -totchange; } // move the weight evenly between the allowed groups, move excess back onto the used groups based on the change - totchange_allowed = redistribute_change(ndv, change_status, 1, -1, validmap, totchange_allowed, total_valid); + totchange_allowed = redistribute_change(ndv, change_status, 1, -1, vgroup_validmap, totchange_allowed, total_valid); left_over += totchange_allowed; if(left_over) { // more than one nonzero weights were changed with the same ratio, so keep them changed that way! @@ -1400,7 +1402,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, c // a weight was changed to zero, only one weight was changed, or designatedw is still -1 // put weight back as evenly as possible else { - redistribute_change(ndv, change_status, 2, -2, validmap, left_over, total_changed); + redistribute_change(ndv, change_status, 2, -2, vgroup_validmap, left_over, total_changed); } } } @@ -1452,7 +1454,10 @@ static void clamp_weights(MDeformVert *dvert) { } } -/* struct to avoid passing many args each call to do_weight_paint_vertex() */ +/* struct to avoid passing many args each call to do_weight_paint_vertex() + * this _could_ be made a part of the operators 'WPaintData' struct, or at + * least a member, but for now keep its own struct, initialized on every + * paint stroke update - campbell */ typedef struct WeightPaintInfo { int defbase_tot; @@ -1468,16 +1473,8 @@ typedef struct WeightPaintInfo { char *defbase_sel; /* boolean array for selected bones, * length of defbase_tot */ - - /* TODO, both are the result of wpaint_make_validmap() buy I'm not - * convinced they must be separated like this, nevertheless there are - * possible side-effects with merging them which need to be looked into - * carefully, for now keep both since theres not too much harm in it - * but review at some point if bone_group's var can use validmap instead. - * - campbell */ - char *vgroup_validmap; - char *bone_groups; - + char *vgroup_validmap; /* same as WeightPaintData.vgroup_validmap, + * only added here for convenience */ char do_flip; char do_multipaint; @@ -1486,7 +1483,7 @@ typedef struct WeightPaintInfo { /* fresh start to make multi-paint and locking modular */ /* returns TRUE if it thinks you need to reset the weights due to * normalizing while multi-painting */ -static int apply_mp_locks_normalize(Mesh *me, WeightPaintInfo *wpi, +static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi, const int index, MDeformWeight *dw, MDeformWeight *tdw, float change, float oldChange, @@ -1512,7 +1509,7 @@ static int apply_mp_locks_normalize(Mesh *me, WeightPaintInfo *wpi, } clamp_weights(dv); - enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->lock_flags, wpi->vgroup_validmap, wpi->vgroup_validmap); + enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->lock_flags, wpi->vgroup_validmap); do_weight_paint_auto_normalize_all_groups(dv, wpi->vgroup_validmap); @@ -1554,9 +1551,8 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *defbase_s static char *wpaint_make_validmap(Object *ob); -// int flip, int vgroup_mirror, char *validmap, int multipaint static void do_weight_paint_vertex( /* vars which remain the same for every vert */ - VPaint *wp, Object *ob, WeightPaintInfo *wpi, + VPaint *wp, Object *ob, const WeightPaintInfo *wpi, /* vars which change on each stroke */ int index, float alpha, float paintweight ) @@ -1609,11 +1605,6 @@ static void do_weight_paint_vertex( /* vars which remain the same for every vert MDeformWeight *tdw = NULL, *tuw; MDeformVert dv= {NULL}; - /* Need to know which groups are bone groups */ - if(wpi->bone_groups == NULL) { - wpi->bone_groups= wpi->vgroup_validmap ? wpi->vgroup_validmap : wpaint_make_validmap(ob); - } - oldw = dw->weight; wpaint_blend(wp, dw, uw, alpha, paintweight, wpi->do_flip, wpi->do_multipaint && wpi->defbase_tot_sel >1); neww = dw->weight; @@ -1644,12 +1635,12 @@ static void do_weight_paint_vertex( /* vars which remain the same for every vert testw = tuw->weight*change; if( testw > tuw->weight ) { if(change > oldChange) { - // reset the weights and use the new change + /* reset the weights and use the new change */ reset_to_prev(wp->wpaint_prev+index, me->dvert+index); } else { - // the old change was more significant, - // so set the change to 0 so that it will not do another multi-paint + /* the old change was more significant, so set + * the change to 0 so that it will not do another multi-paint */ change = 0; } } @@ -1792,7 +1783,7 @@ static char *wpaint_make_validmap(Object *ob) { bDeformGroup *dg; ModifierData *md; - char *validmap; + char *vgroup_validmap; GHash *gh = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "wpaint_make_validmap gh"); int i = 0, step1=1; @@ -1804,7 +1795,7 @@ static char *wpaint_make_validmap(Object *ob) if (!i) return NULL; - validmap = MEM_callocN(i, "wpaint valid map"); + vgroup_validmap= MEM_callocN(i, "wpaint valid map"); /*now loop through the armature modifiers and identify deform bones*/ for (md = ob->modifiers.first; md; md= !md->next && step1 ? (step1=0), modifiers_getVirtualModifierList(ob) : md->next) { @@ -1835,13 +1826,13 @@ static char *wpaint_make_validmap(Object *ob) /*add all names to a hash table*/ for (dg=ob->defbase.first, i=0; dg; dg=dg->next, i++) { if (BLI_ghash_lookup(gh, dg->name) != NULL) { - validmap[i] = 1; + vgroup_validmap[i] = TRUE; } } BLI_ghash_free(gh, NULL, NULL); - return validmap; + return vgroup_validmap; } static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) @@ -1875,7 +1866,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED /*set up auto-normalize, and generate map for detecting which vgroups affect deform bones*/ wpd->auto_normalize = ts->auto_normalize; - if (wpd->auto_normalize) + if (wpd->auto_normalize || ts->multipaint) wpd->vgroup_validmap = wpaint_make_validmap(ob); // if(qual & LR_CTRLKEY) { @@ -1983,8 +1974,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P wpi.defbase_tot_unsel= wpi.defbase_tot - wpi.defbase_tot_sel; wpi.vgroup_mirror= wpd->vgroup_mirror; wpi.lock_flags= gen_lock_flags(ob, wpi.defbase_tot); - wpi.vgroup_validmap= wpd->vgroup_validmap; - wpi.bone_groups= NULL; /* initialized on the fly */ + wpi.vgroup_validmap= wpd->vgroup_validmap; wpi.do_flip= RNA_boolean_get(itemptr, "pen_flip"); wpi.do_multipaint= (ts->multipaint != 0); /* *** done setting up WeightPaintInfo *** */ @@ -2106,9 +2096,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P if(wpi.lock_flags) { MEM_freeN(wpi.lock_flags); } - if(wpi.bone_groups && (wpi.bone_groups != wpi.vgroup_validmap)) { - MEM_freeN(wpi.bone_groups); - } MEM_freeN(wpi.defbase_sel); /* *** dont freeing wpi members */ From 94016ed285c351605057929139caf9b636b179b6 Mon Sep 17 00:00:00 2001 From: Jason Hays Date: Mon, 19 Sep 2011 15:11:01 +0000 Subject: [PATCH 68/68] vgroup_validmap needed to be assigned when locks were active. --- .../editors/sculpt_paint/paint_vertex.c | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 6cda5e07118..fba2f77b40b 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1115,13 +1115,13 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, #endif /* the active group should be involved in auto normalize */ -static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map) +static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map, char do_auto_normalize) { // MDeformWeight *dw = dvert->dw; float sum=0.0f, fac=0.0f; int i, tot=0; - if (!map) + if (do_auto_normalize == FALSE) return; for (i=0; itotweight; i++) { @@ -1242,7 +1242,7 @@ static void multipaint_selection(MDeformVert *dvert, float change, char *defbase // move all change onto valid, unchanged groups. If there is change left over, then return it. // assumes there are valid groups to shift weight onto -static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, const char *vgroup_validmap, float totchange, float total_valid) { +static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, const char *vgroup_validmap, float totchange, float total_valid, char do_auto_normalize) { float was_change; float change; float oldval; @@ -1259,7 +1259,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan if(change_status[ndw->def_nr] == changeme) { oldval = ndw->weight; // if auto normalize is active, don't worry about upper bounds - if(!vgroup_validmap && ndw->weight + change > 1) { + if(do_auto_normalize == FALSE && ndw->weight + change > 1) { totchange -= 1-ndw->weight; ndw->weight = 1; // stop the changes to this group @@ -1290,7 +1290,7 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan // make sure all locked groups on the vertex have the same deformation // by moving the changes made to groups onto other unlocked groups static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, - const char *lock_flags, const char *vgroup_validmap) + const char *lock_flags, const char *vgroup_validmap, char do_auto_normalize) { float totchange = 0.0f; float totchange_allowed = 0.0f; @@ -1378,7 +1378,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, totchange_allowed = -totchange; } // move the weight evenly between the allowed groups, move excess back onto the used groups based on the change - totchange_allowed = redistribute_change(ndv, change_status, 1, -1, vgroup_validmap, totchange_allowed, total_valid); + totchange_allowed = redistribute_change(ndv, change_status, 1, -1, vgroup_validmap, totchange_allowed, total_valid, do_auto_normalize); left_over += totchange_allowed; if(left_over) { // more than one nonzero weights were changed with the same ratio, so keep them changed that way! @@ -1402,7 +1402,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, // a weight was changed to zero, only one weight was changed, or designatedw is still -1 // put weight back as evenly as possible else { - redistribute_change(ndv, change_status, 2, -2, vgroup_validmap, left_over, total_changed); + redistribute_change(ndv, change_status, 2, -2, vgroup_validmap, left_over, total_changed, do_auto_normalize); } } } @@ -1478,6 +1478,7 @@ typedef struct WeightPaintInfo { char do_flip; char do_multipaint; + char do_auto_normalize; } WeightPaintInfo; /* fresh start to make multi-paint and locking modular */ @@ -1509,9 +1510,9 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi, } clamp_weights(dv); - enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->lock_flags, wpi->vgroup_validmap); + enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->lock_flags, wpi->vgroup_validmap, wpi->do_auto_normalize); - do_weight_paint_auto_normalize_all_groups(dv, wpi->vgroup_validmap); + do_weight_paint_auto_normalize_all_groups(dv, wpi->vgroup_validmap, wpi->do_auto_normalize); if(oldChange && wpi->do_multipaint && wpi->defbase_tot_sel > 1) { if(tdw->weight != oldw) { @@ -1580,7 +1581,7 @@ static void do_weight_paint_vertex( /* vars which remain the same for every vert * then there is no need to run the more complicated checks */ if((wpi->do_multipaint == FALSE || wpi->defbase_tot_sel <= 1) && (wpi->lock_flags == NULL || has_locked_group(&me->dvert[index], wpi->lock_flags) == FALSE)) { wpaint_blend(wp, dw, uw, alpha, paintweight, wpi->do_flip, FALSE); - do_weight_paint_auto_normalize_all_groups(me->dvert+index, wpi->vgroup_validmap); + do_weight_paint_auto_normalize_all_groups(me->dvert+index, wpi->vgroup_validmap, wpi->do_auto_normalize); if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ int j= mesh_get_x_mirror_vert(ob, index); @@ -1590,7 +1591,7 @@ static void do_weight_paint_vertex( /* vars which remain the same for every vert uw->weight= dw->weight; - do_weight_paint_auto_normalize_all_groups(me->dvert+j, wpi->vgroup_validmap); + do_weight_paint_auto_normalize_all_groups(me->dvert+j, wpi->vgroup_validmap, wpi->do_auto_normalize); } } } @@ -1777,6 +1778,8 @@ struct WPaintData { /*variables for auto normalize*/ int auto_normalize; char *vgroup_validmap; /*stores if vgroups tie to deforming bones or not*/ + char *lock_flags; + int defbase_tot; }; static char *wpaint_make_validmap(Object *ob) @@ -1866,7 +1869,9 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED /*set up auto-normalize, and generate map for detecting which vgroups affect deform bones*/ wpd->auto_normalize = ts->auto_normalize; - if (wpd->auto_normalize || ts->multipaint) + wpd->defbase_tot = BLI_countlist(&ob->defbase); + wpd->lock_flags = gen_lock_flags(ob, wpd->defbase_tot); + if (wpd->auto_normalize || ts->multipaint || wpd->lock_flags) wpd->vgroup_validmap = wpaint_make_validmap(ob); // if(qual & LR_CTRLKEY) { @@ -1967,16 +1972,17 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P /* *** setup WeightPaintInfo - pass onto do_weight_paint_vertex *** */ - wpi.defbase_tot= BLI_countlist(&ob->defbase); + wpi.defbase_tot= wpd->defbase_tot; wpi.defbase_sel= MEM_mallocN(wpi.defbase_tot*sizeof(char), "wpi.defbase_sel"); wpi.defbase_tot_sel= get_selected_defgroups(ob, wpi.defbase_sel, wpi.defbase_tot); if(wpi.defbase_tot_sel == 0 && ob->actdef) wpi.defbase_tot_sel = 1; wpi.defbase_tot_unsel= wpi.defbase_tot - wpi.defbase_tot_sel; wpi.vgroup_mirror= wpd->vgroup_mirror; - wpi.lock_flags= gen_lock_flags(ob, wpi.defbase_tot); + wpi.lock_flags= wpd->lock_flags; wpi.vgroup_validmap= wpd->vgroup_validmap; wpi.do_flip= RNA_boolean_get(itemptr, "pen_flip"); wpi.do_multipaint= (ts->multipaint != 0); + wpi.do_auto_normalize= (ts->auto_normalize != 0); /* *** done setting up WeightPaintInfo *** */ @@ -2093,9 +2099,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P /* *** free wpi members */ - if(wpi.lock_flags) { - MEM_freeN(wpi.lock_flags); - } MEM_freeN(wpi.defbase_sel); /* *** dont freeing wpi members */ @@ -2119,7 +2122,9 @@ static void wpaint_stroke_done(bContext *C, struct PaintStroke *stroke) if (wpd->vgroup_validmap) MEM_freeN(wpd->vgroup_validmap); - + if(wpd->lock_flags) + MEM_freeN(wpd->lock_flags); + MEM_freeN(wpd); }