[Bf-blender-cvs] [e7d71ce9cf1] blender-v2.82-release: Fluid: Fixed slow cache loading for smoke data

Sebastián Barschkis noreply at git.blender.org
Thu Feb 6 16:54:18 CET 2020


Commit: e7d71ce9cf1eb8ea73d5d77527fc65e7bd6f5d4d
Author: Sebastián Barschkis
Date:   Thu Feb 6 16:53:00 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBe7d71ce9cf1eb8ea73d5d77527fc65e7bd6f5d4d

Fluid: Fixed slow cache loading for smoke data

Cache files are currently loaded via the Manta Python API. With very big caches this can slow down the viewport playback. Especially smoke simulations, which just load grids and no meshes, can suffer from this. This fix solves this problem by directly loading the cache files from disk (no Python). This fix has been in the works for some time. The developer of this patch is ready to handle any potential fall-out of this patch quickly.

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

M	intern/mantaflow/CMakeLists.txt
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/CMakeLists.txt b/intern/mantaflow/CMakeLists.txt
index c7b3c56c3c2..a3d891907a9 100644
--- a/intern/mantaflow/CMakeLists.txt
+++ b/intern/mantaflow/CMakeLists.txt
@@ -47,6 +47,35 @@ set(INC_SYS
   ${ZLIB_INCLUDE_DIRS}
 )
 
