[Bf-blender-cvs] [792b39e193e] sculpt-dev: Sculpt-dev: cleanup SCULPT_neighbor_coords_average_interior

Joseph Eagar noreply at git.blender.org
Sat Dec 11 22:11:49 CET 2021


Commit: 792b39e193ee1b2073d18ee190d3cb79eec1efdd
Author: Joseph Eagar
Date:   Sat Dec 11 13:10:44 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rB792b39e193ee1b2073d18ee190d3cb79eec1efdd

Sculpt-dev: cleanup SCULPT_neighbor_coords_average_interior

* The "boundary smooth" (psuedo-bevel) functionality of
  SCULPT_neighbor_coords_average_interior is now its
  own function.
* Fixed a few more pedantic gcc errors.

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

M	source/blender/blenkernel/intern/bassrelief.cc
M	source/blender/editors/sculpt_paint/sculpt_smooth.c
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/bassrelief.cc b/source/blender/blenkernel/intern/bassrelief.cc
index 5bfbda72cbe..e792874bf33 100644
--- a/source/blender/blenkernel/intern/bassrelief.cc
+++ b/source/blender/blenkernel/intern/bassrelief.cc
@@ -112,7 +112,7 @@ namespace bassrelief {
 struct ReliefVertex {
   float co[3], origco[3];
   float no[3], origno[3];
-  int index;
+  uint index;
   float targetco[3];
   float targetno[3];
   float ray[3], ray_dist, origray[3], origray_dist;
@@ -148,23 +148,23 @@ struct ReliefOptimizer {
   float normalScale, boundWidth;
 
   ReliefOptimizer(const float (*cos)[3],
-                  const MVert *mvert,
-                  int totvert,
-                  MEdge *medge,
-                  int totedge,
+                  const MVert *mvert_,
+                  int totvert_,
+                  MEdge *medge_,
+                  int totedge_,
                   MPropCol *_debugColors[MAX_BASSRELIEF_DEBUG_COLORS],
                   const MLoopTri *_mlooptri,
-                  int totlooptri,
-                  const MLoop *mloop,
+                  int totlooptri_,
+                  const MLoop *mloop_,
                   float optimizeNormalsScale,
-                  float boundSmoothScale,
-                  int boundSmoothSteps)
-      : totvert(totvert),
-        totlooptri(totlooptri),
-        mloop(mloop),
-        boundSmoothSteps(boundSmoothSteps),
+                  float boundSmoothScale_,
+                  int boundSmoothSteps_)
+      : totvert(totvert_),
+        totlooptri(totlooptri_),
+        mloop(mloop_),
+        boundSmoothSteps(boundSmoothSteps_),
         normalScale(optimizeNormalsScale),
-        boundWidth(boundSmoothScale)
+        boundWidth(boundSmoothScale_)
   {
     rmindis = rmaxdis = bmindis = bmaxdis = 0.0f;
     rdis_scale = bdis_scale = 0.0f;
@@ -185,10 +185,10 @@ struct ReliefOptimizer {
     verts = new ReliefVertex[totvert];
     compress_ratio = 0.5f;
 
-    const MVert *mv = mvert;
+    const MVert *mv = mvert_;
     ReliefVertex *rv = verts;
 
-    for (int i = 0; i < totvert; i++, rv++, mv++) {
+    for (uint i = 0; i < (uint)totvert; i++, rv++, mv++) {
       memset(static_cast<void *>(rv), 0, sizeof(ReliefVertex));
 
       copy_v3_v3(rv->co, cos[i]);
@@ -213,8 +213,8 @@ struct ReliefOptimizer {
       rv->flag = 0;
     }
 
-    const MEdge *me = medge;
-    for (int i = 0; i < totedge; i++, me++) {
+    const MEdge *me = medge_;
+    for (int i = 0; i < totedge_; i++, me++) {
       verts[me->v1].totneighbor++;
       verts[me->v2].totneighbor++;
     }
@@ -227,8 +227,8 @@ struct ReliefOptimizer {
           BLI_memarena_alloc(arena, sizeof(float) * rv->totneighbor * 2));
     }
 
-    me = medge;
-    for (int i = 0; i < totedge; i++, me++) {
+    me = medge_;
+    for (int i = 0; i < totedge_; i++, me++) {
       for (int j = 0; j < 2; j++) {
         ReliefVertex *rv = j ? verts + me->v2 : verts + me->v1;
         ReliefVertex *rv_other = j ? verts + me->v1 : verts + me->v2;
@@ -579,7 +579,7 @@ struct ReliefOptimizer {
 
   void smooth_geodesic()
   {
-    std::vector<float> dists(totvert);
+    std::vector<float> dists((size_t)totvert);
 
     blender::threading::parallel_for(IndexRange(totvert), 512, [&](IndexRange subrange) {
       for (auto i : subrange) {
@@ -619,7 +619,7 @@ struct ReliefOptimizer {
 
   void smooth_tangent_field()
   {
-    std::vector<float> dists(totvert);
+    std::vector<float> dists((size_t)totvert);
 
     blender::threading::parallel_for(IndexRange(totvert), 512, [&](IndexRange subrange) {
       for (auto i : subrange) {
diff --git a/source/blender/editors/sculpt_paint/sculpt_smooth.c b/source/blender/editors/sculpt_paint/sculpt_smooth.c
index 4b6fe89f2ab..e199ce6d834 100644
--- a/source/blender/editors/sculpt_paint/sculpt_smooth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_smooth.c
@@ -397,16 +397,11 @@ MINLINE float safe_shell_angle_to_dist(const float angle)
   return (UNLIKELY(angle < 1.e-8f)) ? 1.0f : fabsf(1.0f / th);
 }
 
-void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
-                                             float result[3],
-                                             SculptVertRef vertex,
-                                             SculptSmoothArgs *args)
+static void SCULPT_neighbor_coords_average_interior_boundary(SculptSession *ss,
+                                                             float result[3],
+                                                             SculptVertRef vertex,
+                                                             SculptSmoothArgs *args)
 {
-  if (args->do_origco) {
-    // copy_v3_v3(result, SCULPT_vertex_co_get(ss, vertex));
-    // return;
-  }
-
   float avg[3] = {0.0f, 0.0f, 0.0f};
 
   const float bevel_smooth_factor = 1.0f - args->bevel_smooth_factor;
@@ -467,39 +462,32 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
 
   // bool have_bmesh = ss->bm;
 
-  if (weighted || bound_scl) {
-    int val = SCULPT_vertex_valence_get(ss, vertex);
-    areas = BLI_array_alloca(areas, val);
+  int val = SCULPT_vertex_valence_get(ss, vertex);
+  areas = BLI_array_alloca(areas, val);
 
-    BKE_pbvh_get_vert_face_areas(ss->pbvh, vertex, areas, val);
+  BKE_pbvh_get_vert_face_areas(ss->pbvh, vertex, areas, val);
 
-    /* normalize areas, then apply a 0.25/val floor */
+  /* normalize areas, then apply a 0.25/val floor */
 
-    float totarea = 0.0f;
+  float totarea = 0.0f;
 
-    for (int i = 0; i < val; i++) {
-      totarea += areas[i];
-    }
+  for (int i = 0; i < val; i++) {
+    totarea += areas[i];
+  }
 
-    totarea = totarea != 0.0f ? 1.0f / totarea : 0.0f;
+  totarea = totarea != 0.0f ? 1.0f / totarea : 0.0f;
 
-    float df = 0.25f / (float)val;
+  float df = 0.25f / (float)val;
 
-    for (int i = 0; i < val; i++) {
-      areas[i] = (areas[i] * totarea) + df;
-    }
+  for (int i = 0; i < val; i++) {
+    areas[i] = (areas[i] * totarea) + df;
   }
 
   float *b1 = NULL, btot = 0.0f, b1_orig;
 
-  if (bound_scl) {
-    b1 = SCULPT_temp_cdata_get(vertex, bound_scl);
-    b1_orig = *b1;
-
-    if (1 || is_boundary) {
-      *b1 = 0.0f;
-    }
-  }
+  b1 = SCULPT_temp_cdata_get(vertex, bound_scl);
+  b1_orig = *b1;
+  *b1 = 0.0f;
 
   float vel[3] = {0.0f, 0.0f, 0.0f};
   int totvel = 0;
@@ -509,13 +497,6 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
     MSculptVert *mv2 = SCULPT_vertex_get_sculptvert(ss, ni.vertex);
     const float *co2;
 
-    if (args->vel_scl) {
-      // propagate velocities
-      float *vel2 = SCULPT_temp_cdata_get(ni.vertex, args->vel_scl);
-      add_v3_v3(vel, vel2);
-      totvel++;
-    }
-
     if (!do_origco || mv2->stroke_id != ss->stroke_id) {
       co2 = SCULPT_vertex_co_get(ss, ni.vertex);
     }
@@ -562,12 +543,7 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
     do_diffuse = bound_scl != NULL;
 
     if (final_boundary) {
-      if (totbound == 0) {
-        copy_v3_v3(bound1, co2);
-      }
-      else {
-        copy_v3_v3(bound2, co2);
-      }
+      copy_v3_v3(!totbound ? bound1 : bound2, co2);
 
       totbound++;
     }
@@ -661,11 +637,6 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
       SCULPT_vertex_color_set(ss, ni.vertex, color);
 #endif
 
-      /* jump above the v,no2 plane, using distance from plane (which doubles after this)*/
-      // sub_v3_v3(tmp, co);
-      // madd_v3_v3fl(tmp, no2, th * dot_v3v3(no2, tmp));
-      // add_v3_v3(tmp, co);
-
       float th = min_ff(b1_orig / radius, bevel_smooth_factor);
 
       /*smooth bevel edges slightly to avoid artifacts.
@@ -702,7 +673,6 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
 
   if (btot != 0.0f) {
     *b1 /= btot;
-    //*b1 += (b1_orig - *b1) * 0.95f;
   }
   else if (b1) {
     *b1 = b1_orig;
@@ -720,24 +690,9 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
     cross_v3_v3v3(tan, bound, no);
     normalize_v3(tan);
 
-#if 0
-    float tan1[3],tan2[3];
-    cross_v3_v3v3(tan1,bound1,no);
-    cross_v3_v3v3(tan2,bound2,no);
-
-    normalize_v3(tan1);
-    normalize_v3(tan2);
-
-    interp_v3_v3v3(tan1,tan1,tan,0.5f);
-    interp_v3_v3v3(tan2,tan2,tan,0.5f);
-
-    madd_v3_v3fl(avg,tan1,-dot_v3v3(bound1,tan) * 0.975);
-    madd_v3_v3fl(avg,tan2,dot_v3v3(bound2,tan) * 0.975);
-#else
     // project to plane, remember we negated bound2 earlier
     madd_v3_v3fl(avg, tan, -dot_v3v3(bound1, tan) * 0.75);
     madd_v3_v3fl(avg, tan, dot_v3v3(bound2, tan) * 0.75);
-#endif
   }
 
   if (args->vel_scl && totvel > 1) {
@@ -777,7 +732,7 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
   }
 
   if (c & (SCULPT_CORNER_FACE_SET | SCULPT_CORNER_SEAM | SCULPT_CORNER_UV)) {
-    corner_smooth = MAX2(slide_fset, bound_smooth);
+    corner_smooth = MAX2(slide_fset, 2.0f * bound_smooth);
   }
   else {
     corner_smooth = 2.0f * bound_smooth;
@@ -787,6 +742,267 @@ void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
   PBVH_CHECK_NAN(co);
 }
 
+void SCULPT_neighbor_coords_average_interior(SculptSession *ss,
+                                             float result[3],
+                                             SculptVertRef vertex,
+                                             SculptSmoothArgs *args)
+{
+  if (args->bound_smooth > 0.0f && args->bound_scl) {
+    SCULPT_neighbor_coords_average_interior_boundary(ss, result, vertex, args);
+    return;
+  }
+
+  float avg[3] = {0.0f, 0.0f, 0.0f};
+
+  float projection = args->projection;
+  float slide_fset = args->slide_fset;
+  float bound_smooth = args->bound_smooth;
+  bool do_origco = args->do_origco;
+
+  MSculptVert *mv = SCULPT_vertex_get_sculptvert(ss, vertex);
+
+  float bound1[3], bound2[3];
+  int totbound = 0;
+
+  if (do_origco) {
+    SCULPT_vertex_check_origdata(ss, vertex);
+  }
+
+  float total = 0.0f;
+  int neighbor_count = 0;
+  bool check_fsets = args->preserve_fset_boundaries;
+
+  int bflag = SCULPT_BOUNDARY_MESH | SCULPT_BOUNDARY_SHARP;
+
+  slide_fset = MAX2(slide_fset, bound_smooth);
+
+  if (check_fsets) {
+    bflag |= SCULPT_BOUNDARY_FACE_SET | SCULPT_BOUNDARY_SEAM | SCULPT_BOUNDARY_UV;
+  }
+
+  const Sc

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list