[Bf-blender-cvs] [55415cd62a7] temp_bmesh_multires: * Layer brush now supports dyntopo. - To do this I made a little API to make scratch customdata layers: SCULPT_dyntopo_[ensure/get]_templayer. Takes a customdata type and a layer name (e.g. '__dyntopo_bleh") and returns a customdata offset. - Note that I also did this for the persistent base code.

Joseph Eagar noreply at git.blender.org
Wed Apr 7 10:26:51 CEST 2021


Commit: 55415cd62a78f712329574bae3b6e43657d690de
Author: Joseph Eagar
Date:   Wed Apr 7 01:20:21 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB55415cd62a78f712329574bae3b6e43657d690de

* Layer brush now supports dyntopo.
  - To do this I made a little API to make scratch
    customdata layers: SCULPT_dyntopo_[ensure/get]_templayer.
    Takes a customdata type and a layer name (e.g.
    '__dyntopo_bleh") and returns a customdata offset.
  - Note that I also did this for the persistent base code.

* Added a macro to check if a tool supports splitting the PBVH
  during a stroke, DYNTOPO_HAS_DYNAMIC_SPLIT.  It is in sculpt_intern.h
  (for now) to avoid the enormous amount of recompiling that is
  triggered if DNA_brush_enum.h is modified.

* TODO: Right now the undo code resets original vertex coordinates for
  bmesh PBVH.  This means tools that rely on original data (sharp and
  layer) can't split the pbvh during the stroke, since that will
  allocate new undo nodes and reset original coords.

  The solution is to move the original data API entirely out of the undo
  code.

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/bmesh/intern/bmesh_log.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.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

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 41c58bc5469..66ffb6541ea 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -343,6 +343,11 @@ typedef struct SculptClothSimulation {
   /** #PBVHNode pointer as a key, index in #SculptClothSimulation.node_state as value. */
   struct GHash *node_state_index;
   eSculptClothNodeSimState *node_state;
+
+  //persistent base customdata layer offsets
+  int cd_pers_co;
+  int cd_pers_no;
+  int cd_pers_disp;
 } SculptClothSimulation;
 
 typedef struct SculptPersistentBase {
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index efb417f806f..045d8b5db53 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -658,6 +658,8 @@ 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);
 
+int BKE_pbvh_get_totnodes(PBVH *pbvh);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index e37a12841ee..f79ebf23181 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1385,6 +1385,7 @@ static void sculptsession_bm_to_me_update_data_only(Object *ob, bool reorder)
       BM_ITER_MESH (efa, &iter, ss->bm, BM_FACES_OF_MESH) {
         BM_elem_flag_set(efa, BM_ELEM_SMOOTH, ss->bm_smooth_shading);
       }
+
       if (reorder) {
         BM_log_mesh_elems_reorder(ss->bm, ss->bm_log);
       }
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index a890634e158..8d44655e59c 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -3240,6 +3240,10 @@ int BKE_pbvh_get_node_index(PBVH *pbvh, PBVHNode *node)
   return (int)(node - pbvh->nodes);
 }
 
+int BKE_pbvh_get_totnodes(PBVH *pbvh) {
+  return pbvh->totnode;
+}
+
 int BKE_pbvh_get_node_id(PBVH *pbvh, PBVHNode *node)
 {
   return node->id;
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index 1a21d65d64e..ecebc017e14 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -39,6 +39,8 @@
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
+#include "DNA_meshdata_types.h"
+
 #include "BKE_customdata.h"
 
 #include "bmesh.h"
@@ -454,20 +456,16 @@ static void bm_log_verts_restore(BMesh *bm, BMLog *log, GHash *verts, BMLogEntry
     }
 #endif
 
-    if (log->cd_origco_offset >= 0) {
-      float *oco = BM_ELEM_CD_GET_VOID_P(v, log->cd_origco_offset);
-      copy_v3_v3(oco, v->co);
-    }
+    if (log->cd_dyn_vert >= 0) {
+      MDynTopoVert *mv = BM_ELEM_CD_GET_VOID_P(v, log->cd_dyn_vert);
+      copy_v3_v3(mv->origco, v->co);
+      copy_v3_v3(mv->origno, v->no);
 
-    if (log->cd_origno_offset >= 0) {
-      float *ono = BM_ELEM_CD_GET_VOID_P(v, log->cd_origno_offset);
-      copy_v3_v3(ono, v->no);
-    }
+      if (cd_vcol_offset >= 0) {
+        float *color = BM_ELEM_CD_GET_VOID_P(v, cd_vcol_offset);
 
-    if (log->cd_origvcol_offset >= 0) {
-      float *ocolor = BM_ELEM_CD_GET_VOID_P(v, log->cd_origvcol_offset);
-      float *color = BM_ELEM_CD_GET_VOID_P(v, cd_vcol_offset);
-      copy_v3_v3(ocolor, color);
+        copy_v4_v4(mv->origcolor, color);
+      }
     }
   }
 }
@@ -535,22 +533,6 @@ static void bm_log_vert_values_swap(BMesh *bm, BMLog *log, GHash *verts, BMLogEn
       CustomData_bmesh_copy_data(&entry->vdata, &bm->vdata, lv->customdata, &v->head.data);
     }
 #endif
-
-    if (log->cd_origco_offset >= 0) {
-      float *oco = BM_ELEM_CD_GET_VOID_P(v, log->cd_origco_offset);
-      copy_v3_v3(oco, v->co);
-    }
-
-    if (log->cd_origno_offset >= 0) {
-      float *ono = BM_ELEM_CD_GET_VOID_P(v, log->cd_origno_offset);
-      copy_v3_v3(ono, v->no);
-    }
-
-    if (log->cd_origvcol_offset >= 0) {
-      float *ocolor = BM_ELEM_CD_GET_VOID_P(v, log->cd_origvcol_offset);
-      float *color = BM_ELEM_CD_GET_VOID_P(v, cd_vcol_offset);
-      copy_v3_v3(ocolor, color);
-    }
   }
 }
 
