[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59398] trunk/blender/source/blender: edits to new symmetrize tool

Campbell Barton ideasman42 at gmail.com
Fri Aug 23 07:32:43 CEST 2013


Revision: 59398
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59398
Author:   campbellbarton
Date:     2013-08-23 05:32:43 +0000 (Fri, 23 Aug 2013)
Log Message:
-----------
edits to new symmetrize tool
- snap axis-aligned verts to the center.
- expose the threshold for detecting if a vertex is on the axis.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c
    trunk/blender/source/blender/bmesh/operators/bmo_symmetrize.c
    trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c
    trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.h
    trunk/blender/source/blender/editors/mesh/editmesh_tools.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2013-08-23 05:15:12 UTC (rev 59397)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2013-08-23 05:32:43 UTC (rev 59398)
@@ -1129,6 +1129,7 @@
 	 {"dist",         BMO_OP_SLOT_FLT},     /* minimum distance when testing if a vert is exactly on the plane */
 	 {"plane_co", BMO_OP_SLOT_VEC},         /* point on the plane */
 	 {"plane_no", BMO_OP_SLOT_VEC},         /* direction of the plane */
+	 {"use_snap_center",BMO_OP_SLOT_BOOL},  /* snap axis aligned verts to the center */
 	 {"clear_outer",   BMO_OP_SLOT_BOOL},    /* when enabled. remove all geometry on the positive side of the plane */
 	 {"clear_inner",   BMO_OP_SLOT_BOOL},    /* when enabled. remove all geometry on the negative side of the plane */
 	 {{'\0'}},
@@ -1775,6 +1776,7 @@
 	/* slots_in */
 	{{"input", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT | BM_EDGE | BM_FACE}},
 	 {"direction", BMO_OP_SLOT_INT},
+	 {"dist", BMO_OP_SLOT_FLT}, /* minimum distance */
 	 {{'\0'}},
 	},
 	/* slots_out */

