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:49:23 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-19 14:49:23 +0400
commit80f3b32e066b17da9592aeb510e2b9afaadff632 (patch)
treeae6691191c5e9b34dd47c71f89d37f3bab911c05 /source/blender/editors/object/object_lattice.c
parentdf299ab50015ec99ff507cc89e57b061405c6cda (diff)
patch [#35789] Quick hack more/less tool for lattices
by Pedro Riera (priera), Andrey Dubravin, I also made some changes.
Diffstat (limited to 'source/blender/editors/object/object_lattice.c')
-rw-r--r--source/blender/editors/object/object_lattice.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_lattice.c b/source/blender/editors/object/object_lattice.c
index 0ae4edb4ae3..0de468bac43 100644
--- a/source/blender/editors/object/object_lattice.c
+++ b/source/blender/editors/object/object_lattice.c
@@ -38,6 +38,7 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_rand.h"
+#include "BLI_bitmap.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
@@ -55,6 +56,7 @@
#include "BKE_lattice.h"
#include "BKE_deform.h"
#include "BKE_report.h"
+#include "BKE_utildefines.h"
#include "ED_lattice.h"
#include "ED_object.h"
@@ -224,6 +226,110 @@ void LATTICE_OT_select_random(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
}
+/************************** Select More/Less Operator *************************/
+
+static bool lattice_test_bitmap_uvw(Lattice *lt, BLI_bitmap selpoints, int u, int v, int w, const bool selected)
+{
+ if ((u < 0 || u >= lt->pntsu) ||
+ (v < 0 || v >= lt->pntsv) ||
+ (w < 0 || w >= lt->pntsw))
+ {
+ return false;
+ }
+ else {
+ int i = BKE_lattice_index_from_uvw(lt, u, v, w);
+ if (lt->def[i].hide == 0) {
+ return (BLI_BITMAP_GET(selpoints, i) != 0) == selected;
+ }
+ return false;
+ }
+}
+
+static int lattice_select_more_less(bContext *C, const bool select)
+{
+ Object *obedit = CTX_data_edit_object(C);
+ Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
+ BPoint *bp;
+ const int tot = lt->pntsu * lt->pntsv * lt->pntsw;
+ int i, w, u, v;
+ BLI_bitmap selpoints;
+
+ lt->actbp = LT_ACTBP_NONE;
+
+ bp = lt->def;
+ selpoints = BLI_BITMAP_NEW(tot, __func__);
+ for (i = 0; i < tot; i++, bp++) {
+ if (bp->f1 & SELECT) {
+ BLI_BITMAP_SET(selpoints, i);
+ }
+ }
+
+ bp = lt->def;
+ for (w = 0; w < lt->pntsw; w++) {
+ for (v = 0; v < lt->pntsv; v++) {
+ for (u = 0; u < lt->pntsu; u++) {
+ if ((bp->hide == 0) && (((bp->f1 & SELECT) == 0) == select)) {
+ if (lattice_test_bitmap_uvw(lt, selpoints, u + 1, v, w, select) ||
+ lattice_test_bitmap_uvw(lt, selpoints, u - 1, v, w, select) ||
+ lattice_test_bitmap_uvw(lt, selpoints, u, v + 1, w, select) ||
+ lattice_test_bitmap_uvw(lt, selpoints, u, v - 1, w, select) ||
+ lattice_test_bitmap_uvw(lt, selpoints, u, v, w + 1, select) ||
+ lattice_test_bitmap_uvw(lt, selpoints, u, v, w - 1, select))
+ {
+ BKE_BIT_TEST_SET(bp->f1, select, SELECT);
+ }
+ }
+ bp++;
+ }
+ }
+ }
+
+ MEM_freeN(selpoints);
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ return OPERATOR_FINISHED;
+}
+
+static int lattice_select_more_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ return lattice_select_more_less(C, true);
+}
+
+static int lattice_select_less_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ return lattice_select_more_less(C, false);
+}
+
+void LATTICE_OT_select_more(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select More";
+ ot->description = "Select vertex directly linked to already selected ones";
+ ot->idname = "LATTICE_OT_select_more";
+
+ /* api callbacks */
+ ot->exec = lattice_select_more_exec;
+ ot->poll = ED_operator_editlattice;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+void LATTICE_OT_select_less(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select Less";
+ ot->description = "Deselect vertices at the boundary of each selection region";
+ ot->idname = "LATTICE_OT_select_less";
+
+ /* api callbacks */
+ ot->exec = lattice_select_less_exec;
+ ot->poll = ED_operator_editlattice;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
/************************** Select All Operator *************************/
void ED_setflagsLatt(Object *obedit, int flag)