[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41426] branches/bmesh/blender/source/ blender: enable bmesh subdivide smooth, this isn't working quite right yet.

Campbell Barton ideasman42 at gmail.com
Tue Nov 1 05:31:29 CET 2011


Revision: 41426
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41426
Author:   campbellbarton
Date:     2011-11-01 04:31:25 +0000 (Tue, 01 Nov 2011)
Log Message:
-----------
enable bmesh subdivide smooth, this isn't working quite right yet.
also remove some invalid BMESH_TODO's

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.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

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c	2011-11-01 04:19:21 UTC (rev 41425)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c	2011-11-01 04:31:25 UTC (rev 41426)
@@ -589,7 +589,7 @@
 
 static void bmDM_drawMappedFaces(DerivedMesh *dm, 
 	int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), 
-	void *userData, int useColors, 
+	void *userData, int UNUSED(useColors),
 	int (*setMaterial)(int, void *attribs),
 	int (*compareDrawOptions)(void *userData, int cur_index, int next_index))
 {
@@ -604,9 +604,6 @@
 	GLenum poly_prev= GL_ZERO;
 	GLenum shade_prev= GL_ZERO;
 
-	/*BMESH_TODO*/
-	(void)useColors;
-
 	(void)setMaterial; /* UNUSED */
 
 	/* currently unused -- each original face is handled separately */
@@ -998,13 +995,6 @@
                int (*setMaterial)(int, void *attribs),
                int (*setDrawOptions)(void *userData, int index), void *userData)
 {
-#if 0
-	(void)dm;
-	(void)setMaterial;
-	(void)setDrawOptions;
-	(void)userData;
-#else /*BMESH_TODO*/
-
 	EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
 	BMesh *bm= bmdm->tc->bm;
 	BMEditMesh *em = bmdm->tc;
@@ -1122,7 +1112,6 @@
 			glEnd();
 		}
 	}
-#endif
 }
 
 static void bmDM_drawFacesGLSL(DerivedMesh *dm,

Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2011-11-01 04:19:21 UTC (rev 41425)
+++ branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2011-11-01 04:31:25 UTC (rev 41426)
@@ -165,21 +165,21 @@
 	return NULL;
 }
 /* calculates offset for co, based on fractal, sphere or smooth settings  */
-static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), subdparams *params, float perc,
+static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), const subdparams *params, float perc,
 		     BMVert *vsta, BMVert *vend)
 {
-	float vec1[3], fac;
+	float tvec[3], fac;
 	float *co=NULL, *origco=NULL;
 	int i, totlayer = CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY);
 	
 	BM_Vert_UpdateAllNormals(bm, v);
 
 	origco = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, params->origkey);
-	sub_v3_v3v3(vec1, origco, v->co);
+	sub_v3_v3v3(tvec, 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_v3(co, tvec);
 	}
 
 	for (i=0; i<totlayer; i++) {
@@ -187,7 +187,7 @@
 		
 		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;
+			float len, nor[3], nor1[3], nor2[3], smooth=params->smooth;
 	
 			sub_v3_v3v3(nor, vsta->co, vend->co);
 			len= 0.5f*normalize_v3(nor);
@@ -196,35 +196,23 @@
 			copy_v3_v3(nor2, vend->no);
 	
 			/* cosine angle */
-			fac= nor[0]*nor1[0] + nor[1]*nor1[1] + nor[2]*nor1[2] ;
+			fac=  dot_v3v3(nor, nor1);
+			mul_v3_v3fl(tvec, nor1, fac);
 	
-			vec1[0]= fac*nor1[0];
-			vec1[1]= fac*nor1[1];
-			vec1[2]= fac*nor1[2];
-	
 			/* cosine angle */
-			fac= -nor[0]*nor2[0] - nor[1]*nor2[1] - nor[2]*nor2[2] ;
+			fac= -dot_v3v3(nor, nor2);
+			madd_v3_v3fl(tvec, nor2, fac);
 	
-			vec1[0]+= fac*nor2[0];
-			vec1[1]+= fac*nor2[1];
-			vec1[2]+= fac*nor2[2];
-	
 			/* falloff for multi subdivide */
 			smooth *= sqrtf(fabsf(1.0f - 2.0f*fabsf(0.5f-perc)));
 	
-			vec1[0]*= smooth*len;
-			vec1[1]*= smooth*len;
-			vec1[2]*= smooth*len;
+			mul_v3_fl(tvec, smooth * len);
 	
-			co[0] += vec1[0];
-			co[1] += vec1[1];
-			co[2] += vec1[2];
+			add_v3_v3(co, tvec);
 		}
 		else if(params->beauty & B_SPHERE) { /* subdivide sphere */
 			normalize_v3(co);
-			co[0]*= params->smooth;
-			co[1]*= params->smooth;
-			co[2]*= params->smooth;
+			mul_v3_fl(co, params->smooth);
 		}
 	
 		if(params->beauty & B_FRACTAL) {
@@ -238,11 +226,11 @@
 			mul_v3_fl(vec2, 0.5f);
 			
 			add_v3_v3v3(co2, v->co, params->off);
-			vec1[0] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
-			vec1[1] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
-			vec1[2] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
+			tvec[0] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
+			tvec[1] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
+			tvec[2] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
 			
-			mul_v3_v3(vec2, vec1);
+			mul_v3_v3(vec2, tvec);
 			
 			/*add displacement*/
 			add_v3_v3v3(co, co, vec2);
@@ -254,9 +242,9 @@
 /* percent defines the interpolation, rad and flag are for special options */
 /* results in new vertex with correct coordinate, vertex normal and weight group info */
 static BMVert *bm_subdivide_edge_addvert(BMesh *bm, BMEdge *edge,BMEdge *oedge,
-					subdparams *params, float percent,
-					float percent2,
-					BMEdge **out,BMVert *vsta,BMVert *vend)
+                                         const subdparams *params, float percent,
+                                         float percent2,
+                                         BMEdge **out,BMVert *vsta,BMVert *vend)
 {
 	BMVert *ev;
 	
@@ -286,8 +274,8 @@
 }
 
 static BMVert *subdivideedgenum(BMesh *bm, BMEdge *edge, BMEdge *oedge,
-				int curpoint, int totpoint, subdparams *params,
-				BMEdge **newe, BMVert *vsta, BMVert *vend)
+                                int curpoint, int totpoint, const subdparams *params,
+                                BMEdge **newe, BMVert *vsta, BMVert *vend)
 {
 	BMVert *ev;
 	float percent, percent2 = 0.0f;
@@ -306,8 +294,9 @@
 	return ev;
 }
 
