diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-23 02:00:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-23 02:03:04 +0300 |
commit | 7b4f545e282fcd0b2402c45faf13642bc047d1a5 (patch) | |
tree | e709d057d856cbb3a1743004b152210528a82935 /source/blender | |
parent | 7c74f5006a888a4c42c407752fb53c1da8796a9d (diff) |
Fix bone selection w/ mixed wpaint & pose mode
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 8 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_select.c | 44 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 32 |
3 files changed, 58 insertions, 26 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index f0c805eea8d..78b51dad8d1 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -383,12 +383,16 @@ typedef enum { } eV3DSelectMode; typedef enum { - /* Don't exclude anything. */ + /** Don't exclude anything. */ VIEW3D_SELECT_FILTER_NOP = 0, - /* Don't select objects outside the current mode. */ + /** Don't select objects outside the current mode. */ VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK = 1, + /** A version of #VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK that allows pose-bone selection. */ + VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK = 2, } eV3DSelectObjectFilter; +eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const struct Scene *scene, const struct Object *obact); + void view3d_opengl_select_cache_begin(void); void view3d_opengl_select_cache_end(void); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index a99e276979b..9d9076448d2 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1397,7 +1397,9 @@ finally: view3d_opengl_select_cache_end(); if (vc->scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) { - const bool is_pose_mode = (vc->obact && vc->obact->mode & OB_MODE_POSE); + const bool is_pose_mode = ( + (vc->obact && vc->obact->mode & OB_MODE_POSE) || + (select_filter == VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK)); struct { uint data[4]; } *buffer4 = (void *)buffer; @@ -1648,9 +1650,7 @@ static bool ed_object_select_pick( // TIMEIT_START(select_time); /* if objects have posemode set, the bones are in the same selection buffer */ - const eV3DSelectObjectFilter select_filter = ( - (scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) ? - VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK : VIEW3D_SELECT_FILTER_NOP); + const eV3DSelectObjectFilter select_filter = ED_view3d_select_filter_from_mode(scene, vc.obact); hits = mixed_bones_object_selectbuffer( &vc, buffer, mval, true, enumerate, select_filter, @@ -1670,20 +1670,6 @@ static bool ed_object_select_pick( basact = mouse_select_eval_buffer(&vc, buffer, hits, startbase, has_bones, do_nearest); } - if (scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) { - if (is_obedit == false) { - if (basact && !BKE_object_is_mode_compat(basact->object, object_mode)) { - if (object_mode == OB_MODE_OBJECT) { - struct Main *bmain = CTX_data_main(C); - ED_object_mode_generic_exit(bmain, vc.depsgraph, scene, basact->object); - } - if (!BKE_object_is_mode_compat(basact->object, object_mode)) { - basact = NULL; - } - } - } - } - if (has_bones && basact) { if (basact->object->type == OB_CAMERA) { if (BASACT(view_layer) == basact) { @@ -1770,6 +1756,20 @@ static bool ed_object_select_pick( if (basact == BASACT(view_layer)) basact = NULL; } + + if (scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) { + if (is_obedit == false) { + if (basact && !BKE_object_is_mode_compat(basact->object, object_mode)) { + if (object_mode == OB_MODE_OBJECT) { + struct Main *bmain = CTX_data_main(C); + ED_object_mode_generic_exit(bmain, vc.depsgraph, scene, basact->object); + } + if (!BKE_object_is_mode_compat(basact->object, object_mode)) { + basact = NULL; + } + } + } + } } } @@ -2373,9 +2373,7 @@ static int do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const /* selection buffer now has bones potentially too, so we add MAXPICKBUF */ uint *vbuffer = MEM_mallocN(4 * (totobj + MAXPICKELEMS) * sizeof(uint[4]), "selection buffer"); - const eV3DSelectObjectFilter select_filter = ( - (vc->scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) ? - VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK : VIEW3D_SELECT_FILTER_NOP); + const eV3DSelectObjectFilter select_filter = ED_view3d_select_filter_from_mode(vc->scene, vc->obact); const int hits = view3d_opengl_select( vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL, select_filter); @@ -2451,9 +2449,7 @@ static int do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const eS /* selection buffer now has bones potentially too, so we add MAXPICKBUF */ uint *vbuffer = MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(uint[4]), "selection buffer"); - const eV3DSelectObjectFilter select_filter = ( - (vc->scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) ? - VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK : VIEW3D_SELECT_FILTER_NOP); + const eV3DSelectObjectFilter select_filter = ED_view3d_select_filter_from_mode(vc->scene, vc->obact); const int hits = view3d_opengl_select( vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL, select_filter); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 73823791e6c..af52eb15304 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -893,6 +893,19 @@ static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data) } +eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const Scene *scene, const Object *obact) +{ + if (scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) { + if ((obact->mode & OB_MODE_WEIGHT_PAINT) && + BKE_object_pose_armature_get((Object *)obact)) + { + return VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK; + } + return VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK; + } + return VIEW3D_SELECT_FILTER_NOP; +} + /** Implement #VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK. */ static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data) { @@ -900,6 +913,15 @@ static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data) return BKE_object_is_mode_compat(ob, obact->mode); } +/** Implement #VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK for special case when + * we want to select pose bones (this doesn't switch modes). */ +static bool drw_select_filter_object_mode_lock_for_weight_paint(Object *ob, void *user_data) +{ + const Object *ob_pose = user_data; + return ((DEG_get_original_object(ob) == ob_pose) || + BKE_object_is_mode_compat(ob, OB_MODE_WEIGHT_PAINT)); +} + /** * \warning be sure to account for a negative return value * This is an error, "Too many objects in select buffer" @@ -972,6 +994,16 @@ int view3d_opengl_select( } break; } + case VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK: + { + Object *obact = OBACT(vc->view_layer); + BLI_assert(obact && (obact->mode & OB_MODE_WEIGHT_PAINT)); + Object *ob_pose = BKE_object_pose_armature_get(obact); + + object_filter.fn = drw_select_filter_object_mode_lock_for_weight_paint; + object_filter.user_data = ob_pose; + break; + } case VIEW3D_SELECT_FILTER_NOP: break; |