[Bf-blender-cvs] [303cee750ed] sculpt-mode-features: Mesh Filter: Initial work for relax mesh filter

Pablo Dobarro noreply at git.blender.org
Tue May 14 19:26:19 CEST 2019


Commit: 303cee750ed91240d3838b03e1cef1c8e455870a
Author: Pablo Dobarro
Date:   Tue May 14 19:25:35 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB303cee750ed91240d3838b03e1cef1c8e455870a

Mesh Filter: Initial work for relax mesh filter

The mesh filter tool now manages its own orco cache, so there is no need
for a global orco mode using the pbvh proxies. The tool should be much
faster than before.
The code for the relax mesh filter is there, but it is disabled in the
interface until the algorithm is finished.

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 6b47eb4f246..a492158c50e 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -269,7 +269,8 @@ typedef struct SculptSession {
   float cursor_location[3];
   float cursor_view_normal[3];
   float cursor_normal[3];
-  bool use_orco;
+
+  float (*orco)[3];
 
   /* Automasking active vertex */
   MVert *active_vertex_mesh;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 11e7bf5ab70..2dc2bb5e18a 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2338,6 +2338,112 @@ static void do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
   smooth(sd, ob, nodes, totnode, ss->cache->bstrength, false);
 }
 
+static void relax_vertex(float final_dp[3], PBVHVertexIter vd, SculptSession *ss, bool use_ss_orco)
+{
+  MVert *mvert = ss->mvert;
+  float final_disp[2][3];
+  int vert = vd.vert_indices[vd.i];
+  const MeshElemMap *vert_map = &ss->pmap[vert];
+  GSet *vert_gset[2];
+  vert_gset[0] = BLI_gset_new(BLI_ghashutil_uinthash, BLI_ghashutil_intcmp, "verts sets");
+  vert_gset[1] = BLI_gset_new(BLI_ghashutil_uinthash, BLI_ghashutil_intcmp, "verts sets");
+  BLI_gset_clear(vert_gset[0], NULL);
+  BLI_gset_clear(vert_gset[1], NULL);
+  float len_avg[2] = {0.0f};
+
+  for (int i = 0; i < vert_map->count; i++) {
+    const MPoly *p = &ss->mpoly[vert_map->indices[i]];
+    unsigned f_adj_v[2];
+    if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) {
+      if (vert_map->count > 1) {
+        if (i == 0) {
+          BLI_gset_add(vert_gset[0], f_adj_v[0]);
+          BLI_gset_add(vert_gset[1], f_adj_v[1]);
+        }
+        else if (BLI_gset_haskey(vert_gset[0], f_adj_v[0])) {
+          BLI_gset_add(vert_gset[1], f_adj_v[1]);
+        }
+        else if (BLI_gset_haskey(vert_gset[1], f_adj_v[0])) {
+          BLI_gset_add(vert_gset[0], f_adj_v[1]);
+        }
+        else if (BLI_gset_haskey(vert_gset[0], f_adj_v[1])) {
+          BLI_gset_add(vert_gset[1], f_adj_v[0]);
+        }
+        else if (BLI_gset_haskey(vert_gset[1], f_adj_v[1])) {
+          BLI_gset_add(vert_gset[0], f_adj_v[0]);
+        }
+      }
+    }
+  }
+
+  for (int vs = 0; vs < 2; vs++) {
+    int total = 0;
+    GSetIterator *gsi = BLI_gsetIterator_new(vert_gset[vs]);
+
+    for (BLI_gsetIterator_init(gsi, (GHash *)vert_gset[vs]); !BLI_gsetIterator_done(gsi);
+         BLI_gsetIterator_step(gsi)) {
+      int vin = BLI_gsetIterator_getKey(gsi);
+      MVert *c_vert = &ss->mvert[vin];
+      float connected_vert_co[3];
+      if (use_ss_orco) {
+        copy_v3_v3(connected_vert_co, ss->orco[vin]);
+      }
+      else {
+        copy_v3_v3(connected_vert_co, c_vert->co);
+      }
+      len_avg[vs] += len_v3v3(vd.co, connected_vert_co);
+      total++;
+    }
+
+    BLI_gsetIterator_free(gsi);
+    if (total > 0) {
+      len_avg[vs] = len_avg[vs] / (float)total;
+    }
+    zero_v3(final_disp[vs]);
+
+    gsi = BLI_gsetIterator_new(vert_gset[vs]);
+
+    for (BLI_gsetIterator_init(gsi, (GHash *)vert_gset[vs]); !BLI_gsetIterator_done(gsi);
+         BLI_gsetIterator_step(gsi)) {
+      int vin = BLI_gsetIterator_getKey(gsi);
+      MVert *c_vert = &ss->mvert[vin];
+      float connected_vert_co[3];
+      float connected_vert_disp[3];
+      if (use_ss_orco) {
+        copy_v3_v3(connected_vert_co, ss->orco[vin]);
+      }
+      else {
+        copy_v3_v3(connected_vert_co, c_vert->co);
+      }
+      float len = len_v3v3(vd.co, connected_vert_co);
+      float len_difference = len_avg[vs] - len;
+      sub_v3_v3v3(connected_vert_disp, vd.co, connected_vert_co);
+      normalize_v3(connected_vert_disp);
+      mul_v3_fl(connected_vert_disp, len_difference);
+      add_v3_v3(final_disp[vs], connected_vert_disp);
+    }
+    BLI_gsetIterator_free(gsi);
+    if (total > 0) {
+      mul_v3_fl(final_disp[vs], 1.0f / total);
+    }
+  }
+
+  BLI_gset_free(vert_gset[0], NULL);
+  BLI_gset_free(vert_gset[1], NULL);
+
+  float smooth_co[3];
+  float smooth_disp[3];
+  neighbor_average(ss, smooth_co, vert);
+  sub_v3_v3v3(smooth_disp, smooth_co, vd.co);
+  add_v3_v3v3(final_disp[0], final_disp[0], final_disp[1]);
+  copy_v3_v3(final_dp, final_disp[0]);
+  if (vert_map->count != 4) {
+    mul_v3_fl(final_disp[0], 0.5f);
+    mul_v3_fl(smooth_disp, 0.3f);
+    add_v3_v3(final_disp[0], smooth_disp);
+    copy_v3_v3(final_dp, final_disp[0]);
+  }
+}
 static void do_relax_brush_task_cb_ex(void *__restrict userdata,
                                       const int n,
                                       const ParallelRangeTLS *__restrict tls)