-static void bm_subdivide_multicut(BMesh *bm, BMEdge *edge, subdparams *params, 
-				  BMVert *vsta, BMVert *vend) {
+static void bm_subdivide_multicut(BMesh *bm, BMEdge *edge, const subdparams *params,
+                                  BMVert *vsta, BMVert *vend)
+{
 	BMEdge *eed = edge, *newe, temp = *edge;
 	BMVert *v, ov1=*edge->v1, ov2=*edge->v2, *v1=edge->v1, *v2=edge->v2;
 	int i, numcuts = params->numcuts;
@@ -351,7 +340,8 @@
 
 */
 static void quad_1edge_split(BMesh *bm, BMFace *UNUSED(face),
-			  BMVert **verts, subdparams *params) {
+                             BMVert **verts, const subdparams *params)
+{
 	BMFace *nf;
 	int i, add, numcuts = params->numcuts;
 
@@ -396,7 +386,7 @@
 
 */
 static void quad_2edge_split_path(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, 
-                          subdparams *params)
+                                  const subdparams *params)
 {
 	BMFace *nf;
 	int i, numcuts = params->numcuts;
@@ -424,7 +414,7 @@
 
 */
 static void quad_2edge_split_innervert(BMesh *bm, BMFace *UNUSED(face), BMVert **verts, 
-                          subdparams *params)
+                                       const subdparams *params)
 {
 	BMFace *nf;
 	BMVert *v, *lastv;
@@ -465,7 +455,7 @@
 
 */
 static void quad_2edge_split_fan(BMesh *bm, BMFace *UNUSED(face), BMVert **verts,
-                                 subdparams *params)
+                                 const subdparams *params)
 {
 	BMFace *nf;
 	/* BMVert *v; */               /* UNUSED */
@@ -497,7 +487,7 @@
 
 */
 static void quad_3edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts,
-                          subdparams *params)
+                             const subdparams *params)
 {
 	BMFace *nf;
 	int i, add=0, numcuts = params->numcuts;
@@ -538,7 +528,7 @@
 	   it goes from bottom up
 */
 static void quad_4edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts,
-                          subdparams *params)
+                                 const subdparams *params)
 {
 	BMFace *nf;
 	BMVert *v, *v1, *v2;
@@ -617,7 +607,7 @@
     s    s
 */
 static void tri_1edge_split(BMesh *bm, BMFace *UNUSED(face), BMVert **verts,
-                          subdparams *params)
+                            const subdparams *params)
 {
 	BMFace *nf;
 	int i, numcuts = params->numcuts;
@@ -643,7 +633,7 @@
     s    s
 */
 static void tri_3edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts,
-                          subdparams *params)
+                                const subdparams *params)
 {
 	BMFace *nf;
 	BMEdge *e, *ne, temp;

Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.h	2011-11-01 04:19:21 UTC (rev 41425)
+++ branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.h	2011-11-01 04:31:25 UTC (rev 41426)
@@ -13,7 +13,7 @@
 } subdparams;
 
 typedef void (*subd_pattern_fill_fp)(BMesh *bm, BMFace *face, BMVert **verts, 
-		                     subdparams *params);
+                                     const subdparams *params);
 
 /*
 note: this is a pattern-based edge subdivider.

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2011-11-01 04:19:21 UTC (rev 41425)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2011-11-01 04:31:25 UTC (rev 41426)
@@ -113,9 +113,12 @@
 	Object *obedit= CTX_data_edit_object(C);
 	BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
 	int cuts= RNA_int_get(op->ptr,"number_cuts");
+	float smooth= 0.292f*RNA_float_get(op->ptr, "smoothness");
 	float fractal= RNA_float_get(op->ptr, "fractal")/2.5;
 	int flag= 0;
 
+	if(smooth != 0.0f)
+		flag |= B_SMOOTH;
 	if(fractal != 0.0f)
 		flag |= B_FRACTAL;
 	
@@ -126,7 +129,7 @@
 	}
 	
 	BM_esubdivideflag(obedit, em->bm, BM_SELECT, 
-	                  0.0f, fractal, 
+	                  smooth, fractal,
 	                  ts->editbutflag|flag, 
 	                  cuts, 0, RNA_enum_get(op->ptr, "quadcorner"), 
 	                  RNA_boolean_get(op->ptr, "quadtri"),




More information about the Bf-blender-cvs mailing list