forked from bartvdbraak/blender
use bool arrays rather then char for weight paint lock/select arrays
This commit is contained in:
parent
e1229b2978
commit
65dcc6ad4f
@ -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_normalize(struct MDeformVert *dvert);
|
||||
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
|
||||
* used with defgroups currently */
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
struct Object;
|
||||
|
||||
char *BKE_objdef_lock_flags_get(struct Object *ob, const int defbase_tot);
|
||||
char *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_lock_flags_get(struct Object *ob, const int defbase_tot);
|
||||
bool *BKE_objdef_validmap_get(struct Object *ob, const int defbase_tot);
|
||||
bool *BKE_objdef_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot);
|
||||
|
||||
#endif /* __BKE_OBJECT_DEFORM_H__ */
|
||||
|
@ -1066,7 +1066,7 @@ static void calc_weightpaint_vert_color(
|
||||
MDeformVert *dv,
|
||||
DMWeightColorInfo *dm_wcinfo,
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
int defbase_sel_tot = 0;
|
||||
char *defbase_sel = NULL;
|
||||
bool *defbase_sel = NULL;
|
||||
|
||||
if (draw_flag & CALC_WP_MULTIPAINT) {
|
||||
defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot);
|
||||
|
@ -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) {
|
||||
/* nothing */
|
||||
|
@ -45,12 +45,12 @@
|
||||
* gets the status of "flag" for each bDeformGroup
|
||||
* 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 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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
|
||||
bool *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
|
||||
{
|
||||
bDeformGroup *dg;
|
||||
ModifierData *md;
|
||||
char *vgroup_validmap;
|
||||
bool *vgroup_validmap;
|
||||
GHash *gh;
|
||||
int i, step1 = 1;
|
||||
//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,
|
||||
* 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;
|
||||
unsigned int i;
|
||||
Object *armob = BKE_object_pose_armature_get(ob);
|
||||
|
@ -1528,7 +1528,7 @@ static void vgroup_normalize_all(Object *ob, const bool lock_active)
|
||||
|
||||
if (dvert_array) {
|
||||
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) &&
|
||||
(lock_flags != NULL) &&
|
||||
@ -1809,7 +1809,7 @@ static bool vertex_group_limit_total(Object *ob,
|
||||
|
||||
if (dvert_array) {
|
||||
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) :
|
||||
NULL;
|
||||
int num_to_drop = 0;
|
||||
|
@ -1288,7 +1288,7 @@ void PAINT_OT_weight_sample_group(wmOperatorType *ot)
|
||||
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;
|
||||
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,
|
||||
* 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)
|
||||
{
|
||||
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
|
||||
*/
|
||||
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;
|
||||
MDeformWeight *dw;
|
||||
@ -1406,20 +1406,21 @@ static char has_locked_group(MDeformVert *dvert, const int defbase_tot,
|
||||
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;
|
||||
for (i = 0; i < defbase_tot; i++) {
|
||||
if (defbase_sel[i] && lock_flags[i]) {
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#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;
|
||||
if (defbase_tot == selected) {
|
||||
@ -1435,7 +1436,7 @@ static int has_unselected_unlocked_bone_group(int defbase_tot, char *defbase_sel
|
||||
#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;
|
||||
MDeformWeight *dw;
|
||||
@ -1529,13 +1530,13 @@ static float redistribute_change(MDeformVert *ndv, const int defbase_tot,
|
||||
/* left overs */
|
||||
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.
|
||||
* 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,
|
||||
const int defbase_tot, const char *defbase_sel,
|
||||
const char *lock_flags, const char *vgroup_validmap,
|
||||
const int defbase_tot, const bool *defbase_sel,
|
||||
const bool *lock_flags, const bool *vgroup_validmap,
|
||||
char do_auto_normalize, char do_multipaint)
|
||||
{
|
||||
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 */
|
||||
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;
|
||||
unsigned int i;
|
||||
@ -1702,12 +1703,12 @@ typedef struct WeightPaintInfo {
|
||||
int vgroup_active; /* (ob->actdef - 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 */
|
||||
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 */
|
||||
|
||||
const char *vgroup_validmap; /* same as WeightPaintData.vgroup_validmap,
|
||||
const bool *vgroup_validmap; /* same as WeightPaintData.vgroup_validmap,
|
||||
* only added here for convenience */
|
||||
|
||||
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
|
||||
* !lock_flags[dw->def_nr] helps if nothing is selected, but active group is locked */
|
||||
if ((wpi->lock_flags == NULL) ||
|
||||
((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))
|
||||
((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))
|
||||
{
|
||||
if (wpi->do_multipaint && wpi->defbase_tot_sel > 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
|
||||
* 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;
|
||||
MDeformWeight *dw = dvert->dw;
|
||||
@ -2138,8 +2139,8 @@ struct WPaintData {
|
||||
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;
|
||||
const bool *vgroup_validmap; /* stores if vgroups tie to deforming bones or not */
|
||||
const bool *lock_flags;
|
||||
int defbase_tot;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user