Sculpt: Refactor persistent base to make it usable from other tools
authorPablo Dobarro <pablodp606@gmail.com>
Thu, 11 Jun 2020 18:15:57 +0000 (20:15 +0200)
committerPablo Dobarro <pablodp606@gmail.com>
Tue, 30 Jun 2020 20:02:17 +0000 (22:02 +0200)
This renames the layer persistent base and adds new API functions to get
the mesh state from the base, so it can be used from other tools and
replaced in the future with a better system.

Reviewed By: sergey

Maniphest Tasks: T77738

Differential Revision: https://developer.blender.org/D8003

source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/paint.c
source/blender/editors/sculpt_paint/sculpt.c

index c36e9f6961f9fda5c55cb63d93e4e9638eaee0d9..f88d1a1ee409b6b440f3da11e2067d6f3bed29c7 100644 (file)
@@ -283,11 +283,11 @@ typedef struct SculptClothSimulation {
 
 } SculptClothSimulation;
 
-typedef struct SculptLayerPersistentBase {
+typedef struct SculptPersistentBase {
   float co[3];
   float no[3];
   float disp;
-} SculptLayerPersistentBase;
+} SculptPersistentBase;
 
 typedef struct SculptVertexInfo {
   /* Idexed by vertex, stores and ID of its topologycally connected component. */
@@ -392,9 +392,9 @@ typedef struct SculptSession {
   float pose_origin[3];
   SculptPoseIKChain *pose_ik_chain_preview;
 
-  /* Layer brush persistence between strokes */
+  /* Mesh State Persistence */
   /* This is freed with the PBVH, so it is always in sync with the mesh. */
-  SculptLayerPersistentBase *layer_base;
+  SculptPersistentBase *persistent_base;
 
   SculptVertexInfo vertex_info;
   SculptFakeNeighbors fake_neighbors;
index f0026ec58dc936172dbd4d80ea57f96b4d712a1b..b3ab856468c9c454ab86256e10081799cf9c1b2f 100644 (file)
@@ -1310,7 +1310,7 @@ static void sculptsession_free_pbvh(Object *object)
   MEM_SAFE_FREE(ss->pmap);
   MEM_SAFE_FREE(ss->pmap_mem);
 
-  MEM_SAFE_FREE(ss->layer_base);
+  MEM_SAFE_FREE(ss->persistent_base);
 
   MEM_SAFE_FREE(ss->preview_vert_index_list);
   ss->preview_vert_index_count = 0;
index d414d6d8f0f47b1b45962d1da47a4cb51b4a055c..a753b7b4c26c3cb1c39aac3c8040fbc55616f50d 100644 (file)
@@ -198,6 +198,23 @@ void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3])
   }
 }
 
+const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index)
+{
+  if (ss->persistent_base) {
+    return ss->persistent_base[index].co;
+  }
+  return SCULPT_vertex_co_get(ss, index);
+}
+
+void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3])
+{
+  if (ss->persistent_base) {
+    copy_v3_v3(no, ss->persistent_base[index].no);
+    return;
+  }
+  SCULPT_vertex_normal_get(ss, index, no);
+}
+
 float SCULPT_vertex_mask_get(SculptSession *ss, int index)
 {
   BMVert *v;
@@ -4136,7 +4153,7 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
   Sculpt *sd = data->sd;
   const Brush *brush = data->brush;
 
-  const bool use_persistent_base = ss->layer_base && brush->flag & BRUSH_PERSISTENT;
+  const bool use_persistent_base = ss->persistent_base && brush->flag & BRUSH_PERSISTENT;
 
   PBVHVertexIter vd;
   SculptOrigVertData orig_data;
@@ -4166,7 +4183,7 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
       const int vi = vd.index;
       float *disp_factor;
       if (use_persistent_base) {
-        disp_factor = &ss->layer_base[vi].disp;
+        disp_factor = &ss->persistent_base[vi].disp;
       }
       else {
         disp_factor = &ss->cache->layer_displacement_factor[vi];
@@ -4196,9 +4213,9 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
       float normal[3];
 
       if (use_persistent_base) {
-        copy_v3_v3(normal, ss->layer_base[vi].no);
+        SCULPT_vertex_persistent_normal_get(ss, vi, normal);
         mul_v3_fl(normal, brush->height);
-        madd_v3_v3v3fl(final_co, ss->layer_base[vi].co, normal, *disp_factor);
+        madd_v3_v3v3fl(final_co, SCULPT_vertex_persistent_co_get(ss, vi), normal, *disp_factor);
       }
       else {
         normal_short_to_float_v3(normal, orig_data.no);
@@ -7457,16 +7474,16 @@ static int sculpt_set_persistent_base_exec(bContext *C, wmOperator *UNUSED(op))
     SCULPT_vertex_random_access_init(ss);
     BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false, false);
 
-    MEM_SAFE_FREE(ss->layer_base);
+    MEM_SAFE_FREE(ss->persistent_base);
 
     const int totvert = SCULPT_vertex_count_get(ss);
-    ss->layer_base = MEM_mallocN(sizeof(SculptLayerPersistentBase) * totvert,
-                                 "layer persistent base");
+    ss->persistent_base = MEM_mallocN(sizeof(SculptPersistentBase) * totvert,
+                                      "layer persistent base");
 
     for (int i = 0; i < totvert; i++) {
-      copy_v3_v3(ss->layer_base[i].co, SCULPT_vertex_co_get(ss, i));
-      SCULPT_vertex_normal_get(ss, i, ss->layer_base[i].no);
-      ss->layer_base[i].disp = 0.0f;
+      copy_v3_v3(ss->persistent_base[i].co, SCULPT_vertex_co_get(ss, i));
+      SCULPT_vertex_normal_get(ss, i, ss->persistent_base[i].no);
+      ss->persistent_base[i].disp = 0.0f;
     }
   }