[Bf-blender-cvs] [0dc09668ce9] temp_bmesh_multires: Finished curvature rake.

Joseph Eagar noreply at git.blender.org
Thu Apr 1 22:07:43 CEST 2021


Commit: 0dc09668ce94505d8b140e85bb604b1cf37a1c6f
Author: Joseph Eagar
Date:   Thu Apr 1 13:07:10 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB0dc09668ce94505d8b140e85bb604b1cf37a1c6f

Finished curvature rake.

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_curvature.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index bd8cca847e5..983f9ae9121 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -574,6 +574,8 @@ def brush_settings(layout, context, brush, popover=False):
                 context.sculpt_object.use_dynamic_topology_sculpting
         ):
             layout.prop(brush, "topology_rake_factor", slider=True)
+            layout.prop(brush, "use_curvature_rake")
+
             layout.prop(brush.dyntopo, "disabled", text="Disable Dyntopo");
             
         # normal_weight
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 146eb3208e9..b5a7965161a 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -174,7 +174,8 @@ typedef enum {
 
   PBVH_UpdateTopology = 1 << 13,
   PBVH_UpdateColor = 1 << 14,
-  PBVH_Delete = 1 << 15
+  PBVH_Delete = 1 << 15,
+  PBVH_UpdateCurvatureDir = 1<<16
 } PBVHNodeFlags;
 
 typedef struct PBVHFrustumPlanes {
@@ -653,6 +654,9 @@ void BKE_pbvh_set_flat_vcol_shading(PBVH *pbvh, bool value);
 
 void SCULPT_update_flat_vcol_shading(struct Object *ob, struct Scene *scene);
 
+void BKE_pbvh_curvature_update_set(PBVHNode *node, bool state);
+bool BKE_pbvh_curvature_update_get(PBVHNode *node);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 9ee8bc43de4..acde53509ae 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1823,7 +1823,7 @@ BMesh *BKE_pbvh_get_bmesh(PBVH *pbvh)
 void BKE_pbvh_node_mark_update(PBVHNode *node)
 {
   node->flag |= PBVH_UpdateNormals | PBVH_UpdateBB | PBVH_UpdateOriginalBB |
-                PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw;
+                PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw | PBVH_UpdateCurvatureDir;
 }
 
 void BKE_pbvh_node_mark_update_mask(PBVHNode *node)
@@ -1839,12 +1839,13 @@ void BKE_pbvh_node_mark_update_color(PBVHNode *node)
 void BKE_pbvh_node_mark_update_visibility(PBVHNode *node)
 {
   node->flag |= PBVH_UpdateVisibility | PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers |
-                PBVH_UpdateRedraw;
+                PBVH_UpdateRedraw | PBVH_UpdateCurvatureDir;
 }
 
 void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node)
 {
-  node->flag |= PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw;
+  node->flag |= PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw |
+                PBVH_UpdateCurvatureDir;
 }
 
 void BKE_pbvh_node_mark_redraw(PBVHNode *node)
@@ -1854,7 +1855,23 @@ void BKE_pbvh_node_mark_redraw(PBVHNode *node)
 
 void BKE_pbvh_node_mark_normals_update(PBVHNode *node)
 {
-  node->flag |= PBVH_UpdateNormals;
+  node->flag |= PBVH_UpdateNormals | PBVH_UpdateCurvatureDir;
+}
+
+void BKE_pbvh_node_mark_curvature_update(PBVHNode *node) {
+  node->flag |= PBVH_UpdateCurvatureDir;
+}
+
+void BKE_pbvh_curvature_update_set(PBVHNode *node, bool state) {
+  if (state) {
+    node->flag |= PBVH_UpdateCurvatureDir;
+  } else {
+    node->flag &= ~PBVH_UpdateCurvatureDir;
+  }
+}
+
+bool BKE_pbvh_curvature_update_get(PBVHNode *node) {
+  return node->flag & PBVH_UpdateCurvatureDir;
 }
 
 void BKE_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden)
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index f1d2464d278..c51f5600d2c 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -310,7 +310,7 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
   BKE_pbvh_node_mark_rebuild_draw(n);
 
   BKE_pbvh_node_fully_hidden_set(n, !has_visible);
