[Bf-blender-cvs] [8b2ec99] strand_editmode: Lasso Select operator for hair edit mode.
Lukas Tönne
noreply at git.blender.org
Mon Apr 20 14:24:20 CEST 2015
Commit: 8b2ec99f5778a82aa2a60edc5ae52a79a6a1f76a
Author: Lukas Tönne
Date: Mon Jan 5 21:46:17 2015 +0100
Branches: strand_editmode
https://developer.blender.org/rB8b2ec99f5778a82aa2a60edc5ae52a79a6a1f76a
Lasso Select operator for hair edit mode.
===================================================================
M source/blender/editors/hair/hair_intern.h
M source/blender/editors/hair/hair_select.c
M source/blender/editors/hair/hair_stroke.c
M source/blender/editors/include/ED_physics.h
M source/blender/editors/space_view3d/view3d_select.c
===================================================================
diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/editors/hair/hair_intern.h
index 75e7bfe..cd59af7 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -69,6 +69,7 @@ bool hair_test_vertex_inside_circle(struct HairViewData *viewdata, const float m
bool hair_test_edge_inside_circle(struct HairViewData *viewdata, const float mval[2], float radsq,
struct BMVert *v1, struct BMVert *v2, float *r_dist, float *r_lambda);
bool hair_test_vertex_inside_rect(struct HairViewData *viewdata, struct rcti *rect, struct BMVert *v);
+bool hair_test_vertex_inside_lasso(struct HairViewData *viewdata, const int mcoords[][2], short moves, struct BMVert *v);
typedef struct HairToolData {
/* context */
diff --git a/source/blender/editors/hair/hair_select.c b/source/blender/editors/hair/hair_select.c
index 8da8252..808a1ce 100644
--- a/source/blender/editors/hair/hair_select.c
+++ b/source/blender/editors/hair/hair_select.c
@@ -380,3 +380,49 @@ int ED_hair_circle_select(bContext *C, bool select, const int mval[2], float rad
return tot;
}
+
+/************************ lasso select operator ************************/
+
+typedef struct PollVertexLassoData {
+ HairViewData viewdata;
+ const int (*mcoords)[2];
+ short moves;
+} PollVertexLassoData;
+
+static bool poll_vertex_inside_lasso(void *userdata, struct BMVert *v)
+{
+ PollVertexLassoData *data = userdata;
+
+ return hair_test_vertex_inside_lasso(&data->viewdata, data->mcoords, data->moves, v);
+}
+
+int ED_hair_lasso_select(bContext *C, const int mcoords[][2], const short moves, bool extend, bool select)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+ BMEditStrands *edit = BKE_editstrands_from_object(ob);
+ HairEditSettings *settings = &scene->toolsettings->hair_edit;
+
+ PollVertexLassoData data;
+ int action;
+
+ if (!extend && select)
+ hair_deselect_all(edit);
+
+ hair_init_viewdata(C, &data.viewdata);
+ data.mcoords = mcoords;
+ data.moves = moves;
+
+ if (extend)
+ action = SEL_SELECT;
+ else if (select)
+ action = SEL_INVERT;
+ else
+ action = SEL_DESELECT;
+
+ hair_select_verts_filter(edit, settings->select_mode, action, poll_vertex_inside_lasso, &data);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW | NA_SELECTED, ob);
+
+ return OPERATOR_FINISHED;
+}
diff --git a/source/blender/editors/hair/hair_stroke.c b/source/blender/editors/hair/hair_stroke.c
index b45aa1a..60953cd 100644
--- a/source/blender/editors/hair/hair_stroke.c
+++ b/source/blender/editors/hair/hair_stroke.c
@@ -34,6 +34,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
+#include "BLI_lasso.h"
#include "BLI_math.h"
#include "BLI_rect.h"
@@ -183,6 +184,27 @@ bool hair_test_vertex_inside_rect(HairViewData *viewdata, rcti *rect, BMVert *v)
return false;
}
+bool hair_test_vertex_inside_lasso(HairViewData *viewdata, const int mcoords[][2], short moves, BMVert *v)
+{
+ float (*obmat)[4] = viewdata->vc.obact->obmat;
+ float co_world[3];
+ int screen_co[2];
+
+ mul_v3_m4v3(co_world, obmat, v->co);
+
+ /* TODO, should this check V3D_PROJ_TEST_CLIP_BB too? */
+ if (ED_view3d_project_int_global(viewdata->vc.ar, co_world, screen_co, V3D_PROJ_TEST_CLIP_WIN) != V3D_PROJ_RET_OK)
+ return false;
+
+ if (!BLI_lasso_is_point_inside(mcoords, moves, screen_co[0], screen_co[1], IS_CLIPPED))
+ return false;
+
+ if (hair_test_depth(viewdata, v->co, screen_co))
+ return true;
+ else
+ return false;
+}
+
/* ------------------------------------------------------------------------- */
typedef void (*VertexToolCb)(HairToolData *data, void *userdata, BMVert *v, float factor);
diff --git a/source/blender/editors/include/ED_physics.h b/source/blender/editors/include/ED_physics.h
index 170c7ce..aad2629 100644
--- a/source/blender/editors/include/ED_physics.h
+++ b/source/blender/editors/include/ED_physics.h
@@ -62,6 +62,7 @@ void ED_keymap_physics(struct wmKeyConfig *keyconf);
int ED_hair_mouse_select(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle);
int ED_hair_border_select(struct bContext *C, struct rcti *rect, bool select, bool extend);
int ED_hair_circle_select(struct bContext *C, bool select, const int mval[2], float radius);
+int ED_hair_lasso_select(struct bContext *C, const int mcoords[][2], short moves, bool extend, bool select);
void ED_operatortypes_hair(void);
void ED_keymap_hair(struct wmKeyConfig *keyconf);
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 5d47e32..2e30f38 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -836,6 +836,8 @@ static void view3d_lasso_select(bContext *C, ViewContext *vc,
}
else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT))
PE_lasso_select(C, mcords, moves, extend, select);
+ else if (ob && (ob->mode & OB_MODE_HAIR_EDIT))
+ ED_hair_lasso_select(C, mcords, moves, extend, select);
else {
do_lasso_select_objects(vc, mcords, moves, extend, select);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc->scene);
More information about the Bf-blender-cvs
mailing list