[Bf-blender-cvs] [8c3be511183] temp-sculpt-colors: temp-sculpt-colors: Store loop colors in undo

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


Commit: 8c3be5111838286c2bc17fb868082e73989765dd
Author: Joseph Eagar
Date:   Mon Feb 21 10:36:59 2022 -0800
Branches: temp-sculpt-colors
https://developer.blender.org/rB8c3be5111838286c2bc17fb868082e73989765dd

temp-sculpt-colors: Store loop colors in undo

* Added BKE_pbvh_vertex_color_get/set methods,
  work same as SCULPT_vertex_color_get/set.
  SCULPT_vertex_color_get/set will forward to these
  (but not in this commit).
* PBVH stores active color attribute again.

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

M	release/scripts/addons
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_undo.c

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

diff --git a/release/scripts/addons b/release/scripts/addons
index 089aef61deb..e1d44bf3750 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 089aef61debbece2baff6516e33fc7491629b1d0
+Subproject commit e1d44bf37501eb19a057777bd0b0ba4484773531
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index cd51b7a440b..8cb5e0216fe 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -35,6 +35,7 @@ struct PBVH;
 struct PBVHNode;
 struct SubdivCCG;
 struct TaskParallelSettings;
+struct MeshElemMap;
 
 typedef struct PBVH PBVH;
 typedef struct PBVHNode PBVHNode;
@@ -525,10 +526,40 @@ 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);
-
-bool BKE_pbvh_is_drawing(PBVH *pbvh);
+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]);
+
+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_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_get(PBVH *pbvh, int vertex, float r_color[4]);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 85b714ea34a..12d4d12113b 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1710,6 +1710,10 @@ static void sculpt_update_object(Depsgraph *depsgraph,
   if (need_pmap && ob->type == OB_MESH && !ss->pmap) {
     BKE_mesh_vert_poly_map_create(
         &ss->pmap, &ss->pmap_mem, me->mpoly, me->mloop, me->totvert, me->totpoly, me->totloop);
+
+    if (ss->pbvh) {
+      BKE_pbvh_pmap_set(ss->pbvh, ss->pmap);
+    }
   }
 
   pbvh_show_mask_set(ss->pbvh, ss->show_mask);
@@ -2205,6 +2209,10 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
         BKE_sculpt_bvh_update_from_ccg(pbvh, subdiv_ccg);
       }
     }
+
+    BKE_pbvh_update_active_vcol(pbvh, BKE_object_get_original_mesh(ob));
+    BKE_pbvh_pmap_set(pbvh, ob->sculpt->pmap);
+
     return pbvh;
   }
 
@@ -2224,6 +2232,8 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
     }
   }
 
+  BKE_pbvh_pmap_set(pbvh, ob->sculpt->pmap);
+
   ob->sculpt->pbvh = pbvh;
   return pbvh;
 }
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 9195fd67f09..591f60f9e1b 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -20,6 +20,7 @@
 #include "BKE_attribute.h"
 #include "BKE_ccg.h"
 #include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
 #include "BKE_paint.h"
 #include "BKE_pbvh.h"
 #include "BKE_subdiv_ccg.h"
@@ -600,6 +601,8 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
 
   /* Clear the bitmap so it can be used as an update tag later on. */
   BLI_bitmap_set_all(pbvh->vert_bitmap, false, totvert);
