[Bf-blender-cvs] [7abab97] fluid-mantaflow: started integration of liquids in pointcache

Sebastián Barschkis noreply at git.blender.org
Thu Jun 9 19:29:09 CEST 2016


Commit: 7abab97769c52306dcbcac8980418585df0bd818
Author: Sebastián Barschkis
Date:   Thu Jun 9 19:28:49 2016 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB7abab97769c52306dcbcac8980418585df0bd818

started integration of liquids in pointcache

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

M	intern/mantaflow/extern/manta_smoke_API.h
M	intern/mantaflow/intern/SMOKE.cpp
M	intern/mantaflow/intern/SMOKE.h
M	intern/mantaflow/intern/manta_smoke_API.cpp
M	intern/mantaflow/intern/strings/liquid_script.h
M	source/blender/blenkernel/BKE_pointcache.h
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/smoke.c

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

diff --git a/intern/mantaflow/extern/manta_smoke_API.h b/intern/mantaflow/extern/manta_smoke_API.h
index e343cb2..0734156 100644
--- a/intern/mantaflow/extern/manta_smoke_API.h
+++ b/intern/mantaflow/extern/manta_smoke_API.h
@@ -91,7 +91,7 @@ float *smoke_get_fuel_inflow(struct SMOKE *smoke);
 float *liquid_get_phi(struct SMOKE *liquid);
 float *liquid_turbulence_get_phi(struct SMOKE *liquid);
 void liquid_ensure_init(struct SMOKE *smoke, struct SmokeModifierData *smd);
-
+void liquid_save_mesh(struct SMOKE *smoke, int startFrame);
 
 #ifdef __cplusplus
 }
diff --git a/intern/mantaflow/intern/SMOKE.cpp b/intern/mantaflow/intern/SMOKE.cpp
index d257fc8..04a2aae 100644
--- a/intern/mantaflow/intern/SMOKE.cpp
+++ b/intern/mantaflow/intern/SMOKE.cpp
@@ -284,6 +284,7 @@ void SMOKE::initLiquid(SmokeModifierData *smd)
 		std::string tmpString = alloc_liquid
 			+ liquid_variables
 			+ prep_domain
+			+ save_mesh
 			+ adaptive_step_liquid
 			+ liquid_step;
 		std::string finalString = parseScript(tmpString, smd);
@@ -760,4 +761,14 @@ void SMOKE::updatePointersHigh(SmokeModifierData *smd)
 	}
 }
 
+void SMOKE::saveMesh(int startFrame)
+{
+	mCommands.clear();
+	std::ostringstream save_mesh;
+	save_mesh <<  "save_mesh(" << startFrame << ")";
+	mCommands.push_back(save_mesh.str());
+	
+	runPythonString(mCommands);
+}
+
 
diff --git a/intern/mantaflow/intern/SMOKE.h b/intern/mantaflow/intern/SMOKE.h
index 3671942..56f380f 100644
--- a/intern/mantaflow/intern/SMOKE.h
+++ b/intern/mantaflow/intern/SMOKE.h
@@ -60,6 +60,9 @@ public:
 	void exportScript(struct SmokeModifierData *smd);
 	void exportGrids(struct SmokeModifierData *smd);
 	
+	// Write files for liquids
+	void saveMesh(int startFrame);
+	
 	// Getters
 	inline size_t getTotalCells() { return mTotalCells; }
 	inline size_t getTotalCellsHigh() { return mTotalCellsHigh; }
diff --git a/intern/mantaflow/intern/manta_smoke_API.cpp b/intern/mantaflow/intern/manta_smoke_API.cpp
index fc8d61e..454adc1 100644
--- a/intern/mantaflow/intern/manta_smoke_API.cpp
+++ b/intern/mantaflow/intern/manta_smoke_API.cpp
@@ -496,3 +496,10 @@ extern "C" float *liquid_get_phi(SMOKE *liquid)
 {
 	return liquid->getPhi();
 }
+
+extern "C" void liquid_save_mesh(SMOKE *liquid, int startFrame)
+{
+	if (liquid) {
+		liquid->saveMesh(startFrame);
+	}
+}
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 73cbdef..55e99ed 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -165,7 +165,6 @@ def liquid_step():\n\
     \n\
     if dim==3:\n\
         phi.createMesh(mesh)\n\
-        mesh.save('/Users/sbarschkis/Desktop/surface/fluidsurface_final_%04d.bobj.gz' % step)\n\
     \n\
     # Resample particles\n\
     pVel.setSource( vel, isMAC=True ) # Set source grids for resampling, used in adjustNumber!\n\
@@ -175,6 +174,10 @@ def liquid_step():\n\
     else:\n\
         adjustNumber( parts=pp, vel=vel, flags=flags, minParticles=1*minParticles, maxParticles=2*minParticles, phi=phi )\n";
 