-  n->flag |= PBVH_UpdateNormals | PBVH_UpdateTopology;
+  n->flag |= PBVH_UpdateNormals | PBVH_UpdateTopology | PBVH_UpdateCurvatureDir;
 
   if (add_orco) {
     BKE_pbvh_bmesh_node_save_ortri(pbvh->bm, n);
@@ -2839,6 +2839,8 @@ static void pbvh_update_normals_task_cb(void *__restrict userdata,
   UpdateNormalsTaskData *data = (UpdateNormalsTaskData *)userdata;
   PBVHNode *node = data->nodes[n];
 
+  node->flag |= PBVH_UpdateCurvatureDir;
+
   TGSET_ITER (f, node->bm_faces) {
     BM_face_normal_update(f);
   }
@@ -3092,7 +3094,7 @@ static void pbvh_bmesh_create_nodes_fast_recursive(
     BKE_pbvh_node_mark_rebuild_draw(n);
 
     BKE_pbvh_node_fully_hidden_set(n, !has_visible);
-    n->flag |= PBVH_UpdateNormals;
+    n->flag |= PBVH_UpdateNormals|PBVH_UpdateCurvatureDir;
   }
 }
 
@@ -3232,6 +3234,7 @@ bool BKE_pbvh_bmesh_update_topology_nodes(PBVH *pbvh,
     }
 
     if (node->flag & PBVH_Leaf) {
+      node->flag |= PBVH_UpdateCurvatureDir;
       undopush(node, searchdata);
 
       BKE_pbvh_node_mark_topology_update(pbvh->nodes + i);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index c8ea07c0cfa..36b8a11b255 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3257,6 +3257,7 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
   SculptSession *ss = data->ob->sculpt;
   Sculpt *sd = data->sd;
   const Brush *brush = data->brush;
+  PBVHNode *node = data->nodes[n];
 
   float direction[3];
   copy_v3_v3(direction, ss->cache->grab_delta_symmetry);
@@ -3279,8 +3280,14 @@ 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 update_curvature = node->flag & PBVH_UpdateCurvatureDir;
+  const bool update_curvature = BKE_pbvh_curvature_update_get(node);
+
+  SCULPT_curvature_begin(ss, node);
+
   PBVHVertexIter vd;
-  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
+  BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
     if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
       continue;
     }
@@ -3294,10 +3301,14 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
 
     float avg[3], val[3];
 
-    // SculptCurvatureData cdata;
-    // SCULPT_calc_principle_curvatures(ss, vd.vertex, &cdata);
-    // copy_v3_v3(direction2, cdata.principle[0]);
-    copy_v3_v3(direction2, direction);
+    if (use_curvature) {
+      SCULPT_curvature_dir_get(ss, vd.vertex, direction2);
+      //SculptCurvatureData cdata;
+      //SCULPT_calc_principle_curvatures(ss, vd.vertex, &cdata);
+      //copy_v3_v3(direction2, cdata.principle[0]);
+    } else {
+      copy_v3_v3(direction2, direction);
+    }
 
     SCULPT_bmesh_four_neighbor_average(avg, direction2, vd.bm_vert);
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_curvature.c b/source/blender/editors/sculpt_paint/sculpt_curvature.c
index 82c46538317..411994d4da1 100644
--- a/source/blender/editors/sculpt_paint/sculpt_curvature.c
+++ b/source/blender/editors/sculpt_paint/sculpt_curvature.c
@@ -160,7 +160,7 @@ bool SCULPT_calc_principle_curvatures(SculptSession *ss,
   SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
 
   if (true || !BLI_eigen_solve_selfadjoint_m3(nmat, out->ks, out->principle)) {
-    //do simple power solve in one direction
+    // do simple power solve in one direction
 
     float t[3];
     float t2[3];
@@ -191,3 +191,44 @@ bool SCULPT_calc_principle_curvatures(SculptSession *ss,
 
   return true;
 }
+
+void SCULPT_curvature_dir_get(SculptSession *ss, SculptVertRef v, float dir[3])
+{
+  if (BKE_pbvh_type(ss->pbvh) != PBVH_BMESH) {
+    SculptCurvatureData curv;
+    SCULPT_calc_principle_curvatures(ss, v, &curv);
+
+    copy_v3_v3(dir, curv.principle[0]);
+    return;
+  }
+
+  BMVert *bv = (BMVert *)v.i;
+  MDynTopoVert *mv = BKE_PBVH_DYNVERT(ss->cd_dyn_vert, bv);
+
+  copy_v3_v3(dir, mv->curvature_dir);
+}
+
+void SCULPT_curvature_begin(SculptSession *ss, struct PBVHNode *node)
+{
+  if (BKE_pbvh_type(ss->pbvh) != PBVH_BMESH) {
+    // caching only happens for bmesh for now
+    return;
+  }
+
+  if (BKE_pbvh_curvature_update_get(node)) {
+    PBVHVertexIter vi;
+
+    BKE_pbvh_curvature_update_set(node, false);
+
+    BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vi, PBVH_ITER_UNIQUE) {
+      BMVert *v = (BMVert *)vi.vertex.i;
+      MDynTopoVert *mv = BKE_PBVH_DYNVERT(ss->cd_dyn_vert, v);
+
+      SculptCurvatureData curv;
+      SCULPT_calc_principle_curvatures(ss, vi.vertex, &curv);
+
+      copy_v3_v3(mv->curvature_dir, curv.principle[0]);
+    }
+    BKE_pbvh_vertex_iter_end;
+  }
+}
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 91fc4956dd9..d1e55d7d51c 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1422,3 +1422,5 @@ bool SCULPT_calc_principle_curvatures(SculptSession *ss,
                                       SculptVertRef vertex,
                                       SculptCurvatureData *out);
 
+void SCULPT_curvature_begin(SculptSession *ss, struct PBVHNode *node);
+void SCULPT_curvature_dir_get(SculptSession *ss, SculptVertRef v, float dir[3]);
diff --git a/source/blender/makesdna/DNA_brush_enums.h b/source/blender/makesdna/DNA_brush_enums.h
index bb596bcbc3f..228e14282cb 100644
--- a/source/blender/makesdna/DNA_brush_enums.h
+++ b/source/blender/makesdna/DNA_brush_enums.h
@@ -409,6 +409,7 @@ typedef enum eBrushFlags2 {
   BRUSH_CLOTH_USE_COLLISION = (1 << 6),
   BRUSH_AREA_RADIUS_PRESSURE = (1 << 7),
   BRUSH_GRAB_SILHOUETTE = (1 << 8),
+  BRUSH_CURVATURE_RAKE = (1 << 9)
 } eBrushFlags2;
 
 typedef enum {
diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h
index 7320bcecc3d..4acf53bb710 100644
--- a/source/blender/makesdna/DNA_meshdata_types.h
+++ b/source/blender/makesdna/DNA_meshdata_types.h
@@ -535,6 +535,7 @@ typedef struct MDynTopoVert {
   float origcolor[4];
 
   float origmask;
+  float curvature_dir[3];
 } MDynTopoVert;
 
 /*MDynTopoV

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list