[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35832] branches/bmesh/blender: =bmesh=

Joseph Eagar joeedh at gmail.com
Mon Mar 28 02:29:45 CEST 2011


Revision: 35832
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35832
Author:   joeedh
Date:     2011-03-28 00:29:45 +0000 (Mon, 28 Mar 2011)
Log Message:
-----------
=bmesh=

Improved edge subdivide.  The last tool panel
is a bit clearer, with a "quad/tri" checkbox
(that, in addition to turning on the old 
 singe-edge-triangluation feature also 
 automatically switches cornervert to Inner Vert
 if it is Straight, to avoid producing ngons).
 
I also rewrote fractal to be more likes its name, and
 removed the "smoothness" parameter (which never
 worked, anyway, even in trunk).  Also removed the
 grid fill paramter, it wasn't all that useful.

Modified Paths:
--------------
    branches/bmesh/blender/release/scripts/ui/space_view3d.py
    branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
    branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
    branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.h
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
    branches/bmesh/blender/source/blender/editors/mesh/loopcut.c

Modified: branches/bmesh/blender/release/scripts/ui/space_view3d.py
===================================================================
--- branches/bmesh/blender/release/scripts/ui/space_view3d.py	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/release/scripts/ui/space_view3d.py	2011-03-28 00:29:45 UTC (rev 35832)
@@ -557,7 +557,7 @@
         layout.operator("curve.select_less")
 
 
-class VIEW3D_MT_select_edit_surface(bpy.types.Menu):
+class sVIEW3D_MT_select_edit_surface(bpy.types.Menu):
     bl_label = "Select"
 
     def draw(self, context):
@@ -1366,7 +1366,6 @@
         layout.operator_context = 'INVOKE_REGION_WIN'
 
         layout.operator("mesh.subdivide", text="Subdivide")
-        layout.operator("mesh.subdivide", text="Subdivide Smooth").smoothness = 1.0
         layout.operator("mesh.merge", text="Merge...")
         layout.operator("mesh.remove_doubles")
         layout.operator("mesh.hide", text="Hide")

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c	2011-03-28 00:29:45 UTC (rev 35832)
@@ -1450,8 +1450,9 @@
 	int size = typeInfo->size * totelem, flag = 0, index = data->totlayer;
 	void *newlayerdata;
 
-	if (!typeInfo->defaultname && CustomData_has_layer(data, type))
+	if (!typeInfo->defaultname && CustomData_has_layer(data, type)) {
 		return &data->layers[CustomData_get_layer_index(data, type)];
+	}
 
 	if((alloctype == CD_ASSIGN) || (alloctype == CD_REFERENCE)) {
 		newlayerdata = layerdata;

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h	2011-03-28 00:29:45 UTC (rev 35832)
@@ -204,6 +204,7 @@
 
 /*update a vert normal (but not the faces incident on it)*/
 void BM_Vert_UpdateNormal ( BMesh *bm, BMVert *v );
+void BM_Vert_UpdateAllNormals ( BMesh *bm, BMVert *v );
 
 void BM_flip_normal ( BMesh *bm, BMFace *f );
 
@@ -232,11 +233,12 @@
 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_free_data_layer ( BMesh *em, CustomData *data, int type );
+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_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);
 void BM_SetCDf(struct CustomData *cd, void *element, int type, float val);
 

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2011-03-28 00:29:45 UTC (rev 35832)
@@ -81,7 +81,7 @@
 void BMOP_DupeFromFlag(struct BMesh *bm, int etypeflag, int flag);
 void BM_esubdivideflag(struct Object *obedit, BMesh *bm, int flag, float smooth, 
 		       float fractal, int beauty, int numcuts, int seltype,
-		       int cornertype, int singleedge, int gridfill);
+		       int cornertype, int singleedge, int gridfill, int seed);
 void BM_extrudefaceflag(BMesh *bm, int flag);
 
 /*this next one return 1 if they did anything, or zero otherwise.

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2011-03-28 00:29:45 UTC (rev 35832)
@@ -118,7 +118,10 @@
 			v2loop = (BMLoop*)(l->prev);
 			
 		}
-
+		
+		if (!v1loop || !v2loop)
+			return;
+		
 		src[0] = v1loop->head.data;
 		src[1] = v2loop->head.data;					
 
@@ -719,6 +722,18 @@
 	if (olddata.layers) MEM_freeN(olddata.layers);
 }
 
+void BM_free_data_layer_n(BMesh *bm, CustomData *data, int type, int n)
+{
+	CustomData olddata;
+
+	olddata= *data;
+	olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL;
+	CustomData_free_layer(data, type, 0, CustomData_get_layer_index_n(data, type, n));
+	
+	update_data_blocks(bm, &olddata, data);
+	if (olddata.layers) MEM_freeN(olddata.layers);
+}
+
 float BM_GetCDf(CustomData *cd, void *element, int type)
 {
 	if (CustomData_has_layer(cd, type)) {

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2011-03-28 00:29:45 UTC (rev 35832)
@@ -517,8 +517,8 @@
 	}
 
 	/*v->nv->v2*/
