[Bf-blender-cvs] [03c2439d96e] master: Fluid: Do not show fluid if frame is out of cache range

Sebastián Barschkis noreply at git.blender.org
Tue Aug 4 11:45:14 CEST 2020


Commit: 03c2439d96e8f366646bf20095514c057593aa24
Author: Sebastián Barschkis
Date:   Tue Aug 4 11:44:56 2020 +0200
Branches: master
https://developer.blender.org/rB03c2439d96e8f366646bf20095514c057593aa24

Fluid: Do not show fluid if frame is out of cache range

Before: If the current frame is out of the cache start/end range, the viewport will show the fluid as it was on the last frame that was still in the cache frame range.

Now: If the current frame is out of the cache start/end range, the viewport will show no fluid at all (even if there are cache files present for this frame).

This fix is related / in response to T79423.

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

M	intern/mantaflow/extern/manta_fluid_API.h
M	intern/mantaflow/intern/MANTA_main.cpp
M	intern/mantaflow/intern/MANTA_main.h
M	intern/mantaflow/intern/manta_fluid_API.cpp
M	source/blender/blenkernel/intern/fluid.c

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index dd5eab34ee0..124671467f7 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -77,7 +77,7 @@ int manta_get_frame(struct MANTA *fluid);
 float manta_get_timestep(struct MANTA *fluid);
 void manta_adapt_timestep(struct MANTA *fluid);
 bool manta_needs_realloc(struct MANTA *fluid, struct FluidModifierData *fmd);
-void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd);
+void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd, bool flush);
 
 /* Fluid accessors */
 size_t manta_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */);
diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 7de1aca6e87..586c413b044 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -1969,30 +1969,30 @@ void MANTA::adaptTimestep()
   runPythonString(pythonCommands);
 }
 
-void MANTA::updatePointers(FluidModifierData *fmd)
+void MANTA::updatePointers(FluidModifierData *fmd, bool flush)
 {
   if (with_debug)
     cout << "MANTA::updatePointers()" << endl;
 
   FluidDomainSettings *fds = fmd->domain;
 
-  bool liquid = (fds->type == FLUID_DOMAIN_TYPE_LIQUID);
-  bool smoke = (fds->type == FLUID_DOMAIN_TYPE_GAS);
-  bool noise = smoke && fds->flags & FLUID_DOMAIN_USE_NOISE;
-  bool heat = smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_HEAT;
-  bool colors = smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS;
-  bool fire = smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_FIRE;
-  bool obstacle = fds->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE;
-  bool guiding = fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE;
-  bool invel = fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL;
-  bool outflow = fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW;
-  bool drops = liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY;
-  bool bubble = liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE;
-  bool floater = liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM;
-  bool tracer = liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER;
-  bool parts = liquid && (drops | bubble | floater | tracer);
-  bool mesh = liquid && fds->flags & FLUID_DOMAIN_USE_MESH;
-  bool meshvel = liquid && mesh && fds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS;
+  bool liquid = !flush && (fds->type == FLUID_DOMAIN_TYPE_LIQUID);
+  bool smoke = !flush && (fds->type == FLUID_DOMAIN_TYPE_GAS);
+  bool noise = !flush && smoke && fds->flags & FLUID_DOMAIN_USE_NOISE;
+  bool heat = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_HEAT;
+  bool colors = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS;
+  bool fire = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_FIRE;
+  bool obstacle = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE;
+  bool guiding = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE;
+  bool invel = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL;
+  bool outflow = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW;
+  bool drops = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY;
+  bool bubble = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE;
+  bool floater = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM;
+  bool tracer = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER;
+  bool parts = !flush && liquid && (drops | bubble | floater | tracer);
+  bool mesh = !flush && liquid && fds->flags & FLUID_DOMAIN_USE_MESH;
+  bool meshvel = !flush && liquid && mesh && fds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS;
 
   string func = "getDataPointer";
   string funcNodes = "getNodesDataPointer";
@@ -2006,15 +2006,15 @@ void MANTA::updatePointers(FluidModifierData *fmd)
   string mesh_ext = "_mesh" + id;
   string sn_ext = "_sn" + id;
 
-  mFlags = getPointer<int>("flags" + s_ext, func);
-  mPhiIn = getPointer<float>("phiIn" + s_ext, func);
-  mPhiStaticIn = getPointer<float>("phiSIn" + s_ext, func);
-  mVelocityX = getPointer<float>("x_vel" + s_ext, func);
-  mVelocityY = getPointer<float>("y_vel" + s_ext, func);
-  mVelocityZ = getPointer<float>("z_vel" + s_ext, func);
-  mForceX = getPointer<float>("x_force" + s_ext, func);
-  mForceY = getPointer<float>("y_force" + s_ext, func);
-  mForceZ = getPointer<float>("z_force" + s_ext, func);
+  mFlags = (smoke || liquid) ? getPointer<int>("flags" + s_ext, func) : nullptr;
+  mPhiIn = (smoke || liquid) ? getPointer<float>("phiIn" + s_ext, func) : nullptr;
+  mPhiStaticIn = (smoke || liquid) ? getPointer<float>("phiSIn" + s_ext, func) : nullptr;
+  mVelocityX = (smoke || liquid) ? getPointer<float>("x_vel" + s_ext, func) : nullptr;
+  mVelocityY = (smoke || liquid) ? getPointer<float>("y_vel" + s_ext, func) : nullptr;
+  mVelocityZ = (smoke || liquid) ? getPointer<float>("z_vel" + s_ext, func) : nullptr;
+  mForceX = (smoke || liquid) ? getPointer<float>("x_force" + s_ext, func) : nullptr;
+  mForceY = (smoke || liquid) ? getPointer<float>("y_force" + s_ext, func) : nullptr;
+  mForceZ = (smoke || liquid) ? getPointer<float>("z_force" + s_ext, func) : nullptr;
 
   /* Outflow. */
   mPhiOutIn = (outflow) ? getPointer<float>("phiOutIn" + s_ext, func) : nullptr;
diff --git a/intern/mantaflow/intern/MANTA_main.h b/intern/mantaflow/intern/MANTA_main.h
index 2de484db59d..5fd94ca01bc 100644
--- a/intern/mantaflow/intern/MANTA_main.h
+++ b/intern/mantaflow/intern/MANTA_main.h
@@ -77,14 +77,14 @@ struct MANTA {
   bool initSndParts(FluidModifierData *fmd = nullptr);
   bool initLiquidSndParts(FluidModifierData *fmd = nullptr);
 
-  /* Pointer transfer: Mantaflow -> Blender. */
-  void updatePointers(FluidModifierData *fmd);
+  /* Pointer transfer: Mantaflow -> Blender. Use flush to reset all pointers to nullptr. */
+  void updatePointers(FluidModifierData *fmd, bool flush = false);
 
   /* Write cache. */
   bool writeConfiguration(FluidModifierData *fmd, int framenr);
   bool writeData(FluidModifierData *fmd, int framenr);
   bool writeNoise(FluidModifierData *fmd, int framenr);
-  // write calls for mesh and particles were left in bake calls for now
+  /* Write calls for mesh and particles were left in bake calls for now. */
 
   /* Read cache (via Python). */
   bool readConfiguration(FluidModifierData *fmd, int framenr);
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index f58ac186ff1..530dbd49b7c 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -230,11 +230,11 @@ bool manta_needs_realloc(MANTA *fluid, FluidModifierData *fmd)
   return fluid->needsRealloc(fmd);
 }
 
-void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd)
+void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd, bool flush)
 {
   if (!fluid || !fmd)
     return;
-  fluid->updatePointers(fmd);
+  fluid->updatePointers(fmd, flush);
 }
 
 /* Fluid accessors */
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index e807388ef1d..019230572ef 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -1119,7 +1119,7 @@ static void ensure_obstaclefields(FluidDomainSettings *fds)
   if (fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE) {
     manta_ensure_guiding(fds->fluid, fds->fmd);
   }
