[Bf-blender-cvs] [86b12746653] fluid-mantaflow: refactored liquid script setup

Sebastián Barschkis noreply at git.blender.org
Mon May 14 15:56:59 CEST 2018


Commit: 86b127466537ef3687b4539d8c9798804c35daf0
Author: Sebastián Barschkis
Date:   Mon May 14 15:17:21 2018 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB86b127466537ef3687b4539d8c9798804c35daf0

refactored liquid script setup

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

M	intern/mantaflow/intern/FLUID.cpp
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/shared_script.h
M	release/scripts/startup/bl_operators/object_quick_effects.py
M	source/blender/blenkernel/intern/smoke.c

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

diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index f9667e11c4b..5514185c07c 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -421,7 +421,7 @@ void FLUID::initLiquidMesh(SmokeModifierData *smd)
 {
 	std::vector<std::string> pythonCommands;
 	std::string tmpString = liquid_alloc_mesh
-		+ liquid_variables_mesh
+		+ liquid_step_mesh
 		+ liquid_save_mesh;
 	std::string finalString = parseScript(tmpString, smd);
 	pythonCommands.push_back(finalString);
@@ -1406,8 +1406,6 @@ void FLUID::updateVariablesHigh(SmokeModifierData *smd)
 	tmpString += fluid_variables_noise;
 	if (mUsingSmoke)
 		tmpString += smoke_variables_noise;
-	if (mUsingLiquid)
-		tmpString += liquid_variables_mesh;
 	finalString = parseScript(tmpString, smd);
 	pythonCommands.push_back(finalString);
 
@@ -1470,8 +1468,7 @@ void FLUID::exportLiquidScript(SmokeModifierData *smd)
 		manta_script += fluid_variables_noise
 			+ fluid_solver_noise
 			+ fluid_adaptive_time_stepping_noise
-			+ liquid_alloc_mesh
-			+ liquid_variables_mesh;
+			+ liquid_alloc_mesh;
 	}
 
 	manta_script += liquid_load_data;
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index a72174354da..e9089bc87e9 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -51,9 +51,6 @@ smoothenNeg_s$ID$      = $MESH_SMOOTHEN_NEG$\n\
 randomness_s$ID$       = $PARTICLE_RANDOMNESS$\n\
 surfaceTension_s$ID$   = $LIQUID_SURFACE_TENSION$\n";
 
-const std::string liquid_variables_mesh = "\n\
-mantaMsg('Liquid variables high')\n";
-
 //////////////////////////////////////////////////////////////////////
 // GRIDS & MESH & PARTICLESYSTEM
 //////////////////////////////////////////////////////////////////////
@@ -93,7 +90,10 @@ mesh_sm$ID$     = sm$ID$.create(Mesh)\n\
 \n\
 # Acceleration data for particle nbs\n\
 pindex_sm$ID$  = sm$ID$.create(ParticleIndexSystem)\n\
-gpi_sm$ID$     = sm$ID$.create(IntGrid)\n";
+gpi_sm$ID$     = sm$ID$.create(IntGrid)\n\
+\n\
+# Keep track of important objects in dict to load them later on\n\
+liquid_mesh_dict_s$ID$ = dict(liquid_mesh=mesh_sm$ID$)\n";
 
 const std::string liquid_init_phi = "\n\
 phi_s$ID$.initFromFlags(flags_s$ID$)\n\
@@ -140,9 +140,6 @@ def liquid_post_step_$ID$():\n\
     if using_invel_s$ID$:\n\
         invel_s$ID$.clear()\n\
     \n\
-#    phiIn_s$ID$.setConst(9999)\n\
-#    phiOutIn_s$ID$.setConst(9999)\n\
-    \n\
     #copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n\
     #x_vel_s$ID$.multConst( 1.0/Real(gs_s$ID$.x) )\n\
     #y_vel_s$ID$.multConst( 1.0/Real(gs_s$ID$.y) )\n\
@@ -282,6 +279,32 @@ def liquid_step_$ID$():\n\
     adjustNumber(parts=pp_s$ID$, vel=vel_s$ID$, flags=flags_s$ID$, minParticles=minParticles_s$ID$, maxParticles=maxParticles_s$ID$, phi=phi_s$ID$, exclude=phiObs_s$ID$, radiusFactor=1., narrowBand=adjustedNarrowBandWidth_s$ID$)\n\
     flipVelocityUpdate(vel=vel_s$ID$, velOld=velOld_s$ID$, flags=flags_s$ID$, parts=pp_s$ID$, partVel=pVel_pp$ID$, flipRatio=0.97)\n";
 
