[Bf-blender-cvs] [e07bb3955e7] temp_bmesh_multires: Enabled dyntopo for sharp brush. Also fixed paint brush strength being too strong with dyntopo enabled.

Joseph Eagar noreply at git.blender.org
Tue Nov 3 09:48:34 CET 2020


Commit: e07bb3955e7dc73fbe9efad3f5104f79f6a604ed
Author: Joseph Eagar
Date:   Tue Nov 3 00:47:19 2020 -0800
Branches: temp_bmesh_multires
https://developer.blender.org/rBe07bb3955e7dc73fbe9efad3f5104f79f6a604ed

Enabled dyntopo for sharp brush.  Also fixed paint brush strength being
too strong with dyntopo enabled.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh_bmesh.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_face_set.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/modifiers/intern/MOD_boolean.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 81596fc10da..28df1a259e6 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -401,7 +401,7 @@ bool BKE_pbvh_node_frustum_exclude_AABB(PBVHNode *node, void *frustum);
 struct TableGSet *BKE_pbvh_bmesh_node_unique_verts(PBVHNode *node);
 struct TableGSet *BKE_pbvh_bmesh_node_other_verts(PBVHNode *node);
 struct TableGSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node);
-void BKE_pbvh_bmesh_node_save_orig(struct BMesh *bm, PBVHNode *node);
+void BKE_pbvh_bmesh_node_save_ortri(struct BMesh *bm, PBVHNode *node);
 void BKE_pbvh_bmesh_after_stroke(PBVH *pbvh);
 
 /* Update Bounding Box/Redraw and clear flags */
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index a2065da2818..85d4625ab3b 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -290,7 +290,7 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
   n->flag |= PBVH_UpdateNormals | PBVH_UpdateTopology;
 
   if (add_orco) {
-    BKE_pbvh_bmesh_node_save_orig(pbvh->bm, n);
+    BKE_pbvh_bmesh_node_save_ortri(pbvh->bm, n);
   }
 }
 
@@ -441,6 +441,13 @@ static void pbvh_bmesh_node_split(
   n->orig_vb = n->vb;
 }
 
