[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41289] branches/bmesh/blender/source/ blender: - smooth tool now works for mirror.

Campbell Barton ideasman42 at gmail.com
Wed Oct 26 09:41:56 CEST 2011


Revision: 41289
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41289
Author:   campbellbarton
Date:     2011-10-26 07:41:56 +0000 (Wed, 26 Oct 2011)
Log Message:
-----------
- smooth tool now works for mirror.
- mirror was selecting verts from 0.4 distance which causes errors.
- utility function EDBM_ApplyMirrorCache(...)

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
    branches/bmesh/blender/source/blender/editors/include/ED_mesh.h
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
    branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h	2011-10-26 03:26:52 UTC (rev 41288)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h	2011-10-26 07:41:56 UTC (rev 41289)
@@ -243,10 +243,10 @@
 void BM_loop_interp_multires(BMesh *bm, BMLoop *target, BMFace *source);
 void BM_vert_interp_from_face(BMesh *bm, BMVert *v, BMFace *source);
 
-void BM_Data_Interp_From_Verts (struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, float fac );
-void BM_Data_Facevert_Edgeinterp (struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, struct BMEdge *e1, float fac );
-void BM_add_data_layer (BMesh *em, CustomData *data, int type );
-void BM_add_data_layer_named (BMesh *bm, CustomData *data, int type, char *name );
+void BM_Data_Interp_From_Verts (struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, float fac);
+void BM_Data_Facevert_Edgeinterp (struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, struct BMEdge *e1, float fac);
+void BM_add_data_layer (BMesh *em, CustomData *data, int type);
+void BM_add_data_layer_named (BMesh *bm, CustomData *data, int type, const char *name);
 void BM_free_data_layer (BMesh *em, CustomData *data, int type );
 void BM_free_data_layer_n(BMesh *bm, CustomData *data, int type, int n);
 float BM_GetCDf(struct CustomData *cd, void *element, int type);

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2011-10-26 03:26:52 UTC (rev 41288)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2011-10-26 07:41:56 UTC (rev 41289)
@@ -893,7 +893,7 @@
 	if (olddata.layers) MEM_freeN(olddata.layers);
 }
 
-void BM_add_data_layer_named(BMesh *bm, CustomData *data, int type, char *name)
+void BM_add_data_layer_named(BMesh *bm, CustomData *data, int type, const char *name)
 {
 	CustomData olddata;
 

Modified: branches/bmesh/blender/source/blender/editors/include/ED_mesh.h
===================================================================
--- branches/bmesh/blender/source/blender/editors/include/ED_mesh.h	2011-10-26 03:26:52 UTC (rev 41288)
+++ branches/bmesh/blender/source/blender/editors/include/ED_mesh.h	2011-10-26 07:41:56 UTC (rev 41289)
@@ -127,6 +127,7 @@
   is bad.*/
 struct BMVert *EDBM_GetMirrorVert(struct BMEditMesh *em, struct BMVert *v);
 void EDBM_EndMirrorCache(struct BMEditMesh *em);
+void EDBM_ApplyMirrorCache(struct BMEditMesh *em, const int sel_from, const int sel_to);
 
 void EDBM_RecalcNormals(struct BMEditMesh *em);
 

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2011-10-26 03:26:52 UTC (rev 41288)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2011-10-26 07:41:56 UTC (rev 41289)
@@ -163,6 +163,8 @@
 
 	/* properties */
 	RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10);
+	/* BMESH_TODO, this currently does nothing, just add to stop UI from erroring out! */
+	RNA_def_float(ot->srna, "smoothness", 0.0f, 0.0f, FLT_MAX, "Smoothness", "Smoothness factor (BMESH TODO)", 0.0f, 1.0f);
 
 	RNA_def_boolean(ot->srna, "quadtri", 0, "Quad/Tri Mode", "Tries to prevent ngons");
 	RNA_def_enum(ot->srna, "quadcorner", prop_mesh_cornervert_types, SUBD_STRAIGHT_CUT, "Quad Corner Type", "How to subdivide quad corners (anything other then Straight Cut will prevent ngons)");
