[Bf-blender-cvs] [650f9cfe938] blender-v2.83-release: Fluid: Improved cache 'Replay' option

Sebastián Barschkis noreply at git.blender.org
Wed Apr 22 16:21:10 CEST 2020


Commit: 650f9cfe938f5e65e45a90223ce03c6b232a6217
Author: Sebastián Barschkis
Date:   Wed Apr 15 14:16:13 2020 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rB650f9cfe938f5e65e45a90223ce03c6b232a6217

Fluid: Improved cache 'Replay' option

When using the 'Replay' cache mode the cache needs to be invalidated whenever simulation variables have been changed.
The invalidation will always only affect the according subcaches, e.g. when changing a mesh paramter only the mesh cache will be invalidated, the base cache will remain intact.
Before this change Blender always invalidated the entire cache.

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

M	source/blender/blenkernel/BKE_fluid.h
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/makesdna/DNA_fluid_types.h
M	source/blender/makesrna/intern/rna_fluid.c

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

diff --git a/source/blender/blenkernel/BKE_fluid.h b/source/blender/blenkernel/BKE_fluid.h
index e8b4c819c62..e06a1a9fb92 100644
--- a/source/blender/blenkernel/BKE_fluid.h
+++ b/source/blender/blenkernel/BKE_fluid.h
@@ -61,6 +61,7 @@ void BKE_fluid_reallocate_copy_fluid(struct FluidDomainSettings *mds,
                                      int o_max[3],
                                      int o_shift[3],
                                      int n_shift[3]);
+void BKE_fluid_cache_free_all(struct FluidDomainSettings *mds, struct Object *ob);
 void BKE_fluid_cache_free(struct FluidDomainSettings *mds, struct Object *ob, int cache_map);
 void BKE_fluid_cache_new_name_for_current_session(int maxlen, char *r_name);
 
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 8697cd03827..578a6a13bb7 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -334,6 +334,14 @@ void BKE_fluid_reallocate_copy_fluid(FluidDomainSettings *mds,
   manta_free(fluid_old);
 }
 
+void BKE_fluid_cache_free_all(FluidDomainSettings *mds, Object *ob)
+{
+  int cache_map = (FLUID_DOMAIN_OUTDATED_DATA | FLUID_DOMAIN_OUTDATED_NOISE |
+                   FLUID_DOMAIN_OUTDATED_MESH | FLUID_DOMAIN_OUTDATED_PARTICLES |
+                   FLUID_DOMAIN_OUTDATED_GUIDE);
+  BKE_fluid_cache_free(mds, ob, cache_map);
+}
+
 void BKE_fluid_cache_free(FluidDomainSettings *mds, Object *ob, int cache_map)
 {
   char temp_dir[FILE_MAX];
@@ -1130,7 +1138,18 @@ static void obstacles_from_mesh(Object *coll_ob,
   }
 }
 
+static void ensure_obstaclefields(FluidDomainSettings *mds)
+{
+  if (mds->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE) {
+    manta_ensure_obstacle(mds->fluid, mds->mmd);
+  }
+  if (mds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE) {
+    manta_ensure_guiding(mds->fluid, mds->mmd);
+  }
+}
+
 static void update_obstacleflags(FluidDomainSettings *mds,
+                                 Object *domain,
                                  Object **coll_ob_array,
                                  int coll_ob_array_len)
 {
@@ -1157,6 +1176,11 @@ static void update_obstacleflags(FluidDomainSettings *mds,
       if (!mes) {
         break;
       }
+      if (mes->flags & FLUID_EFFECTOR_NEEDS_UPDATE) {
+        mes->flags &= ~FLUID_EFFECTOR_NEEDS_UPDATE;
+        BKE_fluid_cache_free_all(mds, domain);
+        mds->cache_flag |= FLUID_DOMAIN_OUTDATED_DATA;
+      }
       if (mes->type == FLUID_EFFECTOR_TYPE_COLLISION) {
         active_fields |= FLUID_DOMAIN_ACTIVE_OBSTACLE;
       }
@@ -1165,13 +1189,6 @@ static void update_obstacleflags(FluidDomainSettings *mds,
       }
     }
   }
-  /* Finally, initialize new data fields if any */
-  if (active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE) {
-    manta_ensure_obstacle(mds->fluid, mds->mmd);
-  }
-  if (active_fields & FLUID_DOMAIN_ACTIVE_GUIDE) {
-    manta_ensure_guiding(mds->fluid, mds->mmd);
-  }
   mds->active_fields = active_fields;
 }
 
