Index: source/blender/include/BDR_editmball.h =================================================================== --- source/blender/include/BDR_editmball.h (revision 10749) +++ source/blender/include/BDR_editmball.h (working copy) @@ -42,6 +42,8 @@ */ void add_primitiveMball(int); void deselectall_mball(void); +void selectinverse_mball(void); +void selectrandom_mball(void); void mouse_mball(void); void adduplicate_mball(void); void delete_mball(void); Index: source/blender/src/editmball.c =================================================================== --- source/blender/src/editmball.c (revision 10749) +++ source/blender/src/editmball.c (working copy) @@ -30,6 +30,7 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ +#include #include #ifdef HAVE_CONFIG_H @@ -40,6 +41,7 @@ #include "BLI_blenlib.h" #include "BLI_arithb.h" +#include "BLI_rand.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" @@ -225,6 +227,36 @@ BIF_undo_push("Add MetaElem"); } +/* should be put in some more reusable place and used in each "select random" */ +static void generate_pickable_list(int *list, int size, int pickamount) +{ + int i, j, removable; + + BLI_srand( BLI_rand() ); /* random seed */ + + /* generate list in form 0->1, 1->2, 2->3, ... i-2->i-1, i->0 */ + for(i=0; iflag & SELECT) ml->flag &= ~SELECT; + else ml->flag |= SELECT; + ml= ml->next; + } + + allqueue(REDRAWVIEW3D, 0); + countall(); + BIF_undo_push("Invert MetaElem"); +} + +/* select random metaball selection */ +void selectrandom_mball() +{ + MetaElem *ml; + static short randfac= 50; + int amounttoselect, i= 0; + int *itemstobeselected; + + if(!button(&randfac,0, 100,"Percentage:")) return; + + if(randfac == 0) return; + + itemstobeselected= MEM_callocN(sizeof(int) * G.totvert, "selectitems"); /* there might be a nicer way to get amount of metaballs */ + amounttoselect= floor(randfac * G.totvert / 100 + 0.5); + generate_pickable_list(itemstobeselected, G.totvert, amounttoselect); + + ml= editelems.first; + while(ml) { + if(itemstobeselected[i] != -1) ml->flag |= SELECT; + i++; + ml= ml->next; + } + + allqueue(REDRAWVIEW3D, 0); + countall(); + BIF_undo_push("Random MetaElem"); +} + /* select MetaElement with mouse click (user can select radius circle or * stiffness circle) */ void mouse_mball() Index: source/blender/src/header_view3d.c =================================================================== --- source/blender/src/header_view3d.c (revision 10749) +++ source/blender/src/header_view3d.c (working copy) @@ -1165,6 +1165,12 @@ case 2: /* Select/Deselect all */ deselectall_mball(); break; + case 3: /* Inverse */ + selectinverse_mball(); + break; + case 4: /* Select Random */ + selectrandom_mball(); + break; } allqueue(REDRAWVIEW3D, 0); } @@ -1180,8 +1186,12 @@ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Random...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); if(curarea->headertype==HEADERTOP) {