[Bf-blender-cvs] [cea9cbd] hair_immediate_fixes: Border Select operator for hair edit mode.
Lukas Tönne
noreply at git.blender.org
Mon Jan 5 21:26:14 CET 2015
Commit: cea9cbd9fcc8c220b5e4cd793695092bc8ea9fa3
Author: Lukas Tönne
Date: Mon Jan 5 21:25:57 2015 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rBcea9cbd9fcc8c220b5e4cd793695092bc8ea9fa3
Border 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 0ecb65e..75e7bfe 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -39,6 +39,7 @@
struct ARegion;
struct bContext;
struct wmOperatorType;
+struct rcti;
/* hair_edit.c */
int hair_edit_toggle_poll(struct bContext *C);
@@ -67,6 +68,7 @@ bool hair_test_vertex_inside_circle(struct HairViewData *viewdata, const float m
struct BMVert *v, float *r_dist);
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);
typedef struct HairToolData {
/* context */
diff --git a/source/blender/editors/hair/hair_select.c b/source/blender/editors/hair/hair_select.c
index 9b5a70d..8da8252 100644
--- a/source/blender/editors/hair/hair_select.c
+++ b/source/blender/editors/hair/hair_select.c
@@ -35,6 +35,7 @@
#include "BLI_utildefines.h"
#include "BLI_math.h"
+#include "BLI_rect.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -185,6 +186,16 @@ static int hair_select_verts_closest(BMEditStrands *edit, HairEditSelectMode sel
return tot;
}
+static void hair_deselect_all(BMEditStrands *edit)
+{
+ BMVert *v;
+ BMIter iter;
+
+ BM_ITER_MESH(v, &iter, edit->bm, BM_VERTS_OF_MESH) {
+ BM_elem_flag_set(v, BM_ELEM_SELECT, false);
+ }
+}
+
/* ------------------------------------------------------------------------- */
/************************ select/deselect all operator ************************/
@@ -260,15 +271,11 @@ int ED_hair_mouse_select(bContext *C, const int mval[2], bool extend, bool desel
HairEditSettings *settings = &scene->toolsettings->hair_edit;
float select_radius = ED_view3d_select_dist_px();
- BMVert *v;
- BMIter iter;
DistanceVertexCirleData data;
int action;
if (!extend && !deselect && !toggle) {
- BM_ITER_MESH(v, &iter, edit->bm, BM_VERTS_OF_MESH) {
- BM_elem_flag_set(v, BM_ELEM_SELECT, false);
- }
+ hair_deselect_all(edit);
}
hair_init_viewdata(C, &data.viewdata);
@@ -290,6 +297,50 @@ int ED_hair_mouse_select(bContext *C, const int mval[2], bool extend, bool desel
return OPERATOR_FINISHED;
}
+/************************ border select operator ************************/
+
+typedef struct PollVertexRectData {
+ HairViewData viewdata;
+ rcti rect;
+} PollVertexRectData;
+
+static bool poll_vertex_inside_rect(void *userdata, struct BMVert *v)
+{
+ PollVertexRectData *data = userdata;
+
+ return hair_test_vertex_inside_rect(&data->viewdata, &data->rect, v);
+}
+
+int ED_hair_border_select(bContext *C, rcti *rect, bool select, bool extend)
+{
+ 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;
+
+ PollVertexRectData data;
+ int action;
+
+ if (!extend && select)
+ hair_deselect_all(edit);
+
+ hair_init_viewdata(C, &data.viewdata);
+ data.rect = *rect;
+
+ 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_rect, &data);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW | NA_SELECTED, ob);
+
+ return OPERATOR_FINISHED;
+}
+
/************************ circle select operator ************************/
typedef struct PollVertexCirleData {
diff --git a/source/blender/editors/hair/hair_stroke.c b/source/blender/editors/hair/hair_stroke.c
index bb81ef7..b45aa1a 100644
--- a/source/blender/editors/hair/hair_stroke.c
+++ b/source/blender/editors/hair/hair_stroke.c
@@ -35,6 +35,7 @@
#include "BLI_utildefines.h"
#include "BLI_math.h"
+#include "BLI_rect.h"
#include "DNA_brush_types.h"
#include "DNA_meshdata_types.h"
@@ -161,6 +162,27 @@ bool hair_test_edge_inside_circle(HairViewData *viewdata, const float mval[2], f
return false;
}
+bool hair_test_vertex_inside_rect(HairViewData *viewdata, rcti *rect, 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_rcti_isect_pt_v(rect, screen_co))
+ 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 656efd8..170c7ce 100644
--- a/source/blender/editors/include/ED_physics.h
+++ b/source/blender/editors/include/ED_physics.h
@@ -36,6 +36,7 @@ struct bContext;
struct ReportList;
struct wmKeyConfig;
struct ViewContext;
+struct rcti;
struct Scene;
struct Object;
@@ -59,6 +60,7 @@ void ED_keymap_physics(struct wmKeyConfig *keyconf);
/* hair edit */
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);
void ED_operatortypes_hair(void);
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 3904406..709ed2e 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -2148,6 +2148,9 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
else if (vc.obact && vc.obact->mode & OB_MODE_PARTICLE_EDIT) {
ret = PE_border_select(C, &rect, select, extend);
}
+ else if (vc.obact && vc.obact->mode & OB_MODE_HAIR_EDIT) {
+ ret = ED_hair_border_select(C, &rect, select, extend);
+ }
else { /* object mode with none active */
ret = do_object_pose_box_select(C, &vc, &rect, select, extend);
}
More information about the Bf-blender-cvs
mailing list