[Bf-blender-cvs] [99518589428] master: Fluid: Improved OpenVDB support for fluid caches

Sebastián Barschkis noreply at git.blender.org
Wed Jun 24 16:27:40 CEST 2020


Commit: 9951858942893adeb4eef27ec8a8471a179e9c59
Author: Sebastián Barschkis
Date:   Wed Jun 24 15:30:49 2020 +0200
Branches: master
https://developer.blender.org/rB9951858942893adeb4eef27ec8a8471a179e9c59

Fluid: Improved OpenVDB support for fluid caches

This commit makes uses of the new OpenVDB IO in Mantaflow (introduced in 781f783a66ac).

>From now on, fluid cache files in OpenVDB format will contain a list of grids per frame (before: one .vdb file per grid per frame). Besides regular grids, particle systems are also stored using OpenVDBs PointGrid data structures.

All older cache formats will remain fully functional:
- Uni caches (.uni) files are still available from the UI and can be used as before
- Raw caches (.raw) are no longer available from the UI, but loading them is still possible
- Old OpenVDB caches (one .vdb per grid) can no longer be baked either, but loading them is still possible.

It is also no longer possible to choose file formats for 'Noise' and 'Particles'. Instead there are now options to set the file format for 'Volumetric' and for 'Mesh' data.

