[Bf-blender-cvs] [7a55066b188] sculpt-dev: Sculpt-dev: Add support for attribute triplets

Joseph Eagar noreply at git.blender.org
Wed Nov 17 07:01:23 CET 2021


Commit: 7a55066b188feea45e71d5906914ba11f5546b60
Author: Joseph Eagar
Date:   Tue Nov 16 21:58:50 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rB7a55066b188feea45e71d5906914ba11f5546b60

Sculpt-dev: Add support for attribute triplets

It simply wasn't maintainable to store active/render
vertex color layer as integer indices into the
global attribute list.  Making that work would've
required a great deal of boilerplate that would
have to be inserted in lots of places.  There
is simply no justification for doing that.

Instead, I've coded an AttributeRef struct that
simply stores a (type, name, domain) triplet to
uniquely reference an attribute layer.

This will be submitted as a patch for master
too.

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

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_attribute.h
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenkernel/intern/attribute.c
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenloader/intern/versioning_300.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/io/alembic/intern/abc_reader_mesh.cc
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesrna/intern/rna_attribute.c
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_brush_engine.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index cc693c79c92..c449d097755 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -451,9 +451,13 @@ class MESH_UL_color_attributes(UIList):
             bad = item.domain not in ["POINT", "CORNER"]
             bad = bad or item.data_type not in ["FLOAT_COLOR", "BYTE_COLOR"]
 
+            #if not bad:
+            #print(bad, idx, item.name, item.domain, item.data_type)
+
             ret.append(self.bitflag_filter_item if not bad else 0)
             idxs.append(idx)
 
+            # note this is index in full attribute list, not color list
             idx += 1
 
         return ret, idxs
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 1b13e4c91c8..3cc4fb9c9cf 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -36,6 +36,7 @@ struct CustomData;
 struct CustomDataLayer;
 struct ID;
 struct ReportList;
+struct AttributeRef;
 
 /* Attribute.domain */
 /**
@@ -53,6 +54,15 @@ typedef enum AttributeDomain {
   ATTR_DOMAIN_NUM
 } AttributeDomain;
 
+typedef enum {
+  ATTR_DOMAIN_MASK_POINT = (1 << 0),
+  ATTR_DOMAIN_MASK_EDGE = (1 << 1),
+  ATTR_DOMAIN_MASK_FACE = (1 << 2),
+  ATTR_DOMAIN_MASK_CORNER = (1 << 3),
+  ATTR_DOMAIN_MASK_CURVE = (1 << 4),
+  ATTR_DOMAIN_MASK_ALL = (1 << 5) - 1
+} AttributeDomainMask;
+
 /* Attributes */
 
 bool BKE_id_attributes_supported(struct ID *id);
@@ -60,6 +70,7 @@ bool BKE_id_attributes_supported(struct ID *id);
 struct CustomDataLayer *BKE_id_attribute_new(struct ID *id,
                                              const char *name,
                                              const int type,
+                                             CustomDataMask list_mask,
                                              const AttributeDomain domain,
                                              struct ReportList *reports);
 bool BKE_id_attribute_remove(struct ID *id,
@@ -79,7 +90,9 @@ bool BKE_id_attribute_rename(struct ID *id,
                              const char *new_name,
                              struct ReportList *reports);
 
-int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask);
+int BKE_id_attributes_length(const struct ID *id,
+                             const AttributeDomainMask domain_mask,
+                             const CustomDataMask mask);
 
 struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id);
 void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer);
@@ -88,11 +101,11 @@ int *BKE_id_attributes_active_index_p(struct ID *id);
 CustomData *BKE_id_attributes_iterator_next_domain(struct ID *id, struct CustomDataLayer *layers);
 CustomDataLayer *BKE_id_attribute_from_index(const struct ID *id, int lookup_index);
 
-int *BKE_id_attributes_active_color_index_p(struct ID *id);
+struct AttributeRef *BKE_id_attributes_active_color_ref_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);
+struct AttributeRef *BKE_id_attributes_render_color_ref_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);
 
@@ -100,6 +113,18 @@ bool BKE_id_attribute_find_unique_name(struct ID *id,
                                        const char *name,
                                        char *outname,
                                        CustomDataMask mask);
