diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-02-22 08:09:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-02-22 08:09:04 +0400 |
commit | b00c3b801bf07a67b98b604ee834e2d93dff0f39 (patch) | |
tree | cb7c4c4aacdec65b6d5ee2b79891f64bffc34f08 /source/blender/blenkernel/intern | |
parent | 6bac47f8544a6bdc66d439d1d61b4a850d4ad20a (diff) |
new weight paint draw option to display unweighted vertices with the option to check on the active group or all groups.
notes:
- vertices with zero weights are considered the same as vertices outside of a group.
- currently these show black but this can be made a theme color.
- multi-paint overrides this option (noted in description)
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 35 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 21 |
2 files changed, 48 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 8e740075bc6..aa3d52ce9ce 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1017,8 +1017,12 @@ void weight_to_rgb(float r_rgb[3], const float weight) /* draw_flag's for calc_weightpaint_vert_color */ enum { - CALC_WP_MULTIPAINT = (1 << 0), - CALC_WP_AUTO_NORMALIZE = (1 << 1) + /* only one of these should be set, keep first (for easy bit-shifting) */ + CALC_WP_GROUP_USER_ACTIVE = (1 << 1), + CALC_WP_GROUP_USER_ALL = (1 << 2), + + CALC_WP_MULTIPAINT = (1 << 3), + CALC_WP_AUTO_NORMALIZE = (1 << 4) }; static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input) @@ -1050,7 +1054,7 @@ static void calc_weightpaint_vert_color( { float input = 0.0f; - int make_black = FALSE; + bool make_black = false; if ((defbase_sel_tot > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { int was_a_nonzero = FALSE; @@ -1072,7 +1076,7 @@ static void calc_weightpaint_vert_color( /* make it black if the selected groups have no weight on a vertex */ if (was_a_nonzero == FALSE) { - make_black = TRUE; + make_black = true; } else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) { input /= defbase_sel_tot; /* get the average */ @@ -1081,6 +1085,17 @@ static void calc_weightpaint_vert_color( else { /* default, non tricky behavior */ input = defvert_find_weight(dv, defbase_act); + + if (draw_flag & CALC_WP_GROUP_USER_ACTIVE) { + if (input == 0.0f) { + make_black = true; + } + } + else if (draw_flag & CALC_WP_GROUP_USER_ALL) { + if (input == 0.0f) { + make_black = defvert_is_weight_zero(dv, defbase_tot); + } + } } if (make_black) { /* TODO, theme color */ @@ -1138,7 +1153,12 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i } else { int col_i; - weightpaint_color((unsigned char *)&col_i, coba, 0.0f); + if (draw_flag & (CALC_WP_GROUP_USER_ACTIVE | CALC_WP_GROUP_USER_ALL)) { + col_i = 0; + } + else { + weightpaint_color((unsigned char *)&col_i, coba, 0.0f); + } fill_vn_i((int *)wtcol_v, numVerts, col_i); } @@ -1354,8 +1374,11 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt; int sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm); - const int draw_flag = ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | + const int draw_flag = ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : + /* CALC_WP_GROUP_USER_ACTIVE or CALC_WP_GROUP_USER_ALL*/ + (1 << scene->toolsettings->weightuser)) | (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); + /* Generic preview only in object mode! */ const int do_mod_mcol = (ob->mode == OB_MODE_OBJECT); #if 0 /* XXX Will re-enable this when we have global mod stack options. */ diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index de15100de0b..439180e8d76 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -41,14 +41,13 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" -#include "BKE_deform.h" - #include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BKE_deform.h" /* own include */ void defgroup_copy_list(ListBase *outbase, ListBase *inbase) { @@ -787,6 +786,24 @@ int defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert_b) return -1; } +/** + * return true if has no weights + */ +bool defvert_is_weight_zero(const struct MDeformVert *dvert, const int defgroup_tot) +{ + MDeformWeight *dw = dvert->dw; + unsigned int i; + for (i = dvert->totweight; i != 0; i--, dw++) { + if (dw->weight != 0.0f) { + /* check the group is in-range, happens on rare situations */ + if (LIKELY(dw->def_nr < defgroup_tot)) { + return false; + } + } + } + return true; +} + /* -------------------------------------------------------------------- */ /* Defvert Array functions */ |