diff options
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 30 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 1 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 73 |
3 files changed, 45 insertions, 59 deletions
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 7c13ca388e0..3f400155f7b 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -34,6 +34,7 @@ #include <math.h> #include <ctype.h> #include <stdlib.h> +#include <stddef.h> #include "MEM_guardedalloc.h" @@ -337,37 +338,12 @@ void defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int flip bDeformGroup *defgroup_find_name(Object *ob, const char *name) { - /* return a pointer to the deform group with this name - * or return NULL otherwise. - */ - bDeformGroup *curdef; - - for (curdef = ob->defbase.first; curdef; curdef = curdef->next) { - if (!strcmp(curdef->name, name)) { - return curdef; - } - } - return NULL; + return BLI_findstring(&ob->defbase, name, offsetof(bDeformGroup, name)); } int defgroup_name_index(Object *ob, const char *name) { - /* Return the location of the named deform group within the list of - * deform groups. This function is a combination of BLI_findlink and - * defgroup_find_name. The other two could be called instead, but that - * require looping over the vertexgroups twice. - */ - bDeformGroup *curdef; - int def_nr; - - if (name && name[0] != '\0') { - for (curdef = ob->defbase.first, def_nr = 0; curdef; curdef = curdef->next, def_nr++) { - if (!strcmp(curdef->name, name)) - return def_nr; - } - } - - return -1; + return BLI_findstringindex(&ob->defbase, name, offsetof(bDeformGroup, name)); } /* note, must be freed */ diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 9ebeb61a7bb..2f4115dcd94 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -416,6 +416,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) if (!stroke->stroke_started) { copy_v2_v2(stroke->last_mouse_position, sample_average.mouse); stroke->stroke_started = stroke->test_start(C, op, sample_average.mouse); + BLI_assert((stroke->stroke_started & ~1) == 0); /* 0/1 */ if (stroke->stroke_started) { stroke->smooth_stroke_cursor = diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index bc1d0cd2f69..0ad7d144496 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -372,31 +372,22 @@ static int wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active) bDeformGroup *defgroup = BLI_findlink(&ob->defbase, vgroup_active); if (defgroup) { - bDeformGroup *curdef; int mirrdef; char name[MAXBONENAME]; flip_side_name(name, defgroup->name, FALSE); - - if (strcmp(name, defgroup->name) != 0) { - for (curdef = ob->defbase.first, mirrdef = 0; curdef; curdef = curdef->next, mirrdef++) { - if (!strcmp(curdef->name, name)) { - break; - } - } - - if (curdef == NULL) { - int olddef = ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */ - curdef = ED_vgroup_add_name(ob, name); - ob->actdef = olddef; - } - - /* curdef should never be NULL unless this is - * a lamp and ED_vgroup_add_name fails */ - if (curdef) { - return mirrdef; + mirrdef = defgroup_name_index(ob, name); + if (mirrdef == -1) { + int olddef = ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */ + if (ED_vgroup_add_name(ob, name)) { + mirrdef = BLI_countlist(&ob->defbase) - 1; } + ob->actdef = olddef; } + + /* curdef should never be NULL unless this is + * a lamp and ED_vgroup_add_name fails */ + return mirrdef; } return -1; @@ -2061,32 +2052,29 @@ struct WPaintData { int vgroup_mirror; DMCoNo *vertexcosnos; float wpimat[3][3]; - + /* variables for auto normalize */ const char *vgroup_validmap; /* stores if vgroups tie to deforming bones or not */ const char *lock_flags; int defbase_tot; }; -static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNUSED(mouse[2])) +/* ensure we have data on wpaint start, add if needed */ +static int wpaint_ensure_data(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); - struct PaintStroke *stroke = op->customdata; - ToolSettings *ts = scene->toolsettings; - VPaint *wp = ts->wpaint; Object *ob = CTX_data_active_object(C); - struct WPaintData *wpd; - Mesh *me; + Mesh *me = BKE_mesh_from_object(ob); - float mat[4][4], imat[4][4]; - if (scene->obedit) { return FALSE; } - + me = BKE_mesh_from_object(ob); - if (me == NULL || me->totpoly == 0) return OPERATOR_PASS_THROUGH; - + if (me == NULL || me->totpoly == 0) { + return FALSE; + } + /* if nothing was added yet, we make dverts and a vertex deform group */ if (!me->dvert) { ED_vgroup_data_create(&me->id); @@ -2125,6 +2113,25 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNU return FALSE; } + return TRUE; +} + +static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNUSED(mouse[2])) +{ + Scene *scene = CTX_data_scene(C); + struct PaintStroke *stroke = op->customdata; + ToolSettings *ts = scene->toolsettings; + VPaint *wp = ts->wpaint; + Object *ob = CTX_data_active_object(C); + Mesh *me = BKE_mesh_from_object(ob); + struct WPaintData *wpd; + + float mat[4][4], imat[4][4]; + + if (wpaint_ensure_data(C, op) == FALSE) { + return FALSE; + } + { /* check if we are attempting to paint onto a locked vertex group, * and other options disallow it from doing anything useful */ @@ -3208,7 +3215,9 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) static int paint_weight_gradient_invoke(bContext *C, wmOperator *op, wmEvent *event) { - int ret = WM_gesture_straightline_invoke(C, op, event); + int ret; + + ret = WM_gesture_straightline_invoke(C, op, event); if (ret & OPERATOR_RUNNING_MODAL) { struct ARegion *ar = CTX_wm_region(C); if (ar->regiontype == RGN_TYPE_WINDOW) { |