[Bf-blender-cvs] [924b13b03a7] temp_bmesh_multires: * Added a new CustomData type for dyntopo vertex data: MDynTopoVert. It stores: - Original coordiates, colors and mask (which were previously four seperate layers). - A bitmask with (currently) one bitflag, whether or not a vertex is on a boundary.

Joseph Eagar noreply at git.blender.org
Mon Mar 22 00:28:54 CET 2021


Commit: 924b13b03a78315aa380dce358e4c042cc24a8b4
Author: Joseph Eagar
Date:   Sun Mar 21 16:26:38 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB924b13b03a78315aa380dce358e4c042cc24a8b4

* Added a new CustomData type for dyntopo vertex data: MDynTopoVert.
  It stores:
   - Original coordiates, colors and mask (which were previously four
     seperate layers).
   - A bitmask with (currently) one bitflag, whether or not a vertex is
     on a boundary.

I needed to cache calculating vertex boundary state (which involves
iterating over the edges surrounding a vertex) and got fed up with
having so many CD layers for dyntopo.  This struct consolidates them
and saves having yet another layer just to store a flag.

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/bmesh/intern/bmesh_log.c
M	source/blender/bmesh/intern/bmesh_log.h
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesdna/DNA_customdata_types.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 3e5bf2570a6..41c58bc5469 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -495,6 +495,7 @@ typedef struct SculptSession {
 
   /* BMesh for dynamic topology sculpting */
   struct BMesh *bm;
+  int cd_dyn_vert;
   int cd_vert_node_offset;
   int cd_face_node_offset;
   int cd_vcol_offset;
@@ -617,7 +618,7 @@ typedef struct SculptSession {
    * Set #Main.is_memfile_undo_flush_needed when enabling.
    */
   char needs_flush_to_id;
-
+  char update_boundary_info_bmesh;
 } SculptSession;
 
 void BKE_sculptsession_free(struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 1aff28813a8..fddc6a06bfc 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -224,15 +224,11 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
                           struct BMLog *log,
                           const int cd_vert_node_offset,
                           const int cd_face_node_offset,
-                          const int cd_origco_offset,
-                          const int cd_origno_offset,
-                          const int cd_origvcol_offset);
+                          const int cd_dyn_vert);
 void BKE_pbvh_update_offsets(PBVH *pbvh,
                              const int cd_vert_node_offset,
                              const int cd_face_node_offset,
-                             const int cd_origco_offset,
-                             const int cd_origno_offset,
-                             const int cd_origvcol_offset);
+                             const int cd_dyn_vert);
 void BKE_pbvh_free(PBVH *pbvh);
 
 /** update original data, only data whose r_** parameters are passed in will be updated*/
@@ -496,6 +492,7 @@ typedef struct PBVHVertexIter {
   struct TableGSet *bm_unique_verts, *bm_other_verts;
 
   struct CustomData *bm_vdata;
+  int cd_dyn_vert;
   int cd_vert_mask_offset;
   int cd_vcol_offset;
 
@@ -511,12 +508,17 @@ typedef struct PBVHVertexIter {
   bool visible;
 } PBVHVertexIter;
 
+#define BKE_PBVH_DYNVERT(cd_dyn_vert, v) ((MDynTopoVert *)BM_ELEM_CD_GET_VOID_P(v, cd_dyn_vert))
+
 void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int mode);
 
