[Bf-blender-cvs] [093e29f3c22] temp_bmesh_multires: Tried to fix sculpt vcol paint undo. It's better, but I still need to go through and thorougly analyze just what the undo stack is doing.

Joseph Eagar noreply at git.blender.org
Sat Oct 31 04:06:48 CET 2020


Commit: 093e29f3c2251515d7bbc38dbc11807e982734bb
Author: Joseph Eagar
Date:   Fri Oct 30 20:06:05 2020 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB093e29f3c2251515d7bbc38dbc11807e982734bb

Tried to fix sculpt vcol paint undo.  It's better, but I still need to
go through and thorougly analyze just what the undo stack is doing.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index d8c7d238f49..71c2b447d1f 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -188,6 +188,8 @@ typedef void (*BKE_pbvh_HitOccludedCallback)(PBVHNode *node, void *data, float *
 
 typedef void (*BKE_pbvh_SearchNearestCallback)(PBVHNode *node, void *data, float *tmin);
 
+void BKE_pbvh_get_nodes(PBVH *pbvh, int flag, PBVHNode ***r_array, int *r_totnode);
+
 /* Building */
 
 PBVH *BKE_pbvh_new(void);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 06ee5250a41..d373f75b59c 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -845,8 +845,11 @@ static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter)
   return NULL;
 }
 
-void BKE_pbvh_search_gather(
-    PBVH *pbvh, BKE_pbvh_SearchCallback scb, void *search_data, PBVHNode ***r_array, int *r_tot)
+void BKE_pbvh_search_gather(PBVH *pbvh,
+                            BKE_pbvh_SearchCallback scb,
+                            void *search_data,
+                            PBVHNode ***r_array,
+                            int *r_tot)
 {
   PBVHIter iter;
   PBVHNode **array = NULL, *node;
@@ -3150,6 +3153,11 @@ void BKE_pbvh_respect_hide_set(PBVH *pbvh, bool respect_hide)
   pbvh->respect_hide = respect_hide;
 }
 
+void BKE_pbvh_get_nodes(PBVH *pbvh, int flag, PBVHNode ***r_array, int *r_totnode)
+{
+  BKE_pbvh_search_gather(pbvh, update_search_cb, POINTER_FROM_INT(flag), r_array, r_totnode);
+}
+
 #ifdef PROXY_ADVANCED
 // TODO: if this really works, make sure to pull the neighbor iterator out of sculpt.c and put it
 // here
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index a9324176d15..7ba722d05ab 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1386,7 +1386,8 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter
     if (orig_data->bm_log) {
       orig_data->col = BM_ELEM_CD_GET_VOID_P(iter->bm_vert, orig_data->ss->cd_origvcol_offset);
 
-      //BKE_pbvh_bmesh_update_origvert(orig_data->pbvh, iter->bm_vert, NULL, NULL, &orig_data->col);
+      // BKE_pbvh_bmesh_update_origvert(orig_data->pbvh, iter->bm_vert, NULL, NULL,
+      // &orig_data->col);
     }
     else {
       orig_data->col = orig_data->colors[iter->i];
@@ -1520,11 +1521,11 @@ bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *bru
   return ((BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) &&
 
           (!ss->cache || (!ss->cache->alt_smooth)) &&
-          
+
           /* Requires mesh restore, which doesn't work with
            * dynamic-topology. */
           !(brush->flag & BRUSH_ANCHORED) && !(brush->flag & BRUSH_DRAG_DOT) &&
-          
+
           SCULPT_TOOL_HAS_DYNTOPO(brush->sculpt_tool));
 }
 
@@ -2120,7 +2121,8 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata,
           if (temp_no) {
             normal_float_to_short_v3(no_s, temp_no);
           }
-          //BM_log_original_vert_data(ss->bm, ss->bm_log, vd.bm_vert, &temp_co, &temp_no_s, false);
+          // BM_log_original_vert_data(ss->bm, ss->bm_log, vd.bm_vert, &temp_co, &temp_no_s,
+          // false);
           copy_v3_v3(co, temp_co);
         }
         else {
@@ -5768,7 +5770,7 @@ static void do_brush_action_task_cb(void *__restrict userdata,
     BKE_pbvh_node_mark_update_mask(data->nodes[n]);
   }
   else if (ELEM(data->brush->sculpt_tool, SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR)) {
-    //make sure we have at least one undo_color node
+    // make sure we have at least one undo_color node
     if (!ss->bm || SCULPT_stroke_is_first_brush_step(ss->cache)) {
       SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COLOR);
     }
@@ -7703,6 +7705,11 @@ void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags)
   }
 }
 
+bool all_nodes_callback(PBVHNode *node, void *data)
+{
+  return true;
+}
+
 void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType update_flags)
 {
   /* After we are done drawing the stroke, check if we need to do a more
@@ -7753,12 +7760,28 @@ void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType up
     BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateMask);
   }
 
-  if (update_flags & SCULPT_UPDATE_COLOR) {
-    BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateColor);
-  }
-
   if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
     BKE_pbvh_bmesh_after_stroke(ss->pbvh);
+
+    if (update_flags & SCULPT_UPDATE_COLOR) {
+      PBVHNode **nodes;
+      int totnode = 0;
+
+      //BKE_pbvh_get_nodes(ss->pbvh, PBVH_UpdateColor, &nodes, &totnode);
+      BKE_pbvh_search_gather(ss->pbvh, all_nodes_callback, NULL, &nodes, &totnode);
+
+      for (int i = 0; i < totnode; i++) {
+        SCULPT_undo_push_node(ob, nodes[i], SCULPT_UNDO_COLOR);
+      }
+
+      if (nodes) {
+        MEM_freeN(nodes);
+      }
+    }
+  }
+
+  if (update_flags & SCULPT_UPDATE_COLOR) {
+    BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateColor);
   }
 
   /* Optimization: if there is locked key and active modifiers present in */
@@ -7935,7 +7958,10 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str
 
     SCULPT_undo_push_end();
 
-    if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
+    if (brush->sculpt_tool == SCULPT_TOOL_PAINT || brush->sculpt_tool == SCULPT_TOOL_SMEAR) {
+      SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS|SCULPT_UPDATE_COLOR);
+    }
+    else if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
       SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK);
     }
     else {



More information about the Bf-blender-cvs mailing list