[Bf-blender-cvs] [ad99638844e] temp-sculpt-colors: temp-sculpt-colors: loop colors undo now works

Joseph Eagar noreply at git.blender.org
Tue Feb 22 07:29:33 CET 2022


Commit: ad99638844e7747f70aa4be53fe87a0ede1372e5
Author: Joseph Eagar
Date:   Mon Feb 21 22:21:17 2022 -0800
Branches: temp-sculpt-colors
https://developer.blender.org/rBad99638844e7747f70aa4be53fe87a0ede1372e5

temp-sculpt-colors: loop colors undo now works

* PBVHNode now has entries for the unique loops assigned
  to the node.  It works the same as for verts.  Note
  unlike verts loops are not assigned to nodes at pbvh
  build time to save RAM; code that wishes to use them
  must call BKE_pbvh_ensure_node_loops in the main
  thread.

* Sculpt color attribute wrangling now happens inside
  the PBVH api and in C++.  This saved an enourmous
  amount of duplicate (and thus highly error prone) code.

* SCULPT_vertex_color_get/set now forwards to
  new BKE_pbvh_vertex_color_get/set methods.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
A	source/blender/blenkernel/intern/pbvh.cc
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_ops.c
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 8cb5e0216fe..6abc6f6dcc7 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -301,6 +301,10 @@ void BKE_pbvh_node_get_verts(PBVH *pbvh,
                              PBVHNode *node,
                              const int **r_vert_indices,
                              struct MVert **r_verts);
+void BKE_pbvh_node_get_loops(PBVH *pbvh,
+                             PBVHNode *node,
+                             const int **r_loop_indices,
+                             const struct MLoop **r_loops);
 
 void BKE_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
 void BKE_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
