[Bf-blender-cvs] [e557b2096ae] sculpt-dev: Sculpt: Fix topology rake updating original coordinates

Joseph Eagar noreply at git.blender.org
Tue Oct 5 09:17:51 CEST 2021


Commit: e557b2096ae19e07744173dc99caa2ad8a2e1de8
Author: Joseph Eagar
Date:   Tue Oct 5 00:17:15 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rBe557b2096ae19e07744173dc99caa2ad8a2e1de8

Sculpt: Fix topology rake updating original coordinates

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

M	source/blender/blenkernel/intern/brush_engine.c
M	source/blender/blenkernel/intern/brush_engine_presets.c
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_smooth.c
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index 47e3528e690..2accea81659 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -791,6 +791,8 @@ void BKE_brush_channelset_merge(BrushChannelSet *dst,
       continue;
     }
 
+    /*TODO: should inherit if unset should always apply, i.e. this block should be moved above the
+     * previous one?*/
     if (ch->type == BRUSH_CHANNEL_TYPE_BITMASK && (ch->flag & BRUSH_CHANNEL_INHERIT_IF_UNSET)) {
       mch->ivalue = ch->ivalue | pch->ivalue;
     }
@@ -1537,7 +1539,7 @@ void BKE_builtin_apply_hard_edge_mode(BrushChannelSet *chset, bool do_apply)
     ch->ivalue = 1;
   }
 
-  //turn off dyntopo surface smoothing
+  // turn off dyntopo surface smoothing
   ch = BRUSHSET_LOOKUP(chset, dyntopo_disable_smooth);
   if (ch) {
     ch->flag &= ~BRUSH_CHANNEL_INHERIT;
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index 4d1553a0e85..1cf4f2ab7d1 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -514,6 +514,7 @@ BrushFlagMap brush_flags_map[] =  {
   DEF(flag, use_plane_trim, BRUSH_PLANE_TRIM)
   DEF(flag2, use_surface_falloff, BRUSH_USE_SURFACE_FALLOFF)
   DEF(flag2, use_grab_active_vertex, BRUSH_GRAB_ACTIVE_VERTEX)
+  DEF(flag, accumulate, BRUSH_ACCUMULATE)
 };
 
 int brush_flags_map_len = ARRAY_SIZE(brush_flags_map);
@@ -1465,7 +1466,7 @@ void BKE_brush_builtin_create(Brush *brush, int tool)
       BRUSHSET_SET_FLOAT(chset, strength, 0.5);
       BRUSHSET_SET_FLOAT(chset, autosmooth, 0.05);
       BRUSHSET_SET_INT(chset, topology_rake_mode, 1);  // curvature mode
-      BRUSHSET_SET_FLOAT(chset, topology_rake, 0.35);
+      BRUSHSET_SET_FLOAT(chset, topology_rake, 0.5);
 
       BrushChannel *ch = BRUSHSET_LOOKUP(chset, dyntopo_mode);
       ch->flag &= ~BRUSH_CHANNEL_INHERIT;
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 38090abf9fc..f6615cd9833 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1512,7 +1512,7 @@ static void layerDynTopoVert_interp(
 {
   float co[3], no[3], origmask, color[4];
   MDynTopoVert *mv = (MDynTopoVert *)dest;
-  float totweight = 0.0f;
+  // float totweight = 0.0f;
 
   if (count == 0) {
     memset(mv, 0, sizeof(*mv));
@@ -1533,28 +1533,29 @@ static void layerDynTopoVert_interp(
       mv->stroke_id = mv2->stroke_id;
     }
 
-    if (sub_weights) {
-      w = sub_weights[i];
-    }
-    else {
-      w = 1.0f;
-    }
+    w = weights[i];
 
     madd_v3_v3fl(co, mv2->origco, w);
     madd_v3_v3fl(no, mv2->origno, w);
     madd_v4_v4fl(color, mv2->origcolor, w);
     origmask += mv2->origmask * w;
 
-    totweight += w;
+    // totweight += w;
   }
 
+  normalize_v3(no);
+
+#if 0
+  if (fabsf(totweight - 1.0) > 0.001) {
+    printf("eek\n");
+  }
   float mul = 1.0f / totweight;
 
   mul_v3_fl(co, mul);
-  normalize_v3(no);
 
   mul_v4_fl(color, mul);
   origmask *= mul;
+#endif
 
   copy_v3_v3(mv->origco, co);
   copy_v3_v3(mv->origno, no);
diff --git a/source/blender/blenkernel/intern/dyntopo.c b/source/blender/blenkernel/intern/dyntopo.c
index 20163fe0848..834652000a7 100644
--- a/source/blender/blenkernel/intern/dyntopo.c
+++ b/source/blender/blenkernel/intern/dyntopo.c
@@ -1980,9 +1980,9 @@ BLI_INLINE int dyntopo_thread_rand(int seed)
   return (seed * multiplier + addend) & mask;
 }
 
- static void long_edge_queue_task_cb(void *__restrict userdata,
-                                                const int n,
-                                                const TaskParallelTLS *__restrict tls)
+static void long_edge_queue_task_cb(void *__restrict userdata,
+                                    const int n,
+                                    const TaskParallelTLS *__restrict tls)
 {
   EdgeQueueThreadData *tdata = ((EdgeQueueThreadData *)userdata) + n;
   PBVHNode *node = tdata->node;
@@ -3930,7 +3930,13 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
     copy_v3_v3(v_conn->co, co);
   }
   else {
+    float co[3];
+
+    add_v3_v3v3(co, v_del->co, v_conn->co);
+    mul_v3_fl(co, 0.5f);
+
     BM_edge_collapse(pbvh->bm, e, v_del, true, true, true);
+    copy_v3_v3(v_conn->co, co);
   }
 
   for (int i = 0; i < BLI_array_len(delvs); i++) {
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 6975503c884..2f3e0d7b495 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -4476,7 +4476,7 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
       ss, &test, data->brush->falloff_shape);
   const int thread_id = BLI_task_parallel_thread_id(tls);
 
-  const bool use_curvature = ss->cache->brush->flag2 & BRUSH_CURVATURE_RAKE;
+  const bool use_curvature = data->use_curvature;
   int check_fsets = ss->cache->brush->flag2 & BRUSH_SMOOTH_PRESERVE_FACE_SETS;
   check_fsets = check_fsets ? SCULPT_BOUNDARY_FACE_SET : 0;
 
@@ -4542,39 +4542,55 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
     }
 #endif
 
-    int steps = data->do_origco ? 2 : 1;
+    // check origdata to be sure we don't mess it up
+    SCULPT_vertex_check_origdata(ss, vd.vertex);
 
-    for (int step = 0; step < steps; step++) {
-      float *co = step ? (float *)SCULPT_vertex_origco_get(ss, vd.vertex) : vd.co;
+    float *co = vd.co;
 
-      SCULPT_bmesh_four_neighbor_average(ss,
-                                         avg,
-                                         direction2,
-                                         vd.bm_vert,
-                                         data->rake_projection,
-                                         check_fsets,
-                                         data->cd_temp,
-                                         data->cd_dyn_vert,
-                                         step);
+    float oldco[3];
+    copy_v3_v3(oldco, co);
 
-      sub_v3_v3v3(val, avg, co);
-      madd_v3_v3v3fl(val, co, val, fade);
-      SCULPT_clip(sd, ss, co, val);
-    }
+    SCULPT_bmesh_four_neighbor_average(ss,
+                                       avg,
+                                       direction2,
+                                       vd.bm_vert,
+                                       data->rake_projection,
+                                       check_fsets,
+                                       data->cd_temp,
+                                       data->cd_dyn_vert,
+                                       0);
+
+    sub_v3_v3v3(val, avg, co);
+
+    float tan[3];
+    copy_v3_v3(tan, val);
+    madd_v3_v3fl(tan, vd.bm_vert->no, -dot_v3v3(tan, vd.bm_vert->no));
+
+    MDynTopoVert *mv = BKE_PBVH_DYNVERT(ss->cd_dyn_vert, vd.bm_vert);
+    madd_v3_v3v3fl(mv->origco, mv->origco, tan, fade * 0.5);
+
+    madd_v3_v3v3fl(val, co, val, fade);
+    SCULPT_clip(sd, ss, co, val);
 
     if (vd.mvert) {
       vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
     }
   }
   BKE_pbvh_vertex_iter_end;