-#define BKE_pbvh_vertex_iter_begin(pbvh, node, vi, mode) \
-  pbvh_vertex_iter_init(pbvh, node, &vi, mode); \
-\
-  for (vi.i = 0, vi.g = 0; vi.g < vi.totgrid; vi.g++) { \
+#if 0
+#  include "../bmesh/bmesh.h"
+#  include "DNA_meshdata_types.h"
+
+#  define BKE_pbvh_vertex_iter_begin(pbvh, node, vi, mode) \
+    pbvh_vertex_iter_init(pbvh, node, &vi, mode); \
+    vi.i = vi.g = 0; \
     if (vi.grids) { \
       vi.width = vi.gridsize; \
       vi.height = vi.gridsize; \
@@ -530,87 +532,203 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
       vi.width = vi.totvert; \
       vi.height = 1; \
     } \
+    while (BKE_pbvh_vertex_iter_step(pbvh, node, &vi, mode))
+
+#  define BKE_pbvh_vertex_iter_end ((void)0)
+
+__attribute__((optnone)) static bool BKE_pbvh_vertex_iter_step(PBVH *pbvh,
+                                                               PBVHNode *node,
+                                                               PBVHVertexIter *vi,
+                                                               int mode)
+{
+  for (; vi->g < vi->totgrid; vi->g++) {
+    for (; vi->gy < vi->height; vi->gy++) {
+      for (; vi->gx < vi->width; vi->gx++, vi->i++) {
+        if (vi->grid) {
+          vi->co = CCG_elem_co(&vi->key, vi->grid);
+          vi->fno = CCG_elem_no(&vi->key, vi->grid);
+          vi->mask = vi->key.has_mask ? CCG_elem_mask(&vi->key, vi->grid) : NULL;
+          vi->grid = CCG_elem_next(&vi->key, vi->grid);
+          vi->index++;
+          vi->vertex.i++;
+          vi->visible = true;
+          if (vi->gh) {
+            if (BLI_BITMAP_TEST(vi->gh, vi->gy * vi->gridsize + vi->gx)) {
+              continue;
+            }
+          }
+
+          return true;
+        }
+        else if (vi->mverts) {
+          vi->mvert = &vi->mverts[vi->vert_indices[vi->gx]];
+          if (vi->respect_hide) {
+            vi->visible = !(vi->mvert->flag & ME_HIDE);
+            if (mode == PBVH_ITER_UNIQUE && !vi->visible) {
+              continue;
+            }
+          }
+          else {
+            BLI_assert(vi->visible);
+          }
+          vi->co = vi->mvert->co;
+          vi->no = vi->mvert->no;
+          vi->index = vi->vertex.i = vi->vert_indices[vi->i];
+          if (vi->vmask) {
+            vi->mask = &vi->vmask[vi->index];
+          }
+          if (vi->vcol) {
+            vi->col = vi->vcol[vi->index].color;
+          }
+
+          return true;
+        }
+        else {
+          struct BMVert *bv = 0;
+          while (!bv) {
+            if (!vi->bm_cur_set->elems || vi->bi >= vi->bm_cur_set->cur) {
+              if (vi->bm_cur_set != vi->bm_other_verts && mode != PBVH_ITER_UNIQUE) {
+                vi->bm_cur_set = vi->bm_other_verts;
+                vi->bi = 0;
+                if (!vi->bm_cur_set->elems || vi->bi >= vi->bm_other_verts->cur) {
+                  break;
+                }
+              }
+              else {
+                break;
+              }
+            }
+            else {
+              bv = (BMVert*) vi->bm_cur_set->elems[vi->bi++];
+            }
+          }
+          if (!bv) {
+            continue;
+          }
+          vi->bm_vert = bv;
+          if (vi->cd_vcol_offset >= 0) {
+            MPropCol *vcol = (MPropCol*) BM_ELEM_CD_GET_VOID_P(bv, vi->cd_vcol_offset);
+            vi->col = vcol->color;
+          }
+          vi->vertex.i = (intptr_t)bv;
+          vi->index = BM_elem_index_get(vi->bm_vert);
+          vi->visible = !BM_elem_flag_test_bool(vi->bm_vert, BM_ELEM_HIDDEN);
+          if (mode == PBVH_ITER_UNIQUE && !vi->visible) {
+            continue;
+          }
+
+          vi->co = vi->bm_vert->co;
+          vi->fno = vi->bm_vert->no;
+          vi->mask = &BKE_PBVH_DYNVERT(vi->cd_dyn_vert, vi->bm_vert)->mask;
+          return true;
+        }
+      }
+    }
+  }
+
+  return false;
+}
+
+#else
+#  define BKE_pbvh_vertex_iter_begin(pbvh, node, vi, mode) \
+    pbvh_vertex_iter_init(pbvh, node, &vi, mode); \
 \
-    for (vi.gy = 0; vi.gy < vi.height; vi.gy++) { \
-      for (vi.gx = 0; vi.gx < vi.width; vi.gx++, vi.i++) { \
-        if (vi.grid) { \
-          vi.co = CCG_elem_co(&vi.key, vi.grid); \
-          vi.fno = CCG_elem_no(&vi.key, vi.grid); \
-          vi.mask = vi.key.has_mask ? CCG_elem_mask(&vi.key, vi.grid) : NULL; \
-          vi.grid = CCG_elem_next(&vi.key, vi.grid); \
-          vi.index++; \
-          vi.vertex.i++; \
-          vi.visible = true; \
-          if (vi.gh) { \
-            if (BLI_BITMAP_TEST(vi.gh, vi.gy * vi.gridsize + vi.gx)) { \
-              continue; \
+    for (vi.i = 0, vi.g = 0; vi.g < vi.totgrid; vi.g++) { \
+      if (vi.grids) { \
+        vi.width = vi.gridsize; \
+        vi.height = vi.gridsize; \
+        vi.vertex.i = vi.index = vi.grid_indices[vi.g] * vi.key.grid_area - 1; \
+        vi.grid = vi.grids[vi.grid_indices[vi.g]]; \
+        if (mode == PBVH_ITER_UNIQUE) { \
+          vi.gh = vi.grid_hidden[vi.grid_indices[vi.g]]; \
+        } \
+      } \
+      else { \
+        vi.width = vi.totvert; \
+        vi.height = 1; \
+      } \
+\
+      for (vi.gy = 0; vi.gy < vi.height; vi.gy++) { \
+        for (vi.gx = 0; vi.gx < vi.width; vi.gx++, vi.i++) { \
+          if (vi.grid) { \
+            vi.co = CCG_elem_co(&vi.key, vi.grid); \
+            vi.fno = CCG_elem_no(&vi.key, vi.grid); \
+            vi.mask = vi.key.has_mask ? CCG_elem_mask(&vi.key, vi.grid) : NULL; \
+            vi.grid = CCG_elem_next(&vi.key, vi.grid); \
+            vi.index++; \
+            vi.vertex.i++; \
+            vi.visible = true; \
+            if (vi.gh) { \
+              if (BLI_BITMAP_TEST(vi.gh, vi.gy * vi.gridsize + vi.gx)) { \
+                continue; \
+              } \
             } \
           } \
-        } \
-        else if (vi.mverts) { \
-          vi.mvert = &vi.mverts[vi.vert_indices[vi.gx]]; \
-          if (vi.respect_hide) { \
-            vi.visible = !(vi.mvert->flag & ME_HIDE); \
-            if (mode == PBVH_ITER_UNIQUE && !vi.visible) { \
-              continue; \
+          else if (vi.mverts) { \
+            vi.mvert = &vi.mverts[vi.vert_indices[vi.gx]]; \
+            if (vi.respect_hide) { \
+              vi.visible = !(vi.mvert->flag & ME_HIDE); \
+              if (mode == PBVH_ITER_UNIQUE && !vi.visible) { \
+                continue; \
+              } \
+            } \
+            else { \
+              BLI_assert(vi.visible); \
+            } \
+            vi.co = vi.mvert->co; \
+            vi.no = vi.mvert->no; \
+            vi.index = vi.vertex.i = vi.vert_indices[vi.i]; \
+            if (vi.vmask) { \
+              vi.mask = &vi.vmask[vi.index]; \
+            } \
+            if (vi.vcol) { \
+              vi.col = vi.vcol[vi.index].color; \
             } \
           } \
           else { \
-            BLI_assert(vi.visible); \
-          } \
-          vi.co = vi.mvert->co; \
-          vi.no = vi.mvert->no; \
-          vi.index = vi.vertex.i = vi.vert_indices[vi.i]; \
-          if (vi.vmask) { \
-            vi.mask = &vi.vmask[vi.index]; \
-          } \
-          if (vi.vcol) { \
-            vi.col = vi.vcol[vi.index].color; \
-          } \
-        } \
-        else { \
-          BMVert *bv = NULL; \
-          while (!bv) { \
-            if (!vi.bm_cur_set->elems || vi.bi >= vi.bm_cur_set->cur) { \
-              if (vi.bm_cur_set != vi.bm_other_verts && mode != PBVH_ITER_UNIQUE) { \
-                vi.bm_cur_set = vi.bm_other_verts; \
-                vi.bi = 0; \
-                if (!vi.bm_cur_set->elems || vi.bi >= vi.bm_other_verts->cur) { \
+            BMVert *bv = NULL; \
+            while (!bv) { \
+              if (!vi.bm_cur_set->elems || vi.bi >= vi.bm_cur_set->cur) { \
+                if (vi.bm_cur_set != vi.bm_other_verts && mode != PBVH_ITER_UNIQUE) { \
+  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list