[Bf-blender-cvs] [be8b5ec] soc-2014-nurbs: Added support for loop-select and adjusted disply of NURBS control polygon to 1: use z-test, 2: appear 'thin'.

Jonathan deWerd noreply at git.blender.org
Fri Aug 1 18:28:42 CEST 2014


Commit: be8b5ecc84a90c2673366de3f2e61ca2fafc8674
Author: Jonathan deWerd
Date:   Fri Aug 1 07:39:25 2014 -0400
Branches: soc-2014-nurbs
https://developer.blender.org/rBbe8b5ecc84a90c2673366de3f2e61ca2fafc8674

Added support for loop-select and adjusted disply of NURBS control polygon to 1: use z-test, 2: appear 'thin'.

===================================================================

M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/include/ED_curve.h
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/io/io_rhino_import.cpp
M	source/blender/editors/mesh/editmesh_select.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/space_image/image_edit.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/view3d_buttons.c
M	source/blender/editors/space_view3d/view3d_iterators.c
M	source/blender/editors/space_view3d/view3d_select.c

===================================================================

diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 2955c5c..bb06f29 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -165,6 +165,28 @@ static bool select_bpoint(BPoint *bp, bool selstatus, short flag, bool hidden)
 	return false;
 }
 
+/* Helper to select all points in a UV row or column according to dir */
+static bool nurbs_select_bpoint(Nurb *nu, BPoint *bp, int dir, bool selstatus, short flag, bool hidden) {
+	int pntsu = (nu->pntsu<=1)? 1 : nu->pntsu;
+	int pntsv = (nu->pntsv<=1)? 1 : nu->pntsv;
+	int idx = bp - nu->bp;
+	BLI_assert(0<=idx && idx<pntsu*pntsv);
+	int uidx = idx%pntsu;
+	int vidx = idx/pntsu;
+	/* dir is  0:-v  1:+v  2:-u  3:+u  */
+	if (dir==2 || dir==3) {
+		for (int u=0; u<pntsu; u++) {
+			select_bpoint(&nu->bp[pntsu*vidx+u], selstatus, flag, hidden);
+		}
+	}
+	if (dir==0 || dir==1) {
+		for (int v=0; v<pntsv; v++) {
+			select_bpoint(&nu->bp[pntsu*v+uidx], selstatus, flag, hidden);
+		}
+	}
+	return true;
+}
+
 static bool swap_selection_beztriple(BezTriple *bezt)
 {
 	if (bezt->f2 & SELECT)
@@ -3772,9 +3794,9 @@ void CURVE_OT_subdivide(wmOperatorType *ot)
 
 /******************** find nearest ************************/
 
-static void findnearestNurbvert__doClosest(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, const float screen_co[2])
+static void findnearestNurbvert__doClosest(ViewContext *vc, void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, const float screen_co[2])
 {
-	struct { BPoint *bp; BezTriple *bezt; Nurb *nurb; float dist; int hpoint, select; float mval_fl[2]; } *data = userData;
+	struct { BPoint *bp; BezTriple *bezt; Nurb *nurb; int *dir; float dist; int hpoint, select; float mval_fl[2]; } *data = userData;
 
 	short flag;
 	float dist_test;
@@ -3800,26 +3822,85 @@ static void findnearestNurbvert__doClosest(void *userData, Nurb *nu, BPoint *bp,
 
 	if (dist_test < data->dist) {
 		data->dist = dist_test;
-
 		data->bp = bp;
 		data->bezt = bezt;
 		data->nurb = nu;
 		data->hpoint = bezt ? beztindex : 0;
-	}
-}
-
-static short findnearestNurbvert(ViewContext *vc, short sel, const int mval[2], Nurb **nurb, BezTriple **bezt, BPoint **bp)
+		if (nu->type==CU_NURBS && data->dir) {
+			int pntsu = (nu->pntsu<=1)? 1 : nu->pntsu;
+			int pntsv = (nu->pntsu<=1)? 1 : nu->pntsv;
+			int idx = bp - nu->bp;
+			BLI_assert(0<=idx && idx<pntsu*pntsv);
+			int uidx = idx%pntsu;
+			int vidx = idx/pntsu;
+			float max_cos = -2.0; *data->dir=-1;
+			float compass_pt[2]; /* pos of adjacent bp in {+u,-u,+v,-v} direction */
+			float compass_dir[2]; /* bp ---> bp{+u,-u,+v,-v} */
+			float mouse_dir[2]; /* bp ---> clickpt */
+			sub_v2_v2v2(mouse_dir, data->mval_fl, screen_co);
+			normalize_v2(mouse_dir);
+			*data->dir = -1;
+			BPoint *Upos = (uidx<pntsu-1)? bp+1 : NULL;
+			if (Upos && ED_view3d_project_float_object(vc->ar, Upos->vec, compass_pt, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) == V3D_PROJ_RET_OK) {
+				sub_v2_v2v2(compass_dir, compass_pt, screen_co);
+				normalize_v2(compass_dir);
+				float cos = dot_v2v2(compass_dir, mouse_dir);
+				/* data->dir for directional select (alt+click)  0:-v  1:+v  2:-u  3:+u  */
+				if (cos>max_cos) {
+					*data->dir = 3;
+					max_cos = cos;
+				}
+			}
+			BPoint *Uneg = (uidx>0)? bp-1 : NULL;
+			if (Uneg && ED_view3d_project_float_object(vc->ar, Uneg->vec, compass_pt, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) == V3D_PROJ_RET_OK) {
+				sub_v2_v2v2(compass_dir, compass_pt, screen_co);
+				normalize_v2(compass_dir);
+				float cos = dot_v2v2(compass_dir, mouse_dir);
+				/* data->dir for directional select (alt+click)  0:-v  1:+v  2:-u  3:+u  */
+				if (cos>max_cos) {
+					*data->dir = 2;
+					max_cos = cos;
+				}
+			}
+			BPoint *Vpos = (vidx<pntsv-1)? bp+pntsu : NULL;
+			if (Vpos && ED_view3d_project_float_object(vc->ar, Vpos->vec, compass_pt, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) == V3D_PROJ_RET_OK) {
+				sub_v2_v2v2(compass_dir, compass_pt, screen_co);
+				normalize_v2(compass_dir);
+				float cos = dot_v2v2(compass_dir, mouse_dir);
+				/* data->dir for directional select (alt+click)  0:-v  1:+v  2:-u  3:+u  */
+				if (cos>max_cos) {
+					*data->dir = 1;
+					max_cos = cos;
+				}
+			}
+			BPoint *Vneg = (vidx>0)? bp-pntsu : NULL;
+			if (Vneg && ED_view3d_project_float_object(vc->ar, Vneg->vec, compass_pt, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) == V3D_PROJ_RET_OK) {
+				sub_v2_v2v2(compass_dir, compass_pt, screen_co);
+				normalize_v2(compass_dir);
+				float cos = dot_v2v2(compass_dir, mouse_dir);
+				/* data->dir for directional select (alt+click)  0:-v  1:+v  2:-u  3:+u  */
+				if (cos>max_cos) {
+					*data->dir = 0;
+					max_cos = cos;
+				}
+			}
+		}
+	}
+}
+
+static short findnearestNurbvert(ViewContext *vc, short sel, const int mval[2], Nurb **nurb, BezTriple **bezt, BPoint **bp, int *dir)
 {
 	/* (sel == 1): selected gets a disadvantage */
 	/* in nurb and bezt or bp the nearest is written */
 	/* return 0 1 2: handlepunt */
-	struct { BPoint *bp; BezTriple *bezt; Nurb *nurb; float dist; int hpoint, select; float mval_fl[2]; } data = {NULL};
+	struct { BPoint *bp; BezTriple *bezt; Nurb *nurb; int *dir;  float dist; int hpoint, select; float mval_fl[2]; } data = {NULL};
 
 	data.dist = ED_view3d_select_dist_px();
 	data.hpoint = 0;
 	data.select = sel;
 	data.mval_fl[0] = mval[0];
 	data.mval_fl[1] = mval[1];
+	data.dir = dir;
 
 	ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
 	nurbs_foreachScreenVert(vc, findnearestNurbvert__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
@@ -4637,7 +4718,7 @@ void CURVE_OT_make_segment(wmOperatorType *ot)
 
 /***************** pick select from 3d view **********************/
 
-bool mouse_nurb(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
+bool mouse_nurb(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle, bool alt)
 {
 	Object *obedit = CTX_data_edit_object(C);
 	Curve *cu = obedit->data;
@@ -4655,7 +4736,8 @@ bool mouse_nurb(bContext *C, const int mval[2], bool extend, bool deselect, bool
 	
 	location[0] = mval[0];
 	location[1] = mval[1];
-	hand = findnearestNurbvert(&vc, 1, location, &nu, &bezt, &bp);
+	int dir; /*  for directional select (alt+click)  0:-v  1:+v  2:-u  3:+u  */
+	hand = findnearestNurbvert(&vc, 1, location, &nu, &bezt, &bp, &dir);
 
 	if (bezt || bp) {
 		if (extend) {
@@ -4673,7 +4755,11 @@ bool mouse_nurb(bContext *C, const int mval[2], bool extend, bool deselect, bool
 			}
 			else {
 				BKE_curve_nurb_vert_active_set(cu, nu, bp);
-				select_bpoint(bp, SELECT, SELECT, HIDDEN);
+				if (nu->type==CU_NURBS && alt) { /* Loop select */
+					nurbs_select_bpoint(nu, bp, dir, SELECT, SELECT, HIDDEN);
+				} else { /* Just select bp */
+					select_bpoint(bp, SELECT, SELECT, HIDDEN);
+				}
 			}
 		}
 		else if (deselect) {
@@ -4690,7 +4776,11 @@ bool mouse_nurb(bContext *C, const int mval[2], bool extend, bool deselect, bool
 				}
 			}
 			else {
-				select_bpoint(bp, DESELECT, SELECT, HIDDEN);
+				if (nu->type==CU_NURBS && alt) { /* Loop select */
+					nurbs_select_bpoint(nu, bp, dir, DESELECT, SELECT, HIDDEN);
+				} else { /* Just select bp */
+					select_bpoint(bp, DESELECT, SELECT, HIDDEN);
+				}
 				if (bp == vert) cu->actvert = CU_ACT_NONE;
 			}
 		}
@@ -4715,11 +4805,19 @@ bool mouse_nurb(bContext *C, const int mval[2], bool extend, bool deselect, bool
 			}
 			else {
 				if (bp->f1 & SELECT) {
-					select_bpoint(bp, DESELECT, SELECT, HIDDEN);
+					if (nu->type==CU_NURBS && alt) { /* Loop select */
+						nurbs_select_bpoint(nu, bp, dir, DESELECT, SELECT, HIDDEN);
+					} else { /* Just select bp */
+						select_bpoint(bp, DESELECT, SELECT, HIDDEN);
+					}
 					if (bp == vert) cu->actvert = CU_ACT_NONE;
 				}
 				else {
-					select_bpoint(bp, SELECT, SELECT, HIDDEN);
+					if (nu->type==CU_NURBS && alt) { /* Loop select */
+						nurbs_select_bpoint(nu, bp, dir, SELECT, SELECT, HIDDEN);
+					} else { /* Just select bp */
+						select_bpoint(bp, SELECT, SELECT, HIDDEN);
+					}
 					BKE_curve_nurb_vert_active_set(cu, nu, bp);
 				}
 			}
@@ -4742,7 +4840,11 @@ bool mouse_nurb(bContext *C, const int mval[2], bool extend, bool deselect, bool
 			}
 			else {
 				BKE_curve_nurb_vert_active_set(cu, nu, bp);
-				select_bpoint(bp, SELECT, SELECT, HIDDEN);
+				if (nu->type==CU_NURBS && alt) { /* Loop select */
+					nurbs_select_bpoint(nu, bp, dir, SELECT, SELECT, HIDDEN);
+				} else { /* Just select bp */
+					select_bpoint(bp, SELECT, SELECT, HIDDEN);
+				}
 			}
 		}
 
@@ -5520,7 +5622,8 @@ static int select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent
 	view3d_operator_needs_opengl(C);
 	view3d_set_viewcontext(C, &vc);
 
-	findnearestNurbvert(&vc, 1, event->mval, &nu, &bezt, &bp);
+	int dir;
+	findnearestNurbvert(&vc, 1, event->mval, &nu, &bezt, &bp, &dir);
 
 	if (bezt) {
 		a = nu->pntsu;
diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h
index 330147d..4725cf8 100644
--- a/source/blender/editors/include/ED_curve.h
+++ b/source/blender/editors/include/ED_curve.h
@@ -64,7 +64,7 @@ void    load_editNurb(struct Object *obedit);
 void    make_editNurb(struct Object *obedit);
 void    free_editNurb(struct Object *obedit);
 
-bool    mouse_nurb(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle);
+bool    mouse_nurb(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle, bool alt);
 
 struct Nurb *add_nurbs_primitive(struct bContext *C, struct Object *obedit, float mat[4][4], int type, int newob);
 
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index d31be3e..4dae067 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -161,6 +161,7 @@ int     ED_operator_object_active_editable_font(struct bContext *C);
 int     ED_operator_editmesh(struct bContext *C);
 int     ED_operator_editmesh_view3d(struct bContext *C);
 int     ED_operator_editmesh_region_view3d(struct bContext *C);
+int     ED_operator_editmesh_or_editc

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list