@@ -716,9 +698,6 @@ static void bm_log_id_ghash_release(BMLog *log, GHash *id_ghash)
 void BM_log_set_cd_offsets(
     BMLog *log, int cd_origco_offset, int cd_origno_offset, int cd_origvol_offset, int cd_dyn_vert)
 {
-  log->cd_origco_offset = cd_origco_offset;
-  log->cd_origno_offset = cd_origno_offset;
-  log->cd_origvcol_offset = cd_origvol_offset;
   log->cd_dyn_vert = cd_dyn_vert;
 }
 
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 38ad6c7e48a..8ed8623d36e 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -210,14 +210,27 @@ void SCULPT_vertex_normal_get(SculptSession *ss, SculptVertRef index, float no[3
   }
 }
 
-const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, SculptVertRef index)
+const float *SCULPT_vertex_persistent_co_get(SculptSession *ss,
+                                             SculptVertRef index,
+                                             int cd_pers_co)
 {
-  if (ss->persistent_base) {
-    if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
-      index.i = BM_elem_index_get((BMVert *)index.i);
+  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
+    if (cd_pers_co >= 0) {
+      BMVert *v = (BMVert *)index.i;
+      float *co = BM_ELEM_CD_GET_VOID_P(v, cd_pers_co);
+
+      return co;
     }
-    return ss->persistent_base[index.i].co;
+
+    return SCULPT_vertex_co_get(ss, index);
+  }
+
+  if (ss->persistent_base) {
+    int i = BKE_pbvh_vertex_index_to_table(ss->pbvh, index);
+
+    return ss->persistent_base[i].co;
   }
+
   return SCULPT_vertex_co_get(ss, index);
 }
 
@@ -259,8 +272,24 @@ void SCULPT_vertex_limit_surface_get(SculptSession *ss, SculptVertRef index, flo
   }
 }
 
