[Bf-blender-cvs] [3097c052621] fluid-mantaflow: various smaller fixes / cleanup for obstacles and guiding

Sebastián Barschkis noreply at git.blender.org
Mon Sep 4 01:11:42 CEST 2017


Commit: 3097c052621029806d21f825e5c3eaa3bf93d798
Author: Sebastián Barschkis
Date:   Mon Sep 4 01:11:19 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB3097c052621029806d21f825e5c3eaa3bf93d798

various smaller fixes / cleanup for obstacles and guiding

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

M	intern/mantaflow/intern/FLUID.cpp
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/smoke_script.h
M	source/blender/blenkernel/intern/smoke.c

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

diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 2881d8d3919..77c50ebcc23 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -87,9 +87,6 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
 	mVelocityX      = NULL;
 	mVelocityY      = NULL;
 	mVelocityZ      = NULL;
-	mInVelocityX    = NULL;
-	mInVelocityY    = NULL;
-	mInVelocityZ    = NULL;
 	mForceX         = NULL;
 	mForceY         = NULL;
 	mForceZ         = NULL;
@@ -139,6 +136,11 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
 	mGuideVelocityY = NULL;
 	mGuideVelocityZ = NULL;
 
+	// Fluid initial velocity
+	mInVelocityX    = NULL;
+	mInVelocityY    = NULL;
+	mInVelocityZ    = NULL;
+
 	// Secondary particles
 	mFlipParticleData      = NULL;
 	mFlipParticleVelocity  = NULL;
@@ -520,9 +522,6 @@ FLUID::~FLUID()
 	mVelocityX      = NULL;
 	mVelocityY      = NULL;
 	mVelocityZ      = NULL;
-	mInVelocityX    = NULL;
-	mInVelocityY    = NULL;
-	mInVelocityZ    = NULL;
 	mForceX         = NULL;
 	mForceY         = NULL;
 	mForceZ         = NULL;
@@ -571,6 +570,11 @@ FLUID::~FLUID()
 	mGuideVelocityY = NULL;
 	mGuideVelocityZ = NULL;
 
+	// Fluid initial velocity
+	mInVelocityX    = NULL;
+	mInVelocityY    = NULL;
+	mInVelocityZ    = NULL;
+
 	// Secondary particles
 	mFlipParticleData      = NULL;
 	mFlipParticleVelocity  = NULL;
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 129728d9975..5bdc2f794a7 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -147,6 +147,8 @@ def liquid_pre_step_low_$ID$():\n\
 const std::string liquid_post_step_low = "\n\
 def liquid_post_step_low_$ID$():\n\
     forces_s$ID$.clear()\n\
+    if using_guiding_s$ID$:\n\
+        weightGuide_s$ID$.clear()\n\
     if using_invel_s$ID$:\n\
         invel_s$ID$.clear()\n\
     \n\
@@ -277,7 +279,6 @@ def liquid_step_$ID$():\n\
     \n\
     if using_guiding_s$ID$:\n\
         mantaMsg('Guiding and pressure')\n\
-        weightGuide_s$ID$.multConst(0)\n\
         weightGuide_s$ID$.addConst(alpha_s$ID$)\n\
         PD_fluid_guiding(vel=vel_s$ID$, velT=guidevel_s$ID$, flags=flags_s$ID$, weight=weightGuide_s$ID$, blurRadius=beta_s$ID$, pressure=pressure_s$ID$, tau=tau_s$ID$, sigma=sigma_s$ID$, theta=theta_s$ID$, zeroPressureFixing=not doOpen_s$ID$)\n\
     else:\n\
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h
index e19efc858cb..e6004c579e4 100644
--- a/intern/mantaflow/intern/strings/smoke_script.h
+++ b/intern/mantaflow/intern/strings/smoke_script.h
@@ -109,6 +109,7 @@ mantaMsg('Smoke alloc high')\n\
 flags_xl$ID$     = xl$ID$.create(FlagGrid)\n\
 vel_xl$ID$       = xl$ID$.create(MACGrid)\n\
 density_xl$ID$   = xl$ID$.create(RealGrid)\n\
+phiOut_xl$ID$    = xl$ID$.create(LevelsetGrid)\n\
 phiObs_xl$ID$    = xl$ID$.create(LevelsetGrid)\n\
 energy_s$ID$     = s$ID$.create(RealGrid)\n\
 tempFlag_s$ID$   = s$ID$.create(FlagGrid)\n\
@@ -216,6 +217,8 @@ def smoke_pre_step_high_$ID$():\n\
 const std::string smoke_post_step_low = "\n\
 def smoke_post_step_low_$ID$():\n\
     forces_s$ID$.clear()\n\
+    if using_guiding_s$ID$:\n\
+        weightGuide_s$ID$.clear()\n\
     if using_invel_s$ID$:\n\
         invel_s$ID$.clear()\n\
     \n\
@@ -301,8 +304,9 @@ def step_low_$ID$():\n\
     mantaMsg('Advecting velocity')\n\
     advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=vel_s$ID$, order=$ADVECT_ORDER$, openBounds=doOpen_s$ID$, boundaryWidth=boundaryWidth_s$ID$)\n\
     \n\
-    # Create interpolated version of original phi grid for later use in (optional) high-res step\n\
+    # Create interpolated version of original phi grids for later use in (optional) high-res step\n\
     if using_obstacle_s$ID$ and using_highres_s$ID$:\n\
+        interpolateGrid(target=phiOut_xl$ID$, source=phiOutIn_s$ID$)\n\
         interpolateGrid(target=phiObs_xl$ID$, source=phiObs_s$ID$)\n\
     if doOpen_s$ID$:\n\
         resetOutflow(flags=flags_s$ID$, real=density_s$ID$)\n\
@@ -347,7 +351,6 @@ def step_low_$ID$():\n\
     \n\
     if using_guiding_s$ID$:\n\
         mantaMsg('Guiding and pressure')\n\
-        weightGuide_s$ID$.multConst(0)\n\
         weightGuide_s$ID$.addConst(alpha_s$ID$)\n\
         PD_fluid_guiding(vel=vel_s$ID$, velT=guidevel_s$ID$, flags=flags_s$ID$, weight=weightGuide_s$ID$, blurRadius=beta_s$ID$, pressure=pressure_s$ID$, tau=tau_s$ID$, sigma=sigma_s$ID$, theta=theta_s$ID$, preconditioner=preconditioner_s$ID$, zeroPressureFixing=not doOpen_s$ID$)\n\
     else:\n\
@@ -368,8 +371,7 @@ def update_flame_low_$ID$():\n\
 const std::string smoke_step_high = "\n\
 def step_high_$ID$():\n\
     mantaMsg('Smoke step high')\n\
