[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33278] trunk/blender/source/blender: Fixes for [#24862] Fluid Simulator issues

Janne Karhu jhkarh at gmail.com
Wed Nov 24 11:56:16 CET 2010


Revision: 33278
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33278
Author:   jhk
Date:     2010-11-24 11:56:15 +0100 (Wed, 24 Nov 2010)

Log Message:
-----------
Fixes for [#24862] Fluid Simulator issues
* Fluid baking (using the job system) didn't update the "lastgoodframe" anymore, so reversing the frames didn't work. Now the last valid frame is checked by going through all fluid bake files when "reverse frames" is selected.
* There was all kinds of fancy checks done in the fluid modifier for reading a different frame in different cases, but as the "lastgoodframe" was really not working I don't see the point of this whole code, so removed it for now. The new functionality is: if the fluid data for current frame exists use it, otherwise just return unmodified domain mesh without any fancy backup plans.
* There were also some errors on reading uncompleted files (scrubbing timeline while bake was running), so I made the fluid file reader just return null if the number of faces didn't correspond to to actually read data. Previously this just printed an error to the console.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c
    trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c	2010-11-24 10:23:23 UTC (rev 33277)
+++ trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c	2010-11-24 10:56:15 UTC (rev 33278)
@@ -42,6 +42,7 @@
 
 #include "BKE_depsgraph.h"
 #include "BKE_fluidsim.h"
+#include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_modifier.h"
 #include "BKE_particle.h"
@@ -79,6 +80,38 @@
 	WM_main_add_notifier(NC_OBJECT|ND_MODIFIER, ob);
 }
 
+static int fluidsim_find_lastframe(FluidsimSettings *fss)
+{
+	char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR];
+	int curFrame = 1;
+
+	strncpy(targetDir, fss->surfdataPath, FILE_MAXDIR);
+	strcat(targetDir,"fluidsurface_final_####");
+	BLI_path_abs(targetDir, G.main->name);
+
+	do {
+		strcpy(targetFile,targetDir);
+		BLI_path_frame(targetFile, curFrame++, 0);
+		strcat(targetFile, ".bobj.gz");
+	} while(BLI_exist(targetFile));
+
+	return curFrame - 1;
+}
+
+static void rna_fluid_find_enframe(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	Object *ob= ptr->id.data;
+	FluidsimModifierData *fluidmd= (FluidsimModifierData*)modifiers_findByType(ob, eModifierType_Fluidsim);
+
+	if(fluidmd->fss->flag & OB_FLUIDSIM_REVERSE) {
+		fluidmd->fss->lastgoodframe = fluidsim_find_lastframe(fluidmd->fss);
+	}
+	else {
+		fluidmd->fss->lastgoodframe = -1;
+	}
+	rna_fluid_update(bmain, scene, ptr);
+}
+
 static void rna_FluidSettings_update_type(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	Object *ob= (Object*)ptr->id.data;
@@ -231,6 +264,7 @@
 	prop= RNA_def_property(srna, "use_reverse_frames", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", OB_FLUIDSIM_REVERSE);
 	RNA_def_property_ui_text(prop, "Reverse Frames", "Reverse fluid frames");
+	RNA_def_property_update(prop, 0, "rna_fluid_find_enframe");
 
 	prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_DIRPATH);
 	RNA_def_property_string_maxlength(prop, 240);
@@ -527,6 +561,7 @@
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", OB_FLUIDSIM_REVERSE);
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_ui_text(prop, "Reverse Frames", "Reverse control object movement");
+	RNA_def_property_update(prop, 0, "rna_fluid_find_enframe");
 }
 
 void RNA_def_fluidsim(BlenderRNA *brna)

Modified: trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c	2010-11-24 10:23:23 UTC (rev 33277)
+++ trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c	2010-11-24 10:56:15 UTC (rev 33278)
@@ -275,8 +275,13 @@
 	/* read no. of triangles */
 	gotBytes = gzread(gzf, &wri, sizeof(wri));
 
-	if(wri!=numfaces)
+	if(wri!=numfaces) {
 		printf("Fluidsim: error in reading data from file.\n");
+		if(dm)
+			dm->release(dm);
+		gzclose( gzf );
+		return NULL;
+	}
 
 	// read triangles from file
 	mface = CDDM_get_faces(dm);
@@ -540,7 +545,6 @@
 
 	return dm;
 }
-
 #endif // DISABLE_ELBEEM
 
 DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene,
@@ -567,7 +571,7 @@
 	
 	// timescale not supported yet
 	// clmd->sim_parms->timescale= timescale;
-	
+
 	// support reversing of baked fluid frames here
 	if((fss->flag & OB_FLUIDSIM_REVERSE) && (fss->lastgoodframe >= 0))
 	{
@@ -576,39 +580,9 @@
 	}
 	
 	/* try to read from cache */
-	if(((fss->lastgoodframe >= framenr) || (fss->lastgoodframe < 0)) && (result = fluidsim_read_cache(dm, fluidmd, framenr, useRenderParams)))
-	{
-		// fss->lastgoodframe = framenr; // set also in src/fluidsim.c
+	/* if the frame is there, fine, otherwise don't do anything */
+	if((result = fluidsim_read_cache(dm, fluidmd, framenr, useRenderParams)))
 		return result;
-	}
-	else
-	{	
-		// display last known good frame
-		if(fss->lastgoodframe >= 0)
-		{
-			if((result = fluidsim_read_cache(dm, fluidmd, fss->lastgoodframe, useRenderParams))) 
-			{
-				return result;
-			}
-			
-			// it was supposed to be a valid frame but it isn't!
-			fss->lastgoodframe = framenr - 1;
-			
-			
-			// this could be likely the case when you load an old fluidsim
-			if((result = fluidsim_read_cache(dm, fluidmd, fss->lastgoodframe, useRenderParams))) 
-			{
-				return result;
-			}
-		}
-		
-		result = CDDM_copy(dm);
-
-		if(result) 
-		{
-			return result;
-		}
-	}
 	
 	return dm;
 #else





More information about the Bf-blender-cvs mailing list