[Bf-blender-cvs] [05696185789] sculpt-dev: Sculpt-dev: get vcol render layer working

Joseph Eagar noreply at git.blender.org
Tue Nov 9 09:13:28 CET 2021


Commit: 056961857897531b30cb0ef355fcfcf90f32328d
Author: Joseph Eagar
Date:   Tue Nov 9 00:11:03 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rB056961857897531b30cb0ef355fcfcf90f32328d

Sculpt-dev: get vcol render layer working

* Mesh now has a render_color_index member.
  + We really need an attribute ref system
    based on (domain, type, name) triplets.
* RNA uses render_color_index in all three
  cases (loop colors, vert colors, and
         the generic attribute types).
* PBVH draw uses render_color_index too.

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

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_attribute.h
M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/attribute.c
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/bmesh/intern/bmesh_mesh_convert.c
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc
M	source/blender/editors/geometry/geometry_attributes.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesrna/intern/rna_attribute.c
M	source/blender/makesrna/intern/rna_mesh.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 85c195cdb11..cc693c79c92 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -466,6 +466,9 @@ class MESH_UL_color_attributes(UIList):
         split = layout.split(factor=0.50)
         split.emboss = 'NONE'
         split.prop(attribute, "name", text="")
+
+        split.prop(attribute, "active_render", text="", icon = 'RESTRICT_RENDER_OFF' if attribute.active_render else 'RESTRICT_RENDER_ON')
+
         sub = split.row()
         sub.alignment = 'RIGHT'
         sub.active = False
@@ -526,8 +529,6 @@ class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
         add_builtin("crease")
 
         add_attributes(mesh.attributes)
-        add_attributes(mesh.uv_layers)
-        add_attributes(ob.vertex_groups)
 
         colliding_names = [name for name, layers in attributes_by_name.items() if len(layers) >= 2]
         if len(colliding_names) == 0:
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index ecaf71bc8f8..1b13e4c91c8 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -92,6 +92,14 @@ int *BKE_id_attributes_active_color_index_p(struct ID *id);
 void BKE_id_attributes_active_color_set(struct ID *id, struct CustomDataLayer *active_layer);
 struct CustomDataLayer *BKE_id_attributes_active_color_get(struct ID *id);
 
+int *BKE_id_attributes_render_color_index_p(struct ID *id);
+void BKE_id_attributes_render_color_set(struct ID *id, struct CustomDataLayer *active_layer);
+CustomDataLayer *BKE_id_attributes_render_color_get(struct ID *id);
+
+bool BKE_id_attribute_find_unique_name(struct ID *id,
+                                       const char *name,
+                                       char *outname,
+                                       CustomDataMask mask);
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 513fe5b3e6e..cde642375dd 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -665,6 +665,7 @@ BLI_INLINE int BKE_mesh_origindex_mface_mpoly(const int *index_mf_to_mpoly,
 }
 
 /* ensures attribute active indices are kept up to date */
+
 bool BKE_mesh_customdata_merge(struct Mesh *me,
                                AttributeDomain domain,
                                CustomData *src,
@@ -679,22 +680,21 @@ void BKE_mesh_customdata_copy(struct Mesh *me,
                               eCDAllocType alloctype,
                               int totelem);
 
+typedef struct CustomDataMergeState {
+  struct CustomData *dst;
+  int active_type, active_color_type, render_color_type;
+  char active_name[MAX_CUSTOMDATA_LAYER_NAME];
+  char active_color_name[MAX_CUSTOMDATA_LAYER_NAME];
+  char render_color_name[MAX_CUSTOMDATA_LAYER_NAME];
+} CustomDataMergeState;
+
 void BKE_mesh_attributes_update_pre(struct Mesh *me,
                                     AttributeDomain domain,
-                                    CustomData **r_dst,
-                                    CustomData *src,
-                                    int *active_type,
-                                    char active_name[MAX_CUSTOMDATA_LAYER_NAME],
-                                    int *active_color_type,
-                                    char active_color_name[MAX_CUSTOMDATA_LAYER_NAME]);
+                                    CustomDataMergeState *state);
+
 void BKE_mesh_attributes_update_post(struct Mesh *me,
                                      AttributeDomain domain,
-                                     CustomData *dst,
-                                     CustomData *src,
-                                     int *active_type,
-                                     char active_name[MAX_CUSTOMDATA_LAYER_NAME],
-                                     int *active_color_type,
-                                     char active_color_name[MAX_CUSTOMDATA_LAYER_NAME]);
+                                     CustomDataMergeState *state);
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index dfefb9b7680..6a4f144cc15 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -1050,4 +1050,4 @@ void BKE_dyntopo_remesh(DynTopoState *ds,
                         int steps,
                         PBVHTopologyUpdateMode mode);
 void BKE_pbvh_bmesh_get_vcol(
-    struct BMVert *v, float color[4], int vcol_type, int vcol_domain, int vcol_offset);
+    struct BMVert *v, float color[4], int vcol_type, AttributeDomain vcol_domain, int vcol_offset);
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 3b4baa2110d..88b4c9a43e5 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -35,7 +35,10 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_pointcloud_types.h"
 
+#include "BLI_string.h"
 #include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_attribute.h"
 #include "BKE_customdata.h"
@@ -149,6 +152,48 @@ bool BKE_id_attribute_rename(ID *id,
   return true;
 }
 
