[Bf-blender-cvs] [201555e] soc-2014-fluid: updating highres fluid_3d; writing smoke cache to BKE_pointcache

Roman Pogribnyi noreply at git.blender.org
Tue Aug 12 00:57:05 CEST 2014


Commit: 201555edca98ac0eaae4da1e827b27e333bbc697
Author: Roman Pogribnyi
Date:   Tue Aug 12 00:55:35 2014 +0200
Branches: soc-2014-fluid
https://developer.blender.org/rB201555edca98ac0eaae4da1e827b27e333bbc697

updating highres fluid_3d; writing smoke cache to BKE_pointcache

===================================================================

M	intern/smoke/extern/smoke_API.h
M	intern/smoke/intern/MANTA.cpp
M	intern/smoke/intern/MANTA.h
M	intern/smoke/intern/smoke_API.cpp
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/editors/physics/physics_fluid.c

===================================================================

diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h
index a8fae1a..7ef01cf 100644
--- a/intern/smoke/extern/smoke_API.h
+++ b/intern/smoke/extern/smoke_API.h
@@ -114,7 +114,7 @@ void smoke_ensure_fire(struct FLUID_3D *fluid, struct WTURBULENCE *wt);
 void smoke_ensure_colors(struct FLUID_3D *fluid, struct WTURBULENCE *wt, float init_r, float init_g, float init_b);
 
 /*Mantaflow functions*/
-void smoke_mantaflow_read(struct FLUID_3D *fluid, char* name);
+int smoke_mantaflow_read(struct FLUID_3D *fluid, char* name); //1:success, 0: no file,error
 void smoke_mantaflow_write_scene_file(struct Scene *s, struct SmokeModifierData *smd);
 void smoke_mantaflow_sim_step(struct Scene *scene, struct SmokeModifierData *smd);
 void smoke_mantaflow_stop_sim();
diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index 2490b8e..9248086 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -15,7 +15,7 @@ extern "C" bool manta_check_grid_size(struct FLUID_3D *fluid, int dimX, int dimY
 	return true;
 }
 
