[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36651] trunk/blender/source/blender: * Enabled rna access to fluid sim velocity vectors

Matt Ebb matt at mke3.net
Fri May 13 00:52:31 CEST 2011


Revision: 36651
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36651
Author:   broken
Date:     2011-05-12 22:52:30 +0000 (Thu, 12 May 2011)
Log Message:
-----------
* Enabled rna access to fluid sim velocity vectors

The main purpose for this is to allow rendering motion blurred blender fluids in external renderers (eg. http://vimeo.com/21870635 ).

Python code snippet for interpreting this data here: http://www.pasteall.org/21577 . Cleaned up some ugly hacks in this area too

* Also added read-only access to scene.subframe to RNA - setting current frame and subframe should still go via scene.frame_set()

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_object_fluidsim.h
    trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c
    trunk/blender/source/blender/makesrna/intern/rna_scene.c
    trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c
    trunk/blender/source/blender/render/intern/source/convertblender.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2011-05-12 18:46:21 UTC (rev 36650)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2011-05-12 22:52:30 UTC (rev 36651)
@@ -3967,7 +3967,7 @@
 			
 			fluidmd->fss= newdataadr(fd, fluidmd->fss);
 			fluidmd->fss->fmd= fluidmd;
-			fluidmd->fss->meshSurfNormals = NULL;
+			fluidmd->fss->meshVelocities = NULL;
 		}
 		else if (md->type==eModifierType_Smoke) {
 			SmokeModifierData *smd = (SmokeModifierData*) md;
@@ -9623,7 +9623,7 @@
 				
 				fluidmd->fss->lastgoodframe = INT_MAX;
 				fluidmd->fss->flag = 0;
-				fluidmd->fss->meshSurfNormals = NULL;
+				fluidmd->fss->meshVelocities = NULL;
 			}
 		}
 	}

Modified: trunk/blender/source/blender/makesdna/DNA_object_fluidsim.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_object_fluidsim.h	2011-05-12 18:46:21 UTC (rev 36650)
+++ trunk/blender/source/blender/makesdna/DNA_object_fluidsim.h	2011-05-12 22:52:30 UTC (rev 36651)
@@ -42,7 +42,10 @@
 	
 struct Mesh;
 struct Ipo;
-struct MVert;
+
+typedef struct FluidVertexVelocity {
+	float vel[3];
+} FluidVertexVelocity;
 	
 typedef struct FluidsimSettings {
 	struct FluidsimModifierData *fmd; /* for fast RNA access */
@@ -82,8 +85,6 @@
 
 	/* store pointer to original mesh (for replacing the current one) */
 	struct Mesh *orgMesh;
-	/* pointer to the currently loaded fluidsim mesh */
-	struct Mesh *meshSurface;
 	/* a mesh to display the bounding box used for simulation */
 	struct Mesh *meshBB;
 
@@ -122,8 +123,10 @@
 	/* testing vars */
 	float farFieldSize;
 
-	/* save fluidsurface normals in mvert.no, and surface vertex velocities (if available) in mvert.co */
-	struct MVert *meshSurfNormals;
+	/* vertex velocities of simulated fluid mesh */
+	struct FluidVertexVelocity *meshVelocities;
+	/* number of vertices in simulated fluid mesh */
+	int totvert;
 	
 	/* Fluid control settings */
 	float cpsTimeStart;
@@ -136,6 +139,8 @@
 	float velocityforceRadius;
 
 	int lastgoodframe;
+	
+	int pad;
 
 } FluidsimSettings;
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c	2011-05-12 18:46:21 UTC (rev 36650)
+++ trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c	2011-05-12 22:52:30 UTC (rev 36651)
@@ -195,6 +195,18 @@
 	return BLI_sprintfN("modifiers[\"%s\"].settings", md->name);
 }
 
+static void rna_FluidMeshVertex_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+	FluidsimSettings *fss = (FluidsimSettings*)ptr->data;
+	rna_iterator_array_begin(iter, fss->meshVelocities, sizeof(float)*3, fss->totvert, 0, NULL);
+}
+
+static int rna_FluidMeshVertex_data_length(PointerRNA *ptr)
+{
+	FluidsimSettings *fss = (FluidsimSettings*)ptr->data;
+	return fss->totvert;
+}
+
 #else
 
 static void rna_def_fluidsim_slip(StructRNA *srna)
