[Bf-blender-cvs] [f0d03695065] sculpt-dev: Sculpt-dev: all vertex colors now live in single UI list.

Joseph Eagar noreply at git.blender.org
Tue Nov 9 06:14:45 CET 2021


Commit: f0d036950650ee02510cb45cc0fe2f15120624a1
Author: Joseph Eagar
Date:   Mon Nov 8 21:09:17 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rBf0d036950650ee02510cb45cc0fe2f15120624a1

Sculpt-dev: all vertex colors now live in single
            UI list.

* Added an index to Mesh for active color attribute.
  This seems janky to me, shouldn't this (along
  with the active attribute index) be a
  domain, name, cdtype triplet?
* Added a little api to preserve the active attribute
  and color indices when changing mesh customdata
  layouts.  See above comment.
* The vertex color panel is now completely unified.
* TODO: allow setting render color layer (not sure how
  to do this).

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

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_attribute.h
M	source/blender/blenkernel/BKE_customdata.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/customdata.c
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/bmesh/intern/bmesh_mesh_convert.c
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/editors/geometry/CMakeLists.txt
M	source/blender/editors/geometry/geometry_attributes.c
M	source/blender/editors/geometry/geometry_intern.h
M	source/blender/editors/geometry/geometry_ops.c
M	source/blender/editors/sculpt_paint/sculpt_undo.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

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

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index b074e28fd94..85c195cdb11 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -433,6 +433,44 @@ class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
         col.operator("mesh.uv_texture_add", icon='ADD', text="")
         col.operator("mesh.uv_texture_remove", icon='REMOVE', text="")
 
+class MESH_UL_color_attributes(UIList):
+    display_domain_names = {
+        'POINT': "Vertex",
+        'EDGE': "Edge",
+        'FACE': "Face",
+        'CORNER': "Face Corner",
+    }
+
+    def filter_items(self, context, data, property):
+        attrs = getattr(data, property)
+        ret = []
+        idxs = []
+        idx = 0
+
+        for item in attrs:
+            bad = item.domain not in ["POINT", "CORNER"]
+            bad = bad or item.data_type not in ["FLOAT_COLOR", "BYTE_COLOR"]
+
+            ret.append(self.bitflag_filter_item if not bad else 0)
+            idxs.append(idx)
+
+            idx += 1
+
+        return ret, idxs
+
+    def draw_item(self, _context, layout, _data, attribute, _icon, _active_data, _active_propname, _index):
+        data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type]
+
+        domain_name = self.display_domain_names.get(attribute.domain, "")
+
+        split = layout.split(factor=0.50)
+        split.emboss = 'NONE'
+        split.prop(attribute, "name", text="")
+        sub = split.row()
+        sub.alignment = 'RIGHT'
+        sub.active = False
+        sub.label(text="%s ▶ %s" % (domain_name, data_type.name))
+
 
 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
     bl_label = "Vertex Colors"
@@ -440,18 +478,62 @@ class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
 
     def draw(self, context):
-        layout = self.layout
-
-        me = context.mesh
+        mesh = context.mesh
 
+        layout = self.layout
         row = layout.row()
-        col = row.column()
 
