[Bf-blender-cvs] [d321d34a501] temp-sculpt-colors: temp-sculpt-colors: make requested changes

Joseph Eagar noreply at git.blender.org
Mon Apr 4 17:51:54 CEST 2022


Commit: d321d34a501c09234b123345badd8a7bdf2aba8a
Author: Joseph Eagar
Date:   Mon Apr 4 08:50:08 2022 -0700
Branches: temp-sculpt-colors
https://developer.blender.org/rBd321d34a501c09234b123345badd8a7bdf2aba8a

temp-sculpt-colors: make requested changes

* BKE_id_attribute_copy_domains_temp:
  - ID argument is now an explicit output parameter,
    r_id.
  - Takes ID type explicitly and sets id->name's type
    code.
* Rotate/reverse color bmops now take an index
  into the color attribute list instead of an
  Object pointer.

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

M	source/blender/blenkernel/BKE_attribute.h
M	source/blender/blenkernel/intern/attribute.c
M	source/blender/bmesh/intern/bmesh_opdefines.c
M	source/blender/bmesh/operators/bmo_utils.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc
M	source/blender/editors/mesh/editmesh_tools.c

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

diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index e085b96525c..83cac8ab8f4 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -103,16 +103,17 @@ void BKE_id_attribute_subset_active_set(struct ID *id,
                                         CustomDataMask mask);
 
 /**
- * Copies CustomData instances into a (usually stack-allocated) ID.  This is a shallow copy, the
- * purpose is to create a bridge for using the C attribute API on arbitrary sets of CustomData
- * domains.
+ * Sets up a temporary ID with arbitrary CustomData domains.  ID will
+ * be zero'd, any non-nullptr CustomData parameter will then be
+ * copied into the appropriate field.
  */
-void BKE_id_attribute_copy_domains_temp(struct ID *temp_id,
+void BKE_id_attribute_copy_domains_temp(short id_type,
                                         const struct CustomData *vdata,
                                         const struct CustomData *edata,
                                         const struct CustomData *ldata,
                                         const struct CustomData *pdata,
-                                        const struct CustomData *cdata);
+                                        const struct CustomData *cdata,
+                                        struct ID *r_id);
 
 struct CustomDataLayer *BKE_id_attributes_active_color_get(const struct ID *id);
 void BKE_id_attributes_active_color_set(struct ID *id, struct CustomDataLayer *active_layer);
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index e6ae02b7c38..651ba197f51 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -614,20 +614,22 @@ void BKE_id_attributes_render_color_set(ID *id, CustomDataLayer *active_layer)
       id, active_layer, CD_FLAG_COLOR_RENDER, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
 }
 