-  manta_update_pointers(fds->fluid, fds->fmd);
+  manta_update_pointers(fds->fluid, fds->fmd, false);
 }
 
 static void update_obstacleflags(FluidDomainSettings *fds,
@@ -2606,7 +2606,7 @@ static void ensure_flowsfields(FluidDomainSettings *fds)
        fds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER)) {
     manta_liquid_ensure_sndparts(fds->fluid, fds->fmd);
   }
-  manta_update_pointers(fds->fluid, fds->fmd);
+  manta_update_pointers(fds->fluid, fds->fmd, false);
 }
 
 static void update_flowsflags(FluidDomainSettings *fds, Object **flowobjs, int numflowobj)
@@ -3738,29 +3738,35 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
   int mode = fds->cache_type;
 
   /* Do not process modifier if current frame is out of cache range. */
+  bool escape = false;
   switch (mode) {
     case FLUID_DOMAIN_CACHE_ALL:
     case FLUID_DOMAIN_CACHE_MODULAR:
       if (fds->cache_frame_offset > 0) {
         if (scene_framenr < fds->cache_frame_start ||
             scene_framenr > fds->cache_frame_end + fds->cache_frame_offset) {
-          return;
+          escape = true;
         }
       }
       else {
         if (scene_framenr < fds->cache_frame_start + fds->cache_frame_offset ||
             scene_framenr > fds->cache_frame_end) {
-          return;
+          escape = true;
         }
       }
       break;
     case FLUID_DOMAIN_CACHE_REPLAY:
     default:
       if (scene_framenr < fds->cache_frame_start || scene_framenr > fds->cache_frame_end) {
-        return;
+        escape = true;
       }
       break;
   }
+  /* If modifier will not be processed, update/flush pointers from (old) fluid object once more. */
+  if (escape && fds->fluid) {
+    manta_update_pointers(fds->fluid, fmd, true);
+    return;
+  }
 
   /* Reset fluid if no fluid present. Also resets active fields. */
   if (!fds->fluid) {
@@ -4096,7 +4102,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
   }
 
   /* Ensure that fluid pointers are always up to date at the end of modifier processing. */
-  manta_update_pointers(fds->fluid, fmd);
+  manta_update_pointers(fds->fluid, fmd, false);
 
   fds->flags &= ~FLUID_DOMAIN_FILE_LOAD;
   fmd->time = scene_framenr;



More information about the Bf-blender-cvs mailing list