-void SCULPT_vertex_persistent_normal_get(SculptSession *ss, SculptVertRef index, float no[3])
+void SCULPT_vertex_persistent_normal_get(SculptSession *ss,
+                                         SculptVertRef index,
+                                         float no[3],
+                                         int cd_pers_no)
 {
+  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
+    if (cd_pers_no >= 0) {
+      BMVert *v = (BMVert *)index.i;
+      float(*no2)[3] = BM_ELEM_CD_GET_VOID_P(v, cd_pers_no);
+
+      copy_v3_v3(no, no2);
+      return;
+    }
+
+    SCULPT_vertex_normal_get(ss, index, no);
+    return;
+  }
+
   if (ss->persistent_base) {
     copy_v3_v3(no, ss->persistent_base[BKE_pbvh_vertex_index_to_table(ss->pbvh, index)].no);
     return;
@@ -5060,7 +5089,26 @@ 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->persistent_base && brush->flag & BRUSH_PERSISTENT;
+  bool use_persistent_base = brush->flag & BRUSH_PERSISTENT;
+  const bool is_bmesh = BKE_pbvh_type(ss->pbvh) == PBVH_BMESH;
+
+  bool reset_disp = false;
+
+  if (is_bmesh) {
+    use_persistent_base = use_persistent_base && data->cd_pers_co >= 0;
+
+    // check if we need to zero displacement factor
+    // in first run of brush stroke
+    if (!use_persistent_base) {
+      int nidx = BKE_pbvh_get_node_index(ss->pbvh, data->nodes[n]);
+
+      reset_disp = !BLI_BITMAP_TEST(ss->cache->layer_disp_map, nidx);
+      BLI_BITMAP_SET(ss->cache->layer_disp_map, nidx, true);
+    }
+  }
+  else {
+    use_persistent_base = use_persistent_base && ss->persistent_base;
+  }
 
   PBVHVertexIter vd;
   SculptOrigVertData orig_data;
@@ -5073,10 +5121,6 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
   const int thread_id = BLI_task_parallel_thread_id(tls);
 
   bool bmeshpbvh = BKE_pbvh_type(ss->pbvh) == PBVH_BMESH;
-  if (bmeshpbvh) {
-    BM_mesh_elem_index_ensure(ss->bm, BM_VERT);
-    // BM_mesh_elem_table_ensure(ss->bm, BM_VERT);
-  }
 
   BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
     SCULPT_orig_vert_data_update(&orig_data, &vd);
@@ -5097,12 +5141,26 @@ 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->persistent_base[vi].disp;
+      if (is_bmesh) {
+        BMVert *v = (BMVert *)vd.vertex.i;
+        disp_factor = BM_ELEM_CD_GET_VOID_P(v, data->cd_pers_disp);
+      }
+      else {
+        disp_factor = &ss->persistent_base[vi].disp;
+      }
+    }
+    else if (is_bmesh) {
+      BMVert *v = (BMVert *)vd.vertex.i;
+      disp_factor = BM_ELEM_CD_GET_VOID_P(v, data->cd_layer_disp);
     }
     else {
       disp_factor = &ss->cache->layer_displacement_factor[vi];
     }
 
+    if (reset_disp) {
+      *disp_factor = 0.0f;
+    }
+
     /* When using persistent base, the layer brush (holding Control) invert mode resets the
      * height of the layer to 0. This makes possible to clean edges of previously added layers
      * on top of the base. */
@@ -5127,10 +5185,12 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
     float normal[3];
 
     if (use_persistent_base) {
-      SCULPT_vertex_persistent_normal_get(ss, vd.vertex, normal);
+      SCULPT_vertex_persistent_normal_get(ss, vd.vertex, normal, data->cd_pers_no);
       mul_v3_fl(normal, brush->height);
-      madd_v3_v3v3fl(
-          final_co, SCULPT_vertex_persistent_co_get(ss, vd.vertex), normal, *disp_factor);
+      madd_v3_v3v3fl(final_co,
+                     SCULPT_vertex_persistent_co_get(ss, vd.vertex, data->cd_pers_co),
+                     normal,
+                     *disp_factor);
     }
     else {
       normal_short_to_float_v3(normal, orig_data.no);
@@ -5156,17 +5216,53 @@ static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
 {
   SculptSession *ss = ob->sculpt;
   Brush *brush = BKE_paint_brush(&sd->paint);
+  int cd_pers_co = -1, cd_pers_no = -1, cd_pers_disp = -1, cd_layer_disp = -1;
+
+  if (BKE_pbvh_type(ss->pbvh

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list