[Bf-blender-cvs] [00192167229] master: Fix linking errors WITH_MOD_FLUID=OFF, again

Campbell Barton noreply at git.blender.org
Wed Dec 18 02:54:21 CET 2019


Commit: 00192167229ea41c3e4fc6e71c15b2a7b9f643ce
Author: Campbell Barton
Date:   Wed Dec 18 12:38:22 2019 +1100
Branches: master
https://developer.blender.org/rB00192167229ea41c3e4fc6e71c15b2a7b9f643ce

Fix linking errors WITH_MOD_FLUID=OFF, again

Expose BKE_fluid_modifier_* functions for readfile versioning.

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

M	source/blender/blenkernel/BKE_fluid.h
M	source/blender/blenkernel/intern/fluid.c

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

diff --git a/source/blender/blenkernel/BKE_fluid.h b/source/blender/blenkernel/BKE_fluid.h
index b655f244aa9..0f64dd262cc 100644
--- a/source/blender/blenkernel/BKE_fluid.h
+++ b/source/blender/blenkernel/BKE_fluid.h
@@ -24,10 +24,12 @@
  * \ingroup bke
  */
 
+struct Depsgraph;
 struct FluidDomainSettings;
 struct FluidEffectorSettings;
 struct FluidFlowSettings;
 struct FluidModifierData;
