[Bf-blender-cvs] [d1f5551bdec] fluid-mantaflow: preparations for liquid real time updates during bake

Sebastián Barschkis noreply at git.blender.org
Sat May 5 21:24:50 CEST 2018


Commit: d1f5551bdec4193740a195faee141cc998bee769
Author: Sebastián Barschkis
Date:   Wed May 2 16:43:39 2018 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBd1f5551bdec4193740a195faee141cc998bee769

preparations for liquid real time updates during bake

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

M	intern/mantaflow/intern/FLUID.cpp
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/shared_script.h
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/editors/physics/physics_fluid.c

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

diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index a1d6eed139a..0e6391a85d9 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -1181,6 +1181,11 @@ int FLUID::writeCache(SmokeModifierData *smd, int framenr)
 	if (with_debug)
 		std::cout << "FLUID::writeCacheLow()" << std::endl;
 
+	// Exit liquids early - no shadows to write
+	if (mUsingLiquid) {
+		return true;
+	}
+
 	std::ostringstream ss;
 	std::vector<std::string> pythonCommands;
 	bool writeSuccess = false;
@@ -1200,9 +1205,6 @@ int FLUID::writeCache(SmokeModifierData *smd, int framenr)
 
 		writeSuccess = true;
 	}
-	if (mUsingLiquid) {
-		writeSuccess = true;
-	}
 	runPythonString(pythonCommands);
 
 	return writeSuccess;
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 3595060c5fb..585f863d397 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -356,7 +356,7 @@ def liquid_load_particles_$ID$(path, framenr, file_format):\n\
 
 const std::string liquid_save_data = "\n\
 def liquid_save_data_$ID$(path, framenr, file_format):\n\
-    mantaMsg('Liquid save data low')\n\
+    mantaMsg('Liquid save data')\n\
     framenr = fluid_cache_get_framenr_formatted_$ID$(framenr)\n\
     phi_s$ID$.save(os.path.join(path, 'phi_' + framenr + file_format))\n\
     phiTmp_s$ID$.save(os.path.join(path, 'phiTmp_' + framenr + file_format))\n\
@@ -365,14 +365,14 @@ def liquid_save_data_$ID$(path, framenr, file_format):\n\
 
 const std::string liquid_save_flip = "\n\
 def liquid_save_flip_$ID$(path, framenr, file_format):\n\
-    mantaMsg('Liquid save data low')\n\
+    mantaMsg('Liquid save flip')\n\
     framenr = fluid_cache_get_framenr_formatted_$ID$(framenr)\n\
     pp_s$ID$.save(os.path.join(path, 'pp_' + framenr + file_format))\n\
     pVel_pp$ID$.save(os.path.join(path, 'pVel_' + framenr + file_format))\n";
 
 const std::string liquid_save_mesh = "\n\
 def liquid_save_mesh_$ID$(path, framenr, file_format):\n\
-    mantaMsg('Liquid save mesh high')\n\
+    mantaMsg('Liquid save mesh')\n\
     framenr = fluid_cache_get_framenr_formatted_$ID$(framenr)\n\
     \n\
     interpolateGrid(target=phi_xl$ID$, source=phiTmp_s$ID$) # mis-use phiParts as temp grid\n\
@@ -401,7 +401,7 @@ def liquid_save_mesh_$ID$(path, framenr, file_format):\n\
 
 const std::string liquid_save_particles = "\n\
 def liquid_save_particles_$ID$(path, framenr, file_format):\n\
-    mantaMsg('Liquid save particles low')\n\
+    mantaMsg('Liquid save particles')\n\
     framenr = fluid_cache_get_framenr_formatted_$ID$(framenr)\n\
     ppSnd_sp$ID$.save(os.path.join(path, 'ppSnd_' + framenr + file_format))\n\
     pVelSnd_pp$ID$.save(os.path.join(path, 'pVelSnd_' + framenr + file_format))\n\
diff --git a/intern/mantaflow/intern/strings/shared_script.h b/intern/mantaflow/intern/strings/shared_script.h
index ebb71ed4550..f2ec0d0c0d3 100644
--- a/intern/mantaflow/intern/strings/shared_script.h
+++ b/intern/mantaflow/intern/strings/shared_script.h
@@ -37,8 +37,9 @@ const std::string manta_import = "\
 from manta import *\n\
 import os.path, shutil, math, sys, gc, multiprocessing, platform, time\n\
 \n\
-# TODO (sebbas): Use this to simulate Windows multiprocessing (has default mode spawn)\n\
 debugMp = True\n\
+isWindows = platform.system() != 'Darwin' and platform.system() != 'Linux'\n\
+# TODO (sebbas): Use this to simulate Windows multiprocessing (has default mode spawn)\n\
 #try:\n\
 #    multiprocessing.set_start_method('spawn')\n\
 #except:\n\
@@ -321,6 +322,8 @@ const std::string fluid_bake_data = "\n\
 def bake_fluid_process_data_$ID$(framenr, format_data, format_particles, path_data):\n\
     mantaMsg('Bake fluid data')\n\
     \n\
