use bool arrays rather then char for weight paint lock/select arrays

This commit is contained in:
2013-05-15 15:52:48 +00:00
parent e1229b2978
commit 65dcc6ad4f
7 changed files with 37 additions and 36 deletions

View File

@@ -74,7 +74,7 @@ void defvert_flip(struct MDeformVert *dvert, const int *flip_map, const int flip
void defvert_flip_merged(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len); void defvert_flip_merged(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len);
void defvert_normalize(struct MDeformVert *dvert); void defvert_normalize(struct MDeformVert *dvert);
void defvert_normalize_lock_single(struct MDeformVert *dvert, const int def_nr_lock); void defvert_normalize_lock_single(struct MDeformVert *dvert, const int def_nr_lock);
void defvert_normalize_lock_map(struct MDeformVert *dvert, const char *lock_flags, const int defbase_tot); void defvert_normalize_lock_map(struct MDeformVert *dvert, const bool *lock_flags, const int defbase_tot);
/* utility function, note that MAX_VGROUP_NAME chars is the maximum string length since its only /* utility function, note that MAX_VGROUP_NAME chars is the maximum string length since its only
* used with defgroups currently */ * used with defgroups currently */

View File

@@ -31,8 +31,8 @@
struct Object; struct Object;
char *BKE_objdef_lock_flags_get(struct Object *ob, const int defbase_tot); bool *BKE_objdef_lock_flags_get(struct Object *ob, const int defbase_tot);
char *BKE_objdef_validmap_get(struct Object *ob, const int defbase_tot); bool *BKE_objdef_validmap_get(struct Object *ob, const int defbase_tot);
char *BKE_objdef_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot); bool *BKE_objdef_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot);
#endif /* __BKE_OBJECT_DEFORM_H__ */ #endif /* __BKE_OBJECT_DEFORM_H__ */

View File