+
+  BKE_pbvh_update_active_vcol(pbvh, mesh);
 }
 
 void BKE_pbvh_build_grids(PBVH *pbvh,
@@ -1260,12 +1263,16 @@ bool BKE_pbvh_get_color_layer(const Mesh *me, CustomDataLayer **r_layer, Attribu
   CustomDataLayer *layer = BKE_id_attributes_active_color_get((ID *)me);
 
   if (!layer || !ELEM(layer->type, CD_PROP_COLOR, CD_MLOOPCOL)) {
+    *r_layer = NULL;
+    *r_attr = ATTR_DOMAIN_NUM;
     return false;
   }
 
   AttributeDomain domain = BKE_id_attribute_domain((ID *)me, layer);
 
   if (!ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER)) {
+    *r_layer = NULL;
+    *r_attr = ATTR_DOMAIN_NUM;
     return false;
   }
 
@@ -3101,7 +3108,7 @@ void BKE_pbvh_respect_hide_set(PBVH *pbvh, bool respect_hide)
 {
   pbvh->respect_hide = respect_hide;
 }
-bool BKE_pbvh_is_drawing(PBVH *pbvh)
+bool BKE_pbvh_is_drawing(const PBVH *pbvh)
 {
   return pbvh->is_drawing;
 }
@@ -3110,3 +3117,391 @@ 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])
+{
+  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]);
+      }
+    }
+  }
+  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);
+      }
+    }
+  }
+}
+
+void BKE_pbvh_save_node_loop_colors(PBVH *pbvh, const Mesh *me, PBVHNode *node, float (*colors)[4])
+{
+  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);
+      }
+    }
+  }
+}
+
+int BKE_pbvh_node_get_num_loops(PBVH *pbvh, PBVHNode *node)
+{
+  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;
+}
+
+static void pbvh_load_node_vertex_colors(
+    PBVH *pbvh, Mesh *me, PBVHNode *node, float (*colors)[4], CustomDataLayer *layer)
+{
+  MPropCol *pcol = NULL;
+  MLoopCol *mcol = NULL;
+
+  BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
+  BLI_assert(layer != NULL);
+
+  if (layer->type == CD_PROP_COLOR) {
+    pcol = layer->data;
+  }
+  else {
+    mcol = layer->data;
+  }
+
+  int allvert;
+  BKE_pbvh_node_num_verts(pbvh, node, NULL, &allvert);
+
+  if (pcol) {
+    for (int i = 0; i < allvert; i++) {
+      copy_v4_v4(pcol[node->vert_indices[i]].color, colors[i]);
+    }
+  }
+  else {
+    for (int i = 0; i < allvert; i++) {
+      float color[4];
+
+      copy_v4_v4(color, colors[i]);
+      linearrgb_to_srgb_v3_v3(color, color);
+      rgba_float_to_uchar((char *)(mcol + node->vert_indices[i]), color);
+    }
+  }
+}
+
+static void pbvh_load_node_loop_vertex_colors(
+    PBVH *pbvh, Mesh *me, PBVHNode *node, float (*colors)[4], CustomDataLayer *layer)
+{
+  BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
+
+  int allvert;
+  BKE_pbvh_node_num_verts(pbvh, node, NULL, &allvert);
+
+  for (int i = 0; i < allvert; i++) {
+    BKE_pbvh_vertex_color_set(pbvh, node->vert_indices[i], colors[i]);
+  }
+}
+
+void BKE_pbvh_load_node_vertex_colors(PBVH *pbvh,
+                                      struct Mesh *me,
+                                      PBVHNode *node,
+                                      float (*colors)[4])
+{
+  CustomDataLayer *layer;
+  AttributeDomain domain;
+
+  BKE_pbvh_get_color_layer(me, &layer, &domain);
+
+  if (domain == ATTR_DOMAIN_CORNER) {
+    pbvh_load_node_loop_vertex_colors(pbvh, me, node, colors, layer);
+  }
+  else {
+    pbvh_load_node_vertex_colors(pbvh, me, node, colors, layer);
+  }
+}
+
+void BKE_pbvh_swap_node_vertex_colors(PBVH *pbvh, Mesh *me, PBVHNode *node, float (*colors)[4])
+{
+}
+
+void pbvh_save_node_vertex_colors(PBVH *pbvh, const Mesh *me, PBVHNode *node, float (*colors)[4])
+{
+  BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
+
+  CustomDataLayer *layer;
+  AttributeDomain doma

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list