Modified: trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c	2013-08-23 05:15:12 UTC (rev 59397)
+++ trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c	2013-08-23 05:32:43 UTC (rev 59398)
@@ -40,6 +40,7 @@
 void bmo_bisect_plane_exec(BMesh *bm, BMOperator *op)
 {
 	const float dist  = BMO_slot_float_get(op->slots_in, "dist");
+	const bool use_snap_center = BMO_slot_bool_get(op->slots_in,  "use_snap_center");
 	const bool clear_outer = BMO_slot_bool_get(op->slots_in,  "clear_outer");
 	const bool clear_inner = BMO_slot_bool_get(op->slots_in,  "clear_inner");
 
@@ -64,7 +65,7 @@
 	BMO_slot_buffer_flag_enable(bm, op->slots_in, "geom", BM_ALL_NOLOOP, ELE_INPUT);
 
 
-	BM_mesh_bisect_plane(bm, plane, true,
+	BM_mesh_bisect_plane(bm, plane, use_snap_center, true,
 	                     ELE_NEW, dist);
 
 

Modified: trunk/blender/source/blender/bmesh/operators/bmo_symmetrize.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_symmetrize.c	2013-08-23 05:15:12 UTC (rev 59397)
+++ trunk/blender/source/blender/bmesh/operators/bmo_symmetrize.c	2013-08-23 05:32:43 UTC (rev 59398)
@@ -39,6 +39,7 @@
 
 void bmo_symmetrize_exec(BMesh *bm, BMOperator *op)
 {
+	const float dist = BMO_slot_float_get(op->slots_in, "dist");
 	const int direction = BMO_slot_int_get(op->slots_in, "direction");
 	const int axis = direction % 3;
 
@@ -63,8 +64,8 @@
 
 	/* Cut in half */
 	BMO_op_initf(bm, &op_bisect, op->flag,
-	             "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b",
-	             op, "input", plane_no, 0.00001f, true);
+	             "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b",
+	             op, "input", plane_no, dist, true, true);
 
 	BMO_op_exec(bm, &op_bisect);
 

Modified: trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c
===================================================================
--- trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c	2013-08-23 05:15:12 UTC (rev 59397)
+++ trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c	2013-08-23 05:32:43 UTC (rev 59398)
@@ -24,6 +24,13 @@
  *  \ingroup bmesh
  *
  * Cut the geometry in half using a plane.
+ *
+ * \par Implementation
+ * This simply works by splitting tagged edges whos verts span either side of
+ * the plane, then splitting faces along their dividing verts.
+ * The only complex case is when a ngon spans the axis multiple times,
+ * in this case we need to do some extra checks to correctly bisect the ngon.
+ * see: #bm_face_bisect_verts
  */
 
 #include <limits.h>
@@ -54,7 +61,7 @@
 
 static int plane_point_test_v3(const float plane[4], const float co[3], const float eps, float *r_depth)
 {
-	const float f = plane_point_side_v3(co, plane);
+	const float f = plane_point_side_v3(plane, co);
 	*r_depth = f;
 
 	if      (f <= -eps) return -1;
@@ -68,26 +75,13 @@
  * later we may want to move this into some hash lookup
  * to a separate struct, but for now we can store in BMesh data */
 
-/**
- * Direction -1/0/1
- */
-#define BM_VERT_DIR(v) ((v)->head.index)
-/**
- * Distance from the plane.
- */
-#define BM_VERT_DIST(v) ((v)->no[0])
+#define BM_VERT_DIR(v)     ((v)->head.index)    /* Direction -1/0/1 */
+#define BM_VERT_DIST(v)    ((v)->no[0])         /* Distance from the plane. */
+#define BM_VERT_SORTVAL(v) ((v)->no[1])         /* Temp value for sorting. */
+#define BM_VERT_LOOPINDEX(v)                    /* The verts index within a face (temp var) */ \
+	(*((unsigned int *)(&(v)->no[2])))
 
 /**
- * Temp value for sorting.
- */
-#define BM_VERT_SORTVAL(v) ((v)->no[1])
-
-/**
- * Temp value for sorting.
- */
-#define BM_VERT_LOOPINDEX(v) (*((unsigned int *)(&(v)->no[2])))
-
-/**
  * Hide flag access
  * (for more readable code since same flag is used differently for vert/edgeface)...
  */
@@ -97,6 +91,7 @@
 BLI_INLINE void vert_is_center_disable(BMVert *v) { BM_elem_flag_disable(v, BM_ELEM_TAG); }
 BLI_INLINE bool vert_is_center_test(BMVert *v) { return (BM_elem_flag_test(v, BM_ELEM_TAG) != 0); }
 
+/* enable when the edge can be cut */
 BLI_INLINE void edge_is_cut_enable(BMEdge *e) { BM_elem_flag_enable(e, BM_ELEM_TAG); }
 BLI_INLINE void edge_is_cut_disable(BMEdge *e) { BM_elem_flag_disable(e, BM_ELEM_TAG); }
 BLI_INLINE bool edge_is_cut_test(BMEdge *e) { return (BM_elem_flag_test(e, BM_ELEM_TAG) != 0); }
@@ -244,7 +239,7 @@
 				float co_mid[2];
 
 				/* geometric test before doing face lookups,
-				 * find if the split */
+				 * find if the split spans a filled region of the polygon. */
 				mid_v2_v2v2(co_mid,
 				            face_verts_proj_2d[BM_VERT_LOOPINDEX(v_a)],
 				            face_verts_proj_2d[BM_VERT_LOOPINDEX(v_b)]);
@@ -292,14 +287,15 @@
 
 }
 
-
 /* -------------------------------------------------------------------- */
 /* Main logic */
 
 /**
  * \param use_tag  Only bisect tagged edges and faces.
+ * \param use_snap  Snap verts onto the plane.
  */
-void BM_mesh_bisect_plane(BMesh *bm, float plane[4], const bool use_tag,
+void BM_mesh_bisect_plane(BMesh *bm, float plane[4],
+                          const bool use_snap_center, const bool use_tag,
                           const short oflag_new, const float eps)
 {
 	unsigned int einput_len;
@@ -314,8 +310,12 @@
 	BMIter iter;
 
 	BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-		BM_VERT_DIR(v) = plane_point_test_v3(v->co, plane, eps, &(BM_VERT_DIST(v)));
 		vert_is_center_disable(v);
+
+		BM_VERT_DIR(v) = plane_point_test_v3(plane, v->co, eps, &(BM_VERT_DIST(v)));
+		if (use_snap_center && (BM_VERT_DIR(v) == 0)) {
+			closest_to_plane_v3(v->co, plane, v->co);
+		}
 	}
 
 	if (use_tag) {

Modified: trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.h
===================================================================
--- trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.h	2013-08-23 05:15:12 UTC (rev 59397)
+++ trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.h	2013-08-23 05:32:43 UTC (rev 59398)
@@ -27,7 +27,8 @@
  *  \ingroup bmesh
  */
 
-void BM_mesh_bisect_plane(BMesh *bm, float plane[4], const bool use_tag,
+void BM_mesh_bisect_plane(BMesh *bm, float plane[4],
+                          const bool use_snap_center, const bool use_tag,
                           const short oflag_new, const float eps);
 
 #endif /* __BMESH_BISECT_PLANE_H__ */

Modified: trunk/blender/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_tools.c	2013-08-23 05:15:12 UTC (rev 59397)
+++ trunk/blender/source/blender/editors/mesh/editmesh_tools.c	2013-08-23 05:32:43 UTC (rev 59398)
@@ -4441,8 +4441,11 @@
 	BMEditMesh *em = BKE_editmesh_from_object(obedit);
 	BMOperator bmop;
 
-	EDBM_op_init(em, &bmop, op, "symmetrize input=%hvef direction=%i",
-	             BM_ELEM_SELECT, RNA_enum_get(op->ptr, "direction"));
+	const float thresh = RNA_float_get(op->ptr, "threshold");
+
+	EDBM_op_init(em, &bmop, op,
+	             "symmetrize input=%hvef direction=%i dist=%f",
+	             BM_ELEM_SELECT, RNA_enum_get(op->ptr, "direction"), thresh);
 	BMO_op_exec(em->bm, &bmop);
 
 	EDBM_flag_disable_all(em, BM_ELEM_SELECT);
@@ -4476,6 +4479,7 @@
 	ot->prop = RNA_def_enum(ot->srna, "direction", symmetrize_direction_items,
 	                        BMO_SYMMETRIZE_NEGATIVE_X,
 	                        "Direction", "Which sides to copy from and to");
+	RNA_def_float(ot->srna, "threshold", 0.0001, 0.0, 10.0, "Threshold", "", 0.00001, 0.1);
 }
 
 static int mesh_symmetry_snap_exec(bContext *C, wmOperator *op)




More information about the Bf-blender-cvs mailing list