Known issues (planned to be resolved soon):
- OpenVDB files are currently not taking into consideration the clipping value (FluidDomainSettings). Empty cells are therefore being written too. Depending on the scene, this can make file sizes unnecessarily large.
- Domains are not being exported at their world position. Instead they are always clipped to the origin.

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

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	intern/mantaflow/intern/strings/fluid_script.h
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/smoke_script.h
M	release/scripts/startup/bl_operators/object_quick_effects.py
M	release/scripts/startup/bl_ui/properties_physics_fluid.py
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/editors/physics/physics_fluid.c
M	source/blender/makesdna/DNA_fluid_types.h
M	source/blender/makesrna/intern/rna_fluid.c

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 7825ad14d7d..d78aa6732b1 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -41,23 +41,23 @@ int manta_write_config(struct MANTA *fluid, struct FluidModifierData *mmd, int f
 int manta_write_data(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
 int manta_write_noise(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
 int manta_read_config(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
-int manta_read_data(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
-int manta_read_noise(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_read_data(struct MANTA *fluid,
+                    struct FluidModifierData *mmd,
+                    int framenr,
+                    bool resumable);
+int manta_read_noise(struct MANTA *fluid,
+                     struct FluidModifierData *mmd,
+                     int framenr,
+                     bool resumable);
 int manta_read_mesh(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
-int manta_read_particles(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
+int manta_read_particles(struct MANTA *fluid,
+                         struct FluidModifierData *mmd,
+                         int framenr,
+                         bool resumable);
 int manta_read_guiding(struct MANTA *fluid,
                        struct FluidModifierData *mmd,
                        int framenr,
                        bool sourceDomain);
-int manta_update_liquid_structures(struct MANTA *fluid,
-                                   struct FluidModifierData *mmd,
-                                   int framenr);
-int manta_update_mesh_structures(struct MANTA *fluid, struct FluidModifierData *mmd, int framenr);
-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 e760cef8641..e81b2b2e268 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -301,9 +301,8 @@ void MANTA::initDomain(FluidModifierData *mmd)
   string tmpString = fluid_variables + fluid_solver + fluid_alloc + fluid_cache_helper +
                      fluid_bake_multiprocessing + fluid_bake_data + fluid_bake_noise +
                      fluid_bake_mesh + fluid_bake_particles + fluid_bake_guiding +
-                     fluid_file_import + fluid_file_export + fluid_save_data + fluid_load_data +
-                     fluid_pre_step + fluid_post_step + fluid_adapt_time_step +
-                     fluid_time_stepping;
+                     fluid_file_import + fluid_file_export + fluid_pre_step + fluid_post_step +
+                     fluid_adapt_time_step + fluid_time_stepping;
   string finalString = parseScript(tmpString, mmd);
   pythonCommands.push_back(finalString);
   runPythonString(pythonCommands);
@@ -674,7 +673,7 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
 
   if (!mmd) {
     if (with_debug)
-      cout << "No modifier data given in RNA map setup - returning early" << endl;
+      cout << "Fluid: No modifier data given in RNA map setup - returning early" << endl;
     return;
   }
 
@@ -730,6 +729,20 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
   float viscosity = mds->viscosity_base * pow(10.0f, -mds->viscosity_exponent);
   float domainSize = MAX3(mds->global_size[0], mds->global_size[1], mds->global_size[2]);
 
+  string vdbCompressionMethod = "Compression_None";
+  if (mds->openvdb_compression == VDB_COMPRESSION_NONE)
+    vdbCompressionMethod = "Compression_None";
+  else if (mds->openvdb_compression == VDB_COMPRESSION_ZIP)
+    vdbCompressionMethod = "Compression_Zip";
+  else if (mds->openvdb_compression == VDB_COMPRESSION_BLOSC)
+    vdbCompressionMethod = "Compression_Blosc";
+
+  string vdbPrecisionHalf = "True";
+  if (mds->openvdb_data_depth == VDB_PRECISION_HALF_FLOAT)
+    vdbPrecisionHalf = "True";
+  else if (mds->openvdb_data_depth == VDB_PRECISION_FULL_FLOAT)
+    vdbPrecisionHalf = "False";
+
   mRNAMap["USING_SMOKE"] = getBooleanString(mds->type == FLUID_DOMAIN_TYPE_GAS);
   mRNAMap["USING_LIQUID"] = getBooleanString(mds->type == FLUID_DOMAIN_TYPE_LIQUID);
   mRNAMap["USING_COLORS"] = getBooleanString(mds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS);
@@ -743,7 +756,7 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
   mRNAMap["USING_LOG_DISSOLVE"] = getBooleanString(mds->flags & FLUID_DOMAIN_USE_DISSOLVE_LOG);
   mRNAMap["USING_DISSOLVE"] = getBooleanString(mds->flags & FLUID_DOMAIN_USE_DISSOLVE);
   mRNAMap["DO_OPEN"] = getBooleanString(mds->border_collisions == 0);
-  mRNAMap["CACHE_RESUMABLE"] = getBooleanString(mds->cache_type != FLUID_DOMAIN_CACHE_FINAL);
+  mRNAMap["CACHE_RESUMABLE"] = getBooleanString(mds->flags & FLUID_DOMAIN_USE_RESUMABLE_CACHE);
   mRNAMap["USING_ADAPTIVETIME"] = getBooleanString(mds->flags & FLUID_DOMAIN_USE_ADAPTIVE_TIME);
   mRNAMap["USING_SPEEDVECTORS"] = getBooleanString(mds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS);
   mRNAMap["USING_FRACTIONS"] = getBooleanString(mds->flags & FLUID_DOMAIN_USE_FRACTIONS);
@@ -850,6 +863,9 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
   mRNAMap["LIQUID_SURFACE_TENSION"] = to_string(mds->surface_tension);
   mRNAMap["FLUID_VISCOSITY"] = to_string(viscosity);
   mRNAMap["FLUID_DOMAIN_SIZE"] = to_string(domainSize);
+  mRNAMap["FLUID_DOMAIN_SIZE_X"] = to_string(mds->global_size[0]);
+  mRNAMap["FLUID_DOMAIN_SIZE_Y"] = to_string(mds->global_size[1]);
+  mRNAMap["FLUID_DOMAIN_SIZE_Z"] = to_string(mds->global_size[2]);
   mRNAMap["SNDPARTICLE_TYPES"] = particleTypesStr;
   mRNAMap["GUIDING_ALPHA"] = to_string(mds->guide_alpha);
   mRNAMap["GUIDING_BETA"] = to_string(mds->guide_beta);
@@ -858,6 +874,8 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
   mRNAMap["GRAVITY_Y"] = to_string(mds->gravity[1]);
   mRNAMap["GRAVITY_Z"] = to_string(mds->gravity[2]);
   mRNAMap["CACHE_DIR"] = cacheDirectory;
+  mRNAMap["COMPRESSION_OPENVDB"] = vdbCompressionMethod;
+  mRNAMap["PRECISION_OPENVDB"] = vdbPrecisionHalf;
 
   /* Fluid object names. */
   mRNAMap["NAME_FLAGS"] = FLUID_NAME_FLAGS;
@@ -900,6 +918,8 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
   mRNAMap["NAME_DENSITYIN"] = FLUID_NAME_DENSITYIN;
   mRNAMap["NAME_HEAT"] = FLUID_NAME_HEAT;
   mRNAMap["NAME_HEATIN"] = FLUID_NAME_HEATIN;
+  mRNAMap["NAME_TEMPERATURE"] = FLUID_NAME_TEMPERATURE;
+  mRNAMap["NAME_TEMPERATUREIN"] = FLUID_NAME_TEMPERATUREIN;
   mRNAMap["NAME_COLORR"] = FLUID_NAME_COLORR;
   mRNAMap["NAME_COLORG"] = FLUID_NAME_COLORG;
   mRNAMap["NAME_COLORB"] = FLUID_NAME_COLORB;
@@ -921,6 +941,8 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
   mRNAMap["NAME_MAPWEIGHTS"] = FLUID_NAME_MAPWEIGHTS;
   mRNAMap["NAME_PP"] = FLUID_NAME_PP;
   mRNAMap["NAME_PVEL"] = FLUID_NAME_PVEL;
+  mRNAMap["NAME_PARTS"] = FLUID_NAME_PARTS;
+  mRNAMap["NAME_PARTSVELOCITY"] = FLUID_NAME_PARTSVELOCITY;
   mRNAMap["NAME_PINDEX"] = FLUID_NAME_PINDEX;
   mRNAMap["NAME_GPI"] = FLUID_NAME_GPI;
   mRNAMap["NAME_CURVATURE"] = FLUID_NAME_CURVATURE;
@@ -967,6 +989,10 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
   mRNAMap["NAME_PVEL_PARTICLES"] = FLUID_NAME_PVEL_PARTICLES;
   mRNAMap["NAME_PFORCE_PARTICLES"] = FLUID_NAME_PFORCE_PARTICLES;
   mRNAMap["NAME_PLIFE_PARTICLES"] = FLUID_NAME_PLIFE_PARTICLES;
+  mRNAMap["NAME_PARTS_PARTICLES"] = FLUID_NAME_PARTS_PARTICLES;
+  mRNAMap["NAME_PARTSVEL_PARTICLES"] = FLUID_NAME_PARTSVEL_PARTICLES;
+  mRNAMap["NAME_PARTSFORCE_PARTICLES"] = FLUID_NAME_PARTSFORCE_PARTICLES;
+  mRNAMap["NAME_PARTSLIFE_PARTICLES"] = FLUID_NAME_PARTSLIFE_PARTICLES;
   mRNAMap["NAME_VELOCITY_PARTICLES"] = FLUID_NAME_VELOCITY_PARTICLES;
   mRNAMap["NAME_FLAGS_PARTICLES"] = FLUID_NAME_FLAGS_PARTICLES;
   mRNAMap["NAME_PHI_PARTICLES"] = FLUID_NAME_PHI_PARTICLES;
@@ -1000,9 +1026,6 @@ void MANTA::initializeRNAMap(FluidModifierData *mmd)
 
 string MANTA::getRealValue(const string &varName)
 {
-  if (with_debug)
-    cout << "MANTA::getRealValue()" << endl;
-
   unordered_map<string, string>::iterator it;
   it = mRNAMap.find(varName);
 
@@ -1011,9 +1034,6 @@ string MANTA::getRealValue(const string &varName)
          << endl;
     return "";
   }
-  if (with_debug) {
-    cout << "Found variable " << varName << " with value " << it->second << endl;
-  }
 
   return it->second;
 }
@@ -1062,409 +1082,6 @@ string MANTA::parseScript(const string &setup_string, FluidModifierData *mmd)
   return res.str();
 }
 
-bool MANTA::updateFlipStructures(FluidModifierData *mmd, int framenr)
-{
-  if (MANTA::with_debug)
-    cout << "MANTA::updateFlipStructures()" << endl;
-
-  FluidDomainSettings *mds = mmd->domain;
-  mFlipFromFile = false;
-
-  if (!mUsingLiquid)
-    return false;
-  if (BLI_path_is_rel(mds->cache_directory))
-    return false;
-
-  int result = 0;
-  int expected = 0; /* Expected number of read successes for this frame. */
-
-  /* Ensure empty data structures at start. */
-  if (!mFlipParticleData || !mFlipParticleVelocity)
-    return false;
-
-  mFlipParticleData->clear();
-  mFlipParticleVelocity->clear();
-
-  string pformat = getCacheFileEnding(mds->cache_particle_format);
-  string file = getFile(mmd, FLUID_DOMAIN_DIR_DATA, FLUID_NAME_PP, pformat, framenr);
-
-  expected += 1;
-  if (BLI_exists(file.c_str())) {
-    result += updateParticlesFromFile(file, false, false);
-    assert(result == expected);
-  }
-
-  file = getFile(mmd, FLUID_DOMAIN_DIR_DATA, FLUID_NAME

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list