+const std::string liquid_step_mesh = "\n\
+def liquid_step_mesh_$ID$():\n\
+    mantaMsg('Liquid step mesh')\n\
+    \n\
+    interpolateGrid(target=phi_sm$ID$, source=phiTmp_s$ID$) # mis-use phiParts as temp grid\n\
+    \n\
+    # create surface\n\
+    pp_sm$ID$.readParticles(pp_s$ID$)\n\
+    gridParticleIndex(parts=pp_sm$ID$, flags=flags_sm$ID$, indexSys=pindex_sm$ID$, index=gpi_sm$ID$)\n\
+    \n\
+    if using_final_mesh_s$ID$:\n\
+        mantaMsg('Liquid using improved particle levelset')\n\
+        improvedParticleLevelset(pp_sm$ID$, pindex_sm$ID$, flags_sm$ID$, gpi_sm$ID$, phiParts_sm$ID$, radiusFactor_s$ID$, smoothenPos_s$ID$, smoothenNeg_s$ID$, smoothenLower_s$ID$, smoothenUpper_s$ID$)\n\
+    else:\n\
+        mantaMsg('Liquid using union particle levelset')\n\
+        unionParticleLevelset(pp_sm$ID$, pindex_sm$ID$, flags_sm$ID$, gpi_sm$ID$, phiParts_sm$ID$, radiusFactor_s$ID$)\n\
+    \n\
+    phi_sm$ID$.addConst(1.) # shrink slightly\n\
+    phi_sm$ID$.join(phiParts_sm$ID$)\n\
+    extrapolateLsSimple(phi=phi_sm$ID$, distance=narrowBandWidth_s$ID$+2, inside=True)\n\
+    extrapolateLsSimple(phi=phi_sm$ID$, distance=3)\n\
+    phi_sm$ID$.setBoundNeumann(boundaryWidth_s$ID$) # make sure no particles are placed at outer boundary\n\
+    \n\
+    phi_sm$ID$.setBound(0.5,int(((upres_sm$ID$)*2)-2) )\n\
+    phi_sm$ID$.createMesh(mesh_sm$ID$)\n";
+
 const std::string liquid_step_particles = "\n\
 def liquid_step_particles_$ID$():\n\
     mantaMsg('Sampling snd particles')\n\
@@ -317,6 +340,11 @@ def liquid_load_flip_$ID$(path, framenr, file_format):\n\
     mantaMsg('Liquid load flip')\n\
     fluid_file_import_s$ID$(dict=liquid_flip_dict_s$ID$, path=path, framenr=framenr, file_format=file_format)\n";
 
+const std::string liquid_load_mesh = "\n\
+def liquid_save_mesh_$ID$(path, framenr, file_format):\n\
+    mantaMsg('Liquid load mesh')\n\
+    fluid_file_import_s$ID$(dict=liquid_mesh_dict_s$ID$, path=path, framenr=framenr, file_format=file_format)\n";
+
 //////////////////////////////////////////////////////////////////////
 // EXPORT
 //////////////////////////////////////////////////////////////////////