+if(WITH_TBB)
+  list(APPEND INC_SYS
+    ${TBB_INCLUDE_DIRS}
+  )
+  list(APPEND LIB
+    ${TBB_LIBRARIES}
+  )
+endif()
+
+if(WITH_OPENVDB)
+  list(APPEND INC_SYS
+    ${BOOST_INCLUDE_DIR}
+    ${OPENEXR_INCLUDE_DIRS}
+    ${OPENVDB_INCLUDE_DIRS}
+  )
+  list(APPEND LIB
+    ${OPENVDB_LIBRARIES}
+    ${OPENEXR_LIBRARIES}
+    ${ZLIB_LIBRARIES}
+    ${BOOST_LIBRARIES}
+  )
+  if(WITH_OPENVDB_BLOSC)
+    list(APPEND LIB
+      ${BLOSC_LIBRARIES}
+      ${ZLIB_LIBRARIES}
+    )
+  endif()
+endif()
+
 set(SRC
   intern/manta_python_API.cpp
   intern/manta_fluid_API.cpp
diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 8dc2cf1805a..4ebedeb5e38 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -55,6 +55,8 @@ int manta_update_mesh_structures(struct MANTA *fluid, struct FluidModifierData *
 int manta_update_particle_structures(struct MANTA *fluid,
                                      struct FluidModifierData *mmd,
                                      int framenr);
+int manta_update_smoke_structures(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_update_noise_structures(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
 int manta_bake_data(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
 int manta_bake_noise(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
 int manta_bake_mesh(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 7f6ff9094c6..11b8fb820d6 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -27,6 +27,10 @@
 #include <iomanip>
 #include <zlib.h>
 
+#if OPENVDB == 1
+#  include "openvdb/openvdb.h"
+#endif
+
 #include "MANTA_main.h"
 #include "manta.h"
 #include "Python.h"
@@ -1168,6 +1172,244 @@ int MANTA::updateParticleStructures(FluidModifierData *mmd, int framenr)
   return 1;
 }
 
+int MANTA::updateSmokeStructures(FluidModifierData *mmd, int framenr)
+{
+  if (MANTA::with_debug)
+    std::cout << "MANTA::updateGridStructures()" << std::endl;
+
+  mSmokeFromFile = false;
+
+  if (!mUsingSmoke)
+    return 0;
+  if (BLI_path_is_rel(mmd->domain->cache_directory))
+    return 0;
+
+  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);
+
+  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)) {
+    return 0;
+  }
+  result += updateGridFromFile(targetFile, mDensity);
+
+  expected += 1;
+  ss.str("");
+  ss << "shadow_####" << dformat;
+  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+  BLI_path_frame(targetFile, framenr, 0);
+  if (!BLI_exists(targetFile)) {
+    return 0;
+  }
+  result += updateGridFromFile(targetFile, mShadow);
+
+  if (mUsingHeat) {
+    expected += 1;
+    ss.str("");
+    ss << "heat_####" << dformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mHeat);
+  }
+
+  if (mUsingColors) {
+    expected += 3;
+    ss.str("");
+    ss << "color_r_####" << dformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mColorR);
+
+    ss.str("");
+    ss << "color_g_####" << dformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mColorG);
+
+    ss.str("");
+    ss << "color_b_####" << dformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mColorB);
+  }
+
+  if (mUsingFire) {
+    expected += 3;
+    ss.str("");
+    ss << "flame_####" << dformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mFlame);
+
+    ss.str("");
+    ss << "fuel_####" << dformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mFuel);
+
+    ss.str("");
+    ss << "react_####" << dformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mReact);
+  }
+
+  mSmokeFromFile = true;
+  return (result == expected) ? 1 : 0;
+}
+
+int MANTA::updateNoiseStructures(FluidModifierData *mmd, int framenr)
+{
+  if (MANTA::with_debug)
+    std::cout << "MANTA::updateNoiseStructures()" << std::endl;
+
+  mNoiseFromFile = false;
+
+  if (!mUsingSmoke || !mUsingNoise)
+    return 0;
+  if (BLI_path_is_rel(mmd->domain->cache_directory))
+    return 0;
+
+  int result = 0;
+  int expected = 0; /* Expected number of read successes for this frame. */
+
+  std::ostringstream ss;
+  char cacheDirData[FILE_MAX], cacheDirNoise[FILE_MAX], targetFile[FILE_MAX];
+  cacheDirData[0] = '\0';
+  cacheDirNoise[0] = '\0';
+  targetFile[0] = '\0';
+
+  std::string dformat = getCacheFileEnding(mmd->domain->cache_data_format);
+  std::string nformat = getCacheFileEnding(mmd->domain->cache_noise_format);
+  BLI_path_join(cacheDirData,
+                sizeof(cacheDirData),
+                mmd->domain->cache_directory,
+                FLUID_DOMAIN_DIR_DATA,
+                nullptr);
+  BLI_path_join(cacheDirNoise,
+                sizeof(cacheDirNoise),
+                mmd->domain->cache_directory,
+                FLUID_DOMAIN_DIR_NOISE,
+                nullptr);
+
+  expected += 1;
+  ss.str("");
+  ss << "density_noise_####" << nformat;
+  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirNoise, ss.str().c_str());
+  BLI_path_frame(targetFile, framenr, 0);
+  if (!BLI_exists(targetFile)) {
+    return 0;
+  }
+  result += updateGridFromFile(targetFile, mDensityHigh);
+
+  expected += 1;
+  ss.str("");
+  ss << "shadow_####" << dformat;
+  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirData, ss.str().c_str());
+  BLI_path_frame(targetFile, framenr, 0);
+  if (!BLI_exists(targetFile)) {
+    return 0;
+  }
+  result += updateGridFromFile(targetFile, mShadow);
+
+  if (mUsingColors) {
+    expected += 3;
+    ss.str("");
+    ss << "color_r_noise_####" << nformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirNoise, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mColorRHigh);
+
+    ss.str("");
+    ss << "color_g_noise_####" << nformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirNoise, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mColorGHigh);
+
+    ss.str("");
+    ss << "color_b_noise_####" << nformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirNoise, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mColorBHigh);
+  }
+
+  if (mUsingFire) {
+    expected += 3;
+    ss.str("");
+    ss << "flame_noise_####" << nformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirNoise, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mFlameHigh);
+
+    ss.str("");
+    ss << "fuel_noise_####" << nformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirNoise, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mFuelHigh);
+
+    ss.str("");
+    ss << "react_noise_####" << nformat;
+    BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDirNoise, ss.str().c_str());
+    BLI_path_frame(targetFile, framenr, 0);
+    if (!BLI_exists(targetFile)) {
+      return 0;
+    }
+    result += updateGridFromFile(targetFile, mReactHigh);
+  }
+
+  mNoiseFromFile = true;
+  return (result == expected) ? 1 : 0;
+}
+
 /* Dirty hack: Needed to format paths from python code that is run via PyRun_SimpleString */
 static std::string escapeSlashes(std::string const &s)
 {
@@ -1194,7 +1436,7 @@ int MANTA::writeConfiguration(FluidModifierData *mmd, int framenr)
   cacheDir[0] = '\0';
   targetFile[0] = '\0';
 
-  std::string dformat = getCacheFileEnding(mmd->domain->cache_data_format);
+  std::string dformat = ".uni";
 
   BLI_path_join(
       cacheDir, sizeof(cacheDir), mmd->domain->cache_dir

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list