+struct Main;
 struct Scene;
 
 typedef float (*BKE_Fluid_BresenhamFn)(
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index be8c1401b53..42e8544d3c4 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -21,46 +21,56 @@
  * \ingroup bke
  */
 
-#ifdef WITH_FLUID
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+
+#include "BLI_fileops.h"
+#include "BLI_math.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_task.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_fluid_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
 
-#  include "MEM_guardedalloc.h"
+#include "BKE_effect.h"
+#include "BKE_fluid.h"
+#include "BKE_library.h"
+#include "BKE_modifier.h"
+#include "BKE_pointcache.h"
+
+#ifdef WITH_FLUID
 
 #  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_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 "BLI_kdopbvh.h"
+#  include "BLI_threads.h"
+#  include "BLI_kdtree.h"
+#  include "BLI_voxel.h"
 
 #  include "BKE_bvhutils.h"
 #  include "BKE_collision.h"
 #  include "BKE_colortools.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"
@@ -70,12 +80,20 @@
 
 #  include "manta_fluid_API.h"
 
-#  include "BLI_task.h"
-#  include "BLI_kdtree.h"
-#  include "BLI_voxel.h"
+#endif /* WITH_FLUID */
+
+/** Time step default value for nice appearance. */
+#define DT_DEFAULT 0.1f
 
+static void BKE_fluid_modifier_reset_ex(struct FluidModifierData *mmd, bool need_lock);
+
+#ifdef WITH_FLUID
 // #define DEBUG_PRINT
 
+/* -------------------------------------------------------------------- */
+/** \name Fluid API
+ * \{ */
+
 static ThreadMutex object_update_lock = BLI_MUTEX_INITIALIZER;
 
 struct FluidModifierData;
@@ -83,9 +101,6 @@ struct Mesh;
 struct Object;
 struct Scene;
 
-// 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)))
@@ -545,4379 +560,4407 @@ static bool BKE_fluid_modifier_init(
   return false;
 }
 
-static void BKE_fluid_modifier_freeDomain(FluidModifierData *mmd)
+// forward declaration
+static void manta_smoke_calc_transparency(FluidDomainSettings *mds, ViewLayer *view_layer);
+static float calc_voxel_transp(
+    float *result, float *input, int res[3], int *pixel, float *t_ray, float correct);
+static void update_mesh_distances(int index,
+                                  float *mesh_distances,
+                                  BVHTreeFromMesh *tree_data,
+                                  const float ray_start[3],
+                                  float surface_thickness,
+                                  int use_plane_init);
+
+static int get_light(ViewLayer *view_layer, float *light)
 {
-  if (mmd->domain) {
-    if (mmd->domain->fluid) {
-      manta_free(mmd->domain->fluid);
-    }
+  Base *base_tmp = NULL;
+  int found_light = 0;
 
-    if (mmd->domain->fluid_mutex) {
-      BLI_rw_mutex_free(mmd->domain->fluid_mutex);
-    }
+  // try to find a lamp, preferably local
+  for (base_tmp = FIRSTBASE(view_layer); base_tmp; base_tmp = base_tmp->next) {
+    if (base_tmp->object->type == OB_LAMP) {
+      Light *la = base_tmp->object->data;
 
-    if (mmd->domain->effector_weights) {
-      MEM_freeN(mmd->domain->effector_weights);
+      if (la->type == LA_LOCAL) {
+        copy_v3_v3(light, base_tmp->object->obmat[3]);
+        return 1;
+      }
+      else if (!found_light) {
+        copy_v3_v3(light, base_tmp->object->obmat[3]);
+        found_light = 1;
+      }
     }
-    mmd->domain->effector_weights = NULL;
+  }
 
-    if (!(mmd->modifier.flag & eModifierFlag_SharedCaches)) {
-      BKE_ptcache_free_list(&(mmd->domain->ptcaches[0]));
-      mmd->domain->point_cache[0] = NULL;
-    }
+  return found_light;
+}
 
-    if (mmd->domain->mesh_velocities) {
-      MEM_freeN(mmd->domain->mesh_velocities);
-    }
-    mmd->domain->mesh_velocities = NULL;
+/** \} */
 
-    if (mmd->domain->coba) {
-      MEM_freeN(mmd->domain->coba);
-    }
+/* -------------------------------------------------------------------- */
+/** \name Obstacles
+ * \{ */
 
-    MEM_freeN(mmd->domain);
-    mmd->domain = NULL;
-  }
-}
+typedef struct ObstaclesFromDMData {
+  FluidDomainSettings *mds;
+  FluidEffectorSettings *mes;
+  const MVert *mvert;
+  const MLoop *mloop;
+  const MLoopTri *looptri;
+  BVHTreeFromMesh *tree;
 
-static void BKE_fluid_modifier_freeFlow(FluidModifierData *mmd)
+  bool has_velocity;
+  float *vert_vel;
+  float *velocity_x, *velocity_y, *velocity_z;
+  int *num_objects;
+  float *distances_map;
+} ObstaclesFromDMData;
+
+static void obstacles_from_mesh_task_cb(void *__restrict userdata,
+                                        const int z,
+                                        const TaskParallelTLS *__restrict UNUSED(tls))
 {
-  if (mmd->flow) {
-    if (mmd->flow->mesh) {
-      BKE_id_free(NULL, mmd->flow->mesh);
-    }
-    mmd->flow->mesh = NULL;
+  ObstaclesFromDMData *data = userdata;
+  FluidDomainSettings *mds = data->mds;
 
-    if (mmd->flow->verts_old) {
-      MEM_freeN(mmd->flow->verts_old);
-    }
-    mmd->flow->verts_old = NULL;
-    mmd->flow->numverts = 0;
+  /* slightly rounded-up sqrt(3 * (0.5)^2) == max. distance of cell boundary along the diagonal */
+  const float surface_distance = 2.0f;  // 0.867f;
+  /* Note: Use larger surface distance to cover larger area with obvel. Manta will use these obvels
+   * and extrapolate them (inside and outside obstacle) */
 
-    MEM_freeN(mmd->flow);
-    mmd->flow = NULL;
-  }
-}
+  for (int x = mds->res_min[0]; x < mds->res_max[0]; x++) {
+    for (int y = mds->res_min[1]; y < mds->res_max[1]; y++) {
+      const int index = manta_get_index(
+          x - mds->res_min[0], mds->res[0], y - mds->res_min[1], mds->res[1], z - mds->res_min[2]);
 
-static void BKE_fluid_modifier_freeEffector(FluidModifierData *mmd)
-{
-  if (mmd->effector) {
-    if (mmd->effector->mesh) {
-      BKE_id_free(NULL, mmd->effector->mesh);
-    }
-    mmd->effector->mesh = NULL;
+      float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f};
+      BVHTreeNearest nearest = {0};
+      nearest.index = -1;
+      nearest.dist_sq = surface_distance *
+                        surface_distance; /* find_nearest uses squared distance */
+      bool has_inc_obj = false;
 
-    if (mmd->effector->verts_old) {
-      MEM_freeN(mmd->effector->verts_old);
-    }
-    mmd->effector->verts_old = NULL;
-    mmd->effector->numverts = 0;
+      /* find the nearest point on the mesh */
+      if (BLI_bvhtree_find_nearest(
+              data->tree->tree, ray_start, &nearest, data->tree->nearest_callback, data->tree) !=
+          -1) {
+        const MLoopTri *lt = &data->looptri[nearest.index];
+        float weights[3];
+        int v1, v2, v3;
 
-    MEM_freeN(mmd->effector);
-    mmd->effector = NULL;
-  }
-}
+        /* calculate barycentric weights for nearest point */
+        v1 = data->mloop[lt->tri[0]].v;
+        v2 = data->mloop[lt->tri[1]].v;
+        v3 = data->mloop[lt->tri[2]].v;
+        interp_weights_tri_v3(
+            weights, data->mvert[v1].co, data->mvert[v2].co, data->mvert[v3].co, nearest.co);
 
-static void BKE_fluid_modifier_reset_ex(struct FluidModifierData *mmd, bool need_lock)
-{
-  if (!mmd) {
-    return;
-  }
+        if (data->has_velocity) {
+          /* increase object count */
+          data->num_objects[index]++;
+          has_inc_obj = true;
 
-  if (mmd->domain) {
-    if (mmd->domain->fluid) {
-      if (need_lock) {
-        BLI_rw_mutex_lock(mmd->domain->fluid_mutex, THREAD_LOCK_WRITE);
-      }
+          /* apply object velocity */
+          float hit_vel[3];
+          interp_v3_v3v3v3(hit_vel,
+                           &data->vert_vel[v1 * 3],
+                           &data->vert_vel[v2 * 3],
+                           &data->vert_vel[v3 * 3],
+                           weights);
 
-      manta_free(mmd->domain->fluid);
-      mmd->domain->fluid = NULL;
+          /* Guiding has additional velocity multiplier */
+          if (data->mes->type == FLUID_EFFECTOR_TYPE_GUIDE) {
+            mul_v3_fl(hit_vel, data->mes->vel_multi);
 
-      if (need_lock) {
-        BLI_rw_mutex_unlock(mmd->domain->fluid_mutex);
+            switch (data->mes->guide_mode) {
+              case FLUID_EFFECTOR_GUIDE_AVERAGED:
+                data->velocity_x[index] = (data->velocity_x[index] + hit_vel[0]) * 0.5f;
+                data->velocity_y[index] = (data->velocity_y[index] + hit_vel[1]) * 0.5f;
+                data->velocity_z[index] = (data->velocity_z[index] + hit_vel[2]) * 0.5f;
+                break;
+              case FLUID_EFFECTOR_GUIDE_OVERRIDE:
+                data->velocity_x[index] = hit_vel[0];
+                data->velocity_y[i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list