[Bf-blender-cvs] [db18178] fluid-mantaflow: refactored manta script export and also added script export functionality for liquids

Sebastián Barschkis noreply at git.blender.org
Mon Sep 19 01:21:54 CEST 2016


Commit: db18178f97e1e81a29193bcb5d32bff0060047e3
Author: Sebastián Barschkis
Date:   Sun Sep 11 19:24:18 2016 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBdb18178f97e1e81a29193bcb5d32bff0060047e3

refactored manta script export and also added script export functionality for liquids

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

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	source/blender/editors/physics/physics_fluid.c

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 7cca7b5..668b4f2 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -111,6 +111,8 @@ void liquid_update_mesh_data(struct FLUID *liquid, char *filename);
 void liquid_save_mesh_high(struct FLUID *liquid, char *filename);
 void liquid_save_data_high(struct FLUID *liquid, char *pathname);
 void liquid_load_data_high(struct FLUID *liquid, char *pathname);
+void liquid_manta_export(struct FLUID* smoke, SmokeModifierData *smd);
+
 
 #ifdef __cplusplus
 }
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 216e09c..4738999 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -216,6 +216,7 @@ void FLUID::initSmoke(SmokeModifierData *smd)
 		+ smoke_variables_low
 		+ smoke_bounds_low
 		+ smoke_adaptive_step
+		+ smoke_export_low
 		+ smoke_step_low;
 	std::string finalString = parseScript(tmpString, smd);
 	mCommands.clear();
@@ -231,6 +232,7 @@ void FLUID::initSmokeHigh(SmokeModifierData *smd)
 		+ smoke_uv_setup
 		+ smoke_bounds_high
 		+ smoke_wavelet_turbulence_noise
+		+ smoke_export_high
 		+ smoke_step_high;
 	std::string finalString = parseScript(tmpString, smd);
 	mCommands.clear();
@@ -633,7 +635,7 @@ std::string FLUID::parseScript(const std::string& setup_string, SmokeModifierDat
 	return res.str();
 }
 
-void FLUID::exportScript(SmokeModifierData *smd)
+void FLUID::exportSmokeScript(SmokeModifierData *smd)
 {
 	// Setup low
 	std::string manta_script =
@@ -711,7 +713,8 @@ void FLUID::exportScript(SmokeModifierData *smd)
 	std::string final_script = FLUID::parseScript(manta_script, smd);
 	
 	// Add standalone mode (loop, gui, ...)
-	final_script += smoke_standalone;
+	final_script += smoke_standalone_load;
+	final_script += fluid_standalone;
 	
 	// Write script
 	std::ofstream myfile;
@@ -720,18 +723,71 @@ void FLUID::exportScript(SmokeModifierData *smd)
 	myfile.close();
 }
 
-void FLUID::exportGrids(SmokeModifierData *smd)
+void FLUID::exportSmokeData(SmokeModifierData *smd)
 {
-	PyGILState_STATE gilstate = PyGILState_Ensure();
+	bool highres = smd->domain->flags & MOD_SMOKE_HIGHRES;
+
+	char parent_dir[1024];
+	BLI_split_dir_part(smd->domain->manta_filepath, parent_dir, sizeof(parent_dir));
 	
-	// Export low res grids
-	PyRun_SimpleString(FLUID::parseScript(smoke_export_low, smd).c_str());
+	FLUID::saveSmokeData(parent_dir);
+	if (highres)
+		FLUID::saveSmokeDataHigh(parent_dir);
+}
 