+    s$ID$.frame = framenr\n\
+    \n\
     start_time = time.time()\n\
     if using_smoke_s$ID$:\n\
         smoke_adaptive_step_$ID$(framenr)\n\
@@ -338,7 +341,7 @@ def bake_fluid_process_data_$ID$(framenr, format_data, format_particles, path_da
     mantaMsg('--- Writing: %s seconds ---' % (time.time() - start_time))\n\
 \n\
 def bake_fluid_data_$ID$(path_data, framenr, format_data, format_particles):\n\
-    if debugMp or platform.system() != 'Darwin' and platform.system() != 'Linux':\n\
+    if debugMp or isWindows:\n\
         bake_fluid_process_data_$ID$(framenr, format_data, format_particles, path_data)\n\
     else:\n\
         fluid_cache_multiprocessing_start_$ID$(function=bake_fluid_process_data_$ID$, framenr=framenr, format_data=format_data, format_particles=format_particles, path_data=path_data)\n";
@@ -346,13 +349,16 @@ def bake_fluid_data_$ID$(path_data, framenr, format_data, format_particles):\n\
 const std::string fluid_bake_noise = "\n\
 def bake_noise_process_$ID$(framenr, format_data, format_noise, path_data, path_noise):\n\
     mantaMsg('Bake fluid noise')\n\
+    \n\
+    sn$ID$.frame = framenr\n\
+    \n\
     fluid_load_data_$ID$(path_data, framenr, format_data)\n\
     smoke_load_data_$ID$(path_data, framenr, format_data)\n\
     smoke_adaptive_step_noise_$ID$(framenr)\n\
     smoke_save_noise_$ID$(path_noise, framenr, format_noise)\n\
 \n\
 def bake_noise_$ID$(path_data, path_noise, framenr, format_data, format_noise):\n\
-    if debugMp or platform.system() != 'Darwin' and platform.system() != 'Linux':\n\
+    if debugMp or isWindows:\n\
         bake_noise_process_$ID$(framenr, format_data, format_noise, path_data, path_noise)\n\
     else:\n\
         fluid_cache_multiprocessing_start_$ID$(function=bake_noise_process_$ID$, framenr=framenr, format_data=format_data, format_noise=format_noise, path_data=path_data, path_noise=path_noise)\n";
@@ -361,7 +367,8 @@ const std::string fluid_bake_mesh = "\n\
 def bake_mesh_process_$ID$(framenr, format_data, format_mesh, format_particles, path_data, path_mesh):\n\
     mantaMsg('Bake fluid mesh')\n\
     \n\
-    fluid_load_data_$ID$(path_data, framenr, format_data)\n\
+    sm$ID$.frame = framenr\n\
+    \n\
     #if using_smoke_s$ID$:\n\
         # TODO (sebbas): Future update could include smoke mesh (vortex sheets)\n\
     if using_liquid_s$ID$:\n\
@@ -370,7 +377,7 @@ def bake_mesh_process_$ID$(framenr, format_data, format_mesh, format_particles,
         liquid_save_mesh_$ID$(path_mesh, framenr, format_mesh)\n\
 \n\
 def bake_mesh_$ID$(path_data, path_mesh, framenr, format_data, format_mesh, format_particles):\n\
-    if debugMp or platform.system() != 'Darwin' and platform.system() != 'Linux':\n\
+    if debugMp or isWindows:\n\
         bake_mesh_process_$ID$(framenr, format_data, format_mesh, format_particles, path_data, path_mesh)\n\
     else:\n\
         fluid_cache_multiprocessing_start_$ID$(function=bake_mesh_process_$ID$, framenr=framenr, format_data=format_data, format_mesh=format_mesh, format_particles=format_particles, path_data=path_data, path_mesh=path_mesh)\n";
@@ -379,6 +386,8 @@ const std::string fluid_bake_particles = "\n\
 def bake_particles_process_$ID$(framenr, format_data, format_particles, path_data, path_particles):\n\
     mantaMsg('Bake secondary particles')\n\
     \n\
+    sp$ID$.frame = framenr\n\
+    \n\
     fluid_load_data_$ID$(path_data, framenr, format_data)\n\
     #if using_smoke_s$ID$:\n\
         # TODO (sebbas): Future update could include smoke particles (e.g. fire sparks)\n\
@@ -391,7 +400,7 @@ def bake_particles_process_$ID$(framenr, format_data, format_particles, path_dat
         liquid_save_particles_$ID$(path_particles, framenr, format_particles)\n\
 \n\
 def bake_particles_$ID$(path_data, path_particles, framenr, format_data, format_particles):\n\
-    if debugMp or platform.system() != 'Darwin' and platform.system() != 'Linux':\n\
+    if debugMp or isWindows:\n\
         bake_particles_process_$ID$(framenr, format_data, format_particles, path_data, path_particles)\n\
     else:\n\
         fluid_cache_multiprocessing_start_$ID$(function=bake_particles_process_$ID$, framenr=framenr, format_data=format_data, format_particles=format_particles, path_data=path_data, path_particles=path_particles)\n";
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 1c1cf3cd44a..d97afddb667 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -2625,9 +2625,8 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd
 				/* Emission from mesh */
 				else if (sfs->source == MOD_SMOKE_FLOW_SOURCE_MESH) {
 					/* Update flow object frame */
-					BLI_mutex_lock(&object_update_lock);
+					// BLI_mutex_lock() called in smoke_step(), so safe to update subframe here
 					BKE_object_modifier_update_subframe(scene, flowobj, true, 5, BKE_scene_frame_get(scene), eModifierType_Smoke);
-					BLI_mutex_unlock(&object_update_lock);
 
 					/* Apply flow */
 					if (subframes) {
@@ -3451,6 +3450,8 @@ int smoke_step(Scene *scene, Object *ob, SmokeModifierData *smd, int frame)
 
 	time_per_frame = 0;
 
+	BLI_mutex_lock(&object_update_lock);
+
 	// loop as long as time_per_frame (sum of sudivdt) does not exceed dt (actual framelength)
 	while (time_per_frame < dt)
 	{
@@ -3473,6 +3474,7 @@ int smoke_step(Scene *scene, Object *ob, SmokeModifierData *smd, int frame)
 	if (sds->type == MOD_SMOKE_DOMAIN_TYPE_GAS) {
 		smoke_calc_transparency(sds, scene);
 	}
+	BLI_mutex_unlock(&object_update_lock);
 
 	/* Write call currently only writes shadow grid */
 	return fluid_write_cache(sds->fluid, smd, frame);
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index 2c08d71264a..08d88d794d2 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -1206,11 +1206,11 @@ static void fluid_manta_bake_sequence(FluidMantaflowJob *job)
 	scene->r.cfra = (int)frame;
 
 	/* Update animation system - needs annoying lock */
-//	G.is_rendering = true;
-//	BKE_spacedata_draw_locks(true);
+	G.is_rendering = true;
+	BKE_spacedata_draw_locks(true);
 	ED_update_for_newframe(job->bmain, scene, 1);
-//	G.is_rendering = false;
-//	BKE_spacedata_draw_locks(false);
+	G.is_rendering = false;
+	BKE_spacedata

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list