GPv3: Weight Paint tools (Draw, Blur, Average, Smear, Sample weight) #118347

Merged
Falk David merged 48 commits from SietseB/blender:gpv3-weight-paint-tools into main 2024-04-25 15:21:26 +02:00
2 changed files with 8 additions and 13 deletions
Showing only changes of commit cfb630d550 - Show all commits

View File

@ -335,7 +335,9 @@ Vector<Vector<MutableDrawingInfo>> retrieve_editable_drawings_per_frame(
BKE_curvemapping_init(toolsettings->gp_sculpt.cur_falloff);
}
/* Get set of unique frame numbers with editable drawings on them. */
/* Get set of unique frame numbers with editable drawings on them.
* Note: we want an ordered list here, so we use `set` from STL, not the unordered Set from
* Blender. */
std::set<int> selected_frames;
Span<const Layer *> layers = grease_pencil.layers();
for (const int layer_i : layers.index_range()) {

View File

@ -35,9 +35,6 @@ namespace blender::ed::greasepencil {
int create_vertex_group_in_object(Object *ob)
SietseB marked this conversation as resolved Outdated

This function does multiple things that are not obvious when looking at its name. It should be split.
This function can take a name and just do:

if (name.is_empty()) {
   /* Create a vertex group with a general name. */
   BKE_object_defgroup_add(&ob);
   return 0;
}
const int def_nr = BKE_object_defgroup_name_index(&ob, name);
if (def_nr == -1) {
   BKE_object_defgroup_add_name(&ob, name);
   return BKE_object_defgroup_active_index_get(&ob) - 1;
}
return def_nr;

Then finding the active bone channel name can be it's own function, e.g. (find_active_bone_channel_name).

This function does multiple things that are not obvious when looking at its name. It should be split. This function can take a `name` and just do: ``` if (name.is_empty()) { /* Create a vertex group with a general name. */ BKE_object_defgroup_add(&ob); return 0; } const int def_nr = BKE_object_defgroup_name_index(&ob, name); if (def_nr == -1) { BKE_object_defgroup_add_name(&ob, name); return BKE_object_defgroup_active_index_get(&ob) - 1; } return def_nr; ``` Then finding the active bone channel name can be it's own function, e.g. (`find_active_bone_channel_name`).
{
int def_nr = 0;
bool named_by_bone = false;
/* Look for an active bone in armature to name the vertex group after. */
Object *ob_armature = BKE_modifiers_is_deformed_by_armature(ob);
if (ob_armature != nullptr) {
@ -48,28 +45,23 @@ int create_vertex_group_in_object(Object *ob)
const int channel_def_nr = BKE_object_defgroup_name_index(ob, pchan->name);
if (channel_def_nr == -1) {
BKE_object_defgroup_add_name(ob, pchan->name);
def_nr = BKE_object_defgroup_active_index_get(ob) - 1;
return (BKE_object_defgroup_active_index_get(ob) - 1);
}
else {
SietseB marked this conversation as resolved Outdated

else after return is unnecessary

else after return is unnecessary
def_nr = channel_def_nr;
return channel_def_nr;
}
named_by_bone = true;
}
}
}
/* Create a vertex group with a general name. */
if (!named_by_bone) {
BKE_object_defgroup_add(ob);
}
BKE_object_defgroup_add(ob);
return def_nr;
return 0;
}
SietseB marked this conversation as resolved
Review

get_bone_deformed_vertex_group_names

`get_bone_deformed_vertex_group_names`
Set<std::string> get_bone_deformed_vertex_groups(Object &object)
{
Set<std::string> bone_deformed_vgroups;
/* Get all vertex group names in the object. */
const ListBase *defbase = BKE_object_defgroup_list(&object);
Set<std::string> defgroups;
@ -78,6 +70,7 @@ Set<std::string> get_bone_deformed_vertex_groups(Object &object)
}
/* Lambda function for finding deforming bones with a name matching a vertex group. */
Set<std::string> bone_deformed_vgroups;
SietseB marked this conversation as resolved Outdated

Would be a bit more readable if this loop was outside the lambda.

Would be a bit more readable if this loop was outside the lambda.
const auto find_pose_channels = [&](ModifierData *md) {
for (; md; md->next) {
if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual)) ||