-	BM_Data_Facevert_Edgeinterp(bm,v2, v, nv, e, percent);	
-	BM_Data_Interp_From_Verts(bm, v2, v, nv, percent);
+	BM_Data_Facevert_Edgeinterp(bm, v2, v, nv, e, percent);	
+	BM_Data_Interp_From_Verts(bm, v, v2, nv, percent);
 
 	if (CustomData_has_layer(&bm->ldata, CD_MDISPS) && e->l && nv) {
 		int i, j;

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2011-03-28 00:29:45 UTC (rev 35832)
@@ -657,6 +657,7 @@
 	{BMOP_OPSLOT_FLT, "smooth"},
 	{BMOP_OPSLOT_FLT, "fractal"},
 	{BMOP_OPSLOT_INT, "beauty"},
+	{BMOP_OPSLOT_INT, "seed"},
 	{BMOP_OPSLOT_MAPPING, "custompatterns"},
 	{BMOP_OPSLOT_MAPPING, "edgepercents"},
 	

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c	2011-03-28 00:29:45 UTC (rev 35832)
@@ -445,9 +445,28 @@
 
 	if (!len) return;
 
-	mul_v3_fl(v->no, 1.0f/(int)len);
+	mul_v3_fl(v->no, 1.0f/(float)len);
 }
 
+void BM_Vert_UpdateAllNormals(BMesh *bm, BMVert *v)
+{
+	BMIter iter;
+	BMFace *f;
+	int len=0;
+
+	v->no[0] = v->no[1] = v->no[2] = 0.0f;
+
+	f = BMIter_New(&iter, bm, BM_FACES_OF_VERT, v);
+	for (; f; f=BMIter_Step(&iter), len++) {
+		BM_Face_UpdateNormal(bm, f);
+		add_v3_v3v3(v->no, f->no, v->no);
+	}
+
+	if (!len) return;
+
+	mul_v3_fl(v->no, 1.0f/(float)len);
+}
+
 void bmesh_update_face_normal(BMesh *bm, BMFace *f, float (*projectverts)[3])
 {
 	BMIter iter;

Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2011-03-27 23:19:32 UTC (rev 35831)
+++ branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2011-03-28 00:29:45 UTC (rev 35832)
@@ -86,6 +86,59 @@
     split the edge only?
 */
 
+#if 0 //misc. code, maps a parametric coordinate to a fractal line
+float lastrnd[3], vec2[3] = {0.0f, 0.0f, 0.0f};
+int seed = BLI_rand();
+int d, i, j, dp, lvl, wid;
+float df;
+
+BLI_srandom(seed);
+
+wid = (params->numcuts+2);
+dp = perc*wid;
+wid /= 2;
+d = lvl = 0;
+while (1) {
+	if (d > dp) {
+		d -= wid;
+	} else if (d < dp) {
+		d += wid;
+	} else {
+		break;
+	}
+	
+	
+	wid = MAX2((wid/2), 1);
+	lvl++;
+}
+
+zero_v3(vec1);
+df = 1.0f;
+for (i=0; i<lvl; i++, df /= 4.0f) {
+	int tot = (1<<i);
+	
+	lastrnd[0] = BLI_drand()-0.5f;
+	lastrnd[1] = BLI_drand()-0.5f;
+	lastrnd[2] = BLI_drand()-0.5f;
+	for (j=0; j<tot; j++) {
+		float a, b, rnd[3], rnd2[3];
+		
+		rnd[0] = BLI_drand()-0.5f;
+		rnd[1] = BLI_drand()-0.5f;
+		rnd[2] = BLI_drand()-0.5f;
+		
+		a = (float)j*(float)((float)params->numcuts/(float)tot);
+		b = (float)(j+1)*(float)((float)params->numcuts/(float)tot);
+		if (d >= a && d <= b) {
+			interp_v3_v3v3(rnd2, lastrnd, rnd, (((float)d)-a)/(b-a));
+			mul_v3_fl(rnd2, df);
+			add_v3_v3(vec1, rnd2);
+		}
+		
+		copy_v3_v3(lastrnd, rnd);
+	}
+}
+#endif
 /*connects face with smallest len, which I think should always be correct for
   edge subdivision*/
 BMEdge *connect_smallest_face(BMesh *bm, BMVert *v1, BMVert *v2, BMFace **nf) {
@@ -115,60 +168,89 @@
 	return NULL;
 }
 /* calculates offset for co, based on fractal, sphere or smooth settings  */
-static void alter_co(float *co, BMEdge *UNUSED(edge), subdparams *params, float perc,
+static void alter_co(BMesh *bm, BMVert *v, BMEdge *origed, subdparams *params, float perc,
 		     BMVert *vsta, BMVert *vend)
 {
 	float vec1[3], fac;
+	float *co=NULL, *origco=NULL;
+	int i, totlayer = CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY);
+	
+	BM_Vert_UpdateAllNormals(bm, v);
 
-	if(params->beauty & B_SMOOTH) {
-		/* we calculate an offset vector vec1[], to be added to *co */
-		float len, fac, nor[3], nor1[3], nor2[3], smooth=params->smooth;
+	origco = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, params->origkey);
+	sub_v3_v3v3(vec1, origco, v->co);
+	
+	for (i=0; i<totlayer; i++) {
+		co = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, i);
+		sub_v3_v3(co, vec1);
+	}
 
-		sub_v3_v3v3(nor, vsta->co, vend->co);
-		len= 0.5f*normalize_v3(nor);
+	for (i=0; i<totlayer; i++) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list