@@ -219,6 +231,24 @@
 	RNA_def_property_ui_text(prop, "Partial Slip Amount", "Amount of mixing between no- and free-slip, 0 is no slip and 1 is free slip");
 }
 
+static void rna_def_fluid_mesh_vertices(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna= RNA_def_struct(brna, "FluidMeshVertex", NULL);
+	RNA_def_struct_sdna(srna, "FluidVertexVelocity");
+	RNA_def_struct_ui_text(srna, "Fluid Mesh Vertex", "Vertex of a simulated fluid mesh");
+	RNA_def_struct_ui_icon(srna, ICON_VERTEXSEL);
+
+	prop= RNA_def_property(srna, "velocity", PROP_FLOAT, PROP_VELOCITY);
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_float_sdna(prop, NULL, "vel");
+	RNA_def_property_ui_text(prop, "Velocity", "");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+}
+
+
 static void rna_def_fluidsim_domain(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -367,6 +397,13 @@
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_range(prop, 0.0, 10.0);
 	RNA_def_property_ui_text(prop, "Generate Particles", "Amount of particles to generate (0=off, 1=normal, >1=more)");
+	
+	/* simulated fluid mesh data */
+	prop= RNA_def_property(srna, "fluid_mesh_vertices", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_struct_type(prop, "FluidMeshVertex");
+	RNA_def_property_ui_text(prop, "Fluid Mesh Vertices", "Vertices of the fluid mesh generated by simulation");
+	RNA_def_property_collection_funcs(prop, "rna_FluidMeshVertex_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_FluidMeshVertex_data_length", 0, 0);
+	rna_def_fluid_mesh_vertices(brna);
 }
 
 static void rna_def_fluidsim_volume(StructRNA *srna)

Modified: trunk/blender/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_scene.c	2011-05-12 18:46:21 UTC (rev 36650)
+++ trunk/blender/source/blender/makesrna/intern/rna_scene.c	2011-05-12 22:52:30 UTC (rev 36651)
@@ -3226,6 +3226,11 @@
 	RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
 	RNA_def_property_update(prop, NC_SCENE|ND_FRAME, "rna_Scene_frame_update");
 	
+	prop= RNA_def_property(srna, "frame_subframe", PROP_FLOAT, PROP_TIME);
+	RNA_def_property_float_sdna(prop, NULL, "r.subframe");
+	RNA_def_property_ui_text(prop, "Current Sub-Frame", "");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE|PROP_EDITABLE);
+	
 	prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_int_sdna(prop, NULL, "r.sfra");

Modified: trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c	2011-05-12 18:46:21 UTC (rev 36650)
+++ trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c	2011-05-12 22:52:30 UTC (rev 36651)
@@ -139,8 +139,7 @@
 		fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize);	
 		*/
 		
-		// (ab)used to store velocities
-		fss->meshSurfNormals = NULL;
+		fss->meshVelocities = NULL;
 		
 		fss->lastgoodframe = -1;
 		
@@ -158,10 +157,10 @@
 #ifndef DISABLE_ELBEEM
 	if(fluidmd)
 	{
-		if(fluidmd->fss->meshSurfNormals)
+		if(fluidmd->fss->meshVelocities)
 		{
-			MEM_freeN(fluidmd->fss->meshSurfNormals);
-			fluidmd->fss->meshSurfNormals = NULL;
+			MEM_freeN(fluidmd->fss->meshVelocities);
+			fluidmd->fss->meshVelocities = NULL;
 		}
 		MEM_freeN(fluidmd->fss);
 	}
@@ -394,12 +393,12 @@
 	FluidsimSettings *fss = fluidmd->fss;
 	int len = strlen(filename);
 	int totvert = dm->getNumVerts(dm);
-	float *velarray = NULL;
+	FluidVertexVelocity *velarray = NULL;
 
 	// mesh and vverts have to be valid from loading...
 