+static void pbvh_bmesh_copy_facedata(BMesh *bm, BMFace *dest, BMFace *src)
+{
+  dest->head.hflag = src->head.hflag;
+  dest->mat_nr = src->mat_nr;
+  CustomData_bmesh_copy_data(&bm->pdata, &bm->pdata, src->head.data, &dest->head.data);
+}
+
 /* Recursively split the node if it exceeds the leaf_limit */
 static bool pbvh_bmesh_node_limit_ensure(PBVH *pbvh, int node_index)
 {
@@ -1534,6 +1541,8 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
                                   BMEdge *e,
                                   BLI_Buffer *edge_loops)
 {
+  BMesh *bm = pbvh->bm;
+
   float co_mid[3], no_mid[3];
 
   /* Get all faces adjacent to the edge */
@@ -1622,6 +1631,8 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
     f_new = pbvh_bmesh_face_create(pbvh, ni, v_tri, e_tri, f_adj);
     long_edge_queue_face_add(eq_ctx, f_new);
 
+    pbvh_bmesh_copy_facedata(bm, f_new, f_adj);
+
 #ifdef DYNTOPO_CD_INTERP
     BMLoop *lfirst = f_adj->l_first;
     while (lfirst->v != v1) {
@@ -1664,6 +1675,8 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
     f_new = pbvh_bmesh_face_create(pbvh, ni, v_tri, e_tri, f_adj);
     long_edge_queue_face_add(eq_ctx, f_new);
 
+    pbvh_bmesh_copy_facedata(bm, f_new, f_adj);
+
 #ifdef DYNTOPO_CD_INTERP
     lsrcs[0] = lfirst->head.data;
     lsrcs[1] = lfirst->next->head.data;
@@ -1980,7 +1993,8 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
 #ifdef DYNTOPO_CD_INTERP
       BMLoop *l2 = f2->l_first;
 
-      CustomData_bmesh_copy_data(&pbvh->bm->pdata, &pbvh->bm->pdata, f->head.data, &f2->head.data);
+      pbvh_bmesh_copy_facedata(pbvh->bm, f2, f);
+
       CustomData_bmesh_copy_data(&pbvh->bm->ldata, &pbvh->bm->ldata, l->head.data, &l2->head.data);
       CustomData_bmesh_copy_data(
           &pbvh->bm->ldata, &pbvh->bm->ldata, l->next->head.data, &l2->next->head.data);
@@ -2047,10 +2061,10 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
   /* Move v_conn to the midpoint of v_conn and v_del (if v_conn still exists, it
    * may have been deleted above) */
   if (v_conn != NULL) {
-    // BM_log_vert_before_modified(pbvh->bm, pbvh->bm_log, v_conn, eq_ctx->cd_vert_mask_offset,
-    // false);
-    void *dummy;
-    BKE_pbvh_bmesh_update_origvert(pbvh, v_conn, &dummy, &dummy, &dummy);
+    //log vert in bmlog, but don't update original customata layers, we want them to be interpolated
+    BM_log_vert_before_modified(pbvh->bm_log, v_conn, eq_ctx->cd_vert_mask_offset, true);
+    //void *dummy;
+    //BKE_pbvh_bmesh_update_origvert(pbvh, v_conn, &dummy, &dummy, &dummy);
 
     mid_v3_v3v3(v_conn->co, v_conn->co, v_del->co);
     add_v3_v3(v_conn->no, v_del->no);
@@ -2287,7 +2301,7 @@ bool pbvh_bmesh_node_raycast(PBVHNode *node,
 
             for (int j = 0; j < 3; j++) {
               if (!hit || len_squared_v3v3(location, v_tri[j]->co) <
-                  len_squared_v3v3(location, nearest_vertex_co)) {
+                              len_squared_v3v3(location, nearest_vertex_co)) {
                 copy_v3_v3(nearest_vertex_co, v_tri[j]->co);
                 SculptVertRef vref = {(intptr_t)v_tri[j]};  // BM_elem_index_get(v_tri[j]);
                 *r_active_vertex_index = vref;
@@ -2854,7 +2868,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
  * (currently just raycast), store the node's triangles and vertices.
  *
  * Skips triangles that are hidden. */
-void BKE_pbvh_bmesh_node_save_orig(BMesh *bm, PBVHNode *node)
+void BKE_pbvh_bmesh_node_save_ortri(BMesh *bm, PBVHNode *node)
 {
   /* Skip if original coords/triangles are already saved */
   if (node->bm_orco) {
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index 7a1bb43a482..49c10c8d21d 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -264,6 +264,10 @@ static void bm_log_vert_customdata(BMesh *bm, BMLog *log, BMVert *v, BMLogVert *
   //}
   BMLogEntry *entry = log->current_entry;
 
+  if (!entry) {
+    return;
+  }
+
   if (lv->customdata) {
     BLI_mempool_free(entry->vdata.pool, lv->customdata);
     lv->customdata = NULL;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index e9b7876b206..05571c75cca 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1356,6 +1356,7 @@ void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *
   SculptUndoNode *unode = NULL;
   data->ss = ob->sculpt;
 
+  /*do not allocate an undo node for bmesh pbvh*/
   if (!ob->sculpt->bm) {
     unode = SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COORDS);
   }
@@ -1378,11 +1379,6 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter
       orig_data->no = orig_data->_no;
 
       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, &orig_data->co, &orig_data->no, &orig_data->col);
-      // BM_log_original_vert_data(orig_data->bm_log, iter->bm_vert, &orig_data->co,
-      // &orig_data->no);
     }
     else {
       orig_data->co = orig_data->coords[iter->i];
@@ -1392,9 +1388,6 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter
   else if (orig_data->datatype == SCULPT_UNDO_COLOR) {
     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);
     }
     else {
       orig_data->col = orig_data->colors[iter->i];
@@ -5719,16 +5712,22 @@ static void sculpt_topology_update(Sculpt *sd,
       }
     }
 
+    bool undo_push = !use_original ||
+                     SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache);
+
     for (n = 0; n < totnode; n++) {
-      SCULPT_undo_push_node(ob,
-                            nodes[n],
-                            brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK :
-                                                                     SCULPT_UNDO_COORDS);
+      if (undo_push) {
+        SCULPT_undo_push_node(ob,
+                              nodes[n],
+                              brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK :
+                                                                       SCULPT_UNDO_COORDS);
+      }
+
       BKE_pbvh_node_mark_update(nodes[n]);
 
       if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
         BKE_pbvh_node_mark_topology_update(nodes[n]);
-        BKE_pbvh_bmesh_node_save_orig(ss->bm, nodes[n]);
+        BKE_pbvh_bmesh_node_save_ortri(ss->bm, nodes[n]);
       }
     }
 
@@ -5784,7 +5783,9 @@ static void do_brush_action_task_cb(void *__restrict userdata,
     BKE_pbvh_node_mark_update_color(data->nodes[n]);
   }
   else {
-    SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
+    if (!ss->bm) {
+      SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
+    }
     BKE_pbvh_node_mark_update(data->nodes[n]);
   }
 }
@@ -5892,11 +5893,17 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
     };
 
     // dyntopo can't push undo nodes inside a thread
-    if (ss->bm) {
+    if (ss->bm && ELEM(brush->sculpt_tool, SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR)) {
       for (int i = 0; i < totnode; i++) {
-        //SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COLOR);
-        SCULPT_undo_push_node(ob, nodes[i], SCULPT_UNDO_COLOR);
-        BKE_pbvh_update_origcolor_bmesh(ss->pbvh, nodes[i]);
+        if (SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COLOR)) {
+          BKE_pbvh_update_origcolor_bmesh(ss->pbvh, nodes[i]);
+        }
+       // SCULPT_undo_push_node(ob, nodes[i], SCULPT_UNDO_COLOR);
+      }
+    }
+    else if (ss->bm) {
+      for (int i = 0; i < totnode; i++) {
+        SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COORDS);
       }
     }
 
@@ -9593,14 +9600,14 @@ static void dyntopo_detail_size_sample_from_surface(Object *ob,
                                                     DyntopoDetailSizeEditCustomData *cd)
 {
   SculptSession *ss = ob->sculpt;
-  const int active_vertex = SCULPT_active_vertex_get(ss);
+  const SculptVertRef active_vertex = SCULPT_active_vertex_get(ss);
 
   float len_accum = 0;
   int num_neighbors = 0;
   SculptVertexNeighborIter ni;
   SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, active_vertex, ni) {
     len_accum += len_v3v3(SCULPT_vertex_co_get(ss, active_vertex),
-                          SCULPT_vertex_co_get(ss, ni.index));
+                          SCULPT_vertex_co_get(ss, ni.vertex));
     num_neighbors++;
   }
   SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
diff --git a/sour

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list