patch [#36032] Quick Hack lattice random selection
by Andrey Dubravin (daa)
This commit is contained in:
@@ -723,6 +723,7 @@ class VIEW3D_MT_select_edit_lattice(Menu):
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("lattice.select_random")
|
||||
layout.operator("lattice.select_all").action = 'TOGGLE'
|
||||
layout.operator("lattice.select_all", text="Inverse").action = 'INVERT'
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ void OBJECT_OT_hook_recenter(struct wmOperatorType *ot);
|
||||
/* object_lattice.c */
|
||||
void LATTICE_OT_select_all(struct wmOperatorType *ot);
|
||||
void LATTICE_OT_select_ungrouped(struct wmOperatorType *ot);
|
||||
void LATTICE_OT_select_random(struct wmOperatorType *ot);
|
||||
void LATTICE_OT_make_regular(struct wmOperatorType *ot);
|
||||
void LATTICE_OT_flip(struct wmOperatorType *ot);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_rand.h"
|
||||
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_key_types.h"
|
||||
@@ -170,6 +171,59 @@ void load_editLatt(Object *obedit)
|
||||
}
|
||||
}
|
||||
|
||||
/************************** Select Random Operator **********************/
|
||||
|
||||
static int lattice_select_random_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
Lattice *lt = ((Lattice*)obedit->data)->editlatt->latt;
|
||||
const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f;
|
||||
int tot;
|
||||
BPoint *bp;
|
||||
|
||||
if (!RNA_boolean_get(op->ptr, "extend")) {
|
||||
ED_setflagsLatt(obedit, !SELECT);
|
||||
}
|
||||
else {
|
||||
lt->actbp = LT_ACTBP_NONE;
|
||||
}
|
||||
|
||||
tot = lt->pntsu * lt->pntsv * lt->pntsw;
|
||||
bp = lt->def;
|
||||
while (tot--) {
|
||||
if (!bp->hide) {
|
||||
if (BLI_frand() < randfac) {
|
||||
bp->f1 |= SELECT;
|
||||
}
|
||||
}
|
||||
bp++;
|
||||
}
|
||||
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void LATTICE_OT_select_random(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Select Random";
|
||||
ot->description = "Randomly select UVW control points";
|
||||
ot->idname = "LATTICE_OT_select_random";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = lattice_select_random_exec;
|
||||
ot->poll = ED_operator_editlattice;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* props */
|
||||
RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f,
|
||||
"Percent", "Percentage of elements to select randomly", 0.f, 100.0f);
|
||||
RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
|
||||
}
|
||||
|
||||
/************************** Select All Operator *************************/
|
||||
|
||||
void ED_setflagsLatt(Object *obedit, int flag)
|
||||
|
||||
@@ -218,6 +218,7 @@ void ED_operatortypes_object(void)
|
||||
|
||||
WM_operatortype_append(LATTICE_OT_select_all);
|
||||
WM_operatortype_append(LATTICE_OT_select_ungrouped);
|
||||
WM_operatortype_append(LATTICE_OT_select_random);
|
||||
WM_operatortype_append(LATTICE_OT_make_regular);
|
||||
WM_operatortype_append(LATTICE_OT_flip);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user