[Bf-blender-cvs] [829a83262f8] master: Mantaflow [Part 7]: Added bake configuration

Sebastián Barschkis noreply at git.blender.org
Mon Dec 16 16:33:58 CET 2019


Commit: 829a83262f8fc537652f40f1210cb9db6c349ad4
Author: Sebastián Barschkis
Date:   Mon Dec 16 15:46:47 2019 +0100
Branches: master
https://developer.blender.org/rB829a83262f8fc537652f40f1210cb9db6c349ad4

Mantaflow [Part 7]: Added bake configuration

Similarly to physics_fluid.c (in same directory) which handled the baking process for Elbeem, there is now physics_manta.c which handles it for Mantaflow.

There are two types of jobs: one for baking and another for freeing. The generic jobs will be used to bake / free specific parts of the simulation (e.g. bake mesh, free particles, etc.).

The jobs are only being used in the "modular" cache mode where the simulation has to be baked in parts.

Reviewed By: sergey

Maniphest Tasks: T59995

Differential Revision: https://developer.blender.org/D3856

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

M	source/blender/editors/physics/physics_fluid.c

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

diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index 44858e36fab..2642f000762 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -1,4 +1,6 @@
 /*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
@@ -15,10 +17,16 @@
  *
  * The Original Code is Copyright (C) Blender Foundation
  * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Sebastian Barschkis (sebbas)
+ *
+ * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file
- * \ingroup edphys
+/** \file blender/editors/physics/physics_fluid.c
+ *  \ingroup edphys
  */
 
 #include <math.h>
@@ -31,1219 +39,798 @@
 /* types */
 #include "DNA_action_types.h"
 #include "DNA_object_types.h"
-#include "DNA_object_fluidsim_types.h"
 
+#include "BLI_blenlib.h"
+#include "BLI_path_util.h"
+#include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+#include "BLT_translation.h"
+
 #include "BKE_context.h"
 #include "BKE_customdata.h"
-#include "BKE_fluidsim.h"
+#include "BKE_main.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_fluid.h"
+#include "BKE_global.h"
 
 #include "DEG_depsgraph.h"
 
 #include "ED_screen.h"
-#include "ED_object.h"
+#include "PIL_time.h"
 
 #include "WM_types.h"
 #include "WM_api.h"
 
 #include "physics_intern.h"  // own include
+#include "manta_fluid_API.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_fluid_types.h"
+#include "DNA_mesh_types.h"
+
+#define FLUID_JOB_BAKE_ALL "FLUID_OT_bake_all"
+#define FLUID_JOB_BAKE_DATA "FLUID_OT_bake_data"
+#define FLUID_JOB_BAKE_NOISE "FLUID_OT_bake_noise"
+#define FLUID_JOB_BAKE_MESH "FLUID_OT_bake_mesh"
+#define FLUID_JOB_BAKE_PARTICLES "FLUID_OT_bake_particles"
+#define FLUID_JOB_BAKE_GUIDING "FLUID_OT_bake_guiding"
+#define FLUID_JOB_FREE_ALL "FLUID_OT_free_all"
+#define FLUID_JOB_FREE_DATA "FLUID_OT_free_data"
+#define FLUID_JOB_FREE_NOISE "FLUID_OT_free_noise"
+#define FLUID_JOB_FREE_MESH "FLUID_OT_free_mesh"
+#define FLUID_JOB_FREE_PARTICLES "FLUID_OT_free_particles"
+#define FLUID_JOB_FREE_GUIDING "FLUID_OT_free_guiding"
+#define FLUID_JOB_BAKE_PAUSE "FLUID_OT_pause_bake"
+
+typedef struct FluidJob {
+  /* from wmJob */
+  void *owner;
+  short *stop, *do_update;
+  float *progress;
+  const char *type;
+  const char *name;
 
-/* enable/disable overall compilation */
-#ifdef WITH_MOD_FLUID
-
-#  include "LBM_fluidsim.h"
-
-#  include "BLI_blenlib.h"
-#  include "BLI_path_util.h"
-#  include "BLI_math.h"
+  struct Main *bmain;
+  Scene *scene;
+  Depsgraph *depsgraph;
+  Object *ob;
 
-#  include "BKE_global.h"
-#  include "BKE_main.h"
+  FluidModifierData *mmd;
 
-#  include "WM_api.h"
+  int success;
+  double start;
 
-#  include "DNA_scene_types.h"
-#  include "DNA_mesh_types.h"
+  int *pause_frame;
+} FluidJob;
 
