[Bf-blender-cvs] [9b57037a037] temp-sculpt-colors: temp-sculpt-colors: remove PBVHNode.uniq_loops

Joseph Eagar noreply at git.blender.org
Wed Mar 30 22:33:00 CEST 2022


Commit: 9b57037a037ef5358096e6c7d194a113e4ef69ec
Author: Joseph Eagar
Date:   Wed Mar 30 13:32:40 2022 -0700
Branches: temp-sculpt-colors
https://developer.blender.org/rB9b57037a037ef5358096e6c7d194a113e4ef69ec

temp-sculpt-colors: remove PBVHNode.uniq_loops

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

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

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index ba40bb10310..acbc4778555 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -482,7 +482,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
           vi.co = vi.bm_vert->co; \
           vi.fno = vi.bm_vert->no; \
           vi.index = BM_elem_index_get(vi.bm_vert); \
-          vi.mask = (float*)BM_ELEM_CD_GET_VOID_P(vi.bm_vert, vi.cd_vert_mask_offset); \
+          vi.mask = (float *)BM_ELEM_CD_GET_VOID_P(vi.bm_vert, vi.cd_vert_mask_offset); \
         }
 
 #define BKE_pbvh_vertex_iter_end \
@@ -546,7 +546,7 @@ bool BKE_pbvh_is_drawing(const PBVH *pbvh);
 void BKE_pbvh_is_drawing_set(PBVH *pbvh, bool val);
 
 /* Do not call in PBVH_GRIDS mode */
-void BKE_pbvh_node_num_loops(PBVH *pbvh, PBVHNode *node, int *r_uniqueloop, int *r_totloop);
+void BKE_pbvh_node_num_loops(PBVH *pbvh, PBVHNode *node, int *r_totloop);
 
 void BKE_pbvh_update_active_vcol(PBVH *pbvh, const struct Mesh *mesh);
 void BKE_pbvh_pmap_set(PBVH *pbvh, const struct MeshElemMap *pmap);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 8e2b89d746e..06a01e58e7c 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -3137,14 +3137,10 @@ void BKE_pbvh_is_drawing_set(PBVH *pbvh, bool val)
   pbvh->is_drawing = val;
 }
 
-void BKE_pbvh_node_num_loops(PBVH *UNUSED(pbvh), PBVHNode *node, int *r_uniqueloop, int *r_totloop)
+void BKE_pbvh_node_num_loops(PBVH *UNUSED(pbvh), PBVHNode *node, int *r_totloop)
 {
   BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
 
-  if (r_uniqueloop) {
-    *r_uniqueloop = node->uniq_loops;
-  }
-
   if (r_totloop) {
     *r_totloop = node->face_loops;
   }
@@ -3164,6 +3160,9 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh, const Mesh *me)
 {
   BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
 
+  int totloop = 0;
+
+  /* Check if nodes already have loop indices. */
   for (int i = 0; i < pbvh->totnode; i++) {
     PBVHNode *node = pbvh->nodes + i;
 
@@ -3174,52 +3173,13 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh, const Mesh *me)
     if (node->loop_indices) {
       return;
     }
-  }
 
-  int *visit = MEM_malloc_arrayN(me->totloop, sizeof(int), __func__);
-
-  for (int i = 0; i < me->totloop; i++) {
-    visit[i] = -1;
+    totloop += node->totprim * 3;
   }
 
-  for (int i = 0; i < pbvh->totnode; i++) {
-    PBVHNode *node = pbvh->nodes + i;
-
-    if (!(node->flag & PBVH_Leaf)) {
-      continue;
-    }
-
-    int totloop = 0;
-
-    for (int j = 0; j < node->totprim; j++) {
-      const MLoopTri *mlt = pbvh->looptri + node->prim_indices[j];
-      const MPoly *mp = pbvh->mpoly + mlt->poly;
-
-      totloop += mp->totloop;
-    }
-
-    node->loop_indices = MEM_malloc_arrayN(totloop, sizeof(int), __func__);
-    node->uniq_loops = 0;
-
-    for (int j = 0; j < node->totprim; j++) {
-      const MLoopTri *mlt = pbvh->looptri + node->prim_indices[j];
-      const MPoly *mp = pbvh->mpoly + mlt->poly;
+  BLI_bitmap *visit = BLI_BITMAP_NEW(totloop, __func__);
 
-      for (int k = 0; k < mp->totloop; k++) {
-        int loop = mp->loopstart + k;
-
-        if (visit[loop] != -1) {
-          continue;
-        }
-
-        node->loop_indices[node->uniq_loops++] = loop;
-        visit[loop] = i;
-      }
-    }
-
-  }
-
-  /* Add non-unique loops at the end. */
+  /* Create loop indices from node loop triangles. */
   for (int i = 0; i < pbvh->totnode; i++) {
     PBVHNode *node = pbvh->nodes + i;
 
@@ -3227,17 +3187,16 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh, const Mesh *me)
       continue;
     }
 