+const std::string save_mesh = "\n\
+def save_mesh(step):\n\
+    mesh.save('/Users/sbarschkis/Desktop/surface/fluidsurface_final_%04d.bobj.gz' % step)\n";
+
 //////////////////////////////////////////////////////////////////////
 // DESTRUCTION
 //////////////////////////////////////////////////////////////////////
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index d955072..e854c5b 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -160,6 +160,11 @@ typedef struct PTCacheID {
 	int (*write_openvdb_stream)(struct OpenVDBWriter *writer, void *calldata);
 	/* copies cache cata to point data */
 	int (*read_openvdb_stream)(struct OpenVDBReader *reader, void *calldata);
+	
+	/* copies point data to cache data */
+	int (*write_liquid_stream)(void *calldata, int cfra);
+	/* copies cache cata to point data */
+	int (*read_liquid_stream)(void *calldata, int cfra);
 
 	/* copies custom extradata to cache data */
 	void (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 817c07c..1ff3a90 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1215,6 +1215,37 @@ static int ptcache_smoke_openvdb_read(struct OpenVDBReader *reader, void *smoke_
 }
 #endif
 
+#ifdef WITH_MANTA
+static int ptcache_liquid_read(PTCacheFile *pf, void *smoke_v)
+{
+	SmokeModifierData *smd = (SmokeModifierData *)smoke_v;
+
+	if (!smd) {
+		return 0;
+	}
+
+	SmokeDomainSettings *sds = smd->domain;
+	return 1;
+}
+
+static int ptcache_liquid_write(void *smoke_v, int cfra)
+{
+	SmokeModifierData *smd = (SmokeModifierData *) smoke_v;
+
+	if (!smd) {
+		return 0;
+	}
+
+	SmokeDomainSettings *sds = smd->domain;
+	
+	if (sds->fluid) {
+		liquid_save_mesh(sds->fluid, cfra);
+		return 1;
+	}
+	return 0;
+}
+#endif // WITH_MANTA
+
 #else // WITH_SMOKE
 static int  ptcache_smoke_totpoint(void *UNUSED(smoke_v), int UNUSED(cfra)) { return 0; }
 static void ptcache_smoke_error(void *UNUSED(smoke_v), const char *UNUSED(message)) { }
@@ -1457,6 +1488,9 @@ void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
 
 	pid->write_openvdb_stream	= NULL;
 	pid->read_openvdb_stream	= NULL;
+	
+	pid->write_liquid_stream	= NULL;
+	pid->read_liquid_stream		= NULL;
 
 	pid->write_extra_data		= NULL;
 	pid->read_extra_data		= NULL;
@@ -1502,6 +1536,9 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p
 
 	pid->write_openvdb_stream	= NULL;
 	pid->read_openvdb_stream	= NULL;
+	
+	pid->write_liquid_stream	= NULL;
+	pid->read_liquid_stream		= NULL;
 
 	pid->write_extra_data		= NULL;
 	pid->read_extra_data		= NULL;
@@ -1559,6 +1596,9 @@ void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *cl
 
 	pid->write_stream			= NULL;
 	pid->read_stream			= NULL;
+	
+	pid->write_liquid_stream	= NULL;
+	pid->read_liquid_stream		= NULL;
 
 	pid->write_extra_data		= NULL;
 	pid->read_extra_data		= NULL;
@@ -1598,11 +1638,14 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo
 	pid->interpolate_point		= NULL;
 
 	// TODO (sebbas) need to disable this again for liquids
-	pid->read_stream			= NULL; //ptcache_smoke_read;
-	pid->write_stream			= NULL; //ptcache_smoke_write;
+	pid->read_stream			= ptcache_smoke_read;
+	pid->write_stream			= ptcache_smoke_write;
 
 	pid->write_openvdb_stream	= ptcache_smoke_openvdb_write;
 	pid->read_openvdb_stream	= ptcache_smoke_openvdb_read;
+	
+	pid->write_liquid_stream	= ptcache_liquid_write;
+	pid->read_liquid_stream		= ptcache_liquid_read;
 
 	pid->write_extra_data		= NULL;
 	pid->read_extra_data		= NULL;
@@ -2836,6 +2879,16 @@ static int ptcache_write_openvdb_stream(PTCacheID *pid, int cfra)
 	return 0;
 #endif
 }
+static int ptcache_write_liquid_stream(PTCacheID *pid, int cfra)
+{
+	char filename[FILE_MAX * 2];
+	BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_FRAME, cfra);
+	ptcache_filename(pid, filename, cfra, 1, 1);
+	
+	int error = pid->write_liquid_stream(pid->calldata, cfra);
+	
+	return error == 0;
+}
 static int ptcache_write(PTCacheID *pid, int cfra, int overwrite)
 {
 	PointCache *cache = pid->cache;
@@ -2970,6 +3023,9 @@ int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
 	if (pid->file_type == PTCACHE_FILE_OPENVDB && pid->write_openvdb_stream) {
 		ptcache_write_openvdb_stream(pid, cfra);
 	}
+	else if (pid->file_type == PTCACHE_FILE_LIQUID && pid->write_liquid_stream) {
+		ptcache_write_liquid_stream(pid, cfra);
+	}
 	else if (pid->write_stream) {
 		ptcache_write_stream(pid, cfra, totpoint);
 	}
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index bc6aced..94e27e2 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -3032,10 +3032,9 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 			smoke_turbulence_step(sds->wt, sds->fluid);
 		}
 #endif
-		// TODO (sebbas) disabled for liquid integration
-//		BKE_ptcache_validate(cache, framenr);
-//		if (framenr != startframe)
-//			BKE_ptcache_write(&pid, framenr);
+		BKE_ptcache_validate(cache, framenr);
+		if (framenr != startframe)
+			BKE_ptcache_write(&pid, framenr);
 
 #ifdef DEBUG_TIME
 		double end = PIL_check_seconds_timer();




More information about the Bf-blender-cvs mailing list