-	// Export high res grids
-	if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
-		PyRun_SimpleString(FLUID::parseScript(smoke_export_high, smd).c_str());
+void FLUID::exportLiquidScript(SmokeModifierData *smd)
+{
+	bool highres = smd->domain->flags & MOD_SMOKE_HIGHRES;
+
+	std::string manta_script;
+	
+	manta_script += manta_import
+		+ fluid_solver_low
+		+ fluid_adaptive_time_stepping_low
+		+ liquid_alloc_low
+		+ liquid_init_phi
+		+ liquid_bounds_low
+		+ liquid_variables_low;
+
+	if (highres) {
+		manta_script += fluid_solver_high
+			+ fluid_adaptive_time_stepping_high
+			+ liquid_alloc_high
+			+ liquid_bounds_high
+			+ liquid_variables_high;
 	}
-	PyGILState_Release(gilstate);
+
+	manta_script += liquid_import_low;
+	if (highres)
+		manta_script += liquid_import_high;
+
+	manta_script += liquid_step_low;
+	if (highres)
+		manta_script += liquid_step_high;
+	
+	manta_script += liquid_adaptive_step;
+	manta_script += liquid_standalone_load;
+	manta_script += fluid_standalone;
+
+	std::string final_script = FLUID::parseScript(manta_script, smd);
+	
+	// Write script
+	std::ofstream myfile;
+	myfile.open(smd->domain->manta_filepath);
+	myfile << final_script;
+	myfile.close();
+}
+
+void FLUID::exportLiquidData(SmokeModifierData *smd)
+{
+	bool highres = smd->domain->flags & MOD_SMOKE_HIGHRES;
+
+	char parent_dir[1024];
+	BLI_split_dir_part(smd->domain->manta_filepath, parent_dir, sizeof(parent_dir));
+	
+	FLUID::saveLiquidData(parent_dir);
+	if (highres)
+		FLUID::saveLiquidDataHigh(parent_dir);
 }
 
 void* FLUID::getGridPointer(std::string gridName, std::string solverName)
@@ -943,6 +999,30 @@ void FLUID::saveMeshHigh(char *filename)
 	runPythonString(mCommands);
 }
 
+void FLUID::saveSmokeData(char *pathname)
+{
+	std::string path(pathname);
+	
+	mCommands.clear();
+	std::ostringstream save_smoke_data_low;
+	save_smoke_data_low <<  "save_smoke_data_low('" << path << "')";
+	mCommands.push_back(save_smoke_data_low.str());
+	
+	runPythonString(mCommands);
+}
+
+void FLUID::saveSmokeDataHigh(char *pathname)
+{
+	std::string path(pathname);
+	
+	mCommands.clear();
+	std::ostringstream save_smoke_data_high;
+	save_smoke_data_high <<  "save_smoke_data_high('" << path << "')";
+	mCommands.push_back(save_smoke_data_high.str());
+	
+	runPythonString(mCommands);
+}
+
 void FLUID::saveLiquidData(char *pathname)
 {
 	std::string path(pathname);
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index c6690f5..607bee0 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -58,14 +58,18 @@ public:
 	void updatePointersHigh(struct SmokeModifierData *smd);
 
 	// IO for Mantaflow scene script
-	void exportScript(struct SmokeModifierData *smd);
-	void exportGrids(struct SmokeModifierData *smd);
+	void exportSmokeScript(struct SmokeModifierData *smd);
+	void exportSmokeData(struct SmokeModifierData *smd);
+	void exportLiquidScript(struct SmokeModifierData *smd);
+	void exportLiquidData(struct SmokeModifierData *smd);
 	
 	// Write files for liquids
 	void saveMesh(char *filename);
 	void saveMeshHigh(char *filename);
 	void saveLiquidData(char *pathname);
 	void saveLiquidDataHigh(char *pathname);
+	void saveSmokeData(char *pathname);
+	void saveSmokeDataHigh(char *pathname);
 
 	// Load files for liquids
 	void loadLiquidData(char *pathname);
@@ -239,4 +243,4 @@ private:
 	void* getGridPointer(std::string gridName, std::string solverName);
 };
 
-#endif
\ No newline at end of file
+#endif
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index 3b3d097..2aa457b 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -58,8 +58,8 @@ extern "C" size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z
 extern "C" void smoke_manta_export(FLUID* smoke, SmokeModifierData *smd)
 {
 	if (!smoke && !smd) return;
-	smoke->exportScript(smd);
-	smoke->exportGrids(smd);
+	smoke->exportSmokeScript(smd);
+	smoke->exportSmokeData(smd);
 }
 
 extern "C" void smoke_step(FLUID *smoke, SmokeModifierData *smd)