-    node->face_loops = node->uniq_loops;
+    node->loop_indices = MEM_malloc_arrayN(node->totprim * 3, sizeof(int), __func__);
+    node->face_loops = 0;
 
     for (int j = 0; j < node->totprim; j++) {
       const MLoopTri *mlt = pbvh->looptri + node->prim_indices[j];
-      const MPoly *mp = pbvh->mpoly + mlt->poly;
-
-      for (int k = 0; k < mp->totloop; k++) {
-        int loop = mp->loopstart + k;
 
-        if (visit[loop] != i) {
-          node->loop_indices[node->face_loops++] = loop;
+      for (int k = 0; k < 3; k++) {
+        if (!BLI_BITMAP_TEST(visit, mlt->tri[k])) {
+          node->loop_indices[node->face_loops++] = mlt->tri[k];
+          BLI_BITMAP_ENABLE(visit, mlt->tri[k]);
         }
       }
     }
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 038e2a515da..0a3a04cec6f 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -67,7 +67,7 @@ struct PBVHNode {
    * are loops unique to this node, see comment for
    * vert_indices for more details.*/
   int *loop_indices;
-  unsigned int uniq_loops, face_loops;
+  unsigned int face_loops;
 
   /* An array mapping face corners into the vert_indices
    * array. The array is sized to match 'totprim', and each of
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 93d8cd39faf..f3026b36e70 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -1064,7 +1064,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
   if (need_loops) {
     int totloop;
 
-    BKE_pbvh_node_num_loops(ss->pbvh, node, &totloop, NULL);
+    BKE_pbvh_node_num_loops(ss->pbvh, node, &totloop);
 
     unode->loop_index = MEM_calloc_arrayN(totloop, sizeof(int), __func__);
     unode->maxloop = 0;
@@ -1399,16 +1399,16 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType
   }
   else {
     const int *vert_indices, *loop_indices;
-    int allvert, uniqloop;
+    int allvert, allloop;
 
     BKE_pbvh_node_num_verts(ss->pbvh, unode->node, NULL, &allvert);
     BKE_pbvh_node_get_verts(ss->pbvh, node, &vert_indices, NULL);
     memcpy(unode->index, vert_indices, sizeof(int) * allvert);
 
     if (unode->loop_index) {
-      BKE_pbvh_node_num_loops(ss->pbvh, unode->node, &uniqloop, NULL);
+      BKE_pbvh_node_num_loops(ss->pbvh, unode->node, &allloop);
       BKE_pbvh_node_get_loops(ss->pbvh, unode->node, &loop_indices, NULL);
-      memcpy(unode->loop_index, loop_indices, sizeof(int) * uniqloop);
+      memcpy(unode->loop_index, loop_indices, sizeof(int) * allloop);
 
       unode->maxloop = BKE_object_get_original_mesh(ob)->totloop;
     }
@@ -1591,7 +1591,9 @@ static void sculpt_undosys_step_encode_init(struct bContext *UNUSED(C), UndoStep
   BLI_listbase_clear(&us->data.nodes);
 }
 
-static bool sculpt_undosys_step_encode(struct bContext *UNUSED(C), struct Main *bmain, UndoStep *us_p)
+static bool sculpt_undosys_step_encode(struct bContext *UNUSED(C),
+                                       struct Main *bmain,
+                                       UndoStep *us_p)
 {
   /* Dummy, encoding is done along the way by adding tiles
    * to the current 'SculptUndoStep' added by encode_init. */



More information about the Bf-blender-cvs mailing list