@@ -334,30 +362,7 @@ def liquid_save_flip_$ID$(path, 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')\n\
-    framenr = fluid_cache_get_framenr_formatted_$ID$(framenr)\n\
-    \n\
-    interpolateGrid(target=phi_sm$ID$, source=phiTmp_s$ID$) # mis-use phiParts as temp grid\n\
-    \n\
-    # create surface\n\
-    pp_sm$ID$.readParticles(pp_s$ID$)\n\
-    gridParticleIndex(parts=pp_sm$ID$, flags=flags_sm$ID$, indexSys=pindex_sm$ID$, index=gpi_sm$ID$)\n\
-    \n\
-    if using_final_mesh_s$ID$:\n\
-        mantaMsg('Liquid using improved particle levelset')\n\
-        improvedParticleLevelset(pp_sm$ID$, pindex_sm$ID$, flags_sm$ID$, gpi_sm$ID$, phiParts_sm$ID$, radiusFactor_s$ID$, smoothenPos_s$ID$, smoothenNeg_s$ID$, smoothenLower_s$ID$, smoothenUpper_s$ID$)\n\
-    else:\n\
-        mantaMsg('Liquid using union particle levelset')\n\
-        unionParticleLevelset(pp_sm$ID$, pindex_sm$ID$, flags_sm$ID$, gpi_sm$ID$, phiParts_sm$ID$, radiusFactor_s$ID$)\n\
-    \n\
-    phi_sm$ID$.addConst(1.) # shrink slightly\n\
-    phi_sm$ID$.join(phiParts_sm$ID$)\n\
-    extrapolateLsSimple(phi=phi_sm$ID$, distance=narrowBandWidth_s$ID$+2, inside=True)\n\
-    extrapolateLsSimple(phi=phi_sm$ID$, distance=3)\n\
-    phi_sm$ID$.setBoundNeumann(boundaryWidth_s$ID$) # make sure no particles are placed at outer boundary\n\
-    \n\
-    phi_sm$ID$.setBound(0.5,int(((upres_sm$ID$)*2)-2) )\n\
-    phi_sm$ID$.createMesh(mesh_sm$ID$)\n\
-    mesh_sm$ID$.save(os.path.join(path, 'liquid_mesh_' + framenr + file_format))\n";
+    fluid_file_export_s$ID$(dict=liquid_mesh_dict_s$ID$, path=path, framenr=framenr, file_format=file_format)\n";
 
 //////////////////////////////////////////////////////////////////////
 // STANDALONE MODE
diff --git a/intern/mantaflow/intern/strings/shared_script.h b/intern/mantaflow/intern/strings/shared_script.h
index 57a18edc511..7db8990076b 100644
--- a/intern/mantaflow/intern/strings/shared_script.h
+++ b/intern/mantaflow/intern/strings/shared_script.h
@@ -374,6 +374,7 @@ def bake_mesh_process_$ID$(framenr, format_data, format_mesh, format_particles,
     if using_liquid_s$ID$:\n\
         liquid_load_data_$ID$(path_data, framenr, format_data)\n\
         liquid_load_flip_$ID$(path_data, framenr, format_particles)\n\
+        liquid_step_mesh_$ID$()\n\
         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\
diff --git a/release/scripts/startup/bl_operators/object_quick_effects.py b/release/scripts/startup/bl_operators/object_quick_effects.py
index 2dca821b60c..3e50184b9ed 100644
--- a/release/scripts/startup/bl_operators/object_quick_effects.py
+++ b/release/scripts/startup/bl_operators/object_quick_effects.py
@@ -628,9 +628,9 @@ class QuickLiquid(Operator):
         obj.modifiers[-1].domain_settings.use_surface_cache = True
         obj.modifiers[-1].domain_settings.use_volume_cache = False
         obj.modifiers[-1].domain_settings.cache_surface_format = 'BOBJECT'
-		
-        # make domain solid so that liquid becomes better visible
-        obj.draw_type = 'SOLID'
+
+        # allocate and show particle system for FLIP 
+        obj.modifiers[-1].domain_settings.use_flip_particles = True
 
         # make the domain smooth so it renders nicely
         bpy.ops.object.shade_smooth()
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 10ef8826cf4..4a1c26015a9 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -1278,6 +1278,7 @@ static void em_combineMaps(EmissionMap *output, EmissionMap *em2, int hires_mult
 
 					/* values */
 					output->influence[index_out] = em1.influence[index_in];
+					output->distances[index_out] = em1.distances[index_in];
 					if (output->velocity && em1.velocity) {
 						copy_v3_v3(&output->velocity[index_out * 3], &em1.velocity[index_in * 3]);
 					}
@@ -1293,12 +1294,11 @@ static void em_combineMaps(EmissionMap *output, EmissionMap *em2, int hires_mult
 					/* values */
 					if (additive) {
 						output->influence[index_out] += em2->influence[index_in] * sample_size;
-						output->distances[index_out] += em2->distances[index_in] * sample_size;
 					}
 					else {
 						output->influence[index_out] = MAX2(em2->influence[index_in], output->influence[index_out]);
-						output->distances[index_out] = MAX2(em2->distances[index_in], output->distances[index_out]);
 					}
+					output->distances[index_out] = MIN2(em2->distances[index_in], output->distances[index_out]);
 					if (output->velocity && em2->velocity) {
 						/* last sample replaces the velocity */
 						output->velocity[index_out * 3]		= ADD_IF_LOWER(output->velocity[index_out * 3], em2->velocity[in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list