From 29530f9583bd35287a2b70d1a457bc3e07f06707 Mon Sep 17 00:00:00 2001 From: Daiki Hashimoto Date: Sat, 25 Nov 2023 19:52:24 +0900 Subject: [PATCH 1/4] Show bone selection icon when in weight painting mode with pose mode armature --- .../editors/space_view3d/view3d_header.cc | 7 +++++++ source/blender/makesrna/intern/rna_mesh.cc | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/source/blender/editors/space_view3d/view3d_header.cc b/source/blender/editors/space_view3d/view3d_header.cc index 592a323ff10..b7cc67067f7 100644 --- a/source/blender/editors/space_view3d/view3d_header.cc +++ b/source/blender/editors/space_view3d/view3d_header.cc @@ -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); + } } } } diff --git a/source/blender/makesrna/intern/rna_mesh.cc b/source/blender/makesrna/intern/rna_mesh.cc index 87cc4d1765c..d7e76e8aa51 100644 --- a/source/blender/makesrna/intern/rna_mesh.cc +++ b/source/blender/makesrna/intern/rna_mesh.cc @@ -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(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(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"); -- 2.30.2 From 1f033073bc878703ea6ca6c29298dde4eb57169b Mon Sep 17 00:00:00 2001 From: Daiki Hashimoto Date: Sat, 25 Nov 2023 19:53:22 +0900 Subject: [PATCH 2/4] Add default shortcut for bone selection icon --- scripts/presets/keyconfig/keymap_data/blender_default.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index 8271499c6d9..544a3e453cd 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -5245,6 +5245,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'}), -- 2.30.2 From 96a15c79de1baf2e87aa928a465491aa16efa363 Mon Sep 17 00:00:00 2001 From: Daiki Hashimoto Date: Sat, 25 Nov 2023 20:33:02 +0900 Subject: [PATCH 3/4] Show tweak tool in bone selection mode if pose mode armature exists --- scripts/startup/bl_ui/space_toolsystem_toolbar.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/scripts/startup/bl_ui/space_toolsystem_toolbar.py index 4cee8d87c91..9c45eb7f9bf 100644 --- a/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -3105,6 +3105,11 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): _defs_weight_paint.sample_weight_group, ), None, + lambda context: ( + (_defs_view3d_select.select,) + if context is None or (context.pose_object and not _defs_weight_paint.poll_select_mask(context)) + else () + ), lambda context: ( ( _defs_view3d_generic.cursor, -- 2.30.2 From 6edded7564686b7a4301c636b84eab9f19154665 Mon Sep 17 00:00:00 2001 From: Daiki Hashimoto Date: Wed, 29 Nov 2023 11:50:43 +0900 Subject: [PATCH 4/4] Align the order of toolbar items between vert/face/bone select modes --- .../startup/bl_ui/space_toolsystem_toolbar.py | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/scripts/startup/bl_ui/space_toolsystem_toolbar.py index 9c45eb7f9bf..a3ff89dd900 100644 --- a/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -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): @@ -3105,11 +3109,6 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): _defs_weight_paint.sample_weight_group, ), None, - lambda context: ( - (_defs_view3d_select.select,) - if context is None or (context.pose_object and not _defs_weight_paint.poll_select_mask(context)) - else () - ), lambda context: ( ( _defs_view3d_generic.cursor, @@ -3120,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': [ -- 2.30.2