@@ -2346,7 +2452,6 @@ static void do_relax_brush_task_cb_ex(void *__restrict userdata,
   SculptSession *ss = data->ob->sculpt;
   Sculpt *sd = data->sd;
   const Brush *brush = data->brush;
-  const bool smooth_mask = data->smooth_mask;
   float bstrength = data->strength;
 
   PBVHVertexIter vd;
@@ -2368,100 +2473,14 @@ static void do_relax_brush_task_cb_ex(void *__restrict userdata,
                                             sqrtf(test.dist),
                                             vd.no,
                                             vd.fno,
-                                            smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f),
+                                            vd.mask ? *vd.mask : 0.0f,
                                             tls->thread_id);
 
-      float final_disp[2][3];
+      float final_disp[3];
       float final_pos[3];
-      int vert = vd.vert_indices[vd.i];
-      const MeshElemMap *vert_map = &ss->pmap[vert];
-      GSet *vert_gset[2];
-      vert_gset[0] = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "verts sets");
-      vert_gset[1] = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "verts sets");
-      BLI_gset_clear(vert_gset[0], NULL);
-      BLI_gset_clear(vert_gset[1], NULL);
-      float len_avg[2] = {0.0f};
-
-      for (int i = 0; i < vert_map->count; i++) {
-        const MPoly *p = &ss->mpoly[vert_map->indices[i]];
-        unsigned f_adj_v[2];
-        if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) {
-          if (vert_map->count > 1) {
-            if (i == 0) {
-              BLI_gset_add(vert_gset[0], &mvert[f_adj_v[0]]);
-              BLI_gset_add(vert_gset[1], &mvert[f_adj_v[1]]);
-            }
-            else if (BLI_gset_haskey(vert_gset[0], &mvert[f_adj_v[0]])) {
-              BLI_gset_add(vert_gset[1], &mvert[f_adj_v[1]]);
-            }
-            else if (BLI_gset_haskey(vert_gset[1], &mvert[f_adj_v[0]])) {
-              BLI_gset_add(vert_gset[0], &mvert[f_adj_v[1]]);
-            }
-            else if (BLI_gset_haskey(vert_gset[0], &mvert[f_adj_v[1]])) {
-              BLI_gset_add(vert_gset[1], &mvert[f_adj_v[0]]);
-            }
-            else if (BLI_gset_haskey(vert_gset[1], &mvert[f_adj_v[1]])) {
-              BLI_gset_add(vert_gset[0], &mvert[f_adj_v[0]]);
-            }
-          }
-        }
-      }
-
-      for (int vs = 0; vs < 2; vs++) {
-        int total = 0;
-        GSetIterator *gsi = BLI_gsetIterator_new(vert_gset[vs]);
-
-        for (BLI_gsetIterator_init(gsi, (GHash *)vert_gset[vs]); !BLI_gsetIterator_done(gsi);
-             BLI_gsetIterator_step(gsi)) {
-          MVert *c_vert = BLI_gsetIterator_getKey(gsi);
-          float connected_vert_co[3];
-          copy_v3_v3(connected_vert_co, c_vert->co);
-          len_avg[vs] += len_v3v3(vd.co, connected_vert_co);
-          total++;
-        }
-
-        BLI_gsetIterator_free(gsi);
-        if (total > 0) {
-          len_avg[vs] = len_avg[vs] / (float)total;
-        }
-        zero_v3(final_disp[vs]);
-
-        gsi = BLI_gsetIterator_new(vert_gset[vs]);
-
-        for (BLI_gsetIterator_init(gsi, (GHash *)vert_gset[vs]); !BLI_gsetIterator_done(gsi);
-             BLI_gsetIterator_step(gsi)) {
-          MVert *c_vert = BLI_gsetIterator_getKey(gsi);
-          float connected_vert_co[3];
-          float connected_vert_disp[3];
-          copy_v3_v3(connected_vert_co, c_vert->co);
-          float len = len_v3v3(vd.co, connected_vert_co);
-          float len_difference = len_avg[vs] - len;
-          sub_v3_v3v3(connected_vert_disp, vd.co, connected_vert_co);
-          normalize_v3(connected_vert_disp);
-          mul_v3_fl(connected_vert_disp, len_difference);
-          add_v3_v3(final_disp[vs], connected_vert_disp);
-        }
-        BLI_gsetIterator_free(gsi);
-        if (total > 0) {
-          mul_v3_fl(final_disp[vs], 1.0f / total);
-        }
-      }
-
-      BLI_gset_free(vert_gset[0], NULL);
-      BLI_gset_free(vert_gset[1], NULL);
-
-      float smooth_co[3];
-      float smooth_disp[3];
-      neighbor_average(ss, smooth_co, vert);
-      sub_v3_v3v3(smooth_disp, smooth_co, vd.co);
-      add_v3_v3v3(final_disp[0], final_disp[0], final_disp[1]);
-      madd_v3_v3v3fl(final_pos, vd.co, final_disp[0], fade);
-      if (vert_map->count != 4) {
-        mul_v3_fl(final_disp[0], 0.5f);
-        mul_v3_fl(smooth_disp, 0.3f);
-        add_v3_v3(final_disp[0], smooth_disp);
-        madd_v3_v3v3fl(final_pos, vd.co, smooth_disp, fade);
-      }
+      relax_vertex(final_disp, vd, ss, false);
+      copy_v3_v3(final_pos, vd.co);
+      madd_v3_v3fl(final_pos, final_disp, fade);
 
       sculpt_clip(sd, ss, vd.co, final_pos);
 
@@ -4305,9 +4324,8 @@ static void sculpt_topology_update(Sculpt *sd,
 
   int n, totnode;
   /* Build a list of all nodes that are potentially within the brush's area of influence */
-  const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ?
-                                true :
-                                ss->cache->original || ss->use_orco;
+  const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true :
+                                                                             ss->cache->original;
   const float radius_scale = 1.25f;
   PBVHNode **nodes = sculpt_pbvh_gather_generic(
       ob, sd, brush, use_original, radius_scale, &totnode);
@@ -4702,9 +4720,6 @@ static void do_brus

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list