[Bf-blender-cvs] [d7161fc3f13] fluid-mantaflow: more changes for decoupled fluid cache

Sebastián Barschkis noreply at git.blender.org
Mon Mar 19 13:48:36 CET 2018


Commit: d7161fc3f1327e5c36ca2fb6752dd7cbbd835bed
Author: Sebastián Barschkis
Date:   Mon Mar 19 13:48:23 2018 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rBd7161fc3f1327e5c36ca2fb6752dd7cbbd835bed

more changes for decoupled fluid cache

liquid support finished, smoke and stability todo

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

M	intern/mantaflow/extern/manta_fluid_API.h
M	intern/mantaflow/intern/FLUID.cpp
M	intern/mantaflow/intern/FLUID.h
M	intern/mantaflow/intern/manta_fluid_API.cpp
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/shared_script.h
M	intern/mantaflow/intern/strings/smoke_script.h
M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/BKE_pointcache.h
M	source/blender/blenkernel/BKE_smoke.h
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/editors/physics/physics_fluid.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/windowmanager/WM_api.h

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 79ff2a9622e..6f03899ffc0 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -102,7 +102,7 @@ void liquid_ensure_init(struct FLUID *liquid, struct SmokeModifierData *smd);
 void liquid_manta_export(struct FLUID* smoke, struct SmokeModifierData *smd);
 
 // Liquid Mantaflow IO
-void liquid_save_mesh(struct FLUID *liquid, char *filename);
+void liquid_save_mesh(struct FLUID *liquid, char *filename, int framenr);
 void liquid_save_mesh_high(struct FLUID *liquid, char *filename);
 void liquid_save_particles(struct FLUID *liquid, char *filename);
 void liquid_save_particle_velocities(struct FLUID *liquid, char *filename);