@@ -1609,6 +1611,11 @@
 	int mirrx=0, mirry=0, mirrz=0;
 	int i, repeat;
 
+	/* mirror before smooth */
+	if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) {
+		EDBM_CacheMirrorVerts(em);
+	}
+
 	/* if there is a mirror modifier with clipping, flag the verts that
 	 * are within tolerance of the plane(s) of reflection 
 	 */
@@ -1639,8 +1646,11 @@
 		}
 	}
 
-	//BMESH_TODO: need to handle the x-axis editing option here properly.
-	//should probably make a helper function for that? I dunno.
+	/* apply mirror */
+	if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) {
+		EDBM_ApplyMirrorCache(em, BM_SELECT, 0);
+		EDBM_EndMirrorCache(em);
+	}
 
 	DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
 	WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c	2011-10-26 03:26:52 UTC (rev 41288)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c	2011-10-26 07:41:56 UTC (rev 41289)
@@ -785,7 +785,9 @@
 	return em && em->bm->totface && CustomData_has_layer(&em->bm->ldata, CD_MLOOPCOL);
 }
 
-
+/* BM_SEARCH_MAXDIST is too big, copied from 2.6x MOC_THRESH, should become a
+ * preference */
+#define BM_SEARCH_MAXDIST_MIRR 0.00002f
 void EDBM_CacheMirrorVerts(BMEditMesh *em)
 {
 	Mesh *me = em->me;
@@ -804,8 +806,8 @@
 		em->mirr_free_arrays = 1;
 	}
 
-	if (!CustomData_get_layer_named(&em->bm->vdata, CD_PROP_INT, (char*)"__mirror_index")) {
-		BM_add_data_layer_named(em->bm, &em->bm->vdata, CD_PROP_INT, (char*)"__mirror_index");
+	if (!CustomData_get_layer_named(&em->bm->vdata, CD_PROP_INT, "__mirror_index")) {
+		BM_add_data_layer_named(em->bm, &em->bm->vdata, CD_PROP_INT, "__mirror_index");
 	}
 
 	li = CustomData_get_named_layer_index(&em->bm->vdata, CD_PROP_INT, "__mirror_index");
@@ -821,13 +823,17 @@
 			continue;
 		
 		mirr = topo ?
-			BMBVH_FindClosestVertTopo(tree, co, BM_SEARCH_MAXDIST, v) :
-			BMBVH_FindClosestVert(tree, co, BM_SEARCH_MAXDIST);
+			BMBVH_FindClosestVertTopo(tree, co, BM_SEARCH_MAXDIST_MIRR, v) :
+			BMBVH_FindClosestVert(tree, co, BM_SEARCH_MAXDIST_MIRR);
+
 		if (mirr && mirr != v) {
 			*idx = BM_GetIndex(mirr);
 			idx = CustomData_bmesh_get_layer_n(&em->bm->vdata,mirr->head.data, li);
 			*idx = BM_GetIndex(v);
-		} else *idx = -1;
+		}
+		else {
+			*idx = -1;
+		}
 	}
 
 	BMBVH_FreeBVH(tree);
@@ -857,3 +863,23 @@
 		em->vert_index = NULL;
 	}
 }
+
+void EDBM_ApplyMirrorCache(BMEditMesh *em, const int sel_from, const int sel_to)
+{
+	BMIter iter;
+	BMVert *v;
+
+	BLI_assert(em->vert_index != NULL);
+
+	BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+		if (BM_TestHFlag(v, BM_SELECT) == sel_from) {
+			BMVert *mirr= EDBM_GetMirrorVert(em, v);
+			if (mirr) {
+				if (BM_TestHFlag(mirr, BM_SELECT) == sel_to) {
+					copy_v3_v3(mirr->co, v->co);
+					mirr->co[0] *= -1.0f;
+				}
+			}
+		}
+	}
+}




More information about the Bf-blender-cvs mailing list