-static float get_fluid_viscosity(FluidsimSettings *settings)
-{
-  return (1.0f / powf(10.0f, settings->viscosityExponent)) * settings->viscosityValue;
+static inline bool fluid_is_bake_all(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_BAKE_ALL));
 }
-
-static float get_fluid_rate(FluidsimSettings *settings)
-{
-  float rate = 1.0f; /* default rate if not animated... */
-
-  rate = settings->animRate;
-
-  if (rate < 0.0f) {
-    rate = 0.0f;
-  }
-
-  return rate;
+static inline bool fluid_is_bake_data(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_BAKE_DATA));
 }
-
-static void get_fluid_gravity(float *gravity, Scene *scene, FluidsimSettings *fss)
-{
-  if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
-    copy_v3_v3(gravity, scene->physics_settings.gravity);
-  }
-  else {
-    copy_v3_v3(gravity, fss->grav);
-  }
+static inline bool fluid_is_bake_noise(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_BAKE_NOISE));
+}
+static inline bool fluid_is_bake_mesh(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_BAKE_MESH));
+}
+static inline bool fluid_is_bake_particle(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_BAKE_PARTICLES));
+}
+static inline bool fluid_is_bake_guiding(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_BAKE_GUIDING));
+}
+static inline bool fluid_is_free_all(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_FREE_ALL));
+}
+static inline bool fluid_is_free_data(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_FREE_DATA));
+}
+static inline bool fluid_is_free_noise(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_FREE_NOISE));
+}
+static inline bool fluid_is_free_mesh(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_FREE_MESH));
+}
+static inline bool fluid_is_free_particles(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_FREE_PARTICLES));
+}
+static inline bool fluid_is_free_guiding(FluidJob *job) {
+  return (STREQ(job->type, FLUID_JOB_FREE_GUIDING));
 }
 
-static float get_fluid_size_m(Scene *scene, Object *domainob, FluidsimSettings *fss)
+static bool fluid_initjob(
+    bContext *C, FluidJob *job, wmOperator *op, char *error_msg, int error_size)
 {
-  if (!scene->unit.system) {
-    return fss->realsize;
-  }
-  else {
-    float dim[3];
-    float longest_axis;
-
-    BKE_object_dimensions_get(domainob, dim);
-    longest_axis = max_fff(dim[0], dim[1], dim[2]);
+  FluidModifierData *mmd = NULL;
+  FluidDomainSettings *mds;
+  Object *ob = CTX_data_active_object(C);
 
-    return longest_axis * scene->unit.scale_length;
+  mmd = (FluidModifierData *)modifiers_findByType(ob, eModifierType_Fluid);
+  if (!mmd) {
+    BLI_strncpy(error_msg, N_("Bake failed: no Fluid modifier found"), error_size);
+    return false;
+  }
+  mds = mmd->domain;
+  if (!mds) {
+    BLI_strncpy(error_msg, N_("Bake failed: invalid domain"), error_size);
+    return false;
   }
-}
 
-static bool fluid_is_animated_mesh(FluidsimSettings *fss)
-{
-  return ((fss->type == OB_FLUIDSIM_CONTROL) || fss->domainNovecgen);
-}
+  job->bmain = CTX_data_main(C);
+  job->scene = CTX_data_scene(C);
+  job->depsgraph = CTX_data_depsgraph_pointer(C);
+  job->ob = CTX_data_active_object(C);
+  job->mmd = mmd;
+  job->type = op->type->idname;
+  job->name = op->type->name;
 
-/* ********************** fluid sim settings struct functions ********************** */
+  return true;
+}
 