-        col.template_list("MESH_UL_vcols", "vcols", me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
+        col = row.column()
+        col.template_list("MESH_UL_color_attributes",
+            "attributes",
+            mesh,
+            "attributes",
+            mesh.attributes,
+            "active_color_index",
+            rows=3,)
 
         col = row.column(align=True)
-        col.operator("mesh.vertex_color_add", icon='ADD', text="")
-        col.operator("mesh.vertex_color_remove", icon='REMOVE', text="")
+        col.operator("geometry.color_attribute_add", icon='ADD', text="")
+        col.operator("geometry.attribute_remove", icon='REMOVE', text="")
+
+        active = mesh.attributes.active
+        
+        if active and (active.domain == "POINT" and active.data_type == "FLOAT_COLOR"):
+            layout.operator("sculpt.vertex_to_loop_colors", text="Save To Corners")
+            layout.operator("sculpt.loop_to_vertex_colors", text="Load From Corners")
+
+        self.draw_attribute_warnings(context, layout)
+
+    def draw_attribute_warnings(self, context, layout):
+        attributes_by_name = defaultdict(list)
+
+        ob = context.object
+        mesh = ob.data
+
+        builtin_attribute = object()
+
+        def add_builtin(name):
+            attributes_by_name[name].append(builtin_attribute)
+
+        def add_attributes(layers):
+            for layer in layers:
+                attributes_by_name[layer.name].append(layer)
+
+        add_builtin("position")
+        add_builtin("material_index")
+        add_builtin("shade_smooth")
+        add_builtin("normal")
+        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:
+            return
+
+        layout.label(text="Name collisions: {}".format(", ".join(colliding_names)), icon='ERROR')
 
 class DATA_PT_remesh(MeshButtonsPanel, Panel):
     bl_label = "Remesh"
@@ -615,6 +697,7 @@ classes = (MESH_MT_vertex_group_context_menu,
     MESH_UL_uvmaps,
     MESH_UL_vcols,
     MESH_UL_attributes,
+    MESH_UL_color_attributes,
     DATA_PT_context_mesh,
     DATA_PT_vertex_groups,
     DATA_PT_shape_keys,
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 7476474258b..ecaf71bc8f8 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -86,6 +86,11 @@ void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer);
 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);
+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);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index c330c2de8be..1aedf1f2b28 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -465,6 +465,14 @@ int CustomData_layertype_layers_max(const int type);
 /* make sure the name of layer at index is unique */
 void CustomData_set_layer_unique_name(struct CustomData *data, int index);
 
+/* get unique layer name for a layer that doesn't currently exist */
+void CustomData_find_unique_layer_name(CustomData *data,
+                                       int type,
+                                       const char *name,
+                                       char *outname);
+
+/* try to find layer with name name; if it does not exist,
+   load the active layer name into outname*/
 void CustomData_validate_layer_name(const struct CustomData *data,
                                     int type,
                                     const char *name,
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index be31a09d754..513fe5b3e6e 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -22,6 +22,8 @@
  * \ingroup bke
  */
 
+#include "BKE_attribute.h"
+#include "BKE_customdata.h"
 #include "BKE_mesh_types.h"
 #include "BLI_utildefines.h"
 
@@ -662,6 +664,37 @@ BLI_INLINE int BKE_mesh_origindex_mface_mpoly(const int *index_mf_to_mpoly,
   return (j != -1) ? (index_mp_to_orig ? index_mp_to_orig[j] : j) : -1;
 }
 
+/* ensures attribute active indices are kept up to date */
+bool BKE_mesh_customdata_merge(struct Mesh *me,
+                               AttributeDomain domain,
+                               CustomData *src,
+                               CustomDataMask mask,
+                               eCDAllocType alloctype,
+                               int totelem);
+
+void BKE_mesh_customdata_copy(struct Mesh *me,
+                              AttributeDomain domain,
+                              CustomData *src,
+                              CustomDataMask mask,
+                              eCDAllocType alloctype,
+                              int totelem);
+
+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]);
+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]);
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 1217255300b..dfefb9b7680 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -409,6 +409,7 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *pbvh,
 /* Drawing */
 
 void BKE_pbvh_draw_cb(PBVH *pbvh,
+                      struct Mesh *me,
                       bool update_only_visible,
                       PBVHFrustumPlanes *update_frustum,
                       PBVHFrustumPlanes *draw_frustum,
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index ee8ef5e97f7..3b4baa2110d 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -149,7 +149,7 @@ bool BKE_id_attribute_rename(ID *id,
   return true;
 }
 
-CustomDataLayer *BKE_id_attribute_new(
+ATTR_NO_OPT CustomDataLayer *BKE_id_attribute_new(
     ID *id, const char *name, const int type, const AttributeDomain domain, ReportList *reports)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
@@ -161,25 +161,30 @@ CustomDataLayer *BKE_id_attribute_new(
     return NULL;
   }
 
+  char uniquename[sizeof(customdata->layers->name)];
+  CustomData_find_unique_layer_name(customdata, type, name, uniquename);
+
   switch (GS(id->name)) {
     case ID_ME: {
       Mesh *me = (Mesh *)id;
       BMEditMesh *em = me->edit_mesh;
       if (em != NULL) {
-        BM_data_layer_add_named(em->bm, customdata, type, name);
+        BM_data_layer_add_named(em->bm, cust

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list