[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45468] trunk/blender/source/blender: Fix [#30855] Vertex Slide not using the active vertex

Francisco De La Cruz dlcs.frank at gmail.com
Sat Apr 7 21:53:40 CEST 2012


Revision: 45468
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45468
Author:   xercesblue
Date:     2012-04-07 19:53:39 +0000 (Sat, 07 Apr 2012)
Log Message:
-----------
Fix [#30855] Vertex Slide not using the active vertex

Now uses the last selected vertex. 
Also, snapping thresholds are now dynamic and the tool's operation should be more consistent with multiple edges selected on invocation.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/operators/bmo_slide.c
    trunk/blender/source/blender/editors/mesh/editmesh_slide.c

Modified: trunk/blender/source/blender/bmesh/operators/bmo_slide.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_slide.c	2012-04-07 18:39:29 UTC (rev 45467)
+++ trunk/blender/source/blender/bmesh/operators/bmo_slide.c	2012-04-07 19:53:39 UTC (rev 45468)
@@ -47,10 +47,10 @@
 	BMHeader *h;
 	BMVert *vertex;
 	BMEdge *edge;
+	BMEdge *slide_edge;
 	int is_start_v1 = 0;
 
 	/* Selection counts */
-	int selected_verts = 0;
 	int selected_edges = 0;
 
 	/* Get slide amount */
@@ -69,9 +69,6 @@
 	/* Count selected edges */
 	BMO_ITER(h, &oiter, bm, op, "edge", BM_VERT | BM_EDGE) {
 		switch (h->htype) {
-			case BM_VERT:
-				selected_verts++;
-				break;
 			case BM_EDGE:
 				selected_edges++;
 				/* Mark all selected edges (cast BMHeader->BMEdge) */
@@ -80,9 +77,8 @@
 		}
 	}
 
-	/* Only allow sliding between two verts */
-
-	if (selected_verts != 2 || selected_edges == 0) {
+	/* Only allow sliding if an edge is selected */
+	if (selected_edges == 0) {
 		if (G.debug & G_DEBUG)
 			fprintf(stderr, "vertslide: select a single edge\n");
 		return;
@@ -90,15 +86,15 @@
 
 	/* Make sure we get the correct edge. */
 	BM_ITER(edge, &iter, bm, BM_EDGES_OF_VERT, vertex) {
-		if (BMO_elem_flag_test(bm, edge, EDGE_MARK)) {
-			is_start_v1 = (edge->v1 == vertex);
+		if (BMO_elem_flag_test(bm, edge, EDGE_MARK) && BM_vert_in_edge(edge, vertex)) {
+			slide_edge = edge;
 			break;
 		}
 	}
 
 	/* Found edge */
-	if (edge) {
-		BMVert *other = BM_edge_other_vert(edge, vertex);
+	if (slide_edge) {
+		BMVert *other = BM_edge_other_vert(slide_edge, vertex);
 
 		/* mark */
 		BMO_elem_flag_enable(bm, vertex, VERT_MARK);

Modified: trunk/blender/source/blender/editors/mesh/editmesh_slide.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_slide.c	2012-04-07 18:39:29 UTC (rev 45467)
+++ trunk/blender/source/blender/editors/mesh/editmesh_slide.c	2012-04-07 19:53:39 UTC (rev 45468)
@@ -55,8 +55,7 @@
 
 #include "mesh_intern.h"
 
-#define VTX_SLIDE_SLIDE_SENS_F 15.0f
-#define VTX_SLIDE_SNAP_THRSH    0.3f
+#define VTX_SLIDE_SNAP_THRSH 0.15
 
 /* Cusom VertexSlide Operator data */
 typedef struct VertexSlideOp {
@@ -75,10 +74,13 @@
 
 	/* Are we in slide mode */
 	int slide_mode;
-	int snap_n_weld;
+	int snap_n_merge;
 	int snap_to_end_vtx;
 	int snap_to_mid;
 
+	/* Snap threshold */
+	float snap_threshold;
+
 	float distance;
 	float interp[3];
 
@@ -105,13 +107,13 @@
 {
 	Object *obedit = CTX_data_edit_object(C);
 	BMEditMesh *em = BMEdit_FromObject(obedit);
-	BMEditSelection *ese = em->bm->selected.first;
+	BMEditSelection *ese;
 
 	/* Custom data */
 	VertexSlideOp *vso;
 
 	const char *header_str = "Vertex Slide: Hover over an edge and left-click to select slide edge. "
-	                         "Left-Shift: Midpoint Snap, Left-Alt: Snap, Left-Ctrl: Snap&Weld";
+	                         "Left-Shift: Midpoint Snap, Left-Alt: Snap, Left-Ctrl: Snap&Merge";
 
 	if (!obedit) {
 		BKE_report(op->reports, RPT_ERROR, "Vertex Slide Error: Not object in context");
@@ -122,7 +124,7 @@
 	ese = em->bm->selected.last;
 
 	/* Is there a starting vertex  ? */
-	if (ese == NULL || ese->htype != BM_VERT) {
+	if (ese == NULL || (ese->htype != BM_VERT && ese->htype != BM_EDGE)) {
 		BKE_report(op->reports, RPT_ERROR_INVALID_INPUT, "Vertex Slide Error: Select a (single) vertex");
 		return FALSE;
 	}
@@ -146,7 +148,7 @@
 
 	vso->slide_mode = FALSE;
 
-	vso->snap_n_weld = FALSE;
+	vso->snap_n_merge = FALSE;
 
 	vso->snap_to_end_vtx = FALSE;
 
@@ -154,6 +156,8 @@
 
 	vso->distance = 0.0f;
 
+	vso->snap_threshold = 0.2f;
+
 	/* Add handler for the vertex sliding */
 	WM_event_add_modal_handler(C, op);
 
@@ -194,12 +198,21 @@
 	/* Invoke operator */
 	edbm_vert_slide_exec(C, op);
 
-	if(vso->snap_n_weld) {
+	if(vso->snap_n_merge) {
+		float other_d;
 		BMVert* other = BM_edge_other_vert(vso->sel_edge, vso->start_vtx);
-		BM_vert_select_set(bm, other, TRUE);
-	
-		EDBM_op_callf(em, op, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, other->co);
-		EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+		other_d = len_v3v3(vso->interp, other->co);
+
+		/* Only snap if within threshold */
+		if (other_d < vso->snap_threshold) {
+			BM_vert_select_set(bm, other, TRUE);
+			BM_vert_select_set(bm, vso->start_vtx, TRUE);
+			EDBM_op_callf(em, op, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, other->co);
+			EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+		} else {
+			/* Store in historty if not merging */
+			EDBM_editselection_store(em, &vso->start_vtx->head);		
+		}
 	}
 	else {
 		/* Store edit selection of the active vertex, allows other
@@ -365,12 +378,18 @@
 
 	if (nst_edge) {
 		/* Find a connected edge */
-		if (nst_edge->v1 == start_vtx || nst_edge->v2 == start_vtx) {
+		if (BM_vert_in_edge(nst_edge, vso->start_vtx)) {
+			float edge_len;
+
 			/* Save mouse coords */
 			copy_v2_v2_int(vso->m_co, event->mval);
 
 			/* Set edge */
 			vso->sel_edge = nst_edge;
+			
+			/* Set snap threshold to be proportional to edge length */
+			edge_len = len_v3v3(nst_edge->v1->co, nst_edge->v2->co);
+			vso->snap_threshold = edge_len * VTX_SLIDE_SNAP_THRSH;
 		}
 	}
 }
@@ -426,7 +445,7 @@
 			float v1_d = len_v3v3(vso->interp, edge->v1->co);
 			float v2_d = len_v3v3(vso->interp, edge->v2->co);
 
-			if (v1_d > v2_d && v2_d < VTX_SLIDE_SNAP_THRSH) {
+			if (v1_d > v2_d && v2_d < vso->snap_threshold) {
 				copy_v3_v3(vso->interp, edge->v2->co);
 
 				if (start_at_v1)
@@ -434,7 +453,7 @@
 				else
 					vso->distance = 0.0f;
 			}
-			if (v2_d > v1_d && v1_d < VTX_SLIDE_SNAP_THRSH) {
+			if (v2_d > v1_d && v1_d < vso->snap_threshold) {
 				copy_v3_v3(vso->interp, edge->v1->co);
 				if (start_at_v1)
 					vso->distance = 0.0f;
@@ -514,11 +533,11 @@
 		{
 			switch (event->val) {
 				case KM_PRESS:
-					vso->snap_n_weld = TRUE;
+					vso->snap_n_merge = TRUE;
 					vso->snap_to_end_vtx = TRUE;
 					break;
 				case KM_RELEASE:
-					vso->snap_n_weld = FALSE;
+					vso->snap_n_merge = FALSE;
 					vso->snap_to_end_vtx = FALSE;
 					break;
 			}
@@ -611,7 +630,7 @@
 	BMesh *bm = em->bm;
 	BMVert *start_vert;
 	BMOperator bmop;
-	BMEditSelection *ese = em->bm->selected.first;
+	BMEditSelection *ese = em->bm->selected.last;
 
 	float distance_t = 0.0f;
 
@@ -620,10 +639,14 @@
 		VertexSlideOp *vso = op->customdata;
 
 		if (bm->totedgesel > 1) {
+			/* Reset selections */
 			EDBM_flag_disable_all(em, BM_ELEM_SELECT);
 			BM_edge_select_set(bm, vso->sel_edge, TRUE);
+			BM_vert_select_set(bm, vso->start_vtx, TRUE);
+
 			EDBM_editselection_store(em, &vso->sel_edge->head);
-			ese = em->bm->selected.first;
+			EDBM_editselection_store(em, &vso->start_vtx->head);			
+			ese = em->bm->selected.last;
 		}
 		distance_t = vso->distance;
 		RNA_float_set(op->ptr, "distance_t", distance_t);
@@ -642,7 +665,7 @@
 	start_vert = (BMVert *)ese->ele;
 
 	/* Prepare operator */
-	if (!EDBM_op_init(em, &bmop, op, "vertslide vert=%e edge=%hfev distance_t=%f", start_vert, BM_ELEM_SELECT, distance_t))  {
+	if (!EDBM_op_init(em, &bmop, op, "vertslide vert=%e edge=%hev distance_t=%f", start_vert, BM_ELEM_SELECT, distance_t))  {
 		return OPERATOR_CANCELLED;
 	}
 	/* Execute operator */




More information about the Bf-blender-cvs mailing list