@@ -1066,7 +1066,7 @@ static void calc_weightpaint_vert_color(
MDeformVert *dv, MDeformVert *dv,
DMWeightColorInfo *dm_wcinfo, DMWeightColorInfo *dm_wcinfo,
const int defbase_tot, const int defbase_act, const int defbase_tot, const int defbase_act,
const char *defbase_sel, const int defbase_sel_tot, const bool *defbase_sel, const int defbase_sel_tot,
const int draw_flag) const int draw_flag)
{ {
float input = 0.0f; float input = 0.0f;
@@ -1154,7 +1154,7 @@ static void calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const d
const int defbase_act = ob->actdef - 1; const int defbase_act = ob->actdef - 1;
int defbase_sel_tot = 0; int defbase_sel_tot = 0;
char *defbase_sel = NULL; bool *defbase_sel = NULL;
if (draw_flag & CALC_WP_MULTIPAINT) { if (draw_flag & CALC_WP_MULTIPAINT) {
defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot); defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot);

View File

@@ -254,7 +254,7 @@ void defvert_normalize_lock_single(MDeformVert *dvert, const int def_nr_lock)
} }
} }
void defvert_normalize_lock_map(MDeformVert *dvert, const char *lock_flags, const int defbase_tot) void defvert_normalize_lock_map(MDeformVert *dvert, const bool *lock_flags, const int defbase_tot)
{ {
if (dvert->totweight <= 0) { if (dvert->totweight <= 0) {
/* nothing */ /* nothing */

View File

@@ -45,12 +45,12 @@
* gets the status of "flag" for each bDeformGroup * gets the status of "flag" for each bDeformGroup
* in ob->defbase and returns an array containing them * in ob->defbase and returns an array containing them
*/ */
char *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot) bool *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot)
{ {
char is_locked = FALSE; bool is_locked = false;
int i; int i;
//int defbase_tot = BLI_countlist(&ob->defbase); //int defbase_tot = BLI_countlist(&ob->defbase);
char *lock_flags = MEM_mallocN(defbase_tot * sizeof(char), "defflags"); bool *lock_flags = MEM_mallocN(defbase_tot * sizeof(bool), "defflags");
bDeformGroup *defgroup; bDeformGroup *defgroup;
for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) {
@@ -65,11 +65,11 @@ char *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot)
return NULL; return NULL;
} }
char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot) bool *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
{ {
bDeformGroup *dg; bDeformGroup *dg;
ModifierData *md; ModifierData *md;
char *vgroup_validmap; bool *vgroup_validmap;
GHash *gh; GHash *gh;
int i, step1 = 1; int i, step1 = 1;
//int defbase_tot = BLI_countlist(&ob->defbase); //int defbase_tot = BLI_countlist(&ob->defbase);
@@ -127,9 +127,9 @@ char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
/* Returns total selected vgroups, /* Returns total selected vgroups,
* wpi.defbase_sel is assumed malloc'd, all values are set */ * wpi.defbase_sel is assumed malloc'd, all values are set */
char *BKE_objdef_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot) bool *BKE_objdef_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
{ {
char *dg_selection = MEM_mallocN(defbase_tot * sizeof(char), __func__); bool *dg_selection = MEM_mallocN(defbase_tot * sizeof(bool), __func__);
bDeformGroup *defgroup; bDeformGroup *defgroup;
unsigned int i; unsigned int i;
Object *armob = BKE_object_pose_armature_get(ob); Object *armob = BKE_object_pose_armature_get(ob);

View File

@@ -1528,7 +1528,7 @@ static void vgroup_normalize_all(Object *ob, const bool lock_active)
if (dvert_array) { if (dvert_array) {
const int defbase_tot = BLI_countlist(&ob->defbase); const int defbase_tot = BLI_countlist(&ob->defbase);
char *lock_flags = BKE_objdef_lock_flags_get(ob, defbase_tot); bool *lock_flags = BKE_objdef_lock_flags_get(ob, defbase_tot);
if ((lock_active == true) && if ((lock_active == true) &&
(lock_flags != NULL) && (lock_flags != NULL) &&
@@ -1809,7 +1809,7 @@ static bool vertex_group_limit_total(Object *ob,
if (dvert_array) { if (dvert_array) {
int defbase_tot = BLI_countlist(&ob->defbase); int defbase_tot = BLI_countlist(&ob->defbase);
const char *vgroup_validmap = (all_deform_weights == false) ? const bool *vgroup_validmap = (all_deform_weights == false) ?
BKE_objdef_validmap_get(ob, defbase_tot) : BKE_objdef_validmap_get(ob, defbase_tot) :
NULL; NULL;
int num_to_drop = 0; int num_to_drop = 0;

View File

@@ -1288,7 +1288,7 @@ void PAINT_OT_weight_sample_group(wmOperatorType *ot)
ot->prop = prop; ot->prop = prop;
} }
static void do_weight_paint_normalize_all(MDeformVert *dvert, const int defbase_tot, const char *vgroup_validmap) static void do_weight_paint_normalize_all(MDeformVert *dvert, const int defbase_tot, const bool *vgroup_validmap)
{ {
float sum = 0.0f, fac; float sum = 0.0f, fac;
unsigned int i, tot = 0; unsigned int i, tot = 0;
@@ -1330,7 +1330,7 @@ static void do_weight_paint_normalize_all(MDeformVert *dvert, const int defbase_
* *
* note that the active is just the group which is unchanged, it can be any, * note that the active is just the group which is unchanged, it can be any,
* can also be -1 to normalize all but in that case call 'do_weight_paint_normalize_all' */ * can also be -1 to normalize all but in that case call 'do_weight_paint_normalize_all' */
static void do_weight_paint_normalize_all_active(MDeformVert *dvert, const int defbase_tot, const char *vgroup_validmap, static void do_weight_paint_normalize_all_active(MDeformVert *dvert, const int defbase_tot, const bool *vgroup_validmap,
const int vgroup_active) const int vgroup_active)
{ {
float sum = 0.0f, fac; float sum = 0.0f, fac;
@@ -1391,7 +1391,7 @@ static void do_weight_paint_normalize_all_active(MDeformVert *dvert, const int d
* See if the current deform vertex has a locked group * See if the current deform vertex has a locked group
*/ */
static char has_locked_group(MDeformVert *dvert, const int defbase_tot, static char has_locked_group(MDeformVert *dvert, const int defbase_tot,
const char *bone_groups, const char *lock_flags) const bool *bone_groups, const bool *lock_flags)
{ {
int i; int i;
MDeformWeight *dw; MDeformWeight *dw;
@@ -1406,20 +1406,21 @@ static char has_locked_group(MDeformVert *dvert, const int defbase_tot,
return FALSE; return FALSE;
} }
static int has_locked_group_selected(int defbase_tot, const char *defbase_sel, const char *lock_flags) static bool has_locked_group_selected(int defbase_tot, const bool *defbase_sel, const bool *lock_flags)
{ {
int i; int i;
for (i = 0; i < defbase_tot; i++) { for (i = 0; i < defbase_tot; i++) {
if (defbase_sel[i] && lock_flags[i]) { if (defbase_sel[i] && lock_flags[i]) {
return TRUE; return true;
} }
} }
return FALSE; return false;
} }
#if 0 /* UNUSED */ #if 0 /* UNUSED */
static int has_unselected_unlocked_bone_group(int defbase_tot, char *defbase_sel, int selected, char *lock_flags, char *vgroup_validmap) static int has_unselected_unlocked_bone_group(int defbase_tot, bool *defbase_sel, int selected,
const bool *lock_flags, const bool *vgroup_validmap)
{ {
int i; int i;
if (defbase_tot == selected) { if (defbase_tot == selected) {
@@ -1435,7 +1436,7 @@ static int has_unselected_unlocked_bone_group(int defbase_tot, char *defbase_sel
#endif #endif
static void multipaint_selection(MDeformVert *dvert, const int defbase_tot, float change, const char *defbase_sel) static void multipaint_selection(MDeformVert *dvert, const int defbase_tot, float change, const bool *defbase_sel)
{ {
int i; int i;
MDeformWeight *dw; MDeformWeight *dw;
@@ -1529,13 +1530,13 @@ static float redistribute_change(MDeformVert *ndv, const int defbase_tot,
/* left overs */ /* left overs */
return totchange; return totchange;
} }
static float get_mp_change(MDeformVert *odv, const int defbase_tot, const char *defbase_sel, float brush_change); static float get_mp_change(MDeformVert *odv, const int defbase_tot, const bool *defbase_sel, float brush_change);
/* observe the changes made to the weights of groups. /* observe the changes made to the weights of groups.
* make sure all locked groups on the vertex have the same deformation * make sure all locked groups on the vertex have the same deformation
* by moving the changes made to groups onto other unlocked groups */ * by moving the changes made to groups onto other unlocked groups */
static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, static void enforce_locks(MDeformVert *odv, MDeformVert *ndv,
const int defbase_tot, const char *defbase_sel, const int defbase_tot, const bool *defbase_sel,
const char *lock_flags, const char *vgroup_validmap, const bool *lock_flags, const bool *vgroup_validmap,
char do_auto_normalize, char do_multipaint) char do_auto_normalize, char do_multipaint)
{ {
float totchange = 0.0f; float totchange = 0.0f;
@@ -1645,7 +1646,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv,
} }
/* multi-paint's initial, potential change is computed here based on the user's stroke */ /* multi-paint's initial, potential change is computed here based on the user's stroke */
static float get_mp_change(MDeformVert *odv, const int defbase_tot, const char *defbase_sel, float brush_change) static float get_mp_change(MDeformVert *odv, const int defbase_tot, const bool *defbase_sel, float brush_change)
{ {
float selwsum = 0.0f; float selwsum = 0.0f;
unsigned int i; unsigned int i;
@@ -1702,12 +1703,12 @@ typedef struct WeightPaintInfo {
int vgroup_active; /* (ob->actdef - 1) */ int vgroup_active; /* (ob->actdef - 1) */
int vgroup_mirror; /* mirror group or -1 */ int vgroup_mirror; /* mirror group or -1 */
const char *lock_flags; /* boolean array for locked bones, const bool *lock_flags; /* boolean array for locked bones,
* length of defbase_tot */ * length of defbase_tot */
const char *defbase_sel; /* boolean array for selected bones, const bool *defbase_sel; /* boolean array for selected bones,
* length of defbase_tot, cant be const because of how its passed */ * length of defbase_tot, cant be const because of how its passed */
const char *vgroup_validmap; /* same as WeightPaintData.vgroup_validmap, const bool *vgroup_validmap; /* same as WeightPaintData.vgroup_validmap,
* only added here for convenience */ * only added here for convenience */
char do_flip; char do_flip;
@@ -1738,8 +1739,8 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi,
/* do not multi-paint if a locked group is selected or the active group is locked /* 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 */ * !lock_flags[dw->def_nr] helps if nothing is selected, but active group is locked */
if ((wpi->lock_flags == NULL) || if ((wpi->lock_flags == NULL) ||
((wpi->lock_flags[dw->def_nr] == FALSE) && /* def_nr range has to be checked for by caller */ ((wpi->lock_flags[dw->def_nr] == false) && /* def_nr range has to be checked for by caller */
has_locked_group_selected(wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags) == 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 (wpi->do_multipaint && wpi->defbase_tot_sel > 1) {
if (change && change != 1) { if (change && change != 1) {
@@ -1781,7 +1782,7 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi,
/* within the current dvert index, get the dw that is selected and has a weight /* within the current dvert index, get the dw that is selected and has a weight
* above 0, this helps multi-paint */ * above 0, this helps multi-paint */
static int get_first_selected_nonzero_weight(MDeformVert *dvert, const int defbase_tot, const char *defbase_sel) static int get_first_selected_nonzero_weight(MDeformVert *dvert, const int defbase_tot, const bool *defbase_sel)
{ {
int i; int i;
MDeformWeight *dw = dvert->dw; MDeformWeight *dw = dvert->dw;
@@ -2138,8 +2139,8 @@ struct WPaintData {
float wpimat[3][3]; float wpimat[3][3];
/* variables for auto normalize */ /* variables for auto normalize */
const char *vgroup_validmap; /* stores if vgroups tie to deforming bones or not */ const bool *vgroup_validmap; /* stores if vgroups tie to deforming bones or not */
const char *lock_flags; const bool *lock_flags;
int defbase_tot; int defbase_tot;
}; };