-	if(fss->meshSurfNormals)
-		MEM_freeN(fss->meshSurfNormals);
+	if(fss->meshVelocities)
+		MEM_freeN(fss->meshVelocities);
 
 	if(len<7)
 	{
@@ -408,12 +407,10 @@
 
 	if(fss->domainNovecgen>0) return;
 
-	// abusing pointer to hold an array of 3d-velocities
-	fss->meshSurfNormals = MEM_callocN(sizeof(float)*3*dm->getNumVerts(dm), "Fluidsim_velocities");
-	// abusing pointer to hold an INT
-	fss->meshSurface = SET_INT_IN_POINTER(totvert);
+	fss->meshVelocities = MEM_callocN(sizeof(FluidVertexVelocity)*dm->getNumVerts(dm), "Fluidsim_velocities");
+	fss->totvert = totvert;
 
-	velarray = (float *)fss->meshSurfNormals;
+	velarray = fss->meshVelocities;
 
 	// .bobj.gz , correct filename
 	// 87654321
@@ -424,16 +421,16 @@
 	gzf = gzopen(filename, "rb");
 	if (!gzf)
 	{
-		MEM_freeN(fss->meshSurfNormals);
-		fss->meshSurfNormals = NULL;
+		MEM_freeN(fss->meshVelocities);
+		fss->meshVelocities = NULL;
 		return;
 	}
 
 	gzread(gzf, &wri, sizeof( wri ));
 	if(wri != totvert)
 	{
-		MEM_freeN(fss->meshSurfNormals);
-		fss->meshSurfNormals = NULL;
+		MEM_freeN(fss->meshVelocities);
+		fss->meshVelocities = NULL;
 		return;
 	}
 
@@ -442,7 +439,7 @@
 		for(j=0; j<3; j++)
 		{
 			gzread(gzf, &wrf, sizeof( wrf ));
-			velarray[3*i + j] = wrf;
+			velarray[i].vel[j] = wrf;
 		}
 	}
 
@@ -531,10 +528,10 @@
 	}
 	else
 	{
-		if(fss->meshSurfNormals)
-			MEM_freeN(fss->meshSurfNormals);
+		if(fss->meshVelocities)
+			MEM_freeN(fss->meshVelocities);
 
-		fss->meshSurfNormals = NULL;
+		fss->meshVelocities = NULL;
 	}
 
 	return dm;

Modified: trunk/blender/source/blender/render/intern/source/convertblender.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/convertblender.c	2011-05-12 18:46:21 UTC (rev 36650)
+++ trunk/blender/source/blender/render/intern/source/convertblender.c	2011-05-12 22:52:30 UTC (rev 36651)
@@ -5387,7 +5387,7 @@
 	float imat[4][4];
 	FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsob, eModifierType_Fluidsim);
 	FluidsimSettings *fss;
-	float *velarray = NULL;
+	FluidVertexVelocity *velarray = NULL;
 	
 	/* only one step needed */
 	if(step) return 1;
@@ -5401,14 +5401,14 @@
 	invert_m4_m4(imat, mat);
 
 	/* set first vertex OK */
-	if(!fss->meshSurfNormals) return 0;
+	if(!fss->meshVelocities) return 0;
 	
-	if( obr->totvert != GET_INT_FROM_POINTER(fss->meshSurface) ) {
+	if( obr->totvert != fss->totvert) {
 		//fprintf(stderr, "load_fluidsimspeedvectors - modified fluidsim mesh, not using speed vectors (%d,%d)...\n", obr->totvert, fsob->fluidsimSettings->meshSurface->totvert); // DEBUG
 		return 0;
 	}
 	
-	velarray = (float *)fss->meshSurfNormals;
+	velarray = fss->meshVelocities;
 
 	if(obi->flag & R_TRANSFORMED)
 		mul_m4_m4m4(winmat, obi->mat, re->winmat);
@@ -5420,7 +5420,7 @@
 	so that also small drops/little water volumes return a velocity != 0. 
 	But I had no luck in fixing that function - DG */
 	for(a=0; a<obr->totvert; a++) {
-		for(j=0;j<3;j++) avgvel[j] += velarray[3*a + j];
+		for(j=0;j<3;j++) avgvel[j] += velarray[a].vel[j];
 		
 	}
 	for(j=0;j<3;j++) avgvel[j] /= (float)(obr->totvert);
@@ -5435,7 +5435,7 @@
 		// get fluid velocity
 		fsvec[3] = 0.; 
 		//fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.; fsvec[2] = 2.; // NT fixed test
-		for(j=0;j<3;j++) fsvec[j] = velarray[3*a + j];
+		for(j=0;j<3;j++) fsvec[j] = velarray[a].vel[j];
 		
 		/* (bad) HACK insert average velocity if none is there (see previous comment) */
 		if((fsvec[0] == 0.0) && (fsvec[1] == 0.0) && (fsvec[2] == 0.0))




More information about the Bf-blender-cvs mailing list