@@ -1193,7 +1210,8 @@ static void update_obstacles(Depsgraph *depsgraph,
       depsgraph, ob, mds->effector_group, &numeffecobjs, eModifierType_Fluid);
 
   /* Update all effector related flags and ensure that corresponding grids get initialized. */
-  update_obstacleflags(mds, effecobjs, numeffecobjs);
+  update_obstacleflags(mds, ob, effecobjs, numeffecobjs);
+  ensure_obstaclefields(mds);
 
   /* Initialize effector maps for each flow. */
   bb_maps = MEM_callocN(sizeof(struct FluidObjectBB) * numeffecobjs, "fluid_effector_bb_maps");
@@ -2573,21 +2591,49 @@ BLI_INLINE void apply_inflow_fields(FluidFlowSettings *mfs,
   }
 }
 
-static void update_flowsflags(FluidDomainSettings *mds, Object **flowobjs, int numflowobj)
+static void ensure_flowsfields(FluidDomainSettings *mds)
+{
+  if (mds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL) {
+    manta_ensure_invelocity(mds->fluid, mds->mmd);
+  }
+  if (mds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW) {
+    manta_ensure_outflow(mds->fluid, mds->mmd);
+  }
+  if (mds->active_fields & FLUID_DOMAIN_ACTIVE_HEAT) {
+    manta_smoke_ensure_heat(mds->fluid, mds->mmd);
+  }
+  if (mds->active_fields & FLUID_DOMAIN_ACTIVE_FIRE) {
+    manta_smoke_ensure_fire(mds->fluid, mds->mmd);
+  }
+  if (mds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS) {
+    /* initialize all smoke with "active_color" */
+    manta_smoke_ensure_colors(mds->fluid, mds->mmd);
+  }
+  if (mds->type == FLUID_DOMAIN_TYPE_LIQUID &&
+      (mds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY ||
+       mds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM ||
+       mds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER)) {
+    manta_liquid_ensure_sndparts(mds->fluid, mds->mmd);
+  }
+}
+
+static void update_flowsflags(FluidDomainSettings *mds,
+                              Object *domain,
+                              Object **flowobjs,
+                              int numflowobj)
 {
   int active_fields = mds->active_fields;
   uint flow_index;
 
   /* First, remove all flags that we want to update. */
   int prev_flags = (FLUID_DOMAIN_ACTIVE_INVEL | FLUID_DOMAIN_ACTIVE_OUTFLOW |
-                    FLUID_DOMAIN_ACTIVE_HEAT | FLUID_DOMAIN_ACTIVE_FIRE |
-                    FLUID_DOMAIN_ACTIVE_COLOR_SET | FLUID_DOMAIN_ACTIVE_COLORS);
+                    FLUID_DOMAIN_ACTIVE_HEAT | FLUID_DOMAIN_ACTIVE_FIRE);
   active_fields &= ~prev_flags;
 
   /* Monitor active fields based on flow settings */
   for (flow_index = 0; flow_index < numflowobj; flow_index++) {
-    Object *coll_ob = flowobjs[flow_index];
-    FluidModifierData *mmd2 = (FluidModifierData *)modifiers_findByType(coll_ob,
+    Object *flow_ob = flowobjs[flow_index];
+    FluidModifierData *mmd2 = (FluidModifierData *)modifiers_findByType(flow_ob,
                                                                         eModifierType_Fluid);
 
     /* Sanity check. */
@@ -2600,6 +2646,11 @@ static void update_flowsflags(FluidDomainSettings *mds, Object **flowobjs, int n
       if (!mfs) {
         break;
       }
+      if (mfs->flags & FLUID_FLOW_NEEDS_UPDATE) {
+        mfs->flags &= ~FLUID_FLOW_NEEDS_UPDATE;
+        BKE_fluid_cache_free_all(mds, domain);
+        mds->cache_flag |= FLUID_DOMAIN_OUTDATED_DATA;
+      }
       if (mfs->flags & FLUID_FLOW_INITVELOCITY) {
         active_fields |= FLUID_DOMAIN_ACTIVE_INVEL;
       }
@@ -2648,29 +2699,6 @@ static void update_flowsflags(FluidDomainSettings *mds, Object **flowobjs, int n
       active_fields |= FLUID_DOMAIN_ACTIVE_COLORS;
     }
   }
-  /* Finally, initialize new data fields if any */
-  if (active_fields & FLUID_DOMAIN_ACTIVE_INVEL) {
-    manta_ensure_invelocity(mds->fluid, mds->mmd);
-  }
-  if (active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW) {
-    manta_ensure_outflow(mds->fluid, mds->mmd);
-  }
-  if (active_fields & FLUID_DOMAIN_ACTIVE_HEAT) {
-    manta_smoke_ensure_heat(mds->fluid, mds->mmd);
-  }
-  if (active_fields & FLUID_DOMAIN_ACTIVE_FIRE) {
-    manta_smoke_ensure_fire(mds->fluid, mds->mmd);
-  }
-  if (active_fields & FLUID_DOMAIN_ACTIVE_COLORS) {
-    /* initialize all smoke with "active_color" */
-    manta_smoke_ensure_colors(mds->fluid, mds->mmd);
-  }
-  if (mds->type == FLUID_DOMAIN_TYPE_LIQUID &&
-      (mds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY ||
-       mds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM ||
-       mds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER)) {
-    manta_liquid_ensure_sndparts(mds->fluid, mds->mmd);
-  }
   mds->active_fields = active_fields;
 }
 
@@ -2692,7 +2720,8 @@ static void update_flowsfluids(struct Depsgraph *depsgraph,
       depsgraph, ob, mds->fluid_group, &numflowobj, eModifierType_Fluid);
 
   /* Update all flow related flags and ensure that corresponding grids get initialized. */
-  update_flowsflags(mds, flowobjs, numflowobj);
+  update_flowsflags(mds, ob, flowobjs, numflowobj);
+  ensure_flowsfields(mds);
 
   /* Initialize emission maps for each flow. */
   bb_maps = MEM_callocN(sizeof(struct FluidObjectBB) * numflowobj, "fluid_flow_bb_maps");
@@ -3566,6 +3595,7 @@ static int manta_step(
       break;
     }
 
+    /* Only bake if the domain is bigger than one cell (important for adaptive domain). */
     if (mds->total_cells > 1) {
       update_effectors(depsgraph, scene, ob, mds, dt);
       manta_bake_data(mds->fluid, mmd, frame);
@@ -3585,7 +3615,7 @@ static int manta_step(
     }
   }
 
-  if (mds->type == FLUID_DOMAIN_TYPE_GAS) {
+  if (mds->type == FLUID_DOMAIN_TYPE_GAS && result) {
     manta_smoke_calc_transparency(mds, DEG_get_evaluated_view_layer(depsgraph));
   }
   BLI_mutex_unlock(&object_update_lock);
@@ -3684,8 +3714,35 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
     return;
   }
 
+  bool bake_outdated = mds->cache_flag &
+                       (FLUID_DOMAIN_OUTDATED_DATA | FLUID_DOMAIN_OUTDATED_NOISE |
+                        FLUID_DOMAIN_OUTDATED_MESH | FLUID_DOMAIN_OUTDATED_PARTICLES |
+                        FLUID_DOMAIN_OUTDATED_GUIDE);
+
+  /* Exit early if cache is outdated. */
+  if (bake_outdated) {
+    return;
+  }
+
+  /* Ensure cache directory is not relative. */
+  const char *relbase = modifier_path_relbase_from_global(ob);
+  BLI_path_abs(mds->cache_directory, relbase);
+
+  objs = BKE_collision_objects_create(
+      depsgraph, ob, mds->fluid_group, &numobj, eModifierType_Fluid);
+  update_flowsflags(mds, ob, objs, numobj);
+  if (objs) {
+    MEM_freeN(objs);
+  }
+  objs = BKE_collision_objects_create(
+      depsgraph, ob, mds->effector_group, &numobj, eModifierType_Fluid);
+  update_obstacleflags(mds, ob, objs, numobj);
+  if (objs) {
+    MEM_freeN(objs);
+  }
+
   /* Reset fluid if no fluid present. */
-  if (!mds->fluid) {
+  if (!mds->fluid || mds->cache_flag & FLUID_DOMAIN_OUTDATED_DATA) {
     BKE_fluid_modifier_reset_ex(mmd, false);
 
     /* Fluid domain init must not fail in order to continue modifier evaluation. */
@@ -3712,23 +3769,10 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
   /* Get distance between cache start and current frame for total time. */
   mds->time_total = abs(scene_framenr - mds->cache_frame_start) * mds->frame_length;
 
-  objs = BKE_collision_objects_create(
-      depsgraph, ob, mds->

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list