+
+int BKE_id_attribute_index_from_ref(struct ID *id,
+                                    struct AttributeRef *ref,
+                                    AttributeDomainMask domain_mask,
+                                    CustomDataMask type_filter);
+
+bool BKE_id_attribute_ref_from_index(struct ID *id,
+                                     int attr_index,
+                                     AttributeDomainMask domain_mask,
+                                     CustomDataMask type_filter,
+                                     struct AttributeRef *r_ref);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 43784b5a856..46c1d502164 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -39,7 +39,7 @@ extern "C" {
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 2
+#define BLENDER_FILE_SUBVERSION 3
 
 /* Minimum Blender version that supports reading file written with the current
  * version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 53d97ff0f13..340e1a957bb 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -189,13 +189,17 @@ bool BKE_id_attribute_find_unique_name(ID *id,
 {
   AttrUniqueData data = {.id = id, .mask = mask};
 
-  BLI_strncpy(outname, name, MAX_CUSTOMDATA_LAYER_NAME);
+  BLI_strncpy_utf8(outname, name, MAX_CUSTOMDATA_LAYER_NAME);
 
   return BLI_uniquename_cb(unique_name_cb, &data, NULL, '.', outname, MAX_CUSTOMDATA_LAYER_NAME);
 }
 
-CustomDataLayer *BKE_id_attribute_new(
-    ID *id, const char *name, const int type, const AttributeDomain domain, ReportList *reports)
+CustomDataLayer *BKE_id_attribute_new(ID *id,
+                                      const char *name,
+                                      const int type,
+                                      CustomDataMask list_mask,
+                                      const AttributeDomain domain,
+                                      ReportList *reports)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
@@ -206,12 +210,9 @@ CustomDataLayer *BKE_id_attribute_new(
     return NULL;
   }
 
-  char uniquename[sizeof(customdata->layers->name)];
-  BKE_id_attribute_find_unique_name(
-      id,
-      name,
-      uniquename,
-      ((1ULL << type) & CD_MASK_PROP_ALL) ? CD_MASK_PROP_ALL : (CustomDataMask)(1ULL << type));
+  char uniquename[MAX_CUSTOMDATA_LAYER_NAME];
+
+  BKE_id_attribute_find_unique_name(id, name, uniquename, list_mask);
 
   switch (GS(id->name)) {
     case ID_ME: {
@@ -327,7 +328,9 @@ CustomDataLayer *BKE_id_attribute_from_index(const ID *id, int lookup_index)
   return NULL;
 }
 
-int BKE_id_attributes_length(ID *id, const CustomDataMask mask)
+int BKE_id_attributes_length(const ID *id,
+                             const AttributeDomainMask domain_mask,
+                             const CustomDataMask mask)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
@@ -336,7 +339,8 @@ int BKE_id_attributes_length(ID *id, const CustomDataMask mask)
 
   for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) {
     CustomData *customdata = info[domain].customdata;
-    if (customdata) {
+
+    if (customdata && ((1 << (int)domain) & domain_mask)) {
       length += CustomData_number_of_layers_typemask(customdata, mask);
     }
   }
@@ -393,7 +397,7 @@ bool BKE_id_attribute_required(ID *id, CustomDataLayer *layer)
 CustomDataLayer *BKE_id_attributes_active_get(ID *id)
 {
   int active_index = *BKE_id_attributes_active_index_p(id);
-  if (active_index > BKE_id_attributes_length(id, CD_MASK_PROP_ALL)) {
+  if (active_index > BKE_id_attributes_length(id, ATTR_DOMAIN_MASK_ALL, CD_MASK_PROP_ALL)) {
     active_index = 0;
   }
 
@@ -463,46 +467,30 @@ int *BKE_id_attributes_active_index_p(ID *id)
 
 CustomDataLayer *BKE_id_attributes_active_color_get(ID *id)
 {
-  int active_index = *BKE_id_attributes_active_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);
+  AttributeRef *ref = BKE_id_attributes_active_color_ref_p(id);
+
+  if (!ref) {
+    fprintf(stderr, "%s: vertex colors not supported for this type\n", __func__);
     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++;
-        }
-      }
-    }
-  }
+  int idx = CustomData_get_named_layer_index(info[ref->domain].customdata, ref->type, ref->name);
 
-  return NULL;
+  return idx != -1 ? info[ref->domain].customdata->layers + idx : NULL;
 }
 
 void BKE_id_attributes_active_color_set(ID *id, CustomDataLayer *active_layer)
 {
+  AttributeRef *ref = BKE_id_attributes_active_color_ref_p(id);
+
+  if (!ref) {
+    fprintf(stderr, "%s: vertex colors not supported for this type\n", __func__);
+    return;
+  }
+
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
 
@@ -514,31 +502,29 @@ void BKE_id_attributes_active_color_set(ID *id, CustomDataLayer *active_layer)
     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 = &c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list