-void BKE_id_attribute_copy_domains_temp(ID *temp_id,
+void BKE_id_attribute_copy_domains_temp(short id_type,
                                         const CustomData *vdata,
                                         const CustomData *edata,
                                         const CustomData *ldata,
                                         const CustomData *pdata,
-                                        const CustomData *cdata)
+                                        const CustomData *cdata,
+                                        ID *r_id)
 {
   CustomData reset;
 
   CustomData_reset(&reset);
 
-  switch (GS(temp_id->name)) {
+  switch (id_type) {
     case ID_ME: {
-      Mesh *me = (Mesh *)temp_id;
+      Mesh *me = (Mesh *)r_id;
+      memset((void *)me, 0, sizeof(*me));
 
       me->edit_mesh = NULL;
 
@@ -639,13 +641,17 @@ void BKE_id_attribute_copy_domains_temp(ID *temp_id,
       break;
     }
     case ID_PT: {
-      PointCloud *pointcloud = (PointCloud *)temp_id;
+      PointCloud *pointcloud = (PointCloud *)r_id;
+
+      memset((void *)pointcloud, 0, sizeof(*pointcloud));
 
       pointcloud->pdata = vdata ? *vdata : reset;
       break;
     }
     case ID_CV: {
-      Curves *curves = (Curves *)temp_id;
+      Curves *curves = (Curves *)r_id;
+
+      memset((void *)curves, 0, sizeof(*curves));
 
       curves->geometry.point_data = vdata ? *vdata : reset;
       curves->geometry.curve_data = cdata ? *cdata : reset;
@@ -654,4 +660,6 @@ void BKE_id_attribute_copy_domains_temp(ID *temp_id,
     default:
       break;
   }
+
+  *((short *)r_id->name) = id_type;
 }
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index 928b7538f73..7424fdb9247 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1493,7 +1493,7 @@ static BMOpDefine bmo_rotate_colors_def = {
   /* slots_in */
   {{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}},    /* input faces */
    {"use_ccw", BMO_OP_SLOT_BOOL},         /* rotate counter-clockwise if true, otherwise clockwise */
-   {"object", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_MESH}},
+   {"color_index", BMO_OP_SLOT_INT}, /* index into color attribute list */
    {{'\0'}},
   },
   {{{'\0'}}},  /* no output */
@@ -1510,7 +1510,7 @@ static BMOpDefine bmo_reverse_colors_def = {
   "reverse_colors",
   /* slots_in */
   {{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}},    /* input faces */
-   {"object", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_MESH}},
+   {"color_index", BMO_OP_SLOT_INT}, /* index into color attribute list */
    {{'\0'}},
   },
   {{{'\0'}}},  /* no output */
diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c
index 1002e970763..60a893ab5da 100644
--- a/source/blender/bmesh/operators/bmo_utils.c
+++ b/source/blender/bmesh/operators/bmo_utils.c
@@ -9,6 +9,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 
@@ -557,20 +558,19 @@ void bmo_reverse_uvs_exec(BMesh *bm, BMOperator *op)
  * Cycle colors for a face
  **************************************************************************** */
 static void bmo_get_loop_color_ref(BMesh *bm,
-                                   Object *ob,
+                                   int index,
                                    int *r_cd_color_offset,
                                    int *r_cd_color_type)
 {
-  *r_cd_color_offset = -1;
+  Mesh me_query;
 
-  if (!ob || ob->type != OB_MESH) {
-    fprintf(stderr, "Must pass in a valid mesh object to reverse_colors\n");
-    return;
-  }
+  BKE_id_attribute_copy_domains_temp(ID_ME, &bm->vdata, NULL, &bm->ldata, NULL, NULL, &me_query.id);
 
-  CustomDataLayer *layer = BKE_id_attributes_active_color_get((ID *)ob->data);
+  CustomDataLayer *layer = BKE_id_attribute_from_index(
+      &me_query.id, index, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
 
-  if (!layer || BKE_id_attribute_domain((ID *)ob->data, layer) != ATTR_DOMAIN_CORNER) {
+  if (!layer || BKE_id_attribute_domain(&me_query.id, layer) != ATTR_DOMAIN_CORNER) {
+    *r_cd_color_offset = -1;
     return;
   }
 
@@ -588,63 +588,66 @@ void bmo_rotate_colors_exec(BMesh *bm, BMOperator *op)
 
   const bool use_ccw = BMO_slot_bool_get(op->slots_in, "use_ccw");
 
-  Object *ob = (Object *)BMO_slot_ptr_get(op->slots_in, "object");
+  const int color_index = BMO_slot_int_get(op->slots_in, "color_index");
 
   int cd_loop_color_offset;
   int cd_loop_color_type;
 
-  bmo_get_loop_color_ref(bm, ob, &cd_loop_color_offset, &cd_loop_color_type);
-
-  if (cd_loop_color_offset != -1) {
-    const size_t size = cd_loop_color_type == CD_PROP_COLOR ? sizeof(MPropCol) : sizeof(MLoopCol);
-    void *p_col;                /* previous color */
-    void *t_col = alloca(size); /* tmp color */
-
-    BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
-      if (use_ccw == false) { /* same loops direction */
-        BMLoop *lf;           /* current face loops */
-        void *f_lcol;         /* first face loop color */
+  bmo_get_loop_color_ref(bm, color_index, &cd_loop_color_offset, &cd_loop_color_type);
 
-        int n = 0;
-        BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
-          /* current loop color is the previous loop color */
-          void *lcol = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_color_offset);
+  if (cd_loop_color_offset == -1) {
+    BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "color_index is invalid");
+    return;
+  }
 
-          if (n == 0) {
-            f_lcol = lcol;
-            p_col = lcol;
-          }
-          else {
-            memcpy(t_col, lcol, size);
-            memcpy(lcol, p_col, size);
-            memcpy(p_col, t_col, size);
-          }
-          n++;
+  const size_t size = cd_loop_color_type == CD_PROP_COLOR ? sizeof(MPropCol) : sizeof(MLoopCol);
+  void *p_col;                /* previous color */
+  void *t_col = alloca(size); /* tmp color */
+
+  BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
+    if (use_ccw == false) { /* same loops direction */
+      BMLoop *lf;           /* current face loops */
+      void *f_lcol;         /* first face loop color */
+
+      int n = 0;
+      BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
+        /* current loop color is the previous loop color */
+        void *lcol = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_color_offset);
+
+        if (n == 0) {
+          f_lcol = lcol;
+          p_col = lcol;
         }
-
-        memcpy(f_lcol, p_col, size);
+        else {
+          memcpy(t_col, lcol, size);
+          memcpy(lcol, p_col, size);
+          memcpy(p_col, t_col, size);
+        }
+        n++;
       }
-      else {        /* counter loop direction */
-        BMLoop *lf; /* current face loops */
-        void *lcol, *p_lcol;
 
-        int n = 0;
-        BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
-          /* previous loop color is the current loop color */
-          lcol = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_color_offset);
-          if (n == 0) {
-            p_lcol = lcol;
-            memcpy(t_col, lcol, size);
-          }
-          else {
-            memcpy(p_lcol, lcol, size);
-            p_lcol = lcol;
-          }
-          n++;
+      memcpy(f_lcol, p_col, size);
+    }
+    else {        /* counter loop direction */
+      BMLoop *lf; /* current face loops */
+      void *lcol, *p_lcol;
+
+      int n = 0;
+      BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
+        /* previous loop color is the current loop color */
+        lcol = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_color_offset);
+        if (n == 0) {
+          p_lcol = lcol;
+          memcpy(t_col, lcol, size);
         }
-
-        memcpy(lcol, t_col, size);
+        else {
+          memcpy(p_lcol, lcol, size);
+          p_lcol = lcol;
+        }
+        n++;
       }
+
+      memcpy(lcol, t_col, size);
     }
   }
 }
@@ -686,16 +689,19 @@ void bmo_reverse_colors_exec(BMesh *bm, BMOperator *op)
   BMOIter iter;
   BMFace *f;
 
-  Object *ob = (Object *)BMO_slot_ptr_get(op->slots_in, "object");
+  const int color_index = BMO_slot_int_get

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list