[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47155] branches/soc-2012-sushi/source/ blender: Added midpoint snapping.

luke frisken l.frisken at gmail.com
Tue May 29 09:09:11 CEST 2012


Revision: 47155
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47155
Author:   lfrisken
Date:     2012-05-29 07:09:11 +0000 (Tue, 29 May 2012)
Log Message:
-----------
Added midpoint snapping. Will need a new icon for this. Using edge snap
icon as a placeholder.

Modified Paths:
--------------
    branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c
    branches/soc-2012-sushi/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2012-sushi/source/blender/makesrna/intern/rna_scene.c

Modified: branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c
===================================================================
--- branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c	2012-05-29 06:58:54 UTC (rev 47154)
+++ branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c	2012-05-29 07:09:11 UTC (rev 47155)
@@ -746,8 +746,8 @@
 static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
 {
 	if (t->spacetype == SPACE_VIEW3D) {
-		float loc[3];
-		float no[3];
+		float loc[3]; //temporary snapPoint location
+		float no[3]; //snapNormal
 		float mval[2];
 		int found = 0;
 		int dist = SNAP_MIN_DISTANCE; // Use a user defined value here
@@ -1167,6 +1167,54 @@
 	return retval;
 }
 
+static int snapEdgeMiddle(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2no[3], float obmat[][4], float timat[][3],
+					const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], const float mval[2],
+					float r_loc[3], float r_no[3], int *r_dist, float *r_depth)
+{
+	/*TODO: still need to calculate normal output properly using snapEdge code*/
+	float middle[3];
+	int retval = 0;
+	float dvec[3];
+
+
+	mid_v3_v3v3(middle, v1co, v2co); /*find the spot in the middle of the two edge vertices*/
+
+	sub_v3_v3v3(dvec, middle, ray_start_local);
+
+	if (dot_v3v3(ray_normal_local, dvec) > 0) {
+		float location[3];
+		float new_depth;
+		int screen_loc[2];
+		int new_dist;
+
+		copy_v3_v3(location, middle);
+
+		mul_m4_v3(obmat, location);
+
+		new_depth = len_v3v3(location, ray_start);
+
+		project_int(ar, location, screen_loc);
+		new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]);
+
+		if (new_dist <= *r_dist && new_depth < *r_depth) {
+			*r_depth = new_depth;
+			retval = 1;
+
+			copy_v3_v3(r_loc, location);
+
+			if (r_no) {
+				normal_short_to_float_v3(r_no, v1no);
+				mul_m3_v3(timat, r_no);
+				normalize_v3(r_no);
+			}
+
+			*r_dist = new_dist;
+		}
+	}
+
+	return retval;
+}
+
 static int snapVertex(ARegion *ar, float vco[3], short vno[3], float obmat[][4], float timat[][3],
                       const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], const float mval[2],
                       float r_loc[3], float r_no[3], int *r_dist, float *r_depth)
@@ -1500,6 +1548,8 @@
 							else {
 								eed = EDBM_edge_at_index(em, index);
 								
+								/*if edge is hidden, or vertex on either end of the edge is selected, then
+								  don't use it to check for snapping*/
 								if (eed && (BM_elem_flag_test(eed, BM_ELEM_HIDDEN) ||
 									BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) || 
 									BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)))
@@ -1519,6 +1569,61 @@
 					}
 					break;
 				}
+				case SCE_SNAP_MODE_EDGE_MIDDLE:
+				{
+					MVert *verts = dm->getVertArray(dm);
+					MEdge *edges = dm->getEdgeArray(dm);
+					int totedge = dm->getNumEdges(dm);
+					int *index_array = NULL;
+					int index = 0;
+					int i;
+
+					if (em != NULL) {
+						index_array = dm->getEdgeDataArray(dm, CD_ORIGINDEX);
+						EDBM_index_arrays_init(em, 0, 1, 0);
+					}
+
+					for ( i = 0; i < totedge; i++) {
+						BMEdge *eed = NULL;
+						MEdge *e = edges + i;
+
+						test = 1; /* reset for every vert */
+
+						if (em != NULL) {
+							if (index_array) {
+								index = index_array[i];
+							}
+							else {
+								index = i;
+							}
+
+							if (index == ORIGINDEX_NONE) {
+								test = 0;
+							}
+							else {
+								eed = EDBM_edge_at_index(em, index);
+
+								/*if edge is hidden, or vertex on either end of the edge is selected, then
+								  don't use it to check for snapping*/
+								if (eed && (BM_elem_flag_test(eed, BM_ELEM_HIDDEN) ||
+									BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
+									BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)))
+								{
+									test = 0;
+								}
+							}
+						}
+
+						if (test) {
+							retval |= snapEdgeMiddle(ar, verts[e->v1].co, verts[e->v1].no, verts[e->v2].co, verts[e->v2].no, obmat, timat, ray_start, ray_start_local, ray_normal_local, mval, r_loc, r_no, r_dist, r_depth);
+						}
+					}
+
+					if (em != NULL) {
+						EDBM_index_arrays_free(em);
+					}
+					break;
+				}
 			}
 		}
 	}

Modified: branches/soc-2012-sushi/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2012-sushi/source/blender/makesdna/DNA_scene_types.h	2012-05-29 06:58:54 UTC (rev 47154)
+++ branches/soc-2012-sushi/source/blender/makesdna/DNA_scene_types.h	2012-05-29 07:09:11 UTC (rev 47155)
@@ -1359,6 +1359,7 @@
 #define SCE_SNAP_MODE_EDGE		2
 #define SCE_SNAP_MODE_FACE		3
 #define SCE_SNAP_MODE_VOLUME	4
+#define SCE_SNAP_MODE_EDGE_MIDDLE	8
 
 /* toolsettings->selectmode */
 #define SCE_SELECT_VERTEX	1 /* for mesh */

Modified: branches/soc-2012-sushi/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2012-sushi/source/blender/makesrna/intern/rna_scene.c	2012-05-29 06:58:54 UTC (rev 47154)
+++ branches/soc-2012-sushi/source/blender/makesrna/intern/rna_scene.c	2012-05-29 07:09:11 UTC (rev 47155)
@@ -121,6 +121,7 @@
 	{SCE_SNAP_MODE_INCREMENT, "INCREMENT", ICON_SNAP_INCREMENT, "Increment", "Snap to increments of grid"},
 	{SCE_SNAP_MODE_VERTEX, "VERTEX", ICON_SNAP_VERTEX, "Vertex", "Snap to vertices"},
 	{SCE_SNAP_MODE_EDGE, "EDGE", ICON_SNAP_EDGE, "Edge", "Snap to edges"},
+    {SCE_SNAP_MODE_EDGE_MIDDLE, "EDGE_MIDDLE", ICON_SNAP_EDGE, "Edge Middle", "Snap to middle of edges"},
 	{SCE_SNAP_MODE_FACE, "FACE", ICON_SNAP_FACE, "Face", "Snap to faces"},
 	{SCE_SNAP_MODE_VOLUME, "VOLUME", ICON_SNAP_VOLUME, "Volume", "Snap to volume"},
 	{0, NULL, 0, NULL, NULL}




More information about the Bf-blender-cvs mailing list