[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43863] trunk/blender/source/blender: Minor Speedup: avoid for() loop over all faces in fluidsim by passing an example face to the mesh read function (also avoid a lot of int -> short/char conversions).

Campbell Barton ideasman42 at gmail.com
Fri Feb 3 00:58:47 CET 2012


Revision: 43863
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43863
Author:   campbellbarton
Date:     2012-02-02 23:58:46 +0000 (Thu, 02 Feb 2012)
Log Message:
-----------
Minor Speedup: avoid for() loop over all faces in fluidsim by passing an example face to the mesh read function (also avoid a lot of int -> short/char conversions).

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/texture.c
    trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c

Modified: trunk/blender/source/blender/blenkernel/intern/texture.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/texture.c	2012-02-02 21:46:29 UTC (rev 43862)
+++ trunk/blender/source/blender/blenkernel/intern/texture.c	2012-02-02 23:58:46 UTC (rev 43863)
@@ -500,8 +500,6 @@
 
 CBData *colorband_element_add(struct ColorBand *coba, float position)
 {
-	int a;
-
 	if(coba->tot==MAXCOLORBAND) {
 		return NULL;
 	}

Modified: trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c	2012-02-02 21:46:29 UTC (rev 43862)
+++ trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c	2012-02-02 23:58:46 UTC (rev 43863)
@@ -152,9 +152,7 @@
 
 void fluidsim_free(FluidsimModifierData *fluidmd)
 {
-#ifdef WITH_MOD_FLUID
-	if(fluidmd)
-	{
+	if(fluidmd) {
 		if(fluidmd->fss->meshVelocities)
 		{
 			MEM_freeN(fluidmd->fss->meshVelocities);
@@ -162,16 +160,13 @@
 		}
 		MEM_freeN(fluidmd->fss);
 	}
-#else
-	(void)fluidmd; /* unused */
-#endif
 	
 	return;
 }
 
 #ifdef WITH_MOD_FLUID
 /* read .bobj.gz file into a fluidsimDerivedMesh struct */
-static DerivedMesh *fluidsim_read_obj(const char *filename)
+static DerivedMesh *fluidsim_read_obj(const char *filename, const MFace *mf_example)
 {
 	int wri = 0,i;
 	int gotBytes;
@@ -183,6 +178,9 @@
 	short *normals, *no_s;
 	float no[3];
 
+	const short mf_mat_nr = mf_example->mat_nr;
+	const char  mf_flag =   mf_example->flag;
+
 	// ------------------------------------------------
 	// get numverts + numfaces first
 	// ------------------------------------------------
@@ -287,6 +285,10 @@
 
 		gotBytes = gzread(gzf, face, sizeof(int) * 3);
 
+		/* initialize from existing face */
+		mf->mat_nr = mf_mat_nr;
+		mf->flag =   mf_flag;
+
 		// check if 3rd vertex has index 0 (not allowed in blender)
 		if(face[2])
 		{
@@ -452,9 +454,9 @@
 	FluidsimSettings *fss = fluidmd->fss;
 	DerivedMesh *dm = NULL;
 	MFace *mface;
-	int numfaces;
-	int mat_nr, flag, i;
+	MFace mf_example = {0};
 
+
 	if(!useRenderParams) {
 		displaymode = fss->guiDisplayMode;
 	} else {
@@ -481,8 +483,16 @@
 	BLI_path_abs(targetFile, modifier_path_relbase(ob));
 	BLI_path_frame(targetFile, curFrame, 0); // fixed #frame-no
 
-	dm = fluidsim_read_obj(targetFile);
+	// assign material + flags to new dm
+	// if there's no faces in original dm, keep materials and flags unchanged
+	mface = orgdm->getFaceArray(orgdm);
+	if (mface) {
+		mf_example = *mface;
+	}
+	/* else leave NULL'd */
 
+	dm = fluidsim_read_obj(targetFile, &mf_example);
+
 	if(!dm)
 	{
 		// switch, abort background rendering when fluidsim mesh is missing
@@ -502,23 +512,6 @@
 		return NULL;
 	}
 
-	// assign material + flags to new dm
-	// if there's no faces in original dm, keep materials and flags unchanged
-	mface = orgdm->getFaceArray(orgdm);
-
-	if(mface) {
-		mat_nr = mface[0].mat_nr;
-		flag = mface[0].flag;
-
-		mface = dm->getFaceArray(dm);
-		numfaces = dm->getNumFaces(dm);
-		for(i=0; i<numfaces; i++)
-			{
-				mface[i].mat_nr = mat_nr;
-				mface[i].flag = flag;
-			}
-	}
-
 	// load vertex velocities, if they exist...
 	// TODO? use generate flag as loading flag as well?
 	// warning, needs original .bobj.gz mesh loading filename




More information about the Bf-blender-cvs mailing list