code cleanup: move get_selected_defgroups into object_deform.c and make it behave like similar functions, also when drawing vertex weight colors, only call this function when multi-paint is enabled.
This commit is contained in:
@@ -101,8 +101,6 @@ void get_objectspace_bone_matrix(struct Bone *bone, float M_accumulatedMatrix[][
|
||||
void vec_roll_to_mat3(const float vec[3], const float roll, float mat[][3]);
|
||||
void mat3_to_vec_roll(float mat[][3], float *vec, float *roll);
|
||||
|
||||
int get_selected_defgroups(struct Object *ob, char *defbase_sel, int defbase_len);
|
||||
|
||||
/* Common Conversions Between Co-ordinate Spaces */
|
||||
void BKE_armature_mat_world_to_pose(struct Object *ob, float inmat[][4], float outmat[][4]);
|
||||
void BKE_armature_loc_world_to_pose(struct Object *ob, const float inloc[3], float outloc[3]);
|
||||
|
@@ -33,5 +33,6 @@ 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);
|
||||
|
||||
#endif /* __BKE_OBJECT_DEFORM_H__ */
|
||||
|
@@ -59,6 +59,7 @@
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_object_deform.h"
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_multires.h"
|
||||
@@ -1015,14 +1016,14 @@ static void calc_weightpaint_vert_color(
|
||||
unsigned char r_col[4],
|
||||
MDeformVert *dv, ColorBand *coba,
|
||||
const int defbase_tot, const int defbase_act,
|
||||
const char *dg_flags,
|
||||
const int selected, const int draw_flag)
|
||||
const char *defbase_sel, const int defbase_sel_tot,
|
||||
const int draw_flag)
|
||||
{
|
||||
float input = 0.0f;
|
||||
|
||||
int make_black = FALSE;
|
||||
|
||||
if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) {
|
||||
if ((defbase_sel_tot > 1) && (draw_flag & CALC_WP_MULTIPAINT)) {
|
||||
int was_a_nonzero = FALSE;
|
||||
unsigned int i;
|
||||
|
||||
@@ -1031,7 +1032,7 @@ static void calc_weightpaint_vert_color(
|
||||
/* in multipaint, get the average if auto normalize is inactive
|
||||
* get the sum if it is active */
|
||||
if (dw->def_nr < defbase_tot) {
|
||||
if (dg_flags[dw->def_nr]) {
|
||||
if (defbase_sel[dw->def_nr]) {
|
||||
if (dw->weight) {
|
||||
input += dw->weight;
|
||||
was_a_nonzero = TRUE;
|
||||
@@ -1045,7 +1046,7 @@ static void calc_weightpaint_vert_color(
|
||||
make_black = TRUE;
|
||||
}
|
||||
else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) {
|
||||
input /= selected; /* get the average */
|
||||
input /= defbase_sel_tot; /* get the average */
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1090,14 +1091,21 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i
|
||||
/* variables for multipaint */
|
||||
const int defbase_tot = BLI_countlist(&ob->defbase);
|
||||
const int defbase_act = ob->actdef - 1;
|
||||
char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__);
|
||||
const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot);
|
||||
|
||||
for (i = numVerts; i != 0; i--, wc += 4, dv++) {
|
||||
calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, dg_flags, selected, draw_flag);
|
||||
int defbase_sel_tot = 0;
|
||||
char *defbase_sel = NULL;
|
||||
|
||||
if (draw_flag & CALC_WP_MULTIPAINT) {
|
||||
defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot);
|
||||
}
|
||||
|
||||
MEM_freeN(dg_flags);
|
||||
for (i = numVerts; i != 0; i--, wc += 4, dv++) {
|
||||
calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag);
|
||||
}
|
||||
|
||||
if (defbase_sel) {
|
||||
MEM_freeN(defbase_sel);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int col_i;
|
||||
|
@@ -2517,36 +2517,6 @@ void BKE_pose_where_is(Scene *scene, Object *ob)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 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_tot)
|
||||
{
|
||||
bDeformGroup *defgroup;
|
||||
unsigned int i;
|
||||
Object *armob = BKE_object_pose_armature_get(ob);
|
||||
int dg_flags_sel_tot = 0;
|
||||
|
||||
if (armob) {
|
||||
bPose *pose = armob->pose;
|
||||
for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) {
|
||||
bPoseChannel *pchan = BKE_pose_channel_find_name(pose, defgroup->name);
|
||||
if (pchan && (pchan->bone->flag & BONE_SELECTED)) {
|
||||
dg_selection[i] = TRUE;
|
||||
dg_flags_sel_tot++;
|
||||
}
|
||||
else {
|
||||
dg_selection[i] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
memset(dg_selection, FALSE, sizeof(char) * defbase_tot);
|
||||
}
|
||||
|
||||
return dg_flags_sel_tot;
|
||||
}
|
||||
|
||||
/************** Bounding box ********************/
|
||||
static int minmax_armature(Object *ob, float r_min[3], float r_max[3])
|
||||
{
|
||||
|
@@ -210,7 +210,9 @@ void defvert_normalize_lock(MDeformVert *dvert, const int def_nr_lock)
|
||||
/* nothing */
|
||||
}
|
||||
else if (dvert->totweight == 1) {
|
||||
dvert->dw[0].weight = 1.0f;
|
||||
if (def_nr_lock != 0) {
|
||||
dvert->dw[0].weight = 1.0f;
|
||||
}
|
||||
}
|
||||
else {
|
||||
MDeformWeight *dw_lock = NULL;
|
||||
|
@@ -23,13 +23,16 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_ghash.h"
|
||||
|
||||
#include "BKE_action.h"
|
||||
#include "BKE_object_deform.h" /* own include */
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_modifier.h"
|
||||
|
||||
#include "DNA_armature_types.h"
|
||||
@@ -121,3 +124,33 @@ char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
|
||||
|
||||
return vgroup_validmap;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
char *dg_selection = MEM_mallocN(defbase_tot * sizeof(char), __func__);
|
||||
bDeformGroup *defgroup;
|
||||
unsigned int i;
|
||||
Object *armob = BKE_object_pose_armature_get(ob);
|
||||
(*r_dg_flags_sel_tot) = 0;
|
||||
|
||||
if (armob) {
|
||||
bPose *pose = armob->pose;
|
||||
for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) {
|
||||
bPoseChannel *pchan = BKE_pose_channel_find_name(pose, defgroup->name);
|
||||
if (pchan && (pchan->bone->flag & BONE_SELECTED)) {
|
||||
dg_selection[i] = TRUE;
|
||||
(*r_dg_flags_sel_tot) += 1;
|
||||
}
|
||||
else {
|
||||
dg_selection[i] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
memset(dg_selection, FALSE, sizeof(char) * defbase_tot);
|
||||
}
|
||||
|
||||
return dg_selection;
|
||||
}
|
||||
|
@@ -2160,7 +2160,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
|
||||
float alpha;
|
||||
float mval[2];
|
||||
int use_vert_sel;
|
||||
char *defbase_sel;
|
||||
|
||||
const float pressure = RNA_float_get(itemptr, "pressure");
|
||||
const float brush_size_pressure = BKE_brush_size_get(scene, brush) * (BKE_brush_use_size_pressure(scene, brush) ? pressure : 1.0f);
|
||||
@@ -2194,12 +2193,13 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
|
||||
|
||||
|
||||
|
||||
|
||||
/* *** setup WeightPaintInfo - pass onto do_weight_paint_vertex *** */
|
||||
wpi.defbase_tot = wpd->defbase_tot;
|
||||
defbase_sel = MEM_mallocN(wpi.defbase_tot * sizeof(char), "wpi.defbase_sel");
|
||||
wpi.defbase_tot_sel = get_selected_defgroups(ob, defbase_sel, wpi.defbase_tot);
|
||||
wpi.defbase_sel = defbase_sel; /* so we can stay const */
|
||||
if (wpi.defbase_tot_sel == 0 && ob->actdef > 0) wpi.defbase_tot_sel = 1;
|
||||
wpi.defbase_sel = BKE_objdef_selected_get(ob, wpi.defbase_tot, &wpi.defbase_tot_sel);
|
||||
if (wpi.defbase_tot_sel == 0 && ob->actdef > 0) {
|
||||
wpi.defbase_tot_sel = 1;
|
||||
}
|
||||
|
||||
wpi.defbase_tot_unsel = wpi.defbase_tot - wpi.defbase_tot_sel;
|
||||
wpi.vgroup_active = wpd->vgroup_active;
|
||||
|
Reference in New Issue
Block a user