diff options
-rw-r--r-- | intern/mantaflow/intern/strings/liquid_script.h | 9 | ||||
-rw-r--r-- | intern/mantaflow/intern/strings/smoke_script.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fluid.c | 43 |
3 files changed, 15 insertions, 45 deletions
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h index bb42b781c19..442b09b5a8a 100644 --- a/intern/mantaflow/intern/strings/liquid_script.h +++ b/intern/mantaflow/intern/strings/liquid_script.h @@ -139,7 +139,7 @@ waveCrest_sp$ID$ = sp$ID$.create(RealGrid)\n\ kineticEnergy_sp$ID$ = sp$ID$.create(RealGrid)\n\ \n\ # Keep track of important objects in dict to load them later on\n\ -liquid_particles_dict_final_s$ID$ = dict(ppSnd=ppSnd_sp$ID$, pVelSnd=pVelSnd_pp$ID$, pLifeSnd=pLifeSnd_pp$ID$)\n\ +liquid_particles_dict_final_s$ID$ = dict(ppSnd=ppSnd_sp$ID$, pVelSnd=pVelSnd_pp$ID$, pLifeSnd=pLifeSnd_pp$ID$)\n\ liquid_particles_dict_resume_s$ID$ = dict(trappedAir=trappedAir_sp$ID$, waveCrest=waveCrest_sp$ID$, kineticEnergy=kineticEnergy_sp$ID$)\n"; const std::string liquid_init_phi = @@ -166,15 +166,18 @@ def liquid_adaptive_step_$ID$(framenr):\n\ mantaMsg('Initializing obstacle levelset')\n\ phiObsIn_s$ID$.fillHoles(maxDepth=int(res_s$ID$), boundaryWidth=2)\n\ extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\ - extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=int(res_s$ID$/2), inside=False)\n\ + extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=3, inside=False)\n\ phiObs_s$ID$.join(phiObsIn_s$ID$)\n\ \n\ # Using boundaryWidth=2 to not search beginning from walls (just a performance optimization)\n\ # Additional sanity check: fill holes in phiObs which can result after joining with phiObsIn\n\ phiObs_s$ID$.fillHoles(maxDepth=int(res_s$ID$), boundaryWidth=2)\n\ extrapolateLsSimple(phi=phiObs_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\ - extrapolateLsSimple(phi=phiObs_s$ID$, distance=int(res_s$ID$/2), inside=False)\n\ + extrapolateLsSimple(phi=phiObs_s$ID$, distance=3, inside=False)\n\ \n\ + mantaMsg('Initializing fluid levelset')\n\ + extrapolateLsSimple(phi=phiIn_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\ + extrapolateLsSimple(phi=phiIn_s$ID$, distance=int(res_s$ID$/2), inside=False)\n\ phi_s$ID$.join(phiIn_s$ID$)\n\ \n\ if using_obstacle_s$ID$:\n\ diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h index ad966503fd1..b4f7a39adeb 100644 --- a/intern/mantaflow/intern/strings/smoke_script.h +++ b/intern/mantaflow/intern/strings/smoke_script.h @@ -279,14 +279,18 @@ def smoke_adaptive_step_$ID$(framenr):\n\ mantaMsg('Initializing obstacle levelset')\n\ phiObsIn_s$ID$.fillHoles(maxDepth=int(res_s$ID$), boundaryWidth=2)\n\ extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\ - extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=int(res_s$ID$/2), inside=False)\n\ + extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=3, inside=False)\n\ phiObs_s$ID$.join(phiObsIn_s$ID$)\n\ \n\ # Using boundaryWidth=2 to not search beginning from walls (just a performance optimization)\n\ # Additional sanity check: fill holes in phiObs which can result after joining with phiObsIn\n\ phiObs_s$ID$.fillHoles(maxDepth=int(res_s$ID$), boundaryWidth=2)\n\ extrapolateLsSimple(phi=phiObs_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\ - extrapolateLsSimple(phi=phiObs_s$ID$, distance=int(res_s$ID$/2), inside=False)\n\ + extrapolateLsSimple(phi=phiObs_s$ID$, distance=3, inside=False)\n\ + \n\ + mantaMsg('Initializing fluid levelset')\n\ + extrapolateLsSimple(phi=phiIn_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\ + extrapolateLsSimple(phi=phiIn_s$ID$, distance=3, inside=False)\n\ \n\ if using_outflow_s$ID$:\n\ phiOut_s$ID$.join(phiOutIn_s$ID$)\n\ diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index b8d7429fa94..f19137bf796 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -1452,7 +1452,7 @@ static void update_mesh_distances(int index, return; } - /* b) Volumetric initialization: 1) Ray-casts around mesh object. */ + /* b) Volumetric initialization: Ray-casts around mesh object. */ /* Ray-casts in 26 directions. * (6 main axis + 12 quadrant diagonals (2D) + 8 octant diagonals (3D)). */ @@ -1508,45 +1508,8 @@ static void update_mesh_distances(int index, min_dist = (-1.0f) * fabsf(min_dist); } - /* Update global distance array with distance value. */ - mesh_distances[index] = min_dist; - - /* b) Volumetric initialization: 2) Use nearest neighbor search on mesh surface. */ - - /* Distance between two opposing vertices in a unit cube. - * I.e. the unit cube diagonal or sqrt(3). - * This value is our nearest neighbour search distance. */ - const float surface_distance = 1.732; - BVHTreeNearest nearest = {0}; - nearest.index = -1; - nearest.dist_sq = surface_distance * surface_distance; /* find_nearest uses squared distance. */ - - if (BLI_bvhtree_find_nearest( - tree_data->tree, ray_start, &nearest, tree_data->nearest_callback, tree_data) != -1) { - float ray[3] = {0}; - sub_v3_v3v3(ray, nearest.co, ray_start); - min_dist = len_v3(ray); - - BVHTreeRayHit hit_tree = {0}; - hit_tree.index = -1; - hit_tree.dist = PHI_MAX; - - normalize_v3(ray); - BLI_bvhtree_ray_cast( - tree_data->tree, ray_start, ray, 0.0f, &hit_tree, tree_data->raycast_callback, tree_data); - - /* Only proceed if casted ray hit the mesh surface. */ - if (hit_tree.index != -1) { - - /* Ray and normal are pointing in the same direction: Point must lie inside mesh. */ - if (dot_v3v3(ray, hit_tree.no) > 0) { - min_dist = (-1.0f) * fabsf(min_dist); - } - - /* Update distance map with more accurate distance from this nearest neighbor search. */ - mesh_distances[index] = min_dist; - } - } + /* Update global distance array but ensure that older entries are not overridden. */ + mesh_distances[index] = MIN2(mesh_distances[index], min_dist); /* Subtract optional surface thickness value and virtually increase the object size. */ if (surface_thickness) { |