@@ -610,3 +610,9 @@ extern "C" void liquid_update_mesh_data(FLUID *liquid, char* filename)
 	liquid->updateMeshData(filename);
 }
 
+extern "C" void liquid_manta_export(FLUID* liquid, SmokeModifierData *smd)
+{
+	if (!liquid && !smd) return;
+	liquid->exportLiquidScript(smd);
+	liquid->exportLiquidData(smd);
+}
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 592f741..a54e0c1 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -379,3 +379,16 @@ if 'maxVel'           in globals() : del maxVel\n";
 
 const std::string liquid_delete_variables_high = "\n\
 mantaMsg('Deleting highres liquid variables')\n";
+
+//////////////////////////////////////////////////////////////////////
+// STANDALONE MODE
+//////////////////////////////////////////////////////////////////////
+
+const std::string liquid_standalone_load = "\n\
+# import *.uni files\n\
+path_prefix = '$MANTA_EXPORT_PATH$'\n\
+load_liquid_data_low(path_prefix)\n\
+if using_highres:\n\
+    load_liquid_data_high(path_prefix)\n";
+
+
diff --git a/intern/mantaflow/intern/strings/shared_script.h b/intern/mantaflow/intern/strings/shared_script.h
index 1473b02..9f9ba95 100644
--- a/intern/mantaflow/intern/strings/shared_script.h
+++ b/intern/mantaflow/intern/strings/shared_script.h
@@ -122,3 +122,22 @@ if 'xl' in globals() : del xl\n";
 
 const std::string gc_collect = "\n\
 gc.collect()\n";
+
+//////////////////////////////////////////////////////////////////////
+// STANDALONE MODE
+//////////////////////////////////////////////////////////////////////
+
+const std::string fluid_standalone = "\n\
+if (GUI):\n\
+    gui=Gui()\n\
+    gui.show()\n\
+    gui.pause()\n\
+\n\
+start_frame = $CURRENT_FRAME$\n\
+end_frame = 100\n\
+\n\
+# All low and high res steps\n\
+while start_frame <= end_frame:\n\
+    manta_step(start_frame)\n\
+    start_frame += 1\n";
+
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h
index 0fb19e6..5f1caa5 100644
--- a/intern/mantaflow/intern/strings/smoke_script.h
+++ b/intern/mantaflow/intern/strings/smoke_script.h
@@ -342,71 +342,68 @@ def update_flame_high():\n\
 //////////////////////////////////////////////////////////////////////
 
 const std::string smoke_import_low = "\n\
-def import_grids_low():\n\
-    mantaMsg('Importing grids low')\n\
-    density.load('$MANTA_EXPORT_PATH$density.uni')\n\
-    flags.load('$MANTA_EXPORT_PATH$flags.uni')\n\
-    vel.save(os.path.join('$MANTA_EXPORT_PATH$','vel.uni'))\n\
-    forces.load('$MANTA_EXPORT_PATH$forces.uni')\n\
-    inflow_grid.load('$MANTA_EXPORT_PATH$inflow_low.uni')\n\
-    fuel_inflow.load('$MANTA_EXPORT_PATH$fuel_inflow.uni')\n\
+def load_smoke_data_low(path):\n\
+    density.load(path + str('density.uni'))\n\
+    flags.load(path + str('flags.uni'))\n\
+    vel.load(path + str('vel.uni'))\n\
+    forces.load(path + str('forces.uni')\n\
+    inflow_grid.load(path + str('inflow_low.uni')\n\
+    fuel_inflow.load(path + str('fuel_inflow.uni')\n\
     if using_colors:\n\
-        color_r.load('$MANTA_EXPORT_PATH$color_r.uni')\n\
-        color_g.load('$MANTA_EXPORT_PATH$color_g.uni')\n\
-        color_b.load('$MANTA_EXPORT_PATH$color_b.uni')\n\
+        color_r.load(path + str('color_r.uni')\n\
+        color_g.load(path + str('color_g.uni')\n\
+        color_b.load(path + str('color_b.uni')\n\
     if using_heat:\n\
-        heat.load('$MANTA_EXPORT_PATH$heat.

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list