[Bf-blender-cvs] [5c774392642] temp_bmesh_multires: * Fix bug in BKE_pbvh_node_color_buffer_get.

Joseph Eagar noreply at git.blender.org
Tue Oct 27 08:20:46 CET 2020


Commit: 5c774392642caa79327a3854734ee2a70d73eebc
Author: Joseph Eagar
Date:   Tue Oct 27 00:20:07 2020 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB5c774392642caa79327a3854734ee2a70d73eebc

* Fix bug in BKE_pbvh_node_color_buffer_get.

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

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/bmesh/intern/bmesh_log.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/makesdna/DNA_brush_types.h

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 60f0b420864..752c2a537fa 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -144,6 +144,7 @@ typedef struct {
 
 typedef struct {
   float (*color)[4];
+  int size;
 } PBVHColorBufferNode;
 
 typedef enum {
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 936205c91ce..7a919a2bd38 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -2941,8 +2941,14 @@ PBVHColorBufferNode *BKE_pbvh_node_color_buffer_get(PBVHNode *node)
     totvert = node->uniq_verts;
   }
 
+  if (node->color_buffer.color && node->color_buffer.size != totvert) {
+    MEM_freeN(node->color_buffer.color);
+    node->color_buffer.color = NULL;
+  }
+
   if (!node->color_buffer.color) {
     node->color_buffer.color = MEM_callocN(sizeof(float[4]) * totvert, "Color buffer");
+    node->color_buffer.size = totvert;
   }
   return &node->color_buffer;
 }
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 3d2dddf36c4..947b7fa6615 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -582,6 +582,7 @@ static BMVert *pbvh_bmesh_vert_create(PBVH *pbvh,
 
   /* Log the new vertex */
   BM_log_vert_added(pbvh->bm_log, v, cd_vert_mask_offset);
+  v->head.index = pbvh->bm->totvert; //set provisional index
 
   return v;
 }
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index dcad3e78c99..1c543c24379 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -999,7 +999,7 @@ void BM_log_vert_added(BMLog *log, BMVert *v, const int cd_vert_mask_offset)
   lv = bm_log_vert_alloc(log, v, cd_vert_mask_offset);
   BLI_ghash_insert(log->current_entry->added_verts, key, lv);
 
-  bm_log_vert_customdata(log->bm, log, v, lv);
+  //bm_log_vert_customdata(log->bm, log, v, lv);
 }
 
 /* Log a face before it is modified
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 45abe3b5bd3..06fc4bb6507 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -787,7 +787,7 @@ static void sculpt_vertex_neighbors_get_faces(SculptSession *ss,
                                               SculptVertRef vertex,
                                               SculptVertexNeighborIter *iter)
 {
-  int index = (int)vertex.i;
+  int index = BKE_pbvh_vertex_index_to_table(ss->pbvh, vertex);
 
   MeshElemMap *vert_map = &ss->pmap[index];
   iter->size = 0;
@@ -1326,6 +1326,7 @@ void SCULPT_orig_vert_data_unode_init(SculptOrigVertData *data, Object *ob, Scul
   data->unode = unode;
 
   data->pbvh = ss->pbvh;
+  data->ss = ss;
 
   if (bm) {
     data->bm_log = ss->bm_log;
@@ -1345,6 +1346,7 @@ void SCULPT_orig_vert_data_unode_init(SculptOrigVertData *data, Object *ob, Scul
 void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *node)
 {
   SculptUndoNode *unode;
+  data->ss = ob->sculpt;
   unode = SCULPT_undo_push_node(ob, node, SCULPT_UNDO_COORDS);
   SCULPT_orig_vert_data_unode_init(data, ob, unode);
 }
@@ -1356,8 +1358,16 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter
 {
   if (orig_data->unode->type == SCULPT_UNDO_COORDS) {
     if (orig_data->bm_log) {
-      BKE_pbvh_bmesh_update_origvert(
-          orig_data->pbvh, iter->bm_vert, &orig_data->co, &orig_data->no, NULL);
+      orig_data->co = BM_ELEM_CD_GET_VOID_P(iter->bm_vert, orig_data->ss->cd_origco_offset);
+
+      float *no = BM_ELEM_CD_GET_VOID_P(iter->bm_vert, orig_data->ss->cd_origno_offset);
+      normal_float_to_short_v3(orig_data->_no, no);
+      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);
     }
@@ -1368,7 +1378,9 @@ void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter
   }
   else if (orig_data->unode->type == SCULPT_UNDO_COLOR) {
     if (orig_data->bm_log) {
-      BKE_pbvh_bmesh_update_origvert(orig_data->pbvh, iter->bm_vert, NULL, NULL, &orig_data->col);
+      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];
@@ -1502,11 +1514,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));
 }
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 06ec9fcce4d..cc3e84a74e9 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -230,6 +230,7 @@ typedef struct {
   short (*normals)[3];
   const float *vmasks;
   float (*colors)[4];
+  short _no[3];
 
   /* Original coordinate, normal, and mask. */
   const float *co;
@@ -237,6 +238,7 @@ typedef struct {
   float mask;
   const float *col;
   struct PBVH *pbvh;
+  struct SculptSession *ss;
 } SculptOrigVertData;
 
 void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *node);
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.c b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
index e74aabce0d3..f5232a262a2 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_color.c
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
@@ -459,6 +459,8 @@ void SCULPT_do_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
     return;
   }
 
+  SCULPT_vertex_random_access_ensure(ss);
+
   const int totvert = SCULPT_vertex_count_get(ss);
 
   if (SCULPT_stroke_is_first_brush_step(ss->cache)) {
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 713f5ee2afa..34262f2a0fb 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -872,8 +872,8 @@ typedef enum eBrushUVSculptTool {
         SCULPT_TOOL_SLIDE_RELAX, \
         SCULPT_TOOL_ELASTIC_DEFORM, \
         SCULPT_TOOL_POSE, \
-        SCULPT_TOOL_DRAW_FACE_SETS, \
         SCULPT_TOOL_PAINT, \
+        SCULPT_TOOL_DRAW_FACE_SETS, \
         SCULPT_TOOL_SMEAR, \
 \
         /* These brushes could handle dynamic topology, \ \



More information about the Bf-blender-cvs mailing list