From 221d07864128687858634aebcfb27798a494557a Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 9 Nov 2018 14:26:58 -0200 Subject: Multi-Objects Metaball: Selection refactor - fix pick and box selection This is inspired/based on the code we use for armature bone selection. Both pick selection, and box selection should be working now. --- .../blender/editors/space_view3d/view3d_select.c | 46 ++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'source/blender/editors/space_view3d/view3d_select.c') diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 230bbd11450..c421c96e530 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -2169,7 +2169,8 @@ static int do_meta_box_select( ViewContext *vc, const rcti *rect, const eSelectOp sel_op) { - MetaBall *mb = (MetaBall *)vc->obedit->data; + Object *ob = vc->obedit; + MetaBall *mb = (MetaBall *)ob->data; MetaElem *ml; int a; @@ -2184,27 +2185,50 @@ static int do_meta_box_select( BKE_mball_deselect_all(mb); } - for (ml = mb->editelems->first; ml; ml = ml->next) { - bool is_inside_1 = false; - bool is_inside_2 = false; + int metaelem_id = 0; + for (ml = mb->editelems->first; ml; ml = ml->next, metaelem_id += 0x10000) { + bool is_inside_radius = false; + bool is_inside_stiff = false; + for (a = 0; a < hits; a++) { - if (ml->selcol1 == buffer[(4 * a) + 3]) { - is_inside_1 = true; + int hitresult = buffer[(4 * a) + 3]; + + if (hitresult == -1) { + continue; + } + else if (hitresult & MBALL_NOSEL) { + continue; + } + + const uint hit_object = hitresult & 0xFFFF; + if (vc->obedit->select_color != hit_object) { + continue; + } + + if (metaelem_id != (hitresult & 0xFFFF0000 & ~(MBALLSEL_ANY))) { + continue; + } + + if (hitresult & MBALLSEL_RADIUS) { + is_inside_radius = true; break; } - if (ml->selcol2 == buffer[(4 * a) + 3]) { - is_inside_2 = true; + + if (hitresult & MBALLSEL_STIFF) { + is_inside_stiff = true; break; } } - if (is_inside_1) { + if (is_inside_radius) { ml->flag |= MB_SCALE_RAD; } - if (is_inside_2) { + if (is_inside_stiff) { ml->flag &= ~MB_SCALE_RAD; } + const bool is_select = (ml->flag & SELECT); - const bool is_inside = is_inside_1 || is_inside_2; + const bool is_inside = is_inside_radius || is_inside_stiff; + const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside); if (sel_op_result != -1) { SET_FLAG_FROM_TEST(ml->flag, sel_op_result, SELECT); -- cgit v1.2.3