@@ -464,11 +468,11 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
         } \
         else { \
           if (!BLI_gsetIterator_done(&vi.bm_unique_verts)) { \
-            vi.bm_vert = BLI_gsetIterator_getKey(&vi.bm_unique_verts); \
+            vi.bm_vert = (BMVert *)BLI_gsetIterator_getKey(&vi.bm_unique_verts); \
             BLI_gsetIterator_step(&vi.bm_unique_verts); \
           } \
           else { \
-            vi.bm_vert = BLI_gsetIterator_getKey(&vi.bm_other_verts); \
+            vi.bm_vert = (BMVert *)BLI_gsetIterator_getKey(&vi.bm_other_verts); \
             BLI_gsetIterator_step(&vi.bm_other_verts); \
           } \
           vi.visible = !BM_elem_flag_test_bool(vi.bm_vert, BM_ELEM_HIDDEN); \
@@ -526,40 +530,32 @@ void BKE_pbvh_node_color_buffer_free(PBVH *pbvh);
 bool BKE_pbvh_get_color_layer(const struct Mesh *me,
                               CustomDataLayer **cl_out,
                               AttributeDomain *attr_out);
-void BKE_pbvh_load_node_loop_colors(PBVH *pbvh,
-                                    struct Mesh *me,
-                                    PBVHNode *node,
-                                    float (*colors)[4]);
-void BKE_pbvh_swap_node_loop_colors(PBVH *pbvh,
-                                    struct Mesh *me,
-                                    PBVHNode *node,
-                                    float (*colors)[4]);
-void BKE_pbvh_save_node_loop_colors(PBVH *pbvh,
-                                    const struct Mesh *me,
-                                    PBVHNode *node,
-                                    float (*colors)[4]);
-
-void BKE_pbvh_load_node_vertex_colors(
-    PBVH *pbvh, struct Mesh *me, PBVHNode *node, float (*colors)[4]);
-void BKE_pbvh_swap_node_vertex_colors(
-    PBVH *pbvh, struct Mesh *me, PBVHNode *node, float (*colors)[4]);
-void BKE_pbvh_save_node_vertex_colors(PBVH *pbvh,
-                                      const struct Mesh *me,
-                                      PBVHNode *node,
-                                      float (*colors)[4]);
+
+/* Swaps colors at each element in indices (of domain pbvh->vcol_domain)
+ * with values in colors. */
+void BKE_pbvh_swap_colors(PBVH *pbvh, float (*colors)[4], int *indices, int totelem);
+
+/* Stores colors from the elements in indices (of domain pbvh->vcol_domain)
+ * into colors. */
+void BKE_pbvh_store_colors(PBVH *pbvh, float (*colors)[4], int *indices, int totelem);
+
+/* Like BKE_pbvh_store_colors but handles loop->vert conversion */
+void BKE_pbvh_store_colors_vertex(PBVH *pbvh, float (*colors)[4], int *indices, int totelem);
 
 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 */
-int BKE_pbvh_node_get_num_loops(PBVH *pbvh, PBVHNode *node);
+void BKE_pbvh_node_num_loops(PBVH *pbvh, PBVHNode *node, int *r_uniqueloop, 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);
 
-void BKE_pbvh_vertex_color_set(PBVH *pbvh, int vertex, float color[4]);
+void BKE_pbvh_vertex_color_set(PBVH *pbvh, int vertex, const float color[4]);
 void BKE_pbvh_vertex_color_get(PBVH *pbvh, int vertex, float r_color[4]);
 
+void BKE_pbvh_ensure_node_loops(PBVH *pbvh, const struct Mesh *me);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 78a145335b4..8a600edc7e3 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -233,6 +233,7 @@ set(SRC
   intern/particle_child.c
   intern/particle_distribute.c
   intern/particle_system.c
+  intern/pbvh.cc
   intern/pbvh.c
   intern/pbvh_bmesh.c
   intern/pointcache.c
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 12d4d12113b..81ffa47cbfa 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1668,9 +1668,6 @@ static void sculpt_update_object(Depsgraph *depsgraph,
     CustomDataLayer *cl;
     AttributeDomain domain;
 
-    ss->vcol = NULL;
-    ss->mcol = NULL;
-
     if (BKE_pbvh_get_color_layer(me, &cl, &domain)) {
       if (cl->type == CD_PROP_COLOR) {
         ss->vcol = cl->data;
@@ -1683,7 +1680,11 @@ static void sculpt_update_object(Depsgraph *depsgraph,
       ss->vcol_type = cl->type;
     }
     else {
+      ss->vcol = NULL;
+      ss->mcol = NULL;
+
       ss->vcol_type = -1;
+      ss->vcol_domain = ATTR_DOMAIN_NUM;
     }
   }
 
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 591f60f9e1b..ecb4891c0cf 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -671,6 +671,9 @@ void BKE_pbvh_free(PBVH *pbvh)
       if (node->vert_indices) {
         MEM_freeN((void *)node->vert_indices);
       }
+      if (node->loop_indices) {
+        MEM_freeN(node->loop_indices);
+      }
       if (node->face_vert_indices) {
         MEM_freeN((void *)node->face_vert_indices);
       }
@@ -1857,6 +1860,22 @@ void BKE_pbvh_vert_mark_update(PBVH *pbvh, int index)
   BLI_BITMAP_ENABLE(pbvh->vert_bitmap, index);
 }
 
+void BKE_pbvh_node_get_loops(PBVH *pbvh,
+                             PBVHNode *node,
+                             const int **r_loop_indices,
+                             const MLoop **r_loops)
+{
+  BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
+
+  if (r_loop_indices) {
+    *r_loop_indices = node->loop_indices;
+  }
+
+  if (r_loops) {
+    *r_loops = pbvh->mloop;
+  }
+}
+
 void BKE_pbvh_node_get_verts(PBVH *pbvh,
                              PBVHNode *node,
                              const int **r_vert_indices,
@@ -3118,390 +3137,111 @@ void BKE_pbvh_is_drawing_set(PBVH *pbvh, bool val)
   pbvh->is_drawing = val;
 }
 
-void BKE_pbvh_swap_node_loop_colors(PBVH *pbvh, Mesh *me, PBVHNode *node, float (*colors)[4])
-{
-}
-
-void BKE_pbvh_load_node_loop_colors(PBVH *pbvh, Mesh *me, PBVHNode *node, float (*colors)[4])
+void BKE_pbvh_node_num_loops(PBVH *pbvh, PBVHNode *node, int *r_uniqueloop, int *r_totloop)
 {
   BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
-  BLI_assert(colors);
-
-  CustomDataLayer *layer;
-  AttributeDomain domain;
-
-  BKE_pbvh_get_color_layer(me, &layer, &domain);
-  MPropCol *pcol = NULL;
-  MLoopCol *mcol = NULL;
-
-  BLI_assert(domain == ATTR_DOMAIN_CORNER);
-  BLI_assert(layer != NULL);
-
-  if (layer->type == CD_PROP_COLOR) {
-    pcol = layer->data;
-  }
-  else {
-    mcol = layer->data;
-  }
-
-  int loop_index = 0;
 
-  if (pcol) {
-    for (int i = 0; i < node->totprim; i++) {
-      const MLoopTri *lt = pbvh->looptri + node->prim_indices[i];
-
-      for (int j = 0; j < 3; j++, loop_index++) {
-        copy_v4_v4(pcol[lt->tri[j]].color, colors[loop_index]);
-      }
-    }
+  if (r_uniqueloop) {
+    *r_uniqueloop = node->uniq_loops;
   }
-  else {
-    for (int i = 0; i < node->totprim; i++) {
-      const MLoopTri *lt = pbvh->looptri + node->prim_indices[i];
-
-      for (int j = 0; j < 3; j++, loop_index++) {
-        float color[4];
 
-        copy_v4_v4(color, colors[loop_index]);
-        linearrgb_to_srgb_v3_v3(color, colors[loop_index]);
-        rgba_float_to_uchar((char *)(mcol + lt->tri[j]), color);
-      }
-    }
+  if (r_totloop) {
+    *r_totloop = node->face_loops;
   }
 }
 
-void BKE_pbvh_save_node_loop_colors(PBVH *pbvh, const Mesh *me, PBVHNode *node, float (*colors)[4])
+void BKE_pbvh_update_active_vcol(PBVH *pbvh, const Mesh *mesh)
 {
-  BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
-
-  CustomDataLayer *layer;
-  AttributeDomain domain;
-
-  BKE_pbvh_get_color_layer(me, &layer, &domain);
-  MPropCol *pcol = NULL;
-  MLoopCol *mcol = NULL;
-
-  BLI_assert(domain == ATTR_DOMAIN_CORNER);
-  BLI_assert(layer != NULL);
-
-  if (layer->type == CD_PROP_COLOR) {
-    pcol = layer->data;
-  }
-  else {
-    mcol = layer->data;
-  }
-
-  int loop_index = 0;
-
-  if (pcol) {
-    for (int i = 0; i < node->totprim; i++) {
-      const MLoopTri *lt = pbvh->looptri + node->prim_indices[i];
-
-      for (int j = 0; j < 3; j++) {
-        copy_v4_v4(colors[loop_index++], pcol[lt->tri[j]].color);
-      }
-    }
-  }
-  else {
-    for (int i = 0; i < node->totprim; i++) {
-      const MLoopTri *lt = pbvh->looptri + node->prim_indices[i];
-
-      for (int j = 0; j < 3; j++) {
-        float color[4];
-
-        rgba_uchar_to_float(color, (const char *)(mcol + lt->tri[j]));
-        srgb_to_linearrgb_v3_v3(color, color);
-
-        copy_v4_v4(colors[loop_index++], color);
-      }
-    }
-  }
+  BKE_pbvh_get_color_layer(mesh, &pbvh->vcol, &pbvh->vcol_domain);
 }
 
-int BKE_pbvh_node_get_num_loops(PBVH *pbvh, PBVHNode *node)
+void BKE_pbvh_pmap_set(PBVH *pbvh, const MeshElemMap *pmap)
 {
-  BLI_assert(BKE_pbvh_type(pbvh) != PBVH_GRIDS);
-
-  switch (BKE_pbvh_type(pbvh)) {
-    case PBVH_FACES:
-      return node->totprim * 3;
-    case PBVH_BMESH:
-      return BLI_gset_len(node->bm_faces) * 3;
-    case PBVH_GRIDS:
-      return 0;
-  }
-
-  return 0;
+  pbvh->pmap = pmap;
 }
 
-static void pbvh_load_node_vertex_colors(
-    PBVH *pbvh, Mesh *me, PBVHNode *node, float (*colors)[4], CustomDataLayer *layer)
+void BKE_pbvh_ensure_node_loops(PBVH *pbvh, const Mesh *me)
 {
-  MPropCol *pcol = 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list