-extern "C" void read_mantaflow_sim(struct FLUID_3D *fluid, char *name)
+extern "C" int read_mantaflow_sim(struct FLUID_3D *fluid, char *name)
 {
     /*! legacy headers for reading old files */
 	typedef struct {
@@ -41,7 +41,7 @@ extern "C" void read_mantaflow_sim(struct FLUID_3D *fluid, char *name)
     if (!gzf) {
 		for (int cnt(0); cnt < fluid->_totalCells; cnt++)
 			fluid->_density[cnt] = 0.0f;
-		return;
+		return 0;
 	}
 	
     char ID[5] = {0,0,0,0,0};
@@ -51,7 +51,7 @@ extern "C" void read_mantaflow_sim(struct FLUID_3D *fluid, char *name)
     if (!strcmp(ID, "DDF2")) {
         UniLegacyHeader head;
 		gzread(gzf, &head, sizeof(UniLegacyHeader));
-		if (!manta_check_grid_size(fluid, head.dimX, head.dimY, head.dimZ))	return;
+		if (!manta_check_grid_size(fluid, head.dimX, head.dimY, head.dimZ))	return 0;
         int numEl = head.dimX*head.dimY*head.dimZ;
         gzseek(gzf, numEl, SEEK_CUR);
         /* actual grid read */
@@ -61,7 +61,7 @@ extern "C" void read_mantaflow_sim(struct FLUID_3D *fluid, char *name)
     else if (!strcmp(ID, "MNT1")) {
         UniLegacyHeader2 head;
         gzread(gzf, &head, sizeof(UniLegacyHeader2));
-		if (!manta_check_grid_size(fluid, head.dimX, head.dimY, head.dimZ))	return;
+		if (!manta_check_grid_size(fluid, head.dimX, head.dimY, head.dimZ))	return 0;
         /* actual grid read*/
         gzread(gzf, fluid->_density, sizeof(float)*head.dimX*head.dimY*head.dimZ);
     }
@@ -69,13 +69,14 @@ extern "C" void read_mantaflow_sim(struct FLUID_3D *fluid, char *name)
     else if (!strcmp(ID, "MNT2")) {
         UniHeader head;
         gzread(gzf, &head, sizeof(UniHeader));
-		if (!manta_check_grid_size(fluid, head.dimX, head.dimY, head.dimZ))	return;
+		if (!manta_check_grid_size(fluid, head.dimX, head.dimY, head.dimZ))	return 0;
 		/* actual grid read */
         gzread(gzf,fluid->_density, sizeof(float)*head.dimX*head.dimY*head.dimZ);
     }
     gzclose(gzf);
-	
+	return 1;
 #	endif	/*zlib*/
+	return 0;
 }
 
 void indent_ss(stringstream& ss, int indent)
diff --git a/intern/smoke/intern/MANTA.h b/intern/smoke/intern/MANTA.h
index 91bdf61..a04916d 100644
--- a/intern/smoke/intern/MANTA.h
+++ b/intern/smoke/intern/MANTA.h
@@ -29,7 +29,7 @@ void runMantaScript(vector<string>& args);//defined in manta_pp/pwrapper/pymain.
 
 extern "C" bool manta_check_grid_size(struct FLUID_3D *fluid, int dimX, int dimY, int dimZ);
 
-extern "C" void read_mantaflow_sim(struct FLUID_3D *fluid, char *name);
+extern "C" int read_mantaflow_sim(struct FLUID_3D *fluid, char *name);
 
 void indent_ss(stringstream& ss, int indent);
 
diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp
index a72b883..7eb2150 100644
--- a/intern/smoke/intern/smoke_API.cpp
+++ b/intern/smoke/intern/smoke_API.cpp
@@ -501,9 +501,9 @@ extern "C" void smoke_ensure_colors(FLUID_3D *fluid, WTURBULENCE *wt, float init
 }
 
 /*MantaFlow funcs*/
-extern "C" void smoke_mantaflow_read(struct FLUID_3D *fluid, char* name)
+extern "C" int smoke_mantaflow_read(struct FLUID_3D *fluid, char* name)
 {
-	read_mantaflow_sim(fluid, name);
+	return read_mantaflow_sim(fluid, name);
 }
 
 extern "C" void smoke_mantaflow_write_scene_file(struct Scene *s, struct SmokeModifierData *smd)
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index ced48e8..512de1b 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -2739,6 +2739,7 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 		//printf("time: %d\n", scene->r.cfra);
 
 		cache = sds->point_cache[0];
+
 		BKE_ptcache_id_from_smoke(&pid, ob, smd);
 		BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
 
@@ -2765,73 +2766,81 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 			printf("bad smokeModifier_init\n");
 			return;
 		}
-		if(smd->domain->flags & MOD_SMOKE_USE_MANTA)
+		
+		if(smd->domain->flags & MOD_SMOKE_USE_MANTA)	/*load manta sim data into fluid object*/
 		{
 			char buff[100];
 			if(smd->domain->manta_start_frame > scene->r.cfra)
 				return;
 			sprintf(buff, "./den%04d.uni", scene->r.cfra - smd->domain->manta_start_frame);
-			smoke_mantaflow_read(smd->domain->fluid, buff);
-			return;
+			if (smoke_mantaflow_read(smd->domain->fluid, buff))
+			{	BKE_ptcache_write(&pid, framenr);
+			}
 		}
+		
 		/* try to read from cache */
 		if (BKE_ptcache_read(&pid, (float)framenr) == PTCACHE_READ_EXACT) {
 			BKE_ptcache_validate(cache, framenr);
 			smd->time = framenr;
 			return;
 		}
-
-		/* only calculate something when we advanced a single frame */
-		if (framenr != (int)smd->time + 1)
-			return;
-
-		/* don't simulate if viewing start frame, but scene frame is not real start frame */
-		if (framenr != scene->r.cfra)
-			return;
-
-		tstart();
-
-		/* if on second frame, write cache for first frame */
-		if ((int)smd->time == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
-			BKE_ptcache_write(&pid, startframe);
-		}
-
-		// set new time
-		smd->time = scene->r.cfra;
-
-		/* do simulation */
-
-		// simulate the actual smoke (c++ code in intern/smoke)
-		// DG: interesting commenting this line + deactivating loading of noise files
-		if (framenr != startframe)
-		{
-			if (sds->flags & MOD_SMOKE_DISSOLVE) {
-				/* low res dissolve */
-				smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
-				/* high res dissolve */
-				if (sds->wt) {
-					smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
-				}
-
-			}
-
-			step(scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base, for_render);
-		}
-
-		// create shadows before writing cache so they get stored
-		smoke_calc_transparency(sds, scene);
-
-		if (sds->wt)
+		
+		if (smd->domain->flags & MOD_SMOKE_USE_MANTA)/*manta should go no further that this poin*/
 		{
-			smoke_turbulence_step(sds->wt, sds->fluid);
+			return;
 		}
-
-		BKE_ptcache_validate(cache, framenr);
-		if (framenr != startframe)
-			BKE_ptcache_write(&pid, framenr);
-
-		tend();
-		// printf ( "Frame: %d, Time: %f\n\n", (int)smd->time, (float) tval() );
+		
+//		/* only calculate something when we advanced a single frame */
+//		if (framenr != (int)smd->time + 1)
+//			return;
+//
+//		/* don't simulate if viewing start frame, but scene frame is not real start frame */
+//		if (framenr != scene->r.cfra)
+//			return;
+//
+//		tstart();
+//
+//		/* if on second frame, write cache for first frame */
+//		if ((int)smd->time == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
+//			BKE_ptcache_write(&pid, startframe);
+//		}
+//
+//		// set new time
+//		smd->time = scene->r.cfra;
+//
+//		/* do simulation */
+//
+//		// simulate the actual smoke (c++ code in intern/smoke)
+//		// DG: interesting commenting this line + deactivating loading of noise files
+//		if (framenr != startframe)
+//		{
+//			if (sds->flags & MOD_SMOKE_DISSOLVE) {
+//				/* low res dissolve */
+//				smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
+//				/* high res dissolve */
+//				if (sds->wt) {
+//					smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
+//				}
+//
+//			}
+//
+//			step(scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base, for_render);
+//		}
+//
+//		// create shadows before writing cache so they get stored
+//		smoke_calc_transparency(sds, scene);
+//
+//		if (sds->wt)
+//		{
+//			smoke_turbulence_step(sds->wt, sds->fluid);
+//		}
+//
+//		BKE_ptcache_validate(cache, framenr);
+//		if (framenr != startframe)
+//			BKE_ptcache_write(&pid, framenr);
+//
+//		tend();
+//		// printf ( "Frame: %d, Time: %f\n\n", (int)smd->time, (float) tval() );
 	}
 }
 
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index 679c608..67b7bc3 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -1153,10 +1153,14 @@ static int manta_make_file_exec(bContext *C, wmOperator *op)
 	SmokeModifierData *smd;
 	Object * smokeDomain = CTX_data_active_object(C);
 	smd = (SmokeModifierData *)modifiers_findByType(smokeDomain, eModifierType_Smoke);
+	
 	if (smd->domain->fluid == NULL)
 	{
-		smoke_reallocate_fluid(smd->domain, 0.1,smd->domain->res, 1);
-//		smd->domain->fluid = smoke_init(smd->domain->res, 0.1f, 0.1f, 0,0,0);
+		smoke_reallocate_fluid(smd->domain, smd->domain->dx, smd->domain->res, 1);
+		if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
+			smoke_reallocate_highres_fluid(smd->domain, smd->domain->dx, smd->domain->res, 1);
+		}
+		//		smd->domain->fluid = smoke_init(smd->domain->res, 0.1f, 0.1f, 0,0,0);
 	}
 	smoke_mantaflow_write_scene_file(scene, smd);




More information about the Bf-blender-cvs mailing list