[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41970] branches/bmesh/blender/source/ blender: speedup for editmesh tesselation (approx 4. 4x speedup in optimized builds),

Campbell Barton ideasman42 at gmail.com
Fri Nov 18 17:06:21 CET 2011


Revision: 41970
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41970
Author:   campbellbarton
Date:     2011-11-18 16:06:20 +0000 (Fri, 18 Nov 2011)
Log Message:
-----------
speedup for editmesh tesselation (approx 4.4x speedup in optimized builds),
this is important because it runs while transforming the mesh in editmode.

also made this code a bit more efficient.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
    branches/bmesh/blender/source/blender/bmesh/bmesh_class.h
    branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c	2011-11-18 15:52:00 UTC (rev 41969)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c	2011-11-18 16:06:20 UTC (rev 41970)
@@ -130,8 +130,12 @@
 
 static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm)
 {
+	/* use this to avoid locking pthread for _every_ polygon
+	 * and calling the fill function */
+#define USE_TESSFACE_SPEEDUP
+
 	BMesh *bm = tm->bm;
-	BMLoop **looptris = NULL;
+	BMLoop *(*looptris)[3]= NULL;
 	BLI_array_declare(looptris);
 	BMIter iter, liter;
 	BMFace *f;
@@ -142,69 +146,99 @@
 
 	f = BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL);
 	for ( ; f; f=BMIter_Step(&iter)) {
-		EditVert *v, *lastv=NULL, *firstv=NULL;
-		EditEdge *e;
-		EditFace *efa;
-
 		/*don't consider two-edged faces*/
-		if (f->len < 3) continue;
-		
-		BLI_begin_edgefill();
-		/*scanfill time*/
-		l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
-		for (j=0; l; l=BMIter_Step(&liter), j++) {
-			/*mark order*/
-			l->_index = j;
+		if (f->len < 3) {
+			/* do nothing */
+		}
 
-			v = BLI_addfillvert(l->v->co);
-			v->tmp.p = l;
-			
-			if (lastv) {
-				e = BLI_addfilledge(lastv, v);
+#ifdef USE_TESSFACE_SPEEDUP
+
+		/* no need to ensure the loop order, we know its ok */
+
+		else if (f->len == 3) {
+			BLI_array_growone(looptris);
+			l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
+			for (j=0; l; l=BMIter_Step(&liter), j++) {
+				looptris[i][j] = l;
 			}
+			i += 1;
+		}
+		else if (f->len == 4) {
+			BMLoop *ltmp[4];
+			BLI_array_growitems(looptris, 2);
 
-			lastv = v;
-			if (firstv==NULL) firstv = v;
+			l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
+			for (j=0; l; l=BMIter_Step(&liter), j++) {
+				ltmp[j] = l;
+			}
+
+			looptris[i][0] = ltmp[0];
+			looptris[i][1] = ltmp[1];
+			looptris[i][2] = ltmp[2];
+			i += 1;
+
+			looptris[i][0] = ltmp[0];
+			looptris[i][1] = ltmp[2];
+			looptris[i][2] = ltmp[3];
+			i += 1;
 		}
 
-		/*complete the loop*/
-		BLI_addfilledge(firstv, v);
+#endif /* USE_TESSFACE_SPEEDUP */
 
-		BLI_edgefill(2);
-		
-		for (efa = fillfacebase.first; efa; efa=efa->next) {
-			BMLoop *l1, *l2, *l3;
+		else {
+			EditVert *v, *lastv=NULL, *firstv=NULL;
+			EditEdge *e;
+			EditFace *efa;
 
-			BLI_array_growone(looptris);
-			BLI_array_growone(looptris);
-			BLI_array_growone(looptris);
-			
-			looptris[i*3] = l1 = efa->v1->tmp.p;
-			looptris[i*3+1] = l2 = efa->v2->tmp.p;
-			looptris[i*3+2] = l3 = efa->v3->tmp.p;
-			
-			if (l1->_index > l2->_index) {
-				SWAP(BMLoop*, l1, l2);
+			BLI_begin_edgefill();
+			/*scanfill time*/
+			l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
+			for (j=0; l; l=BMIter_Step(&liter), j++) {
+				/*mark order*/
+				l->_index = j;
+
+				v = BLI_addfillvert(l->v->co);
+				v->tmp.p = l;
+
+				if (lastv) {
+					e = BLI_addfilledge(lastv, v);
+				}
+
+				lastv = v;
+				if (firstv==NULL) firstv = v;
 			}
-			if (l2->_index > l3->_index) {
-				SWAP(BMLoop*, l2, l3);
+
+			/*complete the loop*/
+			BLI_addfilledge(firstv, v);
+
+			BLI_edgefill(2);
+
+			for (efa = fillfacebase.first; efa; efa=efa->next) {
+				BMLoop *l1= efa->v1->tmp.p;
+				BMLoop *l2= efa->v2->tmp.p;
+				BMLoop *l3= efa->v3->tmp.p;
+
+				BLI_array_growone(looptris);
+
+				if (l1->_index > l2->_index) { SWAP(BMLoop*, l1, l2); }
+				if (l2->_index > l3->_index) { SWAP(BMLoop*, l2, l3); }
+				if (l1->_index > l2->_index) { SWAP(BMLoop*, l1, l2); }
+
+				looptris[i][0] = l1;
+				looptris[i][1] = l2;
+				looptris[i][2] = l3;
+				i += 1;
 			}
-			if (l1->_index > l2->_index) {
-				SWAP(BMLoop*, l1, l2);
-			}
-			
-			looptris[i*3] = l1;
-			looptris[i*3+1] = l2;
-			looptris[i*3+2] = l3;
 
-			i += 1;
+			BLI_end_edgefill();
 		}
-
-		BLI_end_edgefill();
 	}
 
 	tm->tottri = i;
-	tm->looptris = (BMLoop *(*)[3])looptris;
+	tm->looptris = looptris;
+
+#undef USE_TESSFACE_SPEEDUP
+
 }
 
 void BMEdit_RecalcTesselation(BMEditMesh *em)

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2011-11-18 15:52:00 UTC (rev 41969)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2011-11-18 16:06:20 UTC (rev 41970)
@@ -2430,6 +2430,9 @@
 	}
 
 	return totface;
+
+#undef USE_TESSFACE_SPEEDUP
+
 }
 
 /*

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_class.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_class.h	2011-11-18 15:52:00 UTC (rev 41969)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_class.h	2011-11-18 16:06:20 UTC (rev 41970)
@@ -97,7 +97,7 @@
 	struct BMLoop *radial_next, *radial_prev;
 	
 	/*private variables*/
-	struct BMLoop *next, *prev; /*won't be able to use listbase API, ger, due to head*/\
+	struct BMLoop *next, *prev; /*won't be able to use listbase API, ger, due to head*/
 	int _index; /*used for sorting during tesselation*/
 } BMLoop;
 
@@ -108,10 +108,10 @@
 
 typedef struct BMFace {
 	BMHeader head;
-	int len; /*includes all boundary loops*/\
-	int totbounds; /*total boundaries, is one plus the number of holes in the face*/\
+	int len; /*includes all boundary loops*/
+	int totbounds; /*total boundaries, is one plus the number of holes in the face*/
 	ListBase loops;
-	float no[3]; /*yes, we do store this here*/\
+	float no[3]; /*yes, we do store this here*/
 	short mat_nr;
 } BMFace;
 

Modified: branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c	2011-11-18 15:52:00 UTC (rev 41969)
+++ branches/bmesh/blender/source/blender/makesrna/intern/rna_mesh.c	2011-11-18 16:06:20 UTC (rev 41970)
@@ -884,7 +884,7 @@
 
 static void rna_MeshColorLayer_name_set(PointerRNA *ptr, const char *value)
 {
-	Mesh *me = rna_mesh(ptr);
+	/* Mesh *me = rna_mesh(ptr); */ /* UNUSED */
 	/* CustomData *pdata = rna_mesh_pdata(ptr); */ /* UNUSED */
 	CustomDataLayer *cdl= (CustomDataLayer*)ptr->data;
 	BLI_strncpy_utf8(cdl->name, value, sizeof(cdl->name));
@@ -1875,7 +1875,7 @@
 	RNA_def_property_boolean_sdna(prop, NULL, "texflag", AUTOSPACE);
 	RNA_def_property_ui_text(prop, "Auto Texture Space", "Adjusts active object's texture space automatically when transforming object");
 
-	prop= RNA_def_property(srna, "texspace_loc", PROP_FLOAT, PROP_TRANSLATION);
+	prop= RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION);
 	RNA_def_property_float_sdna(prop, NULL, "loc");
 	RNA_def_property_ui_text(prop, "Texure Space Location", "Texture space location");
 	RNA_def_property_editable_func(prop, texspace_editable);
@@ -2363,15 +2363,15 @@
 	prop= RNA_def_property(srna, "use_auto_texspace", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "texflag", AUTOSPACE);
 	RNA_def_property_ui_text(prop, "Auto Texture Space", "Adjusts active object's texture space automatically when transforming object");
-	
+
 	/*prop= RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION);
 	RNA_def_property_array(prop, 3);
 	RNA_def_property_ui_text(prop, "Texture Space Location", "Texture space location");
 	RNA_def_property_editable_func(prop, "rna_Mesh_texspace_editable");
-	RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_loc_get", "rna_Mesh_texspace_loc_set", NULL);	
+	RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_loc_get", "rna_Mesh_texspace_loc_set", NULL);
 	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
 	*/
-	
+
 	/* not supported yet
 	prop= RNA_def_property(srna, "texspace_rot", PROP_FLOAT, PROP_EULER);
 	RNA_def_property_float(prop, NULL, "rot");




More information about the Bf-blender-cvs mailing list