[Bf-blender-cvs] [70b061b4fdd] master: Fluid: Refactored caching in main Mantaflow class

Sebastián Barschkis noreply at git.blender.org
Fri Apr 3 17:49:15 CEST 2020


Commit: 70b061b4fdd487c971b12fd0f772767387ebc8f4
Author: Sebastián Barschkis
Date:   Fri Apr 3 16:38:38 2020 +0200
Branches: master
https://developer.blender.org/rB70b061b4fdd487c971b12fd0f772767387ebc8f4

Fluid: Refactored caching in main Mantaflow class

This refactor cleans up code for the Manta file IO. It also improves the cache 'Replay' option.

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

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
M	source/blender/makesdna/DNA_fluid_types.h

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 48d42504994..939f24fbeef 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -62,6 +62,15 @@ int manta_bake_noise(struct MANTA *fluid, struct FluidModifierData *mmd, int fra
 int manta_bake_mesh(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
 int manta_bake_particles(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
 int manta_bake_guiding(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_has_data(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_has_noise(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_has_mesh(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_has_particles(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_has_guiding(struct MANTA *fluid,
+                      struct FluidModifierData *mmd,
+                      int framenr,
+                      bool domain);
+
 void manta_update_variables(struct MANTA *fluid, struct FluidModifierData *mmd);
 int manta_get_frame(struct MANTA *fluid);
 float manta_get_timestep(struct MANTA *fluid);
diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 3555e098caf..54b728b734e 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -595,19 +595,19 @@ static std::string getCacheFileEnding(char cache_format)
 
   switch (cache_format) {
     case FLUID_DOMAIN_FILE_UNI:
-      return ".uni";
+      return FLUID_DOMAIN_EXTENSION_UNI;
     case FLUID_DOMAIN_FILE_OPENVDB:
-      return ".vdb";
+      return FLUID_DOMAIN_EXTENSION_OPENVDB;
     case FLUID_DOMAIN_FILE_RAW:
-      return ".raw";
+      return FLUID_DOMAIN_EXTENSION_RAW;
     case FLUID_DOMAIN_FILE_BIN_OBJECT:
-      return ".bobj.gz";
+      return FLUID_DOMAIN_EXTENSION_BINOBJ;
     case FLUID_DOMAIN_FILE_OBJECT:
-      return ".obj";
+      return FLUID_DOMAIN_EXTENSION_OBJ;
     default:
       std::cerr << "Fluid Error -- Could not find file extension. Using default file extension."
                 << std::endl;
-      return ".uni";
+      return FLUID_DOMAIN_EXTENSION_UNI;
   }
 }
 
@@ -1054,38 +1054,27 @@ bool MANTA::updateFlipStructures(FluidModifierData *mmd, int framenr)
   int result = 0;
   int expected = 0; /* Expected number of read successes for this frame. */
 
-  // Ensure empty data structures at start
-  if (mFlipParticleData)
-    mFlipParticleData->clear();
-  if (mFlipParticleVelocity)
-    mFlipParticleVelocity->clear();
+  /* Ensure empty data structures at start. */
+  if (!mFlipParticleData || !mFlipParticleVelocity)
+    return false;
 
-  std::ostringstream ss;
-  char cacheDir[FILE_MAX], targetFile[FILE_MAX];
-  cacheDir[0] = '\0';
-  targetFile[0] = '\0';
+  mFlipParticleData->clear();
+  mFlipParticleVelocity->clear();
 
   std::string pformat = getCacheFileEnding(mmd->domain->cache_particle_format);
-  BLI_path_join(
-      cacheDir, sizeof(cacheDir), mmd->domain->cache_directory, FLUID_DOMAIN_DIR_DATA, nullptr);
+  std::string file = getFile(
+      mmd, FLUID_DOMAIN_DIR_DATA, FLUID_DOMAIN_FILE_PP, pformat.c_str(), framenr);
 
   expected += 1;
-  ss.str("");
-  ss << "pp_####" << pformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetFile, framenr, 0);
-  if (BLI_exists(targetFile)) {
-    result += updateParticlesFromFile(targetFile, false, false);
+  if (BLI_exists(file.c_str())) {
+    result += updateParticlesFromFile(file, false, false);
     assert(result == expected);
   }
 
+  file = getFile(mmd, FLUID_DOMAIN_DIR_DATA, FLUID_DOMAIN_FILE_PVEL, pformat.c_str(), framenr);
   expected += 1;
-  ss.str("");
-  ss << "pVel_####" << pformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetFile, framenr, 0);
-  if (BLI_exists(targetFile)) {
-    result += updateParticlesFromFile(targetFile, false, true);
+  if (BLI_exists(file.c_str())) {
+    result += updateParticlesFromFile(file, false, true);
     assert(result == expected);
   }
 
@@ -1108,42 +1097,29 @@ bool MANTA::updateMeshStructures(FluidModifierData *mmd, int framenr)
   int result = 0;
   int expected = 0; /* Expected number of read successes for this frame. */
 
-  // Ensure empty data structures at start
-  if (mMeshNodes)
-    mMeshNodes->clear();
-  if (mMeshTriangles)
-    mMeshTriangles->clear();
-  if (mMeshVelocities)
-    mMeshVelocities->clear();
+  /* Ensure empty data structures at start. */
+  if (!mMeshNodes || !mMeshTriangles || !mMeshVelocities)
+    return false;
 
-  std::ostringstream ss;
-  char cacheDir[FILE_MAX], targetFile[FILE_MAX];
-  cacheDir[0] = '\0';
-  targetFile[0] = '\0';
+  mMeshNodes->clear();
+  mMeshTriangles->clear();
+  mMeshVelocities->clear();
 
   std::string mformat = getCacheFileEnding(mmd->domain->cache_mesh_format);
   std::string dformat = getCacheFileEnding(mmd->domain->cache_data_format);
-  BLI_path_join(
-      cacheDir, sizeof(cacheDir), mmd->domain->cache_directory, FLUID_DOMAIN_DIR_MESH, nullptr);
+  std::string file = getFile(mmd, FLUID_DOMAIN_DIR_MESH, FLUID_DOMAIN_FILE_MESH, mformat, framenr);
 
   expected += 1;
-  ss.str("");
-  ss << "lMesh_####" << mformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetFile, framenr, 0);
-  if (BLI_exists(targetFile)) {
-    result += updateMeshFromFile(targetFile);
+  if (BLI_exists(file.c_str())) {
+    result += updateMeshFromFile(file);
     assert(result == expected);
   }
 
   if (mUsingMVel) {
+    file = getFile(mmd, FLUID_DOMAIN_DIR_MESH, FLUID_DOMAIN_FILE_MESHVEL, dformat, framenr);
     expected += 1;
-    ss.str("");
-    ss << "lVelMesh_####" << dformat;
-    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-    BLI_path_frame(targetFile, framenr, 0);
-    if (BLI_exists(targetFile)) {
-      result += updateMeshFromFile(targetFile);
+    if (BLI_exists(file.c_str())) {
+      result += updateMeshFromFile(file);
       assert(result == expected);
     }
   }
@@ -1167,53 +1143,35 @@ bool MANTA::updateParticleStructures(FluidModifierData *mmd, int framenr)
   int result = 0;
   int expected = 0; /* Expected number of read successes for this frame. */
 
-  // Ensure empty data structures at start
-  if (mSndParticleData)
-    mSndParticleData->clear();
-  if (mSndParticleVelocity)
-    mSndParticleVelocity->clear();
-  if (mSndParticleLife)
-    mSndParticleLife->clear();
+  /* Ensure empty data structures at start. */
+  if (!mSndParticleData || !mSndParticleVelocity || !mSndParticleLife)
+    return false;
 
-  std::ostringstream ss;
-  char cacheDir[FILE_MAX], targetFile[FILE_MAX];
-  cacheDir[0] = '\0';
-  targetFile[0] = '\0';
+  mSndParticleData->clear();
+  mSndParticleVelocity->clear();
+  mSndParticleLife->clear();
 
   std::string pformat = getCacheFileEnding(mmd->domain->cache_particle_format);
-  BLI_path_join(cacheDir,
-                sizeof(cacheDir),
-                mmd->domain->cache_directory,
-                FLUID_DOMAIN_DIR_PARTICLES,
-                nullptr);
+  std::string file = getFile(
+      mmd, FLUID_DOMAIN_DIR_PARTICLES, FLUID_DOMAIN_FILE_PPSND, pformat, framenr);
 
   expected += 1;
-  ss.str("");
-  ss << "ppSnd_####" << pformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetFile, framenr, 0);
-  if (BLI_exists(targetFile)) {
-    result += updateParticlesFromFile(targetFile, true, false);
+  if (BLI_exists(file.c_str())) {
+    result += updateParticlesFromFile(file, true, false);
     assert(result == expected);
   }
 
+  file = getFile(mmd, FLUID_DOMAIN_DIR_PARTICLES, FLUID_DOMAIN_FILE_PVELSND, pformat, framenr);
   expected += 1;
-  ss.str("");
-  ss << "pVelSnd_####" << pformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetFile, framenr, 0);
-  if (BLI_exists(targetFile)) {
-    result += updateParticlesFromFile(targetFile, true, true);
+  if (BLI_exists(file.c_str())) {
+    result += updateParticlesFromFile(file, true, true);
     assert(result == expected);
   }
 
+  file = getFile(mmd, FLUID_DOMAIN_DIR_PARTICLES, FLUID_DOMAIN_FILE_PLIFESND, pformat, framenr);
   expected += 1;
-  ss.str("");
-  ss << "pLifeSnd_####" << pformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetFile, framenr, 0);
-  if (BLI_exists(targetFile)) {
-    result += updateParticlesFromFile(targetFile, true, false);
+  if (BLI_exists(file.c_str())) {
+    result += updateParticlesFromFile(file, true, false);
     assert(result == expected);
   }
 
@@ -1236,103 +1194,70 @@ bool MANTA::updateSmokeStructures(FluidModifierData *mmd, int framenr)
   int result = 0;
   int expected = 0; /* Expected number of read successes for this frame. */
 
-  std::ostringstream ss;
-  char cacheDir[FILE_MAX], targetFile[FILE_MAX];
-  cacheDir[0] = '\0';
-  targetFile[0] = '\0';
-
   std::string dformat = getCacheFileEnding(mmd->domain->cache_data_format);
-  BLI_path_join(
-      cacheDir, sizeof(cacheDir), mmd->domain->cache_directory, FLUID_DOMAIN_DIR_DATA, nullptr);
+  std::string file = getFile(
+      mmd, FLUID_DOMAIN_DIR_DATA, FLUID_DOMAIN_FILE_DENSITY, dformat, framenr);
 
   expected += 1;
-  ss.str("");
-  ss << "density_####" << dformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetFile, framenr, 0);
-  if (BLI_exists(targetFile)) {
-    result += updateGridFromFile(targetFile, mDensity, false);
+  if (BLI_exists(file.c_str())) {
+    result += updateGridFromFile(file, mDensity, false);
     assert(result == expected);
   }
 
+  file = getFile(mmd, FLUID_DOMAIN_DIR_DATA, FLUID_DOMAIN_FILE_SHADOW, dformat, framenr);
   expected += 1;
-  ss.str("");
-  ss << "shadow_####" << dformat;
-  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
-  BLI_path_frame(targetF

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list