[Bf-blender-cvs] [7b87d3d34ec] master: Mantaflow [Part 11]: Updated entire smoke.c code

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


Commit: 7b87d3d34ec5bbaf777bdc27abdb69600915fce1
Author: Sebastián Barschkis
Date:   Mon Dec 16 15:49:07 2019 +0100
Branches: master
https://developer.blender.org/rB7b87d3d34ec5bbaf777bdc27abdb69600915fce1

Mantaflow [Part 11]: Updated entire smoke.c code

Probably the most significant changes are in smoke.c.

New functionality includes:
- support for adative time steps (substeps)
- write flow objects to grid structure so that Mantaflow can generate levelsets
- no more distinction between FLUID_3D and WTURBULENCE objects. Everthing that communicates with Mantaflow now lives in a FLUID object.

Reviewed By: sergey

Maniphest Tasks: T59995

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

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

A	source/blender/blenkernel/intern/fluid.c

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

diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
new file mode 100644
index 00000000000..c45b87f8a71
--- /dev/null
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -0,0 +1,4772 @@
+/*
+ * 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
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+#include <string.h> /* memset */
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_kdopbvh.h"
+#include "BLI_threads.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_customdata_types.h"
+#include "DNA_light_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_fluid_types.h"
+
+#include "BKE_appdir.h"
+#include "BKE_animsys.h"
+#include "BKE_armature.h"
+#include "BKE_bvhutils.h"
+#include "BKE_collision.h"
+#include "BKE_colortools.h"
+#include "BKE_constraint.h"
+#include "BKE_customdata.h"
+#include "BKE_deform.h"
+#include "BKE_effect.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_particle.h"
+#include "BKE_pointcache.h"
+#include "BKE_scene.h"
+#include "BKE_fluid.h"
+#include "BKE_texture.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "RE_shader_ext.h"
+
+#include "GPU_glew.h"
+
+//#define DEBUG_TIME
+
+#include "manta_fluid_API.h"
+
+#ifdef DEBUG_TIME
+#  include "PIL_time.h"
+#endif
+
+#include "BLI_task.h"
+#include "BLI_kdtree.h"
+#include "BLI_voxel.h"
+
+static ThreadMutex object_update_lock = BLI_MUTEX_INITIALIZER;
+
+struct Mesh;
+struct Object;
+struct Scene;
+struct FluidModifierData;
+
+// timestep default value for nice appearance 0.1f
+#define DT_DEFAULT 0.1f
+
+#define ADD_IF_LOWER_POS(a, b) (min_ff((a) + (b), max_ff((a), (b))))
+#define ADD_IF_LOWER_NEG(a, b) (max_ff((a) + (b), min_ff((a), (b))))
+#define ADD_IF_LOWER(a, b) (((b) > 0) ? ADD_IF_LOWER_POS((a), (b)) : ADD_IF_LOWER_NEG((a), (b)))
+
+void BKE_fluid_reallocate_fluid(FluidDomainSettings *mds, int res[3], int free_old)
+{
+  if (free_old && mds->fluid) {
+    manta_free(mds->fluid);
+  }
+  if (!min_iii(res[0], res[1], res[2])) {
+    mds->fluid = NULL;
+    return;
+  }
+
+  mds->fluid = manta_init(res, mds->mmd);
+
+  mds->res_noise[0] = res[0] * mds->noise_scale;
+  mds->res_noise[1] = res[1] * mds->noise_scale;
+  mds->res_noise[2] = res[2] * mds->noise_scale;
+}
+
+void BKE_fluid_reallocate_copy_fluid(FluidDomainSettings *mds,
+                                     int o_res[3],
+                                     int n_res[3],
+                                     int o_min[3],
+                                     int n_min[3],
+                                     int o_max[3],
+                                     int o_shift[3],
+                                     int n_shift[3])
+{
+  int x, y, z;
+  struct MANTA *fluid_old = mds->fluid;
+  const int block_size = mds->noise_scale;
+  int new_shift[3] = {0};
+  sub_v3_v3v3_int(new_shift, n_shift, o_shift);
+
+  /* allocate new fluid data */
+  BKE_fluid_reallocate_fluid(mds, n_res, 0);
+
+  int o_total_cells = o_res[0] * o_res[1] * o_res[2];
+  int n_total_cells = n_res[0] * n_res[1] * n_res[2];
+
+  /* boundary cells will be skipped when copying data */
+  int bwidth = mds->boundary_width;
+
+  /* copy values from old fluid to new */
+  if (o_total_cells > 1 && n_total_cells > 1) {
+    /* base smoke */
+    float *o_dens, *o_react, *o_flame, *o_fuel, *o_heat, *o_vx, *o_vy, *o_vz, *o_r, *o_g, *o_b;
+    float *n_dens, *n_react, *n_flame, *n_fuel, *n_heat, *n_vx, *n_vy, *n_vz, *n_r, *n_g, *n_b;
+    float dummy, *dummy_s;
+    int *dummy_p;
+    /* noise smoke */
+    int wt_res_old[3];
+    float *o_wt_dens, *o_wt_react, *o_wt_flame, *o_wt_fuel, *o_wt_tcu, *o_wt_tcv, *o_wt_tcw,
+        *o_wt_tcu2, *o_wt_tcv2, *o_wt_tcw2, *o_wt_r, *o_wt_g, *o_wt_b;
+    float *n_wt_dens, *n_wt_react, *n_wt_flame, *n_wt_fuel, *n_wt_tcu, *n_wt_tcv, *n_wt_tcw,
+        *n_wt_tcu2, *n_wt_tcv2, *n_wt_tcw2, *n_wt_r, *n_wt_g, *n_wt_b;
+
+    if (mds->flags & FLUID_DOMAIN_USE_NOISE) {
+      manta_smoke_turbulence_export(fluid_old,
+                                    &o_wt_dens,
+                                    &o_wt_react,
+                                    &o_wt_flame,
+                                    &o_wt_fuel,
+                                    &o_wt_r,
+                                    &o_wt_g,
+                                    &o_wt_b,
+                                    &o_wt_tcu,
+                                    &o_wt_tcv,
+                                    &o_wt_tcw,
+                                    &o_wt_tcu2,
+                                    &o_wt_tcv2,
+                                    &o_wt_tcw2);
+      manta_smoke_turbulence_get_res(fluid_old, wt_res_old);
+      manta_smoke_turbulence_export(mds->fluid,
+                                    &n_wt_dens,
+                                    &n_wt_react,
+                                    &n_wt_flame,
+                                    &n_wt_fuel,
+                                    &n_wt_r,
+                                    &n_wt_g,
+                                    &n_wt_b,
+                                    &n_wt_tcu,
+                                    &n_wt_tcv,
+                                    &n_wt_tcw,
+                                    &n_wt_tcu2,
+                                    &n_wt_tcv2,
+                                    &n_wt_tcw2);
+    }
+
+    manta_smoke_export(fluid_old,
+                       &dummy,
+                       &dummy,
+                       &o_dens,
+                       &o_react,
+                       &o_flame,
+                       &o_fuel,
+                       &o_heat,
+                       &o_vx,
+                       &o_vy,
+                       &o_vz,
+                       &o_r,
+                       &o_g,
+                       &o_b,
+                       &dummy_p,
+                       &dummy_s);
+    manta_smoke_export(mds->fluid,
+                       &dummy,
+                       &dummy,
+                       &n_dens,
+                       &n_react,
+                       &n_flame,
+                       &n_fuel,
+                       &n_heat,
+                       &n_vx,
+                       &n_vy,
+                       &n_vz,
+                       &n_r,
+                       &n_g,
+                       &n_b,
+                       &dummy_p,
+                       &dummy_s);
+
+    for (x = o_min[0]; x < o_max[0]; x++) {
+      for (y = o_min[1]; y < o_max[1]; y++) {
+        for (z = o_min[2]; z < o_max[2]; z++) {
+          /* old grid index */
+          int xo = x - o_min[0];
+          int yo = y - o_min[1];
+          int zo = z - o_min[2];
+          int index_old = manta_get_index(xo, o_res[0], yo, o_res[1], zo);
+          /* new grid index */
+          int xn = x - n_min[0] - new_shift[0];
+          int yn = y - n_min[1] - new_shift[1];
+          int zn = z - n_min[2] - new_shift[2];
+          int index_new = manta_get_index(xn, n_res[0], yn, n_res[1], zn);
+
+          /* skip if outside new domain */
+          if (xn < 0 || xn >= n_res[0] || yn < 0 || yn >= n_res[1] || zn < 0 || zn >= n_res[2]) {
+            continue;
+          }
+          /* skip if trying to copy from old boundary cell */
+          if (xo < bwidth || yo < bwidth || zo < bwidth || xo >= o_res[0] - bwidth ||
+              yo >= o_res[1] - bwidth || zo >= o_res[2] - bwidth) {
+            continue;
+          }
+          /* skip if trying to copy into new boundary cell */
+          if (xn < bwidth || yn < bwidth || zn < bwidth || xn >= n_res[0] - bwidth ||
+              yn >= n_res[1] - bwidth || zn >= n_res[2] - bwidth) {
+            continue;
+          }
+
+          /* copy data */
+          if (mds->flags & FLUID_DOMAIN_USE_NOISE) {
+            int i, j, k;
+            /* old grid index */
+            int xx_o = xo * block_size;
+            int yy_o = yo * block_size;
+            int zz_o = zo * block_size;
+            /* new grid index */
+            int xx_n = xn * block_size;
+            int yy_n = yn * block_size;
+            int zz_n = zn * block_size;
+
+            /* insert old texture values into new texture grids */
+            n_wt_tcu[index_new] = o_wt_tcu[index_old];
+            n_wt_tcv[index_new] = o_wt_tcv[index_old];
+            n_wt_tcw[index_new] = o_wt_tcw[index_old];
+
+            n_wt_tcu2[index_new] = o_wt_tcu2[index_old];
+            n_wt_tcv2[index_new] = o_wt_tcv2[index_old];
+            n_wt_tcw2[index_new] = o_wt_tcw2[index_old];
+
+            for (i = 0; i < block_size; i++) {
+              for (j = 0; j < block_size; j++) {
+                for (k = 0; k < block_size; k++) {
+                  int big_index_old = manta_get_index(
+                      xx_o + i, wt_res_old[0], yy_o + j, wt_res_old[1], zz_o + k);
+                  int big_index_new = manta_get_index(
+                      xx_n + i, mds->res_noise[0], yy_n + j, mds->res_noise[1], zz_n + k);
+                  /* copy data */
+   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list