+typedef struct AttrUniqueData {
+  ID *id;
+  CustomDataMask mask;
+} AttrUniqueData;
+
+static bool unique_name_cb(void *arg, const char *name)
+{
+  AttrUniqueData *data = (AttrUniqueData *)arg;
+
+  DomainInfo info[ATTR_DOMAIN_NUM];
+  get_domains(data->id, info);
+
+  for (AttributeDomain domain = ATTR_DOMAIN_POINT; domain < ATTR_DOMAIN_NUM; domain++) {
+    if (!info[domain].customdata) {
+      continue;
+    }
+
+    CustomData *cdata = info[domain].customdata;
+    for (int i = 0; i < cdata->totlayer; i++) {
+      CustomDataLayer *layer = cdata->layers + i;
+
+      if ((CD_TYPE_AS_MASK(layer->type) & data->mask) && STREQ(layer->name, name)) {
+        return true;
+      }
+    }
+  }
+
+  return false;
+}
+
+bool BKE_id_attribute_find_unique_name(ID *id,
+                                       const char *name,
+                                       char *outname,
+                                       CustomDataMask mask)
+{
+  AttrUniqueData data = {.id = id, .mask = mask};
+
+  BLI_strncpy(outname, name, MAX_CUSTOMDATA_LAYER_NAME);
+
+  return BLI_uniquename_cb(unique_name_cb, &data, NULL, '.', outname, MAX_CUSTOMDATA_LAYER_NAME);
+}
+
 ATTR_NO_OPT CustomDataLayer *BKE_id_attribute_new(
     ID *id, const char *name, const int type, const AttributeDomain domain, ReportList *reports)
 {
@@ -162,7 +207,11 @@ ATTR_NO_OPT CustomDataLayer *BKE_id_attribute_new(
   }
 
   char uniquename[sizeof(customdata->layers->name)];
-  CustomData_find_unique_layer_name(customdata, type, name, uniquename);
+  BKE_id_attribute_find_unique_name(
+      id,
+      name,
+      uniquename,
+      ((1ULL << type) & CD_MASK_PROP_ALL) ? CD_MASK_PROP_ALL : (CustomDataMask)(1ULL << type));
 
   switch (GS(id->name)) {
     case ID_ME: {
@@ -496,6 +545,90 @@ int *BKE_id_attributes_active_color_index_p(ID *id)
   }
 }
 
+CustomDataLayer *BKE_id_attributes_render_color_get(ID *id)
+{
+  int active_index = *BKE_id_attributes_render_color_index_p(id);
+  if (active_index > BKE_id_attributes_length(id, CD_MASK_PROP_ALL)) {
+    fprintf(stderr, "bad active color index %d; was out of bounds\n", active_index);
+    return NULL;
+  }
+
+  DomainInfo info[ATTR_DOMAIN_NUM];
+  get_domains(id, info);
+
+  int index = 0;
+
+  for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) {
+    CustomData *customdata = info[domain].customdata;
+    if (customdata) {
+      for (int i = 0; i < customdata->totlayer; i++) {
+        CustomDataLayer *layer = &customdata->layers[i];
+        if (CD_MASK_PROP_ALL & CD_TYPE_AS_MASK(layer->type)) {
+          if (index == active_index) {
+            if (ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER) &&
+                ELEM(layer->type, CD_PROP_COLOR, CD_MLOOPCOL)) {
+              return layer;
+            }
+            else {
+              fprintf(
+                  stderr, "bad active color index %d; type was: %d\n", active_index, layer->type);
+              return NULL;
+            }
+          }
+
+          index++;
+        }
+      }
+    }
+  }
+
+  return NULL;
+}
+
+ATTR_NO_OPT void BKE_id_attributes_render_color_set(ID *id, CustomDataLayer *active_layer)
+{
+  DomainInfo info[ATTR_DOMAIN_NUM];
+  get_domains(id, info);
+
+  if (!active_layer || !ELEM(active_layer->type, CD_PROP_COLOR, CD_MLOOPCOL)) {
+    fprintf(stderr,
+            "bad active color layer %p; type was %d\n",
+            active_layer,
+            active_layer ? active_layer->type : -1);
+    return;
+  }
+
+  int index = 0;
+
+  for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) {
+    CustomData *customdata = info[domain].customdata;
+
+    if (customdata) {
+      for (int i = 0; i < customdata->totlayer; i++) {
+        CustomDataLayer *layer = &customdata->layers[i];
+        if (layer == active_layer && ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER)) {
+          *BKE_id_attributes_render_color_index_p(id) = index;
+          return;
+        }
+        if (CD_MASK_PROP_ALL & CD_TYPE_AS_MASK(layer->type)) {
+          index++;
+        }
+      }
+    }
+  }
+}
+
+int *BKE_id_attributes_render_color_index_p(ID *id)
+{
+  switch (GS(id->name)) {
+    case ID_ME: {
+      return &((Mesh *)id)->render_color_index;
+    }
+    default:
+      return NULL;
+  }
+}
+
 CustomData *BKE_id_attributes_iterator_next_domain(ID *id, CustomDataLayer *layers)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 174b3b7bcfa..462e6d933aa 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -2274,15 +2274,11 @@ void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh)
 
 void BKE_mesh_attributes_update_pre(Mesh *me,
                                     Attr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list