@@ -167,19 +167,12 @@ void fluid_ensure_guiding(struct FLUID *fluid, struct SmokeModifierData *smd);
 void fluid_ensure_invelocity(struct FLUID *fluid, struct SmokeModifierData *smd);
 void fluid_ensure_sndparts(struct FLUID *fluid, struct SmokeModifierData *smd);
 int fluid_read_cache(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
-void fluid_free_geometry(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_bake_low(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_free_low(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_bake_high(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_free_high(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_bake_mesh_low(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_free_mesh_low(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_bake_mesh_high(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_free_mesh_high(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_bake_particles_low(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_free_particles_low(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_bake_particles_high(struct FLUID* fluid, struct SmokeModifierData *smd);
-void fluid_free_particles_high(struct FLUID* fluid, struct SmokeModifierData *smd);
+int fluid_bake_low(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
+int fluid_bake_high(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
+int fluid_bake_mesh_low(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
+int fluid_bake_mesh_high(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
+int fluid_bake_particles_low(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
+int fluid_bake_particles_high(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
 
 #ifdef __cplusplus
 }
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 630cc769462..f987931bd8e 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -30,6 +30,7 @@
 #include <sstream>
 #include <fstream>
 #include <iostream>
+#include <iomanip>
 #include <zlib.h>
 
 #include "FLUID.h"
@@ -243,20 +244,14 @@ void FLUID::initDomain(SmokeModifierData *smd)
 		+ fluid_alloc_low
 		+ fluid_bake_helper
 		+ fluid_bake_geometry
-		+ fluid_free_geometry
 		+ fluid_bake_low
-		+ fluid_free_low
 		+ fluid_bake_high
-		+ fluid_free_high
 		+ fluid_bake_mesh_low
-		+ fluid_free_mesh_low
 		+ fluid_bake_mesh_high
-		+ fluid_free_mesh_high
 		+ fluid_bake_particles_low
-		+ fluid_free_particles_low
 		+ fluid_bake_particles_high
-		+ fluid_free_particles_high
 		+ fluid_save_geometry_low
+		+ fluid_load_geometry_low
 		+ fluid_save_data_low
 		+ fluid_load_data_low
 		+ fluid_obstacle_export_low
@@ -294,7 +289,9 @@ void FLUID::initSmoke(SmokeModifierData *smd)
 		+ smoke_bounds_low
 		+ smoke_adaptive_step_low
 		+ smoke_save_geometry_low
+		+ smoke_load_geometry_low
 		+ smoke_save_data_low
+		+ smoke_load_data_low
 		+ smoke_pre_step_low
 		+ smoke_step_low
 		+ smoke_post_step_low;
@@ -403,6 +400,7 @@ void FLUID::initLiquid(SmokeModifierData *smd)
 			+ liquid_variables_low
 			+ liquid_init_phi
 			+ liquid_save_geometry_low
+			+ liquid_load_geometry_low
 			+ liquid_save_mesh_low
 			+ liquid_save_particles_low
 			+ liquid_save_data_low
@@ -428,7 +426,9 @@ void FLUID::initLiquidHigh(SmokeModifierData *smd)
 	std::string tmpString = liquid_alloc_high
 		+ liquid_variables_high
 		+ liquid_save_mesh_high
+		+ liquid_save_data_high
 		+ liquid_load_mesh_high
+		+ liquid_load_data_high
 		+ liquid_adaptive_step_high
 		+ liquid_step_high;
 	std::string finalString = parseScript(tmpString, smd);
@@ -496,20 +496,17 @@ void FLUID::initSndParts(SmokeModifierData *smd)
 
 void FLUID::step(SmokeModifierData *smd, int framenr)
 {
-	// TODO (sebbas): Use geometry bake instead of fluid_step
-//	std::string path(smd->domain->cache_directory);
-//
-//	mCommands.clear();
-//	std::ostringstream ss;
-//	ss <<  "bake_geometry_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
-//	mCommands.push_back(ss.str());
-//
-//	runPythonString(mCommands);
-
-	// Run manta step: regular step or init only (sets up geometry only, no vel update, for first frame)
+	if (with_debug)
+		std::cout << "FLUID::step()" << std::endl;
+
+	char cacheDir[FILE_MAX];
+	cacheDir[0] = '\0';
+
+	BLI_path_join(cacheDir, sizeof(cacheDir), smd->domain->cache_directory, FLUID_CACHE_DIR_GEOMETRY, NULL);
+
 	mCommands.clear();
 	std::ostringstream ss;
-	ss <<  "fluid_step_low_" << mCurrentID << "(" << framenr << ")";
+	ss << "bake_geometry_" << mCurrentID << "(r'" << cacheDir << "', " << framenr << ")";
 	mCommands.push_back(ss.str());
 
 	runPythonString(mCommands);
@@ -987,206 +984,296 @@ void FLUID::exportSmokeScript(SmokeModifierData *smd)
 	myfile.close();
 }
 
-/* BEGIN TODO (sebbas): read decoupled uni cache */
-int FLUID::readCache(SmokeModifierData *smd, int framenr)
+int FLUID::readCacheLow(SmokeModifierData *smd, int framenr)
 {
-	std::string path(smd->domain->cache_directory);
+	if (with_debug)
+		std::cout << "FLUID::readCacheLow()" << std::endl;
+
 	std::ostringstream ss;
+	bool readSuccess = false;
 
-	try {
-		mCommands.clear();
-		ss <<  "fluid_load_data_low_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
+	/* Helper cacheDir used to navigate to cache subdirs, ie data, mesh, particles */
+	char cacheDir[FILE_MAX], helperDir[FILE_MAX];
+	cacheDir[0] = '\0';
+	helperDir[0] = '\0';
+
+	mCommands.clear();
+
+	if (mUsingSmoke) {
+		BLI_path_join(cacheDir, sizeof(cacheDir), smd->domain->cache_directory, FLUID_CACHE_DIR_DATA_LOW, NULL);
+		if (!BLI_exists(cacheDir)) return 0;
+		printf("READCACHE 2()\n");
+
+		ss.str("");
+		ss << "smoke_load_geometry_low_" << mCurrentID << "('" << cacheDir << "', " << framenr << ")";
 		mCommands.push_back(ss.str());
+		runPythonString(mCommands);
+	}
+	if (mUsingLiquid) {
+		/* First try loading the mesh */
+		BLI_path_join(cacheDir, sizeof(cacheDir), smd->domain->cache_directory, FLUID_CACHE_DIR_MESH_LOW, NULL);
+		if (BLI_exists(cacheDir)) {
 
-		if (mUsingSmoke) {
 			ss.str("");
-			ss <<  "smoke_load_data_low_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
+			ss << "liquid_load_mesh_low_" << mCurrentID << "('" << cacheDir << "', " << framenr << ")";
 			mCommands.push_back(ss.str());
+			runPythonString(mCommands);
+
+			ss.str("");
+			ss << "mesh_low_" << std::setw(4) << std::setfill('0') << framenr << ".bobj.gz";
+			BLI_join_dirfile(helperDir, sizeof(helperDir), cacheDir, ss.str().c_str());
+			updateMeshData(helperDir);
+
+			readSuccess = true;
 		}
+		/* If no mesh found, try loading FLIP particles */
+		BLI_path_join(cacheDir, sizeof(cacheDir), smd->domain->cache_directory, FLUID_CACHE_DIR_DATA_LOW, NULL);
+		if (BLI_exists(cacheDir)) {
 
-		if (mUsingLiquid) {
 			ss.str("");
-			ss <<  "liquid_load_data_low_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
+			ss << "liquid_load_data_low_" << mCurrentID << "('" << cacheDir << "', " << framenr << ", True)";
 			mCommands.push_back(ss.str());
-		}
+			runPythonString(mCommands);
+			
+			ss.str("");
+			ss << "pp_" << std::setw(4) << std::setfill('0') << framenr << ".uni";
+			BLI_join_dirfile(helperDir, sizeof(helperDir), cacheDir, ss.str().c_str());
+			updateParticleData(helperDir, false);
 
-		mCommands.push_back(ss.str());
+			ss.str("");
+			ss << "pVel_" << std::setw(4) << std::setfill('0') << framenr << ".uni";
+			BLI_join_dirfile(helperDir, sizeof(helperDir), cacheDir, ss.str().c_str());
+			updateParticleData(helperDir, false);
 
-		runPythonString(mCommands);
-	} catch (const std::runtime_error& error) {
-		std::cout << "Missing cache files. Continue with simulation" << std::endl;
-		return 0;
+			readSuccess = true;
+		}
 	}
-	return 1;
-}
+	if (mUsingDrops || mUsingBubbles || mUsingFloats || mUsingTracers) {
+		/* Optional liquid particles all live in one particle system */
+		BLI_path_join(cacheDir, sizeof(cacheDir), smd->domain->cache_directory, FLUID_CACHE_DIR_PARTICLES_LOW, NULL);
+		if (BLI_exists(cacheDir)) {
 
-void FLUID::freeGeometry(SmokeModifierData *smd)
-{
-	std::string path(smd->domain->cache_directory);
+			ss.str("");
+			ss << "liquid_load_particles_low_" << mCurrentID << "('" << cacheDir << "', " << framenr << ")";
+			mCommands.push_back(ss.str());
+			runPythonString(mCommands);
+			
+			ss.str("");
+			ss << "ppSnd_" << std::setw(4) << std::setfill('0') << framenr << ".uni";
+			BLI_join_dirfile(helperDir, sizeof(helperDir), cacheDir, ss.str().c_str());
+			updateParticleData(helperDir, true);
+			
+			ss.str("");
+			ss << "pVelSnd_" << std::setw(4) << std::setfill('0') << framenr << ".uni";
+			BLI_join_dirfile(helperDir, sizeof(helperDir), cacheDir, ss.str().c_str());
+			updateParticleData(helperDir, true);
 
-	mCommands.clear();
-	std::ostringstream ss;
-	ss <<  "free_geometry_" << mCurrentID << "(r'" << path << "')";
-	mCommands.push_back(ss.str());
+			ss.str("");
+			ss << "pLifeSnd_" << std::setw(4) << std::setfill('0') << framenr << ".uni";
+			BLI_join_dirfile(helperDir, sizeof(helperDir), cacheDir, ss.str().c_str());
+			updateParticleData(helperDir, true);
 
-	runPythonString(mCommands);
+			readSuccess = true;
+		}
+		
+	}
+	return readSuccess;
 }
-/* END TODO (se

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list