-    if using_obstacle_s$ID$: # TODO (sebbas): allow outflow objects when no obstacle set\n\
-        setObstacleFlags(flags=flags_xl$ID$, phiObs=phiObs_xl$ID$)\n\
+    setObstacleFlags(flags=flags_xl$ID$, phiObs=phiObs_xl$ID$, phiOut=phiOut_xl$ID$)\n\
     flags_xl$ID$.fillGrid()\n\
     \n\
     interpolateMACGrid(source=vel_s$ID$, target=vel_xl$ID$)\n\
@@ -459,6 +461,8 @@ const std::string smoke_import_high = "\n\
 def load_smoke_data_high_$ID$(path):\n\
     density_xl$ID$.load(path + '_density_xl.uni')\n\
     flags_xl$ID$.load(path + '_flags_xl.uni')\n\
+    phiOut_xl$ID$.load(path + '_phiOut_xl.uni')\n\
+    phiObs_xl$ID$.load(path + '_phiObs_xl.uni')\n\
     \n\
     texture_u_s$ID$.load(path + '_texture_u.uni')\n\
     texture_v_s$ID$.load(path + '_texture_v.uni')\n\
@@ -507,6 +511,8 @@ const std::string smoke_export_high = "\n\
 def save_smoke_data_high_$ID$(path):\n\
     density_xl$ID$.save(path + '_density_xl.uni')\n\
     flags_xl$ID$.save(path + '_flags_xl.uni')\n\
+    phiOut_xl$ID$.save(path + '_phiOut_xl.uni')\n\
+    phiObs_xl$ID$.save(path + '_phiObs_xl.uni')\n\
     \n\
     texture_u_s$ID$.save(path + '_texture_u.uni')\n\
     texture_v_s$ID$.save(path + '_texture_v.uni')\n\
@@ -578,6 +584,7 @@ mantaMsg('Deleting base grids high')\n\
 if 'flags_xl$ID$'      in globals() : del flags_xl$ID$\n\
 if 'vel_xl$ID$'        in globals() : del vel_xl$ID$\n\
 if 'density_xl$ID$'    in globals() : del density_xl$ID$\n\
+if 'phiOut_xl$ID$'     in globals() : del phiOut_xl$ID$\n\
 if 'phiObs_xl$ID$'     in globals() : del phiObs_xl$ID$\n\
 if 'energy_s$ID$'      in globals() : del energy_s$ID$\n\
 if 'tempFlag_s$ID$'    in globals() : del tempFlag_s$ID$\n\
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index e289b05df89..d104bb1c35c 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -816,6 +816,7 @@ static void obstacles_from_derivedmesh_task_cb(void *userdata, const int z)
 			BVHTreeNearest nearest = {0};
 			nearest.index = -1;
 			nearest.dist_sq = surface_distance * surface_distance; /* find_nearest uses squared distance */
+			bool hasIncObj = false;
 
 			/* find the nearest point on the mesh */
 			if (BLI_bvhtree_find_nearest(data->tree->tree, ray_start, &nearest, data->tree->nearest_callback, data->tree) != -1) {
@@ -841,12 +842,18 @@ static void obstacles_from_derivedmesh_task_cb(void *userdata, const int z)
 
 					/* increase object count */
 					data->num_objects[index]++;
+					hasIncObj = true;
 				}
 			}
 
 			/* Get distance to mesh surface from both within and outside grid (mantaflow phi grid) */
 			if (data->distances_map) {
 				update_mesh_distances(index, data->distances_map, data->tree, ray_start, data->surface_thickness);
+
+				/* Ensure that num objects are also counted inside object. But dont count twice (see object inc for nearest point) */
+				if (data->distances_map[index] < 0 && !hasIncObj) {
+					data->num_objects[index]++;
+				}
 			}
 		}
 	}
@@ -1721,12 +1728,12 @@ static void update_mesh_distances(int index, float *mesh_distances, BVHTreeFromM
 		if (dot_v3v3(ray_dirs[i], hit_tree.no) < 0) { inside = false; }
 	}
 
+	/* Levelset is negative inside mesh */
+	if (inside) min_dist *= (-1.0f);
+
 	/* Update mesh distance in map */
 	mesh_distances[index] = MIN2(mesh_distances[index], min_dist);
 
-	/* Levelset is negative inside mesh */
-	if (inside) mesh_distances[index] = fabsf(mesh_distances[index]) * (-1.0f);
-
 	/* Optional object thickening. Checks area around object. Thickness value determines size of search area. */
 	if (surface_thickness) {
 		BVHTreeNearest nearest = {0};



More information about the Bf-blender-cvs mailing list