+
+  BKE_pbvh_node_mark_normals_update(data->nodes[n]);
 }
 
-static void bmesh_topology_rake(
-    Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength)
+static void bmesh_topology_rake(Sculpt *sd,
+                                Object *ob,
+                                PBVHNode **nodes,
+                                const int totnode,
+                                float bstrength,
+                                bool needs_origco)
 {
   SculptSession *ss = ob->sculpt;
   Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
-  const float strength = clamp_f(bstrength, 0.0f, 1.0f);
+  const float strength = bstrength;  // clamp_f(bstrength, 0.0f, 1.0f);
 
   Brush local_brush;
 
@@ -4632,23 +4648,26 @@ static void bmesh_topology_rake(
 
   int iteration;
   const int count = iterations * strength + 1;
-  const float factor = iterations * strength / count;
+  const float factor = iterations * strength / count * 0.25;
 
   for (iteration = 0; iteration <= count; iteration++) {
 
-    SculptThreadedTaskData data = {.sd = sd,
-                                   .ob = ob,
-                                   .brush = brush,
-                                   .nodes = nodes,
-                                   .strength = factor,
-                                   .cd_temp = cd_temp,
-                                   .cd_dyn_vert = ss->cd_dyn_vert,
-                                   .rake_projection = brush->topology_rake_projection,
-                                   .do_origco = SCULPT_stroke_needs_original(brush)};
+    SculptThreadedTaskData data = {
+        .sd = sd,
+        .ob = ob,
+        .brush = brush,
+        .nodes = nodes,
+        .strength = factor,
+        .cd_temp = cd_temp,
+        .use_curvature = SCULPT_get_int(ss, topology_rake_mode, sd, brush),
+        .cd_dyn_vert = ss->cd_dyn_vert,
+        .rake_projection = brush->topology_rake_projection,
+        .do_origco = needs_origco};
     TaskParallelSettings settings;
     BKE_pbvh_parallel_range_settings(&settings, true, totnode);
 
     BLI_task_parallel_range(0, totnode, &data, do_topology_rake_bmesh_task_cb_ex, &settings);
+    BKE_pbvh_update_normals(ss->pbvh, ss->subdiv_ccg);
   }
 }
 
@@ -7471,6 +7490,8 @@ static void do_clay_brush_task_cb_ex(void *__restrict userdata,
       continue;
     }
 
+    SCULPT_vertex_check_origdata(ss, vd.vertex);
+
     float intr[3];
     float val[3];
     closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co);
@@ -8965,7 +8986,14 @@ void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings
       break;
     case SCULPT_TOOL_SMOOTH:
       if (brush->smooth_deform_type == BRUSH_SMOOTH_DEFORM_LAPLACIAN) {
-        SCULPT_do_smooth_brush(sd, ob, nodes, totnode, brush->autosmooth_projection);
+        SCULPT_do_smooth_brush(
+            sd,
+            ob,
+            nodes,
+            totnode,
+            brush->au

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list