-#  if 0
-/* helper function */
-void fluidsimGetGeometryObjFilename(Object *ob, char *dst)  //, char *srcname)
+static bool fluid_initpaths(FluidJob *job, ReportList *reports)
 {
-  //BLI_snprintf(dst, FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name);
-  BLI_snprintf(dst, FILE_MAXFILE, "fluidcfgdata_%s.bobj.gz", ob->id.name);
-}
-#  endif
+  FluidDomainSettings *mds = job->mmd->domain;
+  char tmpDir[FILE_MAX];
+  tmpDir[0] = '\0';
 
-/* ********************** fluid sim channel helper functions ********************** */
+  const char *relbase = modifier_path_relbase(job->bmain, job->ob);
 
-typedef struct FluidAnimChannels {
-  int length;
+  /* We do not accept empty paths, they can end in random places silently, see T51176. */
+  if (mds->cache_directory[0] == '\0') {
+    modifier_path_init(
+        mds->cache_directory, sizeof(mds->cache_directory), FLUID_DOMAIN_DIR_DEFAULT);
+    BKE_reportf(reports,
+                RPT_WARNING,
+                "Fluid: Empty cache path, reset to default '%s'",
+                mds->cache_directory);
+  }
 
-  double aniFrameTime;
+  BLI_strncpy(tmpDir, mds->cache_directory, FILE_MAXDIR);
+  BLI_path_abs(tmpDir, relbase);
 
-  float *timeAtFrame;
-  float *DomainTime;
-  float *DomainGravity;
-  float *DomainViscosity;
-} FluidAnimChannels;
+  /* Ensure whole path exists */
+  const bool dir_exists = BLI_dir_create_recursive(tmpDir);
 
-typedef struct FluidObject {
-  struct FluidObject *next, *prev;
+  /* We change path to some presumably valid default value, but do not allow bake process to
+   * continue, this gives user chance to set manually another path. */
+  if (!dir_exists) {
+    modifier_path_init(
+        mds->cache_directory, sizeof(mds->cache_directory), FLUID_DOMAIN_DIR_DEFAULT);
 
-  struct Object *object;
+    BKE_reportf(reports,
+                RPT_ERROR,
+                "Fluid: Could not create cache directory '%s', reset to default '%s'",
+                tmpDir,
+                mds->cache_directory);
 
-  float *Translation;
-  float *Rotation;
-  float *Scale;
-  float *Active;
+    BLI_strncpy(tmpDir, mds->cache_directory, FILE_MAXDIR);
+    BLI_path_abs(tmpDir, relbase);
 
-  float *InitialVelocity;
+    /* Ensure whole path exists and is writable. */
+    if (!BLI_dir_create_recursive(tmpDir)) {
+      BKE_reportf(reports,
+                  RPT_ERROR,
+                  "Fluid: Could not use default cache directory '%s', "
+                  "please define a valid cache path manually",
+                  tmpDir);
+    }
+    /* Copy final dir back into domain settings */
+    BLI_strncpy(mds->cache_directory, tmpDir, FILE_MAXDIR);
 
-  float *AttractforceStrength;
-  float *AttractforceRadius;
-  float *VelocityforceStrength;
-  float *VelocityforceRadius;
+    return false;
+  }
 
-  float *VertexCache;
-  int numVerts, numTris;
-} FluidObject;
+  /* Copy final dir back into domain settings */
+  BLI_strncpy(mds->cache_directory, tmpDir, FILE_MAXDIR);
+  return true;
+}
 
-// no. of entries for the two channel sizes
-#  define CHANNEL_FLOAT 1
-#  define CHANNEL_VEC 3
+static void fluid_bake_free(void *customdata)
+{
+  FluidJob *job = customdata;
+  MEM_freeN(job);
+}
 
-// simplify channels before printing
-// for API this is done anyway upon init
-#  if 0
-static void fluidsimPrintChannel(FILE *file, float *channel, int paramsize, char *str, int entries)
+static void fluid_bake_sequence(FluidJob *job)
 {
-  int i, j;
-  int channelSize = paramsize;
+  FluidDomainSettings *mds = job->mmd->domain;
+  Scene *scene = job->scene;
+  int frame = 1, orig_frame;
+  int frames;
+  int *pause_frame = NULL;
+  bool is_first_frame;
 
-  if (entries == 3) {
-    elbeemSimpl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list