Fix #44834: Add bone selection icon next to face and vertex selection in weight paint mode

Currently, in weight paint mode, there is an icon for
face and vertex selection mode, but there isn't one
for the default mode where the user can select a bone
in any tool by alt clicking.
This lack of indication might lead to confusion for the users
when they are not able to select a bone by
alt clicking during weight painting.

By adding a bone selection icon when there is a pose
mode armature, we can communicate to the user that:
1. they can select a bone while the bone selection icon is active.
(when they are not in face or vertex selection mode)
2. they have forgot to select an armature when entering
weight paint mode by not showing the bone selection
icon at all when there is no pose mode armature.

When the bone selection icon is inactive,
the user can't select a bone.
(alt clicking selects face and vertex mode's respective element)

When no armature is selected when entering weight paint mode,
the bone selection icon doesn't show up indicating that the user
has forgot to select an armature.
(The user is also unable to select a bone by alt clicking.)

## Selection tool for bone selection mode
Currently, while selection tools exist for face and vertex
selection mode, one doesn't exist for the default mode
(bone selection mode). As the default mode will be getting
a clear indicator that it will function as a bone selection mode,
I added a selection tool entry for the bone selection mode.

Face and vertex selection modes has the shortcut 1 and 2,
so it seemed natural to give bone selection mode the shortcut of 3.

Pull Request: https://projects.blender.org/blender/blender/pulls/115409
This commit is contained in:
Daiki Hashimoto
2023-12-01 13:38:58 +01:00
committed by Christoph Lendenfeld
parent cd6c7c4b23
commit edcac1f48b
4 changed files with 37 additions and 10 deletions

View File

@@ -5260,6 +5260,8 @@ def km_weight_paint(params):
{"properties": [("data_path", 'weight_paint_object.data.use_paint_mask')]}),
("wm.context_toggle", {"type": 'TWO', "value": 'PRESS'},
{"properties": [("data_path", 'weight_paint_object.data.use_paint_mask_vertex')]}),
("wm.context_toggle", {"type": 'THREE', "value": 'PRESS'},
{"properties": [("data_path", 'weight_paint_object.data.use_paint_bone_selection'), ("value", True)]}),
("wm.context_toggle", {"type": 'S', "value": 'PRESS', "shift": True},
{"properties": [("data_path", 'tool_settings.weight_paint.brush.use_smooth_stroke')]}),
op_menu_pie("VIEW3D_MT_wpaint_vgroup_lock_pie", {"type": 'K', "value": 'PRESS'}),

View File

@@ -1654,13 +1654,17 @@ class _defs_texture_paint:
class _defs_weight_paint:
@staticmethod
def poll_select_mask(context):
def poll_select_tools(context):
if context is None:
return True
return VIEW3D_PT_tools_active._tools_select
ob = context.active_object
return (ob and ob.type == 'MESH' and
(ob.data.use_paint_mask or
ob.data.use_paint_mask_vertex))
if (ob and ob.type == 'MESH' and
(ob.data.use_paint_mask or
ob.data.use_paint_mask_vertex)):
return VIEW3D_PT_tools_active._tools_select
elif context.pose_object:
return (_defs_view3d_select.select,)
return ()
@staticmethod
def generate_from_brushes(context):
@@ -3115,11 +3119,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
else ()
),
None,
lambda context: (
VIEW3D_PT_tools_active._tools_select
if _defs_weight_paint.poll_select_mask(context)
else ()
),
_defs_weight_paint.poll_select_tools,
*_tools_annotate,
],
'PAINT_GREASE_PENCIL': [

View File

@@ -22,6 +22,7 @@
#include "BKE_context.hh"
#include "BKE_editmesh.hh"
#include "BKE_layer.h"
#include "BKE_object.hh"
#include "DEG_depsgraph.hh"
@@ -138,6 +139,12 @@ static void uiTemplatePaintModeSelection(uiLayout *layout, bContext *C)
uiLayout *row = uiLayoutRow(layout, true);
uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
/* Show the bone selection mode icon only if there is a pose mode armature */
Object *ob_armature = BKE_object_pose_armature_get(ob);
if (ob_armature) {
uiItemR(row, &meshptr, "use_paint_bone_selection", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
}
}
}
}

View File

@@ -228,6 +228,17 @@ void rna_Mesh_update_draw(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
}
static void rna_Mesh_update_bone_selection_mode(Main *bmain, Scene *scene, PointerRNA *ptr)
{
Mesh *me = static_cast<Mesh *>(ptr->data);
me->editflag &= ~ME_EDIT_PAINT_VERT_SEL;
me->editflag &= ~ME_EDIT_PAINT_FACE_SEL;
BKE_mesh_batch_cache_dirty_tag(me, BKE_MESH_BATCH_DIRTY_ALL);
rna_Mesh_update_draw(bmain, scene, ptr);
}
static void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr)
{
Mesh *me = static_cast<Mesh *>(ptr->data);
@@ -3250,6 +3261,13 @@ static void rna_def_mesh(BlenderRNA *brna)
"Use topology based mirroring "
"(for when both sides of mesh have matching, unique topology)");
prop = RNA_def_property(srna, "use_paint_bone_selection", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(
prop, nullptr, "editflag", ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL);
RNA_def_property_ui_text(prop, "Bone Selection", "Bone selection during painting");
RNA_def_property_ui_icon(prop, ICON_BONE_DATA, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_bone_selection_mode");
prop = RNA_def_property(srna, "use_paint_mask", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "editflag", ME_EDIT_PAINT_FACE_SEL);
RNA_def_property_ui_text(prop, "Paint Mask", "Face selection masking for painting");