Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-07-19 14:44:39 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-19 14:44:39 +0400
commitdf299ab50015ec99ff507cc89e57b061405c6cda (patch)
treef0a85f6e0cbbef9cac45e5d1949579c03df0b000 /source/blender/editors/object/object_lattice.c
parent02468b290a9c4246767ed4d1fcaa222de71d1ad5 (diff)
patch [#36032] Quick Hack lattice random selection
by Andrey Dubravin (daa)
Diffstat (limited to 'source/blender/editors/object/object_lattice.c')
-rw-r--r--source/blender/editors/object/object_lattice.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_lattice.c b/source/blender/editors/object/object_lattice.c
index 0e220357d30..0ae4edb4ae3 100644
--- a/source/blender/editors/object/object_lattice.c
+++ b/source/blender/editors/object/object_lattice.c
@@ -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)